2 /* Compiler implementation of the D programming language
3 * Copyright (C) 1999-2019 by The D Language Foundation, All Rights Reserved
4 * written by Walter Bright
5 * http://www.digitalmars.com
6 * Distributed under the Boost Software License, Version 1.0.
7 * http://www.boost.org/LICENSE_1_0.txt
8 * https://github.com/D-Programming-Language/dmd/blob/master/src/idgen.c
11 // Program to generate string files in d data structures.
12 // Saves much tedious typing, and eliminates typo problems.
17 #include "root/dsystem.h"
21 const char* ident; // name to use in DMD source
22 const char* name; // name in D executable
36 { "_super", "super" },
39 { "__xdtor", "__xdtor" },
40 { "__fieldDtor", "__fieldDtor" },
41 { "__aggrDtor", "__aggrDtor" },
42 { "postblit", "__postblit" },
43 { "__xpostblit", "__xpostblit" },
44 { "__fieldPostblit", "__fieldPostblit" },
45 { "__aggrPostblit", "__aggrPostblit" },
46 { "classInvariant", "__invariant" },
47 { "unitTest", "__unitTest" },
48 { "require", "__require" },
49 { "ensure", "__ensure" },
51 { "__sizeof", "sizeof" },
52 { "__xalignof", "alignof" },
53 { "_mangleof", "mangleof" },
55 { "_tupleof", "tupleof" },
61 { "dollar", "__dollar" },
65 { "ModuleInfo", NULL },
66 { "ClassInfo", NULL },
67 { "classinfo", NULL },
70 { "Exception", NULL },
72 { "Throwable", NULL },
74 { "withSym", "__withSym" },
75 { "result", "__result" },
76 { "returnLabel", "__returnLabel" },
82 { "__monitor", NULL },
85 { "__c_ulong", NULL },
86 { "__c_longlong", NULL },
87 { "__c_ulonglong", NULL },
88 { "__c_long_double", NULL },
89 { "cpp_type_info_ptr", "__cpp_type_info_ptr" },
90 { "_assert", "assert" },
91 { "_unittest", "unittest" },
95 { "TypeInfo_Class", NULL },
96 { "TypeInfo_Interface", NULL },
97 { "TypeInfo_Struct", NULL },
98 { "TypeInfo_Enum", NULL },
99 { "TypeInfo_Pointer", NULL },
100 { "TypeInfo_Vector", NULL },
101 { "TypeInfo_Array", NULL },
102 { "TypeInfo_StaticArray", NULL },
103 { "TypeInfo_AssociativeArray", NULL },
104 { "TypeInfo_Function", NULL },
105 { "TypeInfo_Delegate", NULL },
106 { "TypeInfo_Tuple", NULL },
107 { "TypeInfo_Const", NULL },
108 { "TypeInfo_Invariant", NULL },
109 { "TypeInfo_Shared", NULL },
110 { "TypeInfo_Wild", "TypeInfo_Inout" },
111 { "elements", NULL },
112 { "_arguments_typeinfo", NULL },
113 { "_arguments", NULL },
116 { "xopEquals", "__xopEquals" },
117 { "xopCmp", "__xopCmp" },
118 { "xtoHash", "__xtoHash" },
120 { "LINE", "__LINE__" },
121 { "FILE", "__FILE__" },
122 { "MODULE", "__MODULE__" },
123 { "FUNCTION", "__FUNCTION__" },
124 { "PRETTY_FUNCTION", "__PRETTY_FUNCTION__" },
125 { "DATE", "__DATE__" },
126 { "TIME", "__TIME__" },
127 { "TIMESTAMP", "__TIMESTAMP__" },
128 { "VENDOR", "__VENDOR__" },
129 { "VERSIONX", "__VERSION__" },
130 { "EOFX", "__EOF__" },
133 { "infinity", NULL },
136 { "mant_dig", NULL },
137 { "max_10_exp", NULL },
139 { "min_10_exp", NULL },
141 { "min_normal", NULL },
150 { "Objective", NULL },
160 { "future", "__future" },
161 { "property", NULL },
168 // For inline assembler
173 { "__LOCAL_SIZE", NULL },
175 // For operator overloads
180 { "add_r", "opAdd_r" },
182 { "sub_r", "opSub_r" },
184 { "mul_r", "opMul_r" },
186 { "div_r", "opDiv_r" },
188 { "mod_r", "opMod_r" },
189 { "eq", "opEquals" },
192 { "iand_r", "opAnd_r" },
194 { "ior_r", "opOr_r" },
196 { "ixor_r", "opXor_r" },
198 { "shl_r", "opShl_r" },
200 { "shr_r", "opShr_r" },
201 { "ushr", "opUShr" },
202 { "ushr_r", "opUShr_r" },
204 { "cat_r", "opCat_r" },
205 { "assign", "opAssign" },
206 { "addass", "opAddAssign" },
207 { "subass", "opSubAssign" },
208 { "mulass", "opMulAssign" },
209 { "divass", "opDivAssign" },
210 { "modass", "opModAssign" },
211 { "andass", "opAndAssign" },
212 { "orass", "opOrAssign" },
213 { "xorass", "opXorAssign" },
214 { "shlass", "opShlAssign" },
215 { "shrass", "opShrAssign" },
216 { "ushrass", "opUShrAssign" },
217 { "catass", "opCatAssign" },
218 { "postinc", "opPostInc" },
219 { "postdec", "opPostDec" },
220 { "index", "opIndex" },
221 { "indexass", "opIndexAssign" },
222 { "slice", "opSlice" },
223 { "sliceass", "opSliceAssign" },
224 { "call", "opCall" },
225 { "_cast", "opCast" },
230 { "opDispatch", NULL },
231 { "opDollar", NULL },
233 { "opIndexUnary", NULL },
234 { "opSliceUnary", NULL },
235 { "opBinary", NULL },
236 { "opBinaryRight", NULL },
237 { "opOpAssign", NULL },
238 { "opIndexOpAssign", NULL },
239 { "opSliceOpAssign", NULL },
241 { "pow_r", "opPow_r" },
242 { "powass", "opPowAssign" },
244 { "classNew", "new" },
245 { "classDelete", "delete" },
248 { "apply", "opApply" },
249 { "applyReverse", "opApplyReverse" },
252 { "Fempty", "empty" },
253 { "Ffront", "front" },
255 { "FpopFront", "popFront" },
256 { "FpopBack", "popBack" },
258 // For internal functions
259 { "aaLen", "_aaLen" },
260 { "aaKeys", "_aaKeys" },
261 { "aaValues", "_aaValues" },
262 { "aaRehash", "_aaRehash" },
263 { "monitorenter", "_d_monitorenter" },
264 { "monitorexit", "_d_monitorexit" },
265 { "criticalenter", "_d_criticalenter" },
266 { "criticalexit", "_d_criticalexit" },
267 { "_ArrayEq", NULL },
268 { "_ArrayPostblit", NULL },
269 { "_ArrayDtor", NULL },
272 { "Pinline", "inline" },
276 { "startaddress", NULL },
278 // For special functions
279 { "tohash", "toHash" },
280 { "tostring", "toString" },
281 { "getmembers", "getMembers" },
284 { "__alloca", "alloca" },
288 { "tls_get_addr", "___tls_get_addr" },
289 { "entrypoint", "__entrypoint" },
291 // varargs implementation
292 { "va_start", NULL },
297 { "attribute", NULL },
317 { "isAbstractClass", NULL },
318 { "isArithmetic", NULL },
319 { "isAssociativeArray", NULL },
320 { "isFinalClass", NULL },
321 { "isTemplate", NULL },
323 { "isNested", NULL },
324 { "isFloating", NULL },
325 { "isIntegral", NULL },
326 { "isScalar", NULL },
327 { "isStaticArray", NULL },
328 { "isUnsigned", NULL },
329 { "isVirtualFunction", NULL },
330 { "isVirtualMethod", NULL },
331 { "isAbstractFunction", NULL },
332 { "isFinalFunction", NULL },
333 { "isOverrideFunction", NULL },
334 { "isStaticFunction", NULL },
338 { "hasMember", NULL },
339 { "identifier", NULL },
340 { "getProtection", NULL },
342 { "getMember", NULL },
343 { "getOverloads", NULL },
344 { "getVirtualFunctions", NULL },
345 { "getVirtualMethods", NULL },
346 { "classInstanceSize", NULL },
347 { "allMembers", NULL },
348 { "derivedMembers", NULL },
350 { "compiles", NULL },
351 { "parameters", NULL },
352 { "getAliasThis", NULL },
353 { "getAttributes", NULL },
354 { "getFunctionAttributes", NULL },
355 { "getFunctionVariadicStyle", NULL },
356 { "getParameterStorageClasses", NULL },
357 { "getLinkage", NULL },
358 { "getUnitTests", NULL },
359 { "getVirtualIndex", NULL },
360 { "getPointerBitmap", NULL },
363 { "allocator", NULL },
364 { "basic_string", NULL },
365 { "basic_istream", NULL },
366 { "basic_ostream", NULL },
367 { "basic_iostream", NULL },
368 { "char_traits", NULL },
370 // Compiler recognized UDA's
371 { "udaSelector", "selector" },
373 // C names, for undefined identifier error messages
376 { "_FALSE", "FALSE" },
377 { "_unsigned", "unsigned" },
384 FILE *fp = fopen("id.h","wb");
387 printf("can't open id.h\n");
391 fprintf(fp, "// File generated by idgen.c\n");
392 fprintf(fp, "#ifndef DMD_ID_H\n");
393 fprintf(fp, "#define DMD_ID_H 1\n");
394 fprintf(fp, "class Identifier;\n");
395 fprintf(fp, "struct Id\n");
398 for (unsigned i = 0; i < sizeof(msgtable) / sizeof(msgtable[0]); i++)
400 const char *id = msgtable[i].ident;
401 fprintf(fp," static Identifier *%s;\n", id);
404 fprintf(fp, " static void initialize();\n");
406 fprintf(fp, "#endif\n");
412 FILE *fp = fopen("id.c","wb");
415 printf("can't open id.c\n");
419 fprintf(fp, "// File generated by idgen.c\n");
420 fprintf(fp, "#include \"identifier.h\"\n");
421 fprintf(fp, "#include \"id.h\"\n");
422 fprintf(fp, "#include \"mars.h\"\n");
424 for (unsigned i = 0; i < sizeof(msgtable) / sizeof(msgtable[0]); i++)
426 const char *id = msgtable[i].ident;
427 const char *p = msgtable[i].name;
431 fprintf(fp,"Identifier *Id::%s;\n", id);
434 fprintf(fp, "void Id::initialize()\n");
437 for (unsigned i = 0; i < sizeof(msgtable) / sizeof(msgtable[0]); i++)
439 const char *id = msgtable[i].ident;
440 const char *p = msgtable[i].name;
444 fprintf(fp," %s = Identifier::idPool(\"%s\");\n", id, p);
453 FILE *fp = fopen("id.d","wb");
456 printf("can't open id.d\n");
460 fprintf(fp, "// File generated by idgen.c\n");
462 fprintf(fp, "module ddmd.id;\n");
464 fprintf(fp, "import ddmd.identifier, ddmd.tokens;\n");
466 fprintf(fp, "struct Id\n");
469 for (unsigned i = 0; i < sizeof(msgtable) / sizeof(msgtable[0]); i++)
471 const char *id = msgtable[i].ident;
472 const char *p = msgtable[i].name;
476 fprintf(fp, " extern (C++) static __gshared Identifier %s;\n", id);
480 fprintf(fp, " extern (C++) static void initialize()\n");
483 for (unsigned i = 0; i < sizeof(msgtable) / sizeof(msgtable[0]); i++)
485 const char *id = msgtable[i].ident;
486 const char *p = msgtable[i].name;
490 fprintf(fp," %s = Identifier.idPool(\"%s\");\n", id, p);