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

symtab

the symbol table of the type: one Variable per data component and one StructMethodDeclaration per type-bound procedure.

name

the name of the derived type.

struct_signature

the StructType that describes an instance of this type.

dependencies

the names of the symbols the definition refers to.

members

the names of the data components, in declaration order. The order fixes the storage layout.

member_functions

the names of the type-bound procedures.

abi

Source for a type defined here, BindC for bind(c).

access

Public or Private.

is_packed

true when the layout must not be padded.

is_abstract

true for an abstract type, which cannot be instantiated.

is_sequence

true for a sequence type, whose components are laid out in declaration order with no padding.

initializers

the default initializers of the components, in members order.

alignment

an explicit alignment in bytes, or nil.

parent

the type this one extends, or nil.

kind_params

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