Struct AstVariableDeclaration
pub struct AstVariableDeclaration {
pub node_id: AstNodeId,
pub is_declaration_only: bool,
pub is_file_scope: bool,
pub declared_type: AstDeclaredType,
pub ident: AstIdentifier,
pub unique_name: AstUniqueName,
pub initializer: Option<AstVariableInitializer>,
pub init_constant_eval: Vec<AstStaticStorageInitializer>,
pub linkage: AstLinkage,
pub storage: AstStorageDuration,
}Expand description
A variable declaration with optional definition.
The is_declaration_only field specifies whether the variable is a declaration only, or if it’s a declaration and
definition. A variable can be defined even if there is no init_expr, e.g. in file scope or a static variable
declaration in block scope. In both of those cases, the variable is a definition but has no initializer, and
will get a default value of zero.
If is_declaration_only is true, then the declaration only introduces the variable’s name and type, and does not
allocate any storage for it. For example, extern int i; or struct Foo;.
Note that extern int i = 3; is a definition and the extern is ignored (and a warning is emitted).
If the initializer expression can be evaluated at compile-time (i.e. it’s a constant expression) then the result
of its evaluation is stored in init_constant_eval. The sema stage is responsible for this evaluation. The
evaluation is a Vec because a static storage variable of array type may have more than one initializer value.
Scalar types will only have one value.
Fields§
§node_id: AstNodeId§is_declaration_only: bool§is_file_scope: bool§declared_type: AstDeclaredType§ident: AstIdentifier§unique_name: AstUniqueName§initializer: Option<AstVariableInitializer>§init_constant_eval: Vec<AstStaticStorageInitializer>§linkage: AstLinkage§storage: AstStorageDuration