groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From emil...@apache.org
Subject [groovy] branch master updated: minor edits
Date Fri, 24 Jan 2020 18:18:46 GMT
This is an automated email from the ASF dual-hosted git repository.

emilles pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new d3e3851  minor edits
d3e3851 is described below

commit d3e3851d2b869cffc49bd61b119164876e0f46f5
Author: Eric Milles <eric.milles@thomsonreuters.com>
AuthorDate: Fri Jan 24 12:18:05 2020 -0600

    minor edits
---
 .../groovy/classgen/asm/DelegatingController.java  |   1 +
 .../groovy/classgen/asm/WriterController.java      | 229 +++++++++++----------
 2 files changed, 120 insertions(+), 110 deletions(-)

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 @@ public class DelegatingController extends WriterController {
     }
 
     @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 @@ import static org.codehaus.groovy.ast.ClassHelper.isGeneratedFunction;
 
 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 @@ public class WriterController {
     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 @@ public class WriterController {
         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 @@ public class WriterController {
         }
 
         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 @@ public class WriterController {
         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 @@ public class WriterController {
         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,18 +161,33 @@ public class WriterController {
         }
     }
 
+    //--------------------------------------------------------------------------
+
     public AsmClassGenerator getAcg() {
         return acg;
     }
 
-    public void setMethodVisitor(final MethodVisitor methodVisitor) {
-        this.methodVisitor = methodVisitor;
+    @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 GeneratorContext getContext() {
+        return context;
+    }
+
     public CompileStack getCompileStack() {
         return compileStack;
     }
@@ -181,16 +196,38 @@ public class WriterController {
         return operandStack;
     }
 
-    public ClassNode getClassNode() {
-        return classNode;
+    public SourceUnit getSourceUnit() {
+        return sourceUnit;
     }
 
-    public CallSiteWriter getCallSiteWriter() {
-        return callSiteWriter;
+    public TypeChooser getTypeChooser() {
+        return typeChooser;
     }
 
-    public ClassVisitor getClassVisitor() {
-        return cv;
+    public UnaryExpressionHelper getUnaryExpressionHelper() {
+        if (fastPath) {
+            return fastPathUnaryExpressionHelper;
+        } else {
+            return unaryExpressionHelper;
+        }
+    }
+
+    public BinaryExpressionHelper getBinaryExpressionHelper() {
+        if (fastPath) {
+            return fastPathBinaryExpHelper;
+        } else {
+            return binaryExpHelper;
+        }
+    }
+
+    //--------------------------------------------------------------------------
+
+    public AssertionWriter getAssertionWriter() {
+        return assertionWriter;
+    }
+
+    public CallSiteWriter getCallSiteWriter() {
+        return callSiteWriter;
     }
 
     public ClosureWriter getClosureWriter() {
@@ -201,26 +238,14 @@ public class WriterController {
         return lambdaWriter;
     }
 
-    public ClassVisitor getCv() {
-        return cv;
-    }
-
-    public String getInternalClassName() {
-        return internalClassName;
+    public StatementWriter getStatementWriter() {
+        return statementWriter;
     }
 
     public InvocationWriter getInvocationWriter() {
         return invocationWriter;
     }
 
-    public BinaryExpressionHelper getBinaryExpressionHelper() {
-        if (fastPath) {
-            return fastPathBinaryExpHelper;
-        } else {
-            return binaryExpHelper;
-        }
-    }
-
     public MethodPointerExpressionWriter getMethodPointerExpressionWriter() {
         return methodPointerExpressionWriter;
     }
@@ -229,24 +254,20 @@ public class WriterController {
         return methodReferenceExpressionWriter;
     }
 
-    public UnaryExpressionHelper getUnaryExpressionHelper() {
-        if (fastPath) {
-            return fastPathUnaryExpressionHelper;
+    //--------------------------------------------------------------------------
+
+    public String getClassName() {
+        String className;
+        if (!classNode.isInterface() || interfaceClassLoadingClass == null) {
+            className = internalClassName;
         } else {
-            return unaryExpressionHelper;
+            className = BytecodeHelper.getClassInternalName(interfaceClassLoadingClass);
         }
+        return className;
     }
 
-    public AssertionWriter getAssertionWriter() {
-        return assertionWriter;
-    }
-
-    public TypeChooser getTypeChooser() {
-        return typeChooser;
-    }
-
-    public String getInternalBaseClassName() {
-        return internalBaseClassName;
+    public ClassNode getClassNode() {
+        return classNode;
     }
 
     public MethodNode getMethodNode() {
@@ -267,10 +288,46 @@ public class WriterController {
         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 @@ public class WriterController {
         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 @@ public class WriterController {
         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 @@ public class WriterController {
         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 @@ public class WriterController {
         return fastPath;
     }
 
-    public int getBytecodeVersion() {
-        return bytecodeVersion;
-    }
-
     public int getLineNumber() {
         return lineNumber;
     }
@@ -390,11 +399,11 @@ public class WriterController {
         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;
     }
 }


Mime
View raw message