You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2019/12/12 00:57:57 UTC
[groovy] branch master updated (1e3dfbc -> ca57397)
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git.
from 1e3dfbc fix class config for wildcard types
new 1a5d280 Minor refactoring: remove redundant code
new ca57397 Minor refactoring: remove redundant internal variable of lambda
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../classgen/asm/sc/StaticTypesLambdaWriter.java | 54 ++--------------------
1 file changed, 4 insertions(+), 50 deletions(-)
[groovy] 02/02: Minor refactoring: remove redundant internal
variable of lambda
Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit ca5739716baa19c6475df0d6bb31c523c8124f44
Author: Daniel.Sun <re...@hotmail.com>
AuthorDate: Thu Dec 12 08:18:35 2019 +0800
Minor refactoring: remove redundant internal variable of lambda
---
.../groovy/classgen/asm/sc/StaticTypesLambdaWriter.java | 12 +-----------
1 file changed, 1 insertion(+), 11 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesLambdaWriter.java b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesLambdaWriter.java
index 88da6c7..05dae39 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesLambdaWriter.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesLambdaWriter.java
@@ -72,7 +72,6 @@ import static org.objectweb.asm.Opcodes.CHECKCAST;
import static org.objectweb.asm.Opcodes.DUP;
import static org.objectweb.asm.Opcodes.H_INVOKEVIRTUAL;
import static org.objectweb.asm.Opcodes.ICONST_0;
-import static org.objectweb.asm.Opcodes.ICONST_1;
import static org.objectweb.asm.Opcodes.INVOKESPECIAL;
import static org.objectweb.asm.Opcodes.INVOKEVIRTUAL;
import static org.objectweb.asm.Opcodes.NEW;
@@ -83,7 +82,6 @@ import static org.objectweb.asm.Opcodes.NEW;
public class StaticTypesLambdaWriter extends LambdaWriter implements AbstractFunctionalInterfaceWriter {
private static final String DO_CALL = "doCall";
private static final String LAMBDA_SHARED_VARIABLES = "__LAMBDA_SHARED_VARIABLES";
- private static final String ENCLOSING_THIS = "__enclosing_this";
private static final String LAMBDA_THIS = "__lambda_this";
private static final String INIT = "<init>";
private static final String IS_GENERATED_CONSTRUCTOR = "__IS_GENERATED_CONSTRUCTOR";
@@ -137,7 +135,6 @@ public class StaticTypesLambdaWriter extends LambdaWriter implements AbstractFun
boolean accessingInstanceMembers = isAccessingInstanceMembersOfEnclosingClass(syntheticLambdaMethodNode);
newGroovyLambdaWrapperAndLoad(lambdaWrapperClassNode, expression, accessingInstanceMembers);
- loadEnclosingClassInstance(accessingInstanceMembers);
}
MethodVisitor mv = controller.getMethodVisitor();
@@ -154,7 +151,7 @@ public class StaticTypesLambdaWriter extends LambdaWriter implements AbstractFun
mv.visitTypeInsn(CHECKCAST, "java/io/Serializable");
}
- operandStack.replace(redirect, 2);
+ operandStack.replace(redirect, 1);
}
private Parameter[] createDeserializeLambdaMethodParams() {
@@ -238,7 +235,6 @@ public class StaticTypesLambdaWriter extends LambdaWriter implements AbstractFun
private String createAbstractMethodDesc(ClassNode functionalInterfaceType, ClassNode lambdaClassNode) {
List<Parameter> lambdaSharedVariableList = new LinkedList<>();
- prependEnclosingThis(lambdaSharedVariableList);
prependParameter(lambdaSharedVariableList, LAMBDA_THIS, lambdaClassNode);
return BytecodeHelper.getMethodDescriptor(functionalInterfaceType.redirect(), lambdaSharedVariableList.toArray(Parameter.EMPTY_ARRAY));
@@ -312,7 +308,6 @@ public class StaticTypesLambdaWriter extends LambdaWriter implements AbstractFun
removeInitialValues(localVariableParameters);
List<Parameter> methodParameterList = new LinkedList<>(Arrays.asList(parametersWithExactType));
- prependEnclosingThis(methodParameterList);
MethodNode methodNode =
answer.addMethod(
@@ -330,10 +325,6 @@ public class StaticTypesLambdaWriter extends LambdaWriter implements AbstractFun
return methodNode;
}
- private Parameter prependEnclosingThis(List<Parameter> methodParameterList) {
- return prependParameter(methodParameterList, ENCLOSING_THIS, controller.getClassNode().getPlainNodeReference());
- }
-
private Parameter[] createParametersWithExactType(LambdaExpression expression) {
Parameter[] parameters = expression.getParameters();
if (parameters == null) {
@@ -390,7 +381,6 @@ public class StaticTypesLambdaWriter extends LambdaWriter implements AbstractFun
@Override
public void visit(MethodVisitor mv) {
callGetCapturedArg(mv, ICONST_0, lambdaWrapperClassNode);
- callGetCapturedArg(mv, ICONST_1, classNode);
}
private void callGetCapturedArg(MethodVisitor mv, int capturedArgIndex, ClassNode resultType) {
[groovy] 01/02: Minor refactoring: remove redundant code
Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 1a5d2803107911adb1cdbcd02c5826d4414f38eb
Author: Daniel.Sun <re...@hotmail.com>
AuthorDate: Thu Dec 12 08:10:01 2019 +0800
Minor refactoring: remove redundant code
---
.../classgen/asm/sc/StaticTypesLambdaWriter.java | 42 ++--------------------
1 file changed, 3 insertions(+), 39 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesLambdaWriter.java b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesLambdaWriter.java
index 8f2fe0c..88da6c7 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesLambdaWriter.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesLambdaWriter.java
@@ -34,7 +34,6 @@ import org.codehaus.groovy.ast.expr.ClosureExpression;
import org.codehaus.groovy.ast.expr.ConstantExpression;
import org.codehaus.groovy.ast.expr.Expression;
import org.codehaus.groovy.ast.expr.LambdaExpression;
-import org.codehaus.groovy.ast.expr.MethodCallExpression;
import org.codehaus.groovy.ast.expr.VariableExpression;
import org.codehaus.groovy.ast.stmt.BlockStatement;
import org.codehaus.groovy.ast.stmt.Statement;
@@ -186,18 +185,6 @@ public class StaticTypesLambdaWriter extends LambdaWriter implements AbstractFun
}
@Override
- public void visitMethodCallExpression(MethodCallExpression call) {
- if (!call.getMethodTarget().isStatic()) {
- Expression objectExpression = call.getObjectExpression();
- if (objectExpression instanceof VariableExpression && ENCLOSING_THIS.equals(((VariableExpression) objectExpression).getName())) {
- objectHolder.setObject(true);
- }
- }
-
- super.visitMethodCallExpression(call);
- }
-
- @Override
protected SourceUnit getSourceUnit() {
return null;
}
@@ -300,8 +287,7 @@ public class StaticTypesLambdaWriter extends LambdaWriter implements AbstractFun
ConstructorNode constructorNode = addConstructor(expression, localVariableParameters, answer, createBlockStatementForConstructor(expression, outerClass, classNode));
constructorNode.putNodeMetaData(IS_GENERATED_CONSTRUCTOR, Boolean.TRUE);
- Parameter enclosingThisParameter = syntheticLambdaMethodNode.getParameters()[0];
- new TransformationVisitor(answer, enclosingThisParameter).visitMethod(syntheticLambdaMethodNode);
+ new LambdaBodyTransformationVisitor(answer).visitMethod(syntheticLambdaMethodNode);
return answer;
}
@@ -443,13 +429,11 @@ public class StaticTypesLambdaWriter extends LambdaWriter implements AbstractFun
return staticTypesClosureWriter.createClosureClass(expression, mods);
}
- private static final class TransformationVisitor extends ClassCodeVisitorSupport {
+ private static final class LambdaBodyTransformationVisitor extends ClassCodeVisitorSupport {
private final CorrectAccessedVariableVisitor correctAccessedVariableVisitor;
- private final Parameter enclosingThisParameter;
- public TransformationVisitor(InnerClassNode icn, Parameter enclosingThisParameter) {
+ public LambdaBodyTransformationVisitor(InnerClassNode icn) {
this.correctAccessedVariableVisitor = new CorrectAccessedVariableVisitor(icn);
- this.enclosingThisParameter = enclosingThisParameter;
}
@Override
@@ -458,26 +442,6 @@ public class StaticTypesLambdaWriter extends LambdaWriter implements AbstractFun
}
@Override
- public void visitMethodCallExpression(MethodCallExpression call) {
- if (!call.getMethodTarget().isStatic()) {
- Expression objectExpression = call.getObjectExpression();
-
- if (objectExpression instanceof VariableExpression) {
- VariableExpression originalObjectExpression = (VariableExpression) objectExpression;
- if (null == originalObjectExpression.getAccessedVariable()) {
- VariableExpression thisVariable = new VariableExpression(enclosingThisParameter);
- thisVariable.setSourcePosition(originalObjectExpression);
-
- call.setObjectExpression(thisVariable);
- call.setImplicitThis(false);
- }
- }
- }
-
- super.visitMethodCallExpression(call);
- }
-
- @Override
protected SourceUnit getSourceUnit() {
return null;
}