Allow log_ statements outside of a class
[delight/core.git] / dmd / idgen.c
blob55912b2063c571888ad1b96efb54c938555b20ad
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_Array" },
84 { "TypeInfo_StaticArray" },
85 { "TypeInfo_AssociativeArray" },
86 { "TypeInfo_Function" },
87 { "TypeInfo_Delegate" },
88 { "TypeInfo_Tuple" },
89 { "TypeInfo_Const" },
90 { "TypeInfo_Invariant" },
91 { "elements" },
92 { "_arguments_typeinfo" },
93 { "_arguments" },
94 { "_argptr" },
95 { "_match" },
97 { "LINE", "__LINE__" },
98 { "FILE", "__FILE__" },
99 { "DATE", "__DATE__" },
100 { "TIME", "__TIME__" },
101 { "TIMESTAMP", "__TIMESTAMP__" },
102 { "VENDOR", "__VENDOR__" },
103 { "VERSIONX", "__VERSION__" },
105 { "nan" },
106 { "infinity" },
107 { "dig" },
108 { "epsilon" },
109 { "mant_dig" },
110 { "max_10_exp" },
111 { "max_exp" },
112 { "min_10_exp" },
113 { "min_exp" },
114 { "re" },
115 { "im" },
117 { "C" },
118 { "D" },
119 { "Windows" },
120 { "Pascal" },
121 { "System" },
123 { "exit" },
124 { "success" },
125 { "failure" },
127 { "keys" },
128 { "values" },
129 { "rehash" },
131 { "sort" },
132 { "reverse" },
133 { "dup" },
134 { "idup" },
136 // For inline assembler
137 { "___out", "out" },
138 { "___in", "in" },
139 { "__int", "int" },
140 { "__dollar", "$" },
141 { "__LOCAL_SIZE" },
143 // For operator overloads
144 { "uadd", "opPos" },
145 { "neg", "opNeg" },
146 { "com", "opCom" },
147 { "add", "opAdd" },
148 { "add_r", "opAdd_r" },
149 { "sub", "opSub" },
150 { "sub_r", "opSub_r" },
151 { "mul", "opMul" },
152 { "mul_r", "opMul_r" },
153 { "div", "opDiv" },
154 { "div_r", "opDiv_r" },
155 { "mod", "opMod" },
156 { "mod_r", "opMod_r" },
157 { "eq", "opEquals" },
158 { "cmp", "opCmp" },
159 { "iand", "opAnd" },
160 { "iand_r", "opAnd_r" },
161 { "ior", "opOr" },
162 { "ior_r", "opOr_r" },
163 { "ixor", "opXor" },
164 { "ixor_r", "opXor_r" },
165 { "shl", "opShl" },
166 { "shl_r", "opShl_r" },
167 { "shr", "opShr" },
168 { "shr_r", "opShr_r" },
169 { "ushr", "opUShr" },
170 { "ushr_r", "opUShr_r" },
171 { "cat", "opCat" },
172 { "cat_r", "opCat_r" },
173 { "assign", "opAssign" },
174 { "addass", "opAddAssign" },
175 { "subass", "opSubAssign" },
176 { "mulass", "opMulAssign" },
177 { "divass", "opDivAssign" },
178 { "modass", "opModAssign" },
179 { "andass", "opAndAssign" },
180 { "orass", "opOrAssign" },
181 { "xorass", "opXorAssign" },
182 { "shlass", "opShlAssign" },
183 { "shrass", "opShrAssign" },
184 { "ushrass", "opUShrAssign" },
185 { "catass", "opCatAssign" },
186 { "postinc", "opPostInc" },
187 { "postdec", "opPostDec" },
188 { "index", "opIndex" },
189 { "indexass", "opIndexAssign" },
190 { "slice", "opSlice" },
191 { "sliceass", "opSliceAssign" },
192 { "call", "opCall" },
193 { "cast", "opCast" },
194 { "match", "opMatch" },
195 { "next", "opNext" },
196 { "opIn" },
197 { "opIn_r" },
199 { "classNew", "new" },
200 { "classDelete", "delete" },
202 // For foreach
203 { "apply", "opApply" },
204 { "applyReverse", "opApplyReverse" },
206 { "adDup", "_adDupT" },
207 { "adReverse", "_adReverse" },
209 // For internal functions
210 { "aaLen", "_aaLen" },
211 { "aaKeys", "_aaKeys" },
212 { "aaValues", "_aaValues" },
213 { "aaRehash", "_aaRehash" },
214 { "_externals" },
215 { "Externals" },
216 { "externals" },
217 { "args" },
218 { "__logger" },
219 { "log" }, // getLogger().log()
221 // For pragma's
222 { "lib" },
223 { "msg" },
224 { "GNU_asm" },
225 { "GNU_attribute" },
226 { "GNU_set_attribute" },
228 // For toHash/toString
229 { "tohash", "toHash" },
230 { "tostring", "toString" },
232 // Special functions
233 { "alloca" },
234 { "main" },
235 { "WinMain" },
236 { "DllMain" },
238 // Special classes
239 { "Main" },
243 int main()
245 FILE *fp;
246 unsigned i;
249 fp = fopen("id.h","w");
250 if (!fp)
251 { printf("can't open id.h\n");
252 exit(EXIT_FAILURE);
255 fprintf(fp, "// File generated by idgen.c\n");
256 #if __DMC__
257 fprintf(fp, "#pragma once\n");
258 #endif
259 fprintf(fp, "#ifndef DMD_ID_H\n");
260 fprintf(fp, "#define DMD_ID_H 1\n");
261 fprintf(fp, "struct Identifier;\n");
262 fprintf(fp, "struct Id\n");
263 fprintf(fp, "{\n");
265 for (i = 0; i < sizeof(msgtable) / sizeof(msgtable[0]); i++)
266 { char *id = msgtable[i].ident;
268 fprintf(fp," static Identifier *%s;\n", id);
271 fprintf(fp, " static void initialize();\n");
272 fprintf(fp, "};\n");
273 fprintf(fp, "#endif\n");
275 fclose(fp);
279 fp = fopen("id.c","w");
280 if (!fp)
281 { printf("can't open id.c\n");
282 exit(EXIT_FAILURE);
285 fprintf(fp, "// File generated by idgen.c\n");
286 fprintf(fp, "#include \"id.h\"\n");
287 fprintf(fp, "#include \"identifier.h\"\n");
288 fprintf(fp, "#include \"lexer.h\"\n");
290 for (i = 0; i < sizeof(msgtable) / sizeof(msgtable[0]); i++)
291 { char *id = msgtable[i].ident;
292 char *p = msgtable[i].name;
294 if (!p)
295 p = id;
296 fprintf(fp,"Identifier *Id::%s;\n", id);
299 fprintf(fp, "void Id::initialize()\n");
300 fprintf(fp, "{\n");
302 for (i = 0; i < sizeof(msgtable) / sizeof(msgtable[0]); i++)
303 { char *id = msgtable[i].ident;
304 char *p = msgtable[i].name;
306 if (!p)
307 p = id;
308 fprintf(fp," %s = Lexer::idPool(\"%s\");\n", id, p);
311 fprintf(fp, "}\n");
313 fclose(fp);
316 return EXIT_SUCCESS;