Skip to content

Commit 86c39f2

Browse files
committedJan 12, 2025·
Implement m_public, m_protected and m_private matchers functions
1 parent 08d248a commit 86c39f2

File tree

4 files changed

+91
-25
lines changed

4 files changed

+91
-25
lines changed
 

‎docs/MatcherFunctions.md

+17-14
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
### AST matchers functions
22

3-
| Function | Parameters | Return | Description |
4-
| :----------------------: | :--------: | :-------------: | :---------------------------------------------------------------: |
5-
| m_virtual | () | FunctionMatcher | Create Matcher to check if the function is virtual |
6-
| m_pure_virtual | () | FunctionMatcher | Create Matcher to check if the function is pure virtual |
7-
| m_method | () | FunctionMatcher | Create Matcher to check if the function is a method |
8-
| m_static | () | FunctionMatcher | Create Matcher to check if the function is static |
9-
| m_const | () | FunctionMatcher | Create Matcher to check if the function is const |
10-
| m_deleted | () | FunctionMatcher | Create Matcher to check if the function is deleted |
11-
| m_constructor | () | FunctionMatcher | Create Matcher to check if the function is constructor |
12-
| m_default_constructor | () | FunctionMatcher | Create Matcher to check if the function is default constructor |
13-
| m_copy_constructor | () | FunctionMatcher | Create Matcher to check if the function is copy constructor |
14-
| m_move_constructor | () | FunctionMatcher | Create Matcher to check if the function is move constructor |
15-
| m_converting_constructor | () | FunctionMatcher | Create Matcher to check if the function is converting constructor |
16-
| m_destructor | () | FunctionMatcher | Create Matcher to check if the function is destructor |
3+
| Function | Parameters | Return | Description |
4+
| :----------------------: | :--------: | :-------------: | :--------------------------------------------: |
5+
| m_virtual | () | FunctionMatcher | Create Matcher to match virtual function |
6+
| m_pure_virtual | () | FunctionMatcher | Create Matcher to match pure virtual function |
7+
| m_method | () | FunctionMatcher | Create Matcher to match method |
8+
| m_static | () | FunctionMatcher | Create Matcher to match static function |
9+
| m_const | () | FunctionMatcher | Create Matcher to match const function |
10+
| m_deleted | () | FunctionMatcher | Create Matcher to match deleted function |
11+
| m_constructor | () | FunctionMatcher | Create Matcher to match constructor |
12+
| m_default_constructor | () | FunctionMatcher | Create Matcher to match default constructor |
13+
| m_copy_constructor | () | FunctionMatcher | Create Matcher to match copy constructor |
14+
| m_move_constructor | () | FunctionMatcher | Create Matcher to match move constructor |
15+
| m_converting_constructor | () | FunctionMatcher | Create Matcher to match converting constructor |
16+
| m_destructor | () | FunctionMatcher | Create Matcher to match function is destructor |
17+
| m_public | () | FunctionMatcher | Create Matcher to match public function |
18+
| m_protected | () | FunctionMatcher | Create Matcher to match protected function |
19+
| m_private | () | FunctionMatcher | Create Matcher to match private function |

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

+35
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use gitql_core::signature::StandardFunction;
66
use gitql_core::values::base::Value;
77
use gitql_core::values::boolean::BoolValue;
88

9+
use crate::clang_ql::matchers::AccessSpecifierMatcher;
910
use crate::clang_ql::matchers::IsConstMethodMatcher;
1011
use crate::clang_ql::matchers::IsConstructorMatcher;
1112
use crate::clang_ql::matchers::IsConvertingConstructorMatcher;
@@ -45,6 +46,10 @@ pub(crate) fn register_function_matchers_functions(
4546
match_converting_constructor_function,
4647
);
4748
map.insert("m_destructor", match_destructor_function);
49+
50+
map.insert("m_public", match_public_function);
51+
map.insert("m_protected", match_protected_function);
52+
map.insert("m_private", match_private_function);
4853
}
4954

5055
#[inline(always)]
@@ -110,6 +115,21 @@ pub(crate) fn register_function_matchers_signatures(map: &mut HashMap<&'static s
110115
"m_destructor",
111116
Signature::with_return(Box::new(FunctionMatcherType)),
112117
);
118+
119+
map.insert(
120+
"m_public",
121+
Signature::with_return(Box::new(FunctionMatcherType)),
122+
);
123+
124+
map.insert(
125+
"m_protected",
126+
Signature::with_return(Box::new(FunctionMatcherType)),
127+
);
128+
129+
map.insert(
130+
"m_private",
131+
Signature::with_return(Box::new(FunctionMatcherType)),
132+
);
113133
}
114134

