aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2017-03-31 19:01:10 +0200
committerMartin Odersky <odersky@gmail.com>2017-04-11 09:33:12 +0200
commita574ba6b70fc8a8dadf4ec493fcb5dc19d1fa478 (patch)
tree6203155dd48e40d5a56a5fa458660c6ee903427e
parent4a54b2c24d6f6feb5864461697f5872df220ba52 (diff)
downloaddotty-a574ba6b70fc8a8dadf4ec493fcb5dc19d1fa478.tar.gz
dotty-a574ba6b70fc8a8dadf4ec493fcb5dc19d1fa478.tar.bz2
dotty-a574ba6b70fc8a8dadf4ec493fcb5dc19d1fa478.zip
Further simplification for Name
-rw-r--r--compiler/src/dotty/tools/dotc/core/Definitions.scala2
-rw-r--r--compiler/src/dotty/tools/dotc/core/NameOps.scala6
-rw-r--r--compiler/src/dotty/tools/dotc/core/Names.scala6
-rw-r--r--compiler/src/dotty/tools/dotc/core/StdNames.scala27
-rw-r--r--compiler/src/dotty/tools/dotc/core/SymDenotations.scala6
-rw-r--r--compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala2
-rw-r--r--compiler/test/dotty/tools/DottyTypeStealer.scala2
7 files changed, 17 insertions, 34 deletions
diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala
index a1858e934..d4d652d6b 100644
--- a/compiler/src/dotty/tools/dotc/core/Definitions.scala
+++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala
@@ -119,7 +119,7 @@ class Definitions {
enterTypeParam(cls, name ++ "$T" ++ i.toString, Contravariant, decls)
val resParam = enterTypeParam(cls, name ++ "$R", Covariant, decls)
val (methodType, parentTraits) =
- if (name.startsWith(str.ImplicitFunction)) {
+ if (name.firstPart.startsWith(str.ImplicitFunction)) {
val superTrait =
FunctionType(arity).appliedTo(argParams.map(_.typeRef) ::: resParam.typeRef :: Nil)
(ImplicitMethodType, ctx.normalizeToClassRefs(superTrait :: Nil, cls, decls))
diff --git a/compiler/src/dotty/tools/dotc/core/NameOps.scala b/compiler/src/dotty/tools/dotc/core/NameOps.scala
index 5a71c2bd2..ac4b296bb 100644
--- a/compiler/src/dotty/tools/dotc/core/NameOps.scala
+++ b/compiler/src/dotty/tools/dotc/core/NameOps.scala
@@ -63,9 +63,9 @@ object NameOps {
def isConstructorName = name == CONSTRUCTOR || name == TRAIT_CONSTRUCTOR
def isStaticConstructorName = name == STATIC_CONSTRUCTOR
- def isLocalDummyName = name startsWith LOCALDUMMY_PREFIX
+ def isLocalDummyName = name startsWith str.LOCALDUMMY_PREFIX
def isReplWrapperName = name.toString contains str.INTERPRETER_IMPORT_WRAPPER
- def isSetterName = name endsWith SETTER_SUFFIX
+ def isSetterName = name endsWith str.SETTER_SUFFIX
def isScala2LocalSuffix = testSimple(_.endsWith(" "))
def isSelectorName = testSimple(n => n.startsWith("_") && n.drop(1).forall(_.isDigit))
@@ -275,7 +275,7 @@ object NameOps {
def getterName: TermName =
name.exclude(FieldName).mapLast(n =>
- if (n.endsWith(SETTER_SUFFIX)) n.take(n.length - str.SETTER_SUFFIX.length).asSimpleName
+ if (n.endsWith(str.SETTER_SUFFIX)) n.take(n.length - str.SETTER_SUFFIX.length).asSimpleName
else n)
def fieldName: TermName =
diff --git a/compiler/src/dotty/tools/dotc/core/Names.scala b/compiler/src/dotty/tools/dotc/core/Names.scala
index 56bdb1623..95cc2fef7 100644
--- a/compiler/src/dotty/tools/dotc/core/Names.scala
+++ b/compiler/src/dotty/tools/dotc/core/Names.scala
@@ -101,11 +101,7 @@ object Names {
def isEmpty: Boolean
def startsWith(str: String): Boolean = firstPart.startsWith(str)
- def startsWith(name: Name): Boolean = startsWith(name.toString)
def endsWith(str: String): Boolean = lastPart.endsWith(str)
- def endsWith(name: Name): Boolean = endsWith(name.toString)
- def lastIndexOfSlice(str: String): Int = lastPart.toString.lastIndexOfSlice(str)
- def lastIndexOfSlice(name: Name): Int = lastIndexOfSlice(name.toString)
override def hashCode = System.identityHashCode(this)
override def equals(that: Any) = this eq that.asInstanceOf[AnyRef]
@@ -240,6 +236,8 @@ object Names {
i
}
+ def lastIndexOfSlice(str: String): Int = toString.lastIndexOfSlice(str)
+
override def replace(from: Char, to: Char): SimpleTermName = {
val cs = new Array[Char](length)
Array.copy(chrs, start, cs, 0, length)
diff --git a/compiler/src/dotty/tools/dotc/core/StdNames.scala b/compiler/src/dotty/tools/dotc/core/StdNames.scala
index c942a058a..815940eb0 100644
--- a/compiler/src/dotty/tools/dotc/core/StdNames.scala
+++ b/compiler/src/dotty/tools/dotc/core/StdNames.scala
@@ -25,6 +25,9 @@ object StdNames {
final val AVOID_CLASH_SUFFIX = "$_avoid_name_clash_$"
final val MODULE_SUFFIX = NameTransformer.MODULE_SUFFIX_STRING
final val DEFAULT_GETTER = "$default$"
+ final val LOCALDUMMY_PREFIX = "<local " // owner of local blocks
+ final val ANON_CLASS = "$anon"
+ final val ANON_FUN = "$anonfun"
final val INTERPRETER_IMPORT_WRAPPER = "$iw"
final val INTERPRETER_LINE_PREFIX = "line"
@@ -109,8 +112,8 @@ object StdNames {
final val HASHkw: N = kw("#")
final val ATkw: N = kw("@")
- val ANON_CLASS: N = "$anon"
- val ANON_FUN: N = "$anonfun"
+ val ANON_CLASS: N = str.ANON_CLASS
+ val ANON_FUN: N = str.ANON_FUN
val BITMAP_PREFIX: N = "bitmap$" // @darkdimius: $bitmap? Also, the next 4 names are unused.
val BITMAP_NORMAL: N = BITMAP_PREFIX // initialization bitmap for public/protected lazy vals
val BITMAP_TRANSIENT: N = BITMAP_PREFIX + "trans$" // initialization bitmap for transient lazy vals
@@ -125,7 +128,6 @@ object StdNames {
val EXPAND_SEPARATOR: N = str.EXPAND_SEPARATOR
val IMPL_CLASS_SUFFIX: N = "$class"
val IMPORT: N = "<import>"
- val LOCALDUMMY_PREFIX: N = "<local " // owner of local blocks
val MODULE_SUFFIX: N = NameTransformer.MODULE_SUFFIX_STRING
val NAME_JOIN: N = NameTransformer.NAME_JOIN_STRING
val OPS_PACKAGE: N = "<special-ops>"
@@ -261,7 +263,6 @@ object StdNames {
val ROOTPKG: N = "_root_"
val SELECTOR_DUMMY: N = "<unapply-selector>"
val SELF: N = "$this"
- val SETTER_SUFFIX: N = encode("_=")
val SKOLEM: N = "<skolem>"
val SPECIALIZED_INSTANCE: N = "specInstance$"
val THIS: N = "_$this"
@@ -661,22 +662,6 @@ object StdNames {
val isBoxedNumberOrBoolean: N = "isBoxedNumberOrBoolean"
val isBoxedNumber: N = "isBoxedNumber"
-
- val reflPolyCacheName: N = "reflPoly$Cache"
- val reflClassCacheName: N = "reflClass$Cache"
- val reflParamsCacheName: N = "reflParams$Cache"
- val reflMethodCacheName: N = "reflMethod$Cache"
- val reflMethodName: N = "reflMethod$Method"
-
- private val reflectionCacheNames = Set[N](
- reflPolyCacheName,
- reflClassCacheName,
- reflParamsCacheName,
- reflMethodCacheName,
- reflMethodName
- )
-
- def isReflectionCacheName(name: Name) = reflectionCacheNames exists (name startsWith _)
}
class ScalaTermNames extends ScalaNames[TermName] {
@@ -723,7 +708,7 @@ object StdNames {
}
def localDummyName(clazz: Symbol)(implicit ctx: Context): TermName =
- LOCALDUMMY_PREFIX ++ clazz.name ++ ">"
+ termName(str.LOCALDUMMY_PREFIX + clazz.name + ">")
def newBitmapName(bitmapPrefix: TermName, n: Int): TermName = bitmapPrefix ++ n.toString
diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala
index 547fd2d91..1c7206533 100644
--- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala
+++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala
@@ -461,13 +461,13 @@ object SymDenotations {
/** Is this symbol an anonymous class? */
final def isAnonymousClass(implicit ctx: Context): Boolean =
- isClass && (initial.name startsWith tpnme.ANON_CLASS)
+ isClass && (initial.name startsWith str.ANON_CLASS)
final def isAnonymousFunction(implicit ctx: Context) =
- this.symbol.is(Method) && (initial.name startsWith nme.ANON_FUN)
+ this.symbol.is(Method) && (initial.name startsWith str.ANON_FUN)
final def isAnonymousModuleVal(implicit ctx: Context) =
- this.symbol.is(ModuleVal) && (initial.name startsWith nme.ANON_CLASS)
+ this.symbol.is(ModuleVal) && (initial.name startsWith str.ANON_CLASS)
/** Is this a companion class method or companion object method?
* These methods are generated by Symbols#synthesizeCompanionMethod
diff --git a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala
index 608c77a8e..5871ec46c 100644
--- a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala
+++ b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala
@@ -1036,7 +1036,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
val rhs = readTreeRef()
val params = until(end, readIdentRef)
val ldef = DefDef(symbol.asTerm, rhs)
- def isCaseLabel(sym: Symbol) = sym.name.startsWith(nme.CASEkw)
+ def isCaseLabel(sym: Symbol) = sym.name.startsWith(nme.CASEkw.toString)
if (isCaseLabel(symbol)) ldef
else Block(ldef :: Nil, Apply(Ident(symbol.termRef), Nil))
diff --git a/compiler/test/dotty/tools/DottyTypeStealer.scala b/compiler/test/dotty/tools/DottyTypeStealer.scala
index ff6e67e41..727cd9e7d 100644
--- a/compiler/test/dotty/tools/DottyTypeStealer.scala
+++ b/compiler/test/dotty/tools/DottyTypeStealer.scala
@@ -19,7 +19,7 @@ object DottyTypeStealer extends DottyTest {
implicit val ctx = context
val findValDef: (List[ValDef], tpd.Tree) => List[ValDef] =
(acc , tree) => { tree match {
- case t: ValDef if t.name.startsWith(dummyName.toTermName) => t :: acc
+ case t: ValDef if t.name.startsWith(dummyName) => t :: acc
case _ => acc
}
}