Reference¶
The address of a variable, held by a member of a host frame.
声明¶
语法¶
Reference(ttype type)
参数¶
Argument |
描述 |
|---|---|
|
the type of the variable whose address the member holds. |
返回值¶
None. A type is not evaluated.
描述¶
A Reference is the type of a member of a frame, the derived type that the
nested_vars pass declares in a host so that its internal procedures reach
the variables of the instance of the host that invoked them (see “Host
Association” in the design document). It is the type of such a member and of
nothing else: the verifier reports a Reference anywhere else, including inside
another type, as asr.verify.reference.member_only.
BindReference stores the address of a
variable in the member. A
StructInstanceMember of the
member then designates that variable itself and has type type, the type of
the variable, as asr.verify.reference.designator_type checks. It is the
symbolic_value of a variable of HostAssociated
storage, which stands for the variable in an
internal procedure.
Unlike a Pointer, a member of Reference type has no association
status and no value of its own, and nothing allocates, deallocates,
finalizes, copies or default-initializes it with the object that contains it:
generic code that does not know the type leaves it alone. A backend lays it
out as the address of the storage of a variable of type type.
示例¶
(Reference
:type (Integer
:kind 4
)
)
It comes from this complete ASR text document:
(TranslationUnit
:symtab (SymbolTable
:id 0
:symbols {
"host_frame" (Program
:symtab (SymbolTable
:id 1
:symbols {
"k" (Variable
:parent_symtab 1
:name "k"
: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_asynchronous false
:is_protected false
:pass_attr :NotMethod
:self_argument nil
:codims []
:common_block nil
)
"outer" (Function
:symtab (SymbolTable
:id 2
:symbols {
"1_frame_n" (ExternalSymbol
:parent_symtab 2
:name "1_frame_n"
:external (SymbolRef 3 "n")
:module_name "frame"
:scope_names []
:original_name "n"
:access :Public
)
"f" (Variable
:parent_symtab 2
:name "f"
:dependencies []
:intent :Local
:symbolic_value nil
:value nil
:storage :Default
:type (StructType
:data_member_types [
(Reference
:type (Integer
:kind 4
)
)
]
:member_function_types []
:is_cstruct true
:is_unlimited_polymorphic false
)
:type_declaration (SymbolRef 2 "frame")
:abi :Source
:access :Public
:presence :Required
:value_attr false
:target_attr false
:contiguous_attr false
:bindc_name nil
:is_volatile false
:is_asynchronous false
:is_protected false
:pass_attr :NotMethod
:self_argument nil
:codims []
:common_block nil
)
"frame" (Struct
:symtab (SymbolTable
:id 3
:symbols {
"n" (Variable
:parent_symtab 3
:name "n"
:dependencies []
:intent :Unspecified
:symbolic_value nil
:value nil
:storage :Default
:type (Reference
: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_asynchronous false
:is_protected false
:pass_attr :NotMethod
:self_argument nil
:codims []
:common_block nil
)
}
)
:name "frame"
:struct_signature (StructType
:data_member_types [
(Reference
:type (Integer
:kind 4
)
)
]
:member_function_types []
:is_cstruct true
:is_unlimited_polymorphic false
)
:dependencies []
:members [
"n"
]
:member_functions []
:abi :Source
:access :Public
:is_packed false
:is_abstract false
:is_sequence false
:initializers []
:alignment nil
:parent nil
:kind_params []
)
"inner" (Function
:symtab (SymbolTable
:id 4
:symbols {
"f" (Variable
:parent_symtab 4
:name "f"
:dependencies []
:intent :In
:symbolic_value nil
:value nil
:storage :Default
:type (StructType
:data_member_types [
(Reference
:type (Integer
:kind 4
)
)
]
:member_function_types []
:is_cstruct true
:is_unlimited_polymorphic false
)
:type_declaration (SymbolRef 2 "frame")
:abi :Source
:access :Public
:presence :Required
:value_attr false
:target_attr false
:contiguous_attr false
:bindc_name nil
:is_volatile false
:is_asynchronous false
:is_protected false
:pass_attr :NotMethod
:self_argument nil
:codims []
:common_block nil
)
"n" (Variable
:parent_symtab 4
:name "n"
:dependencies [
"f"
]
:intent :Local
:symbolic_value (StructInstanceMember
:v (Var
:v (SymbolRef 4 "f")
)
:m (SymbolRef 2 "1_frame_n")
:type (Integer
:kind 4
)
:value nil
)
:value nil
:storage :HostAssociated
: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_asynchronous false
:is_protected false
:pass_attr :NotMethod
:self_argument nil
:codims []
:common_block nil
)
}
)
:name "inner"
:function_signature (FunctionType
:arg_types [
(StructType
:data_member_types [
(Reference
:type (Integer
:kind 4
)
)
]
:member_function_types []
:is_cstruct true
:is_unlimited_polymorphic false
)
]
:return_var_type nil
:abi :Source
:deftype :Implementation
:bindc_name nil
:elemental false
:pure false
:module false
:inline false
:static false
:restrictions []
:is_restriction false
:exec_space :Host
)
:dependencies []
:args [
(Var
:v (SymbolRef 4 "f")
)
]
:body [
(Assignment
:target (Var
:v (SymbolRef 4 "n")
)
:value (IntegerBinOp
:left (Var
:v (SymbolRef 4 "n")
)
:op :Add
:right (IntegerConstant
:n 1
:type (Integer
:kind 4
)
:intboz_type :Decimal
)
:type (Integer
:kind 4
)
:value nil
)
:overloaded nil
:realloc_lhs false
:move_allocation false
:new_target false
:new_allocation false
)
]
:return_var nil
:access :Public
:deterministic true
:side_effect_free true
:module_file nil
)
"n" (Variable
:parent_symtab 2
:name "n"
:dependencies []
:intent :InOut
: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_asynchronous false
:is_protected false
:pass_attr :NotMethod
:self_argument nil
:codims []
:common_block nil
)
}
)
:name "outer"
:function_signature (FunctionType
:arg_types [
(Integer
:kind 4
)
]
:return_var_type nil
:abi :Source
:deftype :Implementation
:bindc_name nil
:elemental false
:pure false
:module false
:inline false
:static false
:restrictions []
:is_restriction false
:exec_space :Host
)
:dependencies []
:args [
(Var
:v (SymbolRef 2 "n")
)
]
:body [
(BindReference
:reference (StructInstanceMember
:v (Var
:v (SymbolRef 2 "f")
)
:m (SymbolRef 2 "1_frame_n")
:type (Integer
:kind 4
)
:value nil
)
:variable (Var
:v (SymbolRef 2 "n")
)
)
(SubroutineCall
:name (SymbolRef 2 "inner")
:original_name nil
:args [
(call_arg
:value (Var
:v (SymbolRef 2 "f")
)
)
]
:dt nil
:strict_bounds_checking false
)
]
:return_var nil
:access :Public
:deterministic true
:side_effect_free true
:module_file nil
)
}
)
:name "host_frame"
:dependencies []
:body [
(Assignment
:target (Var
:v (SymbolRef 1 "k")
)
:value (IntegerConstant
:n 1
:type (Integer
:kind 4
)
:intboz_type :Decimal
)
:overloaded nil
:realloc_lhs false
:move_allocation false
:new_target false
:new_allocation false
)
(SubroutineCall
:name (SymbolRef 1 "outer")
:original_name nil
:args [
(call_arg
:value (Var
:v (SymbolRef 1 "k")
)
)
]
:dt nil
:strict_bounds_checking false
)
(Print
:text (StringFormat
:fmt nil
:args [
(Var
:v (SymbolRef 1 "k")
)
]
:kind :FormatFortran
:dtio_bindings []
:dtio_unit nil
:type (Allocatable
:type (String
:kind 1
:len nil
:len_kind :DeferredLength
:physical_type :DescriptorString
)
)
:value nil
)
)
]
:global_init nil
)
}
)
:items []
:global_init nil
)