Skip to content

Commit 2095a8d

Browse files
committedJan 28, 2025·
feat: Implement m_template_function function matcher
1 parent a4e7b43 commit 2095a8d

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed
 

‎docs/MatcherFunctions.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
| Function | Parameters | Return | Description |
44
| :----------------------: | :--------: | :-------------: | :--------------------------------------------: |
5+
| m_template_function | () | FunctionMatcher | Create Matcher to match template function |
56
| m_virtual | () | FunctionMatcher | Create Matcher to match virtual function |
67
| m_pure_virtual | () | FunctionMatcher | Create Matcher to match pure virtual function |
78
| m_method | () | FunctionMatcher | Create Matcher to match method |

‎src/clang_ql/functions/matchers/function.rs

+12
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use crate::clang_ql::matchers::IsMethodMatcher;
1818
use crate::clang_ql::matchers::IsMoveConstructorMatcher;
1919
use crate::clang_ql::matchers::IsPureVirtualMatcher;
2020
use crate::clang_ql::matchers::IsStaticMethodMatcher;
21+
use crate::clang_ql::matchers::IsTemplateFunction;
2122
use crate::clang_ql::matchers::IsVirtualMatcher;
2223
use crate::clang_ql::types::FunctionMatcherType;
2324
use crate::clang_ql::types::FunctionType;
@@ -30,6 +31,7 @@ pub(crate) fn register_function_matchers_functions(
3031
) {
3132
map.insert("m_function", match_function);
3233

34+
map.insert("m_template_function", match_template_function);
3335
map.insert("m_virtual", match_virtual_function);
3436
map.insert("m_pure_virtual", match_pure_virtual_function);
3537
map.insert("m_static", match_static_function);
@@ -61,6 +63,11 @@ pub(crate) fn register_function_matchers_signatures(map: &mut HashMap<&'static s
6163
.add_parameter(Box::new(FunctionMatcherType)),
6264
);
6365

66+
map.insert(
67+
"m_template_function",
68+
Signature::with_return(Box::new(FunctionMatcherType)),
69+
);
70+
6471
map.insert(
6572
"m_virtual",
6673
Signature::with_return(Box::new(FunctionMatcherType)),
@@ -142,6 +149,11 @@ fn match_function(values: &[Box<dyn Value>]) -> Box<dyn Value> {
142149
Box::new(BoolValue::new(is_matches))
143150
}
144151

152+
fn match_template_function(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
153+
let matcher = Box::new(IsTemplateFunction);
154+
Box::new(FunctionMatcherValue::new(matcher))
155+
}
156+
145157
fn match_virtual_function(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
146158
let matcher = Box::new(IsVirtualMatcher);
147159
Box::new(FunctionMatcherValue::new(matcher))

‎src/clang_ql/matchers/function.rs

+10
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use clang_sys::clang_getCursorKind;
1111
use clang_sys::CXCursor_CXXMethod;
1212
use clang_sys::CXCursor_Constructor;
1313
use clang_sys::CXCursor_Destructor;
14+
use clang_sys::CXCursor_FunctionTemplate;
1415
use clang_sys::CX_CXXAccessSpecifier;
1516
use clang_sys::CX_CXXPrivate;
1617
use clang_sys::CX_CXXProtected;
@@ -20,6 +21,15 @@ use crate::clang_ql::values::FunctionNode;
2021

2122
use super::Matcher;
2223

24+
#[derive(Clone)]
25+
pub struct IsTemplateFunction;
26+
27+
impl Matcher<FunctionNode> for IsTemplateFunction {
28+
fn is_match(&self, function: &FunctionNode) -> bool {
29+
unsafe { clang_getCursorKind(function.cursor) == CXCursor_FunctionTemplate }
30+
}
31+
}
32+
2333
#[derive(Clone)]
2434
pub struct IsVirtualMatcher;
2535

‎src/clang_ql/matchers/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub use function::IsMethodMatcher;
1313
pub use function::IsMoveConstructorMatcher;
1414
pub use function::IsPureVirtualMatcher;
1515
pub use function::IsStaticMethodMatcher;
16+
pub use function::IsTemplateFunction;
1617
pub use function::IsVirtualMatcher;
1718

1819
mod combine;

0 commit comments

Comments
 (0)