blob: 43b45ace23bdb564e883b7036a34c911f6a2b1a9 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
|
/* NSC -- new Scala compiler
* Copyright 2005-2007 LAMP/EPFL
* @author Martin Odersky
*/
// $Id$
package scala.tools.nsc.symtab
object Flags extends Enumeration {
// modifiers
final val IMPLICIT = 0x00000001
final val FINAL = 0x00000002
final val PRIVATE = 0x00000004
final val PROTECTED = 0x00000008
final val SEALED = 0x00000010
final val OVERRIDE = 0x00000020
final val CASE = 0x00000040
final val ABSTRACT = 0x00000080 // abstract class, or used in conjunction
// with abstract override.
// Note difference to DEFERRED!
final val DEFERRED = 0x00000100 // was `abstract' for members
final val METHOD = 0x00000200 // a method
final val MODULE = 0x00000400 // symbol is module or class implementing a module
final val INTERFACE = 0x00000800 // symbol is an interface
final val MUTABLE = 0x00001000 // symbol is a mutable variable.
final val PARAM = 0x00002000 // symbol is a (value or type) parameter to a method
final val PACKAGE = 0x00004000 // symbol is a java package
final val DEPRECATED = 0x00008000 // symbol is deprecated.
final val COVARIANT = 0x00010000 // symbol is a covariant type variable
final val CAPTURED = 0x00010000 // variable is accessed from nested function.
// Set by LambdaLift
final val BYNAMEPARAM = 0x00010000 // parameter is by name
final val CONTRAVARIANT = 0x00020000 // symbol is a contravariant type variable
final val LABEL = 0x00020000 // method symbol is a label. Set by TailCall
final val INCONSTRUCTOR = 0x00020000 // class symbol is defined in this/superclass
// constructor.
final val ABSOVERRIDE = 0x00040000 // combination of abstract & override
final val LOCAL = 0x00080000 // symbol is local to current class.
// pre: PRIVATE is also set
final val JAVA = 0x00100000 // symbol was defined by a Java class
final val SYNTHETIC = 0x00200000 // symbol is compiler-generated
final val STABLE = 0x00400000 // functions that are assumed to be stable
// (typically, access methods for valdefs)
final val STATIC = 0x00800000 // static field, method or class
final val CASEACCESSOR = 0x01000000 // symbol is a case parameter (or its accessor)
final val TRAIT = 0x02000000 // symbol is a trait
final val BRIDGE = 0x04000000 // function is a bridge method. Set by Erasure
final val ACCESSOR = 0x08000000 // a value or variable accessor
final val SUPERACCESSOR = 0x10000000 // a super accessor
final val PARAMACCESSOR = 0x20000000 // for value definitions: is an access method
// for a final val parameter
// for parameters: is a val parameter
final val MODULEVAR = 0x40000000
final val IS_ERROR = 0x100000000L // symbol is an error symbol
final val OVERLOADED = 0x200000000L // symbol is overloaded
final val LIFTED = 0x400000000L // class has been lifted out to package level
// local value has been lifted out to class level
// todo: make LIFTED = latePRIVATE?
final val MIXEDIN = 0x800000000L // member has been mixed in
final val EXPANDEDNAME = 0x1000000000L // name has been expanded with class suffix
final val IMPLCLASS = 0x2000000000L // symbol is an implementation class
final val PRESUPER = 0x2000000000L // value is evaluated before super call
final val TRANS_FLAG = 0x4000000000L // transient flag guaranteed to be reset
// after each phase.
final val LOCKED = 0x8000000000L // temporary flag to catch cyclic dependencies
final val InitialFlags = 0x000000FFFFFFFFFFL // flags that are enabled from phase 1.
final val LateFlags = 0x000FFF0000000000L // flags that override flags in 0xFFF.
final val AntiFlags = 0x7FF0000000000000L // flags that cancel flags in 0x7FF
final val LateShift = 40L
final val AntiShift = 52L
// late flags (set by a transformer phase)
final val latePRIVATE = (PRIVATE: long) << LateShift
final val lateDEFERRED = (DEFERRED: long) << LateShift
final val lateINTERFACE = (INTERFACE: long) << LateShift
final val lateMODULE = (MODULE: long) << LateShift
final val lateFINAL = (FINAL: long) << LateShift
final val lateMETHOD = (METHOD: long) << LateShift
final val notPRIVATE = (PRIVATE: long) << AntiShift
final val notDEFERRED = (DEFERRED: long) << AntiShift
final val notPROTECTED = (PROTECTED: long) << AntiShift
final val notABSTRACT = (ABSTRACT: long) << AntiShift
final val notOVERRIDE = (OVERRIDE: long) << AntiShift
final val notMETHOD = (METHOD: long) << AntiShift
final val STATICMODULE = lateMODULE
final val STATICMEMBER = notOVERRIDE
// masks
/** This flags can be set when class or module symbol is first created. */
final val TopLevelCreationFlags =
MODULE | PACKAGE | FINAL | JAVA
/** These modifiers can be set explicitly in source programs. */
final val ExplicitFlags =
PRIVATE | PROTECTED | ABSTRACT | FINAL | SEALED |
OVERRIDE | CASE | IMPLICIT | ABSOVERRIDE
/** These modifiers appear in TreePrinter output. */
final val PrintableFlags =
ExplicitFlags | LOCAL | SYNTHETIC | STABLE | CASEACCESSOR |
ACCESSOR | SUPERACCESSOR | PARAMACCESSOR | BRIDGE | STATIC
final val FieldFlags =
MUTABLE | CASEACCESSOR | PARAMACCESSOR | STATIC | FINAL | PRESUPER
final val AccessFlags = PRIVATE | PROTECTED
final val VARIANCES = COVARIANT | CONTRAVARIANT
final val ConstrFlags = JAVA
final val PickledFlags = 0xFFFFFFFF
/** Module flags inherited by their module-class */
final val ModuleToClassFlags = AccessFlags | PACKAGE | CASE
private def listToString(ss: List[String]): String =
ss.filter("" !=).mkString("", " ", "")
def flagsToString(flags: long): String =
listToString(for (i <- List.range(0, 63)) yield flagToString(flags & (1L << i)))
def flagsToString(flags: long, privateWithin: String): String = {
var f = flags
val pw =
if (privateWithin == "") {
if ((flags & (PRIVATE | LOCAL)) == (PRIVATE | LOCAL)) {
f = f & ~(PRIVATE | LOCAL)
"private[this]"
} else if ((flags & (PROTECTED | LOCAL)) == (PROTECTED | LOCAL)) {
f = f & ~(PROTECTED | LOCAL)
"protected[this]"
} else {
""
}
} else if ((f & PROTECTED) != 0) {
f = f & ~PROTECTED
"protected[" + privateWithin + "]"
} else {
"private[" + privateWithin + "]"
}
listToString(List(flagsToString(f), pw))
}
private def flagToString(flag: long): String = {
if (flag == IS_ERROR) "<is-error>"
else if (flag == OVERLOADED ) "<overloaded>"
else if (flag == LIFTED ) "<lifted>"
else if (flag == MIXEDIN ) "<mixedin>"
else if (flag == EXPANDEDNAME) "<expandedname>"
else if (flag == IMPLCLASS ) "<implclass/presuper>"
else if (flag == TRANS_FLAG ) "<trans-flag>"
else if (flag == LOCKED ) "<locked>"
else flag.asInstanceOf[int] match {
case IMPLICIT => "implicit"
case FINAL => "final"
case PRIVATE => "private"
case PROTECTED => "protected"
case SEALED => "sealed"
case OVERRIDE => "override"
case CASE => "case"
case ABSTRACT => "abstract"
case DEFERRED => "<deferred>"
case METHOD => "<method>"
case MODULE => "<module>"
case INTERFACE => "<interface>"
case MUTABLE => "<mutable>"
case PARAM => "<param>"
case PACKAGE => "<package>"
case DEPRECATED => "<deprecated>"
case COVARIANT => "<covariant/captured/byname>"
case CONTRAVARIANT => "<contravariant/label/inconstr>"
case ABSOVERRIDE => "abstract override"
case LOCAL => "<local>"
case JAVA => "<java>"
case SYNTHETIC => "<synthetic>"
case STABLE => "<stable>"
case STATIC => "<static>"
case CASEACCESSOR => "<caseaccessor>"
case TRAIT => "<trait>"
case BRIDGE => "<bridge>"
case ACCESSOR => "<accessor>"
case SUPERACCESSOR => "<superaccessor>"
case PARAMACCESSOR => "<paramaccessor>"
case _ => ""
}
}
class Flag(mods: int) {
def isPrivate = (mods & PRIVATE ) != 0
def isProtected = (mods & PROTECTED) != 0
def isVariable = (mods & MUTABLE) != 0
def isPublic = !isPrivate && !isProtected
}
case class FlagEnum(mask : Int) extends Val(maskToBit(mask), flagToString(mask));
val Implicit = FlagEnum(IMPLICIT)
val Final = FlagEnum(FINAL)
val Private = FlagEnum(PRIVATE)
val Protected= FlagEnum(PROTECTED)
val Sealed = FlagEnum(SEALED)
val Override = FlagEnum(OVERRIDE)
val Case = FlagEnum(CASE)
val Abstract = FlagEnum(ABSTRACT)
val Deferred = FlagEnum(DEFERRED)
val Method = FlagEnum(METHOD)
val Module = FlagEnum(MODULE)
val Interface= FlagEnum(INTERFACE)
val Mutable = FlagEnum(MUTABLE)
val Param = FlagEnum(PARAM)
val Package = FlagEnum(PACKAGE)
val Deprecated=FlagEnum(DEPRECATED)
val Covariant=FlagEnum(COVARIANT)
val Contravariant=FlagEnum(CONTRAVARIANT)
val AbsOverride=FlagEnum(ABSOVERRIDE)
val Local=FlagEnum(LOCAL)
val Synthetic=FlagEnum(SYNTHETIC)
val Stable=FlagEnum(STABLE)
val CaseAccessor=FlagEnum(CASEACCESSOR)
val Trait=FlagEnum(TRAIT)
val Bridge=FlagEnum(BRIDGE)
val Accessor=FlagEnum(ACCESSOR)
val SuperAccessor=FlagEnum(SUPERACCESSOR)
val ParamAccessor=FlagEnum(PARAMACCESSOR)
val ModuleVar=FlagEnum(MODULEVAR)
}
|