TypeParameter

A placeholder for a type inside a template.

Declaration

Syntax

TypeParameter(identifier param, deferred_type_attr deferred_attr, bool is_class)

Arguments

Argument

Description

param

the name of the parameter.

deferred_attr

whether the parameter’s declaration specified ABSTRACT, EXTENSIBLE, or neither. See deferred_type_attr.

is_class

whether the entity was declared CLASS(t) rather than TYPE(t). Instantiation gives such an entity a polymorphic type.

Return values

None. A type is not evaluated.

Description

Inside a Requirement or a Template the concrete types are not known yet, and a TypeParameter stands in for one. Instantiation substitutes real types for the parameters, so nothing outside a template ever holds this type.

deferred_attr records what the DEFERRED TYPE statement declared about the parameter, and it constrains both ends of the substitution: which types may be passed as an instantiation argument for the parameter, and how the parameter may be used inside the template. A non-extensible parameter can only be named by TYPE(t); an abstract one only by CLASS(t); an extensible one by either.

is_class is a property of the entity’s declaration rather than of the parameter, and it is what makes CLASS(t) work once t is substituted. Without it the entity would become a non-polymorphic variable of what may be an abstract type, which the verifier rejects; the instantiation pass reads the flag and makes the substituted StructType polymorphic exactly when it is set.

Examples

(TypeParameter
  :param "t"
  :deferred_attr :NonExtensible
  :is_class false
)

It comes from this complete ASR text document:

(TranslationUnit
  :symtab (SymbolTable
    :id 0
    :symbols {
      "m" (Module
        :symtab (SymbolTable
          :id 1
          :symbols {
            "r" (Requirement
              :symtab (SymbolTable
                :id 2
                :symbols {
                  "op" (Function
                    :symtab (SymbolTable
                      :id 3
                      :symbols {
                        "x" (Variable
                          :parent_symtab 3
                          :name "x"
                          :dependencies []
                          :intent :In
                          :symbolic_value nil
                          :value nil
                          :storage :Default
                          :type (TypeParameter
                            :param "t"
                            :deferred_attr :NonExtensible
                            :is_class false
                          )
                          :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
                        )
                        "z" (Variable
                          :parent_symtab 3
                          :name "z"
                          :dependencies []
                          :intent :ReturnVar
                          :symbolic_value nil
                          :value nil
                          :storage :Default
                          :type (TypeParameter
                            :param "t"
                            :deferred_attr :NonExtensible
                            :is_class false
                          )
                          :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
                        )
                      }
                    )
                    :name "op"
                    :function_signature (FunctionType
                      :arg_types [
                        (TypeParameter
                          :param "t"
                          :deferred_attr :NonExtensible
                          :is_class false
                        )
                      ]
                      :return_var_type (TypeParameter
                        :param "t"
                        :deferred_attr :NonExtensible
                        :is_class false
                      )
                      :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 3 "x")
                      )
                    ]
                    :body []
                    :return_var (Var
                      :v (SymbolRef 3 "z")
                    )
                    :access :Public
                    :deterministic false
                    :side_effect_free false
                    :module_file nil
                  )
                  "t" (Variable
                    :parent_symtab 2
                    :name "t"
                    :dependencies []
                    :intent :In
                    :symbolic_value nil
                    :value nil
                    :storage :Default
                    :type (TypeParameter
                      :param "t"
                      :deferred_attr :NonExtensible
                      :is_class false
                    )
                    :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
                  )
                }
              )
              :name "r"
              :args [
                "t"
                "op"
              ]
              :requires []
            )
          }
        )
        :name "m"
        :parent_module nil
        :dependencies []
        :loaded_from_mod false
        :intrinsic false
        :has_submodules false
        :global_init nil
      )
      "main" (Program
        :symtab (SymbolTable
          :id 4
          :symbols {}
        )
        :name "main"
        :dependencies []
        :body []
        :global_init nil
      )
    }
  )
  :items []
  :global_init nil
)

See Also

Template, Requirement, Function, deferred_type_attr