Skip to content

Commit

Permalink
feat: Support query number of bases for class declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
AmrDeveloper committed May 4, 2024
1 parent 7ce51fb commit b2c58d2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ SELECT * FROM globals WHERE is_volatile
| ------------- | ------- | ------------------------------- |
| name | Text | Class variable name |
| is_struct | Boolean | True if it a struct declaration |
| bases_count | Integer | Number of bases for this class |
| methods_count | Integer | Number of methods declarations |
| fields_count | Integer | Number of fields declarations |
| file | Text | File path |
Expand Down
15 changes: 10 additions & 5 deletions src/data_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,18 @@ fn select_classes(
continue;
}

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

if field_name == "methods_count" {
values.push(Value::Integer(class.attributes.methods_count as i64));
values.push(Value::Integer(class.attributes.methods_count.into()));
continue;
}

if field_name == "fields_count" {
values.push(Value::Integer(class.attributes.fields_count as i64));
values.push(Value::Integer(class.attributes.fields_count.into()));
continue;
}

Expand All @@ -130,17 +135,17 @@ fn select_classes(
}

if field_name == "line" {
values.push(Value::Integer(class.location.line as i64));
values.push(Value::Integer(class.location.line.into()));
continue;
}

if field_name == "column" {
values.push(Value::Integer(class.location.column as i64));
values.push(Value::Integer(class.location.column.into()));
continue;
}

if field_name == "offset" {
values.push(Value::Integer(class.location.offset as i64));
values.push(Value::Integer(class.location.offset.into()));
continue;
}

Expand Down
2 changes: 2 additions & 0 deletions src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ lazy_static! {
map.insert("is_volatile", DataType::Boolean);
map.insert("is_struct", DataType::Boolean);

map.insert("bases_count", DataType::Integer);
map.insert("methods_count", DataType::Integer);
map.insert("fields_count", DataType::Integer);

Expand All @@ -42,6 +43,7 @@ lazy_static! {
vec![
"name",
"is_struct",
"bases_count",
"methods_count",
"fields_count",
"line",
Expand Down
8 changes: 8 additions & 0 deletions src/visitor/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct ClassNode {

#[derive(Default)]
pub struct ClassAttributes {
pub bases_count: u32,
pub methods_count: u32,
pub fields_count: u32,
}
Expand Down Expand Up @@ -99,6 +100,13 @@ extern "C" fn visit_class_attributes(
}

let cursor_kind = clang_getCursorKind(cursor);

if cursor_kind == CXCursor_CXXBaseSpecifier {
let attributes = &mut *(data as *mut ClassAttributes);
attributes.bases_count += 1;
return CXChildVisit_Continue;
}

if cursor_kind == CXCursor_CXXMethod || cursor_kind == CXCursor_FunctionTemplate {
let attributes = &mut *(data as *mut ClassAttributes);
attributes.methods_count += 1;
Expand Down

0 comments on commit b2c58d2

Please sign in to comment.