diff options
author | Paul Phillips <paulp@improving.org> | 2010-12-02 17:28:58 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2010-12-02 17:28:58 +0000 |
commit | 765f9aa2bfd16fc066fcfe6f068bc9ab54b863c2 (patch) | |
tree | 1b8d31bab45162415d6cc6372c7336fc62bbad2b /src/compiler/scala/tools/nsc/ast/parser/SymbolicXMLBuilder.scala | |
parent | a69c1afd4ba602bd4ccc9f9aced9bfc0f6f3c5e7 (diff) | |
download | scala-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/ast/parser/SymbolicXMLBuilder.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/parser/SymbolicXMLBuilder.scala | 66 |
1 files changed, 39 insertions, 27 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/SymbolicXMLBuilder.scala b/src/compiler/scala/tools/nsc/ast/parser/SymbolicXMLBuilder.scala index f0d1c536c4..81bb5db286 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/SymbolicXMLBuilder.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/SymbolicXMLBuilder.scala @@ -22,43 +22,55 @@ import scala.tools.util.StringOps.splitWhere * @author Burak Emir * @version 1.0 */ -abstract class SymbolicXMLBuilder(p: Parsers#Parser, preserveWS: Boolean) -{ +abstract class SymbolicXMLBuilder(p: Parsers#Parser, preserveWS: Boolean) { val global: Global import global._ - def freshName(prefix: String): Name var isPattern: Boolean = _ - def _Comment = global.newTypeName("Comment") - def _Elem = global.newTypeName("Elem") - def _EntityRef = global.newTypeName("EntityRef") - def _Group = global.newTypeName("Group") - def _MetaData = global.newTypeName("MetaData") - def _NamespaceBinding = global.newTypeName("NamespaceBinding") - def _NodeBuffer = global.newTypeName("NodeBuffer") - def _PrefixedAttribute = global.newTypeName("PrefixedAttribute") - def _ProcInstr = global.newTypeName("ProcInstr") - def _Text = global.newTypeName("Text") - def _Unparsed = global.newTypeName("Unparsed") - def _UnprefixedAttribute = global.newTypeName("UnprefixedAttribute") - - def __Elem = global.newTermName("Elem") - def __Text = global.newTermName("Text") - def _Null = global.newTermName("Null") - def _plus = global.newTermName("$amp$plus") - def _xml = global.newTermName("xml") - - final def _buf = global.newTermName("$buf") - final def _md = global.newTermName("$md") - final def _scope = global.newTermName("$scope") - final def _tmpscope = global.newTermName("$tmpscope") + trait XMLTypeNames extends LibraryTypeNames { + val _Comment: NameType = "Comment" + val _Elem: NameType = "Elem" + val _EntityRef: NameType = "EntityRef" + val _Group: NameType = "Group" + val _MetaData: NameType = "MetaData" + val _NamespaceBinding: NameType = "NamespaceBinding" + val _NodeBuffer: NameType = "NodeBuffer" + val _PrefixedAttribute: NameType = "PrefixedAttribute" + val _ProcInstr: NameType = "ProcInstr" + val _Text: NameType = "Text" + val _Unparsed: NameType = "Unparsed" + val _UnprefixedAttribute: NameType = "UnprefixedAttribute" + } + + trait XMLTermNames extends LibraryTermNames { + val _Null: NameType = "Null" + val __Elem: NameType = "Elem" + val __Text: NameType = "Text" + val _buf: NameType = "$buf" + val _md: NameType = "$md" + val _plus: NameType = "$amp$plus" + val _scope: NameType = "$scope" + val _tmpscope: NameType = "$tmpscope" + val _xml: NameType = "xml" + } + + private object xmltypes extends XMLTypeNames { + type NameType = TypeName + implicit def createNameType(name: String): TypeName = newTypeName(name) + } + private object xmlterms extends XMLTermNames { + type NameType = TermName + implicit def createNameType(name: String): TermName = newTermName(name) + } + import xmltypes._ + import xmlterms._ // convenience methods private def LL[A](x: A*): List[List[A]] = List(List(x:_*)) private def const(x: Any) = Literal(Constant(x)) private def wild = Ident(nme.WILDCARD) - private def wildStar = Ident(nme.WILDCARD_STAR) + private def wildStar = Ident(tpnme.WILDCARD_STAR) private def _scala(name: Name) = Select(Select(Ident(nme.ROOTPKG), nme.scala_), name) private def _scala_xml(name: Name) = Select(_scala(_xml), name) |