StructConstructor

A derived type value built from its components.

Declaration

Syntax

StructConstructor(symbol dt_sym, call_arg* args, ttype type,
    expr? value)

Arguments

Argument

Description

dt_sym

the Struct being constructed.

args

the component values, in the order of the type’s members, each a call_arg.

type

the StructType of the result.

value

the folded StructConstant, when every component is constant; nil otherwise.

Return values

The value of the expression.

Description

point(1, 2.0). The arguments are positional and in members order, so the frontend has already reordered any component keywords and filled in any default initialisers.

Examples

(StructConstructor
  :dt_sym (SymbolRef 3 "point")
  :args [
    (call_arg
      :value (IntegerConstant
        :n 1
        :type (Integer
          :kind 4
        )
        :intboz_type :Decimal
      )
    )
    (call_arg
      :value (RealConstant
        :r 2.0
        :type (Real
          :kind 4
        )
      )
    )
  ]
  :type (StructType
    :data_member_types [
      (Integer
        :kind 4
      )
      (Real
        :kind 4
      )
    ]
    :member_function_types []
    :is_cstruct false
    :is_unlimited_polymorphic false
  )
  :value nil
)

It comes from this complete ASR text document:

(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 {
            "i" (Variable
              :parent_symtab 3
              :name "i"
              :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 []
            )
            "p" (Variable
              :parent_symtab 3
              :name "p"
              :dependencies []
              :intent :Local
              :symbolic_value nil
              :value nil
              :storage :Default
              :type (StructType
                :data_member_types [
                  (Integer
                    :kind 4
                  )
                  (Real
                    :kind 4
                  )
                ]
                :member_function_types []
                :is_cstruct false
                :is_unlimited_polymorphic false
              )
              :type_declaration (SymbolRef 3 "point")
              :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 []
            )
            "point" (ExternalSymbol
              :parent_symtab 3
              :name "point"
              :external (SymbolRef 1 "point")
              :module_name "m"
              :scope_names []
              :original_name "point"
              :access :Public
            )
          }
        )
        :name "main"
        :dependencies [
          "m"
        ]
        :body [
          (Assignment
            :target (Var
              :v (SymbolRef 3 "p")
            )
            :value (StructConstructor
              :dt_sym (SymbolRef 3 "point")
              :args [
                (call_arg
                  :value (IntegerConstant
                    :n 1
                    :type (Integer
                      :kind 4
                    )
                    :intboz_type :Decimal
                  )
                )
                (call_arg
                  :value (RealConstant
                    :r 2.0
                    :type (Real
                      :kind 4
                    )
                  )
                )
              ]
              :type (StructType
                :data_member_types [
                  (Integer
                    :kind 4
                  )
                  (Real
                    :kind 4
                  )
                ]
                :member_function_types []
                :is_cstruct false
                :is_unlimited_polymorphic false
              )
              :value nil
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
          (Assignment
            :target (Var
              :v (SymbolRef 3 "i")
            )
            :value (StructInstanceMember
              :v (Var
                :v (SymbolRef 3 "p")
              )
              :m (SymbolRef 2 "x")
              :type (Integer
                :kind 4
              )
              :value nil
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
        ]
      )
    }
  )
  :items []
)

See Also

StructConstant, Struct, StructInstanceMember, StructType