changeset 49713:81ce218e677e datum

refactoring: removing more experimental code
author vromero
date Fri, 06 Apr 2018 15:25:59 -0400
parents 90609e9cd9f4
children b2f943f73aee
files src/jdk.compiler/share/classes/com/sun/tools/javac/code/Source.java src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java 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/TreeInfo.java
diffstat 6 files changed, 15 insertions(+), 171 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Source.java	Fri Apr 06 14:50:20 2018 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Source.java	Fri Apr 06 15:25:59 2018 -0400
@@ -182,7 +182,7 @@
         UNDERSCORE_IDENTIFIER(MIN, JDK8),
         PRIVATE_INTERFACE_METHODS(JDK9, Fragments.FeaturePrivateIntfMethods, DiagKind.PLURAL),
         LOCAL_VARIABLE_TYPE_INFERENCE(JDK10),
-        DATA_CLASSES(JDK10);
+        RECORDS(JDK10);
 
         enum DiagKind {
             NORMAL,
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Fri Apr 06 14:50:20 2018 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Fri Apr 06 15:25:59 2018 -0400
@@ -4604,35 +4604,6 @@
                 }
 
                 if ((c.flags() & RECORD) != 0) {
-                    Type sup = types.supertype(c.type);
-                    List<JCVariableDecl> superFields = TreeInfo.superRecordFields(env.enclClass);
-                    if (sup.tsym != syms.abstractRecordType.tsym &&
-                            (sup.tsym.flags() & (ABSTRACT | RECORD)) != (ABSTRACT | RECORD)) {
-                        log.error(env.enclClass.extending.pos(), Errors.CantExtendRecord(Fragments.BadRecordSuper));
-                    }
-
-                    if (superFields.nonEmpty()) {
-                        if (c.members().findFirst(names.init, s -> (s.flags() & RECORD) == 0) != null) {
-                            log.error(env.enclClass.extending.pos(), Errors.CantExtendRecord(Fragments.BadSuperFields));
-                        }
-                    }
-
-                    List<VarSymbol> supRecordFields = types.recordVars(sup);
-                    for (JCTree supField : superFields) {
-                        JCVariableDecl supVarDecl = (JCVariableDecl)supField;
-                        if (supRecordFields.isEmpty()) break; //arity mismatches will be checked inside implicit constructor
-                        if (supRecordFields.head.name != supVarDecl.name ||
-                                !types.isSameType(supRecordFields.head.type, supVarDecl.vartype.type)) {
-                            log.error(env.enclClass.extending.pos(),
-                                    Errors.CantExtendRecord(
-                                            Fragments.SuperFieldMismatch(
-                                                    supRecordFields.head.type, supRecordFields.head.name,
-                                                    supVarDecl.vartype.type, supVarDecl.name)));
-                            break;
-                        }
-                        supRecordFields = supRecordFields.tail;
-                    }
-
                     List<VarSymbol> vars = types.recordVars(c.type).stream()
                             .filter(v -> v.owner == c)
                             .collect(List.collector());
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java	Fri Apr 06 14:50:20 2018 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java	Fri Apr 06 15:25:59 2018 -0400
@@ -2485,7 +2485,6 @@
 
     /** Translate a record. */
     private void visitRecordDef(JCClassDecl tree) {
-        boolean isAbstract = (tree.mods.flags & ABSTRACT) != 0;
         make_at(tree.pos());
         List<VarSymbol> vars = types.recordVars(tree.type);
         Pool.MethodHandle[] getterMethHandles = new Pool.MethodHandle[vars.size()];
@@ -2499,15 +2498,12 @@
         }
 
         tree.defs = tree.defs.appendList(accessors(tree));
-
-        if (!isAbstract) {
-            tree.defs = tree.defs.appendList(List.of(
-                    recordEquals(tree, getterMethHandles),
-                    recordToString(tree, vars, getterMethHandles),
-                    recordHashCode(tree, getterMethHandles),
-                    recordExtractor(tree, getterMethHandles)
-            ));
-        }
+        tree.defs = tree.defs.appendList(List.of(
+                recordEquals(tree, getterMethHandles),
+                recordToString(tree, vars, getterMethHandles),
+                recordHashCode(tree, getterMethHandles),
+                recordExtractor(tree, getterMethHandles)
+        ));
     }
 
     JCTree recordToString(JCClassDecl tree, List<VarSymbol> vars, Pool.MethodHandle[] getterMethHandles) {
@@ -2730,106 +2726,6 @@
         return qualifier;
     }
 
