From 83dd0cfdc6e127a1617311344457836188caeb95 Mon Sep 17 00:00:00 2001 From: AmrDeveloper Date: Wed, 1 May 2024 21:49:09 +0200 Subject: [PATCH] feat: Support query `is_struct` attribute in classes table --- src/data_provider.rs | 5 +++++ src/schema.rs | 6 +++++- src/visitor/class.rs | 4 ++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/data_provider.rs b/src/data_provider.rs index 3aff8e7..e571811 100644 --- a/src/data_provider.rs +++ b/src/data_provider.rs @@ -109,6 +109,11 @@ fn select_classes( continue; } + if field_name == "is_struct" { + values.push(Value::Boolean(class.is_struct)); + continue; + } + if field_name == "file" { values.push(Value::Text(class.location.file.to_string())); continue; diff --git a/src/schema.rs b/src/schema.rs index 80d446b..1ca4d0d 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -20,6 +20,7 @@ lazy_static! { map.insert("access_modifier", DataType::Integer); map.insert("is_variadic", DataType::Boolean); map.insert("is_volatile", DataType::Boolean); + map.insert("is_struct", DataType::Boolean); // Source code location columns map.insert("file", DataType::Text); @@ -33,7 +34,10 @@ lazy_static! { lazy_static! { pub static ref TABLES_FIELDS_NAMES: HashMap<&'static str, Vec<&'static str>> = { let mut map = HashMap::new(); - map.insert("classes", vec!["name", "line", "column", "offset"]); + map.insert( + "classes", + vec!["name", "is_struct", "line", "column", "offset"], + ); map.insert( "functions", vec![ diff --git a/src/visitor/class.rs b/src/visitor/class.rs index 6117c36..9abcdee 100644 --- a/src/visitor/class.rs +++ b/src/visitor/class.rs @@ -10,6 +10,7 @@ use crate::visitor::location; pub struct ClassNode { pub name: String, + pub is_struct: bool, pub location: location::SourceLocation, } @@ -60,8 +61,11 @@ extern "C" fn visit_children( let location = location::visit_source_location(cursor); let classes = &mut *(data as *mut Vec); + let is_struct = cursor_kind == CXCursor_StructDecl; + classes.push(ClassNode { name: class_name.to_string(), + is_struct, location, });