Skip to content

Commit bf6ce00

Browse files
committed
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.)
1 parent 44d783a commit bf6ce00

29 files changed

+189
-230
lines changed

src/compiler/scala/reflect/internal/AnnotationInfos.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,8 @@ trait AnnotationInfos extends api.AnnotationInfos { self: SymbolTable =>
230230
def refsSymbol(sym: Symbol) = hasArgWhich(_.symbol == sym)
231231

232232
/** Change all ident's with Symbol "from" to instead use symbol "to" */
233-
def substIdentSyms(from: Symbol, to: Symbol) = {
234-
val subs = new TreeSymSubstituter(List(from), List(to))
235-
AnnotationInfo(atp, args.map(subs(_)), assocs).setPos(pos)
236-
}
233+
def substIdentSyms(from: Symbol, to: Symbol) =
234+
AnnotationInfo(atp, args map (_ substTreeSyms (from -> to)), assocs) setPos pos
237235

238236
def stringArg(index: Int) = constantAtIndex(index) map (_.stringValue)
239237
def intArg(index: Int) = constantAtIndex(index) map (_.intValue)

src/compiler/scala/reflect/internal/Symbols.scala

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -212,17 +212,6 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
212212
setInfo OverloadedType(pre, alternatives)
213213
)
214214

215-
/** for explicit outer phase */
216-
final def newOuterAccessor(pos: Position) = {
217-
val accFlags = METHOD | STABLE | SYNTHETIC | (
218-
if (isTrait) DEFERRED else 0
219-
)
220-
val sym = newMethodSymbol(nme.OUTER, pos, accFlags)
221-
sym.expandName(this)
222-
sym.referenced = this
223-
sym
224-
}
225-
226215
final def newErrorValue(name: TermName) =
227216
newTermSymbol(name, pos, SYNTHETIC | IS_ERROR) setInfo ErrorType
228217

@@ -285,6 +274,14 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
285274

286275
final def newClass(name: TypeName, pos: Position = NoPosition, newFlags: Long = 0L) =
287276
newClassSymbol(name, pos, newFlags)
277+
278+
/** A new class with its info set to a ClassInfoType with given scope and parents. */
279+
def newClassWithInfo(name: TypeName, parents: List[Type], scope: Scope, pos: Position = NoPosition, newFlags: Long = 0L) = {
280+
val clazz = newClass(name, pos, newFlags)
281+
clazz setInfo ClassInfoType(parents, scope, clazz)
282+
}
283+
final def newErrorClass(name: TypeName) =
284+
newClassWithInfo(name, Nil, new ErrorScope(this), pos, SYNTHETIC | IS_ERROR)
288285

289286
final def newModuleClass(name: TypeName, pos: Position = NoPosition) =
290287
newModuleClassSymbol(name, pos)
@@ -312,11 +309,6 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
312309
setInfo MethodType(Nil, tpe)
313310
)
314311

315-
final def newErrorClass(name: TypeName) = {
316-
val clazz = newClassSymbol(name, pos, SYNTHETIC | IS_ERROR)
317-
clazz setInfo ClassInfoType(Nil, new ErrorScope(this), clazz)
318-
}
319-
320312
final def newErrorSymbol(name: Name): Symbol = name match {
321313
case x: TypeName => newErrorClass(x)
322314
case x: TermName => newErrorValue(x)
@@ -1196,7 +1188,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
11961188
oldsymbuf += sym
11971189
newsymbuf += (
11981190
if (sym.isClass)
1199-
tp.typeSymbol.newAbstractType(sym.pos, sym.name.toTypeName).setInfo(sym.existentialBound)
1191+
tp.typeSymbol.newAbstractType(sym.name.toTypeName, sym.pos).setInfo(sym.existentialBound)
12001192
else
12011193
sym.cloneSymbol(tp.typeSymbol))
12021194
}
@@ -1346,15 +1338,15 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
13461338
cloneSymbol(owner)
13471339

