]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/d/dmd/id.d
d: Import dmd b8384668f, druntime e6caaab9, phobos 5ab9ad256 (v2.098.0-beta.1)
[thirdparty/gcc.git] / gcc / d / dmd / id.d
1 /**
2 * Contains the `Id` struct with a list of predefined symbols the compiler knows about.
3 *
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
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 { "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" },
118 { "q" },
119 { "__vptr" },
120 { "__monitor" },
121 { "gate", "__gate" },
122 { "__c_long" },
123 { "__c_ulong" },
124 { "__c_longlong" },
125 { "__c_ulonglong" },
126 { "__c_long_double" },
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" },
163
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__" },
175
176 { "nan" },
177 { "infinity" },
178 { "dig" },
179 { "epsilon" },
180 { "mant_dig" },
181 { "max_10_exp" },
182 { "max_exp" },
183 { "min_10_exp" },
184 { "min_exp" },
185 { "min_normal" },
186 { "re" },
187 { "im" },
188
189 { "C" },
190 { "D" },
191 { "Windows" },
192 { "System" },
193 { "Objective" },
194
195 { "exit" },
196 { "success" },
197 { "failure" },
198
199 { "keys" },
200 { "values" },
201 { "rehash" },
202
203 { "future", "__future" },
204 { "property" },
205 { "nogc" },
206 { "live" },
207 { "safe" },
208 { "trusted" },
209 { "system" },
210 { "disable" },
211
212 // For inline assembler
213 { "___out", "out" },
214 { "___in", "in" },
215 { "__int", "int" },
216 { "_dollar", "$" },
217 { "__LOCAL_SIZE" },
218
219 // For operator overloads
220 { "uadd", "opPos" },
221 { "neg", "opNeg" },
222 { "com", "opCom" },
223 { "add", "opAdd" },
224 { "add_r", "opAdd_r" },
225 { "sub", "opSub" },
226 { "sub_r", "opSub_r" },
227 { "mul", "opMul" },
228 { "mul_r", "opMul_r" },
229 { "div", "opDiv" },
230 { "div_r", "opDiv_r" },
231 { "mod", "opMod" },
232 { "mod_r", "opMod_r" },
233 { "eq", "opEquals" },
234 { "cmp", "opCmp" },
235 { "iand", "opAnd" },
236 { "iand_r", "opAnd_r" },
237 { "ior", "opOr" },
238 { "ior_r", "opOr_r" },
239 { "ixor", "opXor" },
240 { "ixor_r", "opXor_r" },
241 { "shl", "opShl" },
242 { "shl_r", "opShl_r" },
243 { "shr", "opShr" },
244 { "shr_r", "opShr_r" },
245 { "ushr", "opUShr" },
246 { "ushr_r", "opUShr_r" },
247 { "cat", "opCat" },
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" },
270 { "opIn" },
271 { "opIn_r" },
272 { "opStar" },
273 { "opDot" },
274 { "opDispatch" },
275 { "opDollar" },
276 { "opUnary" },
277 { "opIndexUnary" },
278 { "opSliceUnary" },
279 { "opBinary" },
280 { "opBinaryRight" },
281 { "opOpAssign" },
282 { "opIndexOpAssign" },
283 { "opSliceOpAssign" },
284 { "pow", "opPow" },
285 { "pow_r", "opPow_r" },
286 { "powass", "opPowAssign" },
287
288 { "classNew", "new" },
289 { "classDelete", "delete" },
290
291 // For foreach
292 { "apply", "opApply" },
293 { "applyReverse", "opApplyReverse" },
294
295 // Ranges
296 { "Fempty", "empty" },
297 { "Ffront", "front" },
298 { "Fback", "back" },
299 { "FpopFront", "popFront" },
300 { "FpopBack", "popBack" },
301
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" },
312 { "__ArrayDtor" },
313 { "_d_delThrowable" },
314 { "_d_assert_fail" },
315 { "dup" },
316 { "_aaApply" },
317 { "_aaApply2" },
318
319 // For pragma's
320 { "Pinline", "inline" },
321 { "lib" },
322 { "linkerDirective" },
323 { "mangle" },
324 { "msg" },
325 { "startaddress" },
326 { "crt_constructor" },
327 { "crt_destructor" },
328
329 // For special functions
330 { "tohash", "toHash" },
331 { "tostring", "toString" },
332 { "getmembers", "getMembers" },
333
334 // Special functions
335 { "__alloca", "alloca" },
336 { "main" },
337 { "WinMain" },
338 { "DllMain" },
339 { "CMain", "_d_cmain" },
340 { "rt_init" },
341 { "__cmp" },
342 { "__equals"},
343 { "__switch"},
344 { "__switch_error"},
345 { "__ArrayCast"},
346 { "_d_HookTraceImpl" },
347 { "_d_arraysetlengthTImpl"},
348 { "_d_arraysetlengthT"},
349 { "_d_arraysetlengthTTrace"},
350
351 // varargs implementation
352 { "stdc" },
353 { "stdarg" },
354 { "va_start" },
355
356 // Builtin functions
357 { "std" },
358 { "core" },
359 { "etc" },
360 { "attribute" },
361 { "math" },
362 { "sin" },
363 { "cos" },
364 { "tan" },
365 { "_sqrt", "sqrt" },
366 { "_pow", "pow" },
367 { "atan2" },
368 { "rint" },
369 { "ldexp" },
370 { "rndtol" },
371 { "exp" },
372 { "expm1" },
373 { "exp2" },
374 { "yl2x" },
375 { "yl2xp1" },
376 { "log" },
377 { "log2" },
378 { "log10" },
379 { "round" },
380 { "floor" },
381 { "trunc" },
382 { "fmax" },
383 { "fmin" },
384 { "fma" },
385 { "isnan" },
386 { "isInfinity" },
387 { "isfinite" },
388 { "ceil" },
389 { "copysign" },
390 { "fabs" },
391 { "toPrec" },
392 { "simd" },
393 { "__prefetch"},
394 { "__simd_sto"},
395 { "__simd"},
396 { "__simd_ib"},
397 { "bitop" },
398 { "bsf" },
399 { "bsr" },
400 { "btc" },
401 { "btr" },
402 { "bts" },
403 { "bswap" },
404 { "volatile"},
405 { "volatileLoad"},
406 { "volatileStore"},
407 { "_popcnt"},
408 { "inp"},
409 { "inpl"},
410 { "inpw"},
411 { "outp"},
412 { "outpl"},
413 { "outpw"},
414
415 // Traits
416 { "isAbstractClass" },
417 { "isArithmetic" },
418 { "isAssociativeArray" },
419 { "isFinalClass" },
420 { "isTemplate" },
421 { "isPOD" },
422 { "isDeprecated" },
423 { "isDisabled" },
424 { "isFuture" },
425 { "isNested" },
426 { "isFloating" },
427 { "isIntegral" },
428 { "isScalar" },
429 { "isStaticArray" },
430 { "isUnsigned" },
431 { "isVirtualFunction" },
432 { "isVirtualMethod" },
433 { "isAbstractFunction" },
434 { "isFinalFunction" },
435 { "isOverrideFunction" },
436 { "isStaticFunction" },
437 { "isModule" },
438 { "isPackage" },
439 { "isRef" },
440 { "isOut" },
441 { "isLazy" },
442 { "hasMember" },
443 { "identifier" },
444 { "getProtection" },
445 { "getVisibility" },
446 { "parent" },
447 { "child" },
448 { "getMember" },
449 { "getOverloads" },
450 { "getVirtualFunctions" },
451 { "getVirtualMethods" },
452 { "classInstanceSize" },
453 { "allMembers" },
454 { "derivedMembers" },
455 { "isSame" },
456 { "compiles" },
457 { "getAliasThis" },
458 { "getAttributes" },
459 { "getFunctionAttributes" },
460 { "getFunctionVariadicStyle" },
461 { "getParameterStorageClasses" },
462 { "getLinkage" },
463 { "getUnitTests" },
464 { "getVirtualIndex" },
465 { "getPointerBitmap" },
466 { "getCppNamespaces" },
467 { "isReturnOnStack" },
468 { "isZeroInit" },
469 { "getTargetInfo" },
470 { "getLocation" },
471 { "hasPostblit" },
472 { "hasCopyConstructor" },
473 { "isCopyable" },
474 { "toType" },
475
476 // For C++ mangling
477 { "allocator" },
478 { "basic_string" },
479 { "basic_istream" },
480 { "basic_ostream" },
481 { "basic_iostream" },
482 { "char_traits" },
483
484 // Compiler recognized UDA's
485 { "udaGNUAbiTag", "gnuAbiTag" },
486 { "udaSelector", "selector" },
487 { "udaOptional", "optional"},
488
489 // C names, for undefined identifier error messages
490 { "NULL" },
491 { "TRUE" },
492 { "FALSE" },
493 { "unsigned" },
494 { "wchar_t" },
495
496 // for C compiler
497 { "__tag" },
498 { "dllimport" },
499 { "dllexport" },
500 { "vector_size" },
501 { "__func__" },
502 { "noreturn" },
503 ];
504
505
506 /*
507 * Tuple of DMD source code identifier and symbol in the D executable.
508 *
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
513 */
514 struct Msgtable
515 {
516 // The identifier to use in the DMD source.
517 string ident;
518
519 // The name to use in the D executable
520 private string name_;
521
522 /*
523 * Returns: the name to use in the D executable, `name_` if non-empty,
524 * otherwise `ident`
525 */
526 string name()
527 {
528 return name_ ? name_ : ident;
529 }
530 }
531
532 /*
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.
536 */
537 string generate(immutable(Msgtable)[] msgtable, string function(Msgtable) dg)
538 {
539 string code;
540
541 foreach (i, m ; msgtable)
542 {
543 if (i != 0)
544 code ~= '\n';
545
546 code ~= dg(m);
547 }
548
549 return code;
550 }
551
552 // Used to generate the code for each identifier.
553 string identifier(Msgtable m)
554 {
555 return "Identifier " ~ m.ident ~ ";";
556 }
557
558 // Used to generate the code for each initializer.
559 string initializer(Msgtable m)
560 {
561 return m.ident ~ ` = Identifier.idPool("` ~ m.name ~ `");`;
562 }
563
564 // Used to generate the code for each deinitializer.
565 string deinitializer(Msgtable m)
566 {
567 return m.ident ~ " = Identifier.init;";
568 }