Class AbstractGenerator

java.lang.Object
org.ek9lang.compiler.phase7.generator.AbstractGenerator
Direct Known Subclasses:
AbstractShortCircuitGenerator, AbstractVariableDeclGenerator, AssertStmtGenerator, AssignExpressionToSymbol, AssignmentExprInstrGenerator, AssignmentStmtGenerator, BinaryOperationGenerator, BlockStmtInstrGenerator, CallInstrGenerator, ControlFlowChainGenerator, ExprInstrGenerator, ForInGenerator, ForRangeGenerator, ForStatementGenerator, GuardedAssignmentBlockGenerator, IfStatementGenerator, ListLiteralGenerator, ObjectAccessInstrGenerator, PrimaryReferenceGenerator, QuestionBlockGenerator, StmtInstrGenerator, SwitchCaseOrChainGenerator, SwitchStatementGenerator, UnaryOperationGenerator, WhileStatementGenerator

abstract class AbstractGenerator extends Object
Acts as base for most generators as they all require the context and in most cases need to generate debug information.

Uses stack-based IRGenerationContext for state management, eliminating parameter threading.

  • Field Details

  • Constructor Details

    • AbstractGenerator

      AbstractGenerator(IRGenerationContext stackContext)
      Constructor accepting only IRGenerationContext - the single source of state.
  • Method Details

    • getRecordedSymbolOrException

      protected ISymbol getRecordedSymbolOrException(org.antlr.v4.runtime.tree.ParseTree node)
    • createTempVariable

      protected VariableDetails createTempVariable(DebugInfo debugInfo)
      Create a temporary variable with associated debug info. This consolidates the common pattern of generating a temp name and wrapping it in VariableDetails.
      Parameters:
      debugInfo - The debug information for this variable
      Returns:
      VariableDetails containing the temp variable name and debug info
    • createTempVariableFromContext

      protected VariableDetails createTempVariableFromContext(org.antlr.v4.runtime.tree.ParseTree ctx)
      Create a temporary variable with debug info extracted from parse tree context. This consolidates the pattern of: createDebugInfo(ctx) → createTempVariable(debugInfo). Used for accurate position tracking of operands in binary/unary operations.
      Parameters:
      ctx - The parse tree context to extract position from
      Returns:
      VariableDetails containing the temp variable name and context-specific debug info
    • extractReturnType

      protected ISymbol extractReturnType(org.antlr.v4.runtime.tree.ParseTree ctx, ISymbol fallbackSymbol)
      Extract return type from a CallSymbol's resolved method. Handles the pattern: CallSymbol → MethodSymbol/FunctionSymbol → returning type. Falls back to expression type if not a CallSymbol.
      Parameters:
      ctx - The parse tree context containing the expression symbol
      fallbackSymbol - Symbol to use if resolved method has no return type
      Returns:
      The return type of the operation