From 6e18fbbd388afcb4627a97fb7bae141b7c36a86a Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Fri, 15 Oct 2010 06:30:07 +0000 Subject: Working out some more of the flags situation. --- src/compiler/scala/tools/nsc/ast/Trees.scala | 3 +- src/compiler/scala/tools/nsc/symtab/Symbols.scala | 7 +- .../scala/tools/nsc/transform/CleanUp.scala | 2 +- src/library/scala/reflect/generic/HasFlags.scala | 82 +++++++++++++++------- src/library/scala/reflect/generic/Symbols.scala | 4 -- 5 files changed, 61 insertions(+), 37 deletions(-) (limited to 'src') diff --git a/src/compiler/scala/tools/nsc/ast/Trees.scala b/src/compiler/scala/tools/nsc/ast/Trees.scala index 17a932575b..1d914aa414 100644 --- a/src/compiler/scala/tools/nsc/ast/Trees.scala +++ b/src/compiler/scala/tools/nsc/ast/Trees.scala @@ -251,8 +251,7 @@ trait Trees extends reflect.generic.Trees { self: SymbolTable => DefDef(NoMods, nme.MIXIN_CONSTRUCTOR, List(), List(List()), TypeTree(), Block(lvdefs, Literal(()))))) } else { // convert (implicit ... ) to ()(implicit ... ) if its the only parameter section - if (vparamss1.isEmpty || - !vparamss1.head.isEmpty && (vparamss1.head.head.mods.flags & IMPLICIT) != 0L) + if (vparamss1.isEmpty || !vparamss1.head.isEmpty && vparamss1.head.head.mods.isImplicit) vparamss1 = List() :: vparamss1; val superRef: Tree = atPos(superPos) { Select(Super(nme.EMPTY.toTypeName, nme.EMPTY.toTypeName), nme.CONSTRUCTOR) diff --git a/src/compiler/scala/tools/nsc/symtab/Symbols.scala b/src/compiler/scala/tools/nsc/symtab/Symbols.scala index 567754dc2e..60ae6b3f07 100644 --- a/src/compiler/scala/tools/nsc/symtab/Symbols.scala +++ b/src/compiler/scala/tools/nsc/symtab/Symbols.scala @@ -393,7 +393,6 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable => final def isValueParameter = isTerm && hasFlag(PARAM) final def isLocalDummy = isTerm && nme.isLocalDummyName(name) - final def isLabel = isMethod && !hasFlag(ACCESSOR) && hasFlag(LABEL) final def isInitializedToDefault = !isType && hasAllFlags(DEFAULTINIT | ACCESSOR) final def isClassConstructor = isTerm && (name == nme.CONSTRUCTOR) final def isMixinConstructor = isTerm && (name == nme.MIXIN_CONSTRUCTOR) @@ -512,8 +511,10 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable => ((hasFlag(notPRIVATE | LIFTED) && !hasFlag(ACCESSOR | SUPERACCESSOR | MODULE) || isConstructor) || (hasFlag(LIFTED) && isModule && isMethod)) - /** Is this symbol a module variable ? */ - final def isModuleVar: Boolean = isVariable && hasFlag(MODULEVAR) + /** Is this symbol a module variable ? + * MUTABLE is needed to partition overloaded flags MODULEVAR and SYNTHETICMETH. + */ + final def isModuleVar: Boolean = hasAllFlags(MODULEVAR | MUTABLE) /** Is this symbol static (i.e. with no outer instance)? */ final def isStatic: Boolean = diff --git a/src/compiler/scala/tools/nsc/transform/CleanUp.scala b/src/compiler/scala/tools/nsc/transform/CleanUp.scala index 932b05c250..2d9c89bea0 100644 --- a/src/compiler/scala/tools/nsc/transform/CleanUp.scala +++ b/src/compiler/scala/tools/nsc/transform/CleanUp.scala @@ -104,7 +104,7 @@ abstract class CleanUp extends Transform with ast.TreeDSL { def addStaticVariableToClass(forName: String, forType: Type, forInit: Tree, isFinal: Boolean): Symbol = { val varSym = currentClass.newVariable(ad.pos, mkName(forName)) - .setFlag(PRIVATE | STATIC | MUTABLE | SYNTHETIC) + .setFlag(PRIVATE | STATIC | SYNTHETIC) .setInfo(forType) if (isFinal) varSym setFlag FINAL else varSym addAnnotation AnnotationInfo(VolatileAttr.tpe, Nil, Nil) currentClass.info.decls enter varSym diff --git a/src/library/scala/reflect/generic/HasFlags.scala b/src/library/scala/reflect/generic/HasFlags.scala index 27c591c6ae..9ce91ce197 100644 --- a/src/library/scala/reflect/generic/HasFlags.scala +++ b/src/library/scala/reflect/generic/HasFlags.scala @@ -21,7 +21,7 @@ package generic * // Defined in the compiler Symbol // - final def isLabel = isMethod && !hasFlag(ACCESSOR) && hasFlag(LABEL) + final def isLabel = isMethod && !hasAccessorFlag && hasFlag(LABEL) final def isLocal: Boolean = owner.isTerm final def isModuleVar: Boolean = isVariable && hasFlag(MODULEVAR) final def isStable = @@ -139,25 +139,28 @@ trait HasFlags { // Tests which come through cleanly: both Symbol and Modifiers use these // identically, testing for a single flag. - def isCase = hasFlag(CASE ) - def isFinal = hasFlag(FINAL ) - def isImplicit = hasFlag(IMPLICIT ) - def isLazy = hasFlag(LAZY ) - def isMutable = hasFlag(MUTABLE ) // in Modifiers, formerly isVariable - def isOverride = hasFlag(OVERRIDE ) - def isPrivate = hasFlag(PRIVATE ) - def isProtected = hasFlag(PROTECTED) - def isSynthetic = hasFlag(SYNTHETIC) + def isCase = hasFlag(CASE ) + def isFinal = hasFlag(FINAL ) + def isImplicit = hasFlag(IMPLICIT ) + def isLazy = hasFlag(LAZY ) + def isMutable = hasFlag(MUTABLE ) // in Modifiers, formerly isVariable + def isOverride = hasFlag(OVERRIDE ) + def isPrivate = hasFlag(PRIVATE ) + def isProtected = hasFlag(PROTECTED) + def isSynthetic = hasFlag(SYNTHETIC) + def isInterface = hasFlag(INTERFACE) // Newly introduced based on having a reasonably obvious clean translation. - def isPrivateLocal = isPrivate && hasFlag(LOCAL) - def isProtectedLocal = isProtected && hasFlag(LOCAL) + def isPrivateLocal = hasAllFlags(PRIVATE | LOCAL) + def isProtectedLocal = hasAllFlags(PROTECTED | LOCAL) def isParamAccessor = hasFlag(PARAMACCESSOR) def isCaseAccessor = hasFlag(CASEACCESSOR) + def isSuperAccessor = hasFlag(SUPERACCESSOR) + def isLifted = hasFlag(LIFTED) // Formerly the Modifiers impl did not include the access boundary check, // which must have been a bug. - def isPublic = !hasFlag(PRIVATE | PROTECTED) && !hasAccessBoundary + def isPublic = hasNoFlags(PRIVATE | PROTECTED) && !hasAccessBoundary // Renamed the Modifiers impl from isArgument. def isParameter = hasFlag(PARAM) @@ -169,23 +172,48 @@ trait HasFlags { // Removed !isClass qualification since the flag isn't overloaded. def isDeferred = hasFlag(DEFERRED ) - // Problematic: - // DEFAULTPARAM overloaded with TRAIT - def hasDefault = isParameter && hasFlag(DEFAULTPARAM) - def hasDefaultFlag = hasFlag(DEFAULTPARAM) - @deprecated("") def isTrait = hasFlag(TRAIT) - // def isTrait: Boolean = isClass && hasFlag(TRAIT) // refined later for virtual classes. - - // Straightforwardly named accessors already being used differently - def hasStaticFlag = hasFlag(STATIC) - def hasLocalFlag = hasFlag(LOCAL) - def hasModuleFlag = hasFlag(MODULE) - + // Dropped isTerm condition because flag isn't overloaded. + def isAbstractOverride = hasFlag(ABSOVERRIDE) + + def isDefaultInit = hasFlag(DEFAULTINIT) + + // Disambiguating: DEFAULTPARAM, TRAIT + def hasDefault = hasAllFlags(DEFAULTPARAM | PARAM) + def isTrait = hasFlag(TRAIT) && !hasFlag(PARAM) + + // Straightforwardly named accessors already being used differently. + // These names are most likely temporary. + def hasAbstractFlag = hasFlag(ABSTRACT) + def hasAccessorFlag = hasFlag(ACCESSOR) + def hasLocalFlag = hasFlag(LOCAL) + def hasModuleFlag = hasFlag(MODULE) + def hasPackageFlag = hasFlag(PACKAGE) + def hasPreSuperFlag = hasFlag(PRESUPER) + def hasStableFlag = hasFlag(STABLE) + def hasStaticFlag = hasFlag(STATIC) + + // Disambiguating: BYNAMEPARAM, CAPTURED, COVARIANT. + def isByNameParam = hasAllFlags(BYNAMEPARAM | PARAM) + // Nope, these aren't going to fly: + // def isCapturedVariable = hasAllFlags(CAPTURED | MUTABLE) + // def isCovariant = hasFlag(COVARIANT) && hasNoFlags(PARAM | MUTABLE) + + // Disambiguating: LABEL, CONTRAVARIANT, INCONSTRUCTOR + def isLabel = hasAllFlags(LABEL | METHOD) && !hasAccessorFlag + // Cannot effectively disambiguate the others at this level. + def hasContravariantFlag = hasFlag(CONTRAVARIANT) + def hasInConstructorFlag = hasFlag(INCONSTRUCTOR) + + // Name + def isJavaDefined = hasFlag(JAVA) + + // Keeping some potentially ambiguous names around so as not to break + // the rest of the world + @deprecated("") def isAbstract = hasFlag(ABSTRACT) // Problematic: // ABSTRACT and DEFERRED too easy to confuse, and // ABSTRACT + OVERRIDE ==> ABSOVERRIDE adds to it. // - @deprecated("") def isAbstract = hasFlag(ABSTRACT) // final def isAbstractClass = isClass && hasFlag(ABSTRACT) // def isAbstractType = false // to be overridden @@ -195,6 +223,6 @@ trait HasFlags { // *ACCESSOR flags. Perhaps something like isSimpleAccessor. // // def isAccessor = hasFlag(ACCESSOR ) - // final def isGetterOrSetter = hasFlag(ACCESSOR) + // final def isGetterOrSetter = hasAccessorFlag } diff --git a/src/library/scala/reflect/generic/Symbols.scala b/src/library/scala/reflect/generic/Symbols.scala index fe541cd6a9..25454698f8 100755 --- a/src/library/scala/reflect/generic/Symbols.scala +++ b/src/library/scala/reflect/generic/Symbols.scala @@ -130,7 +130,6 @@ trait Symbols { self: Universe => override def isTrait: Boolean = isClass && hasFlag(TRAIT) // refined later for virtual classes. final def isAbstractClass = isClass && hasFlag(ABSTRACT) - final def isAbstractOverride = isTerm && hasFlag(ABSOVERRIDE) final def isBridge = hasFlag(BRIDGE) final def isContravariant = isType && hasFlag(CONTRAVARIANT) final def isCovariant = isType && hasFlag(COVARIANT) @@ -138,8 +137,6 @@ trait Symbols { self: Universe => final def isExistentiallyBound = isType && hasFlag(EXISTENTIAL) final def isGetterOrSetter = hasFlag(ACCESSOR) final def isImplClass = isClass && hasFlag(IMPLCLASS) // Is this symbol an implementation class for a mixin? - final def isInterface = hasFlag(INTERFACE) - final def isJavaDefined = hasFlag(JAVA) final def isLazyAccessor = isLazy && lazyAccessor != NoSymbol final def isMethod = isTerm && hasFlag(METHOD) final def isModule = isTerm && hasFlag(MODULE) @@ -147,7 +144,6 @@ trait Symbols { self: Universe => final def isOverloaded = hasFlag(OVERLOADED) final def isRefinementClass = isClass && name == mkTypeName(nme.REFINE_CLASS_NAME) final def isSourceMethod = isMethod && !hasFlag(STABLE) // exclude all accessors!!! - final def isSuperAccessor = hasFlag(SUPERACCESSOR) final def isTypeParameter = isType && isParameter && !isSkolem /** Package tests */ -- cgit v1.2.3