Skip to content

Commit

Permalink
feat: Support query glboal variale is_volatile
Browse files Browse the repository at this point in the history
  • Loading branch information
AmrDeveloper committed Apr 24, 2024
1 parent 9e81635 commit 962f6c4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ SELECT DISTINCT name AS function_name FROM functions

SELECT * FROM globals
SELECT COUNT(name) from globals WHERE type = "int"
SELECT * FROM globals WHERE is_volatile
```

---
Expand All @@ -64,10 +65,11 @@ SELECT COUNT(name) from globals WHERE type = "int"

### Gloal variables table structure

| Name | Type | Description |
| ---- | ---- | ---------------------------- |
| name | Text | Global variable name |
| type | Text | Global variable type literal |
| Name | Type | Description |
| ----------- | ------- | --------------------------------- |
| name | Text | Global variable name |
| type | Text | Global variable type literal |
| is_volatile | Boolean | True if variable type is volatile |

---

Expand Down
5 changes: 5 additions & 0 deletions src/data_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ fn select_variables(
continue;
}

if field_name == "is_volatile" {
values.push(Value::Boolean(variable.is_volatile));
continue;
}

values.push(Value::Null);
}

Expand Down
3 changes: 2 additions & 1 deletion src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ lazy_static! {
map.insert("has_template", DataType::Boolean);
map.insert("access_modifier", DataType::Integer);
map.insert("is_variadic", DataType::Boolean);
map.insert("is_volatile", DataType::Boolean);
map
};
}
Expand All @@ -44,7 +45,7 @@ lazy_static! {
"is_variadic",
],
);
map.insert("globals", vec!["name", "type"]);
map.insert("globals", vec!["name", "type", "is_volatile"]);
map
};
}
4 changes: 4 additions & 0 deletions src/visitor/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::ptr;
pub struct GlobalVariableNode {
pub name: String,
pub type_literal: String,
pub is_volatile: bool,
}

pub fn select_clang_variables(path: &str) -> Vec<GlobalVariableNode> {
Expand Down Expand Up @@ -62,9 +63,12 @@ extern "C" fn visit_children(
CStr::from_ptr(clang_getCString(clang_getTypeSpelling(field_type)))
.to_string_lossy();

let is_volatile = clang_isVolatileQualifiedType(field_type) != 0;

variables.push(GlobalVariableNode {
name: field_name_str.to_string(),
type_literal: field_type_str.to_string(),
is_volatile,
});

clang_disposeString(field_name);
Expand Down

0 comments on commit 962f6c4

Please sign in to comment.