Class StaticTypesWriterController
java.lang.Object
org.codehaus.groovy.classgen.asm.WriterController
org.codehaus.groovy.classgen.asm.DelegatingController
org.codehaus.groovy.classgen.asm.sc.StaticTypesWriterController
An alternative
WriterController which handles static types and method
dispatch. In case of a "mixed mode" where only some methods are annotated with TypeChecked
then this writer will delegate to the classic writer controller.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanTracks whether the current member is being emitted through the static-compilation fast path.Fields inherited from class org.codehaus.groovy.classgen.asm.WriterController
optimizeForInt -
Constructor Summary
ConstructorsConstructorDescriptionStaticTypesWriterController(WriterController controller) Creates a delegating writer controller that switches between dynamic and static code-generation strategies. -
Method Summary
Modifier and TypeMethodDescriptionReturns the appropriate BinaryExpressionHelper for the current code path.Returns the CallSiteWriter responsible for generating dynamic call site infrastructure.getCallSiteWriterFor(Expression expression) Returns the CallSiteWriter for a specific expression.Returns the ClosureWriter for compiling Groovy closure literals into inner classes implementing GroovyObject and supporting variable capture.Returns the InvocationWriter for compiling method calls and dynamic function invocations into appropriate bytecode patterns.Returns the LambdaWriter for compiling Java-style lambda expressions (using the->operator) into functional interfaces.Returns the MethodReferenceExpressionWriter for compiling method reference expressions compatible with Java functional interface targets.Returns the regular dynamic call-site writer used for fallback expressions.Returns the regular dynamic invocation writer used for fallback expressions.Returns the StatementWriter for compiling Groovy statements into bytecode.Returns the TypeChooser used to select appropriate type representations for expressions during compilation, supporting both dynamic and typed paths.Returns the appropriate UnaryExpressionHelper for the current code path.voidinit(AsmClassGenerator asmClassGenerator, GeneratorContext gcon, org.objectweb.asm.ClassVisitor cv, ClassNode cn) Initializes this controller with compilation context and ASM infrastructure.booleanReturns true if the compiler is currently in fast-path mode, emitting specialized bytecode for primitive type operations.booleanGROOVY-11968: returnstruewhen the current statically compiled method contains one or more sub-expressions that will be routed through the regular (non-static) call site writer viagetCallSiteWriterFor(org.codehaus.groovy.ast.expr.Expression).voidSets the ConstructorNode for the constructor currently being compiled.voidSets the MethodNode for the method currently being compiled.Methods inherited from class org.codehaus.groovy.classgen.asm.DelegatingController
getAcg, getAssertionWriter, getBytecodeVersion, getClassName, getClassNode, getClassVisitor, getCompileStack, getConstructorNode, getContext, getCv, getInterfaceClassLoadingClass, getInternalBaseClassName, getInternalClassName, getLineNumber, getMethodNode, getMethodPointerExpressionWriter, getMethodVisitor, getOperandStack, getOutermostClass, getReturnType, getSourceUnit, isConstructor, isInGeneratedFunction, isInGeneratedFunctionConstructor, isInScriptBody, isNotClinit, isStaticConstructor, isStaticContext, isStaticMethod, resetLineNumber, setInterfaceClassLoadingClass, setLineNumber, setMethodVisitor, shouldOptimizeForInt, switchToFastPath, switchToSlowPathMethods inherited from class org.codehaus.groovy.classgen.asm.WriterController
getNextHelperMethodIndex, getSuperMethodNames, getThisType, visitLineNumber
-
Field Details
-
isInStaticallyCheckedMethod
protected boolean isInStaticallyCheckedMethodTracks whether the current member is being emitted through the static-compilation fast path.
-
-
Constructor Details
-
StaticTypesWriterController
Creates a delegating writer controller that switches between dynamic and static code-generation strategies.
-
-
Method Details
-
init
public void init(AsmClassGenerator asmClassGenerator, GeneratorContext gcon, org.objectweb.asm.ClassVisitor cv, ClassNode cn) Initializes this controller with compilation context and ASM infrastructure. Must be called exactly once before any bytecode generation operations. Sets up all supporting writers (call site, closure, lambda, etc.) and configures optimization strategies based on compiler configuration.- Overrides:
initin classDelegatingController- Parameters:
asmClassGenerator- the class generator managing the overall compilationgcon- the compilation context tracking state across the compilation unitcv- the ASM ClassVisitor for emitting bytecode directivescn- the ClassNode being compiled
-
setMethodNode
Sets the MethodNode for the method currently being compiled. Automatically clears any active constructor node, since only one can be active. Used during compilation to track which method's bytecode is being generated.- Overrides:
setMethodNodein classDelegatingController- Parameters:
mn- the MethodNode to compile, or null to deactivate
-
setConstructorNode
Sets the ConstructorNode for the constructor currently being compiled. Automatically clears any active method node, since only one can be active. Used during compilation to track which constructor's bytecode is being generated.- Overrides:
setConstructorNodein classDelegatingController- Parameters:
cn- the ConstructorNode to compile, or null to deactivate
-
methodHasDynamicResolution
public boolean methodHasDynamicResolution()GROOVY-11968: returnstruewhen the current statically compiled method contains one or more sub-expressions that will be routed through the regular (non-static) call site writer viagetCallSiteWriterFor(org.codehaus.groovy.ast.expr.Expression). The regular writer's per-method state must then be initialized at method entry.- Since:
- 6.0.0
-
isFastPath
public boolean isFastPath()Returns true if the compiler is currently in fast-path mode, emitting specialized bytecode for primitive type operations. Use this to determine whether expression helpers should apply optimizations.- Overrides:
isFastPathin classDelegatingController- Returns:
- true if fast-path compilation mode is active
-
getCallSiteWriter
Returns the CallSiteWriter responsible for generating dynamic call site infrastructure. Behavior depends on bytecode strategy: either invokedynamic for modern JVMs or traditional call-site caching for broader compatibility.- Overrides:
getCallSiteWriterin classDelegatingController
-
getCallSiteWriterFor
Returns the CallSiteWriter for a specific expression. Currently delegates to the default CallSiteWriter; reserved for future expression-specific optimization strategies.- Overrides:
getCallSiteWriterForin classDelegatingController- Parameters:
expression- the expression being processed- Returns:
- the appropriate call site writer for this expression
-
getRegularCallSiteWriter
Returns the regular dynamic call-site writer used for fallback expressions. -
getStatementWriter
Returns the StatementWriter for compiling Groovy statements into bytecode. Selection depends on optimization mode: OptimizingStatementWriter forWriterController.optimizeForInt, otherwise generic StatementWriter.- Overrides:
getStatementWriterin classDelegatingController
-
getTypeChooser
Returns the TypeChooser used to select appropriate type representations for expressions during compilation, supporting both dynamic and typed paths.- Overrides:
getTypeChooserin classDelegatingController
-
getInvocationWriter
Returns the InvocationWriter for compiling method calls and dynamic function invocations into appropriate bytecode patterns.- Overrides:
getInvocationWriterin classDelegatingController
-
getRegularInvocationWriter
Returns the regular dynamic invocation writer used for fallback expressions. -
getBinaryExpressionHelper
Returns the appropriate BinaryExpressionHelper for the current code path. Selects fast-path specialized handling whenWriterController.isFastPath()is true, otherwise delegates to the general-purpose binary expression handler. Fast-path optimization is controlled byWriterController.optimizeForInt.- Overrides:
getBinaryExpressionHelperin classDelegatingController- Returns:
- the binary expression writer for the active compilation mode
-
getMethodReferenceExpressionWriter
Returns the MethodReferenceExpressionWriter for compiling method reference expressions compatible with Java functional interface targets.- Overrides:
getMethodReferenceExpressionWriterin classDelegatingController
-
getUnaryExpressionHelper
Returns the appropriate UnaryExpressionHelper for the current code path. Selects fast-path specialized handling whenWriterController.isFastPath()is true, otherwise delegates to the general-purpose unary expression handler. Fast-path optimization is controlled byWriterController.optimizeForInt.- Overrides:
getUnaryExpressionHelperin classDelegatingController- Returns:
- the unary expression writer for the active compilation mode
-
getClosureWriter
Returns the ClosureWriter for compiling Groovy closure literals into inner classes implementing GroovyObject and supporting variable capture.- Overrides:
getClosureWriterin classDelegatingController
-
getLambdaWriter
Returns the LambdaWriter for compiling Java-style lambda expressions (using the->operator) into functional interfaces.- Overrides:
getLambdaWriterin classDelegatingController
-