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
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 Summary
FieldsModifier and TypeFieldDescriptionprotected final DebugInfoCreatorprotected final IRInstructionBuilderprotected final IRGenerationContext -
Constructor Summary
ConstructorsConstructorDescriptionAbstractGenerator(IRGenerationContext stackContext) Constructor accepting only IRGenerationContext - the single source of state. -
Method Summary
Modifier and TypeMethodDescriptionprotected VariableDetailscreateTempVariable(DebugInfo debugInfo) Create a temporary variable with associated debug info.protected VariableDetailscreateTempVariableFromContext(org.antlr.v4.runtime.tree.ParseTree ctx) Create a temporary variable with debug info extracted from parse tree context.protected ISymbolextractReturnType(org.antlr.v4.runtime.tree.ParseTree ctx, ISymbol fallbackSymbol) Extract return type from a CallSymbol's resolved method.protected ISymbolgetRecordedSymbolOrException(org.antlr.v4.runtime.tree.ParseTree node)
-
Field Details
-
stackContext
-
debugInfoCreator
-
instructionBuilder
-
-
Constructor Details
-
AbstractGenerator
AbstractGenerator(IRGenerationContext stackContext) Constructor accepting only IRGenerationContext - the single source of state.
-
-
Method Details
-
getRecordedSymbolOrException
-
createTempVariable
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
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 symbolfallbackSymbol- Symbol to use if resolved method has no return type- Returns:
- The return type of the operation
-