Skip to content

Commit

Permalink
Implement m_public, m_protected and m_private matchers functions
Browse files Browse the repository at this point in the history
  • Loading branch information
AmrDeveloper committed Jan 12, 2025
1 parent 08d248a commit 86c39f2
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 25 deletions.
31 changes: 17 additions & 14 deletions docs/MatcherFunctions.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
### AST matchers functions

| Function | Parameters | Return | Description |
| :----------------------: | :--------: | :-------------: | :---------------------------------------------------------------: |
| m_virtual | () | FunctionMatcher | Create Matcher to check if the function is virtual |
| m_pure_virtual | () | FunctionMatcher | Create Matcher to check if the function is pure virtual |
| m_method | () | FunctionMatcher | Create Matcher to check if the function is a method |
| m_static | () | FunctionMatcher | Create Matcher to check if the function is static |
| m_const | () | FunctionMatcher | Create Matcher to check if the function is const |
| m_deleted | () | FunctionMatcher | Create Matcher to check if the function is deleted |
| m_constructor | () | FunctionMatcher | Create Matcher to check if the function is constructor |
| m_default_constructor | () | FunctionMatcher | Create Matcher to check if the function is default constructor |
| m_copy_constructor | () | FunctionMatcher | Create Matcher to check if the function is copy constructor |
| m_move_constructor | () | FunctionMatcher | Create Matcher to check if the function is move constructor |
| m_converting_constructor | () | FunctionMatcher | Create Matcher to check if the function is converting constructor |
| m_destructor | () | FunctionMatcher | Create Matcher to check if the function is destructor |
| Function | Parameters | Return | Description |
| :----------------------: | :--------: | :-------------: | :--------------------------------------------: |
| m_virtual | () | FunctionMatcher | Create Matcher to match virtual function |
| m_pure_virtual | () | FunctionMatcher | Create Matcher to match pure virtual function |
| m_method | () | FunctionMatcher | Create Matcher to match method |
| m_static | () | FunctionMatcher | Create Matcher to match static function |
| m_const | () | FunctionMatcher | Create Matcher to match const function |
| m_deleted | () | FunctionMatcher | Create Matcher to match deleted function |
| m_constructor | () | FunctionMatcher | Create Matcher to match constructor |
| m_default_constructor | () | FunctionMatcher | Create Matcher to match default constructor |
| m_copy_constructor | () | FunctionMatcher | Create Matcher to match copy constructor |
| m_move_constructor | () | FunctionMatcher | Create Matcher to match move constructor |
| m_converting_constructor | () | FunctionMatcher | Create Matcher to match converting constructor |
| m_destructor | () | FunctionMatcher | Create Matcher to match function is destructor |
| m_public | () | FunctionMatcher | Create Matcher to match public function |
| m_protected | () | FunctionMatcher | Create Matcher to match protected function |
| m_private | () | FunctionMatcher | Create Matcher to match private function |
35 changes: 35 additions & 0 deletions src/clang_ql/functions/matchers/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use gitql_core::signature::StandardFunction;
use gitql_core::values::base::Value;
use gitql_core::values::boolean::BoolValue;

use crate::clang_ql::matchers::AccessSpecifierMatcher;
use crate::clang_ql::matchers::IsConstMethodMatcher;
use crate::clang_ql::matchers::IsConstructorMatcher;
use crate::clang_ql::matchers::IsConvertingConstructorMatcher;
Expand Down Expand Up @@ -45,6 +46,10 @@ pub(crate) fn register_function_matchers_functions(
match_converting_constructor_function,
);
map.insert("m_destructor", match_destructor_function);

map.insert("m_public", match_public_function);
map.insert("m_protected", match_protected_function);
map.insert("m_private", match_private_function);
}

#[inline(always)]
Expand Down Expand Up @@ -110,6 +115,21 @@ pub(crate) fn register_function_matchers_signatures(map: &mut HashMap<&'static s
"m_destructor",
Signature::with_return(Box::new(FunctionMatcherType)),
);

map.insert(
"m_public",
Signature::with_return(Box::new(FunctionMatcherType)),
);

map.insert(
"m_protected",
Signature::with_return(Box::new(FunctionMatcherType)),
);