-    JCTree recordOldToString(JCClassDecl tree, List<VarSymbol> vars) {
-        make_at(tree.pos());
-
-        MethodSymbol toStringSym = lookupMethod(tree.pos(),
-                         names.toString,
-                         tree.sym.type,
-                         List.nil());
-        if ((toStringSym.flags() & RECORD) != 0) {
-            String format = vars.stream()
-                    .map(v -> v.name + "=%s")
-                    .collect(Collectors.joining(", ", tree.name + "[", "]"));
-            JCExpression formatLit = make.Literal(format);
-            JCFieldAccess meth = make.Select(make.Type(syms.stringType), names.fromString("format"));
-            meth.sym = lookupMethod(tree.pos(),
-                    meth.name,
-                    syms.stringType,
-                    List.of(syms.stringType, types.makeArrayType(syms.objectType)));
-            meth.type = meth.sym.type;
-            JCMethodInvocation app = make.Apply(List.nil(), meth,
-                    List.of(formatLit).appendList(vars.map(make::Ident)));
-            app.type = meth.type.getReturnType();
-            app.varargsElement = syms.objectType;
-            return make.MethodDef(toStringSym, make.Block(0, List.of(make.Return(app))));
-        } else {
-            return make.Block(SYNTHETIC, List.nil());
-        }
-    }
-
-    JCTree recordOldHashCode(JCClassDecl tree, List<VarSymbol> vars) {
-        make_at(tree.pos());
-
-        MethodSymbol hashCodeSym = lookupMethod(tree.pos(),
-                         names.hashCode,
-                         tree.sym.type,
-                         List.nil());
-        if ((hashCodeSym.flags() & RECORD) != 0) {
-            JCFieldAccess meth = make.Select(make.Type(syms.objectsType), names.fromString("hash"));
-            meth.sym = lookupMethod(tree.pos(),
-                    meth.name,
-                    syms.objectsType,
-                    List.of(types.makeArrayType(syms.objectType)));
-            meth.type = meth.sym.type;
-            JCMethodInvocation app = make.Apply(List.nil(), meth, vars.map(make::Ident));
-            app.type = meth.type.getReturnType();
-            app.varargsElement = syms.objectType;
-            return make.MethodDef(hashCodeSym, make.Block(0, List.of(make.Return(app))));
-        } else {
-            return make.Block(SYNTHETIC, List.nil());
-        }
-    }
-
-    JCTree recordOldEquals(JCClassDecl tree, List<VarSymbol> vars) {
-        make_at(tree.pos());
-
-        MethodSymbol oldEqualsSym = lookupMethod(tree.pos(),
-                         names.equals,
-                         tree.sym.type,
-                         List.of(syms.objectType));
-
-        if ((oldEqualsSym.flags() & RECORD) != 0) {
-            ListBuffer<JCStatement> trueStats = new ListBuffer<>();
-
-            VarSymbol o = oldEqualsSym.params.head;
-
-            VarSymbol that = new VarSymbol(SYNTHETIC, names.fromString("that" + target.syntheticNameChar()),
-                                                types.erasure(tree.type),
-                                                oldEqualsSym);
-
-            trueStats.add(make.VarDef(that,
-                    make.TypeCast(make.Type(types.erasure(tree.type)),
-                            make.Ident(o)).setType(types.erasure(tree.type))));
-
-            Symbol objectEqualsSym = lookupMethod(tree.pos(),
-                    names.equals,
-                    syms.objectsType,
-                    List.of(syms.objectType, syms.objectType));
-            for (VarSymbol v : vars) {
-                JCFieldAccess meth = make.Select(make.Type(syms.objectsType), names.equals);
-                meth.sym = objectEqualsSym;
-                meth.type = meth.sym.type;
-                JCExpression sel = make.Select(make.Ident(that), v);
-                JCMethodInvocation app = make.Apply(List.nil(), meth, List.of(make.Ident(v), sel));
-                app.type = meth.type.getReturnType();
-                JCUnary neg = make.Unary(Tag.NOT, app);
-                neg.operator = operators.resolveUnary(tree.pos(), Tag.NOT, syms.booleanType);
-                neg.type = neg.operator.getReturnType();
-                trueStats.add(make.If(neg, make.Return(make.Literal(false)), null));
-            }
-            trueStats.add(make.Return(make.Literal(true)));
-
-            JCStatement ifStat = make.If(make.TypeTest(make.Ident(o), make.Type(tree.type)).setType(syms.booleanType),
-                    make.Block(0, trueStats.toList()),
-                    make.Return(make.Literal(false)));
-
-            return make.MethodDef(oldEqualsSym, make.Block(0, List.of(ifStat)));
-        } else {
-            return make.Block(SYNTHETIC, List.nil());
-        }
-    }
-
     public void visitMethodDef(JCMethodDecl tree) {
         if (tree.name == names.init && (currentClass.flags_field&ENUM) != 0) {
             // Add "String $enum$name, int $enum$ordinal" to the beginning of the
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TypeEnter.java	Fri Apr 06 14:50:20 2018 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TypeEnter.java	Fri Apr 06 15:25:59 2018 -0400
@@ -894,10 +894,7 @@
             JCClassDecl tree = env.enclClass;
             ClassSymbol sym = tree.sym;
             if ((sym.flags_field & RECORD) != 0) {
-                List<JCVariableDecl> recordFields = TreeInfo.recordFields(tree);
-                List<JCVariableDecl> superFields = TreeInfo.superRecordFields(tree);
-                memberEnter.memberEnter(recordFields, env);
-                memberEnter.memberEnter(superFields, env);
+                memberEnter.memberEnter(TreeInfo.recordFields(tree), env);
             }
         }
     }
