@@ -5,121 +5,132 @@ import language.implicitConversions
5
5
6
6
object Flags {
7
7
8
- /** A FlagSet represents a set of flags. Flags are encoded as follows:
9
- * The first two bits indicate whether a flagset applies to terms,
10
- * to types, or to both. Bits 2..63 are available for properties
11
- * and can be doubly used for terms and types.
12
- */
13
- case class FlagSet (val bits : Long ) extends AnyVal {
8
+ object opaques {
9
+
10
+ /** A FlagSet represents a set of flags. Flags are encoded as follows:
11
+ * The first two bits indicate whether a flagset applies to terms,
12
+ * to types, or to both. Bits 2..63 are available for properties
13
+ * and can be doubly used for terms and types.
14
+ */
15
+ opaque type FlagSet = Long
16
+ def FlagSet (bits : Long ): FlagSet = bits.asInstanceOf // !!!
17
+ def toBits (fs : FlagSet ): Long = fs
18
+ }
19
+ type FlagSet = opaques.FlagSet
20
+ def FlagSet (bits : Long ): FlagSet = opaques.FlagSet (bits)
21
+
22
+ implicit object FlagOps {
23
+
24
+ def (xs : FlagSet ) bits : Long = opaques.toBits(xs)
14
25
15
- /** The union of this flag set and the given flag set
26
+ /** The union of the given flag sets.
16
27
* Combining two FlagSets with `|` will give a FlagSet
17
28
* that has the intersection of the applicability to terms/types
18
29
* of the two flag sets. It is checked that the intersection is not empty.
19
30
*/
20
- def | (that : FlagSet ): FlagSet =
21
- if (bits == 0 ) that
22
- else if (that.bits == 0 ) this
31
+ def ( x : FlagSet ) | (that : FlagSet ): FlagSet =
32
+ if (x. bits == 0 ) that
33
+ else if (that.bits == 0 ) x
23
34
else {
24
- val tbits = bits & that.bits & KINDFLAGS
35
+ val tbits = x. bits & that.bits & KINDFLAGS
25
36
if (tbits == 0 )
26
- assert(false , s " illegal flagset combination: $this and $that" )
27
- FlagSet (tbits | ((this .bits | that.bits) & ~ KINDFLAGS ))
37
+ assert(false , s " illegal flagset combination: $x and $that" )
38
+ FlagSet (tbits | ((x .bits | that.bits) & ~ KINDFLAGS ))
28
39
}
29
40
30
- /** The intersection of this flag set and the given flag set */
31
- def & (that : FlagSet ): FlagSet = FlagSet (bits & that.bits)
41
+ /** The intersection of the given flag sets */
42
+ def ( x : FlagSet ) & (that : FlagSet ): FlagSet = FlagSet (x. bits & that.bits)
32
43
33
- /** The intersection of this flag set with the complement of the given flag set */
34
- def &~ (that : FlagSet ): FlagSet = {
35
- val tbits = bits & KINDFLAGS
36
- if ((tbits & that.bits) == 0 ) this
37
- else FlagSet (tbits | ((this .bits & ~ that.bits) & ~ KINDFLAGS ))
44
+ /** The intersection of a flag set with the complement of another flag set */
45
+ def ( x : FlagSet ) &~ (that : FlagSet ): FlagSet = {
46
+ val tbits = x. bits & KINDFLAGS
47
+ if ((tbits & that.bits) == 0 ) x
48
+ else FlagSet (tbits | ((x .bits & ~ that.bits) & ~ KINDFLAGS ))
38
49
}
39
50
40
- def ^ (that : FlagSet ) =
41
- FlagSet ((bits | that.bits) & KINDFLAGS | (bits ^ that.bits) & ~ KINDFLAGS )
51
+ def ( x : FlagSet ) ^ (that : FlagSet ) =
52
+ FlagSet ((x. bits | that.bits) & KINDFLAGS | (x. bits ^ that.bits) & ~ KINDFLAGS )
42
53
43
- /** Does this flag set have a non-empty intersection with the given flag set?
54
+ /** Does a given flag set have a non-empty intersection with another flag set?
44
55
* This means that both the kind flags and the carrier bits have non-empty intersection.
45
56
*/
46
- def is (flags : FlagSet ): Boolean = {
57
+ def ( x : FlagSet ) is(flags : FlagSet ): Boolean = {
47
58
assert(flags.numFlags == 1 )
48
- val fs = bits & flags.bits
59
+ val fs = x. bits & flags.bits
49
60
(fs & KINDFLAGS ) != 0 && (fs & ~ KINDFLAGS ) != 0
50
61
}
51
62
52
- /** Does this flag set have a non-empty intersection with the given flag set,
63
+ /** Does a given flag set have a non-empty intersection with another flag set,
53
64
* and at the same time contain none of the flags in the `butNot` set?
54
65
*/
55
- def is (flags : FlagSet , butNot : FlagSet ): Boolean = is(flags) && ! isOneOf(butNot)
66
+ def ( x : FlagSet ) is(flags : FlagSet , butNot : FlagSet ): Boolean = x. is(flags) && ! x. isOneOf(butNot)
56
67
57
- def isOneOf (flags : FlagSet ): Boolean = {
58
- val fs = bits & flags.bits
68
+ def ( x : FlagSet ) isOneOf(flags : FlagSet ): Boolean = {
69
+ val fs = x. bits & flags.bits
59
70
(fs & KINDFLAGS ) != 0 && (fs & ~ KINDFLAGS ) != 0
60
71
}
61
72
62
- def isOneOf (flags : FlagSet , butNot : FlagSet ): Boolean = isOneOf(flags) && ! isOneOf(butNot)
73
+ def ( x : FlagSet ) isOneOf(flags : FlagSet , butNot : FlagSet ): Boolean = x. isOneOf(flags) && ! x. isOneOf(butNot)
63
74
64
- /** Does this flag set have all of the flags in given flag conjunction ?
65
- * Pre: The intersection of the typeflags of both sets must be non-empty.
75
+ /** Does a given flag set have all of the flags of another flag set ?
76
+ * Pre: The intersection of the term/type flags of both sets must be non-empty.
66
77
*/
67
- def isAllOf (flags : FlagSet ): Boolean = {
68
- val fs = bits & flags.bits
78
+ def ( x : FlagSet ) isAllOf(flags : FlagSet ): Boolean = {
79
+ val fs = x. bits & flags.bits
69
80
((fs & KINDFLAGS ) != 0 || flags.bits == 0 ) &&
70
81
(fs >>> TYPESHIFT ) == (flags.bits >>> TYPESHIFT )
71
82
}
72
83
73
- /** Does this flag set have all of the flags in given flag conjunction?
84
+ /** Does a given flag set have all of the flags in another flag set
74
85
* and at the same time contain none of the flags in the `butNot` set?
75
- * Pre: The intersection of the typeflags of both sets must be non-empty.
86
+ * Pre: The intersection of the term/type flags of both sets must be non-empty.
76
87
*/
77
- def isAllOf (flags : FlagSet , butNot : FlagSet ): Boolean = isAllOf(flags) && ! isOneOf(butNot)
88
+ def ( x : FlagSet ) isAllOf(flags : FlagSet , butNot : FlagSet ): Boolean = x. isAllOf(flags) && ! x. isOneOf(butNot)
78
89
79
- def isEmpty : Boolean = (bits & ~ KINDFLAGS ) == 0
90
+ def ( x : FlagSet ) isEmpty : Boolean = (x. bits & ~ KINDFLAGS ) == 0
80
91
81
- /** Is this flag set a subset of that one ? */
82
- def <= (that : FlagSet ): Boolean = (bits & that.bits) == bits
92
+ /** Is a given flag set a subset of another flag set ? */
93
+ def ( x : FlagSet ) <= (that : FlagSet ): Boolean = (x. bits & that.bits) == x. bits
83
94
84
- /** Does this flag set apply to terms? */
85
- def isTermFlags : Boolean = (bits & TERMS ) != 0
95
+ /** Does the given flag set apply to terms? */
96
+ def ( x : FlagSet ) isTermFlags : Boolean = (x. bits & TERMS ) != 0
86
97
87
- /** Does this flag set apply to terms? */
88
- def isTypeFlags : Boolean = (bits & TYPES ) != 0
98
+ /** Does the given flag set apply to terms? */
99
+ def ( x : FlagSet ) isTypeFlags : Boolean = (x. bits & TYPES ) != 0
89
100
90
- /** This flag set with all flags transposed to be type flags */
91
- def toTypeFlags : FlagSet = if (bits == 0 ) this else FlagSet (bits & ~ KINDFLAGS | TYPES )
101
+ /** The given flag set with all flags transposed to be type flags */
102
+ def ( x : FlagSet ) toTypeFlags : FlagSet = if (x. bits == 0 ) x else FlagSet (x. bits & ~ KINDFLAGS | TYPES )
92
103
93
- /** This flag set with all flags transposed to be term flags */
94
- def toTermFlags : FlagSet = if (bits == 0 ) this else FlagSet (bits & ~ KINDFLAGS | TERMS )
104
+ /** The given flag set with all flags transposed to be term flags */
105
+ def ( x : FlagSet ) toTermFlags : FlagSet = if (x. bits == 0 ) x else FlagSet (x. bits & ~ KINDFLAGS | TERMS )
95
106
96
- /** This flag set with all flags transposed to be common flags */
97
- def toCommonFlags : FlagSet = if (bits == 0 ) this else FlagSet (bits | KINDFLAGS )
107
+ /** The given flag set with all flags transposed to be common flags */
108
+ def ( x : FlagSet ) toCommonFlags : FlagSet = if (x. bits == 0 ) x else FlagSet (x. bits | KINDFLAGS )
98
109
99
- /** The number of non-kind flags in this set */
100
- def numFlags : Int = java.lang.Long .bitCount(bits & ~ KINDFLAGS )
110
+ /** The number of non-kind flags in the given flag set */
111
+ def ( x : FlagSet ) numFlags : Int = java.lang.Long .bitCount(x. bits & ~ KINDFLAGS )
101
112
102
- /** The lowest non-kind bit set in this flagset */
103
- def firstBit : Int = java.lang.Long .numberOfTrailingZeros(bits & ~ KINDFLAGS )
113
+ /** The lowest non-kind bit set in the given flag set */
114
+ def ( x : FlagSet ) firstBit : Int = java.lang.Long .numberOfTrailingZeros(x. bits & ~ KINDFLAGS )
104
115
105
- /** The list of non-empty names of flags with given index idx that are set in this FlagSet */
106
- private def flagString (idx : Int ): List [String ] =
107
- if ((bits & (1L << idx)) == 0 ) Nil
116
+ /** The list of non-empty names of flags with given index idx that are set in the given flag set */
117
+ private def ( x : FlagSet ) flagString(idx : Int ): List [String ] =
118
+ if ((x. bits & (1L << idx)) == 0 ) Nil
108
119
else {
109
120
def halfString (kind : Int ) =
110
- if ((bits & (1L << kind)) != 0 ) flagName(idx)(kind) else " "
121
+ if ((x. bits & (1L << kind)) != 0 ) flagName(idx)(kind) else " "
111
122
val termFS = halfString(TERMindex )
112
123
val typeFS = halfString(TYPEindex )
113
124
val strs = termFS :: (if (termFS == typeFS) Nil else typeFS :: Nil )
114
125
strs filter (_.nonEmpty)
115
126
}
116
127
117
- /** The list of non-empty names of flags that are set in this FlagSet */
118
- def flagStrings (privateWithin : String ): Seq [String ] = {
119
- var rawStrings = (2 to MaxFlag ).flatMap(flagString)
120
- if (! privateWithin.isEmpty && ! this .is(Protected ))
128
+ /** The list of non-empty names of flags that are set in teh given flag set */
129
+ def ( x : FlagSet ) flagStrings(privateWithin : String ): Seq [String ] = {
130
+ var rawStrings = (2 to MaxFlag ).flatMap(x. flagString(_)) // !!!
131
+ if (! privateWithin.isEmpty && ! x .is(Protected ))
121
132
rawStrings = rawStrings :+ " private"
122
- val scopeStr = if (this .is(Local )) " this" else privateWithin
133
+ val scopeStr = if (x .is(Local )) " this" else privateWithin
123
134
if (scopeStr != " " )
124
135
rawStrings.filter(_ != " <local>" ).map {
125
136
case " private" => s " private[ $scopeStr] "
@@ -129,8 +140,8 @@ object Flags {
129
140
else rawStrings
130
141
}
131
142
132
- /** The string representation of this flag set */
133
- def flagsString : String = flagStrings(" " ).mkString(" " )
143
+ /** The string representation of the given flag set */
144
+ def ( x : FlagSet ) flagsString : String = x. flagStrings(" " ).mkString(" " )
134
145
}
135
146
136
147
def termFlagSet (x : Long ) = FlagSet (TERMS | x)
@@ -148,7 +159,7 @@ object Flags {
148
159
149
160
private val flagName = Array .fill(64 , 2 )(" " )
150
161
151
- private def isDefinedAsFlag (idx : Int ) = flagName(idx) exists (_.nonEmpty)
162
+ private def isDefinedAsFlag (idx : Int ) = flagName(idx). exists(_.nonEmpty)
152
163
153
164
/** The flag set containing all defined flags of either kind whose bits
154
165
* lie in the given range
@@ -565,11 +576,11 @@ object Flags {
565
576
/** An inline method or inline argument proxy */
566
577
final val InlineOrProxy : FlagSet = Inline | InlineProxy
567
578
568
- final val ImplicitOrImplied = Implicit | Implied
569
- final val ImplicitOrImpliedOrGiven = Implicit | Implied | Given
570
- final val ImplicitOrGiven = Implicit | Given
579
+ final val ImplicitOrImplied : FlagSet = Implicit | Implied
580
+ final val ImplicitOrImpliedOrGiven : FlagSet = Implicit | Implied | Given
581
+ final val ImplicitOrGiven : FlagSet = Implicit | Given
571
582
572
- final val ImpliedOrGiven = Implied | Given
583
+ final val ImpliedOrGiven : FlagSet = Implied | Given
573
584
574
585
final val ImplicitOrImpliedOrGivenTerm = ImplicitOrImpliedOrGiven .toTermFlags
575
586
@@ -598,7 +609,7 @@ object Flags {
598
609
final val InlineParam : FlagSet = Inline | Param
599
610
600
611
/** An extension method */
601
- final val ExtensionMethod = Extension | Method
612
+ final val ExtensionMethod : FlagSet = Extension | Method
602
613
603
614
/** An implied method */
604
615
final val SyntheticImpliedMethod : FlagSet = Synthetic | Implied | Method
0 commit comments