Skip to content

Commit 694d20d

Browse files
committed
feat: Implement m_conversion_function function matcher
1 parent 2095a8d commit 694d20d

File tree

5 files changed

+25
-0
lines changed

5 files changed

+25
-0
lines changed

docs/MatcherFunctions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
| Function | Parameters | Return | Description |
44
| :----------------------: | :--------: | :-------------: | :--------------------------------------------: |
55
| m_template_function | () | FunctionMatcher | Create Matcher to match template function |
6+
| m_conversion_function | () | FunctionMatcher | Create Matcher to match conversion function |
67
| m_virtual | () | FunctionMatcher | Create Matcher to match virtual function |
78
| m_pure_virtual | () | FunctionMatcher | Create Matcher to match pure virtual function |
89
| m_method | () | FunctionMatcher | Create Matcher to match method |

src/clang_ql/functions/matchers/function.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use gitql_core::values::boolean::BoolValue;
99
use crate::clang_ql::matchers::AccessSpecifierMatcher;
1010
use crate::clang_ql::matchers::IsConstMethodMatcher;
1111
use crate::clang_ql::matchers::IsConstructorMatcher;
12+
use crate::clang_ql::matchers::IsConversionFunction;
1213
use crate::clang_ql::matchers::IsConvertingConstructorMatcher;
1314
use crate::clang_ql::matchers::IsCopyConstructorMatcher;
1415
use crate::clang_ql::matchers::IsDefaultConstructorMatcher;
@@ -32,6 +33,7 @@ pub(crate) fn register_function_matchers_functions(
3233
map.insert("m_function", match_function);
3334

3435
map.insert("m_template_function", match_template_function);
36+
map.insert("m_conversion_function", match_conversion_function);
3537
map.insert("m_virtual", match_virtual_function);
3638
map.insert("m_pure_virtual", match_pure_virtual_function);
3739
map.insert("m_static", match_static_function);
@@ -68,6 +70,11 @@ pub(crate) fn register_function_matchers_signatures(map: &mut HashMap<&'static s
6870
Signature::with_return(Box::new(FunctionMatcherType)),
6971
);
7072

73+
map.insert(
74+
"m_conversion_function",
75+
Signature::with_return(Box::new(FunctionMatcherType)),
76+
);
77+
7178
map.insert(
7279
"m_virtual",
7380
Signature::with_return(Box::new(FunctionMatcherType)),
@@ -154,6 +161,11 @@ fn match_template_function(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
154161
Box::new(FunctionMatcherValue::new(matcher))
155162
}
156163

164+
fn match_conversion_function(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
165+
let matcher = Box::new(IsConversionFunction);
166+
Box::new(FunctionMatcherValue::new(matcher))
167+
}
168+
157169
fn match_virtual_function(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
158170
let matcher = Box::new(IsVirtualMatcher);
159171
Box::new(FunctionMatcherValue::new(matcher))

src/clang_ql/matchers/function.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use clang_sys::clang_getCXXAccessSpecifier;
1010
use clang_sys::clang_getCursorKind;
1111
use clang_sys::CXCursor_CXXMethod;
1212
use clang_sys::CXCursor_Constructor;
13+
use clang_sys::CXCursor_ConversionFunction;
1314
use clang_sys::CXCursor_Destructor;
1415
use clang_sys::CXCursor_FunctionTemplate;
1516
use clang_sys::CX_CXXAccessSpecifier;
@@ -30,6 +31,15 @@ impl Matcher<FunctionNode> for IsTemplateFunction {
3031
}
3132
}
3233

34+
#[derive(Clone)]
35+
pub struct IsConversionFunction;
36+
37+
impl Matcher<FunctionNode> for IsConversionFunction {
38+
fn is_match(&self, function: &FunctionNode) -> bool {
39+
unsafe { clang_getCursorKind(function.cursor) == CXCursor_ConversionFunction }
40+
}
41+
}
42+
3343
#[derive(Clone)]
3444
pub struct IsVirtualMatcher;
3545

src/clang_ql/matchers/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ mod function;
44
pub use function::AccessSpecifierMatcher;
55
pub use function::IsConstMethodMatcher;
66
pub use function::IsConstructorMatcher;
7+
pub use function::IsConversionFunction;
78
pub use function::IsConvertingConstructorMatcher;
89
pub use function::IsCopyConstructorMatcher;
910
pub use function::IsDefaultConstructorMatcher;

src/clang_ql/visitors/function.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ extern "C" fn visit_children(
3636
|| cursor_kind == CXCursor_FunctionTemplate
3737
|| cursor_kind == CXCursor_Constructor
3838
|| cursor_kind == CXCursor_Destructor
39+
|| cursor_kind == CXCursor_ConversionFunction
3940
{
4041
let functions = &mut *(data as *mut Vec<FunctionNode>);
4142

0 commit comments

Comments
 (0)