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 2021/08/14 06:02:56 UTC

[groovy] branch danielsun/rewrite-gsrc-to-jsrc updated (5c03116 -> 1436572)

This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a change to branch danielsun/rewrite-gsrc-to-jsrc
in repository https://gitbox.apache.org/repos/asf/groovy.git.


 discard 5c03116  Rewrite Groovy source code in core to Java
     new 1436572  Rewrite Groovy source code in core to Java

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (5c03116)
            \
             N -- N -- N   refs/heads/danielsun/rewrite-gsrc-to-jsrc (1436572)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 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:
 src/main/groovy/org/codehaus/groovy/transform/tailrec/AstHelper.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

[groovy] 01/01: Rewrite Groovy source code in core to Java

Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch danielsun/rewrite-gsrc-to-jsrc
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 14365728428a770a9f6b7a620ff077587cb2afb2
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat Aug 14 14:00:57 2021 +0800

    Rewrite Groovy source code in core to Java
---
 .../groovy/transform/tailrec/AstHelper.groovy      | 75 ---------------------
 .../groovy/transform/tailrec/AstHelper.java        | 78 ++++++++++++++++++++++
 .../transform/tailrec/CollectRecursiveCalls.groovy | 60 -----------------
 .../transform/tailrec/CollectRecursiveCalls.java   | 64 ++++++++++++++++++
 .../transform/tailrec/InWhileLoopWrapper.groovy    |  4 +-
 5 files changed, 144 insertions(+), 137 deletions(-)

