summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/transform/CleanUp.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-12-02 17:28:58 +0000
committerPaul Phillips <paulp@improving.org>2010-12-02 17:28:58 +0000
commit765f9aa2bfd16fc066fcfe6f068bc9ab54b863c2 (patch)
tree1b8d31bab45162415d6cc6372c7336fc62bbad2b /src/compiler/scala/tools/nsc/transform/CleanUp.scala
parenta69c1afd4ba602bd4ccc9f9aced9bfc0f6f3c5e7 (diff)
downloadscala-765f9aa2bfd16fc066fcfe6f068bc9ab54b863c2.tar.gz
scala-765f9aa2bfd16fc066fcfe6f068bc9ab54b863c2.tar.bz2
scala-765f9aa2bfd16fc066fcfe6f068bc9ab54b863c2.zip
It's a big one!
TermName and TypeName are exposed throughout the compiler based on what kind of name a given abstraction ought to have. (There remain places where one needs to create a name without knowing yet what it will be, and those will always be Names.) The nme object in the compiler now holds only term names. To reference a known type name, use tpnme: nme.List == ("List": TermName) tpnme.List == ("List": TypeName) The contents of nme and tpname are defined in traits, many of which are shared, so if a name should exist only as a Type and not a Term, it should be defined in CompilerTypeNames, but otherwise in CompilerTermNames or CompilerCommonNames. This is partially complete but I'm sure there are still many shared which should pick a side. Usage of .toTermName and .toTypeName is strongly discouraged. After the dust has settled, there will be very few places where it will make sense to hop between namespaces like that. There are some implicits to smooth everything out, most of which should be removable eventually. // these two are in no hurry to go anywhere String => TermName String => TypeName // but not String => Name: def view in the compiler is no longer implicit // these two are temporary, and can log when they kick off to help us flush // out remaining issues of "name migration" Name => TermName Name => TypeName There is more work to be done before we're properly protected from naming errors, but I will not allow another eight hour tragedy to befall lukas or anyone else! Review by rytz. (Formality.)
Diffstat (limited to 'src/compiler/scala/tools/nsc/transform/CleanUp.scala')
-rw-r--r--src/compiler/scala/tools/nsc/transform/CleanUp.scala18
1 files changed, 7 insertions, 11 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/CleanUp.scala b/src/compiler/scala/tools/nsc/transform/CleanUp.scala
index 943960c3f7..5955a48499 100644
--- a/src/compiler/scala/tools/nsc/transform/CleanUp.scala
+++ b/src/compiler/scala/tools/nsc/transform/CleanUp.scala
@@ -25,6 +25,7 @@ abstract class CleanUp extends Transform with ast.TreeDSL {
private val newStaticMembers = mutable.Buffer.empty[Tree]
private val newStaticInits = mutable.Buffer.empty[Tree]
private val symbolsStoredAsStatic = mutable.Map.empty[String, Symbol]
+ private def mkTerm(prefix: String): TermName = unit.freshTermName(prefix)
//private val classConstantMeth = new HashMap[String, Symbol]
//private val symbolStaticFields = new HashMap[String, (Symbol, Tree, Tree)]
@@ -91,10 +92,6 @@ abstract class CleanUp extends Transform with ast.TreeDSL {
* refinement, where the refinement defines a parameter based on a
* type variable. */
case ad@ApplyDynamic(qual0, params) =>
- def mkName(s: String = "") =
- if (s == "") unit.fresh.newName()
- else unit.fresh.newName(s)
- def mkTerm(s: String = "") = newTermName(mkName(s))
val typedPos = typedWithPos(ad.pos) _
assert(ad.symbol.isPublic)
@@ -103,7 +100,7 @@ abstract class CleanUp extends Transform with ast.TreeDSL {
/* ### CREATING THE METHOD CACHE ### */
def addStaticVariableToClass(forName: String, forType: Type, forInit: Tree, isFinal: Boolean): Symbol = {
- val varSym = currentClass.newVariable(ad.pos, mkName(forName))
+ val varSym = currentClass.newVariable(ad.pos, mkTerm(forName))
.setFlag(PRIVATE | STATIC | SYNTHETIC)
.setInfo(forType)
if (isFinal) varSym setFlag FINAL else varSym addAnnotation AnnotationInfo(VolatileAttr.tpe, Nil, Nil)
@@ -120,7 +117,7 @@ abstract class CleanUp extends Transform with ast.TreeDSL {
def addStaticMethodToClass(forName: String, forArgsTypes: List[Type], forResultType: Type)
(forBody: Pair[Symbol, List[Symbol]] => Tree): Symbol = {
- val methSym = currentClass.newMethod(ad.pos, mkName(forName))
+ val methSym = currentClass.newMethod(ad.pos, mkTerm(forName))
.setFlag(STATIC | SYNTHETIC)
methSym.setInfo(MethodType(methSym.newSyntheticValueParams(forArgsTypes), forResultType))
@@ -387,7 +384,7 @@ abstract class CleanUp extends Transform with ast.TreeDSL {
def invocation = (lookup DOT invokeName)(qual, invokeArgs) // .invoke(qual, ...)
// exception catching machinery
- val invokeExc = currentOwner.newValue(ad.pos, mkTerm()) setInfo InvocationTargetExceptionClass.tpe
+ val invokeExc = currentOwner.newValue(ad.pos, mkTerm("")) setInfo InvocationTargetExceptionClass.tpe
def catchVar = Bind(invokeExc, Typed(Ident(nme.WILDCARD), TypeTree(InvocationTargetExceptionClass.tpe)))
def catchBody = Throw(Apply(Select(Ident(invokeExc), nme.getCause), Nil))
@@ -431,7 +428,7 @@ abstract class CleanUp extends Transform with ast.TreeDSL {
if (settings.refinementMethodDispatch.value == "invoke-dynamic") {
/* val guardCallSite: Tree = {
val cachedClass = addStaticVariableToClass("cachedClass", definitions.ClassClass.tpe, EmptyTree)
- val tmpVar = currentOwner.newVariable(ad.pos, unit.fresh.newName(ad.pos, "x")).setInfo(definitions.AnyRefClass.tpe)
+ val tmpVar = currentOwner.newVariable(ad.pos, unit.freshTermName(ad.pos, "x")).setInfo(definitions.AnyRefClass.tpe)
atPos(ad.pos)(Block(List(
ValDef(tmpVar, transform(qual))),
If(Apply(Select(gen.mkAttributedRef(cachedClass), nme.EQ), List(getClass(Ident(tmpVar)))),
@@ -551,7 +548,7 @@ abstract class CleanUp extends Transform with ast.TreeDSL {
case theTry @ Try(block, catches, finalizer)
if theTry.tpe.typeSymbol != definitions.UnitClass && theTry.tpe.typeSymbol != definitions.NothingClass =>
val tpe = theTry.tpe.widen
- val tempVar = currentOwner.newVariable(theTry.pos, unit.fresh.newName(nme.EXCEPTION_RESULT_PREFIX)).setInfo(tpe)
+ val tempVar = currentOwner.newVariable(theTry.pos, mkTerm(nme.EXCEPTION_RESULT_PREFIX)).setInfo(tpe)
def assignBlock(rhs: Tree) = super.transform(BLOCK(Ident(tempVar) === transform(rhs)))
val newBlock = assignBlock(block)
@@ -612,11 +609,10 @@ abstract class CleanUp extends Transform with ast.TreeDSL {
*/
private def getSymbolStaticField(pos: Position, symname: String, rhs: Tree, tree: Tree): Symbol =
symbolsStoredAsStatic.getOrElseUpdate(symname, {
- val freshname = unit.fresh.newName("symbol$")
val theTyper = typer.atOwner(tree, currentClass)
// create a symbol for the static field
- val stfieldSym = currentClass.newVariable(pos, freshname)
+ val stfieldSym = currentClass.newVariable(pos, mkTerm("symbol$"))
.setFlag(PRIVATE | STATIC | SYNTHETIC | FINAL)
.setInfo(symbolType)
currentClass.info.decls enter stfieldSym