Select¶
A select case construct.
Declaration¶
Syntax¶
Select(identifier? name, expr test, case_stmt* body, stmt* default,
bool enable_fall_through)
Arguments¶
Argument |
Description |
|---|---|
|
the construct name, or |
|
the expression the cases are matched against. |
|
the cases, each a case_stmt. |
|
the statements of |
|
|
Return values¶
None.
Description¶
The cases are checked in order and at most one runs. A case is either a
CaseStmt, holding a list of values to match,
or a CaseStmt_Range, holding a range.
test must be integer, character or logical; a real selector is not allowed,
which is what makes the construct implementable as a jump table.
Examples¶
An ASR text document that uses it:
(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 []
)