case_stmt

One branch of a select case construct.

Declaration

Syntax

case_stmt
    = CaseStmt(expr* test, stmt* body, bool fall_through)
    | CaseStmt_Range(expr? start, expr? end, stmt* body)

Arguments

None.

Return values

None.

Description

A branch is one of two constructors.

CaseStmt matches a list of values:

Argument

Description

test

the values this branch matches.

body

the statements of the branch.

fall_through

true when control continues into the next branch. Fortran cases never fall through; the member exists for languages whose switch does.

CaseStmt_Range matches a range, case (2:5):

Argument

Description

start

the first value of the range, or nil for case (:n).

end

the last value, or nil for case (n:).

body

the statements of the branch.

The branches of a Select are checked in order and at most one of them runs.

Examples

(CaseStmt
  :test [
    (IntegerConstant
      :n 1
      :type (Integer
        :kind 4
      )
      :intboz_type :Decimal
    )
  ]
  :body [
    (Assignment
      :target (Var
        :v (SymbolRef 1 "j")
      )
      :value (IntegerConstant
        :n 0
        :type (Integer
          :kind 4
        )
        :intboz_type :Decimal
      )
      :overloaded nil
      :realloc_lhs false
      :move_allocation false
    )
  ]
  :fall_through false
)

It comes from this complete ASR text document:

(TranslationUnit
  :symtab (SymbolTable
    :id 0
    :symbols {
      "main" (Program
        :symtab (SymbolTable
          :id 1
          :symbols {
            "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 []
            )
            "j" (Variable
              :parent_symtab 1
              :name "j"
              :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 "main"
        :dependencies []
        :body [
          (Select
            :name nil
            :test (Var
              :v (SymbolRef 1 "i")
            )
            :body [
              (CaseStmt
                :test [
                  (IntegerConstant
                    :n 1
                    :type (Integer
                      :kind 4
                    )
                    :intboz_type :Decimal
                  )
                ]
                :body [
                  (Assignment
                    :target (Var
                      :v (SymbolRef 1 "j")
                    )
                    :value (IntegerConstant
                      :n 0
                      :type (Integer
                        :kind 4
                      )
                      :intboz_type :Decimal
                    )
                    :overloaded nil
                    :realloc_lhs false
                    :move_allocation false
                  )
                ]
                :fall_through false
              )
              (CaseStmt_Range
                :start (IntegerConstant
                  :n 2
                  :type (Integer
                    :kind 4
                  )
                  :intboz_type :Decimal
                )
                :end (IntegerConstant
                  :n 5
                  :type (Integer
                    :kind 4
                  )
                  :intboz_type :Decimal
                )
                :body [
                  (Assignment
                    :target (Var
                      :v (SymbolRef 1 "j")
                    )
                    :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 1 "j")
                )
                :value (IntegerConstant
                  :n 2
                  :type (Integer
                    :kind 4
                  )
                  :intboz_type :Decimal
                )
                :overloaded nil
                :realloc_lhs false
                :move_allocation false
              )
            ]
            :enable_fall_through false
          )
        ]
      )
    }
  )
  :items []
)

See Also

Select, type_stmt, rank_stmt