-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restructure the tables to allow more customizations
- Loading branch information
1 parent
9400824
commit 85cb18b
Showing
15 changed files
with
205 additions
and
127 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,4 @@ gitql-ast = "0.31.0" | |
gitql-parser = "0.34.0" | ||
gitql-engine = "0.35.0" | ||
clang-sys = "1.8.1" | ||
dyn-clone = "1.0.17" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
### AST function node functions | ||
|
||
| Function | Parameters | Return | Description | | ||
| :-------------: | :----------------: | :----: | :----------------------------------: | | ||
| is_virtual | (n : FunctionType) | Bool | True if the function is virtual | | ||
| is_pure_virtual | (n : FunctionType) | Bool | True if the function is pure virtual | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use std::collections::HashMap; | ||
|
||
use clang_sys::clang_CXXMethod_isPureVirtual; | ||
use clang_sys::clang_CXXMethod_isVirtual; | ||
use gitql_ast::types::boolean::BoolType; | ||
use gitql_core::signature::Signature; | ||
use gitql_core::signature::StandardFunction; | ||
use gitql_core::values::base::Value; | ||
use gitql_core::values::boolean::BoolValue; | ||
|
||
use crate::clang_ql::types::FunctionType; | ||
use crate::clang_ql::values::FunctionValue; | ||
|
||
#[inline(always)] | ||
pub fn register_ast_function_functions(map: &mut HashMap<&'static str, StandardFunction>) { | ||
map.insert("is_virtual", function_is_virtual); | ||
map.insert("is_pure_virtual", is_pure_virtual); | ||
} | ||
|
||
#[inline(always)] | ||
pub fn register_ast_function_signatures(map: &mut HashMap<&'static str, Signature>) { | ||
map.insert( | ||
"is_virtual", | ||
Signature::with_return(Box::new(BoolType)).add_parameter(Box::new(FunctionType)), | ||
); | ||
|
||
map.insert( | ||
"is_pure_virtual", | ||
Signature::with_return(Box::new(BoolType)).add_parameter(Box::new(FunctionType)), | ||
); | ||
} | ||
|
||
fn function_is_virtual(values: &[Box<dyn Value>]) -> Box<dyn Value> { | ||
let ast_node = values[0].as_any().downcast_ref::<FunctionValue>().unwrap(); | ||
let is_virtual = unsafe { clang_CXXMethod_isVirtual(ast_node.node.cursor) != 0 }; | ||
Box::new(BoolValue::new(is_virtual)) | ||
} | ||
|
||
fn is_pure_virtual(values: &[Box<dyn Value>]) -> Box<dyn Value> { | ||
let ast_node = values[0].as_any().downcast_ref::<FunctionValue>().unwrap(); | ||
let is_virtual = unsafe { clang_CXXMethod_isPureVirtual(ast_node.node.cursor) != 0 }; | ||
Box::new(BoolValue::new(is_virtual)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
mod functions; | ||
use functions::register_ast_function_functions; | ||
use functions::register_ast_function_signatures; | ||
|
||
use std::collections::HashMap; | ||
|
||
use gitql_core::signature::Signature; | ||
use gitql_core::signature::StandardFunction; | ||
|
||
#[inline(always)] | ||
pub fn register_ast_functions(map: &mut HashMap<&'static str, StandardFunction>) { | ||
register_ast_function_functions(map); | ||
} | ||
|
||
#[inline(always)] | ||
pub fn register_ast_signatures(map: &mut HashMap<&'static str, Signature>) { | ||
register_ast_function_signatures(map); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use std::collections::HashMap; | ||
use std::sync::OnceLock; | ||
|
||
use gitql_core::signature::Signature; | ||
use gitql_core::signature::StandardFunction; | ||
use gitql_std::standard::standard_function_signatures; | ||
use gitql_std::standard::standard_functions; | ||
|
||
mod ast; | ||
|
||
#[inline(always)] | ||
pub fn clang_ql_functions() -> &'static HashMap<&'static str, StandardFunction> { | ||
static HASHMAP: OnceLock<HashMap<&'static str, StandardFunction>> = OnceLock::new(); | ||
HASHMAP.get_or_init(|| { | ||
let mut map = standard_functions().to_owned(); | ||
ast::register_ast_functions(&mut map); | ||
map | ||
}) | ||
} | ||
|
||
#[inline(always)] | ||
pub fn clang_ql_functions_signatures() -> HashMap<&'static str, Signature> { | ||
let mut map = standard_function_signatures().to_owned(); | ||
ast::register_ast_signatures(&mut map); | ||
map | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use dyn_clone::DynClone; | ||
|
||
use super::values::FunctionNode; | ||
|
||
dyn_clone::clone_trait_object!(FunctionMatcher); | ||
|
||
pub trait FunctionMatcher: DynClone { | ||
fn is_match(&self, function: FunctionNode) -> bool; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use std::any::Any; | ||
|
||
use gitql_ast::types::base::DataType; | ||
|
||
#[derive(Clone)] | ||
pub struct FunctionType; | ||
|
||
impl DataType for FunctionType { | ||
fn literal(&self) -> String { | ||
"Function".to_string() | ||
} | ||
|
||
#[allow(clippy::borrowed_box)] | ||
fn equals(&self, other: &Box<dyn DataType>) -> bool { | ||
let self_type: Box<dyn DataType> = Box::new(FunctionType); | ||
other.is_any() | ||
|| other.is_variant_contains(&self_type) | ||
|| other.as_any().downcast_ref::<FunctionType>().is_some() | ||
} | ||
|
||
fn as_any(&self) -> &dyn Any { | ||
self | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
mod source_location; | ||
pub use source_location::SourceLocType; | ||
|
||
mod function; | ||
pub use function::FunctionType; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use clang_sys::CXCursor; | ||
use gitql_core::values::base::Value; | ||
|
||
use crate::clang_ql::types::FunctionType; | ||
|
||
use super::FileLocation; | ||
|
||
#[derive(Clone)] | ||
pub struct FunctionNode { | ||
pub name: String, | ||
pub cursor: CXCursor, | ||
pub parent: CXCursor, | ||
pub signature: String, | ||
pub return_type: String, | ||
pub location: FileLocation, | ||
} | ||
|
||
#[derive(Clone)] | ||
pub struct FunctionValue { | ||
pub node: FunctionNode, | ||
} | ||
|
||
impl FunctionValue { | ||
pub fn new(node: FunctionNode) -> Self { | ||
FunctionValue { node } | ||
} | ||
} | ||
|
||
impl Value for FunctionValue { | ||
fn literal(&self) -> String { | ||
self.node.signature.to_string() | ||
} | ||
|
||
fn equals(&self, other: &Box<dyn Value>) -> bool { | ||
if let Some(other_fun) = other.as_any().downcast_ref::<FunctionValue>() { | ||
return self.node.name.eq(&other_fun.node.name) | ||
&& self.node.signature.eq(&other_fun.node.signature) | ||
&& self.node.return_type.eq(&other_fun.node.return_type) | ||
&& self.node.location.eq(&other_fun.node.location); | ||
} | ||
false | ||
} | ||
|
||
fn compare(&self, _other: &Box<dyn Value>) -> Option<std::cmp::Ordering> { | ||
None | ||
} | ||
|
||
fn data_type(&self) -> Box<dyn gitql_ast::types::base::DataType> { | ||
Box::new(FunctionType) | ||
} | ||
|
||
fn as_any(&self) -> &dyn std::any::Any { | ||
self | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
mod source_location; | ||
pub use source_location::FileLocation; | ||
pub use source_location::SourceLocValue; | ||
|
||
mod function; | ||
pub use function::FunctionNode; | ||
pub use function::FunctionValue; |
Oops, something went wrong.