Class SwitchStatementGenerator
java.lang.Object
org.ek9lang.compiler.phase7.generator.AbstractGenerator
org.ek9lang.compiler.phase7.generator.SwitchStatementGenerator
- All Implemented Interfaces:
Function<EK9Parser.SwitchStatementExpressionContext, List<IRInstr>>
public final class SwitchStatementGenerator
extends AbstractGenerator
implements Function<EK9Parser.SwitchStatementExpressionContext, List<IRInstr>>
Generates IR for switch statements and expressions using CONTROL_FLOW_CHAIN.
Follows the same pattern as IfStatementGenerator.
Supports both statement and expression forms:
- Statement form:
switch expr- no return value - Expression form:
result <- switch expr- returns value assigned to return variable
Current implementation supports:
- Literal case comparisons (case 1, case 2, etc.)
- Integer type evaluation variable
- Default case
- Guard variables with all operators (<-, :=, :=?, ?=)
- Expression form with ARC-safe result assignment
For guards with guard checks (<-, ?= operators), if the guard fails
(null or unset), the switch is skipped entirely (consistent with WHILE/FOR/TRY guards).
Note: Guards are NOT supported in expression forms (enforced by semantic analysis).
NOT yet supported: - Enum case comparisons - Multiple literals per case (case 1, 2, 3) - Expression cases (case < 12, case > 50)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordRecord to hold evaluation variable information. -
Field Summary
Fields inherited from class AbstractGenerator
debugInfoCreator, instructionBuilder, stackContext, typeNameOrException -
Constructor Summary
ConstructorsConstructorDescriptionSwitchStatementGenerator(IRGenerationContext stackContext, GeneratorSet generators) -
Method Summary
Modifier and TypeMethodDescriptionMethods inherited from class AbstractGenerator
createTempVariable, createTempVariableFromContext, extractReturnType, getRecordedSymbolOrException, processBlockStatements, validateNoPreFlowStatement, validateStatementFormOnly
-
Constructor Details
-
SwitchStatementGenerator
-
-
Method Details
-
apply
- Specified by:
applyin interfaceFunction<EK9Parser.SwitchStatementExpressionContext, List<IRInstr>>
-