diff --git a/src/main/groovy/org/codehaus/groovy/transform/tailrec/AstHelper.groovy b/src/main/groovy/org/codehaus/groovy/transform/tailrec/AstHelper.groovy
deleted file mode 100644
index 35cf13f..0000000
--- a/src/main/groovy/org/codehaus/groovy/transform/tailrec/AstHelper.groovy
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- */
-package org.codehaus.groovy.transform.tailrec
-
-import groovy.transform.CompileStatic
-import org.codehaus.groovy.ast.ClassNode
-import org.codehaus.groovy.ast.expr.Expression
-import org.codehaus.groovy.ast.expr.VariableExpression
-import org.codehaus.groovy.ast.stmt.ContinueStatement
-import org.codehaus.groovy.ast.stmt.ExpressionStatement
-import org.codehaus.groovy.ast.stmt.Statement
-
-import java.lang.reflect.Modifier
-
-import static org.codehaus.groovy.ast.tools.GeneralUtils.classX
-import static org.codehaus.groovy.ast.tools.GeneralUtils.declS
-import static org.codehaus.groovy.ast.tools.GeneralUtils.localVarX
-import static org.codehaus.groovy.ast.tools.GeneralUtils.propX
-import static org.codehaus.groovy.ast.tools.GeneralUtils.throwS
-import static org.codehaus.groovy.ast.tools.GeneralUtils.varX
-
-/**
- * Helping to create a few standard AST constructs
- */
-@CompileStatic
-class AstHelper {
-    static ExpressionStatement createVariableDefinition(String variableName, ClassNode variableType, Expression value, boolean variableShouldBeFinal = false) {
-        def newVariable = localVarX(variableName, variableType)
-        if (variableShouldBeFinal)
-            newVariable.modifiers = Modifier.FINAL
-        (ExpressionStatement) declS(newVariable, value)
-    }
-
-    static ExpressionStatement createVariableAlias(String aliasName, ClassNode variableType, String variableName) {
-        createVariableDefinition(aliasName, variableType, varX(variableName, variableType))
-    }
-
-    static VariableExpression createVariableReference(Map variableSpec) {
-        varX((String) variableSpec.name, (ClassNode) variableSpec.type)
-    }
-
-    /**
-     * This statement should make the code jump to surrounding while loop's start label
-     * Does not work from within Closures
-     */
-    static Statement recurStatement() {
-        //continue _RECUR_HERE_
-        new ContinueStatement(InWhileLoopWrapper.LOOP_LABEL)
-    }
-
-    /**
-     * This statement will throw exception which will be caught and redirected to jump to surrounding while loop's start label
-     * Also works from within Closures but is a tiny bit slower
-     */
-    static Statement recurByThrowStatement() {
-        // throw InWhileLoopWrapper.LOOP_EXCEPTION
-        throwS(propX(classX(InWhileLoopWrapper), 'LOOP_EXCEPTION'))
-    }
-}
diff --git a/src/main/groovy/org/codehaus/groovy/transform/tailrec/AstHelper.java b/src/main/groovy/org/codehaus/groovy/transform/tailrec/AstHelper.java
new file mode 100644
index 0000000..fc09f6c
--- /dev/null
+++ b/src/main/groovy/org/codehaus/groovy/transform/tailrec/AstHelper.java
@@ -0,0 +1,78 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.codehaus.groovy.transform.tailrec;
+
+import org.codehaus.groovy.ast.ClassNode;
+import org.codehaus.groovy.ast.expr.Expression;
+import org.codehaus.groovy.ast.expr.VariableExpression;
+import org.codehaus.groovy.ast.stmt.ContinueStatement;
+import org.codehaus.groovy.ast.stmt.ExpressionStatement;
+import org.codehaus.groovy.ast.stmt.Statement;
+
+import java.lang.reflect.Modifier;
+import java.util.Map;
+
+import static org.codehaus.groovy.ast.tools.GeneralUtils.classX;
+import static org.codehaus.groovy.ast.tools.GeneralUtils.declS;
+import static org.codehaus.groovy.ast.tools.GeneralUtils.localVarX;
+import static org.codehaus.groovy.ast.tools.GeneralUtils.propX;
+import static org.codehaus.groovy.ast.tools.GeneralUtils.throwS;
+import static org.codehaus.groovy.ast.tools.GeneralUtils.varX;
+
+/**
+ * Helping to create a few standard AST constructs
+ */
+class AstHelper {
+    public static ExpressionStatement createVariableDefinition(String variableName, ClassNode variableType, Expression value) {
+        return createVariableDefinition(variableName, variableType, value, false);
+    }
+
+    public static ExpressionStatement createVariableDefinition(String variableName, ClassNode variableType, Expression value, boolean variableShouldBeFinal) {
+        VariableExpression newVariable = localVarX(variableName, variableType);
+        if (variableShouldBeFinal)
+            newVariable.setModifiers(Modifier.FINAL);
+        return (ExpressionStatement) declS(newVariable, value);
+    }
+
+    public static ExpressionStatement createVariableAlias(String aliasName, ClassNode variableType, String variableName) {
+        return createVariableDefinition(aliasName, variableType, varX(variableName, variableType));
+    }
+
+    public static VariableExpression createVariableReference(Map<String, ?> variableSpec) {
+        return varX((String) variableSpec.get("name"), (ClassNode) variableSpec.get("type"));
+    }
+
+    /**
+     * This statement should make the code jump to surrounding while loop's start label
+     * Does not work from within Closures
+     */
+    public static Statement recurStatement() {
+        //continue _RECUR_HERE_
+        return new ContinueStatement(InWhileLoopWrapper.LOOP_LABEL);
+    }
+
+    /**
+     * This statement will throw exception which will be caught and redirected to jump to surrounding while loop's start label
+     * Also works from within Closures but is a tiny bit slower
+     */
+    public static Statement recurByThrowStatement() {
+        // throw InWhileLoopWrapper.LOOP_EXCEPTION
+        return throwS(propX(classX(InWhileLoopWrapper.class), "LOOP_EXCEPTION"));
+    }
+}
diff --git a/src/main/groovy/org/codehaus/groovy/transform/tailrec/CollectRecursiveCalls.groovy b/src/main/groovy/org/codehaus/groovy/transform/tailrec/CollectRecursiveCalls.groovy
deleted file mode 100644
index 3f586d8..0000000
--- a/src/main/groovy/org/codehaus/groovy/transform/tailrec/CollectRecursiveCalls.groovy
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- */
-package org.codehaus.groovy.transform.tailrec
-
-import groovy.transform.CompileStatic
-import org.codehaus.groovy.ast.CodeVisitorSupport
-import org.codehaus.groovy.ast.MethodNode
-import org.codehaus.groovy.ast.expr.Expression
-import org.codehaus.groovy.ast.expr.MethodCallExpression
-import org.codehaus.groovy.ast.expr.StaticMethodCallExpression
-
-/**
- * Collect all recursive calls within method
- */
-@CompileStatic
-class CollectRecursiveCalls extends CodeVisitorSupport {
-	MethodNode method
-	List<Expression> recursiveCalls = []
-
-	void visitMethodCallExpression(MethodCallExpression call) {
-		if (isRecursive(call)) {
-			recursiveCalls << call
-		}
-        super.visitMethodCallExpression(call)
-    }
-
-	void visitStaticMethodCallExpression(StaticMethodCallExpression call) {
-		if (isRecursive(call)) {
-            recursiveCalls << call
-        }
-		super.visitStaticMethodCallExpression(call)
-	}
-	
-	private boolean isRecursive(call) {
-		new RecursivenessTester().isRecursive(method: method, call: call)
-	}
-	
-	synchronized List<Expression> collect(MethodNode method) {
-		recursiveCalls.clear()
-		this.method = method
-		this.method.code.visit(this)
-		recursiveCalls
-	}
-}
diff --git a/src/main/groovy/org/codehaus/groovy/transform/tailrec/CollectRecursiveCalls.java b/src/main/groovy/org/codehaus/groovy/transform/tailrec/CollectRecursiveCalls.java
new file mode 100644
index 0000000..e996a86
--- /dev/null
+++ b/src/main/groovy/org/codehaus/groovy/transform/tailrec/CollectRecursiveCalls.java
@@ -0,0 +1,64 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.codehaus.groovy.transform.tailrec;
+
+import org.apache.groovy.util.Maps;
+import org.codehaus.groovy.ast.CodeVisitorSupport;
+import org.codehaus.groovy.ast.MethodNode;
+import org.codehaus.groovy.ast.expr.Expression;
+import org.codehaus.groovy.ast.expr.MethodCallExpression;
+import org.codehaus.groovy.ast.expr.StaticMethodCallExpression;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Collect all recursive calls within method
+ */
+class CollectRecursiveCalls extends CodeVisitorSupport {
+	private final List<Expression> recursiveCalls = new ArrayList<>();
+	private MethodNode method;
+
+	@Override
+	public void visitMethodCallExpression(MethodCallExpression call) {
+		if (isRecursive(call)) {
+			recursiveCalls.add(call);
+		}
+        super.visitMethodCallExpression(call);
+    }
+
+	@Override
+	public void visitStaticMethodCallExpression(StaticMethodCallExpression call) {
+		if (isRecursive(call)) {
+            recursiveCalls.add(call);
+        }
+		super.visitStaticMethodCallExpression(call);
+	}
+	
+	public synchronized List<Expression> collect(MethodNode method) {
+		recursiveCalls.clear();
+		this.method = method;
+		this.method.getCode().visit(this);
+		return recursiveCalls;
+	}
+
+	private boolean isRecursive(Expression call) {
+		return new RecursivenessTester().isRecursive(Maps.of("method", method, "call", call));
+	}
+}
diff --git a/src/main/groovy/org/codehaus/groovy/transform/tailrec/InWhileLoopWrapper.groovy b/src/main/groovy/org/codehaus/groovy/transform/tailrec/InWhileLoopWrapper.groovy
index d622dc5..d069807 100644
--- a/src/main/groovy/org/codehaus/groovy/transform/tailrec/InWhileLoopWrapper.groovy
+++ b/src/main/groovy/org/codehaus/groovy/transform/tailrec/InWhileLoopWrapper.groovy
@@ -48,8 +48,8 @@ import static org.codehaus.groovy.ast.tools.GeneralUtils.tryCatchS
  */
 @CompileStatic
 class InWhileLoopWrapper {
-	static final String LOOP_LABEL = '_RECUR_HERE_'
-    static final GotoRecurHereException LOOP_EXCEPTION = new GotoRecurHereException()
+	public static final String LOOP_LABEL = '_RECUR_HERE_'
+    public static final GotoRecurHereException LOOP_EXCEPTION = new GotoRecurHereException()
 
 	void wrap(MethodNode method) {
 		BlockStatement oldBody = method.code as BlockStatement