Class SwitchCaseOrChainGenerator
java.lang.Object
org.ek9lang.compiler.phase7.generator.AbstractGenerator
org.ek9lang.compiler.phase7.generator.SwitchCaseOrChainGenerator
Generates short-circuit OR chains for multiple switch case expressions.
Example: case 'D', 'A', 'Z' generates:
text._eq('D') OR (text._eq('A') OR text._eq('Z'))
Uses LOGICAL_OR_BLOCK for efficient short-circuit evaluation: - If first comparison is TRUE → return immediately (skip remaining) - If FALSE → evaluate next comparison (recursively)
Backend Benefits: - JVM: Generates IFNE jumps for early exit - LLVM: Generates conditional branches with proper PHI nodes
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordResult of comparison generation. -
Field Summary
Fields inherited from class AbstractGenerator
debugInfoCreator, instructionBuilder, stackContext -
Constructor Summary
ConstructorsConstructorDescriptionSwitchCaseOrChainGenerator(IRGenerationContext stackContext, VariableMemoryManagement variableMemoryManagement, GeneratorSet generators) -
Method Summary
Modifier and TypeMethodDescriptiongenerateOrChain(List<EK9Parser.CaseExpressionContext> caseExpressions, SwitchStatementGenerator.EvalVariable evalVariable, String conditionScopeId) Generate OR chain for multiple case expressions with short-circuit evaluation.Methods inherited from class AbstractGenerator
createTempVariable, createTempVariableFromContext, extractReturnType, getRecordedSymbolOrException
-
Constructor Details
-
SwitchCaseOrChainGenerator
public SwitchCaseOrChainGenerator(IRGenerationContext stackContext, VariableMemoryManagement variableMemoryManagement, GeneratorSet generators)
-
-
Method Details
-
generateOrChain
public SwitchCaseOrChainGenerator.ComparisonResult generateOrChain(List<EK9Parser.CaseExpressionContext> caseExpressions, SwitchStatementGenerator.EvalVariable evalVariable, String conditionScopeId) Generate OR chain for multiple case expressions with short-circuit evaluation.- Parameters:
caseExpressions- List of case expression contextsevalVariable- The switch evaluation variable detailsconditionScopeId- Scope for condition evaluation- Returns:
- ComparisonResult with final result variable, instructions, and primitive condition
-