Skip to content

Commit 86a6e5c

Browse files
committed
Implement m_default_constructor, m_copy_destructor, m_move_destructor matchers functions
1 parent b649e8a commit 86a6e5c

File tree

6 files changed

+167
-1
lines changed

6 files changed

+167
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ gitql-cli = "0.35.0"
1919
gitql-ast = "0.31.0"
2020
gitql-parser = "0.34.0"
2121
gitql-engine = "0.35.0"
22-
clang-sys = "1.8.1"
22+
clang-sys = { version = "1.8.1", features = ["clang_16_0"] }
2323
dyn-clone = "1.0.17"

docs/MatcherFunctions.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
### AST matchers functions
2+
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 |

src/clang_ql/functions/matchers/function.rs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@ use gitql_core::values::base::Value;
77
use gitql_core::values::boolean::BoolValue;
88

99
use crate::clang_ql::matchers::IsConstMethodMatcher;
10+
use crate::clang_ql::matchers::IsConstructorMatcher;
11+
use crate::clang_ql::matchers::IsConvertingConstructorMatcher;
12+
use crate::clang_ql::matchers::IsCopyConstructorMatcher;
13+
use crate::clang_ql::matchers::IsDefaultConstructorMatcher;
1014
use crate::clang_ql::matchers::IsDeletedMethodMatcher;
15+
use crate::clang_ql::matchers::IsDestructorMatcher;
1116
use crate::clang_ql::matchers::IsMethodMatcher;
17+
use crate::clang_ql::matchers::IsMoveConstructorMatcher;
1218
use crate::clang_ql::matchers::IsPureVirtualMatcher;
1319
use crate::clang_ql::matchers::IsStaticMethodMatcher;
1420
use crate::clang_ql::matchers::IsVirtualMatcher;
@@ -29,6 +35,16 @@ pub(crate) fn register_function_matchers_functions(
2935
map.insert("m_const", match_const_function);
3036
map.insert("m_deleted", match_deleted_function);
3137
map.insert("m_method", match_method_function);
38+
39+
map.insert("m_constructor", match_constructor_function);
40+
map.insert("m_default_constructor", match_default_constructor_function);
41+
map.insert("m_copy_constructor", match_copy_constructor_function);
42+
map.insert("m_move_constructor", match_move_constructor_function);
43+
map.insert(
44+
"m_converting_constructor",
45+
match_converting_constructor_function,
46+
);
47+
map.insert("m_destructor", match_destructor_function);
3248
}
3349

3450
#[inline(always)]
@@ -64,6 +80,36 @@ pub(crate) fn register_function_matchers_signatures(map: &mut HashMap<&'static s
6480
"m_method",
6581
Signature::with_return(Box::new(FunctionMatcherType)),
6682
);
83+
84+
map.insert(
85+
"m_constructor",
86+
Signature::with_return(Box::new(FunctionMatcherType)),
87+
);
88+
89+
map.insert(
90+
"m_default_constructor",
91+
Signature::with_return(Box::new(FunctionMatcherType)),
92+
);
93+
94+
map.insert(
95+
"m_copy_constructor",
96+
Signature::with_return(Box::new(FunctionMatcherType)),
97+
);
98+
99+
map.insert(
100+
"m_move_constructor",
101+
Signature::with_return(Box::new(FunctionMatcherType)),
102+
);
103+
104+
map.insert(
105+
"m_converting_constructor",
106+
Signature::with_return(Box::new(FunctionMatcherType)),
107+
);
108+
109+
map.insert(
110+
"m_destructor",
111+
Signature::with_return(Box::new(FunctionMatcherType)),
112+
);
67113
}
68114

