Skip to content

Commit

Permalink
feat: Implement m_conversion_function function matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
AmrDeveloper committed Jan 30, 2025
1 parent 2095a8d commit 694d20d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/MatcherFunctions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
12 changes: 12 additions & 0 deletions src/clang_ql/functions/matchers/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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)),
Expand Down Expand Up @@ -154,6 +161,11 @@ fn match_template_function(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
Box::new(FunctionMatcherValue::new(matcher))
}

fn match_conversion_function(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
let matcher = Box::new(IsConversionFunction);
Box::new(FunctionMatcherValue::new(matcher))
}

fn match_virtual_function(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
let matcher = Box::new(IsVirtualMatcher);
Box::new(FunctionMatcherValue::new(matcher))
Expand Down
10 changes: 10 additions & 0 deletions src/clang_ql/matchers/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,6 +31,15 @@ impl Matcher<FunctionNode> for IsTemplateFunction {
}
}

#[derive(Clone)]
pub struct IsConversionFunction;

impl Matcher<FunctionNode> for IsConversionFunction {
fn is_match(&self, function: &FunctionNode) -> bool {
unsafe { clang_getCursorKind(function.cursor) == CXCursor_ConversionFunction }
}
}

#[derive(Clone)]
pub struct IsVirtualMatcher;

Expand Down
1 change: 1 addition & 0 deletions src/clang_ql/matchers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/clang_ql/visitors/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<FunctionNode>);

Expand Down

0 comments on commit 694d20d

Please sign in to comment.