Class GuardedScopeOrchestrator
Each control flow construct follows an identical template:
- Create debug info and enter outer scope
- Evaluate guard variable (if present)
- Process returning param for expression form
- Generate core body (DIFFERS per construct — supplied as lambda)
- Wrap with guard entry check or scope enter/exit
- Exit outer scope
Two orchestration methods handle different core body types:
orchestrate(ParseTree, EK9Parser.PreFlowStatementContext, EK9Parser.ReturningParamContext, Function)— core producesList<IRInstr>(for-range, for-in, try-catch). No-guard path wraps body with explicitSCOPE_ENTER/EXIT.orchestrateChain(ParseTree, EK9Parser.PreFlowStatementContext, EK9Parser.ReturningParamContext, Function)— core producesControlFlowChainDetails(while, do-while). No-guard path delegates toControlFlowChainGeneratorwhich manages scope internally.
For guards with entry checks (<-, :=?, ?= operators), the guard is checked
ONCE at entry. If the check fails, the entire body is skipped via an IF wrapper.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordContext record passed to core generator lambdas. -
Field Summary
Fields inherited from class AbstractGenerator
debugInfoCreator, instructionBuilder, MAX_MESSAGE_LENGTH, stackContext, typeNameOrException -
Constructor Summary
ConstructorsConstructorDescriptionGuardedScopeOrchestrator(IRGenerationContext stackContext, GeneratorSet generators) -
Method Summary
Modifier and TypeMethodDescriptionorchestrate(org.antlr.v4.runtime.tree.ParseTree ctx, EK9Parser.PreFlowStatementContext preFlowStmt, EK9Parser.ReturningParamContext returningParam, Function<GuardedScopeOrchestrator.OrchestratorContext, List<IRInstr>> coreGenerator) Orchestrate for constructs whose core producesList<IRInstr>.orchestrateChain(org.antlr.v4.runtime.tree.ParseTree ctx, EK9Parser.PreFlowStatementContext preFlowStmt, EK9Parser.ReturningParamContext returningParam, Function<GuardedScopeOrchestrator.OrchestratorContext, ControlFlowChainDetails> coreGenerator) Orchestrate for constructs whose core producesControlFlowChainDetails.Methods inherited from class AbstractGenerator
addCoverageProbe, createTempVariable, createTempVariableFromContext, extractReturnType, getRecordedSymbolOrException, processBlockStatements, processBlockStatements, truncateMessage, truncateMessage, validateNoPreFlowStatement, validateStatementFormOnly
-
Constructor Details
-
GuardedScopeOrchestrator
GuardedScopeOrchestrator(IRGenerationContext stackContext, GeneratorSet generators)
-
-
Method Details
-
orchestrate
public List<IRInstr> orchestrate(org.antlr.v4.runtime.tree.ParseTree ctx, EK9Parser.PreFlowStatementContext preFlowStmt, EK9Parser.ReturningParamContext returningParam, Function<GuardedScopeOrchestrator.OrchestratorContext, List<IRInstr>> coreGenerator) Orchestrate for constructs whose core producesList<IRInstr>. Used by for-range, for-in, and try-catch generators.No-guard path adds explicit
SCOPE_ENTER/EXITaround return variable setup and core body. Guard path usesLoopGuardHelper.wrapExpressionFormWithGuardEntryCheck(GuardVariableDetails, List, List, String, DebugInfo)which handles both statement and expression forms (empty returnVariableSetup for statement form).- Parameters:
ctx- The parse tree context for debug infopreFlowStmt- Pre-flow statement with guard (may be null)returningParam- Returning param for expression form (may be null)coreGenerator- Lambda that generates the core body instructions- Returns:
- Complete IR instructions with scope and guard wrapping
-
orchestrateChain
public List<IRInstr> orchestrateChain(org.antlr.v4.runtime.tree.ParseTree ctx, EK9Parser.PreFlowStatementContext preFlowStmt, EK9Parser.ReturningParamContext returningParam, Function<GuardedScopeOrchestrator.OrchestratorContext, ControlFlowChainDetails> coreGenerator) Orchestrate for constructs whose core producesControlFlowChainDetails. Used by while and do-while generators.No-guard path delegates to
ControlFlowChainGeneratorwhich addsSCOPE_ENTER/EXITinternally, so no explicit scope instructions are added here. Guard path distinguishes expression form (with return variable) from statement form: expression form wraps the chain instruction with return variable setup outside IF, statement form wraps directly without return variable.- Parameters:
ctx- The parse tree context for debug infopreFlowStmt- Pre-flow statement with guard (may be null)returningParam- Returning param for expression form (may be null)coreGenerator- Lambda that generates the core ControlFlowChainDetails- Returns:
- Complete IR instructions with scope and guard wrapping
-