]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/d/dmd/id.d
d: Merge upstream dmd, druntime 09faa4eacd, phobos 13ef27a56.
[thirdparty/gcc.git] / gcc / d / dmd / id.d
CommitLineData
5fee5ec3
IB
1/**
2 * Contains the `Id` struct with a list of predefined symbols the compiler knows about.
3 *
f99303eb 4 * Copyright: Copyright (C) 1999-2023 by The D Language Foundation, All Rights Reserved
c43b5909
IB
5 * Authors: $(LINK2 https://www.digitalmars.com, Walter Bright)
6 * License: $(LINK2 https://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
5fee5ec3
IB
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
10 */
11
12module dmd.id;
13
14import dmd.identifier;
15import 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 */
22extern (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
51private:
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 */
59immutable Msgtable[] msgtable =
60[
61 { "IUnknown" },
62 { "Object" },
63 { "object" },
64 { "string" },
65 { "wstring" },
66 { "dstring" },
67 { "max" },
68 { "min" },
69 { "This", "this" },
70 { "_super", "super" },
71 { "ctor", "__ctor" },
72 { "dtor", "__dtor" },
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" },
88 { "_init", "init" },
89 { "__sizeof", "sizeof" },
90 { "__xalignof", "alignof" },
91 { "_mangleof", "mangleof" },
92 { "stringof" },
93 { "_tupleof", "tupleof" },
94 { "length" },
95 { "remove" },
96 { "ptr" },
97 { "array" },
98 { "funcptr" },
99 { "dollar", "__dollar" },
100 { "ctfe", "__ctfe" },
101 { "offset" },
102 { "offsetof" },
103 { "ModuleInfo" },
104 { "ClassInfo" },
105 { "classinfo" },
106 { "typeinfo" },
107 { "outer" },
108 { "Exception" },
109 { "RTInfo" },
110 { "Throwable" },
111 { "Error" },
112 { "withSym", "__withSym" },
113 { "result", "__result" },
114 { "returnLabel", "__returnLabel" },
115 { "line" },
116 { "empty", "" },
117 { "p" },
5fee5ec3
IB
118 { "__vptr" },
119 { "__monitor" },
120 { "gate", "__gate" },
121 { "__c_long" },
122 { "__c_ulong" },
123 { "__c_longlong" },
124 { "__c_ulonglong" },
125 { "__c_long_double" },
fbdaa581 126 { "__c_char" },
5fee5ec3
IB
127 { "__c_wchar_t" },
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" },
134 { "_body", "body" },
135 { "printf" },
136 { "scanf" },
137
138 { "TypeInfo" },
139 { "TypeInfo_Class" },
140 { "TypeInfo_Interface" },
141 { "TypeInfo_Struct" },
142 { "TypeInfo_Enum" },
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" },
155 { "elements" },
156 { "_arguments_typeinfo" },
157 { "_arguments" },
158 { "_argptr" },
159 { "destroy" },
160 { "xopEquals", "__xopEquals" },
161 { "xopCmp", "__xopCmp" },
162 { "xtoHash", "__xtoHash" },
b7a586be 163 { "__tmpfordtor" },
5fee5ec3
IB
164
165 { "LINE", "__LINE__" },
166 { "FILE", "__FILE__" },
167 { "MODULE", "__MODULE__" },
168 { "FUNCTION", "__FUNCTION__" },
169 { "PRETTY_FUNCTION", "__PRETTY_FUNCTION__" },
170 { "DATE", "__DATE__" },
171 { "TIME", "__TIME__" },
172 { "TIMESTAMP", "__TIMESTAMP__" },
173 { "VENDOR", "__VENDOR__" },
174 { "VERSIONX", "__VERSION__" },
175 { "EOFX", "__EOF__" },
176
177 { "nan" },
178 { "infinity" },
179 { "dig" },
180 { "epsilon" },
181 { "mant_dig" },
182 { "max_10_exp" },
183 { "max_exp" },
184 { "min_10_exp" },
185 { "min_exp" },
186 { "min_normal" },
187 { "re" },
188 { "im" },
189
190 { "C" },
191 { "D" },
192 { "Windows" },
193 { "System" },
194 { "Objective" },
195
196 { "exit" },
197 { "success" },
198 { "failure" },
199
200 { "keys" },
201 { "values" },
202 { "rehash" },
203
204 { "future", "__future" },
205 { "property" },
206 { "nogc" },
207 { "live" },
208 { "safe" },
209 { "trusted" },
210 { "system" },
211 { "disable" },
212
213 // For inline assembler
214 { "___out", "out" },
215 { "___in", "in" },
216 { "__int", "int" },
217 { "_dollar", "$" },
218 { "__LOCAL_SIZE" },
219
220 // For operator overloads
221 { "uadd", "opPos" },
222 { "neg", "opNeg" },
223 { "com", "opCom" },
224 { "add", "opAdd" },
225 { "add_r", "opAdd_r" },
226 { "sub", "opSub" },
227 { "sub_r", "opSub_r" },
228 { "mul", "opMul" },
229 { "mul_r", "opMul_r" },
230 { "div", "opDiv" },
231 { "div_r", "opDiv_r" },
232 { "mod", "opMod" },
233 { "mod_r", "opMod_r" },
234 { "eq", "opEquals" },
235 { "cmp", "opCmp" },
236 { "iand", "opAnd" },
237 { "iand_r", "opAnd_r" },
238 { "ior", "opOr" },
239 { "ior_r", "opOr_r" },
240 { "ixor", "opXor" },
241 { "ixor_r", "opXor_r" },
242 { "shl", "opShl" },
243 { "shl_r", "opShl_r" },
244 { "shr", "opShr" },
245 { "shr_r", "opShr_r" },
246 { "ushr", "opUShr" },
247 { "ushr_r", "opUShr_r" },
248 { "cat", "opCat" },
249 { "cat_r", "opCat_r" },
250 { "assign", "opAssign" },
251 { "addass", "opAddAssign" },
252 { "subass", "opSubAssign" },
253 { "mulass", "opMulAssign" },
254 { "divass", "opDivAssign" },
255 { "modass", "opModAssign" },
256 { "andass", "opAndAssign" },
257 { "orass", "opOrAssign" },
258 { "xorass", "opXorAssign" },
259 { "shlass", "opShlAssign" },
260 { "shrass", "opShrAssign" },
261 { "ushrass", "opUShrAssign" },
262 { "catass", "opCatAssign" },
263 { "postinc", "opPostInc" },
264 { "postdec", "opPostDec" },
265 { "index", "opIndex" },
266 { "indexass", "opIndexAssign" },
267 { "slice", "opSlice" },
268 { "sliceass", "opSliceAssign" },
269 { "call", "opCall" },
270 { "_cast", "opCast" },
271 { "opIn" },
272 { "opIn_r" },
273 { "opStar" },
274 { "opDot" },
275 { "opDispatch" },
276 { "opDollar" },
277 { "opUnary" },
278 { "opIndexUnary" },
279 { "opSliceUnary" },
280 { "opBinary" },
281 { "opBinaryRight" },
282 { "opOpAssign" },
283 { "opIndexOpAssign" },
284 { "opSliceOpAssign" },
285 { "pow", "opPow" },
286 { "pow_r", "opPow_r" },
287 { "powass", "opPowAssign" },
288
289 { "classNew", "new" },
290 { "classDelete", "delete" },
291
292 // For foreach
293 { "apply", "opApply" },
294 { "applyReverse", "opApplyReverse" },
295
296 // Ranges
297 { "Fempty", "empty" },
298 { "Ffront", "front" },
299 { "Fback", "back" },
300 { "FpopFront", "popFront" },
301 { "FpopBack", "popBack" },
302
303 // For internal functions
304 { "aaLen", "_aaLen" },
305 { "aaKeys", "_aaKeys" },
306 { "aaValues", "_aaValues" },
307 { "aaRehash", "_aaRehash" },
308 { "monitorenter", "_d_monitorenter" },
309 { "monitorexit", "_d_monitorexit" },
310 { "criticalenter", "_d_criticalenter2" },
311 { "criticalexit", "_d_criticalexit" },
312 { "__ArrayPostblit" },
313 { "__ArrayDtor" },
314 { "_d_delThrowable" },
ec486b73 315 { "_d_newThrowable" },
5fee5ec3
IB
316 { "_d_assert_fail" },
317 { "dup" },
318 { "_aaApply" },
319 { "_aaApply2" },
9c7d5e88
IB
320 { "_d_arrayctor" },
321 { "_d_arraysetctor" },
c8dfa79c 322 { "_d_arraysetassign" },
b7a586be
IB
323 { "_d_arrayassign_l" },
324 { "_d_arrayassign_r" },
5fee5ec3
IB
325
326 // For pragma's
327 { "Pinline", "inline" },
328 { "lib" },
329 { "linkerDirective" },
330 { "mangle" },
331 { "msg" },
332 { "startaddress" },
333 { "crt_constructor" },
334 { "crt_destructor" },
335
336 // For special functions
337 { "tohash", "toHash" },
338 { "tostring", "toString" },
339 { "getmembers", "getMembers" },
340
341 // Special functions
342 { "__alloca", "alloca" },
343 { "main" },
344 { "WinMain" },
345 { "DllMain" },
346 { "CMain", "_d_cmain" },
347 { "rt_init" },
348 { "__cmp" },
349 { "__equals"},
350 { "__switch"},
351 { "__switch_error"},
352 { "__ArrayCast"},
353 { "_d_HookTraceImpl" },
354 { "_d_arraysetlengthTImpl"},
355 { "_d_arraysetlengthT"},
356 { "_d_arraysetlengthTTrace"},
5eb9927a
IB
357 { "_d_arrayappendT" },
358 { "_d_arrayappendTTrace" },
359 { "_d_arrayappendcTXImpl" },
360 { "_d_arrayappendcTX" },
361 { "_d_arrayappendcTXTrace" },
5fee5ec3
IB
362
363 // varargs implementation
364 { "stdc" },
365 { "stdarg" },
366 { "va_start" },
367
368 // Builtin functions
369 { "std" },
370 { "core" },
371 { "etc" },
372 { "attribute" },
fbdaa581
IB
373 { "atomic" },
374 { "atomicOp" },
5fee5ec3
IB
375 { "math" },
376 { "sin" },
377 { "cos" },
378 { "tan" },
379 { "_sqrt", "sqrt" },
380 { "_pow", "pow" },
381 { "atan2" },
382 { "rint" },
383 { "ldexp" },
384 { "rndtol" },
385 { "exp" },
386 { "expm1" },
387 { "exp2" },
388 { "yl2x" },
389 { "yl2xp1" },
390 { "log" },
391 { "log2" },
392 { "log10" },
393 { "round" },
394 { "floor" },
395 { "trunc" },
396 { "fmax" },
397 { "fmin" },
398 { "fma" },
399 { "isnan" },
400 { "isInfinity" },
401 { "isfinite" },
402 { "ceil" },
403 { "copysign" },
404 { "fabs" },
405 { "toPrec" },
406 { "simd" },
407 { "__prefetch"},
408 { "__simd_sto"},
409 { "__simd"},
410 { "__simd_ib"},
411 { "bitop" },
412 { "bsf" },
413 { "bsr" },
414 { "btc" },
415 { "btr" },
416 { "bts" },
417 { "bswap" },
418 { "volatile"},
419 { "volatileLoad"},
420 { "volatileStore"},
421 { "_popcnt"},
422 { "inp"},
423 { "inpl"},
424 { "inpw"},
425 { "outp"},
426 { "outpl"},
427 { "outpw"},
428
429 // Traits
430 { "isAbstractClass" },
431 { "isArithmetic" },
432 { "isAssociativeArray" },
433 { "isFinalClass" },
434 { "isTemplate" },
435 { "isPOD" },
436 { "isDeprecated" },
437 { "isDisabled" },
438 { "isFuture" },
439 { "isNested" },
440 { "isFloating" },
441 { "isIntegral" },
442 { "isScalar" },
443 { "isStaticArray" },
444 { "isUnsigned" },
445 { "isVirtualFunction" },
446 { "isVirtualMethod" },
447 { "isAbstractFunction" },
448 { "isFinalFunction" },
449 { "isOverrideFunction" },
450 { "isStaticFunction" },
451 { "isModule" },
452 { "isPackage" },
453 { "isRef" },
454 { "isOut" },
455 { "isLazy" },
456 { "hasMember" },
457 { "identifier" },
458 { "getProtection" },
459 { "getVisibility" },
460 { "parent" },
461 { "child" },
462 { "getMember" },
463 { "getOverloads" },
464 { "getVirtualFunctions" },
465 { "getVirtualMethods" },
466 { "classInstanceSize" },
5eb9927a 467 { "classInstanceAlignment" },
5fee5ec3
IB
468 { "allMembers" },
469 { "derivedMembers" },
470 { "isSame" },
471 { "compiles" },
472 { "getAliasThis" },
473 { "getAttributes" },
474 { "getFunctionAttributes" },
475 { "getFunctionVariadicStyle" },
476 { "getParameterStorageClasses" },
477 { "getLinkage" },
478 { "getUnitTests" },
479 { "getVirtualIndex" },
480 { "getPointerBitmap" },
9c7d5e88 481 { "initSymbol" },
5fee5ec3
IB
482 { "getCppNamespaces" },
483 { "isReturnOnStack" },
484 { "isZeroInit" },
485 { "getTargetInfo" },
486 { "getLocation" },
487 { "hasPostblit" },
488 { "hasCopyConstructor" },
489 { "isCopyable" },
490 { "toType" },
d7569187 491 { "parameters" },
5fee5ec3
IB
492
493 // For C++ mangling
494 { "allocator" },
495 { "basic_string" },
496 { "basic_istream" },
497 { "basic_ostream" },
498 { "basic_iostream" },
499 { "char_traits" },
500
501 // Compiler recognized UDA's
502 { "udaGNUAbiTag", "gnuAbiTag" },
503 { "udaSelector", "selector" },
504 { "udaOptional", "optional"},
31350635 505 { "udaMustUse", "mustuse" },
5fee5ec3
IB
506
507 // C names, for undefined identifier error messages
508 { "NULL" },
509 { "TRUE" },
510 { "FALSE" },
511 { "unsigned" },
512 { "wchar_t" },
513
514 // for C compiler
c8dfa79c 515 { "ImportC", "__C" },
5fee5ec3
IB
516 { "__tag" },
517 { "dllimport" },
518 { "dllexport" },
519 { "vector_size" },
520 { "__func__" },
521 { "noreturn" },
0fb57034 522 { "__pragma", "pragma" },
d7569187 523 { "builtins", "__builtins" },
0fb57034 524 { "builtin_va_list", "__builtin_va_list" },
0fb57034 525 { "builtin_va_arg", "__builtin_va_arg" },
0fb57034 526 { "va_list_tag", "__va_list_tag" },
d7569187 527 { "va_arg" },
0fb57034
IB
528 { "pack" },
529 { "show" },
530 { "push" },
531 { "pop" },
610d7898
IB
532 { "define" },
533 { "undef" },
5fee5ec3
IB
534];
535
536
537/*
538 * Tuple of DMD source code identifier and symbol in the D executable.
539 *
540 * The first element of the tuple is the identifier to use in the DMD source
541 * code and the second element, if present, is the name to use in the D
542 * executable. If second element, `name`, is not present the identifier,
543 * `ident`, will be used instead
544 */
545struct Msgtable
546{
547 // The identifier to use in the DMD source.
548 string ident;
549
550 // The name to use in the D executable
551 private string name_;
552
553 /*
554 * Returns: the name to use in the D executable, `name_` if non-empty,
555 * otherwise `ident`
556 */
557 string name()
558 {
559 return name_ ? name_ : ident;
560 }
561}
562
563/*
564 * Iterates the given Msgtable array, passes each element to the given lambda
565 * and accumulates a string from each return value of calling the lambda.
566 * Appends a newline character after each call to the lambda.
567 */
568string generate(immutable(Msgtable)[] msgtable, string function(Msgtable) dg)
569{
570 string code;
571
572 foreach (i, m ; msgtable)
573 {
574 if (i != 0)
575 code ~= '\n';
576
577 code ~= dg(m);
578 }
579
580 return code;
581}
582
583// Used to generate the code for each identifier.
584string identifier(Msgtable m)
585{
586 return "Identifier " ~ m.ident ~ ";";
587}
588
589// Used to generate the code for each initializer.
590string initializer(Msgtable m)
591{
592 return m.ident ~ ` = Identifier.idPool("` ~ m.name ~ `");`;
593}
594
595// Used to generate the code for each deinitializer.
596string deinitializer(Msgtable m)
597{
598 return m.ident ~ " = Identifier.init;";
599}