Skip to content

Commit 8c349ba

Browse files
committed
feat: Support query type literal for enum constants
1 parent e0de3db commit 8c349ba

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ SELECT * FROM globals WHERE is_volatile
7171
| --------------- | ------- | -------------------------------- |
7272
| name | Text | Enumeration name |
7373
| constants_count | Integer | Number of constants in this enum |
74+
| type_literal | Text | Type literal for enum constants |
7475
| file | Text | File path |
7576
| line | Integer | Line at the file path |
7677
| column | Integer | Column at the file path |

src/data_provider.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,11 @@ fn select_enumss(
202202
continue;
203203
}
204204

205+
if field_name == "type_literal" {
206+
values.push(Value::Text(enumeration.type_literal.to_string()));
207+
continue;
208+
}
209+
205210
if field_name == "file" {
206211
values.push(Value::Text(enumeration.location.file.to_string()));
207212
continue;

src/schema.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,24 @@ lazy_static! {
88
map.insert("name", DataType::Text);
99
map.insert("type", DataType::Text);
1010
map.insert("signature", DataType::Text);
11-
map.insert("args_count", DataType::Integer);
12-
map.insert("return_type", DataType::Text);
1311
map.insert("class_name", DataType::Text);
12+
13+
map.insert("access_modifier", DataType::Integer);
14+
1415
map.insert("is_method", DataType::Boolean);
1516
map.insert("is_virtual", DataType::Boolean);
1617
map.insert("is_pure_virtual", DataType::Boolean);
1718
map.insert("is_static", DataType::Boolean);
1819
map.insert("is_const", DataType::Boolean);
19-
map.insert("has_template", DataType::Boolean);
20-
map.insert("access_modifier", DataType::Integer);
2120
map.insert("is_variadic", DataType::Boolean);
2221
map.insert("is_volatile", DataType::Boolean);
2322
map.insert("is_struct", DataType::Boolean);
23+
map.insert("has_template", DataType::Boolean);
2424

25+
map.insert("return_type", DataType::Text);
26+
map.insert("type_literal", DataType::Text);
27+
28+
map.insert("args_count", DataType::Integer);
2529
map.insert("bases_count", DataType::Integer);
2630
map.insert("methods_count", DataType::Integer);
2731
map.insert("fields_count", DataType::Integer);
@@ -54,7 +58,14 @@ lazy_static! {
5458
);
5559
map.insert(
5660
"enums",
57-
vec!["name", "constants_count", "line", "column", "offset"],
61+
vec![
62+
"name",
63+
"constants_count",
64+
"type_literal",
65+
"line",
66+
"column",
67+
"offset",
68+
],
5869
);
5970
map.insert(
6071
"functions",

src/visitor/enumeration.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::visitor::location;
1010

1111
pub struct EnumNode {
1212
pub name: String,
13+
pub type_literal: String,
1314
pub attributes: EnumAttributes,
1415
pub location: location::SourceLocation,
1516
}
@@ -65,19 +66,25 @@ extern "C" fn visit_enum_declaration(
6566

6667
let location = location::visit_source_location(cursor);
6768

68-
let enums = &mut *(data as *mut Vec<EnumNode>);
69+
let enum_type = clang_getEnumDeclIntegerType(cursor);
70+
let enum_type_spelling = clang_getTypeSpelling(enum_type);
71+
let type_literal =
72+
CStr::from_ptr(clang_getCString(enum_type_spelling)).to_string_lossy();
6973

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

78+
let enums: &mut Vec<EnumNode> = &mut *(data as *mut Vec<EnumNode>);
7479
enums.push(EnumNode {
7580
name: enum_name.to_string(),
81+
type_literal: type_literal.to_string(),
7682
attributes,
7783
location,
7884
});
7985

8086
clang_disposeString(cursor_name);
87+
clang_disposeString(enum_type_spelling);
8188
return CXChildVisit_Continue;
8289
}
8390
}

0 commit comments

Comments
 (0)