SelectRank

A select rank construct: dispatch on the rank of an assumed-rank argument.

Declaration

Syntax

SelectRank(identifier? name, expr selector, rank_stmt* body,
    stmt* default)

Arguments

Argument

Description

name

the construct name, or nil.

selector

the assumed-rank dummy argument being examined.

body

the branches, each a rank_stmt matching one rank.

default

the statements of rank default.

Return values

None.

Description

An assumed-rank dummy argument, declared dimension(..), has no rank until it is called. select rank is what gives it one: inside a branch the argument has the branch’s rank and can be indexed and sectioned normally.

Examples

(SelectRank
  :name nil
  :selector (Var
    :v (SymbolRef 2 "a")
  )
  :body [
    (RankExpr
      :rank (IntegerConstant
        :n 1
        :type (Integer
          :kind 4
        )
        :intboz_type :Decimal
      )
      :body [
        (Assignment
          :target (Var
            :v (SymbolRef 2 "n")
          )
          :value (IntegerConstant
            :n 1
            :type (Integer
              :kind 4
            )
            :intboz_type :Decimal
          )
          :overloaded nil
          :realloc_lhs false
          :move_allocation false
        )
      ]
    )
  ]
  :default [
    (Assignment
      :target (Var
        :v (SymbolRef 2 "n")
      )
      :value (IntegerConstant
        :n 0
        :type (Integer
          :kind 4
        )
        :intboz_type :Decimal
      )
      :overloaded nil
      :realloc_lhs false
      :move_allocation false
    )
  ]
)

It comes from this complete ASR text document:

(TranslationUnit
  :symtab (SymbolTable
    :id 0
    :symbols {
      "m" (Module
        :symtab (SymbolTable
          :id 1
          :symbols {
            "show" (Function
              :symtab (SymbolTable
                :id 2
                :symbols {
                  "a" (Variable
                    :parent_symtab 2
                    :name "a"
                    :dependencies []
                    :intent :In
                    :symbolic_value nil
                    :value nil
                    :storage :Default
                    :type (Array
                      :type (Integer
                        :kind 4
                      )
                      :dims []
                      :physical_type :AssumedRankArray
                    )
                    :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 []
                  )
                  "n" (Variable
                    :parent_symtab 2
                    :name "n"
                    :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 []
                  )
                }
              )
              :name "show"
              :function_signature (FunctionType
                :arg_types [
                  (Array
                    :type (Integer
                      :kind 4
                    )
                    :dims []
                    :physical_type :AssumedRankArray
                  )
                ]
                :return_var_type nil
                :abi :Source
                :deftype :Implementation
                :bindc_name nil
                :elemental false
                :pure false
                :module false
                :inline false
                :static false
                :restrictions []
                :is_restriction false
              )
              :dependencies []
              :args [
                (Var
                  :v (SymbolRef 2 "a")
                )
              ]
              :body [
                (SelectRank
                  :name nil
                  :selector (Var
                    :v (SymbolRef 2 "a")
                  )
                  :body [
                    (RankExpr
                      :rank (IntegerConstant
                        :n 1
                        :type (Integer
                          :kind 4
                        )
                        :intboz_type :Decimal
                      )
                      :body [
                        (Assignment
                          :target (Var
                            :v (SymbolRef 2 "n")
                          )
                          :value (IntegerConstant
                            :n 1
                            :type (Integer
                              :kind 4
                            )
                            :intboz_type :Decimal
                          )
                          :overloaded nil
                          :realloc_lhs false
                          :move_allocation false
                        )
                      ]
                    )
                  ]
                  :default [
                    (Assignment
                      :target (Var
                        :v (SymbolRef 2 "n")
                      )
                      :value (IntegerConstant
                        :n 0
                        :type (Integer
                          :kind 4
                        )
                        :intboz_type :Decimal
                      )
                      :overloaded nil
                      :realloc_lhs false
                      :move_allocation false
                    )
                  ]
                )
              ]
              :return_var nil
              :access :Public
              :deterministic false
              :side_effect_free false
              :module_file 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

rank_stmt, SelectType, ArrayRank