11use std:: collections:: HashMap ;
22
3+ use clang_sys:: clang_CXXMethod_isConst;
34use clang_sys:: clang_CXXMethod_isPureVirtual;
5+ use clang_sys:: clang_CXXMethod_isStatic;
46use clang_sys:: clang_CXXMethod_isVirtual;
7+ use clang_sys:: clang_getCursorKind;
8+ use clang_sys:: CXCursor_CXXMethod ;
59use gitql_ast:: types:: boolean:: BoolType ;
610use gitql_core:: signature:: Signature ;
711use gitql_core:: signature:: StandardFunction ;
@@ -14,7 +18,11 @@ use crate::clang_ql::values::FunctionValue;
1418#[ inline( always) ]
1519pub 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
3361fn 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