Skip to content

Commit 8fa6c06

Browse files
committed
Issue #12: Implement m_function_decl and m_function_def function matcher
1 parent 0c74165 commit 8fa6c06

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

docs/MatcherFunctions.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
| Function | Parameters | Return | Description |
44
| :----------------------: | :--------: | :-------------: | :--------------------------------------------: |
5+
| m_function_decl | () | FunctionMatcher | Create Matcher to match function declaration |
6+
| m_function_def | () | FunctionMatcher | Create Matcher to match template definition |
57
| m_template_function | () | FunctionMatcher | Create Matcher to match template function |
68
| m_conversion_function | () | FunctionMatcher | Create Matcher to match conversion function |
79
| m_virtual | () | FunctionMatcher | Create Matcher to match virtual function |

src/clang_ql/functions/matchers/function.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ use crate::clang_ql::matchers::IsCopyConstructorMatcher;
1515
use crate::clang_ql::matchers::IsDefaultConstructorMatcher;
1616
use crate::clang_ql::matchers::IsDeletedMethodMatcher;
1717
use crate::clang_ql::matchers::IsDestructorMatcher;
18+
use crate::clang_ql::matchers::IsFunctionDeclaration;
19+
use crate::clang_ql::matchers::IsFunctionDefination;
1820
use crate::clang_ql::matchers::IsMethodMatcher;
1921
use crate::clang_ql::matchers::IsMoveConstructorMatcher;
2022
use crate::clang_ql::matchers::IsPureVirtualMatcher;
@@ -32,6 +34,8 @@ pub(crate) fn register_function_matchers_functions(
3234
) {
3335
map.insert("m_function", match_function);
3436

37+
map.insert("m_function_decl", match_function_declaration);
38+
map.insert("m_function_def", match_function_defination);
3539
map.insert("m_template_function", match_template_function);
3640
map.insert("m_conversion_function", match_conversion_function);
3741
map.insert("m_virtual", match_virtual_function);
@@ -65,6 +69,16 @@ pub(crate) fn register_function_matchers_signatures(map: &mut HashMap<&'static s
6569
.add_parameter(Box::new(FunctionMatcherType)),
6670
);
6771

72+
map.insert(
73+
"m_function_decl",
74+
Signature::with_return(Box::new(FunctionMatcherType)),
75+
);
76+
77+
map.insert(
78+
"m_function_def",
79+
Signature::with_return(Box::new(FunctionMatcherType)),
80+
);
81+
6882
map.insert(
6983
"m_template_function",
7084
Signature::with_return(Box::new(FunctionMatcherType)),
@@ -156,6 +170,16 @@ fn match_function(values: &[Box<dyn Value>]) -> Box<dyn Value> {
156170
Box::new(BoolValue::new(is_matches))
157171
}
158172

173+
fn match_function_declaration(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
174+
let matcher = Box::new(IsFunctionDeclaration);
175+
Box::new(FunctionMatcherValue::new(matcher))
176+
}
177+
178+
fn match_function_defination(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
179+
let matcher = Box::new(IsFunctionDefination);
180+
Box::new(FunctionMatcherValue::new(matcher))
181+
}
182+
159183
fn match_template_function(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
160184
let matcher = Box::new(IsTemplateFunction);
161185
Box::new(FunctionMatcherValue::new(matcher))

src/clang_ql/matchers/function.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use clang_sys::clang_CXXMethod_isStatic;
88
use clang_sys::clang_CXXMethod_isVirtual;
99
use clang_sys::clang_getCXXAccessSpecifier;
1010
use clang_sys::clang_getCursorKind;
11+
use clang_sys::clang_isCursorDefinition;
12+
use clang_sys::clang_isDeclaration;
1113
use clang_sys::CXCursor_CXXMethod;
1214
use clang_sys::CXCursor_Constructor;
1315
use clang_sys::CXCursor_ConversionFunction;
@@ -22,6 +24,24 @@ use crate::clang_ql::values::FunctionNode;
2224

2325
use super::Matcher;
2426

27+
#[derive(Clone)]
28+
pub struct IsFunctionDeclaration;
29+
30+
impl Matcher<FunctionNode> for IsFunctionDeclaration {
31+
fn is_match(&self, function: &FunctionNode) -> bool {
32+
unsafe { clang_isDeclaration(function.cursor.kind) != 0 }
33+
}
34+
}
35+
36+
#[derive(Clone)]
37+
pub struct IsFunctionDefination;
38+
39+
impl Matcher<FunctionNode> for IsFunctionDefination {
40+
fn is_match(&self, function: &FunctionNode) -> bool {
41+
unsafe { clang_isCursorDefinition(function.cursor) != 0 }
42+
}
43+
}
44+
2545
#[derive(Clone)]
2646
pub struct IsTemplateFunction;
2747

src/clang_ql/matchers/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ pub use function::IsCopyConstructorMatcher;
1010
pub use function::IsDefaultConstructorMatcher;
1111
pub use function::IsDeletedMethodMatcher;
1212
pub use function::IsDestructorMatcher;
13+
pub use function::IsFunctionDeclaration;
14+
pub use function::IsFunctionDefination;
1315
pub use function::IsMethodMatcher;
1416
pub use function::IsMoveConstructorMatcher;
1517
pub use function::IsPureVirtualMatcher;

0 commit comments

Comments
 (0)