summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-10-15 05:38:20 +0000
committerPaul Phillips <paulp@improving.org>2010-10-15 05:38:20 +0000
commitc5c38fc6420ce5a22448a2eeb3b45e1644358575 (patch)
treed6a7ed0994c407520e932e1fe3fe0aefdccc72ce /src
parent185700607dc2fd12cf47a61f583bdbafd726558b (diff)
downloadscala-c5c38fc6420ce5a22448a2eeb3b45e1644358575.tar.gz
scala-c5c38fc6420ce5a22448a2eeb3b45e1644358575.tar.bz2
scala-c5c38fc6420ce5a22448a2eeb3b45e1644358575.zip
There was a fascinating tangle of name creation...
There was a fascinating tangle of name creation functions passing around positions only to reach the end of the line and discard the position since names don't have positions. I deleted all of it. The winner for most creative use of parameters was the freshName function in etaExpand, with this signature: def freshName(pos: util.Position, n: Int) And an implementation referencing neither pos nor n. "In a world beset by attrition on all sides... a people defeated by entropy... one man will show them the power of deletion." No review.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/CompilationUnits.scala2
-rw-r--r--src/compiler/scala/tools/nsc/ast/Trees.scala2
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/Parsers.scala20
-rw-r--r--src/compiler/scala/tools/nsc/backend/opt/ClosureElimination.scala11
-rw-r--r--src/compiler/scala/tools/nsc/javac/JavaParsers.scala4
-rw-r--r--src/compiler/scala/tools/nsc/matching/Matrix.scala6
-rw-r--r--src/compiler/scala/tools/nsc/matching/ParallelMatching.scala2
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Symbols.scala1
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Types.scala2
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala19
-rw-r--r--src/compiler/scala/tools/nsc/util/FreshNameCreator.scala23
11 files changed, 26 insertions, 66 deletions
diff --git a/src/compiler/scala/tools/nsc/CompilationUnits.scala b/src/compiler/scala/tools/nsc/CompilationUnits.scala
index de48ff9931..564e4f2705 100644
--- a/src/compiler/scala/tools/nsc/CompilationUnits.scala
+++ b/src/compiler/scala/tools/nsc/CompilationUnits.scala
@@ -16,7 +16,7 @@ trait CompilationUnits { self: Global =>
class CompilationUnit(val source: SourceFile) extends CompilationUnitTrait {
/** the fresh name creator */
- var fresh : FreshNameCreator = new FreshNameCreator.Default
+ var fresh: FreshNameCreator = new FreshNameCreator.Default
/** the content of the compilation unit in tree form */
var body: Tree = EmptyTree
diff --git a/src/compiler/scala/tools/nsc/ast/Trees.scala b/src/compiler/scala/tools/nsc/ast/Trees.scala
index 4fcfde3beb..17a932575b 100644
--- a/src/compiler/scala/tools/nsc/ast/Trees.scala
+++ b/src/compiler/scala/tools/nsc/ast/Trees.scala
@@ -9,7 +9,7 @@ package ast
import scala.collection.mutable.ListBuffer
import scala.tools.nsc.symtab.SymbolTable
import scala.tools.nsc.symtab.Flags._
-import scala.tools.nsc.util.{FreshNameCreator, HashSet, SourceFile}
+import scala.tools.nsc.util.{ FreshNameCreator, HashSet, SourceFile }
trait Trees extends reflect.generic.Trees { self: SymbolTable =>
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
index 6f41b3ac47..997573f7f5 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
@@ -73,12 +73,10 @@ self =>
val in = new UnitScanner(unit, patches)
in.init()
- def freshName(pos: Position, prefix: String): Name =
- unit.fresh.newName(pos, prefix)
+ def freshName(prefix: String): Name = unit.fresh.newName(prefix)
def o2p(offset: Int): Position = new OffsetPosition(unit.source,offset)
def r2p(start: Int, mid: Int, end: Int): Position = rangePos(unit.source, start, mid, end)
-
def warning(offset: Int, msg: String) { unit.warning(o2p(offset), msg) }
def deprecationWarning(offset: Int,
@@ -150,18 +148,12 @@ self =>
abstract class Parser {
val in: Scanner
- //val unit : CompilationUnit
- //import in.ScanPosition
- def freshName(pos: Position, prefix: String): Name
- def freshName(prefix: String): Name = freshName(NoPosition, prefix) // todo get rid of position
+ def freshName(prefix: String): Name
def o2p(offset: Int): Position
def r2p(start: Int, mid: Int, end: Int): Position
- //private implicit def p2i(pos: Position) = pos.offset.get
/** whether a non-continuable syntax error has been seen */
- //private var syntaxErrorSeen = false
-
private var lastErrorOffset : Int = -1
object treeBuilder extends TreeBuilder {
@@ -1002,7 +994,7 @@ self =>
/** WildcardType ::= `_' TypeBounds
*/
def wildcardType(start: Int) = {
- val pname = freshName(o2p(start), "_$").toTypeName
+ val pname = freshName("_$").toTypeName
val t = atPos(start) { Ident(pname) }
val bounds = typeBounds()
val param = atPos(t.pos union bounds.pos) { makeSyntheticTypeParam(pname, bounds) }
@@ -1141,7 +1133,7 @@ self =>
case WHILE =>
val start = in.offset
atPos(in.skipToken()) {
- val lname: Name = freshName(o2p(start), nme.WHILE_PREFIX)
+ val lname: Name = freshName(nme.WHILE_PREFIX)
val cond = condExpr()
newLinesOpt()
val body = expr()
@@ -1150,7 +1142,7 @@ self =>
case DO =>
val start = in.offset
atPos(in.skipToken()) {
- val lname: Name = freshName(o2p(start), nme.DO_WHILE_PREFIX)
+ val lname: Name = freshName(nme.DO_WHILE_PREFIX)
val body = expr()
if (isStatSep) in.nextToken()
accept(WHILE)
@@ -1325,7 +1317,7 @@ self =>
path(true, false)
case USCORE =>
val start = in.offset
- val pname = freshName(o2p(start), "x$")
+ val pname = freshName("x$")
in.nextToken()
val id = atPos(start) (Ident(pname))
val param = atPos(id.pos.focus){ makeSyntheticParam(pname) }
diff --git a/src/compiler/scala/tools/nsc/backend/opt/ClosureElimination.scala b/src/compiler/scala/tools/nsc/backend/opt/ClosureElimination.scala
index ba7e00901a..d5bb6e0f88 100644
--- a/src/compiler/scala/tools/nsc/backend/opt/ClosureElimination.scala
+++ b/src/compiler/scala/tools/nsc/backend/opt/ClosureElimination.scala
@@ -88,16 +88,6 @@ abstract class ClosureElimination extends SubComponent {
*
*/
class ClosureElim {
-
- /* fresh name counter */
- var count = 0
-
- def freshName(s: String) = {
- val ret = s + this.count
- this.count += 1
- ret
- }
-
def analyzeClass(cls: IClass): Unit = if (settings.Xcloselim.value) {
cls.methods.foreach { m =>
analyzeMethod(m)
@@ -107,7 +97,6 @@ abstract class ClosureElimination extends SubComponent {
val cpp = new copyPropagation.CopyAnalysis
-
import copyPropagation._
/* Some embryonic copy propagation. */
diff --git a/src/compiler/scala/tools/nsc/javac/JavaParsers.scala b/src/compiler/scala/tools/nsc/javac/JavaParsers.scala
index 3c9cdbf878..8c0e5585be 100644
--- a/src/compiler/scala/tools/nsc/javac/JavaParsers.scala
+++ b/src/compiler/scala/tools/nsc/javac/JavaParsers.scala
@@ -22,7 +22,7 @@ trait JavaParsers extends JavaScanners {
class JavaUnitParser(val unit: global.CompilationUnit) extends JavaParser {
val in = new JavaUnitScanner(unit)
- def freshName(pos : Position, prefix : String) = unit.fresh.newName(pos, prefix)
+ def freshName(prefix : String) = unit.fresh.newName(prefix)
implicit def i2p(offset : Int) : Position = new OffsetPosition(unit.source, offset)
def warning(pos : Int, msg : String) : Unit = unit.warning(pos, msg)
def syntaxError(pos: Int, msg: String) : Unit = unit.error(pos, msg)
@@ -32,7 +32,7 @@ trait JavaParsers extends JavaScanners {
val in: JavaScanner
protected def posToReport: Int = in.currentPos
- protected def freshName(pos : Position, prefix : String): Name
+ protected def freshName(prefix : String): Name
protected implicit def i2p(offset : Int) : Position
private implicit def p2i(pos : Position): Int = if (pos.isDefined) pos.point else -1
diff --git a/src/compiler/scala/tools/nsc/matching/Matrix.scala b/src/compiler/scala/tools/nsc/matching/Matrix.scala
index fa3e7371a7..f7f7b2cc41 100644
--- a/src/compiler/scala/tools/nsc/matching/Matrix.scala
+++ b/src/compiler/scala/tools/nsc/matching/Matrix.scala
@@ -194,7 +194,7 @@ trait Matrix extends MatrixAdditions {
override def toString() = "%s: %s = %s".format(lhs, lhs.info, rhs)
}
- def newName(pos: Position, s: String) = cunit.fresh.newName(pos, s)
+ def newName(s: String) = cunit.fresh.newName(s)
/** Sets the rhs to EmptyTree, which makes the valDef ignored in Scrutinee.
*/
@@ -211,7 +211,7 @@ trait Matrix extends MatrixAdditions {
label: String = "temp"): PatternVar =
{
val tpe = ifNull(_tpe, root.tpe)
- val name = newName(root.pos, label)
+ val name = newName(label)
val sym = newVar(root.pos, tpe, flags(checked), name)
tracing("copy", new PatternVar(sym, root, checked))
@@ -233,7 +233,7 @@ trait Matrix extends MatrixAdditions {
flags: List[Long] = Nil,
name: Name = null): Symbol =
{
- val n: Name = if (name == null) newName(pos, "temp") else name
+ val n: Name = if (name == null) newName("temp") else name
// careful: pos has special meaning
owner.newVariable(pos, n) setInfo tpe setFlag (SYNTHETIC.toLong /: flags)(_|_)
}
diff --git a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala
index 61a8b81820..b82298f2de 100644
--- a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala
+++ b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala
@@ -544,7 +544,7 @@ trait ParallelMatching extends ast.TreeDSL
}
lazy val label =
- owner.newLabel(scrut.pos, newName(scrut.pos, "failCont%")) setInfo MethodType(Nil, labelBody.tpe)
+ owner.newLabel(scrut.pos, newName("failCont%")) setInfo MethodType(Nil, labelBody.tpe)
lazy val cond =
handleOuter(rhs MEMBER_== scrut.id )
diff --git a/src/compiler/scala/tools/nsc/symtab/Symbols.scala b/src/compiler/scala/tools/nsc/symtab/Symbols.scala
index 083b6667bf..567754dc2e 100644
--- a/src/compiler/scala/tools/nsc/symtab/Symbols.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Symbols.scala
@@ -217,6 +217,7 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable =>
sym setFlag (STABLE | SYNTHETIC)
if (isTrait) sym setFlag DEFERRED
sym.expandName(this)
+ // todo: stop depending on compiler bug (ticket #3871) to set referenced.
sym.referenced = this
sym
}
diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala
index d4063746a2..abe9569346 100644
--- a/src/compiler/scala/tools/nsc/symtab/Types.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Types.scala
@@ -5194,7 +5194,7 @@ A type's typeSymbol should never be inspected directly.
/** The greatest lower bound wrt <:< of a list of types */
private def glb(ts: List[Type], depth: Int): Type = {
- def glb0(ts0: List[Type]): Type = elimSuper(ts0 map (_.deconst)) match {// todo: deconst needed?
+ def glb0(ts0: List[Type]): Type = elimSuper(ts0) match {
case List() => AnyClass.tpe
case List(t) => t
case ts @ PolyType(tparams, _) :: _ =>
diff --git a/src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala b/src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala
index 7cfc4733d3..c24d5c0505 100644
--- a/src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala
@@ -49,20 +49,11 @@ trait EtaExpansion { self: Analyzer =>
*/
def etaExpand(unit : CompilationUnit, tree: Tree): Tree = {
val tpe = tree.tpe
- val symbolHash = ""
var cnt = 0 // for NoPosition
- def freshName(pos : util.Position, n : Int) = {
+ def freshName() = {
cnt += 1
- newTermName(unit.fresh.newName(pos, "eta$" + (cnt - 1) + "$"))
- // Note - the comment below made more sense before I ripped inIDE out -
- // I leave it in to give context to the todo: at the bottom.
- // Martin to Sean: I removed the
- // else if (n == 0) branch and changed `n' in the line above to `(cnt - 1)'
- // this was necessary because otherwise curried eta-expansions would get the same
- // symbol. An example which fails test/files/run/Course-2002-02.scala
- // todo: review and get rid of the `n' argument (which is unused right now).
+ newTermName(unit.fresh.newName("eta$" + (cnt - 1) + "$"))
}
- // { cnt = cnt + 1; newTermName("eta$" + cnt) }
val defs = new ListBuffer[Tree]
/** Append to <code>defs</code> value definitions for all non-stable
@@ -75,7 +66,7 @@ trait EtaExpansion { self: Analyzer =>
def liftout(tree: Tree): Tree =
if (treeInfo.isPureExpr(tree)) tree
else {
- val vname: Name = freshName(tree.pos, 0)
+ val vname: Name = freshName()
// Problem with ticket #2351 here
defs += atPos(tree.pos) {
ValDef(Modifiers(SYNTHETIC), vname, TypeTree(), tree)
@@ -107,10 +98,6 @@ trait EtaExpansion { self: Analyzer =>
}
/** Eta-expand lifted tree.
- *
- * @param tree ...
- * @param tpe ...
- * @return ...
*/
def expand(tree: Tree, tpe: Type): Tree = tpe match {
case mt @ MethodType(paramSyms, restpe) if !mt.isImplicit =>
diff --git a/src/compiler/scala/tools/nsc/util/FreshNameCreator.scala b/src/compiler/scala/tools/nsc/util/FreshNameCreator.scala
index 714e731891..cf6994da51 100644
--- a/src/compiler/scala/tools/nsc/util/FreshNameCreator.scala
+++ b/src/compiler/scala/tools/nsc/util/FreshNameCreator.scala
@@ -9,25 +9,20 @@ package util
import scala.collection.mutable.HashMap
trait FreshNameCreator {
-
- /** do not call before after type checking ends.
+ /** Do not call before after type checking ends.
+ * PP: I think that directive needs to lose a word somewhere.
*/
- @deprecated("use newName(Position, String) instead")
- def newName(prefix: String): String
-
- /** do not call before after type checking ends.
- */
- @deprecated("use newName(Position) instead")
def newName(): String
+ def newName(prefix: String): String
- def newName(pos: util.Position, prefix: String): String
- def newName(pos: util.Position): String
+ @deprecated("use newName(prefix)")
+ def newName(pos: util.Position, prefix: String): String = newName(prefix)
+ @deprecated("use newName()")
+ def newName(pos: util.Position): String = newName()
}
object FreshNameCreator {
-
class Default extends FreshNameCreator {
-
protected var counter = 0
protected val counters = new HashMap[String, Int]
@@ -42,13 +37,9 @@ object FreshNameCreator {
counters(safePrefix) = count
safePrefix + count
}
- def newName(pos: util.Position, prefix: String) = newName(prefix)
- def newName(pos: util.Position) = newName()
-
def newName(): String = {
counter += 1
"$" + counter + "$"
}
}
-
}