69115
fn match_function(values: &[Box<dyn Value>]) -> Box<dyn Value> {
@@ -105,3 +151,33 @@ fn match_method_function(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
105151
let matcher = Box::new(IsMethodMatcher);
106152
Box::new(FunctionMatcherValue::new(matcher))
107153
}
154+
155+
fn match_constructor_function(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
156+
let matcher = Box::new(IsConstructorMatcher);
157+
Box::new(FunctionMatcherValue::new(matcher))
158+
}
159+
160+
fn match_copy_constructor_function(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
161+
let matcher = Box::new(IsCopyConstructorMatcher);
162+
Box::new(FunctionMatcherValue::new(matcher))
163+
}
164+
165+
fn match_move_constructor_function(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
166+
let matcher = Box::new(IsMoveConstructorMatcher);
167+
Box::new(FunctionMatcherValue::new(matcher))
168+
}
169+
170+
fn match_default_constructor_function(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
171+
let matcher = Box::new(IsDefaultConstructorMatcher);
172+
Box::new(FunctionMatcherValue::new(matcher))
173+
}
174+
175+
fn match_converting_constructor_function(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
176+
let matcher = Box::new(IsConvertingConstructorMatcher);
177+
Box::new(FunctionMatcherValue::new(matcher))
178+
}
179+
180+
fn match_destructor_function(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
181+
let matcher = Box::new(IsDestructorMatcher);
182+
Box::new(FunctionMatcherValue::new(matcher))
183+
}

src/clang_ql/matchers/function.rs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
use clang_sys::clang_CXXConstructor_isConvertingConstructor;
2+
use clang_sys::clang_CXXConstructor_isCopyConstructor;
3+
use clang_sys::clang_CXXConstructor_isDefaultConstructor;
4+
use clang_sys::clang_CXXConstructor_isMoveConstructor;
15
use clang_sys::clang_CXXMethod_isConst;
26
use clang_sys::clang_CXXMethod_isPureVirtual;
37
use clang_sys::clang_CXXMethod_isStatic;
48
use clang_sys::clang_CXXMethod_isVirtual;
59
use clang_sys::clang_getCursorKind;
610
use clang_sys::CXCursor_CXXMethod;
11+
use clang_sys::CXCursor_Constructor;
12+
use clang_sys::CXCursor_Destructor;
713

814
use crate::clang_ql::values::FunctionNode;
915

@@ -65,3 +71,63 @@ impl FunctionMatcher for IsMethodMatcher {
6571
}
6672
}
6773
}
74+
75+
#[derive(Clone)]
76+
pub struct IsConstructorMatcher;
77+
78+
impl FunctionMatcher for IsConstructorMatcher {
79+
fn is_match(&self, function: &FunctionNode) -> bool {
80+
unsafe {
81+
let cursor_kind = clang_getCursorKind(function.cursor);
82+
cursor_kind == CXCursor_Constructor
83+
}
84+
}
85+
}
86+
87+
#[derive(Clone)]
88+
pub struct IsDefaultConstructorMatcher;
89+
90+
impl FunctionMatcher for IsDefaultConstructorMatcher {
91+
fn is_match(&self, function: &FunctionNode) -> bool {
92+
unsafe { clang_CXXConstructor_isDefaultConstructor(function.cursor) != 0 }
93+
}
94+
}
95+
96+
#[derive(Clone)]
97+
pub struct IsCopyConstructorMatcher;
98+
99+
impl FunctionMatcher for IsCopyConstructorMatcher {
100+
fn is_match(&self, function: &FunctionNode) -> bool {
101+
unsafe { clang_CXXConstructor_isCopyConstructor(function.cursor) != 0 }
102+
}
103+
}
104+
105+
#[derive(Clone)]
106+
pub struct IsMoveConstructorMatcher;
107+
108+
impl FunctionMatcher for IsMoveConstructorMatcher {
109+
fn is_match(&self, function: &FunctionNode) -> bool {
110+
unsafe { clang_CXXConstructor_isMoveConstructor(function.cursor) != 0 }
111+
}
112+
}
113+
114+
#[derive(Clone)]
115+
pub struct IsConvertingConstructorMatcher;
116+
117+
impl FunctionMatcher for IsConvertingConstructorMatcher {
118+
fn is_match(&self, function: &FunctionNode) -> bool {
119+
unsafe { clang_CXXConstructor_isConvertingConstructor(function.cursor) != 0 }
120+
}
121+
}
122+
123+
#[derive(Clone)]
124+
pub struct IsDestructorMatcher;
125+
126+
impl FunctionMatcher for IsDestructorMatcher {
127+
fn is_match(&self, function: &FunctionNode) -> bool {
128+
unsafe {
129+
let cursor_kind = clang_getCursorKind(function.cursor);
130+
cursor_kind == CXCursor_Destructor
131+
}
132+
}
133+
}

src/clang_ql/matchers/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@ use super::values::FunctionNode;
44

55
mod function;
66
pub use function::IsConstMethodMatcher;
7+
pub use function::IsConstructorMatcher;
8+
pub use function::IsConvertingConstructorMatcher;
9+
pub use function::IsCopyConstructorMatcher;
10+
pub use function::IsDefaultConstructorMatcher;
711
pub use function::IsDeletedMethodMatcher;
12+
pub use function::IsDestructorMatcher;
813
pub use function::IsMethodMatcher;
14+
pub use function::IsMoveConstructorMatcher;
915
pub use function::IsPureVirtualMatcher;
1016
pub use function::IsStaticMethodMatcher;
1117
pub use function::IsVirtualMatcher;

src/clang_ql/visitors/function.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ extern "C" fn visit_children(
3434
if cursor_kind == CXCursor_FunctionDecl
3535
|| cursor_kind == CXCursor_CXXMethod
3636
|| cursor_kind == CXCursor_FunctionTemplate
37+
|| cursor_kind == CXCursor_Constructor
38+
|| cursor_kind == CXCursor_Destructor
3739
{
3840
let functions = &mut *(data as *mut Vec<FunctionNode>);
3941

0 commit comments

Comments
 (0)