map.insert(
"m_private",
Signature::with_return(Box::new(FunctionMatcherType)),
);
}

fn match_function(values: &[Box<dyn Value>]) -> Box<dyn Value> {
Expand Down Expand Up @@ -181,3 +201,18 @@ fn match_destructor_function(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
let matcher = Box::new(IsDestructorMatcher);
Box::new(FunctionMatcherValue::new(matcher))
}

fn match_public_function(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
let matcher = Box::new(AccessSpecifierMatcher::match_public());
Box::new(FunctionMatcherValue::new(matcher))
}

fn match_protected_function(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
let matcher = Box::new(AccessSpecifierMatcher::match_protected());
Box::new(FunctionMatcherValue::new(matcher))
}

fn match_private_function(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
let matcher = Box::new(AccessSpecifierMatcher::match_private());
Box::new(FunctionMatcherValue::new(matcher))
}
49 changes: 38 additions & 11 deletions src/clang_ql/matchers/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ use clang_sys::clang_CXXMethod_isConst;
use clang_sys::clang_CXXMethod_isPureVirtual;
use clang_sys::clang_CXXMethod_isStatic;
use clang_sys::clang_CXXMethod_isVirtual;
use clang_sys::clang_getCXXAccessSpecifier;
use clang_sys::clang_getCursorKind;
use clang_sys::CXCursor_CXXMethod;
use clang_sys::CXCursor_Constructor;
use clang_sys::CXCursor_Destructor;
use clang_sys::CX_CXXAccessSpecifier;
use clang_sys::CX_CXXPrivate;
use clang_sys::CX_CXXProtected;
use clang_sys::CX_CXXPublic;

use crate::clang_ql::values::FunctionNode;

Expand Down Expand Up @@ -65,10 +70,7 @@ pub struct IsMethodMatcher;

impl FunctionMatcher for IsMethodMatcher {
fn is_match(&self, function: &FunctionNode) -> bool {
unsafe {
let cursor_kind = clang_getCursorKind(function.cursor);
cursor_kind == CXCursor_CXXMethod
}
unsafe { clang_getCursorKind(function.cursor) == CXCursor_CXXMethod }
}
}

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

impl FunctionMatcher for IsConstructorMatcher {
fn is_match(&self, function: &FunctionNode) -> bool {
unsafe {
let cursor_kind = clang_getCursorKind(function.cursor);
cursor_kind == CXCursor_Constructor
}
unsafe { clang_getCursorKind(function.cursor) == CXCursor_Constructor }
}
}

Expand Down Expand Up @@ -125,9 +124,37 @@ pub struct IsDestructorMatcher;

impl FunctionMatcher for IsDestructorMatcher {
fn is_match(&self, function: &FunctionNode) -> bool {
unsafe {
let cursor_kind = clang_getCursorKind(function.cursor);
cursor_kind == CXCursor_Destructor
unsafe { clang_getCursorKind(function.cursor) == CXCursor_Destructor }
}
}

#[derive(Clone)]
pub struct AccessSpecifierMatcher {
access: CX_CXXAccessSpecifier,
}

impl AccessSpecifierMatcher {
pub fn match_public() -> Self {
AccessSpecifierMatcher {
access: CX_CXXPublic,
}
}

pub fn match_protected() -> Self {
AccessSpecifierMatcher {
access: CX_CXXProtected,
}
}

pub fn match_private() -> Self {
AccessSpecifierMatcher {
access: CX_CXXPrivate,
}
}
}

impl FunctionMatcher for AccessSpecifierMatcher {
fn is_match(&self, function: &FunctionNode) -> bool {
unsafe { clang_getCXXAccessSpecifier(function.cursor) == self.access }
}
}
1 change: 1 addition & 0 deletions src/clang_ql/matchers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use dyn_clone::DynClone;
use super::values::FunctionNode;

mod function;
pub use function::AccessSpecifierMatcher;
pub use function::IsConstMethodMatcher;
pub use function::IsConstructorMatcher;
pub use function::IsConvertingConstructorMatcher;
Expand Down

0 comments on commit 86c39f2

Please sign in to comment.