Class RangeIterationHelper
java.lang.Object
org.ek9lang.compiler.phase7.generator.AbstractGenerator
org.ek9lang.compiler.phase7.generator.RangeIterationHelper
Shared helper for range iteration logic used by both for-range loops and stream for-range sources.
Extracts the body-independent parts of range iteration from ForRangeGenerator:
initialization (start/end/by evaluation, assertions, direction detection),
dispatch case generation (ascending/descending/equal), loop condition evaluation,
increment operations, and body setup (loop variable assignment).
Both ForRangeGenerator and StreamStatementGenerator delegate to this helper,
each providing their own body instructions. This eliminates ~500 lines of duplication
between for-range loops and stream for-range sources.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final recordParameters for case constructor (AscendingCase or DescendingCase).(package private) static final recordHelper record to pass initialization data between methods. -
Field Summary
Fields inherited from class AbstractGenerator
debugInfoCreator, instructionBuilder, MAX_MESSAGE_LENGTH, stackContext, typeNameOrException -
Constructor Summary
ConstructorsConstructorDescriptionRangeIterationHelper(IRGenerationContext stackContext, GeneratorSet generators) -
Method Summary
Modifier and TypeMethodDescriptiongenerateBodySetup(String loopVariableName, String currentTemp, DebugInfo debugInfo) Generate body setup: loopVariable = current.(package private) ForRangePolymorphicInstr.DispatchCasesgenerateDispatchCases(RangeIterationHelper.InitializationData initData, String loopVariableName, DebugInfo debugInfo) Generate dispatch cases with explicit IR for all three directions.(package private) RangeIterationHelper.InitializationDatagenerateInitialization(EK9Parser.ForRangeContext forRangeCtx, DebugInfo debugInfo) Generate initialization instructions for the loop.(package private) ForRangePolymorphicInstr.LoopMetadatagenerateLoopMetadata(RangeIterationHelper.InitializationData initData, String loopVariableName) Generate loop metadata containing variable names and types.Methods inherited from class AbstractGenerator
addCoverageProbe, createTempVariable, createTempVariableFromContext, extractReturnType, getRecordedSymbolOrException, processBlockStatements, processBlockStatements, truncateMessage, truncateMessage, validateNoPreFlowStatement, validateStatementFormOnly
-
Constructor Details
-
RangeIterationHelper
RangeIterationHelper(IRGenerationContext stackContext, GeneratorSet generators)
-
-
Method Details
-
generateInitialization
RangeIterationHelper.InitializationData generateInitialization(EK9Parser.ForRangeContext forRangeCtx, DebugInfo debugInfo) Generate initialization instructions for the loop. This includes: evaluating start/end/by, asserting they're set, direction detection. -
generateDispatchCases
ForRangePolymorphicInstr.DispatchCases generateDispatchCases(RangeIterationHelper.InitializationData initData, String loopVariableName, DebugInfo debugInfo) Generate dispatch cases with explicit IR for all three directions. -
generateLoopMetadata
ForRangePolymorphicInstr.LoopMetadata generateLoopMetadata(RangeIterationHelper.InitializationData initData, String loopVariableName) Generate loop metadata containing variable names and types. -
generateBodySetup
-