Struct¶
A derived type definition.
Declaration¶
Syntax¶
Struct(symbol_table symtab, identifier name, ttype struct_signature,
identifier* dependencies, identifier* members,
identifier* member_functions, abi abi, access access,
bool is_packed, bool is_abstract, bool is_sequence,
call_arg* initializers, expr? alignment, symbol? parent,
identifier* kind_params)
Arguments¶
Argument |
Description |
|---|---|
|
the symbol table of the type: one Variable per data component and one StructMethodDeclaration per type-bound procedure. |
|
the name of the derived type. |
|
the StructType that describes an instance of this type. |
|
the names of the symbols the definition refers to. |
|
the names of the data components, in declaration order. The order fixes the storage layout. |
|
the names of the type-bound procedures. |
|
|
|
|
|
|
|
|
|
|
|
the default initializers of the components, in |
|
an explicit alignment in bytes, or |
|
the type this one extends, or |
|
the names of the kind type parameters of the type. |
Return values¶
None.
Description¶
Struct is the definition of a derived type, and it is a symbol: it is owned by a symbol table and referred to by name. The type of a variable of that type is the separate StructType, which holds the component types.
members is authoritative for layout. The symbol table is a mapping and says
nothing about order, so a backend that walks components must walk members and
look each name up, never iterate the symbol table.
A component is read with StructInstanceMember and a whole value is built with StructConstructor.
Examples¶
An ASR text document that uses it:
(TranslationUnit
:symtab (SymbolTable
:id 0
:symbols {
"m" (Module
:symtab (SymbolTable
:id 1
:symbols {
"point" (Struct
:symtab (SymbolTable
:id 2
:symbols {
"x" (Variable
:parent_symtab 2
:name "x"
: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 []
)
"y" (Variable
:parent_symtab 2
:name "y"
:dependencies []
:intent :Local
:symbolic_value nil
:value nil
:storage :Default
:type (Real
: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 "point"
:struct_signature (StructType
:data_member_types [
(Integer
:kind 4
)
(Real
:kind 4
)
]
:member_function_types []
:is_cstruct false
:is_unlimited_polymorphic false
)
:dependencies []
:members [
"x"
"y"
]
:member_functions []
:abi :Source
:access :Public
:is_packed false
:is_abstract false
:is_sequence false
:initializers []
:alignment nil
:parent nil
:kind_params []
)
}
)
:name "m"
:parent_module nil
:dependencies []
:loaded_from_mod false
:intrinsic false
:has_submodules false
)
"main" (Program
:symtab (SymbolTable
:id 3
:symbols {}
)
:name "main"
:dependencies []
:body []
)
}
)
:items []
)
See Also¶
StructType, StructInstanceMember, StructConstructor, StructMethodDeclaration, Union