Skip to content

Commit 6102c9f

Browse files
committed
Implement is_static, is_const and is_deleted functions.
1 parent 85cb18b commit 6102c9f

File tree

2 files changed

+62
-3
lines changed

2 files changed

+62
-3
lines changed

docs/ASTFunctions.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@
33
| Function | Parameters | Return | Description |
44
| :-------------: | :----------------: | :----: | :----------------------------------: |
55
| is_virtual | (n : FunctionType) | Bool | True if the function is virtual |
6-
| is_pure_virtual | (n : FunctionType) | Bool | True if the function is pure virtual |
6+
| is_pure_virtual | (n : FunctionType) | Bool | True if the function is pure virtual |
7+
| is_method | (n : FunctionType) | Bool | True if the function is a method |
8+
| is_static | (n : FunctionType) | Bool | True if the function is static |
9+
| is_const | (n : FunctionType) | Bool | True if the function is const |
10+
| is_deleted | (n : FunctionType) | Bool | True if the function is deleted |

src/clang_ql/functions/ast/functions.rs

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
use std::collections::HashMap;
22

3+
use clang_sys::clang_CXXMethod_isConst;
34
use clang_sys::clang_CXXMethod_isPureVirtual;
5+
use clang_sys::clang_CXXMethod_isStatic;
46
use clang_sys::clang_CXXMethod_isVirtual;
7+
use clang_sys::clang_getCursorKind;
8+
use clang_sys::CXCursor_CXXMethod;
59
use gitql_ast::types::boolean::BoolType;
610
use gitql_core::signature::Signature;
711
use gitql_core::signature::StandardFunction;
@@ -14,7 +18,11 @@ use crate::clang_ql::values::FunctionValue;
1418
#[inline(always)]
1519
pub fn register_ast_function_functions(map: &mut HashMap<&'static str, StandardFunction>) {
1620
map.insert("is_virtual", function_is_virtual);
17-
map.insert("is_pure_virtual", is_pure_virtual);
21+
map.insert("is_pure_virtual", function_is_pure_virtual);
22+
map.insert("is_method", function_is_method);
23+
map.insert("is_static", function_is_static);
24+
map.insert("is_const", function_is_const);
25+
map.insert("is_deleted", function_is_deleted);
1826
}
1927

2028
#[inline(always)]
@@ -28,6 +36,26 @@ pub fn register_ast_function_signatures(map: &mut HashMap<&'static str, Signatur
2836
"is_pure_virtual",
2937
Signature::with_return(Box::new(BoolType)).add_parameter(Box::new(FunctionType)),
3038
);
39+
40+
map.insert(
41+
"is_method",
42+
Signature::with_return(Box::new(BoolType)).add_parameter(Box::new(FunctionType)),
43+
);
44+
45+
map.insert(
46+
"is_static",
47+
Signature::with_return(Box::new(BoolType)).add_parameter(Box::new(FunctionType)),
48+
);
49+
50+
map.insert(
51+
"is_const",
52+
Signature::with_return(Box::new(BoolType)).add_parameter(Box::new(FunctionType)),
53+
);
54+
55+
map.insert(
56+
"is_deleted",
57+
Signature::with_return(Box::new(BoolType)).add_parameter(Box::new(FunctionType)),
58+
);
3159
}
3260

3361
fn function_is_virtual(values: &[Box<dyn Value>]) -> Box<dyn Value> {
@@ -36,8 +64,35 @@ fn function_is_virtual(values: &[Box<dyn Value>]) -> Box<dyn Value> {
3664
Box::new(BoolValue::new(is_virtual))
3765
}
3866

39-
fn is_pure_virtual(values: &[Box<dyn Value>]) -> Box<dyn Value> {
67+
fn function_is_pure_virtual(values: &[Box<dyn Value>]) -> Box<dyn Value> {
4068
let ast_node = values[0].as_any().downcast_ref::<FunctionValue>().unwrap();
4169
let is_virtual = unsafe { clang_CXXMethod_isPureVirtual(ast_node.node.cursor) != 0 };
4270
Box::new(BoolValue::new(is_virtual))
4371
}
72+
73+
fn function_is_method(values: &[Box<dyn Value>]) -> Box<dyn Value> {
74+
let ast_node = values[0].as_any().downcast_ref::<FunctionValue>().unwrap();
75+
let is_virtual = unsafe {
76+
let cursor_kind = clang_getCursorKind(ast_node.node.cursor);
77+
cursor_kind == CXCursor_CXXMethod
78+
};
79+
Box::new(BoolValue::new(is_virtual))
80+
}
81+
82+
fn function_is_static(values: &[Box<dyn Value>]) -> Box<dyn Value> {
83+
let ast_node = values[0].as_any().downcast_ref::<FunctionValue>().unwrap();
84+
let is_virtual = unsafe { clang_CXXMethod_isStatic(ast_node.node.cursor) != 0 };
85+
Box::new(BoolValue::new(is_virtual))
86+
}
87+
88+
fn function_is_const(values: &[Box<dyn Value>]) -> Box<dyn Value> {
89+
let ast_node = values[0].as_any().downcast_ref::<FunctionValue>().unwrap();
90+
let is_virtual = unsafe { clang_CXXMethod_isConst(ast_node.node.cursor) != 0 };
91+
Box::new(BoolValue::new(is_virtual))
92+
}
93+
94+
fn function_is_deleted(values: &[Box<dyn Value>]) -> Box<dyn Value> {
95+
let ast_node = values[0].as_any().downcast_ref::<FunctionValue>().unwrap();
96+
let is_virtual = unsafe { clang_CXXMethod_isConst(ast_node.node.cursor) != 0 };
97+
Box::new(BoolValue::new(is_virtual))
98+
}

0 commit comments

Comments
 (0)