Class AssertPanicExprGenerator
java.lang.Object
org.ek9lang.compiler.phase7.generator.AbstractGenerator
org.ek9lang.compiler.phase7.generator.AbstractAssertExprGenerator
org.ek9lang.compiler.phase7.generator.AssertPanicExprGenerator
- All Implemented Interfaces:
BiFunction<EK9Parser.AssertPanicExpressionContext, String, List<IRInstr>>
public final class AssertPanicExprGenerator
extends AbstractAssertExprGenerator
implements BiFunction<EK9Parser.AssertPanicExpressionContext, String, List<IRInstr>>
IR Generation for the assertPanic expression.
Generates the ASSERT_PANIC opcode for test assertions that expect an
org.ek9.lang::Panic to fire. Reuses AssertThrowsInstr (which multiplexes the
assert-family opcodes) via its assertPanic(...) factory - the catch target is fixed to
org.ek9.lang::Panic, so unlike AssertThrowsExprGenerator there is no typeDef.
Grammar: assertPanicExpression: ASSERT_PANIC LPAREN expression RPAREN
Semantics:
- Evaluates the expression within a try block
- If a Panic is caught, stores it to the result variable (success)
- If no panic thrown, throws AssertionError (failure)
- If a non-Panic throwable escapes, rethrows it (test failure)
Used in two contexts:
- Statement form:
assertPanic(mustBePositive(-1)) - Expression form:
p <- assertPanic(Rating(11))
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractAssertExprGenerator
AbstractAssertExprGenerator.AssertBodyResult -
Field Summary
Fields inherited from class AbstractAssertExprGenerator
generatorsFields inherited from class AbstractGenerator
constantCopyOnAccessLoader, debugInfoCreator, instructionBuilder, MAX_MESSAGE_LENGTH, stackContext, typeNameOrException -
Constructor Summary
ConstructorsConstructorDescriptionAssertPanicExprGenerator(IRGenerationContext stackContext, GeneratorSet generators) Constructor accepting injected GeneratorSet. -
Method Summary
Modifier and TypeMethodDescriptionapply(EK9Parser.AssertPanicExpressionContext ctx, String resultVar) Generate IR for assertPanic expression.Methods inherited from class AbstractAssertExprGenerator
buildAssertionBodyMethods inherited from class AbstractGenerator
addCoverageProbe, createTempVariable, createTempVariableFromContext, extractReturnType, getRecordedSymbolOrException, processBlockStatements, processBlockStatements, truncateMessage, truncateMessageMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface BiFunction
andThen
-
Constructor Details
-
AssertPanicExprGenerator
AssertPanicExprGenerator(IRGenerationContext stackContext, GeneratorSet generators) Constructor accepting injected GeneratorSet.
-
-
Method Details
-
apply
Generate IR for assertPanic expression.- Specified by:
applyin interfaceBiFunction<EK9Parser.AssertPanicExpressionContext, String, List<IRInstr>>- Parameters:
ctx- The ANTLR context for the assertPanic expressionresultVar- The variable to store the caught Panic (null for statement form)- Returns:
- List of IR instructions
-