From a574ba6b70fc8a8dadf4ec493fcb5dc19d1fa478 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 31 Mar 2017 19:01:10 +0200 Subject: Further simplification for Name --- .../src/dotty/tools/dotc/core/Definitions.scala | 2 +- compiler/src/dotty/tools/dotc/core/NameOps.scala | 6 ++--- compiler/src/dotty/tools/dotc/core/Names.scala | 6 ++--- compiler/src/dotty/tools/dotc/core/StdNames.scala | 27 +++++----------------- .../src/dotty/tools/dotc/core/SymDenotations.scala | 6 ++--- .../dotc/core/unpickleScala2/Scala2Unpickler.scala | 2 +- compiler/test/dotty/tools/DottyTypeStealer.scala | 2 +- 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 = "" + 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 } } -- cgit v1.2.3