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