Allocate¶
Allocates allocatable variables and pointers.
Declaration¶
Syntax¶
Allocate(alloc_arg* args, expr? stat, expr? errmsg, expr? source)
Arguments¶
Argument |
Description |
|---|---|
|
one alloc_arg per object being allocated, carrying the object, its shape, its codimensions, its character length and its dynamic type. |
|
a variable receiving the status: zero on success, non-zero on failure. With |
|
a character variable receiving the error message. |
|
the expression of |
Return values¶
None.
Description¶
Allocating an already allocated object is an error at run time.
The shape lives in the dims of each alloc_arg, not in the type of the
variable: an allocatable is declared with a deferred shape and gets its bounds
here. A character length is given by len_expr, and sym_subclass gives the
dynamic type when allocating a polymorphic object.
ReAlloc is the related node for growing an object that may already be allocated, and ExplicitDeallocate is its counterpart.
Examples¶
(Allocate
:args [
(alloc_arg
:a (Var
:v (SymbolRef 1 "a")
)
:dims [
(dimension
:start (IntegerConstant
:n 1
:type (Integer
:kind 4
)
:intboz_type :Decimal
)
:length (IntegerConstant
:n 10
:type (Integer
:kind 4
)
:intboz_type :Decimal
)
)
]
:codims []
:len_expr nil
:sym_subclass nil
:type nil
)
]
:stat (Var
:v (SymbolRef 1 "stat")
)
:errmsg nil
:source nil
)
It comes from this complete ASR text document:
(TranslationUnit
:symtab (SymbolTable
:id 0
:symbols {
"main" (Program
:symtab (SymbolTable
:id 1
:symbols {
"a" (Variable
:parent_symtab 1
:name "a"
:dependencies []
:intent :Local
:symbolic_value nil
:value nil
:storage :Default
:type (Allocatable
:type (Array
:type (Integer
:kind 4
)
:dims [
(dimension
:start nil
:length nil
)
]
:physical_type :DescriptorArray
)
)
: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 []
)
"p" (Variable
:parent_symtab 1
:name "p"
:dependencies []
:intent :Local
:symbolic_value nil
:value nil
:storage :Default
:type (Pointer
: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 []
)
"stat" (Variable
:parent_symtab 1
:name "stat"
:dependencies []
:intent :Local
:symbolic_value nil
:value nil
:storage :Default
: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 []
)
}
)
:name "main"
:dependencies []
:body [
(Allocate
:args [
(alloc_arg
:a (Var
:v (SymbolRef 1 "a")
)
:dims [
(dimension
:start (IntegerConstant
:n 1
:type (Integer
:kind 4
)
:intboz_type :Decimal
)
:length (IntegerConstant
:n 10
:type (Integer
:kind 4
)
:intboz_type :Decimal
)
)
]
:codims []
:len_expr nil
:sym_subclass nil
:type nil
)
]
:stat (Var
:v (SymbolRef 1 "stat")
)
:errmsg nil
:source nil
)
(ReAlloc
:args [
(alloc_arg
:a (Var
:v (SymbolRef 1 "a")
)
:dims [
(dimension
:start (IntegerConstant
:n 1
:type (Integer
:kind 4
)
:intboz_type :Decimal
)
:length (IntegerConstant
:n 20
:type (Integer
:kind 4
)
:intboz_type :Decimal
)
)
]
:codims []
:len_expr nil
:sym_subclass nil
:type nil
)
]
)
(ExplicitDeallocate
:vars [
(Var
:v (SymbolRef 1 "a")
)
]
)
(Nullify
:vars [
(Var
:v (SymbolRef 1 "p")
)
]
)
(ImplicitDeallocate
:vars [
(Var
:v (SymbolRef 1 "a")
)
]
)
]
)
}
)
:items []
)
See Also¶
ReAlloc, ExplicitDeallocate, ImplicitDeallocate, alloc_arg, Allocatable