1 /**
2 * Defines enums common to dmd and dmd as parse library.
3 *
4 * Copyright: Copyright (C) 1999-2022 by The D Language Foundation, All Rights Reserved
5 * License: $(LINK2 https://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
6 * Source: $(LINK2 https://github.com/dlang/dmd/blob/master/src/dmd/astenums.d, _astenums.d)
7 * Documentation: https://dlang.org/phobos/dmd_astenums.html
8 * Coverage: https://codecov.io/gh/dlang/dmd/src/master/src/dmd/astenums.d
9 */
10
11 module dmd.astenums;
12
13 enum Sizeok : ubyte
14 {
15 none, /// size of aggregate is not yet able to compute
16 fwd, /// size of aggregate is ready to compute
17 inProcess, /// in the midst of computing the size
18 done, /// size of aggregate is set correctly
19 }
20
21 enum Baseok : ubyte
22 {
23 none, /// base classes not computed yet
24 start, /// in process of resolving base classes
25 done, /// all base classes are resolved
26 semanticdone, /// all base classes semantic done
27 }
28
29 enum MODFlags : int
30 {
31 none = 0, // default (mutable)
32 const_ = 1, // type is const
33 immutable_ = 4, // type is immutable
34 shared_ = 2, // type is shared
35 wild = 8, // type is wild
36 wildconst = (MODFlags.wild | MODFlags.const_), // type is wild const
37 mutable = 0x10, // type is mutable (only used in wildcard matching)
38 }
39
40 alias MOD = ubyte;
41
42 enum STC : ulong // transfer changes to declaration.h
43 {
44 undefined_ = 0,
45
46 static_ = 1, /// `static`
47 extern_ = 2, /// `extern`
48 const_ = 4, /// `const`
49 final_ = 8, /// `final`
50
51 abstract_ = 0x10, /// `abstract`
52 parameter = 0x20, /// is function parameter
53 field = 0x40, /// is field of struct, union or class
54 override_ = 0x80, /// `override`
55
56 auto_ = 0x100, /// `auto`
57 synchronized_ = 0x200, /// `synchronized`
58 deprecated_ = 0x400, /// `deprecated`
59 in_ = 0x800, /// `in` parameter
60
61 out_ = 0x1000, /// `out` parameter
62 lazy_ = 0x2000, /// `lazy` parameter
63 foreach_ = 0x4000, /// variable for foreach loop
64 variadic = 0x8000, /// the `variadic` parameter in: T foo(T a, U b, V variadic...)
65
66 // = 0x1_0000,
67 templateparameter = 0x2_0000, /// template parameter
68 ref_ = 0x4_0000, /// `ref`
69 scope_ = 0x8_0000, /// `scope`
70
71 maybescope = 0x10_0000, /// parameter might be `scope`
72 scopeinferred = 0x20_0000, /// `scope` has been inferred and should not be part of mangling, `scope_` must also be set
73 return_ = 0x40_0000, /// 'return ref' or 'return scope' for function parameters
74 returnScope = 0x80_0000, /// if `ref return scope` then resolve to `ref` and `return scope`
75
76 returninferred = 0x100_0000, /// `return` has been inferred and should not be part of mangling, `return_` must also be set
77 immutable_ = 0x200_0000, /// `immutable`
78 // = 0x400_0000,
79 manifest = 0x800_0000, /// manifest constant
80
81 nodtor = 0x1000_0000, /// do not run destructor
82 nothrow_ = 0x2000_0000, /// `nothrow` meaning never throws exceptions
83 pure_ = 0x4000_0000, /// `pure` function
84 tls = 0x8000_0000, /// thread local
85
86 alias_ = 0x1_0000_0000, /// `alias` parameter
87 shared_ = 0x2_0000_0000, /// accessible from multiple threads
88 gshared = 0x4_0000_0000, /// accessible from multiple threads, but not typed as `shared`
89 wild = 0x8_0000_0000, /// for wild type constructor
90
91 property = 0x10_0000_0000, /// `@property`
92 safe = 0x20_0000_0000, /// `@safe`
93 trusted = 0x40_0000_0000, /// `@trusted`
94 system = 0x80_0000_0000, /// `@system`
95
96 ctfe = 0x100_0000_0000, /// can be used in CTFE, even if it is static
97 disable = 0x200_0000_0000, /// for functions that are not callable
98 result = 0x400_0000_0000, /// for result variables passed to out contracts
99 nodefaultctor = 0x800_0000_0000, /// must be set inside constructor
100
101 temp = 0x1000_0000_0000, /// temporary variable
102 rvalue = 0x2000_0000_0000, /// force rvalue for variables
103 nogc = 0x4000_0000_0000, /// `@nogc`
104 autoref = 0x8000_0000_0000, /// Mark for the already deduced `auto ref` parameter
105
106 inference = 0x1_0000_0000_0000, /// do attribute inference
107 exptemp = 0x2_0000_0000_0000, /// temporary variable that has lifetime restricted to an expression
108 future = 0x4_0000_0000_0000, /// introducing new base class function
109 local = 0x8_0000_0000_0000, /// do not forward (see dmd.dsymbol.ForwardingScopeDsymbol).
110
111 live = 0x10_0000_0000_0000, /// function `@live` attribute
112 register = 0x20_0000_0000_0000, /// `register` storage class (ImportC)
113 volatile_ = 0x40_0000_0000_0000, /// destined for volatile in the back end
114
115 safeGroup = STC.safe | STC.trusted | STC.system,
116 IOR = STC.in_ | STC.ref_ | STC.out_,
117 TYPECTOR = (STC.const_ | STC.immutable_ | STC.shared_ | STC.wild),
118 FUNCATTR = (STC.ref_ | STC.nothrow_ | STC.nogc | STC.pure_ | STC.property | STC.live |
119 safeGroup),
120
121 /* These are visible to the user, i.e. are expressed by the user
122 */
123 visibleStorageClasses =
124 (STC.auto_ | STC.scope_ | STC.static_ | STC.extern_ | STC.const_ | STC.final_ | STC.abstract_ | STC.synchronized_ |
125 STC.deprecated_ | STC.future | STC.override_ | STC.lazy_ | STC.alias_ | STC.out_ | STC.in_ | STC.manifest |
126 STC.immutable_ | STC.shared_ | STC.wild | STC.nothrow_ | STC.nogc | STC.pure_ | STC.ref_ | STC.return_ | STC.tls | STC.gshared |
127 STC.property | STC.safeGroup | STC.disable | STC.local | STC.live),
128
129 /* These storage classes "flow through" to the inner scope of a Dsymbol
130 */
131 flowThruAggregate = STC.safeGroup, /// for an AggregateDeclaration
132 flowThruFunction = ~(STC.auto_ | STC.scope_ | STC.static_ | STC.extern_ | STC.abstract_ | STC.deprecated_ | STC.override_ |
133 STC.TYPECTOR | STC.final_ | STC.tls | STC.gshared | STC.ref_ | STC.return_ | STC.property |
134 STC.nothrow_ | STC.pure_ | STC.safe | STC.trusted | STC.system), /// for a FuncDeclaration
135
136 }
137
138 alias StorageClass = ulong;
139
140 /********
141 * Determine if it's the ambigous case of where `return` attaches to.
142 * Params:
143 * stc = STC flags
144 * Returns:
145 * true if (`ref` | `out`) and `scope` and `return`
146 */
147 @safe pure @nogc nothrow
isRefReturnScope(const ulong stc)148 bool isRefReturnScope(const ulong stc)
149 {
150 return (stc & (STC.scope_ | STC.return_)) == (STC.scope_ | STC.return_) &&
151 stc & (STC.ref_ | STC.out_);
152 }
153
154 /* This is different from the one in declaration.d, make that fix a separate PR */
155 static if (0)
156 extern (C++) __gshared const(StorageClass) STCStorageClass =
157 (STC.auto_ | STC.scope_ | STC.static_ | STC.extern_ | STC.const_ | STC.final_ |
158 STC.abstract_ | STC.synchronized_ | STC.deprecated_ | STC.override_ | STC.lazy_ |
159 STC.alias_ | STC.out_ | STC.in_ | STC.manifest | STC.immutable_ | STC.shared_ |
160 STC.wild | STC.nothrow_ | STC.nogc | STC.pure_ | STC.ref_ | STC.return_ | STC.tls |
161 STC.gshared | STC.property | STC.live |
162 STC.safeGroup | STC.disable);
163
164 enum TY : ubyte
165 {
166 Tarray, // slice array, aka T[]
167 Tsarray, // static array, aka T[dimension]
168 Taarray, // associative array, aka T[type]
169 Tpointer,
170 Treference,
171 Tfunction,
172 Tident,
173 Tclass,
174 Tstruct,
175 Tenum,
176
177 Tdelegate,
178 Tnone,
179 Tvoid,
180 Tint8,
181 Tuns8,
182 Tint16,
183 Tuns16,
184 Tint32,
185 Tuns32,
186 Tint64,
187
188 Tuns64,
189 Tfloat32,
190 Tfloat64,
191 Tfloat80,
192 Timaginary32,
193 Timaginary64,
194 Timaginary80,
195 Tcomplex32,
196 Tcomplex64,
197 Tcomplex80,
198
199 Tbool,
200 Tchar,
201 Twchar,
202 Tdchar,
203 Terror,
204 Tinstance,
205 Ttypeof,
206 Ttuple,
207 Tslice,
208 Treturn,
209
210 Tnull,
211 Tvector,
212 Tint128,
213 Tuns128,
214 Ttraits,
215 Tmixin,
216 Tnoreturn,
217 Ttag,
218 TMAX
219 }
220
221 alias Tarray = TY.Tarray;
222 alias Tsarray = TY.Tsarray;
223 alias Taarray = TY.Taarray;
224 alias Tpointer = TY.Tpointer;
225 alias Treference = TY.Treference;
226 alias Tfunction = TY.Tfunction;
227 alias Tident = TY.Tident;
228 alias Tclass = TY.Tclass;
229 alias Tstruct = TY.Tstruct;
230 alias Tenum = TY.Tenum;
231 alias Tdelegate = TY.Tdelegate;
232 alias Tnone = TY.Tnone;
233 alias Tvoid = TY.Tvoid;
234 alias Tint8 = TY.Tint8;
235 alias Tuns8 = TY.Tuns8;
236 alias Tint16 = TY.Tint16;
237 alias Tuns16 = TY.Tuns16;
238 alias Tint32 = TY.Tint32;
239 alias Tuns32 = TY.Tuns32;
240 alias Tint64 = TY.Tint64;
241 alias Tuns64 = TY.Tuns64;
242 alias Tfloat32 = TY.Tfloat32;
243 alias Tfloat64 = TY.Tfloat64;
244 alias Tfloat80 = TY.Tfloat80;
245 alias Timaginary32 = TY.Timaginary32;
246 alias Timaginary64 = TY.Timaginary64;
247 alias Timaginary80 = TY.Timaginary80;
248 alias Tcomplex32 = TY.Tcomplex32;
249 alias Tcomplex64 = TY.Tcomplex64;
250 alias Tcomplex80 = TY.Tcomplex80;
251 alias Tbool = TY.Tbool;
252 alias Tchar = TY.Tchar;
253 alias Twchar = TY.Twchar;
254 alias Tdchar = TY.Tdchar;
255 alias Terror = TY.Terror;
256 alias Tinstance = TY.Tinstance;
257 alias Ttypeof = TY.Ttypeof;
258 alias Ttuple = TY.Ttuple;
259 alias Tslice = TY.Tslice;
260 alias Treturn = TY.Treturn;
261 alias Tnull = TY.Tnull;
262 alias Tvector = TY.Tvector;
263 alias Tint128 = TY.Tint128;
264 alias Tuns128 = TY.Tuns128;
265 alias Ttraits = TY.Ttraits;
266 alias Tmixin = TY.Tmixin;
267 alias Tnoreturn = TY.Tnoreturn;
268 alias Ttag = TY.Ttag;
269 alias TMAX = TY.TMAX;
270
271 enum TFlags
272 {
273 integral = 1,
274 floating = 2,
275 unsigned = 4,
276 real_ = 8,
277 imaginary = 0x10,
278 complex = 0x20,
279 }
280
281 enum PKG : int
282 {
283 unknown, /// not yet determined whether it's a package.d or not
284 module_, /// already determined that's an actual package.d
285 package_, /// already determined that's an actual package
286 }
287
288 enum ThreeState : ubyte
289 {
290 none, /// state is not yet computed
291 no, /// state is false
292 yes, /// state is true
293 }
294
295 enum TRUST : ubyte
296 {
297 default_ = 0,
298 system = 1, // @system (same as TRUST.default)
299 trusted = 2, // @trusted
300 safe = 3, // @safe
301 }
302
303 enum PURE : ubyte
304 {
305 impure = 0, // not pure at all
306 fwdref = 1, // it's pure, but not known which level yet
307 weak = 2, // no mutable globals are read or written
308 const_ = 3, // parameters are values or const = strongly pure
309 }
310
311 // Whether alias this dependency is recursive or not
312 enum AliasThisRec : int
313 {
314 no = 0, // no alias this recursion
315 yes = 1, // alias this has recursive dependency
316 fwdref = 2, // not yet known
317 typeMask = 3, // mask to read no/yes/fwdref
318 tracing = 0x4, // mark in progress of implicitConvTo/deduceWild
319 tracingDT = 0x8, // mark in progress of deduceType
320 }
321
322 /***************
323 * Variadic argument lists
324 * https://dlang.org/spec/function.html#variadic
325 */
326 enum VarArg : ubyte
327 {
328 none = 0, /// fixed number of arguments
329 variadic = 1, /// (T t, ...) can be C-style (core.stdc.stdarg) or D-style (core.vararg)
330 typesafe = 2, /// (T t ...) typesafe https://dlang.org/spec/function.html#typesafe_variadic_functions
331 /// or https://dlang.org/spec/function.html#typesafe_variadic_functions
332 }
333
334 /*************************
335 * Identify Statement types with this enum rather than
336 * virtual functions
337 */
338 enum STMT : ubyte
339 {
340 Error,
341 Peel,
342 Exp, DtorExp,
343 Compile,
344 Compound, CompoundDeclaration, CompoundAsm,
345 UnrolledLoop,
346 Scope,
347 Forwarding,
348 While,
349 Do,
350 For,
351 Foreach,
352 ForeachRange,
353 If,
354 Conditional,
355 StaticForeach,
356 Pragma,
357 StaticAssert,
358 Switch,
359 Case,
360 CaseRange,
361 Default,
362 GotoDefault,
363 GotoCase,
364 SwitchError,
365 Return,
366 Break,
367 Continue,
368 Synchronized,
369 With,
370 TryCatch,
371 TryFinally,
372 ScopeGuard,
373 Throw,
374 Debug,
375 Goto,
376 Label,
377 Asm, InlineAsm, GccAsm,
378 Import,
379 }
380
381 /**********************
382 * Discriminant for which kind of initializer
383 */
384 enum InitKind : ubyte
385 {
386 void_,
387 error,
388 struct_,
389 array,
390 exp,
391 C_,
392 }
393
394 /// A linkage attribute as defined by `extern(XXX)`
395 ///
396 /// https://dlang.org/spec/attribute.html#linkage
397 enum LINK : ubyte
398 {
399 default_,
400 d,
401 c,
402 cpp,
403 windows,
404 objc,
405 system,
406 }
407
408 /// Whether to mangle an external aggregate as a struct or class, as set by `extern(C++, struct)`
409 enum CPPMANGLE : ubyte
410 {
411 def, /// default
412 asStruct, /// `extern(C++, struct)`
413 asClass, /// `extern(C++, class)`
414 }
415
416 /// Function match levels
417 ///
418 /// https://dlang.org/spec/function.html#function-overloading
419 enum MATCH : int
420 {
421 nomatch, /// no match
422 convert, /// match with conversions
423 constant, /// match with conversion to const
424 exact, /// exact match
425 }
426
427 /// Inline setting as defined by `pragma(inline, XXX)`
428 enum PINLINE : ubyte
429 {
430 default_, /// as specified on the command line
431 never, /// never inline
432 always, /// always inline
433 }
434
435 /// Source file type
436 enum FileType : ubyte
437 {
438 d, /// normal D source file
439 dhdr, /// D header file (.di)
440 ddoc, /// Ddoc documentation file (.dd)
441 c, /// C source file
442 }
443