changeset 49708:0547bb081005 datum

code clean-up removing references to guards
author vromero
date Fri, 06 Apr 2018 13:20:18 -0400
parents 829d99f94b43
children 92f12a719e67
files src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TypeEnter.java src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java src/jdk.compiler/share/classes/com/sun/tools/javac/tree/JCTree.java src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeMaker.java test/langtools/tools/javac/datum/GuardsInRecordsTest.java
diffstat 6 files changed, 4 insertions(+), 156 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java	Fri Apr 06 12:28:25 2018 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java	Fri Apr 06 13:20:18 2018 -0400
@@ -3839,20 +3839,6 @@
             ListBuffer<JCStatement> stats = new ListBuffer<>();
 
             List<JCExpression> args = ((JCMethodInvocation)tree.expr).args;
-
-            JCRecordDecl recordDecl = (JCRecordDecl)classdefs.get(currentClass);
-            if (recordDecl.guard != null) {
-                MethodSymbol guardSym = lookupMethod(
-                        tree.pos(),
-                        names.guard,
-                        currentClass.type,
-                        vars.map(v -> v.type));
-                JCExpression meth = make.Ident(guardSym);
-                JCMethodInvocation app = make.Apply(null, meth, args);
-                app.type = guardSym.type.asMethodType().restype;
-                JCStatement guardCall = make.Exec(app);
-                stats.add(guardCall);
-            }
             for (VarSymbol vsym : vars) {
                 stats.add(make.Exec(
                         make.Assign(make.Select(makeThis(tree, currentClass), vsym), args.head)
@@ -3861,7 +3847,6 @@
             }
             JCTree block = make.Block(0, stats.toList());
             result = translate(block);
-            return;
         } else {
             super.visitExec(tree);
         }
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TypeEnter.java	Fri Apr 06 12:28:25 2018 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TypeEnter.java	Fri Apr 06 13:20:18 2018 -0400
@@ -898,30 +898,6 @@
                 List<JCVariableDecl> superFields = TreeInfo.superRecordFields(tree);
                 memberEnter.memberEnter(recordFields, env);
                 memberEnter.memberEnter(superFields, env);
-                JCRecordDecl recordDecl = (JCRecordDecl)tree;
-                if (recordDecl.guard != null) {
-                    List<VarSymbol> recordSyms = recordFields.map(vd -> vd.sym);
-                    List<Type> argtypes = superFields.map(v -> v.vartype.type).appendList(recordSyms.map(v -> v.type));
-                    MethodType guardMT = new MethodType(argtypes, syms.voidType, List.nil(), syms.methodClass);
-                    MethodSymbol guardMS = new MethodSymbol(PRIVATE | RECORD, names.guard, guardMT, sym);
-
-                    ListBuffer<VarSymbol> params = new ListBuffer<>();
-                    for (JCVariableDecl p : superFields) {
-                        params.add(new VarSymbol(MANDATED | PARAMETER, p.name, p.vartype.type, guardMS));
-                    }
-                    for (VarSymbol p : recordSyms) {
-                        params.add(new VarSymbol(MANDATED | PARAMETER, p.name, p.type, guardMS));
-                    }
-                    guardMS.params = params.toList();
-
-                    JCUnary neg = make.Unary(Tag.NOT, recordDecl.guard);
-                    JCNewClass newException = make.NewClass(null, null,
-                            make.QualIdent(syms.illegalArgumentExceptionType.tsym),
-                            List.of(make.Literal(TypeTag.CLASS, "fields values are not accepted by the given guard")), null);
-                    JCStatement ifStm = make.If(neg, make.Throw(newException), null);
-                    JCMethodDecl guardDecl = make.MethodDef(guardMS, make.Block(0, List.of(ifStm)));
-                    tree.defs = tree.defs.prepend(guardDecl);
-                }
             }
         }
     }
