diff options
author | Martin Odersky <odersky@gmail.com> | 2013-02-25 12:49:37 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2013-02-25 12:49:37 +0100 |
commit | 94e2c9413def4c6545cfe38ed7b8a5b44bdd6456 (patch) | |
tree | 0b26b3763804acc72a2304e3fabe63159670266c /src/dotty/tools/dotc/core/Flags.scala | |
parent | 6e37f2e4e153109125493c6c82c0ea0eb9800422 (diff) | |
download | dotty-94e2c9413def4c6545cfe38ed7b8a5b44bdd6456.tar.gz dotty-94e2c9413def4c6545cfe38ed7b8a5b44bdd6456.tar.bz2 dotty-94e2c9413def4c6545cfe38ed7b8a5b44bdd6456.zip |
Completed implementation of Flags
Including translation from Scala 2.x flags.
Diffstat (limited to 'src/dotty/tools/dotc/core/Flags.scala')
-rw-r--r-- | src/dotty/tools/dotc/core/Flags.scala | 262 |
1 files changed, 144 insertions, 118 deletions
diff --git a/src/dotty/tools/dotc/core/Flags.scala b/src/dotty/tools/dotc/core/Flags.scala index bded3e822..31062247d 100644 --- a/src/dotty/tools/dotc/core/Flags.scala +++ b/src/dotty/tools/dotc/core/Flags.scala @@ -99,12 +99,20 @@ object Flags { private final val TYPES = 1 << TYPEindex private final val KINDFLAGS = TERMS | TYPES + private final val FirstFlag = 2 + private final val FirstNotPickledFlag = 48 private final val MaxFlag = 63 private var flagName = Array.fill(64, 2)("") private val kindIndices = Set(TERMindex, TYPEindex) + private def isDefinedAsFlag(idx: Int) = flagName(idx) exists (_.nonEmpty) + + private def flagRange(start: Int, end: Int) = + FlagSet((KINDFLAGS.toLong /: (start until end)) ((bits, idx) => + if (isDefinedAsFlag(idx)) bits | (1L << idx) else bits)) + /** The flag with given index between 2 and 63 which applies to terms. * Installs given name as the name of the flag. */ def termFlag(index: Int, name: String): FlagSet = { @@ -164,153 +172,165 @@ object Flags { final val Method = termFlag(7, "<method>") /** Labeled with `abstract` modifier (an abstract class) */ - final val Abstract = typeFlag(8, "abstract") + final val Abstract = typeFlag(7, "abstract") + + /** A (term or type) parameter to a class or method */ + final val Param = commonFlag(8, "<param>") + final val TermParam = Param.toTermFlags + final val TypeParam = Param.toTypeFlags + + /** Labeled with `implicit` modifier (implicit value) */ + final val Implicit = termFlag(9, "implicit") + + /** A trait */ + final val Trait = typeFlag(9, "<trait>") + + /** Labeled with `lazy` (a lazy val). */ + final val Lazy = termFlag(10, "lazy") /** A trait that has only abstract methods as members * (and therefore can be represented by a Java interface */ - final val Interface = typeFlag(9, "interface") + final val Interface = typeFlag(10, "interface") - /** A value or class implementing a module */ - final val Module = commonFlag(10, "module") - final val ModuleVal = Module.toTermFlags - final val ModuleClass = Module.toTypeFlags + /** A value or variable accessor (getter or setter) */ + final val Accessor = termFlag(11, "<accessor>") - /** Labeled with `implicit` modifier (implicit value) */ - final val Implicit = termFlag(11, "implicit") + /** A covariant type variable */ + final val Covariant = typeFlag(11, "<covariant>") - /** Labeled with `sealed` modifier (sealed class) */ - final val Sealed = typeFlag(12, "sealed") + /** A mutable var */ + final val Mutable = termFlag(12, "mutable") - /** A case class or its companion object */ - final val Case = commonFlag(13, "case") - final val CaseClass = Case.toTypeFlags - final val CaseVal = Case.toTermFlags + /** A contravariant type variable */ + final val Contravariant = typeFlag(12, "<contravariant>") - /** Labeled with `lazy` (a lazy val). */ - final val Lazy = termFlag(14, "lazy") + /** Symbol is local to current class (i.e. private[this] or protected[this] + * pre: Private or Protected are also set + */ + final val Local = commonFlag(13, "<local>") - /** A mutable var */ - final val Mutable = termFlag(14, "mutable") + /** A field generated for a primary constructor parameter (no matter if it's a 'val' or not), + * or an accessor of such a field. + */ + final val ParamAccessor = commonFlag(14, "<paramaccessor>") - /** A (term or type) parameter to a class or method */ - final val Param = commonFlag(15, "<param>") - final val TermParam = Param.toTermFlags - final val TypeParam = Param.toTypeFlags + /** A value or class implementing a module */ + final val Module = commonFlag(15, "module") + final val ModuleVal = Module.toTermFlags + final val ModuleClass = Module.toTypeFlags - /** A value or class representing a package */ + /** A value or class representing a package */ final val Package = commonFlag(16, "<package>") final val PackageVal = Package.toTermFlags final val PackageClass = Package.toTypeFlags /** A package object or its module class */ - final val PackageObject = commonFlag(???, "package") + final val PackageObject = commonFlag(17, "package") final val PackageObjectVal = PackageObject.toTermFlags final val PackageObjectClass = PackageObject.toTypeFlags - /** A covariant type variable */ - final val Covariant = typeFlag(17, "<covariant>") + /** A case class or its companion object */ + final val Case = commonFlag(17, "case") + final val CaseClass = Case.toTypeFlags + final val CaseVal = Case.toTermFlags - /** Method is a label. */ - final val Label = termFlag(18, "<label>") + /** A compiler-generated symbol, which is visible for type-checking + * (compare with artifact) + */ + final val Synthetic = commonFlag(18, "<synthetic>") - /** Symbol is a macro */ - final val Macro = commonFlag(???, "<macro>") + /** Symbol's name is expanded */ + final val ExpandedName = commonFlag(19, "<expandedname>") - /** A contravariant type variable */ - final val Contravariant = typeFlag(18, "<contravariant>") + /** Method is a label. */ + final val Label = termFlag(20, "<label>") + + /** Labeled with `sealed` modifier (sealed class) */ + final val Sealed = typeFlag(20, "sealed") /** Labeled with of abstract & override */ - final val AbsOverride = termFlag(19, "abstract override") + final val AbsOverride = termFlag(21, "abstract override") - /** Symbol is local to current class (i.e. private[this] or protected[this] - * pre: Private or Protected are also set - */ - final val Local = commonFlag(20, "<local>") + /** Method is assumed to be stable */ + final val Stable = termFlag(22, "<stable>") - /** Symbol is defined by a Java class */ - final val JavaDefined = commonFlag(21, "<java>") + /** A case parameter (or its accessor, or a GADT skolem) */ + final val CaseAccessor = termFlag(23, "<caseaccessor>") - /** A compiler-generated symbol. which is visible for type-checking - * (compare with artifact) - */ - final val Synthetic = commonFlag(22, "<synthetic>") + /** Class symbol is defined in this/superclass constructor. */ + final val InConstructor = typeFlag(23, "<in-constructor>") - /** Method is assumed to be stable */ - final val Stable = termFlag(23, "<stable>") + /** A super accessor */ + final val SuperAccessor = termFlag(24, "<superaccessor>") - final val Static = commonFlag(24, "<static>") + /** A parameter with a default value */ + final val DefaultParam = termFlag(25, "<defaultparam>") - /** A value or variable accessor (getter or setter) */ - final val Accessor = termFlag(25, "<accessor>") + /** Symbol is initialized to the default value, e.g. var x: T = _ */ + final val DefaultInit = termFlag(26, "<defaultinit>") - /** A case parameter (or its accessor, or a GADT skolem) */ - final val CaseAccessor = termFlag(26, "<caseaccessor>") + /** Symbol is a macro */ + final val Macro = commonFlag(27, "<macro>") - /** A super accessor */ - final val SuperAccessor = termFlag(27, "<superaccessor>") + /** Symbol is defined by a Java class */ + final val JavaDefined = commonFlag(28, "<java>") - /** A field generated for a primary constructor parameter (no matter if it's a 'val' or not), - * or an accessor of such a field. - */ - final val ParamAccessor = termFlag(28, "<paramaccessor>") + /** Symbol is implemented as a Java static */ + final val Static = commonFlag(29, "<static>") - /** A parameter with a default value */ - final val DefaultParam = termFlag(27, "<defaultparam>") + /** Variable is accessed from nested function. */ + final val Captured = termFlag(30, "<captured>") - /** A trait */ - final val Trait = typeFlag(27, "<trait>") + /** Symbol should be ignored when typechecking; will be marked ACC_SYNTHETIC in bytecode */ + final val Artifact = commonFlag(31, "<artifact>") /** A bridge method. Set by Erasure */ - final val Bridge = termFlag(28, "<bridge>") + final val Bridge = termFlag(32, "<bridge>") - /** Symbol is initialized to the default value, e.g. var x: T = _ */ - final val DefaultInit = termFlag(29, "<defaultinit>") + /** Symbol is a Java varargs bridge */ + final val VBridge = termFlag(33, "<vbridge>") - /** An error symbol */ - final val Erroneous = commonFlag(???, "<is-error>") + /** Symbol is a method which should be marked ACC_SYNCHRONIZED */ + final val Synchronized = termFlag(34, "<synchronized>") - /** Denotation is in train of being loaded and completed, flag to catch cyclic dependencies */ - final val CompletionStarted = commonFlag(???, "<locked>") + /** Symbol is a Java-style varargs method */ + final val JavaVarargs = termFlag(35, "<varargs>") - /** Variable is accessed from nested function. */ - final val Captured = termFlag(???, "<captured>") + // Flags following this one are not pickled - /** Class symbol is defined in this/superclass constructor. */ - final val Inconstructor = typeFlag(???, "<in-constructor>") + /** Denotation is in train of being loaded and completed, flag to catch cyclic dependencies */ + final val CompletionStarted = commonFlag(48, "<locked>") /** Class is not allowed to accept new members because fingerprint of subclass has been taken */ - final val Frozen = typeFlag(???, "<frozen>") + final val Frozen = typeFlag(49, "<frozen>") + + /** An error symbol */ + final val Erroneous = commonFlag(50, "<is-error>") /** Class has been lifted out to package level, local value has been lifted out to class level */ - final val Lifted = termFlag(???, "<lifted>") + final val Lifted = commonFlag(51, "<lifted>") /** Term member has been mixed in */ - final val MixedIn = termFlag(???, "<mixedin>") + final val MixedIn = commonFlag(52, "<mixedin>") /** Symbol is a generated specialized member */ - final val Specialized = commonFlag(???, "<specialized>") + final val Specialized = commonFlag(53, "<specialized>") - /** Symbol is a Java-style varargs method */ - final val JavaVarargs = termFlag(???, "<varargs>") - - /** Symbol is a Java varargs bridge */ - final val VBridge = termFlag(???, "<vbridge>") - - /** Symbol is a method which should be marked ACC_SYNCHRONIZED */ - final val Synchronized = termFlag(???, "<synchronized>") + /** Symbol is an implementation class */ + final val ImplClass = typeFlag(54, "<implclass>") - /** Symbol's name is expanded */ - final val ExpandedName = commonFlag(???, "<expandedname>") + /** An existentially bound symbol (Scala 2.x only) */ + final val Scala2Existential = typeFlag(55, "<existential>") - /** Symbol should be ignored when typechecking; will be marked ACC_SYNTHETIC in bytecode */ - final val Artifact = commonFlag(???, "<artifact>") + /** An overloaded symbol (Scala 2.x only) */ + final val Scala2Overloaded = termFlag(56, "<overloaded>") - /** Symbol is an implementation class */ - final val ImplClass = typeFlag(???, "<implclass>") + /** A module variable (Scala 2.x only) */ + final val Scala2ModuleVar = termFlag(57, "<modulevar>") - /** An existentially bound symbol (Scala 2.x only) */ - final val Scala2Existential = typeFlag(???, "<existential>") + /** A definition that's initialized before the super call (Scala 2.x only) */ + final val Scala2PreSuper = termFlag(58, "<presuper>") // --------- Combined Flag Sets and Conjunctions ---------------------- @@ -321,23 +341,12 @@ object Flags { /** Flags representing access rights */ final val AccessFlags = Private | Protected | Local - final val AbstractSealed = Abstract | Sealed - - final val SyntheticArtifact = Synthetic | Artifact - - final val RetainedModuleFlags: FlagSet = ??? - final val RetainedModuleClassFlags: FlagSet = ??? - - final val UninstantiatableFlags = Abstract | Final - - /** These flags are enabled from phase 1 */ - final val InitialFlags: FlagSet = ??? - - /** These flags are not pickled */ - final val FlagsNotPickled = commonFlags(Erroneous, Lifted, Frozen, CompletionStarted) + /** A value that's unstable unless complemented with a Stable flag */ + final val UnstableValue = Mutable | Method - /** These flags are pickled */ - final val PickledFlags = InitialFlags &~ FlagsNotPickled + /** Flags that are passed from a type parameter of a class to a refinement symbol + * that sets the type parameter */ + final val RetainedTypeArgFlags = Covariant | Contravariant | Protected | Local /** Modules always have these flags set */ final val ModuleCreationFlags = Module @@ -345,18 +354,34 @@ object Flags { /** Module classes always have these flags set */ final val ModuleClassCreationFlags = Module | Final + /** The flags of a type parameter */ + final val TypeParamCreationFlags = Protected | Local + + /** Flags that can apply to both a module val and a module class, except those that + * are added at creation anyway + */ + final val RetainedModuleValAndClassFlags: FlagSet = + AccessFlags | Package | PackageObject | Case | + Synthetic | ExpandedName | JavaDefined | Static | Artifact | + Erroneous | Lifted | MixedIn | Specialized + + /** Flags that can apply to a module val */ + final val RetainedModuleValFlags: FlagSet = RetainedModuleValAndClassFlags | + Override | Final | Method | Implicit | Lazy | + Accessor | AbsOverride | Stable | Captured | Synchronized + + /** Flags that can apply to a module class */ + final val RetainedModuleClassFlags: FlagSet = RetainedModuleValAndClassFlags | + InConstructor | ImplClass + /** Packages and package classes always have these flags set */ final val PackageCreationFlags = Module | Package | Final | JavaDefined | Static - /** A value that's unstable unless complemented with a Stable flag */ - final val UnstableValue = Mutable | Method - - /** Flags that are passed from a type parameter of a class to a refinement symbol - * that sets the type parameter */ - final val RetainedTypeArgFlags = Covariant | Contravariant | Protected | Local + /** These flags are pickled */ + final val PickledFlags = flagRange(FirstFlag, FirstNotPickledFlag) - /** An abstract class or trait */ - final val AbstractOrTrait = Trait | Abstract + /** An abstract class or a trait */ + final val AbstractOrTrait = Abstract | Trait /** Labeled `private` or `protected[local]` */ final val PrivateOrLocal = Private | Local @@ -364,9 +389,6 @@ object Flags { /** A type parameter with synthesized name */ final val ExpandedTypeParam = allOf(ExpandedName, TypeParam) - /** The flags of a type parameter */ - final val TypeParamFlags = Protected | Local - /** A Java interface */ final val JavaInterface = allOf(JavaDefined | Trait) @@ -379,6 +401,10 @@ object Flags { /** Java symbol which is `protected` and `static` */ final val StaticProtected = allOf(JavaDefined, Protected, Static) + final val AbstractFinal = allOf(Abstract, Final) + final val AbstractSealed = allOf(Abstract, Sealed) + final val SyntheticArtifact = allOf(Synthetic, Artifact) + implicit def conjToFlagSet(conj: FlagConjunction): FlagSet = FlagSet(conj.bits) }
\ No newline at end of file |