Associate¶
Binds a name to a target rather than copying a value.
Declaration¶
Syntax¶
Associate(expr target, expr value, pointer_bounds_form form)
Arguments¶
Argument |
Description |
|---|---|
|
the pointer or associate name being bound. |
|
what it is bound to. |
|
whether |
Return values¶
None.
Description¶
Associate is pointer assignment, p => t, and it is what gives the names
of an AssociateBlock their meaning. It
makes the target refer to the same storage as the value; it does not copy
anything, which is what distinguishes it from
Assignment.
Associate with a
PointerNullConstant value is how
p => null() is represented, and Nullify is the equivalent
statement form.
A pointer assignment with a bounds-spec-list, p(lb:) => a, or a
bounds-remapping-list, p(lb:ub) => a, has as target an
ArraySection of the pointer, and form
says which of the two it is. For a bounds-spec the section has only the lower
bound of every dimension and no upper bound: the extents of the pointer are
those of the value, so a backend computes the upper bound of dimension i as
lb + size(value, i) - 1. For a bounds-remapping-list it has the lower and
the upper bound of every dimension, as written. Every bound is a scalar
integer expression, neither has a stride, and the value and every bound are
evaluated once. Every other association has form
NoPointerBounds. The verifier checks that the form is set exactly when the
target is a section of a pointer, that the bounds present are those of the
form and are scalar integers, that the value is not null(), that the value
of a bounds-spec has the rank of the pointer, that the value of a
bounds-remapping-list is an array, and that the value is a DescriptorArray
(an array of another physical type is cast to the physical type of the
section). That the value of a bounds-remapping-list has rank one or is simply
contiguous (F2018 9.5.4, 10.2.2.3) is checked by the frontend.
Examples¶
(Associate
:target (Var
:v (SymbolRef 1 "p")
)
:value (GetPointer
:arg (Var
:v (SymbolRef 1 "target")
)
:type (Pointer
:type (Integer
:kind 4
)
)
:value nil
)
:form :NoPointerBounds
)
It comes from this complete ASR text document:
(TranslationUnit
:symtab (SymbolTable
:id 0
:symbols {
"main" (Program
:symtab (SymbolTable
:id 1
:symbols {
"b" (Variable
:parent_symtab 1
:name "b"
:dependencies []
:intent :Local
:symbolic_value nil
:value nil
:storage :Default
:type (Logical
: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 []
:common_block nil
)
"c" (Variable
:parent_symtab 1
:name "c"
:dependencies []
:intent :Local
:symbolic_value nil
:value nil
:storage :Default
:type (CPtr
:kind :CPtrUnspecified
)
: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 []
:common_block nil
)
"n" (Variable
:parent_symtab 1
:name "n"
:dependencies []
:intent :Local
:symbolic_value nil
:value nil
:storage :Default
:type (Integer
:kind 8
)
: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 []
:common_block nil
)
"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 []
:common_block nil
)
"target" (Variable
:parent_symtab 1
:name "target"
: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 true
:contiguous_attr false
:bindc_name nil
:is_volatile false
:is_protected false
:pass_attr :NotMethod
:self_argument nil
:codims []
:common_block nil
)
}
)
:name "main"
:dependencies []
:body [
(Assignment
:target (Var
:v (SymbolRef 1 "c")
)
:value (CLoc
:arg (Var
:v (SymbolRef 1 "target")
)
:type (CPtr
:kind :CPtrUnspecified
)
:value nil
)
:overloaded nil
:realloc_lhs false
:move_allocation false
:new_target false
)
(Assignment
:target (Var
:v (SymbolRef 1 "c")
)
:value (PointerToCPtr
:arg (Var
:v (SymbolRef 1 "p")
)
:type (CPtr
:kind :CPtrUnspecified
)
:value nil
)
:overloaded nil
:realloc_lhs false
:move_allocation false
:new_target false
)
(Associate
:target (Var
:v (SymbolRef 1 "p")
)
:value (GetPointer
:arg (Var
:v (SymbolRef 1 "target")
)
:type (Pointer
:type (Integer
:kind 4
)
)
:value nil
)
:form :NoPointerBounds
)
(Assignment
:target (Var
:v (SymbolRef 1 "b")
)
:value (CPtrCompare
:left (Var
:v (SymbolRef 1 "c")
)
:op :Eq
:right (Var
:v (SymbolRef 1 "c")
)
:type (Logical
:kind 4
)
:value nil
)
:overloaded nil
:realloc_lhs false
:move_allocation false
:new_target false
)
(Assignment
:target (Var
:v (SymbolRef 1 "b")
)
:value (PointerAssociated
:ptr (Var
:v (SymbolRef 1 "p")
)
:tgt (Var
:v (SymbolRef 1 "target")
)
:type (Logical
:kind 4
)
:value nil
)
:overloaded nil
:realloc_lhs false
:move_allocation false
:new_target false
)
(Assignment
:target (Var
:v (SymbolRef 1 "n")
)
:value (SizeOfType
:arg (Integer
:kind 4
)
:type (Integer
:kind 8
)
:value nil
)
:overloaded nil
:realloc_lhs false
:move_allocation false
:new_target false
)
]
:global_init nil
)
}
)
:items []
:global_init nil
)
See Also¶
Assignment, AssociateBlock, Nullify, GetPointer, pointer_bounds_form