Skip to content

Commit

Permalink
feat: Support query size_of class
Browse files Browse the repository at this point in the history
  • Loading branch information
AmrDeveloper committed May 7, 2024
1 parent 8c349ba commit 018f3c3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ SELECT * FROM globals WHERE is_volatile
| bases_count | Integer | Number of bases for this class |
| methods_count | Integer | Number of methods declarations |
| fields_count | Integer | Number of fields declarations |
| size_of | Integer | Class Size in bytes |
| 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 @@ -131,6 +131,11 @@ fn select_classes(
continue;
}

if field_name == "size_of" {
values.push(Value::Integer(class.size_of));
continue;
}

if field_name == "file" {
values.push(Value::Text(class.location.file.to_string()));
continue;
Expand Down
3 changes: 3 additions & 0 deletions src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ lazy_static! {
map.insert("fields_count", DataType::Integer);
map.insert("constants_count", DataType::Integer);

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

// Source code location columns
map.insert("file", DataType::Text);
map.insert("line", DataType::Integer);
Expand All @@ -51,6 +53,7 @@ lazy_static! {
"bases_count",
"methods_count",
"fields_count",
"size_of",
"line",
"column",
"offset",
Expand Down
5 changes: 5 additions & 0 deletions src/visitor/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub struct ClassNode {
pub name: String,
pub attributes: ClassAttributes,
pub is_struct: bool,
pub size_of: i64,
pub location: location::SourceLocation,
}

Expand Down Expand Up @@ -71,6 +72,9 @@ extern "C" fn visit_class_or_struct_declaration(
let classes = &mut *(data as *mut Vec<ClassNode>);
let is_struct = cursor_kind == CXCursor_StructDecl;

let class_type = clang_getCursorType(cursor);
let size_of = clang_Type_getSizeOf(class_type) / 8;

let mut attributes = ClassAttributes::default();
let attributes_pointer = &mut attributes as *mut ClassAttributes as *mut c_void;
clang_visitChildren(cursor, visit_class_attributes, attributes_pointer);
Expand All @@ -79,6 +83,7 @@ extern "C" fn visit_class_or_struct_declaration(
name: class_name.to_string(),
attributes,
is_struct,
size_of,
location,
});

Expand Down

0 comments on commit 018f3c3

Please sign in to comment.