diff options
author | Paul Phillips <paulp@improving.org> | 2012-01-16 07:09:07 -0800 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-01-16 13:27:08 -0800 |
commit | bf6ce00f2146ae2c3feb5d2c8a2ed5f5d441ba3b (patch) | |
tree | 985b1dd8ea85476c73c03a09390a9d513ccc1017 /src/compiler/scala/reflect/internal | |
parent | 44d783a5eaa4e77c45c6565a70395525712ded23 (diff) | |
download | scala-bf6ce00f2146ae2c3feb5d2c8a2ed5f5d441ba3b.tar.gz scala-bf6ce00f2146ae2c3feb5d2c8a2ed5f5d441ba3b.tar.bz2 scala-bf6ce00f2146ae2c3feb5d2c8a2ed5f5d441ba3b.zip |
Symbol creation followup.
Changed most symbol creations to be consistent with all the others.
Opportunistically streamlined various call sites. Moved some phase-specific
methods out of Symbol to somewhere more appropriate (like that phase.)
Diffstat (limited to 'src/compiler/scala/reflect/internal')
4 files changed, 27 insertions, 32 deletions
diff --git a/src/compiler/scala/reflect/internal/AnnotationInfos.scala b/src/compiler/scala/reflect/internal/AnnotationInfos.scala index 665e33e783..255e69c3c6 100644 --- a/src/compiler/scala/reflect/internal/AnnotationInfos.scala +++ b/src/compiler/scala/reflect/internal/AnnotationInfos.scala @@ -230,10 +230,8 @@ trait AnnotationInfos extends api.AnnotationInfos { self: SymbolTable => def refsSymbol(sym: Symbol) = hasArgWhich(_.symbol == sym) /** Change all ident's with Symbol "from" to instead use symbol "to" */ - def substIdentSyms(from: Symbol, to: Symbol) = { - val subs = new TreeSymSubstituter(List(from), List(to)) - AnnotationInfo(atp, args.map(subs(_)), assocs).setPos(pos) - } + def substIdentSyms(from: Symbol, to: Symbol) = + AnnotationInfo(atp, args map (_ substTreeSyms (from -> to)), assocs) setPos pos def stringArg(index: Int) = constantAtIndex(index) map (_.stringValue) def intArg(index: Int) = constantAtIndex(index) map (_.intValue) diff --git a/src/compiler/scala/reflect/internal/Symbols.scala b/src/compiler/scala/reflect/internal/Symbols.scala index 1b9ff54141..20e4362ae4 100644 --- a/src/compiler/scala/reflect/internal/Symbols.scala +++ b/src/compiler/scala/reflect/internal/Symbols.scala @@ -212,17 +212,6 @@ trait Symbols extends api.Symbols { self: SymbolTable => setInfo OverloadedType(pre, alternatives) ) - /** for explicit outer phase */ - final def newOuterAccessor(pos: Position) = { - val accFlags = METHOD | STABLE | SYNTHETIC | ( - if (isTrait) DEFERRED else 0 - ) - val sym = newMethodSymbol(nme.OUTER, pos, accFlags) - sym.expandName(this) - sym.referenced = this - sym - } - final def newErrorValue(name: TermName) = newTermSymbol(name, pos, SYNTHETIC | IS_ERROR) setInfo ErrorType @@ -285,6 +274,14 @@ trait Symbols extends api.Symbols { self: SymbolTable => final def newClass(name: TypeName, pos: Position = NoPosition, newFlags: Long = 0L) = newClassSymbol(name, pos, newFlags) + + /** A new class with its info set to a ClassInfoType with given scope and parents. */ + def newClassWithInfo(name: TypeName, parents: List[Type], scope: Scope, pos: Position = NoPosition, newFlags: Long = 0L) = { + val clazz = newClass(name, pos, newFlags) + clazz setInfo ClassInfoType(parents, scope, clazz) + } + final def newErrorClass(name: TypeName) = + newClassWithInfo(name, Nil, new ErrorScope(this), pos, SYNTHETIC | IS_ERROR) final def newModuleClass(name: TypeName, pos: Position = NoPosition) = newModuleClassSymbol(name, pos) @@ -312,11 +309,6 @@ trait Symbols extends api.Symbols { self: SymbolTable => setInfo MethodType(Nil, tpe) ) - final def newErrorClass(name: TypeName) = { - val clazz = newClassSymbol(name, pos, SYNTHETIC | IS_ERROR) - clazz setInfo ClassInfoType(Nil, new ErrorScope(this), clazz) - } - final def newErrorSymbol(name: Name): Symbol = name match { case x: TypeName => newErrorClass(x) case x: TermName => newErrorValue(x) @@ -1196,7 +1188,7 @@ trait Symbols extends api.Symbols { self: SymbolTable => oldsymbuf += sym newsymbuf += ( if (sym.isClass) - tp.typeSymbol.newAbstractType(sym.pos, sym.name.toTypeName).setInfo(sym.existentialBound) + tp.typeSymbol.newAbstractType(sym.name.toTypeName, sym.pos).setInfo(sym.existentialBound) else sym.cloneSymbol(tp.typeSymbol)) } @@ -1346,15 +1338,15 @@ trait Symbols extends api.Symbols { self: SymbolTable => cloneSymbol(owner) /** A clone of this symbol, but with given owner. */ - final def cloneSymbol(owner: Symbol): Symbol = { - val newSym = cloneSymbolImpl(owner, this.rawflags) + final def cloneSymbol(owner: Symbol): Symbol = cloneSymbol(owner, this.rawflags) + final def cloneSymbol(owner: Symbol, newFlags: Long): Symbol = { + val newSym = cloneSymbolImpl(owner, newFlags) ( newSym setPrivateWithin privateWithin setInfo (info cloneInfo newSym) setAnnotations this.annotations ) } - /** Internal method to clone a symbol's implementation with the given flags and no info. */ def cloneSymbolImpl(owner: Symbol, newFlags: Long): Symbol def cloneSymbolImpl(owner: Symbol): Symbol = cloneSymbolImpl(owner, 0L) diff --git a/src/compiler/scala/reflect/internal/Trees.scala b/src/compiler/scala/reflect/internal/Trees.scala index 1cefc07c3d..a2c55a89d6 100644 --- a/src/compiler/scala/reflect/internal/Trees.scala +++ b/src/compiler/scala/reflect/internal/Trees.scala @@ -121,7 +121,12 @@ trait Trees extends api.Trees { self: SymbolTable => new ChangeOwnerTraverser(oldOwner, newOwner) apply t } } - + + def substTreeSyms(pairs: (Symbol, Symbol)*): Tree = { + val list = pairs.toList + val subst = new TreeSymSubstituter(list map (_._1), list map (_._2)) + subst(tree) + } def shallowDuplicate: Tree = new ShallowDuplicator(tree) transform tree def shortClass: String = tree.getClass.getName split "[.$]" last /** When you want to know a little more than the class, but a lot diff --git a/src/compiler/scala/reflect/internal/Types.scala b/src/compiler/scala/reflect/internal/Types.scala index dfe098e282..73f1f3db84 100644 --- a/src/compiler/scala/reflect/internal/Types.scala +++ b/src/compiler/scala/reflect/internal/Types.scala @@ -3726,7 +3726,7 @@ trait Types extends api.Types { self: SymbolTable => def typeParamsToExistentials(clazz: Symbol, tparams: List[Symbol]): List[Symbol] = { val eparams = mapWithIndex(tparams)((tparam, i) => - clazz.newExistential(clazz.pos, newTypeName("?"+i)) setInfo tparam.info.bounds) + clazz.newExistential(newTypeName("?"+i), clazz.pos) setInfo tparam.info.bounds) eparams map (_ substInfo (tparams, eparams)) } @@ -3848,10 +3848,10 @@ trait Types extends api.Types { self: SymbolTable => if (tree.symbol isNonBottomSubClass clazz) && (pre.widen.typeSymbol isNonBottomSubClass tree.symbol) => if (pre.isStable) { // XXX why is this in this method? pull it out and guard the call `annotationArgRewriter.transform(tree)`? - val termSym = - pre.typeSymbol.owner.newValue( - pre.typeSymbol.pos, - pre.typeSymbol.name.toTermName).setInfo(pre) // what symbol should really be used? + val termSym = ( + pre.typeSymbol.owner.newValue(pre.typeSymbol.name.toTermName, pre.typeSymbol.pos) // what symbol should really be used? + setInfo pre + ) gen.mkAttributedQualifier(pre, termSym) } else giveup() @@ -4205,7 +4205,7 @@ trait Types extends api.Types { self: SymbolTable => val symowner = oldSym.owner val bound = singletonBounds(actualsIndexed(actualIdx)) - val sym = symowner.newExistential(oldSym.pos, newTypeName(oldSym.name + ".type")) + val sym = symowner.newExistential(newTypeName(oldSym.name + ".type"), oldSym.pos) sym.setInfo(bound) sym.setFlag(oldSym.flags) @@ -5892,7 +5892,7 @@ trait Types extends api.Types { self: SymbolTable => else { def lubBounds(bnds: List[TypeBounds]): TypeBounds = TypeBounds(glb(bnds map (_.lo), decr(depth)), lub(bnds map (_.hi), decr(depth))) - lubRefined.typeSymbol.newAbstractType(proto.pos, proto.name.toTypeName) + lubRefined.typeSymbol.newAbstractType(proto.name.toTypeName, proto.pos) .setInfoOwnerAdjusted(lubBounds(symtypes map (_.bounds))) } } |