13481340
/** A clone of this symbol, but with given owner. */
1349-
final def cloneSymbol(owner: Symbol): Symbol = {
1350-
val newSym = cloneSymbolImpl(owner, this.rawflags)
1341+
final def cloneSymbol(owner: Symbol): Symbol = cloneSymbol(owner, this.rawflags)
1342+
final def cloneSymbol(owner: Symbol, newFlags: Long): Symbol = {
1343+
val newSym = cloneSymbolImpl(owner, newFlags)
13511344
( newSym
13521345
setPrivateWithin privateWithin
13531346
setInfo (info cloneInfo newSym)
13541347
setAnnotations this.annotations
13551348
)
13561349
}
1357-
13581350
/** Internal method to clone a symbol's implementation with the given flags and no info. */
13591351
def cloneSymbolImpl(owner: Symbol, newFlags: Long): Symbol
13601352
def cloneSymbolImpl(owner: Symbol): Symbol = cloneSymbolImpl(owner, 0L)

src/compiler/scala/reflect/internal/Trees.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,12 @@ trait Trees extends api.Trees { self: SymbolTable =>
121121
new ChangeOwnerTraverser(oldOwner, newOwner) apply t
122122
}
123123
}
124-
124+
125+
def substTreeSyms(pairs: (Symbol, Symbol)*): Tree = {
126+
val list = pairs.toList
127+
val subst = new TreeSymSubstituter(list map (_._1), list map (_._2))
128+
subst(tree)
129+
}
125130
def shallowDuplicate: Tree = new ShallowDuplicator(tree) transform tree
126131
def shortClass: String = tree.getClass.getName split "[.$]" last
127132
/** When you want to know a little more than the class, but a lot

src/compiler/scala/reflect/internal/Types.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3726,7 +3726,7 @@ trait Types extends api.Types { self: SymbolTable =>
37263726

37273727
def typeParamsToExistentials(clazz: Symbol, tparams: List[Symbol]): List[Symbol] = {
37283728
val eparams = mapWithIndex(tparams)((tparam, i) =>
3729-
clazz.newExistential(clazz.pos, newTypeName("?"+i)) setInfo tparam.info.bounds)
3729+
clazz.newExistential(newTypeName("?"+i), clazz.pos) setInfo tparam.info.bounds)
37303730

37313731
eparams map (_ substInfo (tparams, eparams))
37323732
}
@@ -3848,10 +3848,10 @@ trait Types extends api.Types { self: SymbolTable =>
38483848
if (tree.symbol isNonBottomSubClass clazz) &&
38493849
(pre.widen.typeSymbol isNonBottomSubClass tree.symbol) =>
38503850
if (pre.isStable) { // XXX why is this in this method? pull it out and guard the call `annotationArgRewriter.transform(tree)`?
3851-
val termSym =
3852-
pre.typeSymbol.owner.newValue(
3853-
pre.typeSymbol.pos,
3854-
pre.typeSymbol.name.toTermName).setInfo(pre) // what symbol should really be used?
3851+
val termSym = (
3852+
pre.typeSymbol.owner.newValue(pre.typeSymbol.name.toTermName, pre.typeSymbol.pos) // what symbol should really be used?
3853+
setInfo pre
3854+
)
38553855
gen.mkAttributedQualifier(pre, termSym)
38563856
} else
38573857
giveup()
@@ -4205,7 +4205,7 @@ trait Types extends api.Types { self: SymbolTable =>
42054205
val symowner = oldSym.owner
42064206
val bound = singletonBounds(actualsIndexed(actualIdx))
42074207

4208-
val sym = symowner.newExistential(oldSym.pos, newTypeName(oldSym.name + ".type"))
4208+
val sym = symowner.newExistential(newTypeName(oldSym.name + ".type"), oldSym.pos)
42094209
sym.setInfo(bound)
42104210
sym.setFlag(oldSym.flags)
42114211

@@ -5892,7 +5892,7 @@ trait Types extends api.Types { self: SymbolTable =>
58925892
else {
58935893
def lubBounds(bnds: List[TypeBounds]): TypeBounds =
58945894
TypeBounds(glb(bnds map (_.lo), decr(depth)), lub(bnds map (_.hi), decr(depth)))
5895-
lubRefined.typeSymbol.newAbstractType(proto.pos, proto.name.toTypeName)
5895+
lubRefined.typeSymbol.newAbstractType(proto.name.toTypeName, proto.pos)
58965896
.setInfoOwnerAdjusted(lubBounds(symtypes map (_.bounds)))
58975897
}
58985898
}

src/compiler/scala/reflect/runtime/JavaToScala.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ trait JavaToScala extends ConversionUtil { self: SymbolTable =>
406406
val tparams = new ListBuffer[Symbol]
407407
def targToScala(arg: jType): Type = arg match {
408408
case jwild: WildcardType =>
409-
val tparam = owner.newExistential(NoPosition, newTypeName("T$" + tparams.length))
409+
val tparam = owner.newExistential(newTypeName("T$" + tparams.length))
410410
.setInfo(TypeBounds(
411411
lub(jwild.getLowerBounds.toList map typeToScala),
412412
glb(jwild.getUpperBounds.toList map typeToScala map objToAny)))
@@ -467,9 +467,11 @@ trait JavaToScala extends ConversionUtil { self: SymbolTable =>
467467
* @return A Scala value symbol that wraps all reflection info of `jfield`
468468
*/
469469
private def jfieldAsScala(jfield: jField): Symbol = fieldCache.toScala(jfield) {
470-
val field = sOwner(jfield).newValue(NoPosition, newTermName(jfield.getName))
471-
.setFlag(toScalaFieldFlags(jfield.getModifiers) | JAVA)
472-
.setInfo(typeToScala(jfield.getGenericType))
470+
val field = (
471+
sOwner(jfield)
472+
newValue(newTermName(jfield.getName), NoPosition, toScalaFieldFlags(jfield.getModifiers))
473+
setInfo typeToScala(jfield.getGenericType)
474+
)
473475
fieldCache enter (jfield, field)
474476
copyAnnotations(field, jfield)
475477
field
@@ -487,8 +489,7 @@ trait JavaToScala extends ConversionUtil { self: SymbolTable =>
487489
*/
488490
private def jmethodAsScala(jmeth: jMethod): Symbol = methodCache.toScala(jmeth) {
489491
val clazz = sOwner(jmeth)
490-
val meth = clazz.newMethod(NoPosition, newTermName(jmeth.getName))
491-
.setFlag(toScalaMethodFlags(jmeth.getModifiers) | JAVA)
492+
val meth = clazz.newMethod(newTermName(jmeth.getName), NoPosition, toScalaMethodFlags(jmeth.getModifiers))
492493
methodCache enter (jmeth, meth)
493494
val tparams = jmeth.getTypeParameters.toList map createTypeParameter
494495
val paramtpes = jmeth.getGenericParameterTypes.toList map typeToScala
@@ -510,8 +511,7 @@ trait JavaToScala extends ConversionUtil { self: SymbolTable =>
510511
private def jconstrAsScala(jconstr: jConstructor[_]): Symbol = {
511512
// [Martin] Note: I know there's a lot of duplication wrt jmethodAsScala, but don't think it's worth it to factor this out.
512513
val clazz = sOwner(jconstr)
513-
val constr = clazz.newMethod(NoPosition, nme.CONSTRUCTOR)
514-
.setFlag(toScalaMethodFlags(jconstr.getModifiers) | JAVA)
514+
val constr = clazz.newConstructor(NoPosition, toScalaMethodFlags(jconstr.getModifiers))
515515
constructorCache enter (jconstr, constr)
516516
val tparams = jconstr.getTypeParameters.toList map createTypeParameter
517517
val paramtpes = jconstr.getGenericParameterTypes.toList map typeToScala

src/compiler/scala/reflect/runtime/ToolBoxes.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,12 @@ trait ToolBoxes extends { self: Universe =>
4141
private def isFree(t: Tree) = t.isInstanceOf[Ident] && t.symbol.isInstanceOf[FreeVar]
4242

4343
def typedTopLevelExpr(tree: Tree, pt: Type): Tree = {
44-
val ownerClass = EmptyPackageClass.newClass(newTypeName("<expression-owner>"))
45-
ownerClass.setInfo(new ClassInfoType(List(ObjectClass.tpe), newScope, ownerClass))
46-
val owner = ownerClass.newLocalDummy(tree.pos)
44+
// !!! Why is this is in the empty package? If it's only to make
45+
// it inaccessible then please put it somewhere designed for that
46+
// rather than polluting the empty package with synthetics.
47+
val ownerClass = EmptyPackageClass.newClassWithInfo(newTypeName("<expression-owner>"), List(ObjectClass.tpe), newScope)
48+
val owner = ownerClass.newLocalDummy(tree.pos)
49+
4750
typer.atOwner(tree, owner).typed(tree, analyzer.EXPRmode, pt)
4851
}
4952

src/compiler/scala/tools/nsc/ast/TreeGen.scala

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,7 @@ abstract class TreeGen extends reflect.internal.TreeGen {
218218
*/
219219
private def mkPackedValDef(expr: Tree, owner: Symbol, name: Name): (ValDef, () => Ident) = {
220220
val packedType = typer.packedType(expr, owner)
221-
val sym = (
222-
owner.newValue(expr.pos.makeTransparent, name)
223-
setFlag SYNTHETIC
224-
setInfo packedType
225-
)
221+
val sym = owner.newValue(name, expr.pos.makeTransparent, SYNTHETIC) setInfo packedType
226222

227223
(ValDef(sym, expr), () => Ident(sym) setPos sym.pos.focus setType expr.tpe)
228224
}

src/compiler/scala/tools/nsc/backend/jvm/GenAndroid.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ trait GenAndroid {
3434

3535
def addCreatorCode(codegen: BytecodeGenerator, block: BasicBlock) {
3636
import codegen._
37-
val fieldSymbol = clasz.symbol.newValue(NoPosition, newTermName(fieldName))
38-
.setFlag(Flags.STATIC | Flags.FINAL)
39-
.setInfo(AndroidCreatorClass.tpe)
37+
val fieldSymbol = (
38+
clasz.symbol.newValue(newTermName(fieldName), NoPosition, Flags.STATIC | Flags.FINAL)
39+
setInfo AndroidCreatorClass.tpe
40+
)
4041
val methodSymbol = definitions.getMember(clasz.symbol.companionModule, fieldName)
4142
clasz addField new IField(fieldSymbol)
4243
block emit CALL_METHOD(methodSymbol, Static(false))

src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -966,9 +966,7 @@ abstract class GenJVM extends SubComponent with GenJVMUtil with GenAndroid with
966966
serialVUID foreach { value =>
967967
import Flags._, definitions._
968968
val fieldName = "serialVersionUID"
969-
val fieldSymbol = clasz.symbol.newValue(NoPosition, newTermName(fieldName))
970-
.setFlag(STATIC | FINAL)
971-
.setInfo(longType)
969+
val fieldSymbol = clasz.symbol.newValue(newTermName(fieldName), NoPosition, STATIC | FINAL) setInfo longType
972970
clasz addField new IField(fieldSymbol)
973971
lastBlock emit CONSTANT(Constant(value))
974972
lastBlock emit STORE_FIELD(fieldSymbol, true)

src/compiler/scala/tools/nsc/backend/opt/InlineExceptionHandlers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ abstract class InlineExceptionHandlers extends SubComponent {
203203
// Here we could create a single local for all exceptions of a certain type. TODO: try that.
204204
val localName = currentClass.cunit.freshTermName("exception$")
205205
val localType = exceptionType
206-
val localSymbol = bblock.method.symbol.newValue(NoPosition, localName).setInfo(localType.toType)
206+
val localSymbol = bblock.method.symbol.newValue(localName).setInfo(localType.toType)
207207
val local = new Local(localSymbol, localType, false)
208208

209209
bblock.method.addLocal(local)

0 commit comments

Comments
 (0)