summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/javac
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/javac
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/javac')
-rw-r--r--src/compiler/scala/tools/nsc/javac/JavaParsers.scala44
-rw-r--r--src/compiler/scala/tools/nsc/javac/JavaScanners.scala4
2 files changed, 26 insertions, 22 deletions
diff --git a/src/compiler/scala/tools/nsc/javac/JavaParsers.scala b/src/compiler/scala/tools/nsc/javac/JavaParsers.scala
index 63c62d8d1e..d6cfdd24b1 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(prefix : String) = unit.fresh.newName(prefix)
+ def freshName(prefix : String) = unit.freshTermName(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)
@@ -106,10 +106,10 @@ trait JavaParsers extends JavaScanners {
def javaLangDot(name: Name): Tree =
Select(javaDot(nme.lang), name)
- def javaLangObject(): Tree = javaLangDot(nme.Object.toTypeName)
+ def javaLangObject(): Tree = javaLangDot(tpnme.Object)
def arrayOf(tpt: Tree) =
- AppliedTypeTree(scalaDot(nme.Array.toTypeName), List(tpt))
+ AppliedTypeTree(scalaDot(tpnme.Array), List(tpt))
def blankExpr = Ident(nme.WILDCARD)
@@ -192,14 +192,18 @@ trait JavaParsers extends JavaScanners {
}
def acceptClosingAngle() {
- if (in.token == GTGTGTEQ) in.token = GTGTEQ
- else if (in.token == GTGTGT) in.token = GTGT
- else if (in.token == GTGTEQ) in.token = GTEQ
- else if (in.token == GTGT) in.token = GT
- else if (in.token == GTEQ) in.token = ASSIGN
+ val closers: PartialFunction[Int, Int] = {
+ case GTGTGTEQ => GTGTEQ
+ case GTGTGT => GTGT
+ case GTGTEQ => GTEQ
+ case GTGT => GT
+ case GTEQ => ASSIGN
+ }
+ if (closers isDefinedAt in.token) in.token = closers(in.token)
else accept(GT)
}
+ def identForType(): TypeName = ident().toTypeName
def ident(): Name =
if (in.token == IDENTIFIER) {
val name = in.name
@@ -279,7 +283,7 @@ trait JavaParsers extends JavaScanners {
// turns out to be an instance ionner class instead of a static inner class.
def typeSelect(t: Tree, name: Name) = t match {
case Ident(_) | Select(_, _) => Select(t, name)
- case _ => SelectFromTypeTree(t, name)
+ case _ => SelectFromTypeTree(t, name.toTypeName)
}
while (in.token == DOT) {
in.nextToken
@@ -431,7 +435,7 @@ trait JavaParsers extends JavaScanners {
case _ =>
val privateWithin: Name =
if (isPackageAccess && !inInterface) thisPackageName
- else nme.EMPTY.toTypeName
+ else tpnme.EMPTY
return Modifiers(flags, privateWithin) withAnnotations annots
}
@@ -449,16 +453,16 @@ trait JavaParsers extends JavaScanners {
def typeParam(): TypeDef =
atPos(in.currentPos) {
- val name = ident().toTypeName
+ val name = identForType()
val hi =
if (in.token == EXTENDS) {
in.nextToken
bound()
} else {
- scalaDot(nme.Any.toTypeName)
+ scalaDot(tpnme.Any)
}
TypeDef(Modifiers(Flags.JAVA | Flags.DEFERRED | Flags.PARAM), name, List(),
- TypeBoundsTree(scalaDot(nme.Nothing.toTypeName), hi))
+ TypeBoundsTree(scalaDot(tpnme.Nothing), hi))
}
def bound(): Tree =
@@ -487,7 +491,7 @@ trait JavaParsers extends JavaScanners {
if (in.token == DOTDOTDOT) {
in.nextToken
t = atPos(t.pos) {
- AppliedTypeTree(scalaDot(nme.JAVA_REPEATED_PARAM_CLASS_NAME), List(t))
+ AppliedTypeTree(scalaDot(tpnme.JAVA_REPEATED_PARAM_CLASS_NAME), List(t))
}
}
varDecl(in.currentPos, Modifiers(Flags.JAVA | Flags.PARAM), t, ident())
@@ -548,7 +552,7 @@ trait JavaParsers extends JavaScanners {
if (parentToken == AT && in.token == DEFAULT) {
val annot =
atPos(pos) {
- New(Select(scalaDot(newTermName("runtime")), nme.AnnotationDefaultATTR.toTypeName), List(List()))
+ New(Select(scalaDot(newTermName("runtime")), tpnme.AnnotationDefaultATTR), List(List()))
}
mods1 = Modifiers(mods1.flags, mods1.privateWithin, annot :: mods1.annotations, mods1.positions)
skipTo(SEMI)
@@ -613,7 +617,7 @@ trait JavaParsers extends JavaScanners {
buf.toList
}
- def varDecl(pos: Position, mods: Modifiers, tpt: Tree, name: Name): ValDef = {
+ def varDecl(pos: Position, mods: Modifiers, tpt: Tree, name: TermName): ValDef = {
val tpt1 = optArrayBrackets(tpt)
if (in.token == ASSIGN && !mods.isParameter) skipTo(COMMA, SEMI)
val mods1 = if (mods.isFinal) mods &~ Flags.FINAL else mods | Flags.MUTABLE
@@ -714,7 +718,7 @@ trait JavaParsers extends JavaScanners {
def classDecl(mods: Modifiers): List[Tree] = {
accept(CLASS)
val pos = in.currentPos
- val name = ident().toTypeName
+ val name = identForType()
val tparams = typeParams()
val superclass =
if (in.token == EXTENDS) {
@@ -733,7 +737,7 @@ trait JavaParsers extends JavaScanners {
def interfaceDecl(mods: Modifiers): List[Tree] = {
accept(INTERFACE)
val pos = in.currentPos
- val name = ident().toTypeName
+ val name = identForType()
val tparams = typeParams()
val parents =
if (in.token == EXTENDS) {
@@ -795,7 +799,7 @@ trait JavaParsers extends JavaScanners {
accept(AT)
accept(INTERFACE)
val pos = in.currentPos
- val name = ident().toTypeName
+ val name = identForType()
val parents = List(scalaDot(newTypeName("Annotation")),
Select(javaLangDot(newTermName("annotation")), newTypeName("Annotation")),
scalaDot(newTypeName("ClassfileAnnotation")))
@@ -815,7 +819,7 @@ trait JavaParsers extends JavaScanners {
def enumDecl(mods: Modifiers): List[Tree] = {
accept(ENUM)
val pos = in.currentPos
- val name = ident().toTypeName
+ val name = identForType()
def enumType = Ident(name)
val interfaces = interfacesOpt()
accept(LBRACE)
diff --git a/src/compiler/scala/tools/nsc/javac/JavaScanners.scala b/src/compiler/scala/tools/nsc/javac/JavaScanners.scala
index fccb1746fe..fd69f15edc 100644
--- a/src/compiler/scala/tools/nsc/javac/JavaScanners.scala
+++ b/src/compiler/scala/tools/nsc/javac/JavaScanners.scala
@@ -37,7 +37,7 @@ trait JavaScanners {
var lastPos: Int = 0
/** the name of an identifier or token */
- var name: Name = null
+ var name: TermName = null
/** the base of a number */
var base: Int = 0
@@ -165,7 +165,7 @@ trait JavaScanners {
//Token representation -----------------------------------------------------
/** Convert name to token */
- def name2token(name: Name): Int =
+ def name2token(name: TermName): Int =
if (name.start <= maxKey) key(name.start) else IDENTIFIER
/** Returns the string representation of given token. */