|
| 1 | +use std::collections::HashMap; |
| 2 | + |
| 3 | +use gitql_ast::types::boolean::BoolType; |
| 4 | +use gitql_core::signature::Signature; |
| 5 | +use gitql_core::signature::StandardFunction; |
| 6 | +use gitql_core::values::base::Value; |
| 7 | +use gitql_core::values::boolean::BoolValue; |
| 8 | + |
| 9 | +use crate::clang_ql::matchers::IsConstMethodMatcher; |
| 10 | +use crate::clang_ql::matchers::IsDeletedMethodMatcher; |
| 11 | +use crate::clang_ql::matchers::IsMethodMatcher; |
| 12 | +use crate::clang_ql::matchers::IsPureVirtualMatcher; |
| 13 | +use crate::clang_ql::matchers::IsStaticMethodMatcher; |
| 14 | +use crate::clang_ql::matchers::IsVirtualMatcher; |
| 15 | +use crate::clang_ql::types::FunctionMatcherType; |
| 16 | +use crate::clang_ql::types::FunctionType; |
| 17 | +use crate::clang_ql::values::FunctionMatcherValue; |
| 18 | +use crate::clang_ql::values::FunctionValue; |
| 19 | + |
| 20 | +#[inline(always)] |
| 21 | +pub(crate) fn register_function_matchers_functions( |
| 22 | + map: &mut HashMap<&'static str, StandardFunction>, |
| 23 | +) { |
| 24 | + map.insert("m_function", match_function); |
| 25 | + |
| 26 | + map.insert("m_virtual", match_virtual_function); |
| 27 | + map.insert("m_pure_virtual", match_pure_virtual_function); |
| 28 | + map.insert("m_static", match_static_function); |
| 29 | + map.insert("m_const", match_const_function); |
| 30 | + map.insert("m_deleted", match_deleted_function); |
| 31 | + map.insert("m_method", match_method_function); |
| 32 | +} |
| 33 | + |
| 34 | +#[inline(always)] |
| 35 | +pub(crate) fn register_function_matchers_signatures(map: &mut HashMap<&'static str, Signature>) { |
| 36 | + map.insert( |
| 37 | + "m_function", |
| 38 | + Signature::with_return(Box::new(BoolType)) |
| 39 | + .add_parameter(Box::new(FunctionType)) |
| 40 | + .add_parameter(Box::new(FunctionMatcherType)), |
| 41 | + ); |
| 42 | + |
| 43 | + map.insert( |
| 44 | + "m_virtual", |
| 45 | + Signature::with_return(Box::new(FunctionMatcherType)), |
| 46 | + ); |
| 47 | + |
| 48 | + map.insert( |
| 49 | + "m_pure_virtual", |
| 50 | + Signature::with_return(Box::new(FunctionMatcherType)), |
| 51 | + ); |
| 52 | + |
| 53 | + map.insert( |
| 54 | + "m_const", |
| 55 | + Signature::with_return(Box::new(FunctionMatcherType)), |
| 56 | + ); |
| 57 | + |
| 58 | + map.insert( |
| 59 | + "m_deleted", |
| 60 | + Signature::with_return(Box::new(FunctionMatcherType)), |
| 61 | + ); |
| 62 | + |
| 63 | + map.insert( |
| 64 | + "m_method", |
| 65 | + Signature::with_return(Box::new(FunctionMatcherType)), |
| 66 | + ); |
| 67 | +} |
| 68 | + |
| 69 | +fn match_function(values: &[Box<dyn Value>]) -> Box<dyn Value> { |
| 70 | + let function_node = values[0].as_any().downcast_ref::<FunctionValue>().unwrap(); |
| 71 | + let function_matcher = values[1] |
| 72 | + .as_any() |
| 73 | + .downcast_ref::<FunctionMatcherValue>() |
| 74 | + .unwrap(); |
| 75 | + let is_matches = function_matcher.matcher.is_match(&function_node.node); |
| 76 | + Box::new(BoolValue::new(is_matches)) |
| 77 | +} |
| 78 | + |
| 79 | +fn match_virtual_function(_values: &[Box<dyn Value>]) -> Box<dyn Value> { |
| 80 | + let matcher = Box::new(IsVirtualMatcher); |
| 81 | + Box::new(FunctionMatcherValue::new(matcher)) |
| 82 | +} |
| 83 | + |
| 84 | +fn match_pure_virtual_function(_values: &[Box<dyn Value>]) -> Box<dyn Value> { |
| 85 | + let matcher = Box::new(IsPureVirtualMatcher); |
| 86 | + Box::new(FunctionMatcherValue::new(matcher)) |
| 87 | +} |
| 88 | + |
| 89 | +fn match_static_function(_values: &[Box<dyn Value>]) -> Box<dyn Value> { |
| 90 | + let matcher = Box::new(IsStaticMethodMatcher); |
| 91 | + Box::new(FunctionMatcherValue::new(matcher)) |
| 92 | +} |
| 93 | + |
| 94 | +fn match_const_function(_values: &[Box<dyn Value>]) -> Box<dyn Value> { |
| 95 | + let matcher = Box::new(IsConstMethodMatcher); |
| 96 | + Box::new(FunctionMatcherValue::new(matcher)) |
| 97 | +} |
| 98 | + |
| 99 | +fn match_deleted_function(_values: &[Box<dyn Value>]) -> Box<dyn Value> { |
| 100 | + let matcher = Box::new(IsDeletedMethodMatcher); |
| 101 | + Box::new(FunctionMatcherValue::new(matcher)) |
| 102 | +} |
| 103 | + |
| 104 | +fn match_method_function(_values: &[Box<dyn Value>]) -> Box<dyn Value> { |
| 105 | + let matcher = Box::new(IsMethodMatcher); |
| 106 | + Box::new(FunctionMatcherValue::new(matcher)) |
| 107 | +} |
0 commit comments