From 130069ad787ca20e960d57e11e6f4911e3bed5a0 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 31 Mar 2017 15:01:06 +0200 Subject: Cleanups of NameOps Remove unused functionality --- .../tools/backend/jvm/DottyBackendInterface.scala | 4 +- compiler/src/dotty/tools/dotc/core/NameOps.scala | 79 ---------------------- compiler/src/dotty/tools/dotc/core/StdNames.scala | 1 - .../tools/dotc/transform/SuperAccessors.scala | 4 +- compiler/src/dotty/tools/dotc/typer/Namer.scala | 12 ++-- .../src/dotty/tools/dotc/typer/RefChecks.scala | 15 ++-- 6 files changed, 15 insertions(+), 100 deletions(-) diff --git a/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala b/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala index db4a0c694..a300857ec 100644 --- a/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala +++ b/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala @@ -30,9 +30,9 @@ import Decorators._ import tpd._ import scala.tools.asm -import NameOps._ import StdNames.nme import NameOps._ +import NameKinds.DefaultGetterName import dotty.tools.dotc.core import dotty.tools.dotc.core.Names.TypeName @@ -255,7 +255,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma val evalue = t.symbol.name.toString // value the actual enumeration value. av.visitEnum(name, edesc, evalue) } else { - assert(toDenot(t.symbol).name.toTermName.defaultGetterIndex >= 0) // this should be default getter. do not emmit. + assert(toDenot(t.symbol).name.is(DefaultGetterName)) // this should be default getter. do not emmit. } case t: SeqLiteral => val arrAnnotV: AnnotationVisitor = av.visitArray(name) diff --git a/compiler/src/dotty/tools/dotc/core/NameOps.scala b/compiler/src/dotty/tools/dotc/core/NameOps.scala index 44c5c1e09..2caaaf1ab 100644 --- a/compiler/src/dotty/tools/dotc/core/NameOps.scala +++ b/compiler/src/dotty/tools/dotc/core/NameOps.scala @@ -61,7 +61,6 @@ object NameOps { def isReplWrapperName = name.toSimpleName containsSlice INTERPRETER_IMPORT_WRAPPER def isSetterName = name endsWith SETTER_SUFFIX def isScala2LocalSuffix = name.endsWith(" ") - def isModuleVarName(name: Name): Boolean = name.exclude(UniqueName).is(ModuleVarName) def isSelectorName = name.startsWith("_") && name.tail.forall(_.isDigit) /** Is name a variable name? */ @@ -105,9 +104,6 @@ object NameOps { else name.toTermName.exclude(AvoidClashName) } - /** The superaccessor for method with given name */ - def superName: TermName = SuperAccessorName(name.toTermName) - def expandedName(base: Symbol, kind: QualifiedNameKind = ExpandedName)(implicit ctx: Context): N = { val prefix = if (base.name.is(ExpandedName)) base.name else base.fullNameSeparated(ExpandPrefixName) @@ -307,17 +303,6 @@ object NameOps { } } - // needed??? - private val Boxed = Map[TypeName, TypeName]( - tpnme.Boolean -> jtpnme.BoxedBoolean, - tpnme.Byte -> jtpnme.BoxedByte, - tpnme.Char -> jtpnme.BoxedCharacter, - tpnme.Short -> jtpnme.BoxedShort, - tpnme.Int -> jtpnme.BoxedInteger, - tpnme.Long -> jtpnme.BoxedLong, - tpnme.Float -> jtpnme.BoxedFloat, - tpnme.Double -> jtpnme.BoxedDouble) - implicit class TermNameDecorator(val name: TermName) extends AnyVal { import nme._ @@ -338,18 +323,6 @@ object NameOps { } else FieldName(name) - /** Nominally, name from name$default$N, CONSTRUCTOR for */ - def defaultGetterToMethod: TermName = - name rewrite { - case DefaultGetterName(methName, _) => methName - } - - /** If this is a default getter, its index (starting from 0), else -1 */ - def defaultGetterIndex: Int = - name collect { - case DefaultGetterName(_, num) => num - } getOrElse -1 - def stripScala2LocalSuffix: TermName = if (name.isScala2LocalSuffix) name.init.asTermName else name @@ -361,57 +334,5 @@ object NameOps { case raw.BANG => UNARY_! case _ => name } - - /** The name of a method which stands in for a primitive operation - * during structural type dispatch. - */ - def primitiveInfixMethodName: TermName = name match { - case OR => takeOr - case XOR => takeXor - case AND => takeAnd - case EQ => testEqual - case NE => testNotEqual - case ADD => add - case SUB => subtract - case MUL => multiply - case DIV => divide - case MOD => takeModulo - case LSL => shiftSignedLeft - case LSR => shiftLogicalRight - case ASR => shiftSignedRight - case LT => testLessThan - case LE => testLessOrEqualThan - case GE => testGreaterOrEqualThan - case GT => testGreaterThan - case ZOR => takeConditionalOr - case ZAND => takeConditionalAnd - case _ => NO_NAME - } - - /** Postfix/prefix, really. - */ - def primitivePostfixMethodName: TermName = name match { - case UNARY_! => takeNot - case UNARY_+ => positive - case UNARY_- => negate - case UNARY_~ => complement - case `toByte` => toByte - case `toShort` => toShort - case `toChar` => toCharacter - case `toInt` => toInteger - case `toLong` => toLong - case `toFloat` => toFloat - case `toDouble` => toDouble - case _ => NO_NAME - } - - def primitiveMethodName: TermName = - primitiveInfixMethodName match { - case NO_NAME => primitivePostfixMethodName - case name => name - } } - - private final val FalseSuper = "$$super".toTermName - private val FalseSuperLength = FalseSuper.length } diff --git a/compiler/src/dotty/tools/dotc/core/StdNames.scala b/compiler/src/dotty/tools/dotc/core/StdNames.scala index b5d8e356e..8eea6aded 100644 --- a/compiler/src/dotty/tools/dotc/core/StdNames.scala +++ b/compiler/src/dotty/tools/dotc/core/StdNames.scala @@ -252,7 +252,6 @@ object StdNames { val REIFY_SYMDEF_PREFIX: N = "symdef$" val MODULE_INSTANCE_FIELD: N = NameTransformer.MODULE_INSTANCE_NAME // "MODULE$" val OUTER: N = "$outer" - val OUTER_LOCAL: N = "$outer " val REFINE_CLASS: N = "" val ROOTPKG: N = "_root_" val SELECTOR_DUMMY: N = "" diff --git a/compiler/src/dotty/tools/dotc/transform/SuperAccessors.scala b/compiler/src/dotty/tools/dotc/transform/SuperAccessors.scala index 80d9091fb..84a32f93b 100644 --- a/compiler/src/dotty/tools/dotc/transform/SuperAccessors.scala +++ b/compiler/src/dotty/tools/dotc/transform/SuperAccessors.scala @@ -11,7 +11,7 @@ import Types._, Contexts._, Constants._, Names._, NameOps._, Flags._, DenotTrans import SymDenotations._, Symbols._, StdNames._, Annotations._, Trees._, Scopes._, Denotations._ import util.Positions._ import Decorators._ -import NameKinds.{ProtectedAccessorName, ProtectedSetterName, OuterSelectName} +import NameKinds.{ProtectedAccessorName, ProtectedSetterName, OuterSelectName, SuperAccessorName} import Symbols._, TypeUtils._ /** This class performs the following functions: @@ -72,7 +72,7 @@ class SuperAccessors(thisTransformer: DenotTransformer) { val Select(qual, name) = sel val sym = sel.symbol val clazz = qual.symbol.asClass - var superName = name.superName + var superName = SuperAccessorName(name.asTermName) if (clazz is Trait) superName = superName.expandedName(clazz) val superInfo = sel.tpe.widenSingleton.ensureMethodic diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index 78a1cd9c3..19b6dfa71 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -6,6 +6,7 @@ import core._ import ast._ import Trees._, Constants._, StdNames._, Scopes._, Denotations._, Comments._ import Contexts._, Symbols._, Types._, SymDenotations._, Names._, NameOps._, Flags._, Decorators._ +import NameKinds.DefaultGetterName import ast.desugar, ast.desugar._ import ProtoTypes._ import util.Positions._ @@ -1012,12 +1013,8 @@ class Namer { typer: Typer => * the corresponding parameter where bound parameters are replaced by * Wildcards. */ - def rhsProto = { - val name = sym.asTerm.name - val idx = name.defaultGetterIndex - if (idx < 0) WildcardType - else { - val original = name.defaultGetterToMethod + def rhsProto = sym.asTerm.name collect { + case DefaultGetterName(original, idx) => val meth: Denotation = if (original.isConstructorName && (sym.owner is ModuleClass)) sym.owner.companionClass.info.decl(nme.CONSTRUCTOR) @@ -1035,8 +1032,7 @@ class Namer { typer: Typer => paramProto(defaultAlts.head.info.widen.paramInfoss, idx) else WildcardType - } - } + } getOrElse WildcardType // println(s"final inherited for $sym: ${inherited.toString}") !!! // println(s"owner = ${sym.owner}, decls = ${sym.owner.info.decls.show}") diff --git a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala index 49bc24c80..4715873e5 100644 --- a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala +++ b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala @@ -6,6 +6,7 @@ import core._ import config._ import Symbols._, SymDenotations._, Types._, Contexts._, Decorators._, Flags._, Names._, NameOps._ import StdNames._, Denotations._, Scopes._, Constants.Constant, SymUtils._ +import NameKinds.DefaultGetterName import Annotations._ import util.Positions._ import scala.collection.{ mutable, immutable } @@ -24,12 +25,8 @@ object RefChecks { import reporting.diagnostic.Message import reporting.diagnostic.messages._ - - private def isDefaultGetter(name: Name): Boolean = - name.isTermName && name.asTermName.defaultGetterIndex >= 0 - private val defaultMethodFilter = new NameFilter { - def apply(pre: Type, name: Name)(implicit ctx: Context): Boolean = isDefaultGetter(name) + def apply(pre: Type, name: Name)(implicit ctx: Context): Boolean = name.is(DefaultGetterName) } /** Only one overloaded alternative is allowed to define default arguments */ @@ -45,7 +42,9 @@ object RefChecks { if defaultGetterClass.isClass ) { val defaultGetterNames = defaultGetterClass.asClass.memberNames(defaultMethodFilter) - val defaultMethodNames = defaultGetterNames map (_.asTermName.defaultGetterToMethod) + val defaultMethodNames = defaultGetterNames map { _ rewrite { + case DefaultGetterName(methName, _) => methName + }} for (name <- defaultMethodNames) { val methods = clazz.info.member(name).alternatives.map(_.symbol) @@ -238,7 +237,7 @@ object RefChecks { } } else - isDefaultGetter(member.name) || // default getters are not checked for compatibility + member.name.is(DefaultGetterName) || // default getters are not checked for compatibility memberTp.overrides(otherTp) //Console.println(infoString(member) + " overrides " + infoString(other) + " in " + clazz);//DEBUG @@ -298,7 +297,7 @@ object RefChecks { } else if (other.isEffectivelyFinal) { // (1.2) overrideError(i"cannot override final member ${other.showLocated}") } else if (!other.is(Deferred) && - !isDefaultGetter(other.name) && + !other.name.is(DefaultGetterName) && !member.isAnyOverride) { // (*) Exclusion for default getters, fixes SI-5178. We cannot assign the Override flag to // the default getter: one default getter might sometimes override, sometimes not. Example in comment on ticket. -- cgit v1.2.3