1 /**
2  * Defines enums common to dmd and dmd as parse library.
3  *
4  * Copyright:   Copyright (C) 1999-2021 by The D Language Foundation, All Rights Reserved
5  * License:     $(LINK2 http://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     const_       = 1,    // type is const
32     immutable_   = 4,    // type is immutable
33     shared_      = 2,    // type is shared
34     wild         = 8,    // type is wild
35     wildconst    = (MODFlags.wild | MODFlags.const_), // type is wild const
36     mutable      = 0x10, // type is mutable (only used in wildcard matching)
37 }
38 
39 alias MOD = ubyte;
40 
41 enum STC : ulong  // transfer changes to declaration.h
42 {
43     undefined_          = 0,
44 
45     static_             = 1,   /// `static`
46     extern_             = 2,   /// `extern`
47     const_              = 4,   /// `const`
48     final_              = 8,   /// `final`
49 
50     abstract_           = 0x10,   /// `abstract`
51     parameter           = 0x20,   /// is function parameter
52     field               = 0x40,   /// is field of struct, union or class
53     override_           = 0x80,   /// `override`
54 
55     auto_               = 0x100,   /// `auto`
56     synchronized_       = 0x200,   /// `synchronized`
57     deprecated_         = 0x400,   /// `deprecated`
58     in_                 = 0x800,   /// `in` parameter
59 
60     out_                = 0x1000,   /// `out` parameter
61     lazy_               = 0x2000,   /// `lazy` parameter
62     foreach_            = 0x4000,   /// variable for foreach loop
63     variadic            = 0x8000,   /// the `variadic` parameter in: T foo(T a, U b, V variadic...)
64 
65     ctorinit            = 0x1_0000,   /// can only be set inside constructor
66     templateparameter   = 0x2_0000,   /// template parameter
67     ref_                = 0x4_0000,   /// `ref`
68     scope_              = 0x8_0000,   /// `scope`
69 
70     maybescope          = 0x10_0000,   /// parameter might be `scope`
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     init                = 0x400_0000,   /// has explicit initializer
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 /********
138  * Determine if it's the ambigous case of where `return` attaches to.
139  * Params:
140  *   stc = STC flags
141  * Returns:
142  *   true if (`ref` | `out`) and `scope` and `return`
143  */
144 @safe pure @nogc nothrow
isRefReturnScope(const ulong stc)145 bool isRefReturnScope(const ulong stc)
146 {
147     return (stc & (STC.scope_ | STC.return_)) == (STC.scope_ | STC.return_) &&
148            stc & (STC.ref_ | STC.out_);
149 }
150 
151 /* This is different from the one in declaration.d, make that fix a separate PR */
152 static if (0)
153 extern (C++) __gshared const(StorageClass) STCStorageClass =
154     (STC.auto_ | STC.scope_ | STC.static_ | STC.extern_ | STC.const_ | STC.final_ |
155      STC.abstract_ | STC.synchronized_ | STC.deprecated_ | STC.override_ | STC.lazy_ |
156      STC.alias_ | STC.out_ | STC.in_ | STC.manifest | STC.immutable_ | STC.shared_ |
157      STC.wild | STC.nothrow_ | STC.nogc | STC.pure_ | STC.ref_ | STC.return_ | STC.tls |
158      STC.gshared | STC.property | STC.live |
159      STC.safeGroup | STC.disable);
160 
161 enum TY : ubyte
162 {
163     Tarray,     // slice array, aka T[]
164     Tsarray,    // static array, aka T[dimension]
165     Taarray,    // associative array, aka T[type]
166     Tpointer,
167     Treference,
168     Tfunction,
169     Tident,
170     Tclass,
171     Tstruct,
172     Tenum,
173 
174     Tdelegate,
175     Tnone,
176     Tvoid,
177     Tint8,
178     Tuns8,
179     Tint16,
180     Tuns16,
181     Tint32,
182     Tuns32,
183     Tint64,
184 
185     Tuns64,
186     Tfloat32,
187     Tfloat64,
188     Tfloat80,
189     Timaginary32,
190     Timaginary64,
191     Timaginary80,
192     Tcomplex32,
193     Tcomplex64,
194     Tcomplex80,
195 
196     Tbool,
197     Tchar,
198     Twchar,
199     Tdchar,
200     Terror,
201     Tinstance,
202     Ttypeof,
203     Ttuple,
204     Tslice,
205     Treturn,
206 
207     Tnull,
208     Tvector,
209     Tint128,
210     Tuns128,
211     Ttraits,
212     Tmixin,
213     Tnoreturn,
214     Ttag,
215     TMAX
216 }
217 
218 alias Tarray = TY.Tarray;
219 alias Tsarray = TY.Tsarray;
220 alias Taarray = TY.Taarray;
221 alias Tpointer = TY.Tpointer;
222 alias Treference = TY.Treference;
223 alias Tfunction = TY.Tfunction;
224 alias Tident = TY.Tident;
225 alias Tclass = TY.Tclass;
226 alias Tstruct = TY.Tstruct;
227 alias Tenum = TY.Tenum;
228 alias Tdelegate = TY.Tdelegate;
229 alias Tnone = TY.Tnone;
230 alias Tvoid = TY.Tvoid;
231 alias Tint8 = TY.Tint8;
232 alias Tuns8 = TY.Tuns8;
233 alias Tint16 = TY.Tint16;
234 alias Tuns16 = TY.Tuns16;
235 alias Tint32 = TY.Tint32;
236 alias Tuns32 = TY.Tuns32;
237 alias Tint64 = TY.Tint64;
238 alias Tuns64 = TY.Tuns64;
239 alias Tfloat32 = TY.Tfloat32;
240 alias Tfloat64 = TY.Tfloat64;
241 alias Tfloat80 = TY.Tfloat80;
242 alias Timaginary32 = TY.Timaginary32;
243 alias Timaginary64 = TY.Timaginary64;
244 alias Timaginary80 = TY.Timaginary80;
245 alias Tcomplex32 = TY.Tcomplex32;
246 alias Tcomplex64 = TY.Tcomplex64;
247 alias Tcomplex80 = TY.Tcomplex80;
248 alias Tbool = TY.Tbool;
249 alias Tchar = TY.Tchar;
250 alias Twchar = TY.Twchar;
251 alias Tdchar = TY.Tdchar;
252 alias Terror = TY.Terror;
253 alias Tinstance = TY.Tinstance;
254 alias Ttypeof = TY.Ttypeof;
255 alias Ttuple = TY.Ttuple;
256 alias Tslice = TY.Tslice;
257 alias Treturn = TY.Treturn;
258 alias Tnull = TY.Tnull;
259 alias Tvector = TY.Tvector;
260 alias Tint128 = TY.Tint128;
261 alias Tuns128 = TY.Tuns128;
262 alias Ttraits = TY.Ttraits;
263 alias Tmixin = TY.Tmixin;
264 alias Tnoreturn = TY.Tnoreturn;
265 alias Ttag = TY.Ttag;
266 alias TMAX = TY.TMAX;
267 
268 enum TFlags
269 {
270     integral     = 1,
271     floating     = 2,
272     unsigned     = 4,
273     real_        = 8,
274     imaginary    = 0x10,
275     complex      = 0x20,
276 }
277 
278 enum PKG : int
279 {
280     unknown,      /// not yet determined whether it's a package.d or not
281     module_,      /// already determined that's an actual package.d
282     package_,     /// already determined that's an actual package
283 }
284 
285 enum ThreeState : ubyte
286 {
287     none,  /// state is not yet computed
288     no,    /// state is false
289     yes,   /// state is true
290 }
291 
292 enum TRUST : ubyte
293 {
294     default_   = 0,
295     system     = 1,    // @system (same as TRUST.default)
296     trusted    = 2,    // @trusted
297     safe       = 3,    // @safe
298 }
299 
300 enum PURE : ubyte
301 {
302     impure      = 0,    // not pure at all
303     fwdref      = 1,    // it's pure, but not known which level yet
304     weak        = 2,    // no mutable globals are read or written
305     const_      = 3,    // parameters are values or const
306     strong      = 4,    // parameters are values or immutable
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 }
331 
332 /*************************
333  * Identify Statement types with this enum rather than
334  * virtual functions
335  */
336 enum STMT : ubyte
337 {
338     Error,
339     Peel,
340     Exp, DtorExp,
341     Compile,
342     Compound, CompoundDeclaration, CompoundAsm,
343     UnrolledLoop,
344     Scope,
345     Forwarding,
346     While,
347     Do,
348     For,
349     Foreach,
350     ForeachRange,
351     If,
352     Conditional,
353     StaticForeach,
354     Pragma,
355     StaticAssert,
356     Switch,
357     Case,
358     CaseRange,
359     Default,
360     GotoDefault,
361     GotoCase,
362     SwitchError,
363     Return,
364     Break,
365     Continue,
366     Synchronized,
367     With,
368     TryCatch,
369     TryFinally,
370     ScopeGuard,
371     Throw,
372     Debug,
373     Goto,
374     Label,
375     Asm, InlineAsm, GccAsm,
376     Import,
377 }
378 
379 /**********************
380  * Discriminant for which kind of initializer
381  */
382 enum InitKind : ubyte
383 {
384     void_,
385     error,
386     struct_,
387     array,
388     exp,
389     C_,
390 }
391 
392