Fixed parsing of maybe types in statements
[delight/core.git] / dmd2 / idgen.c
blob98e168f9db51efa9e998871b85efe5b5f4cfa9b2
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_Array" },
86 { "TypeInfo_StaticArray" },
87 { "TypeInfo_AssociativeArray" },
88 { "TypeInfo_Function" },
89 { "TypeInfo_Delegate" },
90 { "TypeInfo_Tuple" },
91 { "TypeInfo_Const" },
92 { "TypeInfo_Invariant" },
93 { "elements" },
94 { "_arguments_typeinfo" },
95 { "_arguments" },
96 { "_argptr" },
97 { "_match" },
98 { "destroy" },
99 { "postblit" },
101 { "LINE", "__LINE__" },
102 { "FILE", "__FILE__" },
103 { "DATE", "__DATE__" },
104 { "TIME", "__TIME__" },
105 { "TIMESTAMP", "__TIMESTAMP__" },
106 { "VENDOR", "__VENDOR__" },
107 { "VERSIONX", "__VERSION__" },
108 { "EOFX", "__EOF__" },
110 { "nan" },
111 { "infinity" },
112 { "dig" },
113 { "epsilon" },
114 { "mant_dig" },
115 { "max_10_exp" },
116 { "max_exp" },
117 { "min_10_exp" },
118 { "min_exp" },
119 { "re" },
120 { "im" },
122 { "C" },
123 { "D" },
124 { "Windows" },
125 { "Pascal" },
126 { "System" },
128 { "exit" },
129 { "success" },
130 { "failure" },
132 { "keys" },
133 { "values" },
134 { "rehash" },
136 { "sort" },
137 { "reverse" },
138 { "dup" },
139 { "idup" },
141 // For inline assembler
142 { "___out", "out" },
143 { "___in", "in" },
144 { "__int", "int" },
145 { "__dollar", "$" },
146 { "__LOCAL_SIZE" },
148 // For operator overloads
149 { "uadd", "opPos" },
150 { "neg", "opNeg" },
151 { "com", "opCom" },
152 { "add", "opAdd" },
153 { "add_r", "opAdd_r" },
154 { "sub", "opSub" },
155 { "sub_r", "opSub_r" },
156 { "mul", "opMul" },
157 { "mul_r", "opMul_r" },
158 { "div", "opDiv" },
159 { "div_r", "opDiv_r" },
160 { "mod", "opMod" },
161 { "mod_r", "opMod_r" },
162 { "eq", "opEquals" },
163 { "cmp", "opCmp" },
164 { "iand", "opAnd" },
165 { "iand_r", "opAnd_r" },
166 { "ior", "opOr" },
167 { "ior_r", "opOr_r" },
168 { "ixor", "opXor" },
169 { "ixor_r", "opXor_r" },
170 { "shl", "opShl" },
171 { "shl_r", "opShl_r" },
172 { "shr", "opShr" },
173 { "shr_r", "opShr_r" },
174 { "ushr", "opUShr" },
175 { "ushr_r", "opUShr_r" },
176 { "cat", "opCat" },
177 { "cat_r", "opCat_r" },
178 { "assign", "opAssign" },
179 { "addass", "opAddAssign" },
180 { "subass", "opSubAssign" },
181 { "mulass", "opMulAssign" },
182 { "divass", "opDivAssign" },
183 { "modass", "opModAssign" },
184 { "andass", "opAndAssign" },
185 { "orass", "opOrAssign" },
186 { "xorass", "opXorAssign" },
187 { "shlass", "opShlAssign" },
188 { "shrass", "opShrAssign" },
189 { "ushrass", "opUShrAssign" },
190 { "catass", "opCatAssign" },
191 { "postinc", "opPostInc" },
192 { "postdec", "opPostDec" },
193 { "index", "opIndex" },
194 { "indexass", "opIndexAssign" },
195 { "slice", "opSlice" },
196 { "sliceass", "opSliceAssign" },
197 { "call", "opCall" },
198 { "cast", "opCast" },
199 { "match", "opMatch" },
200 { "next", "opNext" },
201 { "opIn" },
202 { "opIn_r" },
203 { "opStar" },
204 { "opDot" },
205 { "opImplicitCast" },
207 { "classNew", "new" },
208 { "classDelete", "delete" },
210 // For foreach
211 { "apply", "opApply" },
212 { "applyReverse", "opApplyReverse" },
214 { "adDup", "_adDupT" },
215 { "adReverse", "_adReverse" },
217 // For internal functions
218 { "aaLen", "_aaLen" },
219 { "aaKeys", "_aaKeys" },
220 { "aaValues", "_aaValues" },
221 { "aaRehash", "_aaRehash" },
223 // For pragma's
224 { "GNU_asm" },
225 { "GNU_attribute" },
226 { "GNU_set_attribute" },
227 { "lib" },
228 { "msg" },
229 { "startaddress" },
231 // For special functions
232 { "tohash", "toHash" },
233 { "tostring", "toString" },
234 { "getmembers", "getMembers" },
236 // Special functions
237 { "alloca" },
238 { "main" },
239 { "WinMain" },
240 { "DllMain" },
242 // Builtin functions
243 { "std" },
244 { "math" },
245 { "sin" },
246 { "cos" },
247 { "tan" },
248 { "_sqrt", "sqrt" },
249 { "fabs" },
251 // Traits
252 { "isAbstractClass" },
253 { "isArithmetic" },
254 { "isAssociativeArray" },
255 { "isFinalClass" },
256 { "isFloating" },
257 { "isIntegral" },
258 { "isScalar" },
259 { "isStaticArray" },
260 { "isUnsigned" },
261 { "isVirtualFunction" },
262 { "isAbstractFunction" },
263 { "isFinalFunction" },
264 { "hasMember" },
265 { "getMember" },
266 { "getVirtualFunctions" },
267 { "classInstanceSize" },
268 { "allMembers" },
269 { "derivedMembers" },
270 { "isSame" },
271 { "compiles" },
275 int main()
277 FILE *fp;
278 unsigned i;
281 fp = fopen("id.h","w");
282 if (!fp)
283 { printf("can't open id.h\n");
284 exit(EXIT_FAILURE);
287 fprintf(fp, "// File generated by idgen.c\n");
288 #if __DMC__
289 fprintf(fp, "#pragma once\n");
290 #endif
291 fprintf(fp, "#ifndef DMD_ID_H\n");
292 fprintf(fp, "#define DMD_ID_H 1\n");
293 fprintf(fp, "struct Identifier;\n");
294 fprintf(fp, "struct Id\n");
295 fprintf(fp, "{\n");
297 for (i = 0; i < sizeof(msgtable) / sizeof(msgtable[0]); i++)
298 { char *id = msgtable[i].ident;
300 fprintf(fp," static Identifier *%s;\n", id);
303 fprintf(fp, " static void initialize();\n");
304 fprintf(fp, "};\n");
305 fprintf(fp, "#endif\n");
307 fclose(fp);
311 fp = fopen("id.c","w");
312 if (!fp)
313 { printf("can't open id.c\n");
314 exit(EXIT_FAILURE);
317 fprintf(fp, "// File generated by idgen.c\n");
318 fprintf(fp, "#include \"id.h\"\n");
319 fprintf(fp, "#include \"identifier.h\"\n");
320 fprintf(fp, "#include \"lexer.h\"\n");
322 for (i = 0; i < sizeof(msgtable) / sizeof(msgtable[0]); i++)
323 { char *id = msgtable[i].ident;
324 char *p = msgtable[i].name;
326 if (!p)
327 p = id;
328 fprintf(fp,"Identifier *Id::%s;\n", id);
331 fprintf(fp, "void Id::initialize()\n");
332 fprintf(fp, "{\n");
334 for (i = 0; i < sizeof(msgtable) / sizeof(msgtable[0]); i++)
335 { char *id = msgtable[i].ident;
336 char *p = msgtable[i].name;
338 if (!p)
339 p = id;
340 fprintf(fp," %s = Lexer::idPool(\"%s\");\n", id, p);
343 fprintf(fp, "}\n");
345 fclose(fp);
348 return EXIT_SUCCESS;