Skip to content

Commit

Permalink
feat: Support query is_const attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
AmrDeveloper committed Apr 15, 2024
1 parent 6e77e48 commit 045d924
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ SELECT DISTINCT name AS function_name FROM functions
| is_virtual | Boolean | Return true if a C++ member function or member function template is explicitly declared 'virtual' or if it overrides a virtual method from one of the base classes |
| is_pure_virtual | Boolean | Return ture if a C++ member function or member function template is pure virtual. |
| is_static | Boolean | Return ture if a C++ member function is static. |
| is_const | Boolean | Return ture if a C++ member function is const. |
| has_template | Boolean | True if it's has template |

---
Expand Down
4 changes: 4 additions & 0 deletions src/clang_function_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub struct FunctionNode {
pub is_virtual: bool,
pub is_pure_virtual: bool,
pub is_static: bool,
pub is_const: bool,
pub has_template: bool,
}

Expand Down Expand Up @@ -86,6 +87,7 @@ extern "C" fn visit_children(
let mut is_virtual = false;
let mut is_pure_virtual = false;
let mut is_static = false;
let mut is_const = false;

if cursor_kind == CXCursor_CXXMethod {
is_method = true;
Expand All @@ -99,6 +101,7 @@ extern "C" fn visit_children(
is_virtual = clang_CXXMethod_isVirtual(cursor) != 0;
is_pure_virtual = clang_CXXMethod_isPureVirtual(cursor) != 0;
is_static = clang_CXXMethod_isStatic(cursor) != 0;
is_const = clang_CXXMethod_isConst(cursor) != 0;
}

functions.push(FunctionNode {
Expand All @@ -111,6 +114,7 @@ extern "C" fn visit_children(
is_virtual,
is_pure_virtual,
is_static,
is_const,
has_template,
});

Expand Down
6 changes: 6 additions & 0 deletions src/data_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use gitql_engine::data_provider::DataProvider;
use gitql_engine::engine_evaluator::evaluate_expression;

use crate::clang_function_visitor;

pub struct ClangAstDataProvider {
pub paths: Vec<String>,
}
Expand Down Expand Up @@ -145,6 +146,11 @@ fn select_functions(
continue;
}

if field_name == "is_const" {
values.push(Value::Boolean(function.is_const));
continue;
}

if field_name == "has_template" {
values.push(Value::Boolean(function.has_template));
continue;
Expand Down
2 changes: 2 additions & 0 deletions src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ lazy_static! {
map.insert("is_virtual", DataType::Boolean);
map.insert("is_pure_virtual", DataType::Boolean);
map.insert("is_static", DataType::Boolean);
map.insert("is_const", DataType::Boolean);
map.insert("has_template", DataType::Boolean);
map
};
Expand All @@ -34,6 +35,7 @@ lazy_static! {
"is_virtual",
"is_pure_virtual",
"is_static",
"is_const",
"has_template",
],
);
Expand Down

0 comments on commit 045d924

Please sign in to comment.