From b2c58d20a30c6f45d9a071ad639188ad9d77a171 Mon Sep 17 00:00:00 2001 From: AmrDeveloper Date: Sat, 4 May 2024 20:03:37 +0200 Subject: [PATCH] feat: Support query number of bases for class declaration --- README.md | 1 + src/data_provider.rs | 15 ++++++++++----- src/schema.rs | 2 ++ src/visitor/class.rs | 8 ++++++++ 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e3983ff..f39fb68 100644 --- a/README.md +++ b/README.md @@ -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 | diff --git a/src/data_provider.rs b/src/data_provider.rs index d590125..9790546 100644 --- a/src/data_provider.rs +++ b/src/data_provider.rs @@ -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; } @@ -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; } diff --git a/src/schema.rs b/src/schema.rs index ff52d14..069c577 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -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); @@ -42,6 +43,7 @@ lazy_static! { vec![ "name", "is_struct", + "bases_count", "methods_count", "fields_count", "line", diff --git a/src/visitor/class.rs b/src/visitor/class.rs index cfe6544..5ca50fe 100644 --- a/src/visitor/class.rs +++ b/src/visitor/class.rs @@ -17,6 +17,7 @@ pub struct ClassNode { #[derive(Default)] pub struct ClassAttributes { + pub bases_count: u32, pub methods_count: u32, pub fields_count: u32, } @@ -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;