Skip to main content

gobject_ast/model/statement/
variable_decl.rs

1use serde::Serialize;
2
3use crate::model::{Expression, SourceLocation, TypeInfo};
4
5#[derive(Debug, Clone, Serialize)]
6pub struct VariableDecl {
7    pub type_info: TypeInfo,
8    pub name: String,
9    #[serde(skip_serializing_if = "std::ops::Not::not")]
10    pub is_static: bool,
11    /// Location of the variable name in the source
12    #[serde(skip)]
13    pub name_location: SourceLocation,
14    #[serde(skip_serializing_if = "Option::is_none")]
15    pub initializer: Option<Expression>,
16    /// Array size expression for array declarators (e.g., [N_PROPS])
17    #[serde(skip_serializing_if = "Option::is_none")]
18    pub array_size: Option<Expression>,
19    pub location: SourceLocation,
20}
21
22impl VariableDecl {
23    /// Check if this is a simple identifier (not a field access like
24    /// obj->field)
25    pub fn is_simple_identifier(&self) -> bool {
26        !self.name.contains("->") && !self.name.contains('.')
27    }
28}