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 | None | The Else branch needs no condition. The last header's Else offset names the first instruction of its body. |
| None (synthesized) | Jump |
The trailing jump at the end of each branch's body. Node is null; Target is the End If closer. |
| None (synthesized) | Jump |
The End If closer, on the End If line: a jump to the next instruction. Every branch ends there. |
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 theEnd Ifcloser. - After a branch's body runs, the synthesized trailing
Jumpgoes to theEnd Ifcloser, where a step or a breakpoint stops.
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).- After every branch's body, lowering emits a synthesized, unconditional
Jumpto theEnd Ifcloser, even for the last branch (RD-VBAL §3.5.3 Lowering Block Statements).