Class AbstractAssertExprGenerator

java.lang.Object
org.ek9lang.compiler.phase7.generator.AbstractGenerator
org.ek9lang.compiler.phase7.generator.AbstractAssertExprGenerator
Direct Known Subclasses:
AssertDoesNotThrowExprGenerator, AssertThrowsExprGenerator

abstract class AbstractAssertExprGenerator extends AbstractGenerator
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.

  • Field Details

  • Constructor Details

    • AbstractAssertExprGenerator

      AbstractAssertExprGenerator(IRGenerationContext stackContext, GeneratorSet generators)
      Constructor accepting IRGenerationContext and GeneratorSet.
      Parameters:
      stackContext - The IR generation context for state management
      generators - 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 for
      debugInfo - The debug info for source location
      Returns:
      AssertBodyResult containing body instructions, scope ID, and expression text