2 * Contains the `Id` struct with a list of predefined symbols the compiler knows about.
4 * Copyright: Copyright (C) 1999-2021 by The D Language Foundation, All Rights Reserved
5 * Authors: $(LINK2 http://www.digitalmars.com, Walter Bright)
6 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
7 * Source: $(LINK2 https://github.com/dlang/dmd/blob/master/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/src/dmd/id.d
14 import dmd.identifier;
18 * Represents a list of predefined symbols the compiler knows about.
20 * All static fields in this struct represents a specific predefined symbol.
22 extern (C++) struct Id
26 mixin(msgtable.generate(&identifier));
29 * Populates the identifier pool with all predefined symbols.
31 * An identifier that corresponds to each static field in this struct will
32 * be placed in the identifier pool.
34 extern(C++) void initialize()
36 mixin(msgtable.generate(&initializer));
40 * Deinitializes the global state of the compiler.
42 * This can be used to restore the state set by `initialize` to its original
45 extern (D) void deinitialize()
47 mixin(msgtable.generate(&deinitializer));
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.
59 immutable Msgtable[] msgtable =
70 { "_super", "super" },
73 { "__xdtor", "__xdtor" },
74 { "__fieldDtor", "__fieldDtor" },
75 { "__aggrDtor", "__aggrDtor" },
76 { "cppdtor", "__cppdtor" },
77 { "ticppdtor", "__ticppdtor" },
78 { "postblit", "__postblit" },
79 { "__xpostblit", "__xpostblit" },
80 { "__fieldPostblit", "__fieldPostblit" },
81 { "__aggrPostblit", "__aggrPostblit" },
82 { "classInvariant", "__invariant" },
83 { "unitTest", "__unitTest" },
84 { "require", "__require" },
85 { "ensure", "__ensure" },
86 { "capture", "__capture" },
87 { "this2", "__this" },
89 { "__sizeof", "sizeof" },
90 { "__xalignof", "alignof" },
91 { "_mangleof", "mangleof" },
93 { "_tupleof", "tupleof" },
99 { "dollar", "__dollar" },
100 { "ctfe", "__ctfe" },
112 { "withSym", "__withSym" },
113 { "result", "__result" },
114 { "returnLabel", "__returnLabel" },
121 { "gate", "__gate" },
126 { "__c_long_double" },
128 { "__c_complex_float" },
129 { "__c_complex_double" },
130 { "__c_complex_real" },
131 { "cpp_type_info_ptr", "__cpp_type_info_ptr" },
132 { "_assert", "assert" },
133 { "_unittest", "unittest" },
139 { "TypeInfo_Class" },
140 { "TypeInfo_Interface" },
141 { "TypeInfo_Struct" },
143 { "TypeInfo_Pointer" },
144 { "TypeInfo_Vector" },
145 { "TypeInfo_Array" },
146 { "TypeInfo_StaticArray" },
147 { "TypeInfo_AssociativeArray" },
148 { "TypeInfo_Function" },
149 { "TypeInfo_Delegate" },
150 { "TypeInfo_Tuple" },
151 { "TypeInfo_Const" },
152 { "TypeInfo_Invariant" },
153 { "TypeInfo_Shared" },
154 { "TypeInfo_Wild", "TypeInfo_Inout" },
156 { "_arguments_typeinfo" },
160 { "xopEquals", "__xopEquals" },
161 { "xopCmp", "__xopCmp" },
162 { "xtoHash", "__xtoHash" },
164 { "LINE", "__LINE__" },
165 { "FILE", "__FILE__" },
166 { "MODULE", "__MODULE__" },
167 { "FUNCTION", "__FUNCTION__" },
168 { "PRETTY_FUNCTION", "__PRETTY_FUNCTION__" },
169 { "DATE", "__DATE__" },
170 { "TIME", "__TIME__" },
171 { "TIMESTAMP", "__TIMESTAMP__" },
172 { "VENDOR", "__VENDOR__" },
173 { "VERSIONX", "__VERSION__" },
174 { "EOFX", "__EOF__" },
203 { "future", "__future" },
212 // For inline assembler
219 // For operator overloads
224 { "add_r", "opAdd_r" },
226 { "sub_r", "opSub_r" },
228 { "mul_r", "opMul_r" },
230 { "div_r", "opDiv_r" },
232 { "mod_r", "opMod_r" },
233 { "eq", "opEquals" },
236 { "iand_r", "opAnd_r" },
238 { "ior_r", "opOr_r" },
240 { "ixor_r", "opXor_r" },
242 { "shl_r", "opShl_r" },
244 { "shr_r", "opShr_r" },
245 { "ushr", "opUShr" },
246 { "ushr_r", "opUShr_r" },
248 { "cat_r", "opCat_r" },
249 { "assign", "opAssign" },
250 { "addass", "opAddAssign" },
251 { "subass", "opSubAssign" },
252 { "mulass", "opMulAssign" },
253 { "divass", "opDivAssign" },
254 { "modass", "opModAssign" },
255 { "andass", "opAndAssign" },
256 { "orass", "opOrAssign" },
257 { "xorass", "opXorAssign" },
258 { "shlass", "opShlAssign" },
259 { "shrass", "opShrAssign" },
260 { "ushrass", "opUShrAssign" },
261 { "catass", "opCatAssign" },
262 { "postinc", "opPostInc" },
263 { "postdec", "opPostDec" },
264 { "index", "opIndex" },
265 { "indexass", "opIndexAssign" },
266 { "slice", "opSlice" },
267 { "sliceass", "opSliceAssign" },
268 { "call", "opCall" },
269 { "_cast", "opCast" },
282 { "opIndexOpAssign" },
283 { "opSliceOpAssign" },
285 { "pow_r", "opPow_r" },
286 { "powass", "opPowAssign" },
288 { "classNew", "new" },
289 { "classDelete", "delete" },
292 { "apply", "opApply" },
293 { "applyReverse", "opApplyReverse" },
296 { "Fempty", "empty" },
297 { "Ffront", "front" },
299 { "FpopFront", "popFront" },
300 { "FpopBack", "popBack" },
302 // For internal functions
303 { "aaLen", "_aaLen" },
304 { "aaKeys", "_aaKeys" },
305 { "aaValues", "_aaValues" },
306 { "aaRehash", "_aaRehash" },
307 { "monitorenter", "_d_monitorenter" },
308 { "monitorexit", "_d_monitorexit" },
309 { "criticalenter", "_d_criticalenter2" },
310 { "criticalexit", "_d_criticalexit" },
311 { "__ArrayPostblit" },
313 { "_d_delThrowable" },
314 { "_d_assert_fail" },
320 { "Pinline", "inline" },
322 { "linkerDirective" },
326 { "crt_constructor" },
327 { "crt_destructor" },
329 // For special functions
330 { "tohash", "toHash" },
331 { "tostring", "toString" },
332 { "getmembers", "getMembers" },
335 { "__alloca", "alloca" },
339 { "CMain", "_d_cmain" },
346 { "_d_HookTraceImpl" },
347 { "_d_arraysetlengthTImpl"},
348 { "_d_arraysetlengthT"},
349 { "_d_arraysetlengthTTrace"},
351 // varargs implementation
416 { "isAbstractClass" },
418 { "isAssociativeArray" },
431 { "isVirtualFunction" },
432 { "isVirtualMethod" },
433 { "isAbstractFunction" },
434 { "isFinalFunction" },
435 { "isOverrideFunction" },
436 { "isStaticFunction" },
450 { "getVirtualFunctions" },
451 { "getVirtualMethods" },
452 { "classInstanceSize" },
454 { "derivedMembers" },
459 { "getFunctionAttributes" },
460 { "getFunctionVariadicStyle" },
461 { "getParameterStorageClasses" },
464 { "getVirtualIndex" },
465 { "getPointerBitmap" },
466 { "getCppNamespaces" },
467 { "isReturnOnStack" },
472 { "hasCopyConstructor" },
481 { "basic_iostream" },
484 // Compiler recognized UDA's
485 { "udaGNUAbiTag", "gnuAbiTag" },
486 { "udaSelector", "selector" },
487 { "udaOptional", "optional"},
489 // C names, for undefined identifier error messages
507 * Tuple of DMD source code identifier and symbol in the D executable.
509 * The first element of the tuple is the identifier to use in the DMD source
510 * code and the second element, if present, is the name to use in the D
511 * executable. If second element, `name`, is not present the identifier,
512 * `ident`, will be used instead
516 // The identifier to use in the DMD source.
519 // The name to use in the D executable
520 private string name_;
523 * Returns: the name to use in the D executable, `name_` if non-empty,
528 return name_ ? name_ : ident;
533 * Iterates the given Msgtable array, passes each element to the given lambda
534 * and accumulates a string from each return value of calling the lambda.
535 * Appends a newline character after each call to the lambda.
537 string generate(immutable(Msgtable)[] msgtable, string function(Msgtable) dg)
541 foreach (i, m ; msgtable)
552 // Used to generate the code for each identifier.
553 string identifier(Msgtable m)
555 return "Identifier " ~ m.ident ~ ";";
558 // Used to generate the code for each initializer.
559 string initializer(Msgtable m)
561 return m.ident ~ ` = Identifier.idPool("` ~ m.name ~ `");`;
564 // Used to generate the code for each deinitializer.
565 string deinitializer(Msgtable m)
567 return m.ident ~ " = Identifier.init;";