Skip to content

Commit

Permalink
feat: Support query type literal for enum constants
Browse files Browse the repository at this point in the history
  • Loading branch information
AmrDeveloper committed May 6, 2024
1 parent e0de3db commit 8c349ba
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ SELECT * FROM globals WHERE is_volatile
| --------------- | ------- | -------------------------------- |
| name | Text | Enumeration name |
| constants_count | Integer | Number of constants in this enum |
| type_literal | Text | Type literal for enum constants |
| file | Text | File path |
| line | Integer | Line at the file path |
| column | Integer | Column at the file path |
Expand Down
5 changes: 5 additions & 0 deletions src/data_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ fn select_enumss(
continue;
}

if field_name == "type_literal" {
values.push(Value::Text(enumeration.type_literal.to_string()));
continue;
}

if field_name == "file" {
values.push(Value::Text(enumeration.location.file.to_string()));
continue;
Expand Down
21 changes: 16 additions & 5 deletions src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,24 @@ lazy_static! {
map.insert("name", DataType::Text);
map.insert("type", DataType::Text);
map.insert("signature", DataType::Text);
map.insert("args_count", DataType::Integer);
map.insert("return_type", DataType::Text);
map.insert("class_name", DataType::Text);

map.insert("access_modifier", DataType::Integer);

map.insert("is_method", DataType::Boolean);
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.insert("access_modifier", DataType::Integer);
map.insert("is_variadic", DataType::Boolean);
map.insert("is_volatile", DataType::Boolean);
map.insert("is_struct", DataType::Boolean);
map.insert("has_template", DataType::Boolean);

map.insert("return_type", DataType::Text);
map.insert("type_literal", DataType::Text);

map.insert("args_count", DataType::Integer);
map.insert("bases_count", DataType::Integer);
map.insert("methods_count", DataType::Integer);
map.insert("fields_count", DataType::Integer);
Expand Down Expand Up @@ -54,7 +58,14 @@ lazy_static! {
);
map.insert(
"enums",
vec!["name", "constants_count", "line", "column", "offset"],
vec![
"name",
"constants_count",
"type_literal",
"line",
"column",
"offset",
],
);
map.insert(
"functions",
Expand Down
9 changes: 8 additions & 1 deletion src/visitor/enumeration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::visitor::location;

pub struct EnumNode {
pub name: String,
pub type_literal: String,
pub attributes: EnumAttributes,
pub location: location::SourceLocation,
}
Expand Down Expand Up @@ -65,19 +66,25 @@ extern "C" fn visit_enum_declaration(

let location = location::visit_source_location(cursor);

let enums = &mut *(data as *mut Vec<EnumNode>);
let enum_type = clang_getEnumDeclIntegerType(cursor);
let enum_type_spelling = clang_getTypeSpelling(enum_type);
let type_literal =
CStr::from_ptr(clang_getCString(enum_type_spelling)).to_string_lossy();

let mut attributes = EnumAttributes::default();
let attributes_pointer = &mut attributes as *mut EnumAttributes as *mut c_void;
clang_visitChildren(cursor, visit_enum_attributes, attributes_pointer);

let enums: &mut Vec<EnumNode> = &mut *(data as *mut Vec<EnumNode>);
enums.push(EnumNode {
name: enum_name.to_string(),
type_literal: type_literal.to_string(),
attributes,
location,
});

clang_disposeString(cursor_name);
clang_disposeString(enum_type_spelling);
return CXChildVisit_Continue;
}
}
Expand Down

0 comments on commit 8c349ba

Please sign in to comment.