]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/d/dmd/id.d
docs: Use ; for function declarations.
[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 *
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
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" },
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" },
b3f58f87
IB
314 { "_d_delstructImpl" },
315 { "_d_delstruct" },
316 { "_d_delstructTrace" },
5fee5ec3
IB
317 { "_d_assert_fail" },
318 { "dup" },
319 { "_aaApply" },
320 { "_aaApply2" },
9c7d5e88
IB
321 { "_d_arrayctor" },
322 { "_d_arraysetctor" },
5fee5ec3
IB
323
324 // For pragma's
325 { "Pinline", "inline" },
326 { "lib" },
327 { "linkerDirective" },
328 { "mangle" },
329 { "msg" },
330 { "startaddress" },
331 { "crt_constructor" },
332 { "crt_destructor" },
333
334 // For special functions
335 { "tohash", "toHash" },
336 { "tostring", "toString" },
337 { "getmembers", "getMembers" },
338
339 // Special functions
340 { "__alloca", "alloca" },
341 { "main" },
342 { "WinMain" },
343 { "DllMain" },
344 { "CMain", "_d_cmain" },
345 { "rt_init" },
346 { "__cmp" },
347 { "__equals"},
348 { "__switch"},
349 { "__switch_error"},
350 { "__ArrayCast"},
351 { "_d_HookTraceImpl" },
352 { "_d_arraysetlengthTImpl"},
353 { "_d_arraysetlengthT"},
354 { "_d_arraysetlengthTTrace"},
355
356 // varargs implementation
357 { "stdc" },
358 { "stdarg" },
359 { "va_start" },
360
361 // Builtin functions
362 { "std" },
363 { "core" },
364 { "etc" },
365 { "attribute" },
366 { "math" },
367 { "sin" },
368 { "cos" },
369 { "tan" },
370 { "_sqrt", "sqrt" },
371 { "_pow", "pow" },
372 { "atan2" },
373 { "rint" },
374 { "ldexp" },
375 { "rndtol" },
376 { "exp" },
377 { "expm1" },
378 { "exp2" },
379 { "yl2x" },
380 { "yl2xp1" },
381 { "log" },
382 { "log2" },
383 { "log10" },
384 { "round" },
385 { "floor" },
386 { "trunc" },
387 { "fmax" },
388 { "fmin" },
389 { "fma" },
390 { "isnan" },
391 { "isInfinity" },
392 { "isfinite" },
393 { "ceil" },
394 { "copysign" },
395 { "fabs" },
396 { "toPrec" },
397 { "simd" },
398 { "__prefetch"},
399 { "__simd_sto"},
400 { "__simd"},
401 { "__simd_ib"},
402 { "bitop" },
403 { "bsf" },
404 { "bsr" },
405 { "btc" },
406 { "btr" },
407 { "bts" },
408 { "bswap" },
409 { "volatile"},
410 { "volatileLoad"},
411 { "volatileStore"},
412 { "_popcnt"},
413 { "inp"},
414 { "inpl"},
415 { "inpw"},
416 { "outp"},
417 { "outpl"},
418 { "outpw"},
419
420 // Traits
421 { "isAbstractClass" },
422 { "isArithmetic" },
423 { "isAssociativeArray" },
424 { "isFinalClass" },
425 { "isTemplate" },
426 { "isPOD" },
427 { "isDeprecated" },
428 { "isDisabled" },
429 { "isFuture" },
430 { "isNested" },
431 { "isFloating" },
432 { "isIntegral" },
433 { "isScalar" },
434 { "isStaticArray" },
435 { "isUnsigned" },
436 { "isVirtualFunction" },
437 { "isVirtualMethod" },
438 { "isAbstractFunction" },
439 { "isFinalFunction" },
440 { "isOverrideFunction" },
441 { "isStaticFunction" },
442 { "isModule" },
443 { "isPackage" },
444 { "isRef" },
445 { "isOut" },
446 { "isLazy" },
447 { "hasMember" },
448 { "identifier" },
449 { "getProtection" },
450 { "getVisibility" },
451 { "parent" },
452 { "child" },
453 { "getMember" },
454 { "getOverloads" },
455 { "getVirtualFunctions" },
456 { "getVirtualMethods" },
457 { "classInstanceSize" },
458 { "allMembers" },
459 { "derivedMembers" },
460 { "isSame" },
461 { "compiles" },
462 { "getAliasThis" },
463 { "getAttributes" },
464 { "getFunctionAttributes" },
465 { "getFunctionVariadicStyle" },
466 { "getParameterStorageClasses" },
467 { "getLinkage" },
468 { "getUnitTests" },
469 { "getVirtualIndex" },
470 { "getPointerBitmap" },
9c7d5e88 471 { "initSymbol" },
5fee5ec3
IB
472 { "getCppNamespaces" },
473 { "isReturnOnStack" },
474 { "isZeroInit" },
475 { "getTargetInfo" },
476 { "getLocation" },
477 { "hasPostblit" },
478 { "hasCopyConstructor" },
479 { "isCopyable" },
480 { "toType" },
481
482 // For C++ mangling
483 { "allocator" },
484 { "basic_string" },
485 { "basic_istream" },
486 { "basic_ostream" },
487 { "basic_iostream" },
488 { "char_traits" },
489
490 // Compiler recognized UDA's
491 { "udaGNUAbiTag", "gnuAbiTag" },
492 { "udaSelector", "selector" },
493 { "udaOptional", "optional"},
494
495 // C names, for undefined identifier error messages
496 { "NULL" },
497 { "TRUE" },
498 { "FALSE" },
499 { "unsigned" },
500 { "wchar_t" },
501
502 // for C compiler
503 { "__tag" },
504 { "dllimport" },
505 { "dllexport" },
506 { "vector_size" },
507 { "__func__" },
508 { "noreturn" },
0fb57034
IB
509 { "__pragma", "pragma" },
510 { "builtin_va_list", "__builtin_va_list" },
511 { "builtin_va_start", "__builtin_va_start" },
512 { "builtin_va_arg", "__builtin_va_arg" },
513 { "builtin_va_copy", "__builtin_va_copy" },
514 { "builtin_va_end", "__builtin_va_end" },
515 { "va_list_tag", "__va_list_tag" },
516 { "pack" },
517 { "show" },
518 { "push" },
519 { "pop" },
5fee5ec3
IB
520];
521
522
523/*
524 * Tuple of DMD source code identifier and symbol in the D executable.
525 *
526 * The first element of the tuple is the identifier to use in the DMD source
527 * code and the second element, if present, is the name to use in the D
528 * executable. If second element, `name`, is not present the identifier,
529 * `ident`, will be used instead
530 */
531struct Msgtable
532{
533 // The identifier to use in the DMD source.
534 string ident;
535
536 // The name to use in the D executable
537 private string name_;
538
539 /*
540 * Returns: the name to use in the D executable, `name_` if non-empty,
541 * otherwise `ident`
542 */
543 string name()
544 {
545 return name_ ? name_ : ident;
546 }
547}
548
549/*
550 * Iterates the given Msgtable array, passes each element to the given lambda
551 * and accumulates a string from each return value of calling the lambda.
552 * Appends a newline character after each call to the lambda.
553 */
554string generate(immutable(Msgtable)[] msgtable, string function(Msgtable) dg)
555{
556 string code;
557
558 foreach (i, m ; msgtable)
559 {
560 if (i != 0)
561 code ~= '\n';
562
563 code ~= dg(m);
564 }
565
566 return code;
567}
568
569// Used to generate the code for each identifier.
570string identifier(Msgtable m)
571{
572 return "Identifier " ~ m.ident ~ ";";
573}
574
575// Used to generate the code for each initializer.
576string initializer(Msgtable m)
577{
578 return m.ident ~ ` = Identifier.idPool("` ~ m.name ~ `");`;
579}
580
581// Used to generate the code for each deinitializer.
582string deinitializer(Msgtable m)
583{
584 return m.ident ~ " = Identifier.init;";
585}