Class StaticTypesSwitchExpressionWriter
java.lang.Object
org.codehaus.groovy.classgen.asm.SwitchExpressionWriter
org.codehaus.groovy.classgen.asm.sc.StaticTypesSwitchExpressionWriter
Static-compilation writer for
SwitchExpression. Emits
tableswitch / lookupswitch when the selector and labels are
constants of a type javac would switch on, and otherwise the
isCase method selected by the type checker as a direct call.- Since:
- 6.0.0
-
Field Summary
Fields inherited from class org.codehaus.groovy.classgen.asm.SwitchExpressionWriter
controller -
Constructor Summary
ConstructorsConstructorDescriptionCreates a switch-expression writer for statically compiled methods. -
Method Summary
Modifier and TypeMethodDescriptionprotected ClassNodeprepareSelectorType(OperandStack operandStack) Keeps the selector as visited — boxing is deferred until a path actually needs a reference (isCase or a null check on a wrapper).protected voidwriteIsCaseComparison(CaseStatement caseStatement, int selectorIndex, ClassNode selectorType) Emits theisCasecall selected by the type checker as a direct method call viaAsmClassGenerator.visitMethodCallExpression(org.codehaus.groovy.ast.expr.MethodCallExpression), which reachesStaticInvocationWriter.writeDirectMethodCall.protected booleanwriteOptimizedSwitch(SwitchExpression expression, int selectorIndex, ClassNode selectorType) Attempts a specialized dispatch (tableswitch / lookupswitch).Methods inherited from class org.codehaus.groovy.classgen.asm.SwitchExpressionWriter
enumConstantCount, enumConstantName, intConstant, isIntegralType, isIntegralWrapper, resolveResultType, stringConstant, throwIncompatibleClassChangeError, throwUnmatchedSelector, unwrapEnumType, writeDefaultOrThrow, writeSwitchExpression, writeYield
-
Constructor Details
-
StaticTypesSwitchExpressionWriter
Creates a switch-expression writer for statically compiled methods.- Parameters:
controller- the static types writer controller
-
-
Method Details
-
prepareSelectorType
Keeps the selector as visited — boxing is deferred until a path actually needs a reference (isCase or a null check on a wrapper).- Overrides:
prepareSelectorTypein classSwitchExpressionWriter
-
writeOptimizedSwitch
protected boolean writeOptimizedSwitch(SwitchExpression expression, int selectorIndex, ClassNode selectorType) Description copied from class:SwitchExpressionWriterAttempts a specialized dispatch (tableswitch / lookupswitch). The base writer has none; static compilation overrides this.- Overrides:
writeOptimizedSwitchin classSwitchExpressionWriter- Returns:
trueif specialized bytecode was emitted
-
writeIsCaseComparison
protected void writeIsCaseComparison(CaseStatement caseStatement, int selectorIndex, ClassNode selectorType) Emits theisCasecall selected by the type checker as a direct method call viaAsmClassGenerator.visitMethodCallExpression(org.codehaus.groovy.ast.expr.MethodCallExpression), which reachesStaticInvocationWriter.writeDirectMethodCall. A literalcase nullis identity, notDGM.isCase(Object,Object)(which NPEs). Any other arm must already carryStaticTypesMarker.DIRECT_METHOD_CALL_TARGETon theCaseStatement; missing targets are a type-checking error except underTypeCheckingMode.SKIP.- Overrides:
writeIsCaseComparisonin classSwitchExpressionWriter
-