Enum

An enumeration definition.

Declaration

Syntax

Enum(symbol_table symtab, identifier name, identifier* dependencies,
    identifier* members, abi abi, access access,
    enumtype enum_value_type, ttype type, symbol? parent)

Arguments

Argument

Description

symtab

the symbol table of the enumeration, holding one Variable per enumerator with its value in symbolic_value and value.

name

the name of the enumeration.

dependencies

the names of the symbols the definition refers to.

members

the names of the enumerators, in declaration order.

abi

Source, or BindC for enum, bind(c).

access

Public or Private.

enum_value_type

how the enumerator values are distributed; see enumtype. It tells a backend whether the values can be treated as an index.

type

the integer type the enumerators are stored in.

parent

reserved for an extended enumeration; nil today.

Return values

None.

Description

Enum defines a set of named integer constants. Every enumerator is a Variable in symtab with storage=Parameter and a compile time value, so an enumerator used in an expression needs nothing beyond the ordinary constant folding.

enum_value_type records the shape of the value set: IntegerConsecutiveFromZero allows a backend to use an enumerator directly as a jump table index, while NonInteger forbids arithmetic on the values.

Examples

An ASR text document that uses it:

(TranslationUnit
  :symtab (SymbolTable
    :id 0
    :symbols {
      "m" (Module
        :symtab (SymbolTable
          :id 1
          :symbols {
            "color" (Enum
              :symtab (SymbolTable
                :id 2
                :symbols {
                  "green" (Variable
                    :parent_symtab 2
                    :name "green"
                    :dependencies []
                    :intent :Local
                    :symbolic_value (IntegerConstant
                      :n 1
                      :type (Integer
                        :kind 4
                      )
                      :intboz_type :Decimal
                    )
                    :value (IntegerConstant
                      :n 1
                      :type (Integer
                        :kind 4
                      )
                      :intboz_type :Decimal
                    )
                    :storage :Parameter
                    :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 []
                  )
                  "red" (Variable
                    :parent_symtab 2
                    :name "red"
                    :dependencies []
                    :intent :Local
                    :symbolic_value (IntegerConstant
                      :n 0
                      :type (Integer
                        :kind 4
                      )
                      :intboz_type :Decimal
                    )
                    :value (IntegerConstant
                      :n 0
                      :type (Integer
                        :kind 4
                      )
                      :intboz_type :Decimal
                    )
                    :storage :Parameter
                    :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 []
                  )
                }
              )
              :name "color"
              :dependencies []
              :members [
                "red"
                "green"
              ]
              :abi :Source
              :access :Public
              :enum_value_type :IntegerConsecutiveFromZero
              :type (Integer
                :kind 4
              )
              :parent nil
            )
          }
        )
        :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

EnumType, EnumConstructor, EnumValue, EnumName, Struct