@@ -930,7 +927,7 @@
                         }
                     }
                 } else if ((sym.flags() & RECORD) != 0) {
-                    helper = new RecordConstructorHelper(sym, TreeInfo.recordFields(tree).map(vd -> vd.sym), TreeInfo.superRecordFields(tree));
+                    helper = new RecordConstructorHelper(sym, TreeInfo.recordFields(tree).map(vd -> vd.sym));
                 }
                 if (helper != null) {
                     JCTree constrDef = defaultConstructor(make.at(tree.pos), helper);
@@ -943,11 +940,10 @@
                         if (TreeInfo.isConstructor(def) &&
                             !TreeInfo.hasConstructorInvocation(((JCMethodDecl)def).body.stats, names, true)) {
                             RecordConstructorHelper helper = new RecordConstructorHelper(sym,
-                                    TreeInfo.recordFields(tree).map(vd -> vd.sym),
-                                    TreeInfo.superRecordFields(tree));
+                                    TreeInfo.recordFields(tree).map(vd -> vd.sym));
                             JCMethodDecl methDecl = (JCMethodDecl)def;
                             JCStatement supCall = make.at(methDecl.body.pos).Exec(make.Apply(List.nil(),
-                                    make.Ident(names._super), make.Idents(helper.superFields)));
+                                    make.Ident(names._super), List.nil()));
                             methDecl.body.stats = methDecl.body.stats.append(supCall);
                             ListBuffer<JCStatement> initializations = new ListBuffer<>();
                             for (Name initName : helper.inits()) {
@@ -1267,19 +1263,16 @@
     class RecordConstructorHelper extends BasicConstructorHelper {
 
         List<VarSymbol> recordFields;
-        List<JCVariableDecl> superFields;
 
-        RecordConstructorHelper(TypeSymbol owner, List<VarSymbol> recordFields, List<JCVariableDecl> superFields) {
+        RecordConstructorHelper(TypeSymbol owner, List<VarSymbol> recordFields) {
             super(owner);
             this.recordFields = recordFields;
-            this.superFields = superFields;
         }
 
         @Override
         public Type constructorType() {
             if (constructorType == null) {
-                List<Type> argtypes = superFields.map(v -> v.vartype.type)
-                        .appendList(recordFields.map(v -> v.type));
+                List<Type> argtypes = recordFields.map(v -> v.type);
                 constructorType = new MethodType(argtypes, syms.voidType, List.nil(), syms.methodClass);
             }
             return constructorType;
@@ -1289,9 +1282,6 @@
         public MethodSymbol constructorSymbol() {
             MethodSymbol csym = super.constructorSymbol();
             ListBuffer<VarSymbol> params = new ListBuffer<>();
-            for (JCVariableDecl p : superFields) {
-                params.add(new VarSymbol(MANDATED | PARAMETER, p.name, p.vartype.type, csym));
-            }
             for (VarSymbol p : recordFields) {
                 params.add(new VarSymbol(MANDATED | PARAMETER, p.name, p.type, csym));
             }
@@ -1301,11 +1291,6 @@
         }
 
         @Override
-        public List<Name> superArgs() {
-            return superFields.map(v -> v.name);
-        }
-
-        @Override
         public List<Name> inits() {
             return recordFields.map(v -> v.name);
         }
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java	Fri Apr 06 14:50:20 2018 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java	Fri Apr 06 15:25:59 2018 -0400
@@ -3130,7 +3130,7 @@
     }
 
     boolean isRestrictedRecordTypeName(Name name) {
-        return Feature.DATA_CLASSES.allowedInSource(source) && name == names.record;
+        return Feature.RECORDS.allowedInSource(source) && name == names.record;
     }
 
     /** VariableDeclaratorId = Ident BracketsOpt
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeInfo.java	Fri Apr 06 14:50:20 2018 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeInfo.java	Fri Apr 06 15:25:59 2018 -0400
@@ -184,15 +184,7 @@
         return tree.defs.stream()
                 .filter(t -> t.hasTag(VARDEF))
                 .map(t -> (JCVariableDecl)t)
-                .filter(vd -> (vd.getModifiers().flags & (Flags.RECORD | HYPOTHETICAL)) == RECORD)
-                .collect(List.collector());
-    }
-
-    public static List<JCVariableDecl> superRecordFields(JCClassDecl tree) {
-        return tree.defs.stream()
-                .filter(t -> t.hasTag(VARDEF))
-                .map(t -> (JCVariableDecl)t)
-                .filter(vd -> (vd.getModifiers().flags & (Flags.RECORD | HYPOTHETICAL)) == (RECORD | HYPOTHETICAL))
+                .filter(vd -> (vd.getModifiers().flags & (Flags.RECORD)) == RECORD)
                 .collect(List.collector());
     }