groovy git commit: Fix the test groovy.transform.stc.ClosuresSTCTest#testClosureRecursionWithDef

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

groovy git commit: Fix the test groovy.transform.stc.ClosuresSTCTest#testClosureRecursionWithDef

Daniel.Sun
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X 85676cf7d -> 17b9ceea0


Fix the test groovy.transform.stc.ClosuresSTCTest#testClosureRecursionWithDef

(cherry picked from commit 86091b1)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/17b9ceea
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/17b9ceea
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/17b9ceea

Branch: refs/heads/GROOVY_2_6_X
Commit: 17b9ceea03b01e7f8c2331a296ddb72243e59244
Parents: 85676cf
Author: sunlan <[hidden email]>
Authored: Wed Jul 26 23:26:53 2017 +0800
Committer: sunlan <[hidden email]>
Committed: Wed Jul 26 23:28:31 2017 +0800

----------------------------------------------------------------------
 .../apache/groovy/parser/antlr4/AstBuilder.java | 95 ++++++++++++++------
 1 file changed, 69 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/17b9ceea/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
----------------------------------------------------------------------
diff --git a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
index 1c9b5cf..750e4f8 100644
--- a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
+++ b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
@@ -119,7 +119,6 @@ import org.codehaus.groovy.syntax.SyntaxException;
 import org.codehaus.groovy.syntax.Types;
 import org.objectweb.asm.Opcodes;
 
-import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.io.StringWriter;
@@ -2477,9 +2476,13 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
 
     @Override
     public BinaryExpression visitPowerExprAlt(PowerExprAltContext ctx) {
-        return this.configureAST(
-                this.createBinaryExpression(ctx.left, ctx.op, ctx.right),
-                ctx);
+        BinaryExpression binaryExpression = this.createBinaryExpression(ctx.left, ctx.op, ctx.right);
+
+        if (isTrue(ctx, IS_INSIDE_CONDITIONAL_EXPRESSION)) {
+            return this.configureAST(binaryExpression, ctx.op);
+        }
+
+        return this.configureAST(binaryExpression, ctx);
     }
 
     @Override
@@ -2528,16 +2531,24 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
 
     @Override
     public BinaryExpression visitMultiplicativeExprAlt(MultiplicativeExprAltContext ctx) {
-        return this.configureAST(
-                this.createBinaryExpression(ctx.left, ctx.op, ctx.right),
-                ctx);
+        BinaryExpression binaryExpression = this.createBinaryExpression(ctx.left, ctx.op, ctx.right);
+
+        if (isTrue(ctx, IS_INSIDE_CONDITIONAL_EXPRESSION)) {
+            return this.configureAST(binaryExpression, ctx.op);
+        }
+
+        return this.configureAST(binaryExpression, ctx);
     }
 
     @Override
     public BinaryExpression visitAdditiveExprAlt(AdditiveExprAltContext ctx) {
-        return this.configureAST(
-                this.createBinaryExpression(ctx.left, ctx.op, ctx.right),
-                ctx);
+        BinaryExpression binaryExpression = this.createBinaryExpression(ctx.left, ctx.op, ctx.right);
+
+        if (isTrue(ctx, IS_INSIDE_CONDITIONAL_EXPRESSION)) {
+            return this.configureAST(binaryExpression, ctx.op);
+        }
+
+        return this.configureAST(binaryExpression, ctx);
     }
 
     @Override
@@ -2550,20 +2561,27 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
         }
 
         org.codehaus.groovy.syntax.Token op = null;
+        Token antlrToken = null;
 
         if (asBoolean(ctx.dlOp)) {
             op = this.createGroovyToken(ctx.dlOp, 2);
+            antlrToken = ctx.dlOp;
         } else if (asBoolean(ctx.dgOp)) {
             op = this.createGroovyToken(ctx.dgOp, 2);
+            antlrToken = ctx.dgOp;
         } else if (asBoolean(ctx.tgOp)) {
             op = this.createGroovyToken(ctx.tgOp, 3);
+            antlrToken = ctx.tgOp;
         } else {
             throw createParsingFailedException("Unsupported shift expression: " + ctx.getText(), ctx);
         }
 
-        return this.configureAST(
-                new BinaryExpression(left, op, right),
-                ctx);
+        BinaryExpression binaryExpression = new BinaryExpression(left, op, right);
+        if (isTrue(ctx, IS_INSIDE_CONDITIONAL_EXPRESSION)) {
+            return this.configureAST(binaryExpression, antlrToken);
+        }
+
+        return this.configureAST(binaryExpression, ctx);
     }
 
     @Override
@@ -2589,9 +2607,17 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
             case LT:
             case IN:
             case NOT_IN:
