Class AbstractAssertExprGenerator
java.lang.Object
org.ek9lang.compiler.phase7.generator.AbstractGenerator
org.ek9lang.compiler.phase7.generator.AbstractAssertExprGenerator
- Direct Known Subclasses:
AssertDoesNotThrowExprGenerator, AssertThrowsExprGenerator
Base class for assert expression generators (assertThrows, assertDoesNotThrow).
Extracts common code for:
- Scope management for expression body evaluation
- Expression text truncation for error messages
- Body instruction generation pattern
Follows the AbstractShortCircuitGenerator pattern of extracting ~85% common logic into a base class while allowing subclasses to handle instruction-specific creation.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static final recordResult of building the assertion expression body. -
Field Summary
FieldsFields inherited from class AbstractGenerator
debugInfoCreator, instructionBuilder, MAX_MESSAGE_LENGTH, stackContext, typeNameOrException -
Constructor Summary
ConstructorsConstructorDescriptionAbstractAssertExprGenerator(IRGenerationContext stackContext, GeneratorSet generators) Constructor accepting IRGenerationContext and GeneratorSet. -
Method Summary
Modifier and TypeMethodDescriptionbuildAssertionBody(EK9Parser.ExpressionContext exprCtx, DebugInfo debugInfo) Build the assertion body with proper scope management.
-
Field Details
-
generators
-
-
Constructor Details
-
AbstractAssertExprGenerator
AbstractAssertExprGenerator(IRGenerationContext stackContext, GeneratorSet generators) Constructor accepting IRGenerationContext and GeneratorSet.- Parameters:
stackContext- The IR generation context for state managementgenerators- The set of generators for delegating expression generation
-
-
Method Details
-
buildAssertionBody
protected AbstractAssertExprGenerator.AssertBodyResult buildAssertionBody(EK9Parser.ExpressionContext exprCtx, DebugInfo debugInfo) Build the assertion body with proper scope management.This handles the common pattern of:
- Creating a scope for expression evaluation
- Entering the scope in both stack context and IR
- Generating IR for the expression
- Exiting the scope in both IR and stack context
- Truncating expression text for error messages
- Parameters:
exprCtx- The expression context to generate IR fordebugInfo- The debug info for source location- Returns:
- AssertBodyResult containing body instructions, scope ID, and expression text
-