DictConstant

A dictionary value built from its entries.

声明

语法

DictConstant(expr* keys, expr* values, ttype type)

参数

Argument

描述

keys

the keys, in order.

values

the values, in the same order.

type

the dictionary type of the result.

返回值

The value of the expression.

描述

{k: v}. keys and values are parallel: the entry i maps keys[i] to values[i].

示例

(DictConstant
  :keys [
    (IntegerConstant
      :n 1
      :type (Integer
        :kind 4
      )
      :intboz_type :Decimal
    )
  ]
  :values [
    (RealConstant
      :r 1.5
      :type (Real
        :kind 4
      )
    )
  ]
  :type (Dict
    :key_type (Integer
      :kind 4
    )
    :value_type (Real
      :kind 4
    )
  )
)

It comes from this complete ASR text document:

(TranslationUnit
  :symtab (SymbolTable
    :id 0
    :symbols {
      "main" (Program
        :symtab (SymbolTable
          :id 1
          :symbols {
            "d" (Variable
              :parent_symtab 1
              :name "d"
              :dependencies []
              :intent :Local
              :symbolic_value nil
              :value nil
              :storage :Default
              :type (Dict
                :key_type (Integer
                  :kind 4
                )
                :value_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 []
            )
            "i" (Variable
              :parent_symtab 1
              :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 1
              :name "p"
              :dependencies []
              :intent :Local
              :symbolic_value nil
              :value nil
              :storage :Default
              :type (Logical
                :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 []
            )
            "x" (Variable
              :parent_symtab 1
              :name "x"
              :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 "main"
        :dependencies []
        :body [
          (Assignment
            :target (Var
              :v (SymbolRef 1 "d")
            )
            :value (DictConstant
              :keys [
                (IntegerConstant
                  :n 1
                  :type (Integer
                    :kind 4
                  )
                  :intboz_type :Decimal
                )
              ]
              :values [
                (RealConstant
                  :r 1.5
                  :type (Real
                    :kind 4
                  )
                )
              ]
              :type (Dict
                :key_type (Integer
                  :kind 4
                )
                :value_type (Real
                  :kind 4
                )
              )
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
          (Assignment
            :target (Var
              :v (SymbolRef 1 "i")
            )
            :value (DictLen
              :arg (Var
                :v (SymbolRef 1 "d")
              )
              :type (Integer
                :kind 4
              )
              :value nil
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
          (Assignment
            :target (Var
              :v (SymbolRef 1 "x")
            )
            :value (DictItem
              :a (Var
                :v (SymbolRef 1 "d")
              )
              :key (IntegerConstant
                :n 1
                :type (Integer
                  :kind 4
                )
                :intboz_type :Decimal
              )
              :default (RealConstant
                :r 0.0
                :type (Real
                  :kind 4
                )
              )
              :type (Real
                :kind 4
              )
              :value nil
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
          (Assignment
            :target (Var
              :v (SymbolRef 1 "x")
            )
            :value (DictPop
              :a (Var
                :v (SymbolRef 1 "d")
              )
              :key (IntegerConstant
                :n 1
                :type (Integer
                  :kind 4
                )
                :intboz_type :Decimal
              )
              :type (Real
                :kind 4
              )
              :value nil
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
          (Assignment
            :target (Var
              :v (SymbolRef 1 "p")
            )
            :value (DictContains
              :left (Var
                :v (SymbolRef 1 "d")
              )
              :right (IntegerConstant
                :n 1
                :type (Integer
                  :kind 4
                )
                :intboz_type :Decimal
              )
              :type (Logical
                :kind 4
              )
              :value nil
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
          (DictInsert
            :a (Var
              :v (SymbolRef 1 "d")
            )
            :key (IntegerConstant
              :n 2
              :type (Integer
                :kind 4
              )
              :intboz_type :Decimal
            )
            :value (RealConstant
              :r 2.5
              :type (Real
                :kind 4
              )
            )
          )
          (DictClear
            :a (Var
              :v (SymbolRef 1 "d")
            )
          )
        ]
      )
    }
  )
  :items []
)

也可以看看

Dict, DictItem, DictInsert