-                return this.configureAST(
-                        this.createBinaryExpression(ctx.left, ctx.op, ctx.right),
-                        ctx);
+            {
+                BinaryExpression binaryExpression = this.createBinaryExpression(ctx.left, ctx.op, ctx.right);
+
+                if (ctx.op.getType() == IN || ctx.op.getType() == NOT_IN ) {
+                    if (isTrue(ctx, IS_INSIDE_CONDITIONAL_EXPRESSION)) {
+                        return this.configureAST(binaryExpression, ctx.op);
+                    }
+                }
+
+                return this.configureAST(binaryExpression, ctx);
+            }
 
             default:
                 throw createParsingFailedException("Unsupported relational expression: " + ctx.getText(), ctx);
@@ -2599,7 +2625,7 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
     }
 
     @Override
-    public Expression visitEqualityExprAlt(EqualityExprAltContext ctx) {
+    public BinaryExpression visitEqualityExprAlt(EqualityExprAltContext ctx) {
         return this.configureAST(
                 this.createBinaryExpression(ctx.left, ctx.op, ctx.right),
                 ctx);
@@ -2614,23 +2640,35 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
 
     @Override
     public BinaryExpression visitAndExprAlt(AndExprAltContext ctx) {
-        return this.configureAST(
-                this.createBinaryExpression(ctx.left, ctx.op, ctx.right),
-                ctx);
+        BinaryExpression binaryExpression = this.createBinaryExpression(ctx.left, ctx.op, ctx.right);
+
+        if (isTrue(ctx, IS_INSIDE_CONDITIONAL_EXPRESSION)) {
+            return this.configureAST(binaryExpression, ctx.op);
+        }
+
+        return this.configureAST(binaryExpression, ctx);
     }
 
     @Override
     public BinaryExpression visitExclusiveOrExprAlt(ExclusiveOrExprAltContext ctx) {
-        return this.configureAST(
-                this.createBinaryExpression(ctx.left, ctx.op, ctx.right),
-                ctx);
+        BinaryExpression binaryExpression = this.createBinaryExpression(ctx.left, ctx.op, ctx.right);
+
+        if (isTrue(ctx, IS_INSIDE_CONDITIONAL_EXPRESSION)) {
+            return this.configureAST(binaryExpression, ctx.op);
+        }
+
+        return this.configureAST(binaryExpression, ctx);
     }
 
     @Override
     public BinaryExpression visitInclusiveOrExprAlt(InclusiveOrExprAltContext ctx) {
-        return this.configureAST(
-                this.createBinaryExpression(ctx.left, ctx.op, ctx.right),
-                ctx);
+        BinaryExpression binaryExpression = this.createBinaryExpression(ctx.left, ctx.op, ctx.right);
+
+        if (isTrue(ctx, IS_INSIDE_CONDITIONAL_EXPRESSION)) {
+            return this.configureAST(binaryExpression, ctx.op);
+        }
+
+        return this.configureAST(binaryExpression, ctx);
     }
 
     @Override
@@ -2649,12 +2687,16 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
 
     @Override
     public Expression visitConditionalExprAlt(ConditionalExprAltContext ctx) {
+        ctx.fb.putNodeMetaData(IS_INSIDE_CONDITIONAL_EXPRESSION, true);
+
         if (asBoolean(ctx.ELVIS())) { // e.g. a == 6 ?: 0
             return this.configureAST(
                     new ElvisOperatorExpression((Expression) this.visit(ctx.con), (Expression) this.visit(ctx.fb)),
                     ctx);
         }
 
+        ctx.tb.putNodeMetaData(IS_INSIDE_CONDITIONAL_EXPRESSION, true);
+
         return this.configureAST(
                 new TernaryExpression(
                         this.configureAST(new BooleanExpression((Expression) this.visit(ctx.con)),
@@ -4575,6 +4617,7 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
     private static final String IS_NUMERIC = "_IS_NUMERIC";
     private static final String IS_STRING = "_IS_STRING";
     private static final String IS_INTERFACE_WITH_DEFAULT_METHODS = "_IS_INTERFACE_WITH_DEFAULT_METHODS";
+    private static final String IS_INSIDE_CONDITIONAL_EXPRESSION = "_IS_INSIDE_CONDITIONAL_EXPRESSION";
 
     private static final String PATH_EXPRESSION_BASE_EXPR = "_PATH_EXPRESSION_BASE_EXPR";
     private static final String PATH_EXPRESSION_BASE_EXPR_GENERICS_TYPES = "_PATH_EXPRESSION_BASE_EXPR_GENERICS_TYPES";

Apache Groovy committer & PMC member

Blog: http://blog.sunlan.me
Twitter: @daniel_sun