| 1 |
/** |
| 2 |
* Contains the `Id` struct with a list of predefined symbols the compiler knows about. |
| 3 |
* |
| 4 |
* Copyright: Copyright (C) 1999-2025 by The D Language Foundation, All Rights Reserved |
| 5 |
* Authors: $(LINK2 https://www.digitalmars.com, Walter Bright) |
| 6 |
* License: $(LINK2 https://www.boost.org/LICENSE_1_0.txt, Boost License 1.0) |
| 7 |
* Source: $(LINK2 https://github.com/dlang/dmd/blob/master/compiler/src/dmd/id.d, _id.d) |
| 8 |
* Documentation: https://dlang.org/phobos/dmd_id.html |
| 9 |
* Coverage: https://codecov.io/gh/dlang/dmd/src/master/compiler/src/dmd/id.d |
| 10 |
*/ |
| 11 |
|
| 12 |
module dmd.id; |
| 13 |
|
| 14 |
import dmd.identifier; |
| 15 |
import dmd.tokens; |
| 16 |
|
| 17 |
/** |
| 18 |
* Represents a list of predefined symbols the compiler knows about. |
| 19 |
* |
| 20 |
* All static fields in this struct represents a specific predefined symbol. |
| 21 |
*/ |
| 22 |
extern (C++) struct Id |
| 23 |
{ |
| 24 |
static __gshared: |
| 25 |
|
| 26 |
mixin(msgtable.generate(&identifier)); |
| 27 |
|
| 28 |
/** |
| 29 |
* Populates the identifier pool with all predefined symbols. |
| 30 |
* |
| 31 |
* An identifier that corresponds to each static field in this struct will |
| 32 |
* be placed in the identifier pool. |
| 33 |
*/ |
| 34 |
extern(C++) void initialize() |
| 35 |
{ |
| 36 |
mixin(msgtable.generate(&initializer)); |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Deinitializes the global state of the compiler. |
| 41 |
* |
| 42 |
* This can be used to restore the state set by `initialize` to its original |
| 43 |
* state. |
| 44 |
*/ |
| 45 |
extern (D) void deinitialize() |
| 46 |
{ |
| 47 |
mixin(msgtable.generate(&deinitializer)); |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
private: |
| 52 |
|
| 53 |
|
| 54 |
/** |
| 55 |
* Each element in this array will generate one static field in the `Id` struct |
| 56 |
* and a call to `Identifier.idPool` to populate the identifier pool in the |
| 57 |
* `Id.initialize` method. |
| 58 |
*/ |
| 59 |
immutable Msgtable[] msgtable = |
| 60 |
[ |
| 61 |
{ "IUnknown" }, |
| 62 |
{ "Object" }, |
| 63 |
{ "object" }, |
| 64 |
{ "_size_t", "size_t" }, |
| 65 |
{ "_ptrdiff_t", "ptrdiff_t" }, |
| 66 |
{ "string" }, |
| 67 |
{ "wstring" }, |
| 68 |
{ "dstring" }, |
| 69 |
{ "max" }, |
| 70 |
{ "min" }, |
| 71 |
{ "This", "this" }, |
| 72 |
{ "_super", "super" }, |
| 73 |
{ "ctor", "__ctor" }, |
| 74 |
{ "dtor", "__dtor" }, |
| 75 |
{ "__xdtor", "__xdtor" }, |
| 76 |
{ "__fieldDtor", "__fieldDtor" }, |
| 77 |
{ "__aggrDtor", "__aggrDtor" }, |
| 78 |
{ "cppdtor", "__cppdtor" }, |
| 79 |
{ "ticppdtor", "__ticppdtor" }, |
| 80 |
{ "postblit", "__postblit" }, |
| 81 |
{ "__xpostblit", "__xpostblit" }, |
| 82 |
{ "__fieldPostblit", "__fieldPostblit" }, |
| 83 |
{ "__aggrPostblit", "__aggrPostblit" }, |
| 84 |
{ "classInvariant", "__invariant" }, |
| 85 |
{ "unitTest", "__unitTest" }, |
| 86 |
{ "require", "__require" }, |
| 87 |
{ "ensure", "__ensure" }, |
| 88 |
{ "capture", "__capture" }, |
| 89 |
{ "this2", "__this" }, |
| 90 |
{ "_init", "init" }, |
| 91 |
{ "__sizeof", "sizeof" }, |
| 92 |
{ "__xalignof", "alignof" }, |
| 93 |
{ "_mangleof", "mangleof" }, |
| 94 |
{ "stringof" }, |
| 95 |
{ "_tupleof", "tupleof" }, |
| 96 |
{ "length" }, |
| 97 |
{ "remove" }, |
| 98 |
{ "ptr" }, |
| 99 |
{ "array" }, |
| 100 |
{ "funcptr" }, |
| 101 |
{ "dollar", "__dollar" }, |
| 102 |
{ "ctfe", "__ctfe" }, |
| 103 |
{ "offset" }, |
| 104 |
{ "offsetof" }, |
| 105 |
{ "bitoffsetof" }, |
| 106 |
{ "bitwidth" }, |
| 107 |
{ "ModuleInfo" }, |
| 108 |
{ "ClassInfo" }, |
| 109 |
{ "classinfo" }, |
| 110 |
{ "typeinfo" }, |
| 111 |
{ "outer" }, |
| 112 |
{ "Exception" }, |
| 113 |
{ "RTInfo" }, |
| 114 |
{ "Throwable" }, |
| 115 |
{ "Error" }, |
| 116 |
{ "withSym", "__withSym" }, |
| 117 |
{ "result", "__result" }, |
| 118 |
{ "returnLabel", "__returnLabel" }, |
| 119 |
{ "line" }, |
| 120 |
{ "empty", "" }, |
| 121 |
{ "dotdotdot", "..." }, // use for error messages |
| 122 |
{ "p" }, |
| 123 |
{ "__vptr" }, |
| 124 |
{ "__monitor" }, |
| 125 |
{ "gate", "__gate" }, |
| 126 |
{ "__c_long" }, |
| 127 |
{ "__c_ulong" }, |
| 128 |
{ "__c_longlong" }, |
| 129 |
{ "__c_ulonglong" }, |
| 130 |
{ "__c_long_double" }, |
| 131 |
{ "__c_char" }, |
| 132 |
{ "__c_wchar_t" }, |
| 133 |
{ "__c_complex_float" }, |
| 134 |
{ "__c_complex_double" }, |
| 135 |
{ "__c_complex_real" }, |
| 136 |
{ "cpp_type_info_ptr", "__cpp_type_info_ptr" }, |
| 137 |
{ "_assert", "assert" }, |
| 138 |
{ "_unittest", "unittest" }, |
| 139 |
{ "_body", "body" }, |
| 140 |
{ "printf" }, |
| 141 |
{ "scanf" }, |
| 142 |
|
| 143 |
{ "TypeInfo" }, |
| 144 |
{ "TypeInfo_Class" }, |
| 145 |
{ "TypeInfo_Interface" }, |
| 146 |
{ "TypeInfo_Struct" }, |
| 147 |
{ "TypeInfo_Enum" }, |
| 148 |
{ "TypeInfo_Pointer" }, |
| 149 |
{ "TypeInfo_Vector" }, |
| 150 |
{ "TypeInfo_Array" }, |
| 151 |
{ "TypeInfo_StaticArray" }, |
| 152 |
{ "TypeInfo_AssociativeArray" }, |
| 153 |
{ "TypeInfo_Function" }, |
| 154 |
{ "TypeInfo_Delegate" }, |
| 155 |
{ "TypeInfo_Tuple" }, |
| 156 |
{ "TypeInfo_Const" }, |
| 157 |
{ "TypeInfo_Invariant" }, |
| 158 |
{ "TypeInfo_Shared" }, |
| 159 |
{ "TypeInfo_Wild", "TypeInfo_Inout" }, |
| 160 |
{ "elements" }, |
| 161 |
{ "_arguments_typeinfo" }, |
| 162 |
{ "_arguments" }, |
| 163 |
{ "_argptr" }, |
| 164 |
{ "destroy" }, |
| 165 |
{ "xopEquals", "__xopEquals" }, |
| 166 |
{ "xopCmp", "__xopCmp" }, |
| 167 |
{ "xtoHash", "__xtoHash" }, |
| 168 |
{ "__tmpfordtor" }, |
| 169 |
{ "Entry" }, |
| 170 |
|
| 171 |
{ "LINE", "__LINE__" }, |
| 172 |
{ "FILE", "__FILE__" }, |
| 173 |
{ "MODULE", "__MODULE__" }, |
| 174 |
{ "FUNCTION", "__FUNCTION__" }, |
| 175 |
{ "PRETTY_FUNCTION", "__PRETTY_FUNCTION__" }, |
| 176 |
{ "DATE", "__DATE__" }, |
| 177 |
{ "TIME", "__TIME__" }, |
| 178 |
{ "TIMESTAMP", "__TIMESTAMP__" }, |
| 179 |
{ "VENDOR", "__VENDOR__" }, |
| 180 |
{ "VERSIONX", "__VERSION__" }, |
| 181 |
{ "EOFX", "__EOF__" }, |
| 182 |
|
| 183 |
{ "nan" }, |
| 184 |
{ "infinity" }, |
| 185 |
{ "dig" }, |
| 186 |
{ "epsilon" }, |
| 187 |
{ "mant_dig" }, |
| 188 |
{ "max_10_exp" }, |
| 189 |
{ "max_exp" }, |
| 190 |
{ "min_10_exp" }, |
| 191 |
{ "min_exp" }, |
| 192 |
{ "min_normal" }, |
| 193 |
{ "re" }, |
| 194 |
{ "im" }, |
| 195 |
|
| 196 |
{ "C" }, |
| 197 |
{ "D" }, |
| 198 |
{ "Windows" }, |
| 199 |
{ "System" }, |
| 200 |
{ "Objective" }, |
| 201 |
|
| 202 |
{ "exit" }, |
| 203 |
{ "success" }, |
| 204 |
{ "failure" }, |
| 205 |
|
| 206 |
{ "keys" }, |
| 207 |
{ "values" }, |
| 208 |
{ "rehash" }, |
| 209 |
|
| 210 |
{ "future", "__future" }, |
| 211 |
{ "property" }, |
| 212 |
{ "nogc" }, |
| 213 |
{ "live" }, |
| 214 |
{ "safe" }, |
| 215 |
{ "trusted" }, |
| 216 |
{ "system" }, |
| 217 |
{ "disable" }, |
| 218 |
|
| 219 |
// For inline assembler |
| 220 |
{ "___out", "out" }, |
| 221 |
{ "___in", "in" }, |
| 222 |
{ "__int", "int" }, |
| 223 |
{ "_dollar", "$" }, |
| 224 |
{ "__LOCAL_SIZE" }, |
| 225 |
|
| 226 |
// For operator overloads |
| 227 |
{ "opEquals" }, |
| 228 |
{ "opCmp" }, |
| 229 |
{ "opAssign" }, |
| 230 |
{ "opIndex" }, |
| 231 |
{ "opIndexAssign" }, |
| 232 |
{ "opSlice" }, |
| 233 |
{ "opSliceAssign" }, |
| 234 |
{ "opCall" }, |
| 235 |
{ "opCast" }, |
| 236 |
{ "opDispatch" }, |
| 237 |
{ "opDollar" }, |
| 238 |
{ "opUnary" }, |
| 239 |
{ "opIndexUnary" }, |
| 240 |
{ "opSliceUnary" }, |
| 241 |
{ "opBinary" }, |
| 242 |
{ "opBinaryRight" }, |
| 243 |
{ "opOpAssign" }, |
| 244 |
{ "opIndexOpAssign" }, |
| 245 |
{ "opSliceOpAssign" }, |
| 246 |
|
| 247 |
{ "classNew", "new" }, |
| 248 |
{ "classDelete", "delete" }, |
| 249 |
|
| 250 |
// For foreach |
| 251 |
{ "apply", "opApply" }, |
| 252 |
{ "applyReverse", "opApplyReverse" }, |
| 253 |
|
| 254 |
// Ranges |
| 255 |
{ "Fempty", "empty" }, |
| 256 |
{ "Ffront", "front" }, |
| 257 |
{ "Fback", "back" }, |
| 258 |
{ "FpopFront", "popFront" }, |
| 259 |
{ "FpopBack", "popBack" }, |
| 260 |
|
| 261 |
// For internal functions |
| 262 |
{ "aaLen", "_aaLen" }, |
| 263 |
{ "aaKeys", "_aaKeys" }, |
| 264 |
{ "aaValues", "_aaValues" }, |
| 265 |
{ "aaRehash", "_aaRehash" }, |
| 266 |
{ "_aaAsStruct" }, |
| 267 |
{ "monitorenter", "_d_monitorenter" }, |
| 268 |
{ "monitorexit", "_d_monitorexit" }, |
| 269 |
{ "criticalenter", "_d_criticalenter2" }, |
| 270 |
{ "criticalexit", "_d_criticalexit" }, |
| 271 |
{ "__ArrayPostblit" }, |
| 272 |
{ "__ArrayDtor" }, |
| 273 |
{ "_d_delThrowable" }, |
| 274 |
{ "_d_newThrowable" }, |
| 275 |
{ "_d_newclassT" }, |
| 276 |
{ "_d_newclassTTrace" }, |
| 277 |
{ "_d_newitemT" }, |
| 278 |
{ "_d_newitemTTrace" }, |
| 279 |
{ "_d_newarrayT" }, |
| 280 |
{ "_d_newarrayTTrace" }, |
| 281 |
{ "_d_newarraymTX" }, |
| 282 |
{ "_d_newarraymTXTrace" }, |
| 283 |
{ "_d_assert_fail" }, |
| 284 |
{ "dup" }, |
| 285 |
{ "_aaApply" }, |
| 286 |
{ "_aaApply2" }, |
| 287 |
{ "_d_arrayctor" }, |
| 288 |
{ "_d_arraysetctor" }, |
| 289 |
{ "_d_arraysetassign" }, |
| 290 |
{ "_d_arrayassign_l" }, |
| 291 |
{ "_d_arrayassign_r" }, |
| 292 |
|
| 293 |
{ "imported" }, |
| 294 |
{ "InterpolationHeader" }, |
| 295 |
{ "InterpolationFooter" }, |
| 296 |
{ "InterpolatedLiteral" }, |
| 297 |
{ "InterpolatedExpression" }, |
| 298 |
|
| 299 |
// For pragma's |
| 300 |
{ "Pinline", "inline" }, |
| 301 |
{ "lib" }, |
| 302 |
{ "linkerDirective" }, |
| 303 |
{ "mangle" }, |
| 304 |
{ "msg" }, |
| 305 |
{ "startaddress" }, |
| 306 |
{ "crt_constructor" }, |
| 307 |
{ "crt_destructor" }, |
| 308 |
|
| 309 |
// For special functions |
| 310 |
{ "tohash", "toHash" }, |
| 311 |
{ "tostring", "toString" }, |
| 312 |
{ "getmembers", "getMembers" }, |
| 313 |
|
| 314 |
// Special functions |
| 315 |
{ "__alloca", "alloca" }, |
| 316 |
{ "main" }, |
| 317 |
{ "WinMain" }, |
| 318 |
{ "DllMain" }, |
| 319 |
{ "CMain", "_d_cmain" }, |
| 320 |
{ "rt_init" }, |
| 321 |
{ "__cmp" }, |
| 322 |
{ "__equals"}, |
| 323 |
{ "__switch"}, |
| 324 |
{ "__switch_error"}, |
| 325 |
{ "__ArrayCast"}, |
| 326 |
{ "_d_HookTraceImpl" }, |
| 327 |
{ "_d_arraysetlengthTImpl"}, |
| 328 |
{ "_d_arraysetlengthT"}, |
| 329 |
{ "_d_arraysetlengthTTrace"}, |
| 330 |
{ "_d_arrayappendT" }, |
| 331 |
{ "_d_arrayappendTTrace" }, |
| 332 |
{ "_d_arrayappendcTX" }, |
| 333 |
{ "_d_arrayappendcTXTrace" }, |
| 334 |
{ "_d_arraycatnTX" }, |
| 335 |
{ "_d_arraycatnTXTrace" }, |
| 336 |
|
| 337 |
// varargs implementation |
| 338 |
{ "stdc" }, |
| 339 |
{ "stdarg" }, |
| 340 |
{ "va_start" }, |
| 341 |
|
| 342 |
// Builtin functions |
| 343 |
{ "std" }, |
| 344 |
{ "core" }, |
| 345 |
{ "internal" }, |
| 346 |
{ "config" }, |
| 347 |
{ "c_complex_float" }, |
| 348 |
{ "c_complex_double" }, |
| 349 |
{ "c_complex_real" }, |
| 350 |
{ "etc" }, |
| 351 |
{ "attribute" }, |
| 352 |
{ "atomic" }, |
| 353 |
{ "atomicOp" }, |
| 354 |
{ "math" }, |
| 355 |
{ "sin" }, |
| 356 |
{ "cos" }, |
| 357 |
{ "tan" }, |
| 358 |
{ "_sqrt", "sqrt" }, |
| 359 |
{ "_pow", "pow" }, |
| 360 |
{ "atan2" }, |
| 361 |
{ "rint" }, |
| 362 |
{ "ldexp" }, |
| 363 |
{ "rndtol" }, |
| 364 |
{ "exp" }, |
| 365 |
{ "expm1" }, |
| 366 |
{ "exp2" }, |
| 367 |
{ "yl2x" }, |
| 368 |
{ "yl2xp1" }, |
| 369 |
{ "log" }, |
| 370 |
{ "log2" }, |
| 371 |
{ "log10" }, |
| 372 |
{ "round" }, |
| 373 |
{ "floor" }, |
| 374 |
{ "trunc" }, |
| 375 |
{ "fmax" }, |
| 376 |
{ "fmin" }, |
| 377 |
{ "fma" }, |
| 378 |
{ "isnan" }, |
| 379 |
{ "isInfinity" }, |
| 380 |
{ "isfinite" }, |
| 381 |
{ "ceil" }, |
| 382 |
{ "copysign" }, |
| 383 |
{ "fabs" }, |
| 384 |
{ "toPrec" }, |
| 385 |
{ "simd" }, |
| 386 |
{ "__prefetch"}, |
| 387 |
{ "__simd_sto"}, |
| 388 |
{ "__simd"}, |
| 389 |
{ "__simd_ib"}, |
| 390 |
{ "bitop" }, |
| 391 |
{ "bsf" }, |
| 392 |
{ "bsr" }, |
| 393 |
{ "btc" }, |
| 394 |
{ "btr" }, |
| 395 |
{ "bts" }, |
| 396 |
{ "bswap" }, |
| 397 |
{ "volatile"}, |
| 398 |
{ "volatileLoad"}, |
| 399 |
{ "volatileStore"}, |
| 400 |
{ "_popcnt"}, |
| 401 |
{ "inp"}, |
| 402 |
{ "inpl"}, |
| 403 |
{ "inpw"}, |
| 404 |
{ "outp"}, |
| 405 |
{ "outpl"}, |
| 406 |
{ "outpw"}, |
| 407 |
{ "builtinsModuleName", "builtins" }, |
| 408 |
{ "ctfeWrite", "__ctfeWrite" }, |
| 409 |
|
| 410 |
// Traits |
| 411 |
{ "isAbstractClass" }, |
| 412 |
{ "isArithmetic" }, |
| 413 |
{ "isAssociativeArray" }, |
| 414 |
{ "isBitfield" }, |
| 415 |
{ "isFinalClass" }, |
| 416 |
{ "isTemplate" }, |
| 417 |
{ "isPOD" }, |
| 418 |
{ "isDeprecated" }, |
| 419 |
{ "isDisabled" }, |
| 420 |
{ "isFuture" }, |
| 421 |
{ "isNested" }, |
| 422 |
{ "isFloating" }, |
| 423 |
{ "isIntegral" }, |
| 424 |
{ "isScalar" }, |
| 425 |
{ "isStaticArray" }, |
| 426 |
{ "isUnsigned" }, |
| 427 |
{ "isVirtualFunction" }, |
| 428 |
{ "isVirtualMethod" }, |
| 429 |
{ "isAbstractFunction" }, |
| 430 |
{ "isFinalFunction" }, |
| 431 |
{ "isOverrideFunction" }, |
| 432 |
{ "isStaticFunction" }, |
| 433 |
{ "isModule" }, |
| 434 |
{ "isPackage" }, |
| 435 |
{ "isRef" }, |
| 436 |
{ "isOut" }, |
| 437 |
{ "isLazy" }, |
| 438 |
{ "isCOMClass" }, |
| 439 |
{ "hasMember" }, |
| 440 |
{ "identifier" }, |
| 441 |
{ "fullyQualifiedName" }, |
| 442 |
{ "getBitfieldOffset" }, |
| 443 |
{ "getBitfieldWidth" }, |
| 444 |
{ "getProtection" }, |
| 445 |
{ "getVisibility" }, |
| 446 |
{ "parent" }, |
| 447 |
{ "child" }, |
| 448 |
{ "getMember" }, |
| 449 |
{ "getOverloads" }, |
| 450 |
{ "getVirtualFunctions" }, |
| 451 |
{ "getVirtualMethods" }, |
| 452 |
{ "classInstanceSize" }, |
| 453 |
{ "classInstanceAlignment" }, |
| 454 |
{ "allMembers" }, |
| 455 |
{ "derivedMembers" }, |
| 456 |
{ "isSame" }, |
| 457 |
{ "compiles" }, |
| 458 |
{ "getAliasThis" }, |
| 459 |
{ "getAttributes" }, |
| 460 |
{ "getFunctionAttributes" }, |
| 461 |
{ "getFunctionVariadicStyle" }, |
| 462 |
{ "getParameterStorageClasses" }, |
| 463 |
{ "getLinkage" }, |
| 464 |
{ "getUnitTests" }, |
| 465 |
{ "getVirtualIndex" }, |
| 466 |
{ "getPointerBitmap" }, |
| 467 |
{ "initSymbol" }, |
| 468 |
{ "getCppNamespaces" }, |
| 469 |
{ "isReturnOnStack" }, |
| 470 |
{ "isZeroInit" }, |
| 471 |
{ "getTargetInfo" }, |
| 472 |
{ "getLocation" }, |
| 473 |
{ "hasPostblit" }, |
| 474 |
{ "hasCopyConstructor" }, |
| 475 |
{ "hasMoveConstructor" }, |
| 476 |
{ "isCopyable" }, |
| 477 |
{ "toType" }, |
| 478 |
{ "parameters" }, |
| 479 |
|
| 480 |
// For C++ mangling |
| 481 |
{ "allocator" }, |
| 482 |
{ "basic_string" }, |
| 483 |
{ "basic_istream" }, |
| 484 |
{ "basic_ostream" }, |
| 485 |
{ "basic_iostream" }, |
| 486 |
{ "char_traits" }, |
| 487 |
|
| 488 |
// Compiler recognized UDA's |
| 489 |
{ "udaGNUAbiTag", "gnuAbiTag" }, |
| 490 |
{ "udaSelector", "selector" }, |
| 491 |
{ "udaOptional", "optional"}, |
| 492 |
{ "udaMustUse", "mustuse" }, |
| 493 |
{ "udaStandalone", "standalone" }, |
| 494 |
|
| 495 |
// Editions |
| 496 |
{ "__edition_latest_do_not_use", }, |
| 497 |
|
| 498 |
// C names, for undefined identifier error messages |
| 499 |
{ "NULL" }, |
| 500 |
{ "TRUE" }, |
| 501 |
{ "FALSE" }, |
| 502 |
{ "unsigned" }, |
| 503 |
{ "wchar_t" }, |
| 504 |
|
| 505 |
// for C compiler |
| 506 |
{ "ImportC", "__C" }, |
| 507 |
{ "__tag" }, |
| 508 |
{ "dllimport" }, |
| 509 |
{ "dllexport" }, |
| 510 |
{ "naked" }, |
| 511 |
{ "thread" }, |
| 512 |
{ "vector_size" }, |
| 513 |
{ "__func__" }, |
| 514 |
{ "always_inline" }, |
| 515 |
{ "noinline" }, |
| 516 |
{ "noreturn" }, |
| 517 |
{ "_nothrow", "nothrow" }, |
| 518 |
{ "_deprecated", "deprecated" }, |
| 519 |
{ "_align", "align" }, |
| 520 |
{ "aligned" }, |
| 521 |
{ "__pragma", "pragma" }, |
| 522 |
{ "importc_builtins", "__importc_builtins" }, |
| 523 |
{ "builtin_va_list", "__builtin_va_list" }, |
| 524 |
{ "builtin_va_arg", "__builtin_va_arg" }, |
| 525 |
{ "va_list_tag", "__va_list_tag" }, |
| 526 |
{ "va_arg" }, |
| 527 |
{ "pack" }, |
| 528 |
{ "show" }, |
| 529 |
{ "push" }, |
| 530 |
{ "pop" }, |
| 531 |
{ "_pure", "pure" }, |
| 532 |
{ "define" }, |
| 533 |
{ "undef" }, |
| 534 |
{ "ident" }, |
| 535 |
{ "packed" }, |
| 536 |
]; |
| 537 |
|
| 538 |
|
| 539 |
/* |
| 540 |
* Tuple of DMD source code identifier and symbol in the D executable. |
| 541 |
* |
| 542 |
* The first element of the tuple is the identifier to use in the DMD source |
| 543 |
* code and the second element, if present, is the name to use in the D |
| 544 |
* executable. If second element, `name`, is not present the identifier, |
| 545 |
* `ident`, will be used instead |
| 546 |
*/ |
| 547 |
struct Msgtable |
| 548 |
{ |
| 549 |
// The identifier to use in the DMD source. |
| 550 |
string ident; |
| 551 |
|
| 552 |
// The name to use in the D executable |
| 553 |
private string name_; |
| 554 |
|
| 555 |
/* |
| 556 |
* Returns: the name to use in the D executable, `name_` if non-empty, |
| 557 |
* otherwise `ident` |
| 558 |
*/ |
| 559 |
string name() @safe |
| 560 |
{ |
| 561 |
return name_ ? name_ : ident; |
| 562 |
} |
| 563 |
} |
| 564 |
|
| 565 |
/* |
| 566 |
* Iterates the given Msgtable array, passes each element to the given lambda |
| 567 |
* and accumulates a string from each return value of calling the lambda. |
| 568 |
* Appends a newline character after each call to the lambda. |
| 569 |
*/ |
| 570 |
string generate(immutable(Msgtable)[] msgtable, string function(Msgtable) dg) |
| 571 |
{ |
| 572 |
string code; |
| 573 |
|
| 574 |
foreach (i, m ; msgtable) |
| 575 |
{ |
| 576 |
if (i != 0) |
| 577 |
code ~= '\n'; |
| 578 |
|
| 579 |
code ~= dg(m); |
| 580 |
} |
| 581 |
|
| 582 |
return code; |
| 583 |
} |
| 584 |
|
| 585 |
// Used to generate the code for each identifier. |
| 586 |
string identifier(Msgtable m) @safe |
| 587 |
{ |
| 588 |
return "Identifier " ~ m.ident ~ ";"; |
| 589 |
} |
| 590 |
|
| 591 |
// Used to generate the code for each initializer. |
| 592 |
string initializer(Msgtable m) @safe |
| 593 |
{ |
| 594 |
return m.ident ~ ` = Identifier.idPool("` ~ m.name ~ `");`; |
| 595 |
} |
| 596 |
|
| 597 |
// Used to generate the code for each deinitializer. |
| 598 |
string deinitializer(Msgtable m) @safe |
| 599 |
{ |
| 600 |
return m.ident ~ " = Identifier.init;"; |
| 601 |
} |