Skip to content

Commit d46ab5e

Browse files
committed
Further simplification for Name
1 parent 9d27b3e commit d46ab5e

File tree

7 files changed

+17
-34
lines changed

7 files changed

+17
-34
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class Definitions {
119119
enterTypeParam(cls, name ++ "$T" ++ i.toString, Contravariant, decls)
120120
val resParam = enterTypeParam(cls, name ++ "$R", Covariant, decls)
121121
val (methodType, parentTraits) =
122-
if (name.startsWith(str.ImplicitFunction)) {
122+
if (name.firstPart.startsWith(str.ImplicitFunction)) {
123123
val superTrait =
124124
FunctionType(arity).appliedTo(argParams.map(_.typeRef) ::: resParam.typeRef :: Nil)
125125
(ImplicitMethodType, ctx.normalizeToClassRefs(superTrait :: Nil, cls, decls))

compiler/src/dotty/tools/dotc/core/NameOps.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ object NameOps {
6363

6464
def isConstructorName = name == CONSTRUCTOR || name == TRAIT_CONSTRUCTOR
6565
def isStaticConstructorName = name == STATIC_CONSTRUCTOR
66-
def isLocalDummyName = name startsWith LOCALDUMMY_PREFIX
66+
def isLocalDummyName = name startsWith str.LOCALDUMMY_PREFIX
6767
def isReplWrapperName = name.toString contains str.INTERPRETER_IMPORT_WRAPPER
68-
def isSetterName = name endsWith SETTER_SUFFIX
68+
def isSetterName = name endsWith str.SETTER_SUFFIX
6969
def isScala2LocalSuffix = testSimple(_.endsWith(" "))
7070
def isSelectorName = testSimple(n => n.startsWith("_") && n.drop(1).forall(_.isDigit))
7171

@@ -248,7 +248,7 @@ object NameOps {
248248

249249
def getterName: TermName =
250250
name.exclude(FieldName).mapLast(n =>
251-
if (n.endsWith(SETTER_SUFFIX)) n.take(n.length - str.SETTER_SUFFIX.length).asSimpleName
251+
if (n.endsWith(str.SETTER_SUFFIX)) n.take(n.length - str.SETTER_SUFFIX.length).asSimpleName
252252
else n)
253253

254254
def fieldName: TermName =

compiler/src/dotty/tools/dotc/core/Names.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,7 @@ object Names {
101101
def isEmpty: Boolean
102102

103103
def startsWith(str: String): Boolean = firstPart.startsWith(str)
104-
def startsWith(name: Name): Boolean = startsWith(name.toString)
105104
def endsWith(str: String): Boolean = lastPart.endsWith(str)
106-
def endsWith(name: Name): Boolean = endsWith(name.toString)
107-
def lastIndexOfSlice(str: String): Int = lastPart.toString.lastIndexOfSlice(str)
108-
def lastIndexOfSlice(name: Name): Int = lastIndexOfSlice(name.toString)
109105

110106
override def hashCode = System.identityHashCode(this)
111107
override def equals(that: Any) = this eq that.asInstanceOf[AnyRef]
@@ -240,6 +236,8 @@ object Names {
240236
i
241237
}
242238

239+
def lastIndexOfSlice(str: String): Int = toString.lastIndexOfSlice(str)
240+
243241
override def replace(from: Char, to: Char): SimpleTermName = {
244242
val cs = new Array[Char](length)
245243
Array.copy(chrs, start, cs, 0, length)

compiler/src/dotty/tools/dotc/core/StdNames.scala

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ object StdNames {
2525
final val AVOID_CLASH_SUFFIX = "$_avoid_name_clash_$"
2626
final val MODULE_SUFFIX = NameTransformer.MODULE_SUFFIX_STRING
2727
final val DEFAULT_GETTER = "$default$"
28+
final val LOCALDUMMY_PREFIX = "<local " // owner of local blocks
29+
final val ANON_CLASS = "$anon"
30+
final val ANON_FUN = "$anonfun"
2831

2932
final val INTERPRETER_IMPORT_WRAPPER = "$iw"
3033
final val INTERPRETER_LINE_PREFIX = "line"
@@ -109,8 +112,8 @@ object StdNames {
109112
final val HASHkw: N = kw("#")
110113
final val ATkw: N = kw("@")
111114

112-
val ANON_CLASS: N = "$anon"
113-
val ANON_FUN: N = "$anonfun"
115+
val ANON_CLASS: N = str.ANON_CLASS
116+
val ANON_FUN: N = str.ANON_FUN
114117
val BITMAP_PREFIX: N = "bitmap$" // @darkdimius: $bitmap? Also, the next 4 names are unused.
115118
val BITMAP_NORMAL: N = BITMAP_PREFIX // initialization bitmap for public/protected lazy vals
116119
val BITMAP_TRANSIENT: N = BITMAP_PREFIX + "trans$" // initialization bitmap for transient lazy vals
@@ -125,7 +128,6 @@ object StdNames {
125128
val EXPAND_SEPARATOR: N = str.EXPAND_SEPARATOR
126129
val IMPL_CLASS_SUFFIX: N = "$class"
127130
val IMPORT: N = "<import>"
128-
val LOCALDUMMY_PREFIX: N = "<local " // owner of local blocks
129131
val MODULE_SUFFIX: N = NameTransformer.MODULE_SUFFIX_STRING
130132
val NAME_JOIN: N = NameTransformer.NAME_JOIN_STRING
131133
val OPS_PACKAGE: N = "<special-ops>"
@@ -261,7 +263,6 @@ object StdNames {
261263
val ROOTPKG: N = "_root_"
262264
val SELECTOR_DUMMY: N = "<unapply-selector>"
263265
val SELF: N = "$this"
264-
val SETTER_SUFFIX: N = encode("_=")
265266
val SKOLEM: N = "<skolem>"
266267
val SPECIALIZED_INSTANCE: N = "specInstance$"
267268
val THIS: N = "_$this"
@@ -659,22 +660,6 @@ object StdNames {
659660

660661
val isBoxedNumberOrBoolean: N = "isBoxedNumberOrBoolean"
661662
val isBoxedNumber: N = "isBoxedNumber"
662-
663-
val reflPolyCacheName: N = "reflPoly$Cache"
664-
val reflClassCacheName: N = "reflClass$Cache"
665-
val reflParamsCacheName: N = "reflParams$Cache"
666-
val reflMethodCacheName: N = "reflMethod$Cache"
667-
val reflMethodName: N = "reflMethod$Method"
668-
669-
private val reflectionCacheNames = Set[N](
670-
reflPolyCacheName,
671-
reflClassCacheName,
672-
reflParamsCacheName,
673-
reflMethodCacheName,
674-
reflMethodName
675-
)
676-
677-
def isReflectionCacheName(name: Name) = reflectionCacheNames exists (name startsWith _)
678663
}
679664

680665
class ScalaTermNames extends ScalaNames[TermName] {
@@ -724,7 +709,7 @@ object StdNames {
724709
(0 until num).map(syntheticParamName)(breakOut)
725710

726711
def localDummyName(clazz: Symbol)(implicit ctx: Context): TermName =
727-
LOCALDUMMY_PREFIX ++ clazz.name ++ ">"
712+
termName(str.LOCALDUMMY_PREFIX + clazz.name + ">")
728713

729714
def newBitmapName(bitmapPrefix: TermName, n: Int): TermName = bitmapPrefix ++ n.toString
730715

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -456,13 +456,13 @@ object SymDenotations {
456456

457457
/** Is this symbol an anonymous class? */
458458
final def isAnonymousClass(implicit ctx: Context): Boolean =
459-
isClass && (initial.name startsWith tpnme.ANON_CLASS)
459+
isClass && (initial.name startsWith str.ANON_CLASS)
460460

461461
final def isAnonymousFunction(implicit ctx: Context) =
462-
this.symbol.is(Method) && (initial.name startsWith nme.ANON_FUN)
462+
this.symbol.is(Method) && (initial.name startsWith str.ANON_FUN)
463463

464464
final def isAnonymousModuleVal(implicit ctx: Context) =
465-
this.symbol.is(ModuleVal) && (initial.name startsWith nme.ANON_CLASS)
465+
this.symbol.is(ModuleVal) && (initial.name startsWith str.ANON_CLASS)
466466

467467
/** Is this a companion class method or companion object method?
468468
* These methods are generated by Symbols#synthesizeCompanionMethod

compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
10341034
val rhs = readTreeRef()
10351035
val params = until(end, readIdentRef)
10361036
val ldef = DefDef(symbol.asTerm, rhs)
1037-
def isCaseLabel(sym: Symbol) = sym.name.startsWith(nme.CASEkw)
1037+
def isCaseLabel(sym: Symbol) = sym.name.startsWith(nme.CASEkw.toString)
10381038
if (isCaseLabel(symbol)) ldef
10391039
else Block(ldef :: Nil, Apply(Ident(symbol.termRef), Nil))
10401040

compiler/test/dotty/tools/DottyTypeStealer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ object DottyTypeStealer extends DottyTest {
1919
implicit val ctx = context
2020
val findValDef: (List[ValDef], tpd.Tree) => List[ValDef] =
2121
(acc , tree) => { tree match {
22-
case t: ValDef if t.name.startsWith(dummyName.toTermName) => t :: acc
22+
case t: ValDef if t.name.startsWith(dummyName) => t :: acc
2323
case _ => acc
2424
}
2525
}

0 commit comments

Comments
 (0)