pub struct Variable { /* private fields */ }Expand description
Represents a variable declaration.
Implementations§
Source§impl Variable
impl Variable
Sourcepub fn new_with_initializer(
name: String,
var_type: Type,
initializer: Expression,
) -> Self
pub fn new_with_initializer( name: String, var_type: Type, initializer: Expression, ) -> Self
Create a new variable with an initializer.
Sourcepub fn new_with_storage_class(
name: String,
var_type: Type,
initializer: Option<Expression>,
is_static: bool,
is_extern: bool,
is_const: bool,
) -> Self
pub fn new_with_storage_class( name: String, var_type: Type, initializer: Option<Expression>, is_static: bool, is_extern: bool, is_const: bool, ) -> Self
Create a new variable with storage class specifiers.
Sourcepub fn is_function_pointer(&self) -> bool
pub fn is_function_pointer(&self) -> bool
Check if this variable is a function pointer.
Sourcepub fn function_pointer_param_count(&self) -> usize
pub fn function_pointer_param_count(&self) -> usize
Get the number of parameters if this is a function pointer.
Sourcepub fn function_pointer_has_void_return(&self) -> bool
pub fn function_pointer_has_void_return(&self) -> bool
Check if this function pointer has a void return type.
Sourcepub fn is_string_literal(&self) -> bool
pub fn is_string_literal(&self) -> bool
Check if this variable is a string literal (char* with literal initializer).
Detects patterns like: const char* msg = "Hello";
§Implementation
Checks if:
- Type is a pointer to char (
char*) - Has an initializer that is a
StringLiteralexpression
Note: Const qualifier detection not yet implemented - checks all char* pointers.
Sourcepub fn is_string_buffer(&self) -> bool
pub fn is_string_buffer(&self) -> bool
Check if this variable is a string buffer (char* allocated with malloc).
Detects patterns like: char* buffer = malloc(100);
§Implementation
Checks if:
- Type is a pointer to char (
char*) - Has an initializer that is a malloc/calloc function call
Sourcepub fn initializer(&self) -> Option<&Expression>
pub fn initializer(&self) -> Option<&Expression>
Get the initializer expression for this variable.
Returns Some(&Expression) if the variable has an initializer, None otherwise.