Allow implicit cast from null to maybe types ("Type?")
[delight/core.git] / dmd / idgen.c
blob679ecdea1a80fd25874eaf9a59d7cb9bb44ca341
2 // Compiler implementation of the D programming language
3 // Copyright (c) 1999-2006 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 { "dtor", "_dtor" },
45 { "classInvariant", "__invariant" },
46 { "unitTest", "_unitTest" },
47 { "init" },
48 { "size" },
49 { "__sizeof", "sizeof" },
50 { "alignof" },
51 { "mangleof" },
52 { "stringof" },
53 { "tupleof" },
54 { "length" },
55 { "remove" },
56 { "ptr" },
57 { "funcptr" },
58 { "dollar", "__dollar" },
59 { "offset" },
60 { "offsetof" },
61 { "ModuleInfo" },
62 { "ClassInfo" },
63 { "classinfo" },
64 { "typeinfo" },
65 { "outer" },
66 { "Exception" },
67 { "withSym", "__withSym" },
68 { "result", "__result" },
69 { "returnLabel", "__returnLabel" },
70 { "delegate" },
71 { "line" },
72 { "empty", "" },
73 { "p" },
74 { "coverage", "__coverage" },
76 { "TypeInfo" },
77 { "TypeInfo_Class" },
78 { "TypeInfo_Interface" },
79 { "TypeInfo_Struct" },
80 { "TypeInfo_Enum" },
81 { "TypeInfo_Typedef" },
82 { "TypeInfo_Pointer" },
83 { "TypeInfo_Maybe" },
84 { "TypeInfo_Array" },
85 { "TypeInfo_StaticArray" },
86 { "TypeInfo_AssociativeArray" },
87 { "TypeInfo_Function" },
88 { "TypeInfo_Delegate" },
89 { "TypeInfo_Tuple" },
90 { "TypeInfo_Const" },
91 { "TypeInfo_Invariant" },
92 { "elements" },
93 { "_arguments_typeinfo" },
94 { "_arguments" },
95 { "_argptr" },
96 { "_match" },
98 { "LINE", "__LINE__" },
99 { "FILE", "__FILE__" },
100 { "DATE", "__DATE__" },
101 { "TIME", "__TIME__" },
102 { "TIMESTAMP", "__TIMESTAMP__" },
103 { "VENDOR", "__VENDOR__" },
104 { "VERSIONX", "__VERSION__" },
106 { "nan" },
107 { "infinity" },
108 { "dig" },
109 { "epsilon" },
110 { "mant_dig" },
111 { "max_10_exp" },
112 { "max_exp" },
113 { "min_10_exp" },
114 { "min_exp" },
115 { "re" },
116 { "im" },
118 { "C" },
119 { "D" },
120 { "Windows" },
121 { "Pascal" },
122 { "System" },
124 { "exit" },
125 { "success" },
126 { "failure" },
128 { "keys" },
129 { "values" },
130 { "rehash" },
132 { "sort" },
133 { "reverse" },
134 { "dup" },
135 { "idup" },
137 // For inline assembler
138 { "___out", "out" },
139 { "___in", "in" },
140 { "__int", "int" },
141 { "__dollar", "$" },
142 { "__LOCAL_SIZE" },
144 // For operator overloads
145 { "uadd", "opPos" },
146 { "neg", "opNeg" },
147 { "com", "opCom" },
148 { "add", "opAdd" },
149 { "add_r", "opAdd_r" },
150 { "sub", "opSub" },
151 { "sub_r", "opSub_r" },
152 { "mul", "opMul" },
153 { "mul_r", "opMul_r" },
154 { "div", "opDiv" },
155 { "div_r", "opDiv_r" },
156 { "mod", "opMod" },
157 { "mod_r", "opMod_r" },
158 { "eq", "opEquals" },
159 { "cmp", "opCmp" },
160 { "iand", "opAnd" },
161 { "iand_r", "opAnd_r" },
162 { "ior", "opOr" },
163 { "ior_r", "opOr_r" },
164 { "ixor", "opXor" },
165 { "ixor_r", "opXor_r" },
166 { "shl", "opShl" },
167 { "shl_r", "opShl_r" },
168 { "shr", "opShr" },
169 { "shr_r", "opShr_r" },
170 { "ushr", "opUShr" },
171 { "ushr_r", "opUShr_r" },
172 { "cat", "opCat" },
173 { "cat_r", "opCat_r" },
174 { "assign", "opAssign" },
175 { "addass", "opAddAssign" },
176 { "subass", "opSubAssign" },
177 { "mulass", "opMulAssign" },
178 { "divass", "opDivAssign" },
179 { "modass", "opModAssign" },
180 { "andass", "opAndAssign" },
181 { "orass", "opOrAssign" },
182 { "xorass", "opXorAssign" },
183 { "shlass", "opShlAssign" },
184 { "shrass", "opShrAssign" },
185 { "ushrass", "opUShrAssign" },
186 { "catass", "opCatAssign" },
187 { "postinc", "opPostInc" },
188 { "postdec", "opPostDec" },
189 { "index", "opIndex" },
190 { "indexass", "opIndexAssign" },
191 { "slice", "opSlice" },
192 { "sliceass", "opSliceAssign" },
193 { "call", "opCall" },
194 { "cast", "opCast" },
195 { "match", "opMatch" },
196 { "next", "opNext" },
197 { "opIn" },
198 { "opIn_r" },
200 { "classNew", "new" },
201 { "classDelete", "delete" },
203 // For foreach
204 { "apply", "opApply" },
205 { "applyReverse", "opApplyReverse" },
207 { "adDup", "_adDupT" },
208 { "adReverse", "_adReverse" },
210 // For internal functions
211 { "aaLen", "_aaLen" },
212 { "aaKeys", "_aaKeys" },
213 { "aaValues", "_aaValues" },
214 { "aaRehash", "_aaRehash" },
216 // Delight
217 { "dlt" },
218 { "core" },
219 { "_externals" },
220 { "Externals" },
221 { "externals" },
222 { "args" },
223 { "__log" }, // dlt.core.__log
225 // For pragma's
226 { "lib" },
227 { "msg" },
228 { "GNU_asm" },
229 { "GNU_attribute" },
230 { "GNU_set_attribute" },
232 // For toHash/toString
233 { "tohash", "toHash" },
234 { "tostring", "toString" },
236 // Special functions
237 { "alloca" },
238 { "main" },
239 { "WinMain" },
240 { "DllMain" },
242 // Special classes
243 { "Main" },
247 int main()
249 FILE *fp;
250 unsigned i;
253 fp = fopen("id.h","w");
254 if (!fp)
255 { printf("can't open id.h\n");
256 exit(EXIT_FAILURE);
259 fprintf(fp, "// File generated by idgen.c\n");
260 #if __DMC__
261 fprintf(fp, "#pragma once\n");
262 #endif
263 fprintf(fp, "#ifndef DMD_ID_H\n");
264 fprintf(fp, "#define DMD_ID_H 1\n");
265 fprintf(fp, "struct Identifier;\n");
266 fprintf(fp, "struct Id\n");
267 fprintf(fp, "{\n");
269 for (i = 0; i < sizeof(msgtable) / sizeof(msgtable[0]); i++)
270 { char *id = msgtable[i].ident;
272 fprintf(fp," static Identifier *%s;\n", id);
275 fprintf(fp, " static void initialize();\n");
276 fprintf(fp, "};\n");
277 fprintf(fp, "#endif\n");
279 fclose(fp);
283 fp = fopen("id.c","w");
284 if (!fp)
285 { printf("can't open id.c\n");
286 exit(EXIT_FAILURE);
289 fprintf(fp, "// File generated by idgen.c\n");
290 fprintf(fp, "#include \"id.h\"\n");
291 fprintf(fp, "#include \"identifier.h\"\n");
292 fprintf(fp, "#include \"lexer.h\"\n");
294 for (i = 0; i < sizeof(msgtable) / sizeof(msgtable[0]); i++)
295 { char *id = msgtable[i].ident;
296 char *p = msgtable[i].name;
298 if (!p)
299 p = id;
300 fprintf(fp,"Identifier *Id::%s;\n", id);
303 fprintf(fp, "void Id::initialize()\n");
304 fprintf(fp, "{\n");
306 for (i = 0; i < sizeof(msgtable) / sizeof(msgtable[0]); i++)
307 { char *id = msgtable[i].ident;
308 char *p = msgtable[i].name;
310 if (!p)
311 p = id;
312 fprintf(fp," %s = Lexer::idPool(\"%s\");\n", id, p);
315 fprintf(fp, "}\n");
317 fclose(fp);
320 return EXIT_SUCCESS;