Skip to content

Commit

Permalink
feat: Implement m_template_function function matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
AmrDeveloper committed Jan 28, 2025
1 parent a4e7b43 commit 2095a8d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/MatcherFunctions.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

| Function | Parameters | Return | Description |
| :----------------------: | :--------: | :-------------: | :--------------------------------------------: |
| m_template_function | () | FunctionMatcher | Create Matcher to match template function |
| 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 |
Expand Down
12 changes: 12 additions & 0 deletions src/clang_ql/functions/matchers/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::clang_ql::matchers::IsMethodMatcher;
use crate::clang_ql::matchers::IsMoveConstructorMatcher;
use crate::clang_ql::matchers::IsPureVirtualMatcher;
use crate::clang_ql::matchers::IsStaticMethodMatcher;
use crate::clang_ql::matchers::IsTemplateFunction;
use crate::clang_ql::matchers::IsVirtualMatcher;
use crate::clang_ql::types::FunctionMatcherType;
use crate::clang_ql::types::FunctionType;
Expand All @@ -30,6 +31,7 @@ pub(crate) fn register_function_matchers_functions(
) {
map.insert("m_function", match_function);

map.insert("m_template_function", match_template_function);
map.insert("m_virtual", match_virtual_function);
map.insert("m_pure_virtual", match_pure_virtual_function);
map.insert("m_static", match_static_function);
Expand Down Expand Up @@ -61,6 +63,11 @@ pub(crate) fn register_function_matchers_signatures(map: &mut HashMap<&'static s
.add_parameter(Box::new(FunctionMatcherType)),
);

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

map.insert(
"m_virtual",
Signature::with_return(Box::new(FunctionMatcherType)),
Expand Down Expand Up @@ -142,6 +149,11 @@ fn match_function(values: &[Box<dyn Value>]) -> Box<dyn Value> {
Box::new(BoolValue::new(is_matches))
}

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

fn match_virtual_function(_values: &[Box<dyn Value>]) -> Box<dyn Value> {
let matcher = Box::new(IsVirtualMatcher);
Box::new(FunctionMatcherValue::new(matcher))
Expand Down
10 changes: 10 additions & 0 deletions src/clang_ql/matchers/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use clang_sys::clang_getCursorKind;
use clang_sys::CXCursor_CXXMethod;
use clang_sys::CXCursor_Constructor;
use clang_sys::CXCursor_Destructor;
use clang_sys::CXCursor_FunctionTemplate;
use clang_sys::CX_CXXAccessSpecifier;
use clang_sys::CX_CXXPrivate;
use clang_sys::CX_CXXProtected;
Expand All @@ -20,6 +21,15 @@ use crate::clang_ql::values::FunctionNode;

use super::Matcher;

#[derive(Clone)]
pub struct IsTemplateFunction;

impl Matcher<FunctionNode> for IsTemplateFunction {
fn is_match(&self, function: &FunctionNode) -> bool {
unsafe { clang_getCursorKind(function.cursor) == CXCursor_FunctionTemplate }
}
}

#[derive(Clone)]
pub struct IsVirtualMatcher;

Expand Down
1 change: 1 addition & 0 deletions src/clang_ql/matchers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub use function::IsMethodMatcher;
pub use function::IsMoveConstructorMatcher;
pub use function::IsPureVirtualMatcher;
pub use function::IsStaticMethodMatcher;
pub use function::IsTemplateFunction;
pub use function::IsVirtualMatcher;

mod combine;
Expand Down

0 comments on commit 2095a8d

Please sign in to comment.