minor edits
diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/DelegatingController.java b/src/main/java/org/codehaus/groovy/classgen/asm/DelegatingController.java
index 7a6198c..3029237 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/DelegatingController.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/DelegatingController.java
@@ -145,6 +145,7 @@
}
@Override
+ @Deprecated
public ClassVisitor getCv() {
return delegationController.getCv();
}
diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/WriterController.java b/src/main/java/org/codehaus/groovy/classgen/asm/WriterController.java
index daf249c..8316a3f 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/WriterController.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/WriterController.java
@@ -44,7 +44,7 @@
public class WriterController {
- private final boolean LOG_CLASSGEN = getBooleanSafe("groovy.log.classgen");
+ private static final boolean LOG_CLASSGEN = getBooleanSafe("groovy.log.classgen");
private AsmClassGenerator acg;
private MethodVisitor methodVisitor;
@@ -69,7 +69,7 @@
private InterfaceHelperClassNode interfaceClassLoadingClass;
public boolean optimizeForInt = true;
private StatementWriter statementWriter;
- private boolean fastPath = false;
+ private boolean fastPath;
private TypeChooser typeChooser;
private int bytecodeVersion = Opcodes.V1_8;
private int lineNumber = -1;
@@ -85,19 +85,19 @@
if (optOptions.isEmpty()) {
// IGNORE
} else if (Boolean.FALSE.equals(optOptions.get("all"))) {
- optimizeForInt = false;
+ this.optimizeForInt = false;
// set other optimizations options to false here
} else {
if (Boolean.TRUE.equals(optOptions.get(CompilerConfiguration.INVOKEDYNAMIC))) invokedynamic = true;
- if (Boolean.FALSE.equals(optOptions.get("int"))) optimizeForInt = false;
- if (invokedynamic) optimizeForInt = false;
+ if (Boolean.FALSE.equals(optOptions.get("int"))) this.optimizeForInt = false;
+ if (invokedynamic) this.optimizeForInt = false;
// set other optimizations options to false here
}
this.classNode = cn;
this.outermostClass = null;
- this.internalClassName = BytecodeHelper.getClassInternalName(classNode);
+ this.internalClassName = BytecodeHelper.getClassInternalName(cn);
- bytecodeVersion = chooseBytecodeVersion(invokedynamic, config.isPreviewFeatures(), config.getTargetBytecode());
+ this.bytecodeVersion = chooseBytecodeVersion(invokedynamic, config.isPreviewFeatures(), config.getTargetBytecode());
if (invokedynamic) {
this.invocationWriter = new InvokeDynamicWriter(this);
@@ -110,7 +110,7 @@
}
this.unaryExpressionHelper = new UnaryExpressionHelper(this);
- if (optimizeForInt) {
+ if (this.optimizeForInt) {
this.fastPathBinaryExpHelper = new BinaryExpressionMultiTypeDispatcher(this);
// TODO: replace with a real fast path unary expression helper when available
this.fastPathUnaryExpressionHelper = new UnaryExpressionHelper(this);
@@ -125,13 +125,13 @@
this.lambdaWriter = new LambdaWriter(this);
this.methodPointerExpressionWriter = new MethodPointerExpressionWriter(this);
this.methodReferenceExpressionWriter = new MethodReferenceExpressionWriter(this);
- this.internalBaseClassName = BytecodeHelper.getClassInternalName(classNode.getSuperClass());
+ this.internalBaseClassName = BytecodeHelper.getClassInternalName(cn.getSuperClass());
this.acg = asmClassGenerator;
this.sourceUnit = acg.getSourceUnit();
this.context = gcon;
this.compileStack = new CompileStack(this);
- this.cv = this.createClassVisitor(cv);
- if (optimizeForInt) {
+ this.cv = createClassVisitor(cv);
+ if (this.optimizeForInt) {
this.statementWriter = new OptimizingStatementWriter(this);
} else {
this.statementWriter = new StatementWriter(this);
@@ -139,7 +139,7 @@
this.typeChooser = new StatementMetaTypeChooser();
}
- private ClassVisitor createClassVisitor(final ClassVisitor cv) {
+ private static ClassVisitor createClassVisitor(final ClassVisitor cv) {
if (!LOG_CLASSGEN || cv instanceof LoggableClassVisitor) {
return cv;
}
@@ -161,16 +161,31 @@
}
}
+ //--------------------------------------------------------------------------
+
public AsmClassGenerator getAcg() {
return acg;
}
+ @Deprecated
+ public ClassVisitor getCv() {
+ return cv;
+ }
+
+ public ClassVisitor getClassVisitor() {
+ return cv;
+ }
+
+ public MethodVisitor getMethodVisitor() {
+ return methodVisitor;
+ }
+
public void setMethodVisitor(final MethodVisitor methodVisitor) {
this.methodVisitor = methodVisitor;
}
- public MethodVisitor getMethodVisitor() {
- return methodVisitor;
+ public GeneratorContext getContext() {
+ return context;
}
public CompileStack getCompileStack() {
@@ -181,52 +196,12 @@
return operandStack;
}
- public ClassNode getClassNode() {
- return classNode;
+ public SourceUnit getSourceUnit() {
+ return sourceUnit;
}
- public CallSiteWriter getCallSiteWriter() {
- return callSiteWriter;
- }
-
- public ClassVisitor getClassVisitor() {
- return cv;
- }
-
- public ClosureWriter getClosureWriter() {
- return closureWriter;
- }
-
- public LambdaWriter getLambdaWriter() {
- return lambdaWriter;
- }
-
- public ClassVisitor getCv() {
- return cv;
- }
-
- public String getInternalClassName() {
- return internalClassName;
- }
-
- public InvocationWriter getInvocationWriter() {
- return invocationWriter;
- }
-
- public BinaryExpressionHelper getBinaryExpressionHelper() {
- if (fastPath) {
- return fastPathBinaryExpHelper;
- } else {
- return binaryExpHelper;
- }
- }
-
- public MethodPointerExpressionWriter getMethodPointerExpressionWriter() {
- return methodPointerExpressionWriter;
- }
-
- public MethodReferenceExpressionWriter getMethodReferenceExpressionWriter() {
- return methodReferenceExpressionWriter;
+ public TypeChooser getTypeChooser() {
+ return typeChooser;
}
public UnaryExpressionHelper getUnaryExpressionHelper() {
@@ -237,16 +212,62 @@
}
}
+ public BinaryExpressionHelper getBinaryExpressionHelper() {
+ if (fastPath) {
+ return fastPathBinaryExpHelper;
+ } else {
+ return binaryExpHelper;
+ }
+ }
+
+ //--------------------------------------------------------------------------
+
public AssertionWriter getAssertionWriter() {
return assertionWriter;
}
- public TypeChooser getTypeChooser() {
- return typeChooser;
+ public CallSiteWriter getCallSiteWriter() {
+ return callSiteWriter;
}
- public String getInternalBaseClassName() {
- return internalBaseClassName;
+ public ClosureWriter getClosureWriter() {
+ return closureWriter;
+ }
+
+ public LambdaWriter getLambdaWriter() {
+ return lambdaWriter;
+ }
+
+ public StatementWriter getStatementWriter() {
+ return statementWriter;
+ }
+
+ public InvocationWriter getInvocationWriter() {
+ return invocationWriter;
+ }
+
+ public MethodPointerExpressionWriter getMethodPointerExpressionWriter() {
+ return methodPointerExpressionWriter;
+ }
+
+ public MethodReferenceExpressionWriter getMethodReferenceExpressionWriter() {
+ return methodReferenceExpressionWriter;
+ }
+
+ //--------------------------------------------------------------------------
+
+ public String getClassName() {
+ String className;
+ if (!classNode.isInterface() || interfaceClassLoadingClass == null) {
+ className = internalClassName;
+ } else {
+ className = BytecodeHelper.getClassInternalName(interfaceClassLoadingClass);
+ }
+ return className;
+ }
+
+ public ClassNode getClassNode() {
+ return classNode;
}
public MethodNode getMethodNode() {
@@ -267,10 +288,46 @@
this.methodNode = null;
}
- public SourceUnit getSourceUnit() {
- return sourceUnit;
+ public ClassNode getReturnType() {
+ if (methodNode != null) {
+ return methodNode.getReturnType();
+ } else if (constructorNode != null) {
+ return constructorNode.getReturnType();
+ } else {
+ throw new GroovyBugError("I spotted a return that is neither in a method nor in a constructor... I can not handle that");
+ }
}
+ public ClassNode getOutermostClass() {
+ if (outermostClass == null) {
+ List<ClassNode> outers = classNode.getOuterClasses();
+ outermostClass = !outers.isEmpty() ? outers.get(outers.size() - 1) : classNode;
+ }
+ return outermostClass;
+ }
+
+ public String getInternalClassName() {
+ return internalClassName;
+ }
+
+ public String getInternalBaseClassName() {
+ return internalBaseClassName;
+ }
+
+ public List<String> getSuperMethodNames() {
+ return superMethodNames;
+ }
+
+ public InterfaceHelperClassNode getInterfaceClassLoadingClass() {
+ return interfaceClassLoadingClass;
+ }
+
+ public void setInterfaceClassLoadingClass(final InterfaceHelperClassNode ihc) {
+ interfaceClassLoadingClass = ihc;
+ }
+
+ //
+
public boolean isStaticContext() {
if (compileStack != null && compileStack.getScope() != null) {
return compileStack.getScope().isInStaticContext();
@@ -280,28 +337,10 @@
return classNode.isStaticClass() || isStaticMethod();
}
- public boolean isInGeneratedFunction() {
- return classNode.getOuterClass() != null && isGeneratedFunction(classNode);
- }
-
- public boolean isInGeneratedFunctionConstructor() {
- return isConstructor() && isInGeneratedFunction();
- }
-
public boolean isStaticMethod() {
return methodNode != null && methodNode.isStatic();
}
- public ClassNode getReturnType() {
- if (methodNode != null) {
- return methodNode.getReturnType();
- } else if (constructorNode != null) {
- return constructorNode.getReturnType();
- } else {
- throw new GroovyBugError("I spotted a return that is neither in a method nor in a constructor... I can not handle that");
- }
- }
-
public boolean isNotClinit() {
return methodNode == null || !methodNode.getName().equals("<clinit>");
}
@@ -314,6 +353,14 @@
return constructorNode != null;
}
+ public boolean isInGeneratedFunction() {
+ return classNode.getOuterClass() != null && isGeneratedFunction(classNode);
+ }
+
+ public boolean isInGeneratedFunctionConstructor() {
+ return isConstructor() && isInGeneratedFunction();
+ }
+
/**
* @return true if we are in a script body, where all variables declared are no longer
* local variables but are properties
@@ -322,44 +369,10 @@
return classNode.isScriptBody() || (classNode.isScript() && methodNode != null && methodNode.getName().equals("run"));
}
- public String getClassName() {
- String className;
- if (!classNode.isInterface() || interfaceClassLoadingClass == null) {
- className = internalClassName;
- } else {
- className = BytecodeHelper.getClassInternalName(interfaceClassLoadingClass);
- }
- return className;
- }
-
- public ClassNode getOutermostClass() {
- if (outermostClass == null) {
- List<ClassNode> outers = classNode.getOuterClasses();
- outermostClass = !outers.isEmpty() ? outers.get(outers.size() - 1) : classNode;
- }
- return outermostClass;
- }
-
- public GeneratorContext getContext() {
- return context;
- }
-
- public void setInterfaceClassLoadingClass(final InterfaceHelperClassNode ihc) {
- interfaceClassLoadingClass = ihc;
- }
-
- public InterfaceHelperClassNode getInterfaceClassLoadingClass() {
- return interfaceClassLoadingClass;
- }
-
public boolean shouldOptimizeForInt() {
return optimizeForInt;
}
- public StatementWriter getStatementWriter() {
- return statementWriter;
- }
-
public void switchToFastPath() {
fastPath = true;
resetLineNumber();
@@ -374,10 +387,6 @@
return fastPath;
}
- public int getBytecodeVersion() {
- return bytecodeVersion;
- }
-
public int getLineNumber() {
return lineNumber;
}
@@ -390,11 +399,11 @@
setLineNumber(-1);
}
- public int getNextHelperMethodIndex() {
- return helperMethodIndex += 1;
+ public int getBytecodeVersion() {
+ return bytecodeVersion;
}
- public List<String> getSuperMethodNames() {
- return superMethodNames;
+ public int getNextHelperMethodIndex() {
+ return helperMethodIndex += 1;
}
}