aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/Names.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-03-01 10:41:32 +0100
committerMartin Odersky <odersky@gmail.com>2013-03-01 10:41:32 +0100
commit49e6eb07bf55cf9eabb260e7b7a8fef45923e8df (patch)
treedbb68d57b2820588b2f9e2b1189dc90d798549dd /src/dotty/tools/dotc/core/Names.scala
parent75507c832cf281b18e3dff0cefdee315d777bec9 (diff)
downloaddotty-49e6eb07bf55cf9eabb260e7b7a8fef45923e8df.tar.gz
dotty-49e6eb07bf55cf9eabb260e7b7a8fef45923e8df.tar.bz2
dotty-49e6eb07bf55cf9eabb260e7b7a8fef45923e8df.zip
Bug fixes and cleanups for names.
Diffstat (limited to 'src/dotty/tools/dotc/core/Names.scala')
-rw-r--r--src/dotty/tools/dotc/core/Names.scala31
1 files changed, 25 insertions, 6 deletions
diff --git a/src/dotty/tools/dotc/core/Names.scala b/src/dotty/tools/dotc/core/Names.scala
index c046fd74b..3b9a78dc5 100644
--- a/src/dotty/tools/dotc/core/Names.scala
+++ b/src/dotty/tools/dotc/core/Names.scala
@@ -50,6 +50,9 @@ object Names {
/** Is this name a term name? */
def isTermName: Boolean
+ /** Is this name a local name? */
+ def isLocalName: Boolean = this.isInstanceOf[LocalName]
+
/** This name converted to a type name */
def toTypeName: TypeName
@@ -70,8 +73,22 @@ object Names {
*/
def fromChars(cs: Array[Char], offset: Int, len: Int): ThisName
+ /** Create new name of same kind as this name and with same
+ * characters as given `name`.
+ */
+ def fromName(name: Name): ThisName = fromChars(chrs, name.start, name.length)
+
override def toString = new String(chrs, start, length)
+ /** Show name with namespace suffix: /L for local names,
+ * /V for other term names, /T for type names
+ */
+ def showDetailed: String = toString + {
+ (if (isLocalName) "/L"
+ else if (isTypeName) "/T"
+ else "/V")
+ }
+
/** Write to UTF8 representation of this name to given character array.
* Start copying to index `to`. Return index of next free byte in array.
* Array must have enough remaining space for all bytes
@@ -178,7 +195,8 @@ object Names {
override def hashCode: Int = -start
- override protected[this] def newBuilder: Builder[Char, Name] = typeNameBuilder
+ override protected[this] def newBuilder: Builder[Char, Name] =
+ termNameBuilder.mapResult(_.toTypeName)
def fromChars(cs: Array[Char], offset: Int, len: Int): TypeName = typeName(cs, offset, len)
}
@@ -212,6 +230,10 @@ object Names {
class LocalName(start: Int, length: Int, _next: TermName) extends TermName(start, length, _next) {
override def hashCode: Int = start + 1
def toGlobalName: TermName = next
+ override protected[this] def newBuilder: Builder[Char, Name] =
+ termNameBuilder.mapResult(_.toLocalName)
+ override def fromChars(cs: Array[Char], offset: Int, len: Int): TermName =
+ termName(cs, offset, len).toLocalName
}
// Nametable
@@ -330,7 +352,7 @@ object Names {
def typeName(bs: Array[Byte], offset: Int, len: Int): TypeName =
termName(bs, offset, len).toTypeName
- /** Create a term name from a string, wihtout encoding operators */
+ /** Create a term name from a string, without encoding operators */
def termName(s: String): TermName = termName(s.toCharArray, 0, s.length)
/** Create a term name from a string, encode if necessary*/
@@ -350,12 +372,9 @@ object Names {
/** The type name represented by the empoty string */
val EmptyTypeName = EmptyTermName.toTypeName
- val termNameBuilder: Builder[Char, TermName] =
+ def termNameBuilder: Builder[Char, TermName] =
StringBuilder.newBuilder.mapResult(termName)
- val typeNameBuilder: Builder[Char, TypeName] =
- StringBuilder.newBuilder.mapResult(typeName)
-
implicit val nameCanBuildFrom: CanBuildFrom[Name, Char, Name] = new CanBuildFrom[Name, Char, Name] {
def apply(from: Name): Builder[Char, Name] =
StringBuilder.newBuilder.mapResult(s => from.fromChars(s.toCharArray, 0, s.length))