Allow returning something of type void in a function that returns void
[delight/core.git] / dmd2 / idgen.c
blob0265df41bf8a6b9c679a6a9b34d827c39e692f3e
2 // Compiler implementation of the D programming language
3 // Copyright (c) 1999-2008 by Digital Mars
4 // All Rights Reserved
5 // written by Walter Bright
6 // http://www.digitalmars.com
7 // License for redistribution is by either the Artistic License
8 // in artistic.txt, or the GNU General Public License in gnu.txt.
9 // See the included readme.txt for details.
11 /* NOTE: This file has been patched from the original DMD distribution to
12 work with the GDC compiler.
14 Modified by David Friedman, January 2007
17 // Program to generate string files in d data structures.
18 // Saves much tedious typing, and eliminates typo problems.
19 // Generates:
20 // id.h
21 // id.c
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <stdarg.h>
27 #include <assert.h>
29 struct Msgtable
31 char *ident; // name to use in DMD source
32 char *name; // name in D executable
35 struct Msgtable msgtable[] =
37 { "IUnknown" },
38 { "Object" },
39 { "object" },
40 { "max" },
41 { "min" },
42 { "This", "this" },
43 { "ctor", "_ctor" },
44 { "cpctor", "_cpctor" },
45 { "dtor", "_dtor" },
46 { "_postblit", "_postblit" },
47 { "classInvariant", "__invariant" },
48 { "unitTest", "_unitTest" },
49 { "init" },
50 { "size" },
51 { "__sizeof", "sizeof" },
52 { "alignof" },
53 { "mangleof" },
54 { "stringof" },
55 { "tupleof" },
56 { "length" },
57 { "remove" },
58 { "ptr" },
59 { "funcptr" },
60 { "dollar", "__dollar" },
61 { "offset" },
62 { "offsetof" },
63 { "ModuleInfo" },
64 { "ClassInfo" },
65 { "classinfo" },
66 { "typeinfo" },
67 { "outer" },
68 { "Exception" },
69 { "withSym", "__withSym" },
70 { "result", "__result" },
71 { "returnLabel", "__returnLabel" },
72 { "delegate" },
73 { "line" },
74 { "empty", "" },
75 { "p" },
76 { "coverage", "__coverage" },
78 { "TypeInfo" },
79 { "TypeInfo_Class" },
80 { "TypeInfo_Interface" },
81 { "TypeInfo_Struct" },
82 { "TypeInfo_Enum" },
83 { "TypeInfo_Typedef" },
84 { "TypeInfo_Pointer" },
85 { "TypeInfo_Maybe" },
86 { "TypeInfo_Array" },
87 { "TypeInfo_StaticArray" },
88 { "TypeInfo_AssociativeArray" },
89 { "TypeInfo_Function" },
90 { "TypeInfo_Delegate" },
91 { "TypeInfo_Tuple" },
92 { "TypeInfo_Const" },
93 { "TypeInfo_Invariant" },
94 { "elements" },
95 { "_arguments_typeinfo" },
96 { "_arguments" },
97 { "_argptr" },
98 { "_match" },
99 { "destroy" },
100 { "postblit" },
102 { "LINE", "__LINE__" },
103 { "FILE", "__FILE__" },
104 { "DATE", "__DATE__" },
105 { "TIME", "__TIME__" },
106 { "TIMESTAMP", "__TIMESTAMP__" },
107 { "VENDOR", "__VENDOR__" },
108 { "VERSIONX", "__VERSION__" },
109 { "EOFX", "__EOF__" },
111 { "nan" },
112 { "infinity" },
113 { "dig" },
114 { "epsilon" },
115 { "mant_dig" },
116 { "max_10_exp" },
117 { "max_exp" },
118 { "min_10_exp" },
119 { "min_exp" },
120 { "re" },
121 { "im" },
123 { "C" },
124 { "D" },
125 { "Windows" },
126 { "Pascal" },
127 { "System" },
129 { "exit" },
130 { "success" },
131 { "failure" },
133 { "keys" },
134 { "values" },
135 { "rehash" },
137 { "sort" },
138 { "reverse" },
139 { "dup" },
140 { "idup" },
142 // For inline assembler
143 { "___out", "out" },
144 { "___in", "in" },
145 { "__int", "int" },
146 { "__dollar", "$" },
147 { "__LOCAL_SIZE" },
149 // For operator overloads
150 { "uadd", "opPos" },
151 { "neg", "opNeg" },
152 { "com", "opCom" },
153 { "add", "opAdd" },
154 { "add_r", "opAdd_r" },
155 { "sub", "opSub" },
156 { "sub_r", "opSub_r" },
157 { "mul", "opMul" },
158 { "mul_r", "opMul_r" },
159 { "div", "opDiv" },
160 { "div_r", "opDiv_r" },
161 { "mod", "opMod" },
162 { "mod_r", "opMod_r" },
163 { "eq", "opEquals" },
164 { "cmp", "opCmp" },
165 { "iand", "opAnd" },
166 { "iand_r", "opAnd_r" },
167 { "ior", "opOr" },
168 { "ior_r", "opOr_r" },
169 { "ixor", "opXor" },
170 { "ixor_r", "opXor_r" },
171 { "shl", "opShl" },
172 { "shl_r", "opShl_r" },
173 { "shr", "opShr" },
174 { "shr_r", "opShr_r" },
175 { "ushr", "opUShr" },
176 { "ushr_r", "opUShr_r" },
177 { "cat", "opCat" },
178 { "cat_r", "opCat_r" },
179 { "assign", "opAssign" },
180 { "addass", "opAddAssign" },
181 { "subass", "opSubAssign" },
182 { "mulass", "opMulAssign" },
183 { "divass", "opDivAssign" },
184 { "modass", "opModAssign" },
185 { "andass", "opAndAssign" },
186 { "orass", "opOrAssign" },
187 { "xorass", "opXorAssign" },
188 { "shlass", "opShlAssign" },
189 { "shrass", "opShrAssign" },
190 { "ushrass", "opUShrAssign" },
191 { "catass", "opCatAssign" },
192 { "postinc", "opPostInc" },
193 { "postdec", "opPostDec" },
194 { "index", "opIndex" },
195 { "indexass", "opIndexAssign" },
196 { "slice", "opSlice" },
197 { "sliceass", "opSliceAssign" },
198 { "call", "opCall" },
199 { "cast", "opCast" },
200 { "match", "opMatch" },
201 { "next", "opNext" },
202 { "opIn" },
203 { "opIn_r" },
204 { "opStar" },
205 { "opDot" },
206 { "opImplicitCast" },
208 { "classNew", "new" },
209 { "classDelete", "delete" },
211 // For foreach
212 { "apply", "opApply" },
213 { "applyReverse", "opApplyReverse" },
215 { "adDup", "_adDupT" },
216 { "adReverse", "_adReverse" },
218 // For internal functions
219 { "aaLen", "_aaLen" },
220 { "aaKeys", "_aaKeys" },
221 { "aaValues", "_aaValues" },
222 { "aaRehash", "_aaRehash" },
224 // Delight
225 { "dlt" },
226 { "core" },
227 { "_externals" },
228 { "Externals" },
229 { "externals" },
230 { "args" },
231 { "__log" }, // dlt.core.__log
232 { "SystemExit" },
234 // For pragma's
235 { "GNU_asm" },
236 { "GNU_attribute" },
237 { "GNU_set_attribute" },
238 { "lib" },
239 { "msg" },
240 { "startaddress" },
242 // For special functions
243 { "tohash", "toHash" },
244 { "tostring", "toString" },
245 { "getmembers", "getMembers" },
247 // Special functions
248 { "alloca" },
249 { "main" },
250 { "WinMain" },
251 { "DllMain" },
253 // Builtin functions
254 { "std" },
255 { "math" },
256 { "sin" },
257 { "cos" },
258 { "tan" },
259 { "_sqrt", "sqrt" },
260 { "fabs" },
262 // Traits
263 { "isAbstractClass" },
264 { "isArithmetic" },
265 { "isAssociativeArray" },
266 { "isFinalClass" },
267 { "isFloating" },
268 { "isIntegral" },
269 { "isScalar" },
270 { "isStaticArray" },
271 { "isUnsigned" },
272 { "isVirtualFunction" },
273 { "isAbstractFunction" },
274 { "isFinalFunction" },
275 { "hasMember" },
276 { "getMember" },
277 { "getVirtualFunctions" },
278 { "classInstanceSize" },
279 { "allMembers" },
280 { "derivedMembers" },
281 { "isSame" },
282 { "compiles" },
284 // Special classes
285 { "Main" },
289 int main()
291 FILE *fp;
292 unsigned i;
295 fp = fopen("id.h","w");
296 if (!fp)
297 { printf("can't open id.h\n");
298 exit(EXIT_FAILURE);
301 fprintf(fp, "// File generated by idgen.c\n");
302 #if __DMC__
303 fprintf(fp, "#pragma once\n");
304 #endif
305 fprintf(fp, "#ifndef DMD_ID_H\n");
306 fprintf(fp, "#define DMD_ID_H 1\n");
307 fprintf(fp, "struct Identifier;\n");
308 fprintf(fp, "struct Id\n");
309 fprintf(fp, "{\n");
311 for (i = 0; i < sizeof(msgtable) / sizeof(msgtable[0]); i++)
312 { char *id = msgtable[i].ident;
314 fprintf(fp," static Identifier *%s;\n", id);
317 fprintf(fp, " static void initialize();\n");
318 fprintf(fp, "};\n");
319 fprintf(fp, "#endif\n");
321 fclose(fp);
325 fp = fopen("id.c","w");
326 if (!fp)
327 { printf("can't open id.c\n");
328 exit(EXIT_FAILURE);
331 fprintf(fp, "// File generated by idgen.c\n");
332 fprintf(fp, "#include \"id.h\"\n");
333 fprintf(fp, "#include \"identifier.h\"\n");
334 fprintf(fp, "#include \"lexer.h\"\n");
336 for (i = 0; i < sizeof(msgtable) / sizeof(msgtable[0]); i++)
337 { char *id = msgtable[i].ident;
338 char *p = msgtable[i].name;
340 if (!p)
341 p = id;
342 fprintf(fp,"Identifier *Id::%s;\n", id);
345 fprintf(fp, "void Id::initialize()\n");
346 fprintf(fp, "{\n");
348 for (i = 0; i < sizeof(msgtable) / sizeof(msgtable[0]); i++)
349 { char *id = msgtable[i].ident;
350 char *p = msgtable[i].name;
352 if (!p)
353 p = id;
354 fprintf(fp," %s = Lexer::idPool(\"%s\");\n", id, p);
357 fprintf(fp, "}\n");
359 fclose(fp);
362 return EXIT_SUCCESS;