Class IRGenerationContext

java.lang.Object
org.ek9lang.compiler.phase7.generation.IRGenerationContext

public class IRGenerationContext extends Object
Central state management for IR generation, following the proven SymbolsAndScopes pattern.

This context provides stack-based scope management that eliminates parameter threading throughout the IR generation process. It manages the transient stack of scope contexts, provides debug information management, and handles instruction building coordination.

Like SymbolsAndScopes, this class provides the shared state management that allows focused helpers to work together cleanly without complex parameter passing.

  • Constructor Details

    • IRGenerationContext

      public IRGenerationContext(IRContext irContext)
      Create a new IR generation context with existing IRContext. This preserves the original IRContext state including prefix counters.
  • Method Details

    • enterScope

      public void enterScope(String scopeId, DebugInfo debugInfo, IRFrameType frameType)
      Enter a new IR scope context.
    • enterMethodScope

      public void enterMethodScope(String scopeId, DebugInfo debugInfo, IRFrameType frameType)
      Enter a method/function scope with fresh IRContext for counter isolation. Creates new IRContext via copy constructor to ensure fresh temp var and label counters.
    • enterScope

      public void enterScope(String scopeId, DebugInfo debugInfo, IRFrameType frameType, boolean hasLeftHandSide)
      Enter a new IR scope with left-hand side indication.
    • enterScope

      public void enterScope(String scopeId, DebugInfo debugInfo, IRFrameType frameType, Object contextData)
      Enter a new IR scope with context data.
    • enterScope

      public void enterScope(String scopeId, DebugInfo debugInfo, IRFrameType frameType, boolean hasLeftHandSide, Object contextData)
      Enter a new IR scope with full parameters.
    • exitScope

      public void exitScope()
      Exit the current IR scope.
    • currentScopeId

      public String currentScopeId()
      Get current scope ID from the stack.
    • currentDebugInfo

      public Optional<DebugInfo> currentDebugInfo()
      Get current debug info from the stack.
    • hasLeftHandSide

      public boolean hasLeftHandSide()
      Check if current scope has left-hand side.
    • currentFrameType

      public IRFrameType currentFrameType()
      Get current frame type.
    • createDebugInfo

      public DebugInfo createDebugInfo(org.antlr.v4.runtime.tree.ParseTree ctx)
      Create debug info from a parse context.
    • createDebugInfo

      public DebugInfo createDebugInfo(Ek9Token token)
      Create debug info from a token.
    • createDebugInfo

      public DebugInfo createDebugInfo(org.antlr.v4.runtime.Token token)
      Create debug info from an ANTLR token.
    • createDebugInfo

      public DebugInfo createDebugInfo(IToken token)
      Create debug info from an EK9 IToken.
    • getCurrentIRContext

      public IRContext getCurrentIRContext()
      Get current IRContext from stack frame (traverses up to find method-level IRContext). Always creates a fresh IRContext for proper counter isolation if none exists.
    • generateTempName

      public String generateTempName()
      Generate a unique temporary variable name.
    • generateScopeId

      public String generateScopeId(String prefix)
      Generate a unique scope identifier.
    • generateBlockLabel

      public String generateBlockLabel(String prefix)
      Generate a unique block label.
    • generateLabelName

      public String generateLabelName(String prefix)
      Generate a unique label name.
    • createBasicDetails

      public BasicDetails createBasicDetails()
      Create BasicDetails using current stack context.
    • createBasicDetails

      public BasicDetails createBasicDetails(String scopeId)
      Create BasicDetails with custom scope ID but current debug info.
    • createVariableDetails

      public VariableDetails createVariableDetails(String variableName)
      Create VariableDetails using current stack context.
    • createVariableDetails

      public VariableDetails createVariableDetails(String variableName, String scopeId)
      Create VariableDetails with custom scope ID.
    • addInstruction

      public void addInstruction(IRInstr instruction)
      Add instruction to current instruction list.
    • addInstructions

      public void addInstructions(List<IRInstr> instructions)
      Add multiple instructions to current instruction list.
    • extractInstructions

      public List<IRInstr> extractInstructions()
      Get current instruction list and clear it.
    • getCurrentInstructions

      public List<IRInstr> getCurrentInstructions()
      Get current instruction list without clearing.
    • clearInstructions

      public void clearInstructions()
      Clear current instruction list.
    • needsResultVariable

      public boolean needsResultVariable(String returnType)
      Check if we need a result variable for the current context.
    • findFrameOfType

      public Optional<IRStackFrame> findFrameOfType(IRFrameType frameType)
      Navigate back up stack to find frame of specific type.
    • findMethodOrFunctionFrame

      public Optional<IRStackFrame> findMethodOrFunctionFrame()
      Navigate back up stack to find method or function frame.
    • findAggregateFrame

      public Optional<IRStackFrame> findAggregateFrame()
      Navigate back up stack to find aggregate frame.
    • isInFrameType

      public boolean isInFrameType(IRFrameType frameType)
      Check if we're currently in a specific frame type.
    • getParsedModule

      public ParsedModule getParsedModule()
      Get the parsed module from IRContext.
    • getCompilerFlags

      public CompilerFlags getCompilerFlags()
      Get the compiler flags from IRContext.
    • getIRContext

      public IRContext getIRContext()
      Get the underlying IR context.
    • getIRGenerationStack

      public IRGenerationStack getIRGenerationStack()
      Get the IR generation stack (for advanced operations).
    • getStackDepth

      public int getStackDepth()
      Get current stack depth (for debugging).