@@ -954,7 +930,7 @@
                         }
                     }
                 } else if ((sym.flags() & RECORD) != 0) {
-                    helper = new RecordConstructorHelper(sym, ((JCRecordDecl)tree).guard, TreeInfo.recordFields(tree).map(vd -> vd.sym), TreeInfo.superRecordFields(tree));
+                    helper = new RecordConstructorHelper(sym, TreeInfo.recordFields(tree).map(vd -> vd.sym), TreeInfo.superRecordFields(tree));
                 }
                 if (helper != null) {
                     JCTree constrDef = defaultConstructor(make.at(tree.pos), helper);
@@ -967,7 +943,7 @@
                         if (TreeInfo.isConstructor(def) &&
                             !TreeInfo.hasConstructorInvocation(((JCMethodDecl)def).body.stats, names, true)) {
                             RecordConstructorHelper helper = new RecordConstructorHelper(sym,
-                                    ((JCRecordDecl)tree).guard, TreeInfo.recordFields(tree).map(vd -> vd.sym),
+                                    TreeInfo.recordFields(tree).map(vd -> vd.sym),
                                     TreeInfo.superRecordFields(tree));
                             JCMethodDecl methDecl = (JCMethodDecl)def;
                             JCStatement supCall = make.at(methDecl.body.pos).Exec(make.Apply(List.nil(),
@@ -1292,13 +1268,11 @@
 
         List<VarSymbol> recordFields;
         List<JCVariableDecl> superFields;
-        JCExpression guard;
 
-        RecordConstructorHelper(TypeSymbol owner, JCExpression guard, List<VarSymbol> recordFields, List<JCVariableDecl> superFields) {
+        RecordConstructorHelper(TypeSymbol owner, List<VarSymbol> recordFields, List<JCVariableDecl> superFields) {
             super(owner);
             this.recordFields = recordFields;
             this.superFields = superFields;
-            this.guard = guard;
         }
 
         @Override
@@ -1335,11 +1309,6 @@
         public List<Name> inits() {
             return recordFields.map(v -> v.name);
         }
-
-        @Override
-        public JCExpression guard() {
-            return guard;
-        }
     }
 
     JCTree defaultConstructor(TreeMaker make, DefaultConstructorHelper helper) {
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java	Fri Apr 06 12:28:25 2018 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java	Fri Apr 06 13:20:18 2018 -0400
@@ -3591,7 +3591,7 @@
         for (int i = fields.size() - 1; i >= 0; i--) {
             defs = defs.prepend(fields.get(i));
         }
-        JCRecordDecl result = toP(F.at(pos).RecordDef(mods, name, typarams, extending, implementing, defs, null));
+        JCClassDecl result = toP(F.at(pos).ClassDef(mods, name, typarams, extending, implementing, defs));
         attach(result, dc);
         return result;
     }
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/JCTree.java	Fri Apr 06 12:28:25 2018 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/JCTree.java	Fri Apr 06 13:20:18 2018 -0400
@@ -814,21 +814,6 @@
         }
     }
 
-    public static class JCRecordDecl extends JCClassDecl implements ClassTree {
-        public JCExpression guard;
-        public JCRecordDecl(JCModifiers mods,
-                           Name name,
-                           List<JCTypeParameter> typarams,
-                           JCExpression extending,
-                           List<JCExpression> implementing,
-                           List<JCTree> defs,
-                           ClassSymbol sym,
-                           JCExpression guard) {
-            super(mods, name, typarams, extending, implementing, defs, sym);
-            this.guard = guard;
-        }
-    }
-
     /**
      * A method definition.
      */
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeMaker.java	Fri Apr 06 12:28:25 2018 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeMaker.java	Fri Apr 06 13:20:18 2018 -0400
@@ -171,26 +171,6 @@
         return tree;
     }
 
-    public JCRecordDecl RecordDef(JCModifiers mods,
-                                Name name,
-                                List<JCTypeParameter> typarams,
-                                JCExpression extending,
-                                List<JCExpression> implementing,
-                                List<JCTree> defs,
-                                JCExpression guard)
-    {
-        JCRecordDecl tree = new JCRecordDecl(mods,
-                                     name,
-                                     typarams,
-                                     extending,
-                                     implementing,
-                                     defs,
-                                     null,
-                                     guard);
-        tree.pos = pos;
-        return tree;
-    }
-
     public JCMethodDecl MethodDef(JCModifiers mods,
                                Name name,
                                JCExpression restype,
--- a/test/langtools/tools/javac/datum/GuardsInRecordsTest.java	Fri Apr 06 12:28:25 2018 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,71 +0,0 @@
-/*
- * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/*
- * @test
- * @summary test for guards in records
- * @modules jdk.jdeps/com.sun.tools.classfile
- *          jdk.compiler/com.sun.tools.javac.util
- * @ignore guards will continue to be developed independently
- * @run main GuardsInRecordsTest
- */
-
-public class GuardsInRecordsTest {
-    static record Range1(int lo, int hi) where lo <= hi;
-    static record Range2(int lo, int hi) where lo <= hi {}
-    static record Range3(int lo, int hi) where lo <= hi {
-        Range3(int lo, int hi) {
-            default(lo, hi);
-        }
-    }
-
-    static abstract record A (int a) where a >= 0;
-    static record B (int a, int b) extends A(a) where b >= 0;
-
-    public static void main(String... args) {
-        try {
-            Range1 r = new Range1(2, 1);
-            throw new AssertionError("an exception was expected for Range1");
-        } catch (IllegalArgumentException iae) {}
-
-        try {
-            Range2 r = new Range2(2, 1);
-            throw new AssertionError("an exception was expected for Range2");
-        } catch (IllegalArgumentException iae) {}
-
-        try {
-            Range3 r = new Range3(2, 1);
-            throw new AssertionError("an exception was expected for Range3");
-        } catch (IllegalArgumentException iae) {}
-
-        try {
-            B b1 = new B(-1, 1);
-            throw new AssertionError("an exception was expected for B");
-        } catch (IllegalArgumentException iae) {}
-
-        try {
-            B b2 = new B(-1, -1);
-            throw new AssertionError("an exception was expected for B");
-        } catch (IllegalArgumentException iae) {}
-    }
-}