Variable¶
A variable, a dummy argument, a named constant or a result variable.
Declaration¶
Syntax¶
Variable(symbol_table parent_symtab, identifier name,
identifier* dependencies, intent intent, expr? symbolic_value,
expr? value, storage_type storage, ttype type,
symbol? type_declaration, abi abi, access access,
presence presence, bool value_attr, bool target_attr,
bool contiguous_attr, string? bindc_name, bool is_volatile,
bool is_protected, pass_attr pass_attr, identifier? self_argument,
codimension* codims)
Arguments¶
Argument |
Description |
|---|---|
|
the symbol table this variable is stored in. |
|
the name of the variable. |
|
the names of the symbols its type or initializer refers to. |
|
|
|
the initializer as written, before folding. |
|
the folded compile time value, when there is one. A |
|
|
|
the type of the variable. |
|
for a variable of a derived type, an enumeration or a union, the symbol that defines it; |
|
|
|
|
|
|
|
|
|
|
|
|
|
the linker name given by |
|
|
|
|
|
for a component holding a procedure pointer, whether the object is passed as an argument; |
|
the name of the passed-object dummy argument, when |
|
the codimensions of a coarray; empty for anything else. |
Return values¶
None.
Description¶
Everything a Fortran declaration says about a variable is stored here, so that
a backend never has to look at anything but the Variable and its type to
allocate it.
A variable is referenced from an expression by Var, which holds nothing but a reference to this symbol; every property is read from the symbol itself.
symbolic_value and value are different things. symbolic_value is the
initializer as the user wrote it, and value is what it folds to.
storage=Parameter requires value, since a named constant is substituted
wherever it is used.
Examples¶
(Variable
:parent_symtab 1
:name "n"
:dependencies []
:intent :Local
:symbolic_value (IntegerConstant
:n 10
:type (Integer
:kind 4
)
:intboz_type :Decimal
)
:value (IntegerConstant
:n 10
:type (Integer
:kind 4
)
:intboz_type :Decimal
)
:storage :Parameter
:type (Integer
:kind 4
)
:type_declaration nil
:abi :Source
:access :Public
:presence :Required
:value_attr false
:target_attr false
:contiguous_attr false
:bindc_name nil
:is_volatile false
:is_protected false
:pass_attr :NotMethod
:self_argument nil
:codims []
)
It comes from this complete ASR text document:
(TranslationUnit
:symtab (SymbolTable
:id 0
:symbols {
"main" (Program
:symtab (SymbolTable
:id 1
:symbols {
"n" (Variable
:parent_symtab 1
:name "n"
:dependencies []
:intent :Local
:symbolic_value (IntegerConstant
:n 10
:type (Integer
:kind 4
)
:intboz_type :Decimal
)
:value (IntegerConstant
:n 10
:type (Integer
:kind 4
)
:intboz_type :Decimal
)
:storage :Parameter
:type (Integer
:kind 4
)
:type_declaration nil
:abi :Source
:access :Public
:presence :Required
:value_attr false
:target_attr false
:contiguous_attr false
:bindc_name nil
:is_volatile false
:is_protected false
:pass_attr :NotMethod
:self_argument nil
:codims []
)
"x" (Variable
:parent_symtab 1
:name "x"
:dependencies []
:intent :Local
:symbolic_value nil
:value nil
:storage :Default
:type (Real
:kind 8
)
:type_declaration nil
:abi :Source
:access :Public
:presence :Required
:value_attr false
:target_attr true
:contiguous_attr false
:bindc_name nil
:is_volatile false
:is_protected false
:pass_attr :NotMethod
:self_argument nil
:codims []
)
}
)
:name "main"
:dependencies []
:body [
(Assignment
:target (Var
:v (SymbolRef 1 "x")
)
:value (Cast
:arg (Var
:v (SymbolRef 1 "n")
)
:kind :IntegerToReal
:type (Real
:kind 8
)
:value (RealConstant
:r 10.0
:type (Real
:kind 8
)
)
:dest nil
)
:overloaded nil
:realloc_lhs false
:move_allocation false
)
]
)
}
)
:items []
)