115135
fn match_function(values: &[Box<dyn Value>]) -> Box<dyn Value> {
@@ -181,3 +201,18 @@ fn match_destructor_function(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
181201
let matcher = Box::new(IsDestructorMatcher);
182202
Box::new(FunctionMatcherValue::new(matcher))
183203
}
204+
205+
fn match_public_function(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
206+
let matcher = Box::new(AccessSpecifierMatcher::match_public());
207+
Box::new(FunctionMatcherValue::new(matcher))
208+
}
209+
210+
fn match_protected_function(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
211+
let matcher = Box::new(AccessSpecifierMatcher::match_protected());
212+
Box::new(FunctionMatcherValue::new(matcher))
213+
}
214+
215+
fn match_private_function(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
216+
let matcher = Box::new(AccessSpecifierMatcher::match_private());
217+
Box::new(FunctionMatcherValue::new(matcher))
218+
}

‎src/clang_ql/matchers/function.rs

+38-11
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@ use clang_sys::clang_CXXMethod_isConst;
66
use clang_sys::clang_CXXMethod_isPureVirtual;
77
use clang_sys::clang_CXXMethod_isStatic;
88
use clang_sys::clang_CXXMethod_isVirtual;
9+
use clang_sys::clang_getCXXAccessSpecifier;
910
use clang_sys::clang_getCursorKind;
1011
use clang_sys::CXCursor_CXXMethod;
1112
use clang_sys::CXCursor_Constructor;
1213
use clang_sys::CXCursor_Destructor;
14+
use clang_sys::CX_CXXAccessSpecifier;
15+
use clang_sys::CX_CXXPrivate;
16+
use clang_sys::CX_CXXProtected;
17+
use clang_sys::CX_CXXPublic;
1318

1419
use crate::clang_ql::values::FunctionNode;
1520

@@ -65,10 +70,7 @@ pub struct IsMethodMatcher;
6570

6671
impl FunctionMatcher for IsMethodMatcher {
6772
fn is_match(&self, function: &FunctionNode) -> bool {
68-
unsafe {
69-
let cursor_kind = clang_getCursorKind(function.cursor);
70-
cursor_kind == CXCursor_CXXMethod
71-
}
73+
unsafe { clang_getCursorKind(function.cursor) == CXCursor_CXXMethod }
7274
}
7375
}
7476

@@ -77,10 +79,7 @@ pub struct IsConstructorMatcher;
7779

7880
impl FunctionMatcher for IsConstructorMatcher {
7981
fn is_match(&self, function: &FunctionNode) -> bool {
80-
unsafe {
81-
let cursor_kind = clang_getCursorKind(function.cursor);
82-
cursor_kind == CXCursor_Constructor
83-
}
82+
unsafe { clang_getCursorKind(function.cursor) == CXCursor_Constructor }
8483
}
8584
}
8685

@@ -125,9 +124,37 @@ pub struct IsDestructorMatcher;
125124

126125
impl FunctionMatcher for IsDestructorMatcher {
127126
fn is_match(&self, function: &FunctionNode) -> bool {
128-
unsafe {
129-
let cursor_kind = clang_getCursorKind(function.cursor);
130-
cursor_kind == CXCursor_Destructor
127+
unsafe { clang_getCursorKind(function.cursor) == CXCursor_Destructor }
128+
}
129+
}
130+
131+
#[derive(Clone)]
132+
pub struct AccessSpecifierMatcher {
133+
access: CX_CXXAccessSpecifier,
134+
}
135+
136+
impl AccessSpecifierMatcher {
137+
pub fn match_public() -> Self {
138+
AccessSpecifierMatcher {
139+
access: CX_CXXPublic,
140+
}
141+
}
142+
143+
pub fn match_protected() -> Self {
144+
AccessSpecifierMatcher {
145+
access: CX_CXXProtected,
146+
}
147+
}
148+
149+
pub fn match_private() -> Self {
150+
AccessSpecifierMatcher {
151+
access: CX_CXXPrivate,
131152
}
132153
}
133154
}
155+
156+
impl FunctionMatcher for AccessSpecifierMatcher {
157+
fn is_match(&self, function: &FunctionNode) -> bool {
158+
unsafe { clang_getCXXAccessSpecifier(function.cursor) == self.access }
159+
}
160+
}

‎src/clang_ql/matchers/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use dyn_clone::DynClone;
33
use super::values::FunctionNode;
44

55
mod function;
6+
pub use function::AccessSpecifierMatcher;
67
pub use function::IsConstMethodMatcher;
78
pub use function::IsConstructorMatcher;
89
pub use function::IsConvertingConstructorMatcher;

0 commit comments

Comments
 (0)
Please sign in to comment.