1
|
1
|
|
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.
|
|
10
|
|
11 // Program to generate string files in d data structures.
|
|
12 // Saves much tedious typing, and eliminates typo problems.
|
|
13 // Generates:
|
|
14 // id.h
|
|
15 // id.c
|
|
16
|
|
17 #include <stdio.h>
|
|
18 #include <stdlib.h>
|
|
19 #include <string.h>
|
|
20 #include <stdarg.h>
|
|
21 #include <assert.h>
|
|
22
|
|
23 struct Msgtable
|
|
24 {
|
|
25 char *ident; // name to use in DMD source
|
|
26 char *name; // name in D executable
|
|
27 };
|
|
28
|
|
29 Msgtable msgtable[] =
|
|
30 {
|
|
31 { "IUnknown" },
|
|
32 { "Object" },
|
|
33 { "object" },
|
|
34 { "max" },
|
|
35 { "min" },
|
|
36 { "This", "this" },
|
|
37 { "ctor", "_ctor" },
|
|
38 { "dtor", "_dtor" },
|
|
39 { "classInvariant", "__invariant" },
|
|
40 { "unitTest", "_unitTest" },
|
|
41 { "init" },
|
|
42 { "size" },
|
|
43 { "__sizeof", "sizeof" },
|
|
44 { "alignof" },
|
|
45 { "mangleof" },
|
|
46 { "stringof" },
|
|
47 { "tupleof" },
|
|
48 { "length" },
|
|
49 { "remove" },
|
|
50 { "ptr" },
|
|
51 { "funcptr" },
|
|
52 { "dollar", "__dollar" },
|
|
53 { "offset" },
|
|
54 { "offsetof" },
|
|
55 { "ModuleInfo" },
|
|
56 { "ClassInfo" },
|
|
57 { "classinfo" },
|
|
58 { "typeinfo" },
|
|
59 { "outer" },
|
|
60 { "Exception" },
|
|
61 { "withSym", "__withSym" },
|
|
62 { "result", "__result" },
|
|
63 { "returnLabel", "__returnLabel" },
|
|
64 { "delegate" },
|
|
65 { "line" },
|
|
66 { "empty", "" },
|
|
67 { "p" },
|
|
68 { "coverage", "__coverage" },
|
|
69
|
|
70 { "TypeInfo" },
|
|
71 { "TypeInfo_Class" },
|
|
72 { "TypeInfo_Interface" },
|
|
73 { "TypeInfo_Struct" },
|
|
74 { "TypeInfo_Enum" },
|
|
75 { "TypeInfo_Typedef" },
|
|
76 { "TypeInfo_Pointer" },
|
|
77 { "TypeInfo_Array" },
|
|
78 { "TypeInfo_StaticArray" },
|
|
79 { "TypeInfo_AssociativeArray" },
|
|
80 { "TypeInfo_Function" },
|
|
81 { "TypeInfo_Delegate" },
|
|
82 { "TypeInfo_Tuple" },
|
|
83 { "TypeInfo_Const" },
|
|
84 { "TypeInfo_Invariant" },
|
|
85 { "elements" },
|
|
86 { "_arguments_typeinfo" },
|
|
87 { "_arguments" },
|
|
88 { "_argptr" },
|
|
89 { "_match" },
|
|
90
|
|
91 { "LINE", "__LINE__" },
|
|
92 { "FILE", "__FILE__" },
|
|
93 { "DATE", "__DATE__" },
|
|
94 { "TIME", "__TIME__" },
|
|
95 { "TIMESTAMP", "__TIMESTAMP__" },
|
|
96 { "VENDOR", "__VENDOR__" },
|
|
97 { "VERSIONX", "__VERSION__" },
|
|
98
|
|
99 { "nan" },
|
|
100 { "infinity" },
|
|
101 { "dig" },
|
|
102 { "epsilon" },
|
|
103 { "mant_dig" },
|
|
104 { "max_10_exp" },
|
|
105 { "max_exp" },
|
|
106 { "min_10_exp" },
|
|
107 { "min_exp" },
|
|
108 { "re" },
|
|
109 { "im" },
|
|
110
|
|
111 { "C" },
|
|
112 { "D" },
|
|
113 { "Windows" },
|
|
114 { "Pascal" },
|
|
115 { "System" },
|
|
116
|
|
117 { "exit" },
|
|
118 { "success" },
|
|
119 { "failure" },
|
|
120
|
|
121 { "keys" },
|
|
122 { "values" },
|
|
123 { "rehash" },
|
|
124
|
|
125 { "sort" },
|
|
126 { "reverse" },
|
|
127 { "dup" },
|
|
128 { "idup" },
|
|
129
|
|
130 // For inline assembler
|
|
131 { "___out", "out" },
|
|
132 { "___in", "in" },
|
|
133 { "__int", "int" },
|
|
134 { "__dollar", "$" },
|
|
135 { "__LOCAL_SIZE" },
|
|
136
|
|
137 // For operator overloads
|
|
138 { "uadd", "opPos" },
|
|
139 { "neg", "opNeg" },
|
|
140 { "com", "opCom" },
|
|
141 { "add", "opAdd" },
|
|
142 { "add_r", "opAdd_r" },
|
|
143 { "sub", "opSub" },
|
|
144 { "sub_r", "opSub_r" },
|
|
145 { "mul", "opMul" },
|
|
146 { "mul_r", "opMul_r" },
|
|
147 { "div", "opDiv" },
|
|
148 { "div_r", "opDiv_r" },
|
|
149 { "mod", "opMod" },
|
|
150 { "mod_r", "opMod_r" },
|
|
151 { "eq", "opEquals" },
|
|
152 { "cmp", "opCmp" },
|
|
153 { "iand", "opAnd" },
|
|
154 { "iand_r", "opAnd_r" },
|
|
155 { "ior", "opOr" },
|
|
156 { "ior_r", "opOr_r" },
|
|
157 { "ixor", "opXor" },
|
|
158 { "ixor_r", "opXor_r" },
|
|
159 { "shl", "opShl" },
|
|
160 { "shl_r", "opShl_r" },
|
|
161 { "shr", "opShr" },
|
|
162 { "shr_r", "opShr_r" },
|
|
163 { "ushr", "opUShr" },
|
|
164 { "ushr_r", "opUShr_r" },
|
|
165 { "cat", "opCat" },
|
|
166 { "cat_r", "opCat_r" },
|
|
167 { "assign", "opAssign" },
|
|
168 { "addass", "opAddAssign" },
|
|
169 { "subass", "opSubAssign" },
|
|
170 { "mulass", "opMulAssign" },
|
|
171 { "divass", "opDivAssign" },
|
|
172 { "modass", "opModAssign" },
|
|
173 { "andass", "opAndAssign" },
|
|
174 { "orass", "opOrAssign" },
|
|
175 { "xorass", "opXorAssign" },
|
|
176 { "shlass", "opShlAssign" },
|
|
177 { "shrass", "opShrAssign" },
|
|
178 { "ushrass", "opUShrAssign" },
|
|
179 { "catass", "opCatAssign" },
|
|
180 { "postinc", "opPostInc" },
|
|
181 { "postdec", "opPostDec" },
|
|
182 { "index", "opIndex" },
|
|
183 { "indexass", "opIndexAssign" },
|
|
184 { "slice", "opSlice" },
|
|
185 { "sliceass", "opSliceAssign" },
|
|
186 { "call", "opCall" },
|
|
187 { "cast", "opCast" },
|
|
188 { "match", "opMatch" },
|
|
189 { "next", "opNext" },
|
|
190 { "opIn" },
|
|
191 { "opIn_r" },
|
|
192
|
|
193 { "classNew", "new" },
|
|
194 { "classDelete", "delete" },
|
|
195
|
|
196 // For foreach
|
|
197 { "apply", "opApply" },
|
|
198 { "applyReverse", "opApplyReverse" },
|
|
199
|
|
200 { "adDup", "_adDupT" },
|
|
201 { "adReverse", "_adReverse" },
|
|
202
|
|
203 // For internal functions
|
|
204 { "aaLen", "_aaLen" },
|
|
205 { "aaKeys", "_aaKeys" },
|
|
206 { "aaValues", "_aaValues" },
|
|
207 { "aaRehash", "_aaRehash" },
|
|
208
|
|
209 // For pragma's
|
|
210 { "lib" },
|
|
211 { "msg" },
|
|
212 { "GNU_asm" },
|
|
213 { "LLVM_intrinsic" },
|
|
214 { "LLVM_internal" },
|
|
215
|
|
216 // For toHash/toString
|
|
217 { "tohash", "toHash" },
|
|
218 { "tostring", "toString" },
|
|
219
|
|
220 // Special functions
|
|
221 { "alloca" },
|
|
222 { "main" },
|
|
223 { "WinMain" },
|
|
224 { "DllMain" },
|
|
225 };
|
|
226
|
|
227
|
|
228 int main()
|
|
229 {
|
|
230 FILE *fp;
|
|
231 unsigned i;
|
|
232
|
|
233 {
|
|
234 fp = fopen("id.h","w");
|
|
235 if (!fp)
|
|
236 { printf("can't open id.h\n");
|
|
237 exit(EXIT_FAILURE);
|
|
238 }
|
|
239
|
|
240 fprintf(fp, "// File generated by idgen.c\n");
|
|
241 #if __DMC__
|
|
242 fprintf(fp, "#pragma once\n");
|
|
243 #endif
|
|
244 fprintf(fp, "#ifndef DMD_ID_H\n");
|
|
245 fprintf(fp, "#define DMD_ID_H 1\n");
|
|
246 fprintf(fp, "struct Identifier;\n");
|
|
247 fprintf(fp, "struct Id\n");
|
|
248 fprintf(fp, "{\n");
|
|
249
|
|
250 for (i = 0; i < sizeof(msgtable) / sizeof(msgtable[0]); i++)
|
|
251 { char *id = msgtable[i].ident;
|
|
252
|
|
253 fprintf(fp," static Identifier *%s;\n", id);
|
|
254 }
|
|
255
|
|
256 fprintf(fp, " static void initialize();\n");
|
|
257 fprintf(fp, "};\n");
|
|
258 fprintf(fp, "#endif\n");
|
|
259
|
|
260 fclose(fp);
|
|
261 }
|
|
262
|
|
263 {
|
|
264 fp = fopen("id.c","w");
|
|
265 if (!fp)
|
|
266 { printf("can't open id.c\n");
|
|
267 exit(EXIT_FAILURE);
|
|
268 }
|
|
269
|
|
270 fprintf(fp, "// File generated by idgen.c\n");
|
|
271 fprintf(fp, "#include \"id.h\"\n");
|
|
272 fprintf(fp, "#include \"identifier.h\"\n");
|
|
273 fprintf(fp, "#include \"lexer.h\"\n");
|
|
274
|
|
275 for (i = 0; i < sizeof(msgtable) / sizeof(msgtable[0]); i++)
|
|
276 { char *id = msgtable[i].ident;
|
|
277 char *p = msgtable[i].name;
|
|
278
|
|
279 if (!p)
|
|
280 p = id;
|
|
281 fprintf(fp,"Identifier *Id::%s;\n", id);
|
|
282 }
|
|
283
|
|
284 fprintf(fp, "void Id::initialize()\n");
|
|
285 fprintf(fp, "{\n");
|
|
286
|
|
287 for (i = 0; i < sizeof(msgtable) / sizeof(msgtable[0]); i++)
|
|
288 { char *id = msgtable[i].ident;
|
|
289 char *p = msgtable[i].name;
|
|
290
|
|
291 if (!p)
|
|
292 p = id;
|
|
293 fprintf(fp," %s = Lexer::idPool(\"%s\");\n", id, p);
|
|
294 }
|
|
295
|
|
296 fprintf(fp, "}\n");
|
|
297
|
|
298 fclose(fp);
|
|
299 }
|
|
300
|
|
301 return EXIT_SUCCESS;
|
|
302 }
|