diff options
Diffstat (limited to 'sources/scalac')
-rw-r--r-- | sources/scalac/Global.java | 6 | ||||
-rw-r--r-- | sources/scalac/ast/TreeGen.java | 276 | ||||
-rw-r--r-- | sources/scalac/transformer/Erasure.java | 27 | ||||
-rw-r--r-- | sources/scalac/transformer/ExplicitOuterClassesPhase.java | 12 | ||||
-rw-r--r-- | sources/scalac/transformer/LambdaLift.java | 21 | ||||
-rw-r--r-- | sources/scalac/transformer/matching/CodeFactory.java | 16 | ||||
-rw-r--r-- | sources/scalac/typechecker/Analyzer.java | 12 | ||||
-rw-r--r-- | sources/scalac/typechecker/RefCheck.java | 24 |
8 files changed, 194 insertions, 200 deletions
diff --git a/sources/scalac/Global.java b/sources/scalac/Global.java index 3c24f16468..39a5f8d08d 100644 --- a/sources/scalac/Global.java +++ b/sources/scalac/Global.java @@ -448,7 +448,7 @@ public class Global { impl.body[impl.body.length - 1] = treeGen.Apply(last.pos, treeGen.Select(last.pos, - treeGen.mkRef(last.pos, INTERPRETER()), + treeGen.mkGlobalRef(last.pos, INTERPRETER()), SET_EVALUATION_RESULT()), new Tree[] { last, @@ -480,7 +480,7 @@ public class Global { body.append( treeGen.Apply(tree.pos, treeGen.Select(tree.pos, - treeGen.mkRef(tree.pos, INTERPRETER()), + treeGen.mkGlobalRef(tree.pos, INTERPRETER()), SHOW_DEFINITION()), new Tree[] { treeGen.mkStringLit(tree.pos, show(tree.symbol()))})); @@ -490,7 +490,7 @@ public class Global { body.append( treeGen.Apply(tree.pos, treeGen.Select(tree.pos, - treeGen.mkRef(tree.pos, INTERPRETER()), + treeGen.mkGlobalRef(tree.pos, INTERPRETER()), SHOW_VALUE_DEFINITION()), new Tree[] { treeGen.mkStringLit(tree.pos, show(tree.symbol())), diff --git a/sources/scalac/ast/TreeGen.java b/sources/scalac/ast/TreeGen.java index 669f513c78..7c6a3516ec 100644 --- a/sources/scalac/ast/TreeGen.java +++ b/sources/scalac/ast/TreeGen.java @@ -192,50 +192,104 @@ public class TreeGen implements Kinds, Modifiers, TypeTags { //######################################################################## // Public Methods - Building references - /** Builds references corresponding to given symbols. */ - public Tree[] mkRefs(int pos, Symbol[] syms) { - if (syms.length == 0) return Tree.EMPTY_ARRAY; - Tree[] trees = new Tree[syms.length]; + /** + * Builds a reference to primary constructor of given class with + * given qualifier. + */ + public Tree mkPrimaryConstructorRef(int pos, Tree qualifier, Symbol clasz){ + return mkRef(pos, qualifier, primaryConstructorOf(clasz)); + } + public Tree mkPrimaryConstructorRef(Tree qualifier, Symbol clasz) { + return mkPrimaryConstructorRef(qualifier.pos, qualifier, clasz); + } + + /** + * Builds a reference to primary constructor of given class with + * given stable prefix. + */ + public Tree mkPrimaryConstructorRef(int pos, Type stable, Symbol clasz) { + return mkRef(pos, stable, primaryConstructorOf(clasz)); + } + + /** + * Builds a local reference to primary constructor of given class. + */ + public Tree mkPrimaryConstructorLocalRef(int pos, Symbol clasz) { + return mkLocalRef(pos, primaryConstructorOf(clasz)); + } + + /** + * Builds a global reference to primary constructor of given + * class. + */ + public Tree mkPrimaryConstructorGlobalRef(int pos, Symbol clasz) { + return mkGlobalRef(pos, primaryConstructorOf(clasz)); + } + + /** Builds local references to given symbols. */ + public Tree[] mkLocalRefs(int pos, Symbol[] symbols) { + if (symbols.length == 0) return Tree.EMPTY_ARRAY; + Tree[] trees = new Tree[symbols.length]; for (int i = 0; i < trees.length; i++) - trees[i] = mkRef(pos, syms[i]); + trees[i] = mkLocalRef(pos, symbols[i]); return trees; } - /** Builds a reference corresponding to given symbol. */ - public Tree mkRef(int pos, Symbol sym) { - //System.out.println("mkref " + sym.owner().thisType() + " . " + sym);//DEBUG - return mkRef(pos, sym.owner().thisType(), sym); + /** Builds global references to given symbols. */ + public Tree[] mkGlobalRefs(int pos, Symbol[] symbols) { + if (symbols.length == 0) return Tree.EMPTY_ARRAY; + Tree[] trees = new Tree[symbols.length]; + for (int i = 0; i < trees.length; i++) + trees[i] = mkGlobalRef(pos, symbols[i]); + return trees; } - /** Builds a reference corresponding to given prefix & symbol. */ - public Tree mkRef(int pos, Type pre, Symbol sym) { - if (pre.isSameAs(Type.localThisType) || pre.symbol().isRoot()) - return Ident(pos, sym); - else - return Select(pos, mkStableId(pos, pre), sym); + /** Builds a reference to given symbol with given qualifier. */ + public Tree mkRef(int pos, Tree qualifier, Symbol symbol) { + return Select(pos, qualifier, symbol); + } + public Tree mkRef(Tree qualifier, Symbol symbol) { + return mkRef(qualifier.pos, qualifier, symbol); } - /** Builds a reference corresponding to given stable prefix. */ - public Tree mkStableId(int pos, Type pre) { - switch (pre.expandModuleThis()) { - case ThisType(Symbol sym): - return This(pos, sym); - case SingleType(Type pre1, Symbol sym): - Tree id = mkRef(pos, pre1, sym); - switch (sym.type()) { + /** + * Builds a reference to given symbol with given stable prefix. + */ + public Tree mkRef(int pos, Type stable, Symbol symbol) { + switch (stable) { + case ThisType(Symbol clasz): + if (clasz.isPackage()) return mkRef(pos, mkGlobalRef(pos, clasz.module()), symbol); // !!! + if (clasz.isNone()) return Ident(pos, symbol); + return mkRef(pos, This(pos, clasz), symbol); + case SingleType(Type prefix, Symbol member): + Tree tree = mkRef(pos, prefix, member); + switch (tree.type()) { case MethodType(Symbol[] params, _): - assert params.length == 0 : pre; - id = this.Apply(id, Tree.EMPTY_ARRAY); + assert params.length == 0: tree.type(); + tree = Apply(pos, tree); } - return id; + return mkRef(pos, tree, symbol); default: - throw Debug.abort("illegal case", pre); + throw Debug.abort("illegal case", stable); } } + /** Builds a local reference to given symbol. */ + public Tree mkLocalRef(int pos, Symbol symbol) { + if (symbol.isRoot()) return Ident(pos, symbol); + return mkRef(pos, symbol.owner().thisType(), symbol); + } + + /** Builds a global reference to given symbol. */ + public Tree mkGlobalRef(int pos, Symbol symbol) { + if (symbol.isRoot()) return Ident(pos, symbol); + assert symbol.owner().isModuleClass(): Debug.show(symbol); + return mkRef(pos, mkGlobalRef(pos, symbol.owner().module()), symbol); + } + /** Builds a This node corresponding to given class. */ public This This(int pos, Symbol clazz) { - assert clazz.isClass(): Debug.show(clazz); + assert clazz.isClassType(): Debug.show(clazz); This tree = make.This(pos, clazz); global.nextPhase(); tree.setType(clazz.thisType()); @@ -243,6 +297,19 @@ public class TreeGen implements Kinds, Modifiers, TypeTags { return tree; } + /** Builds a This node corresponding to given type. */ + public This This(int pos, Type type) { + switch (type) { + case ThisType(Symbol clasz): + return This(pos, clasz); + case SingleType(Type prefix, Symbol member): + assert member.isModule(): type; + return This(pos, member.moduleClass()); + default: + throw Debug.abort("illegal case", type); + } + } + /** Builds a Super node corresponding to given class. */ public Super Super(int pos, Symbol clazz) { assert clazz.isClass(): Debug.show(clazz); @@ -276,107 +343,23 @@ public class TreeGen implements Kinds, Modifiers, TypeTags { * Builds a Select node corresponding to given symbol selected * from given qualifier. */ - public Select Select(int pos, Tree qual, Symbol sym) { + public Select Select(int pos, Tree qualifier, Symbol sym) { assert sym.isTerm(): Debug.show(sym); sym.flags |= ACCESSED | SELECTOR; - Select tree = make.Select(pos, sym, qual); + Select tree = make.Select(pos, sym, qualifier); global.nextPhase(); - tree.setType(qual.type.memberStabilizedType(sym)); + tree.setType(qualifier.type.memberStabilizedType(sym)); global.prevPhase(); return tree; } - public Select Select(Tree qual, Symbol sym) { - return Select(qual.pos, qual, sym); + public Select Select(Tree qualifier, Symbol sym) { + return Select(qualifier.pos, qualifier, sym); } //######################################################################## // Public Methods - Building applications /** - * Builds calls to primary constructors of given types with given - * value arguments. - */ - public Tree[] mkPrimaryConstrs(int pos, Type[] types, Tree[][] vargs) { - assert types.length == vargs.length: Debug.show(types, " -- ", vargs); - Tree[] trees = new Tree[types.length]; - for (int i = 0; i < trees.length; i++) - trees[i] = mkPrimaryConstr(pos, types[i], vargs[i]); - return trees; - } - - /** - * Builds calls to primary constructors of given types with no - * value arguments. - */ - public Tree[] mkPrimaryConstrs(int pos, Type[] types) { - Tree[] trees = new Tree[types.length]; - for (int i = 0; i < trees.length; i++) - trees[i] = mkPrimaryConstr(pos, types[i]); - return trees; - } - - /** - * Builds a call to the primary constructor of given type with - * given value arguments. Missing type arguments are extracted - * from the given type. - */ - public Tree mkPrimaryConstr(int pos, Type type, Tree[] vargs) { - switch (type) { - case TypeRef(Type pre, Symbol clazz, Type[] targs): - return mkPrimaryConstr(pos, pre, clazz, targs, vargs); - default: - throw Debug.abort("invalid type", type); - } - } - - /** - * Builds a call to the primary constructor of given type with no - * value arguments. Missing type arguments are extracted from the - * given type. - */ - public Tree mkPrimaryConstr(int pos, Type type) { - return mkPrimaryConstr(pos, type, Tree.EMPTY_ARRAY); - } - - /** - * Builds a call to the primary constructor of given class with - * given type and value arguments. - */ - public Tree mkPrimaryConstr(int pos, Type pre, Symbol clazz, Type[] targs, - Tree[] vargs) - { - global.nextPhase(); - Symbol constr = clazz.primaryConstructor(); - global.prevPhase(); - return mkApplyTV(pos, mkRef(pos, constr), targs, vargs); - } - public Tree mkPrimaryConstr(int pos, Symbol clazz, Type[]targs, Tree[]vargs){ - return mkPrimaryConstr(pos,clazz.owner().thisType(),clazz,targs,vargs); - } - - /** - * Builds a call to the primary constructor of given class with - * given type arguments and no value arguments. - */ - public Tree mkPrimaryConstr(int pos, Type pre, Symbol clazz, Type[] targs){ - return mkPrimaryConstr(pos, pre, clazz, targs, Tree.EMPTY_ARRAY); - } - public Tree mkPrimaryConstr(int pos, Symbol clazz, Type[] targs) { - return mkPrimaryConstr(pos, clazz.owner().thisType(), clazz, targs); - } - - /** - * Builds a call to the primary constructor of given class with no - * type and value arguments. - */ - public Tree mkPrimaryConstr(int pos, Type pre, Symbol clazz) { - return mkPrimaryConstr(pos, pre, clazz, Type.EMPTY_ARRAY); - } - public Tree mkPrimaryConstr(int pos, Symbol clazz) { - return mkPrimaryConstr(pos, clazz.owner().thisType(), clazz); - } - - /** * Builds an application with given function, type arguments and * value arguments. */ @@ -539,7 +522,7 @@ public class TreeGen implements Kinds, Modifiers, TypeTags { return mkImportAll(qualifier.pos, qualifier); } public Import mkImportAll(int pos, Symbol qualifier) { - return mkImportAll(pos, mkRef(pos, qualifier)); + return mkImportAll(pos, mkGlobalRef(pos, qualifier)); } /** Builds an instance test with given value and type. */ @@ -582,7 +565,7 @@ public class TreeGen implements Kinds, Modifiers, TypeTags { return Import(qualifier.pos, qualifier, names); } public Import Import(int pos, Symbol qualifier, Name[] names) { - return Import(pos, mkRef(pos, qualifier), names); + return Import(pos, mkGlobalRef(pos, qualifier), names); } /** Builds a Template node with given symbol, parents and body. */ @@ -739,7 +722,7 @@ public class TreeGen implements Kinds, Modifiers, TypeTags { /** Builds an empty list. */ public Tree mkNil(int pos) { - return mkRef(pos, definitions.NIL); + return mkGlobalRef(pos, definitions.NIL); } /** Builds a list with given element type, head and tail. */ @@ -749,8 +732,11 @@ public class TreeGen implements Kinds, Modifiers, TypeTags { element + " -- " + head + " : " + head.type; assert tail.type().isSubType(definitions.LIST_TYPE(element)): element + " -- " + tail + " : " + tail.type; - Type cons = definitions.CONS_TYPE(element); - return New(mkPrimaryConstr(pos, cons, new Tree[]{head, tail})); + return New( + mkApplyTV( + mkPrimaryConstructorGlobalRef(pos, definitions.CONS_CLASS), + new Type[]{element}, + new Tree[]{head, tail})); } public Tree mkNewCons(Type element, Tree head, Tree tail) { return mkNewCons(head.pos, element, head, tail); @@ -769,8 +755,11 @@ public class TreeGen implements Kinds, Modifiers, TypeTags { /** Builds a new array tree with given element type and length. */ public Tree mkNewArray(int pos, Type element, Tree length) { - Type array = definitions.ARRAY_TYPE(element); - return New(mkPrimaryConstr(pos, array, new Tree[]{length})); + return New( + mkApplyTV( + mkPrimaryConstructorGlobalRef(pos, definitions.ARRAY_CLASS), + new Type[]{element}, + new Tree[]{length})); } public Tree mkNewArray(Type element, Tree length) { return mkNewArray(length.pos, element, length); @@ -892,7 +881,7 @@ public class TreeGen implements Kinds, Modifiers, TypeTags { return tree; } public PackageDef PackageDef(Symbol peckage, Template template) { - return PackageDef(mkRef(peckage.pos, peckage), template); + return PackageDef(mkGlobalRef(peckage.pos, peckage), template); } /** Builds a PackageDef with given package and body. */ @@ -902,7 +891,7 @@ public class TreeGen implements Kinds, Modifiers, TypeTags { Template(peckage.pos, Symbol.NONE, Tree.EMPTY_ARRAY, body)); } public PackageDef PackageDef(Symbol peckage, Tree[] body) { - return PackageDef(mkRef(peckage.pos, peckage), body); + return PackageDef(mkGlobalRef(peckage.pos, peckage), body); } /** Builds a ClassDef node for given class with given template. */ @@ -946,7 +935,18 @@ public class TreeGen implements Kinds, Modifiers, TypeTags { Global.instance.nextPhase(); Type[] parents = clazz.parents(); Global.instance.prevPhase(); - Tree[] constrs = mkPrimaryConstrs(clazz.pos, parents); + Tree[] constrs = new Tree[parents.length]; + for (int i = 0; i < constrs.length; i++) { + switch (parents[i]) { + case TypeRef(Type prefix, Symbol parent, Type[] targs): + constrs[i] = mkApplyT_( + mkPrimaryConstructorRef(clazz.pos, prefix, parent), + targs); + continue; + default: + throw Debug.abort("invalid type", parents[i]); + } + } return ClassDef(clazz, constrs, Symbol.NONE, body); } @@ -1048,6 +1048,14 @@ public class TreeGen implements Kinds, Modifiers, TypeTags { return local; } + /** Returns the primary constructor of given class. */ + private Symbol primaryConstructorOf(Symbol clasz) { + global.nextPhase(); + Symbol constr = clasz.primaryConstructor(); + global.prevPhase(); + return constr; + } + //######################################################################## //######################################################################## //######################################################################## @@ -1102,11 +1110,9 @@ public class TreeGen implements Kinds, Modifiers, TypeTags { params[i].setOwner(applyMeth); } changeOwner(body, owner, applyMeth); - Tree[] parentTrees = mkPrimaryConstrs(pos, parentTypes); Tree[] memberTrees = { DefDef(applyMeth, body) }; - Symbol local = TermSymbol.newLocalDummy(clazz); - Tree classDef = ClassDef(clazz, parentTrees, local, memberTrees); - Tree alloc = New(pos, mkPrimaryConstr(pos, clazz)) + Tree classDef = ClassDef(clazz, memberTrees); + Tree alloc = New(mkApply__(mkPrimaryConstructorLocalRef(pos, clazz))) .setType(parentTypes[1]); // !!! return Block(new Tree[]{classDef, alloc}); } @@ -1122,15 +1128,13 @@ public class TreeGen implements Kinds, Modifiers, TypeTags { clazz.setInfo(Type.compoundType(parentTypes, new Scope(), clazz)); clazz.allConstructors().setInfo( Type.MethodType(Symbol.EMPTY_ARRAY, clazz.typeConstructor())); - Tree[] parentTrees = mkPrimaryConstrs(pos, parentTypes); Tree[] memberTrees = { makeVisitorMethod(pos, Names.apply, applyVisitor, pattype, restype, clazz, owner), makeVisitorMethod(pos, Names.isDefinedAt, isDefinedAtVisitor, pattype, definitions.BOOLEAN_TYPE(), clazz, owner)}; - Symbol local = TermSymbol.newLocalDummy(clazz); - Tree classDef = ClassDef(clazz, parentTrees, local, memberTrees); - Tree alloc = New(pos, mkPrimaryConstr(pos, clazz)) + Tree classDef = ClassDef(clazz, memberTrees); + Tree alloc = New(mkApply__(mkPrimaryConstructorLocalRef(pos, clazz))) .setType(parentTypes[1]); // !!! return Block(new Tree[]{classDef, alloc}); } @@ -1194,7 +1198,7 @@ public class TreeGen implements Kinds, Modifiers, TypeTags { public Tree Console_print(int pos, Tree arg) { Symbol sym = global.definitions.getModule( Names.scala_Console ); return Apply( Select( pos, - mkRef( pos, sym), + mkGlobalRef( pos, sym), global.definitions.CONSOLE_PRINT()), new Tree[] { arg diff --git a/sources/scalac/transformer/Erasure.java b/sources/scalac/transformer/Erasure.java index 244712fe36..0de4624d01 100644 --- a/sources/scalac/transformer/Erasure.java +++ b/sources/scalac/transformer/Erasure.java @@ -295,7 +295,7 @@ public class Erasure extends GenTransformer implements Modifiers { private Tree transformUnit(int pos, Type pt) { Tree unit = pt.isSameAs(UNBOXED_UNIT) ? gen.mkUnitLit(pos) - : gen.mkApply__(gen.mkRef(pos, primitives.BOX_UVALUE)); + : gen.mkApply__(gen.mkGlobalRef(pos, primitives.BOX_UVALUE)); return coerce(unit, pt); } @@ -305,7 +305,7 @@ public class Erasure extends GenTransformer implements Modifiers { if (tree.type().symbol() == definitions.ARRAY_CLASS) { if (pt.symbol() != definitions.ARRAY_CLASS) { Symbol symbol = primitives.UNBOX__ARRAY; - Tree unboxtree = gen.mkRef(tree.pos, symbol); + Tree unboxtree = gen.mkGlobalRef(tree.pos, symbol); tree = gen.mkApply_V(unboxtree, new Tree[] {tree}); return coerce(tree, pt); } @@ -331,7 +331,7 @@ public class Erasure extends GenTransformer implements Modifiers { if (tree.type.symbol() == definitions.ARRAY_CLASS) return unbox(tree, pt); } else if (pt.symbol() == definitions.ARRAY_CLASS) { - Tree boxtree = gen.mkRef(tree.pos, primitives.BOX__ARRAY); + Tree boxtree = gen.mkGlobalRef(tree.pos, primitives.BOX__ARRAY); return gen.mkApply_V(boxtree, new Tree[]{tree}); } return gen.mkAsInstanceOf(tree, pt); @@ -352,7 +352,7 @@ public class Erasure extends GenTransformer implements Modifiers { } } Symbol symbol = primitives.getBoxValueSymbol(tree.getType()); - Tree boxtree = gen.mkRef(tree.pos, symbol); + Tree boxtree = gen.mkGlobalRef(tree.pos, symbol); return tree.getType().equals(UNBOXED_UNIT) ? gen.Block(new Tree[]{tree, gen.mkApply__(boxtree)}) : gen.mkApply_V(boxtree, new Tree[]{tree}); @@ -368,13 +368,15 @@ public class Erasure extends GenTransformer implements Modifiers { } } Symbol symbol = primitives.getUnboxValueSymbol(pt); - return gen.mkApply_V(gen.mkRef(tree.pos, symbol), new Tree[]{tree}); + return gen.mkApply_V( + gen.mkGlobalRef(tree.pos, symbol), new Tree[]{tree}); } /** Converts the given tree to the given type. */ private Tree convert(Tree tree, Type to) { Symbol symbol = primitives.getConvertSymbol(tree.type(), to); - return gen.mkApply_V(gen.mkRef(tree.pos, symbol), new Tree[]{tree}); + return gen.mkApply_V( + gen.mkGlobalRef(tree.pos, symbol), new Tree[]{tree}); } //######################################################################## @@ -385,7 +387,7 @@ public class Erasure extends GenTransformer implements Modifiers { Type type = bridge.nextType(); Tree body = genApply(bridge.pos, gen.Select(gen.This(bridge.pos, bridge.owner()), method), - gen.mkRefs(bridge.pos, type.valueParams())); + gen.mkLocalRefs(bridge.pos, type.valueParams())); return gen.DefDef(bridge, coerce(body, type.resultType())); } @@ -440,7 +442,8 @@ public class Erasure extends GenTransformer implements Modifiers { } String name = primitives.getNameForClassForName(element); Tree[] args = { coerce(size, UNBOXED_INT), gen.mkStringLit(pos,name) }; - Tree array = gen.mkApply_V(gen.mkRef(pos,primitives.NEW_OARRAY), args); + Tree array = + gen.mkApply_V(gen.mkGlobalRef(pos,primitives.NEW_OARRAY), args); return gen.mkAsInstanceOf(array, Type.UnboxedArrayType(element)); } @@ -451,7 +454,7 @@ public class Erasure extends GenTransformer implements Modifiers { private Tree genNewUnboxedArray(int pos, int kind, Tree size) { Symbol symbol = primitives.getNewArraySymbol(kind); Tree[] args = { coerce(size, UNBOXED_INT) }; - return gen.mkApply_V(gen.mkRef(pos, symbol), args); + return gen.mkApply_V(gen.mkGlobalRef(pos, symbol), args); } /** Generates an unboxed array length operation. */ @@ -459,7 +462,7 @@ public class Erasure extends GenTransformer implements Modifiers { assert isUnboxedArrayType(array.getType()): array; Symbol symbol = primitives.getArrayLengthSymbol(array.getType()); Tree[] args = { array }; - return gen.mkApply_V(gen.mkRef(pos, symbol), args); + return gen.mkApply_V(gen.mkGlobalRef(pos, symbol), args); } /** Generates an unboxed array get operation. */ @@ -468,7 +471,7 @@ public class Erasure extends GenTransformer implements Modifiers { Symbol symbol = primitives.getArrayGetSymbol(array.getType()); index = coerce(index, UNBOXED_INT); Tree[] args = { array, index }; - return gen.mkApply_V(gen.mkRef(pos, symbol), args); + return gen.mkApply_V(gen.mkGlobalRef(pos, symbol), args); } /** Generates an unboxed array set operation. */ @@ -478,7 +481,7 @@ public class Erasure extends GenTransformer implements Modifiers { index = coerce(index, UNBOXED_INT); value = coerce(value, getArrayElementType(array.getType())); Tree[] args = { array, index, value }; - return gen.mkApply_V(gen.mkRef(pos, symbol), args); + return gen.mkApply_V(gen.mkGlobalRef(pos, symbol), args); } //######################################################################## diff --git a/sources/scalac/transformer/ExplicitOuterClassesPhase.java b/sources/scalac/transformer/ExplicitOuterClassesPhase.java index 0224d36f91..57c5067862 100644 --- a/sources/scalac/transformer/ExplicitOuterClassesPhase.java +++ b/sources/scalac/transformer/ExplicitOuterClassesPhase.java @@ -260,8 +260,7 @@ public class ExplicitOuterClassesPhase extends Phase { public Type getTypeLink(int level) { if (tlinks.length <= level) return Type.localThisType; if (tlinks[level] != null) return tlinks[level].type(); - // !!! if (clasz.isPackage()) return Type.localThisType; - return Type.singleType(getTypeLink(level + 1), clasz.module()); + return Type.singleType(getTypeLink(level + 1), outers[level].clasz.module()); } public String toString() { @@ -318,14 +317,9 @@ public class ExplicitOuterClassesPhase extends Phase { case ThisType(Symbol clasz): if (clasz == Symbol.NONE) return type; if (clasz == context.clasz) return type; - if (clasz.isPackage()) return Type.localThisType; for (int i = 0; i < context.outers.length; i++) if (clasz == context.outers[i].clasz) return context.getTypeLink(i); - if (clasz.isModuleClass()) { - Type prefix = clasz.owner().thisType(); - return Type.singleType(apply(prefix), clasz.module()); - } throw Debug.abort("illegal ThisType", type); case CompoundType(Type[] parents, Scope members): // !!! this case should not be needed @@ -397,6 +391,8 @@ public class ExplicitOuterClassesPhase extends Phase { case This(_): return genOuterRef(tree.pos, tree.symbol()); +// Symbol clasz = tree.symbol(); +// return clasz.isRoot() ? tree : genOuterRef(tree.pos, clasz); case Select(Tree qualifier, _): Symbol symbol = tree.symbol(); @@ -510,7 +506,7 @@ public class ExplicitOuterClassesPhase extends Phase { Symbol forward = (Symbol)entry.getValue(); int pos = forward.pos; Tree[] targs = gen.mkTypeRefs(pos, forward.nextTypeParams()); - Tree[] vargs = gen.mkRefs(pos, forward.nextValueParams()); + Tree[] vargs = gen.mkLocalRefs(pos, forward.nextValueParams()); Tree fun = gen.Select(gen.Super(pos, context.clasz), method); trees[i] = gen.DefDef(forward, gen.mkApplyTV(fun,targs,vargs)); } diff --git a/sources/scalac/transformer/LambdaLift.java b/sources/scalac/transformer/LambdaLift.java index 1acc0ba676..c2f1378a60 100644 --- a/sources/scalac/transformer/LambdaLift.java +++ b/sources/scalac/transformer/LambdaLift.java @@ -417,18 +417,21 @@ public class LambdaLift extends OwnerTransformer transform(tparams, currentOwner), transform(rhs, currentOwner)); - case ValDef(_, _, Tree tpe, Tree rhs): + case ValDef(_, _, _, Tree rhs): Symbol sym = tree.symbol(); - Tree tpe1 = transform(tpe); - Tree rhs1 = transform(rhs, sym); + rhs = transform(rhs, sym); if ((sym.flags & CAPTURED) != 0) { assert sym.isLocal(); - Type boxedType = sym.nextType(); - tpe1 = gen.mkType(tpe.pos, boxedType); - rhs1 = gen.New( - gen.mkPrimaryConstr(rhs.pos, boxedType, new Tree[]{rhs1})); + switch (sym.nextType()) { + case TypeRef(_, Symbol clasz, Type[] args): + Tree constr = gen.mkPrimaryConstructorGlobalRef(rhs.pos, clasz); + rhs = gen.New(gen.mkApplyTV(constr, args, new Tree[]{rhs})); + break; + default: + throw Debug.abort("illegal case", sym.nextType()); + } } - return copy.ValDef(tree, sym, tpe1, rhs1); + return gen.ValDef(sym, rhs); case Sequence(Tree[] args): Tree tree1 = gen.mkNewList(tree.pos, tree.type.typeArgs()[0], transform(args)); @@ -486,7 +489,7 @@ public class LambdaLift extends OwnerTransformer sym = descr.proxy(sym, currentOwner); } Tree tree1 = (sym.owner().kind == CLASS) - ? gen.mkRef(tree.pos, sym) + ? gen.mkLocalRef(tree.pos, sym) : copy.Ident(tree, sym).setType(sym.nextType()); if (name != sym.name) { if (tree1 instanceof Ident) ((Ident)tree1).name = sym.name; diff --git a/sources/scalac/transformer/matching/CodeFactory.java b/sources/scalac/transformer/matching/CodeFactory.java index 36c4a29683..8bb592327e 100644 --- a/sources/scalac/transformer/matching/CodeFactory.java +++ b/sources/scalac/transformer/matching/CodeFactory.java @@ -69,9 +69,9 @@ class CodeFactory extends PatternTool { // EXPERIMENTAL Tree newRef( Tree init ) { //System.out.println( "hello:"+refSym().type() ); - return gen.New(gen.mkPrimaryConstr(pos, defs.REF_CLASS, - new Type[] { init.getType() }, - new Tree[] { init } )); + return gen.New( gen.mkApplyTV( gen.mkPrimaryConstructorGlobalRef( pos, defs.REF_CLASS), + new Type[] { init.getType() }, + new Tree[] { init } )); } /** returns A for T <: Sequence[ A ] @@ -187,7 +187,7 @@ class CodeFactory extends PatternTool { protected Tree ThrowMatchError(int pos, Type type) { return gen.mkApplyTV( - gen.mkRef(pos, defs.MATCHERROR_FAIL()), + gen.mkGlobalRef(pos, defs.MATCHERROR_FAIL()), new Tree[]{gen.mkType(pos, type)}, new Tree[]{ gen.mkStringLit(pos, unit.toString()), @@ -197,7 +197,7 @@ class CodeFactory extends PatternTool { protected Tree Error(int pos, Type type) { return gen.mkApplyTV( - gen.mkRef(pos, defs.MATCHERROR_FAIL()), + gen.mkGlobalRef(pos, defs.MATCHERROR_FAIL()), new Tree[]{gen.mkType(pos, type)}, new Tree[]{ gen.mkStringLit(pos, unit.toString()), @@ -211,9 +211,9 @@ class CodeFactory extends PatternTool { } Tree newPair( Tree left, Tree right ) { - return gen.New(gen.mkPrimaryConstr(pos, defs.TUPLE_CLASS[2], - new Type[] { left.getType(), right.getType() }, - new Tree[] { left, right })); + return gen.New(gen.mkApplyTV( gen.mkPrimaryConstructorGlobalRef( pos, defs.TUPLE_CLASS[2]), + new Type[] { left.getType(), right.getType() }, + new Tree[] { left, right })); } diff --git a/sources/scalac/typechecker/Analyzer.java b/sources/scalac/typechecker/Analyzer.java index 7099163995..9953f1dde7 100644 --- a/sources/scalac/typechecker/Analyzer.java +++ b/sources/scalac/typechecker/Analyzer.java @@ -1169,13 +1169,6 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { } } - Tree makeStableId(int pos, Type tp) { - if (tp.symbol().isCompoundSym()) - return gen.This(pos, tp.symbol()); - else - return gen.mkStableId(pos, tp); - } - /** Define self type of class or module `sym' * associated with `tree' using given `unit' and `context'. */ @@ -1500,7 +1493,7 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { if (sym.owner().kind == CLASS) { pre = nextcontext.enclClass.owner.thisType(); if (!sym.owner().isPackage()) { - Tree qual1 = makeStableId(tree.pos, pre); + Tree qual1 = gen.This(tree.pos, nextcontext.enclClass.owner); tree = make.Select(tree.pos, qual1, name); //System.out.println(name + " :::> " + tree + " " + qual1.symbol());//DEBUG } @@ -2203,9 +2196,8 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { Tree alloc = gen.New( gen.Apply( - gen.mkRef( + gen.mkLocalRef( tree.pos, - Type.localThisType, clazz.primaryConstructor()), Tree.EMPTY_ARRAY)) .setType(owntype); diff --git a/sources/scalac/typechecker/RefCheck.java b/sources/scalac/typechecker/RefCheck.java index d787c803cf..ac84a1dbac 100644 --- a/sources/scalac/typechecker/RefCheck.java +++ b/sources/scalac/typechecker/RefCheck.java @@ -525,7 +525,7 @@ public class RefCheck extends Transformer implements Modifiers, Kinds { Symbol sym = tree.symbol(); Tree cdef = gen.ClassDef(sym.moduleClass(), templ); if (sym.isGlobalModule()) return new Tree[]{cdef}; - Tree alloc = gen.New(gen.mkPrimaryConstr(tree.pos, sym.moduleClass())); + Tree alloc = gen.New(gen.mkApply__(gen.mkPrimaryConstructorLocalRef(tree.pos, sym.moduleClass()))); { // var m$: T = null; Name varname = Name.fromString(name + "$"); @@ -542,10 +542,10 @@ public class RefCheck extends Transformer implements Modifiers, Kinds { gen.If( gen.Apply( gen.Select(gen.mkNullLit(tree.pos), eqMethod), - new Tree[]{gen.mkRef(tree.pos, mvar)}), - gen.Assign(gen.mkRef(tree.pos, mvar), alloc), + new Tree[]{gen.mkLocalRef(tree.pos, mvar)}), + gen.Assign(gen.mkLocalRef(tree.pos, mvar), alloc), gen.Block(tree.pos, Tree.EMPTY_ARRAY)), - gen.mkRef(tree.pos, mvar)}); + gen.mkLocalRef(tree.pos, mvar)}); // def m: T = { if (m$ == null[T]) m$ = new m$class; m$ } sym.flags |= STABLE; @@ -560,7 +560,7 @@ public class RefCheck extends Transformer implements Modifiers, Kinds { m_eq.setInfo( Type.MethodType(new Symbol[] {m_eqarg}, defs.UNIT_TYPE())); Tree m_eqdef = gen.DefDef(m_eq, - gen.Assign(gen.mkRef(tree.pos, mvar), gen.Ident(tree.pos, m_eqarg))); + gen.Assign(gen.mkLocalRef(tree.pos, mvar), gen.Ident(tree.pos, m_eqarg))); sym.owner().members().enterOrOverload(m_eq); return new Tree[]{cdef, vdef, ddef, m_eqdef}; @@ -622,8 +622,7 @@ public class RefCheck extends Transformer implements Modifiers, Kinds { Symbol[] vparams = clazz.primaryConstructor().type().firstParams(); Tree[] fields = new Tree[vparams.length]; for (int i = 0; i < fields.length; i++) { - fields[i] = gen.mkRef( - clazz.pos, clazz.thisType(), clazz.caseFieldAccessor(i)); + fields[i] = gen.mkRef(clazz.pos, clazz.thisType(), clazz.caseFieldAccessor(i)); } return fields; } @@ -675,9 +674,7 @@ public class RefCheck extends Transformer implements Modifiers, Kinds { } // if (that is C) {... Tree cond = gen.TypeApply( - gen.Select( - gen.mkRef(clazz.pos, Type.localThisType, equalsParam), - defs.ANY_IS), + gen.Select(gen.mkLocalRef(clazz.pos, equalsParam), defs.ANY_IS), new Tree[]{gen.mkType(clazz.pos, testtp)}); Tree thenpart; @@ -687,7 +684,7 @@ public class RefCheck extends Transformer implements Modifiers, Kinds { // val that1 = that as C; Tree cast = gen.TypeApply( gen.Select( - gen.mkRef(clazz.pos, Type.localThisType, equalsParam), + gen.mkLocalRef(clazz.pos, equalsParam), defs.ANY_AS), new Tree[]{gen.mkType(clazz.pos, testtp)}); Symbol that1sym = new TermSymbol(clazz.pos, Names.that1, equalsSym, 0) @@ -697,8 +694,7 @@ public class RefCheck extends Transformer implements Modifiers, Kinds { // this.elem_1 == that1.elem_1 && ... && this.elem_n == that1.elem_n Tree cmp = eqOp( fields[0], - qualCaseField(clazz, - gen.mkRef(clazz.pos, Type.localThisType, that1sym), 0)); + qualCaseField(clazz, gen.mkLocalRef(clazz.pos, that1sym), 0)); for (int i = 1; i < fields.length; i++) { cmp = gen.Apply( gen.Select(cmp, defs.BOOLEAN_AND()), @@ -706,7 +702,7 @@ public class RefCheck extends Transformer implements Modifiers, Kinds { eqOp( fields[i], qualCaseField(clazz, - gen.mkRef(clazz.pos, Type.localThisType, that1sym), i))}); + gen.mkLocalRef(clazz.pos, that1sym), i))}); } thenpart = gen.Block(new Tree[]{that1def, cmp}); } |