5.4.2.8 If Statement
Note
This section describes the implementation of MS-VBAL §5.4.2.8 If Statement.
Syntax
| AST node | Instruction kind(s) | Notes |
|---|---|---|
| IfBlockStatementNode | ConditionalBranch |
The If header. |
| ElseIfBlockStatementNode | ConditionalBranch |
An ElseIf header. |
| ElseBlockStatementNode | — | The Else branch needs no condition. The last header's Else offset names the first instruction of its body. |
| — (synthesized) | Jump |
The trailing jump at the end of each branch's body. Node is null; Target is right past the whole construct. |
See RD-VBAL §3.4.1 Block Statements and RD-VBAL §3.5.2 Instruction.
Runtime Semantics
The executor dispatches ConditionalBranch for an If or ElseIf header, or a single-line If
(RD-VBAL §5.4.2.9 Single-line If Statement), with a Boolean
condition.
- Evaluate the header's condition, forced to
BooleanbyConditionEvaluator(MS-VBAL §5.5.1.2.2 Let-coercion to and from Boolean). - When the condition is
True, fall through into the branch's body. - When the condition is
False, go to the header'sElseoffset: the next header in the chain, the first instruction of theElsebody, or right past the whole construct. - After a branch's body runs, the synthesized trailing
Jumpgoes right past the whole construct.
A condition is not coerced through an operator node, because a condition has no operator of its own in source:
If x Then let-coerces x without any (...).
Implementation
ProcedureExecutordispatchesConditionalBranch.RDCore.Runtime.Execution.ConditionEvaluatorforces the condition toBoolean. It callsVBBooleanLetCoercionRuntimeSemanticsdirectly, rather than through an operator node (RD-VBAL §3.5.4 Execution).- An
Ifblock needs no synthesized closer: leaving the last branch, or theElsebranch, already reaches the offset that the construct's ownEnd/Elsechaining designates. - After every branch's body, lowering emits a synthesized, unconditional
Jumpto right past the whole construct, even for the last branch (RD-VBAL §3.5.3 Lowering Block Statements).
⏮️ RD-VBAL §5.4.2.7 Exit Do Statement | ⏭️ RD-VBAL §5.4.2.9 Single-line If Statement