From 694d20d9beb356095bc80237e3d3f7d52fec9a5e Mon Sep 17 00:00:00 2001 From: AmrDeveloper Date: Thu, 30 Jan 2025 19:00:26 +0100 Subject: [PATCH] feat: Implement `m_conversion_function` function matcher --- docs/MatcherFunctions.md | 1 + src/clang_ql/functions/matchers/function.rs | 12 ++++++++++++ src/clang_ql/matchers/function.rs | 10 ++++++++++ src/clang_ql/matchers/mod.rs | 1 + src/clang_ql/visitors/function.rs | 1 + 5 files changed, 25 insertions(+) diff --git a/docs/MatcherFunctions.md b/docs/MatcherFunctions.md index 8fa458d..13a560f 100644 --- a/docs/MatcherFunctions.md +++ b/docs/MatcherFunctions.md @@ -3,6 +3,7 @@ | Function | Parameters | Return | Description | | :----------------------: | :--------: | :-------------: | :--------------------------------------------: | | m_template_function | () | FunctionMatcher | Create Matcher to match template function | +| m_conversion_function | () | FunctionMatcher | Create Matcher to match conversion function | | m_virtual | () | FunctionMatcher | Create Matcher to match virtual function | | m_pure_virtual | () | FunctionMatcher | Create Matcher to match pure virtual function | | m_method | () | FunctionMatcher | Create Matcher to match method | diff --git a/src/clang_ql/functions/matchers/function.rs b/src/clang_ql/functions/matchers/function.rs index f6ae787..d3576ef 100644 --- a/src/clang_ql/functions/matchers/function.rs +++ b/src/clang_ql/functions/matchers/function.rs @@ -9,6 +9,7 @@ use gitql_core::values::boolean::BoolValue; use crate::clang_ql::matchers::AccessSpecifierMatcher; use crate::clang_ql::matchers::IsConstMethodMatcher; use crate::clang_ql::matchers::IsConstructorMatcher; +use crate::clang_ql::matchers::IsConversionFunction; use crate::clang_ql::matchers::IsConvertingConstructorMatcher; use crate::clang_ql::matchers::IsCopyConstructorMatcher; use crate::clang_ql::matchers::IsDefaultConstructorMatcher; @@ -32,6 +33,7 @@ pub(crate) fn register_function_matchers_functions( map.insert("m_function", match_function); map.insert("m_template_function", match_template_function); + map.insert("m_conversion_function", match_conversion_function); map.insert("m_virtual", match_virtual_function); map.insert("m_pure_virtual", match_pure_virtual_function); map.insert("m_static", match_static_function); @@ -68,6 +70,11 @@ pub(crate) fn register_function_matchers_signatures(map: &mut HashMap<&'static s Signature::with_return(Box::new(FunctionMatcherType)), ); + map.insert( + "m_conversion_function", + Signature::with_return(Box::new(FunctionMatcherType)), + ); + map.insert( "m_virtual", Signature::with_return(Box::new(FunctionMatcherType)), @@ -154,6 +161,11 @@ fn match_template_function(_values: &[Box]) -> Box { Box::new(FunctionMatcherValue::new(matcher)) } +fn match_conversion_function(_values: &[Box]) -> Box { + let matcher = Box::new(IsConversionFunction); + Box::new(FunctionMatcherValue::new(matcher)) +} + fn match_virtual_function(_values: &[Box]) -> Box { let matcher = Box::new(IsVirtualMatcher); Box::new(FunctionMatcherValue::new(matcher)) diff --git a/src/clang_ql/matchers/function.rs b/src/clang_ql/matchers/function.rs index 6931c98..0b3b834 100644 --- a/src/clang_ql/matchers/function.rs +++ b/src/clang_ql/matchers/function.rs @@ -10,6 +10,7 @@ use clang_sys::clang_getCXXAccessSpecifier; use clang_sys::clang_getCursorKind; use clang_sys::CXCursor_CXXMethod; use clang_sys::CXCursor_Constructor; +use clang_sys::CXCursor_ConversionFunction; use clang_sys::CXCursor_Destructor; use clang_sys::CXCursor_FunctionTemplate; use clang_sys::CX_CXXAccessSpecifier; @@ -30,6 +31,15 @@ impl Matcher for IsTemplateFunction { } } +#[derive(Clone)] +pub struct IsConversionFunction; + +impl Matcher for IsConversionFunction { + fn is_match(&self, function: &FunctionNode) -> bool { + unsafe { clang_getCursorKind(function.cursor) == CXCursor_ConversionFunction } + } +} + #[derive(Clone)] pub struct IsVirtualMatcher; diff --git a/src/clang_ql/matchers/mod.rs b/src/clang_ql/matchers/mod.rs index 38f7261..591939c 100644 --- a/src/clang_ql/matchers/mod.rs +++ b/src/clang_ql/matchers/mod.rs @@ -4,6 +4,7 @@ mod function; pub use function::AccessSpecifierMatcher; pub use function::IsConstMethodMatcher; pub use function::IsConstructorMatcher; +pub use function::IsConversionFunction; pub use function::IsConvertingConstructorMatcher; pub use function::IsCopyConstructorMatcher; pub use function::IsDefaultConstructorMatcher; diff --git a/src/clang_ql/visitors/function.rs b/src/clang_ql/visitors/function.rs index 3d99fc1..09ade50 100644 --- a/src/clang_ql/visitors/function.rs +++ b/src/clang_ql/visitors/function.rs @@ -36,6 +36,7 @@ extern "C" fn visit_children( || cursor_kind == CXCursor_FunctionTemplate || cursor_kind == CXCursor_Constructor || cursor_kind == CXCursor_Destructor + || cursor_kind == CXCursor_ConversionFunction { let functions = &mut *(data as *mut Vec);