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