Mercurial > projects > ldc
annotate dmd/idgen.c @ 837:331a176c1f4f
Removed error on naked, not fully complete, but I'll be doing more work on it during this Christmas, and some things do work.
Fixed taking delegate of final class method. see mini/delegate3.d.
author | Tomas Lindquist Olsen <tomas.l.olsen@gmail.com> |
---|---|
date | Tue, 09 Dec 2008 14:07:30 +0100 |
parents | 6aaa3d3c1183 |
children | 03d7c4aac654 |
rev | line source |
---|---|
336 | 1 |
2 // Compiler implementation of the D programming language | |
658
50383e476c7e
Upgraded frontend to DMD 1.035
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
3 // Copyright (c) 1999-2008 by Digital Mars |
336 | 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 { | |
658
50383e476c7e
Upgraded frontend to DMD 1.035
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
25 const char *ident; // name to use in DMD source |
50383e476c7e
Upgraded frontend to DMD 1.035
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
26 const char *name; // name in D executable |
336 | 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 { "__vptr" }, | |
70 { "__monitor" }, | |
71 | |
72 { "TypeInfo" }, | |
73 { "TypeInfo_Class" }, | |
74 { "TypeInfo_Interface" }, | |
75 { "TypeInfo_Struct" }, | |
76 { "TypeInfo_Enum" }, | |
77 { "TypeInfo_Typedef" }, | |
78 { "TypeInfo_Pointer" }, | |
79 { "TypeInfo_Array" }, | |
80 { "TypeInfo_StaticArray" }, | |
81 { "TypeInfo_AssociativeArray" }, | |
82 { "TypeInfo_Function" }, | |
83 { "TypeInfo_Delegate" }, | |
84 { "TypeInfo_Tuple" }, | |
85 { "TypeInfo_Const" }, | |
86 { "TypeInfo_Invariant" }, | |
87 { "elements" }, | |
88 { "_arguments_typeinfo" }, | |
89 { "_arguments" }, | |
90 { "_argptr" }, | |
91 { "_match" }, | |
92 | |
93 { "LINE", "__LINE__" }, | |
94 { "FILE", "__FILE__" }, | |
95 { "DATE", "__DATE__" }, | |
96 { "TIME", "__TIME__" }, | |
97 { "TIMESTAMP", "__TIMESTAMP__" }, | |
98 { "VENDOR", "__VENDOR__" }, | |
99 { "VERSIONX", "__VERSION__" }, | |
100 | |
101 { "nan" }, | |
102 { "infinity" }, | |
103 { "dig" }, | |
104 { "epsilon" }, | |
105 { "mant_dig" }, | |
106 { "max_10_exp" }, | |
107 { "max_exp" }, | |
108 { "min_10_exp" }, | |
109 { "min_exp" }, | |
110 { "re" }, | |
111 { "im" }, | |
112 | |
113 { "C" }, | |
114 { "D" }, | |
115 { "Windows" }, | |
116 { "Pascal" }, | |
117 { "System" }, | |
118 | |
119 { "exit" }, | |
120 { "success" }, | |
121 { "failure" }, | |
122 | |
123 { "keys" }, | |
124 { "values" }, | |
125 { "rehash" }, | |
126 | |
127 { "sort" }, | |
128 { "reverse" }, | |
129 { "dup" }, | |
130 { "idup" }, | |
131 | |
132 // For inline assembler | |
133 { "___out", "out" }, | |
134 { "___in", "in" }, | |
135 { "__int", "int" }, | |
136 { "__dollar", "$" }, | |
137 { "__LOCAL_SIZE" }, | |
138 | |
139 // For operator overloads | |
140 { "uadd", "opPos" }, | |
141 { "neg", "opNeg" }, | |
142 { "com", "opCom" }, | |
143 { "add", "opAdd" }, | |
144 { "add_r", "opAdd_r" }, | |
145 { "sub", "opSub" }, | |
146 { "sub_r", "opSub_r" }, | |
147 { "mul", "opMul" }, | |
148 { "mul_r", "opMul_r" }, | |
149 { "div", "opDiv" }, | |
150 { "div_r", "opDiv_r" }, | |
151 { "mod", "opMod" }, | |
152 { "mod_r", "opMod_r" }, | |
153 { "eq", "opEquals" }, | |
154 { "cmp", "opCmp" }, | |
155 { "iand", "opAnd" }, | |
156 { "iand_r", "opAnd_r" }, | |
157 { "ior", "opOr" }, | |
158 { "ior_r", "opOr_r" }, | |
159 { "ixor", "opXor" }, | |
160 { "ixor_r", "opXor_r" }, | |
161 { "shl", "opShl" }, | |
162 { "shl_r", "opShl_r" }, | |
163 { "shr", "opShr" }, | |
164 { "shr_r", "opShr_r" }, | |
165 { "ushr", "opUShr" }, | |
166 { "ushr_r", "opUShr_r" }, | |
167 { "cat", "opCat" }, | |
168 { "cat_r", "opCat_r" }, | |
169 { "assign", "opAssign" }, | |
170 { "addass", "opAddAssign" }, | |
171 { "subass", "opSubAssign" }, | |
172 { "mulass", "opMulAssign" }, | |
173 { "divass", "opDivAssign" }, | |
174 { "modass", "opModAssign" }, | |
175 { "andass", "opAndAssign" }, | |
176 { "orass", "opOrAssign" }, | |
177 { "xorass", "opXorAssign" }, | |
178 { "shlass", "opShlAssign" }, | |
179 { "shrass", "opShrAssign" }, | |
180 { "ushrass", "opUShrAssign" }, | |
181 { "catass", "opCatAssign" }, | |
182 { "postinc", "opPostInc" }, | |
183 { "postdec", "opPostDec" }, | |
184 { "index", "opIndex" }, | |
185 { "indexass", "opIndexAssign" }, | |
186 { "slice", "opSlice" }, | |
187 { "sliceass", "opSliceAssign" }, | |
188 { "call", "opCall" }, | |
189 { "cast", "opCast" }, | |
190 { "match", "opMatch" }, | |
191 { "next", "opNext" }, | |
192 { "opIn" }, | |
193 { "opIn_r" }, | |
194 | |
195 { "classNew", "new" }, | |
196 { "classDelete", "delete" }, | |
197 | |
198 // For foreach | |
199 { "apply", "opApply" }, | |
200 { "applyReverse", "opApplyReverse" }, | |
201 | |
202 { "adDup", "_adDupT" }, | |
203 { "adReverse", "_adReverse" }, | |
204 | |
205 // For internal functions | |
206 { "aaLen", "_aaLen" }, | |
207 { "aaKeys", "_aaKeys" }, | |
208 { "aaValues", "_aaValues" }, | |
209 { "aaRehash", "_aaRehash" }, | |
210 | |
211 // For pragma's | |
658
50383e476c7e
Upgraded frontend to DMD 1.035
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
212 { "GNU_asm" }, |
336 | 213 { "lib" }, |
214 { "msg" }, | |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
215 |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
216 // LDC pragma's |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
217 { "intrinsic" }, |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
218 { "va_intrinsic" }, |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
219 { "no_typeinfo" }, |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
220 { "no_moduleinfo" }, |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
221 { "Alloca", "alloca" }, |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
222 { "vastart", "va_start" }, |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
223 { "vacopy", "va_copy" }, |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
224 { "vaend", "va_end" }, |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
225 { "vaarg", "va_arg" }, |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
226 { "ldc" }, |
336 | 227 |
658
50383e476c7e
Upgraded frontend to DMD 1.035
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
228 // For special functions |
336 | 229 { "tohash", "toHash" }, |
230 { "tostring", "toString" }, | |
231 | |
232 // Special functions | |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
233 //{ "alloca" }, |
336 | 234 { "main" }, |
235 { "WinMain" }, | |
236 { "DllMain" }, | |
237 }; | |
238 | |
239 | |
240 int main() | |
241 { | |
242 FILE *fp; | |
243 unsigned i; | |
244 | |
245 { | |
246 fp = fopen("id.h","w"); | |
247 if (!fp) | |
248 { printf("can't open id.h\n"); | |
249 exit(EXIT_FAILURE); | |
250 } | |
251 | |
252 fprintf(fp, "// File generated by idgen.c\n"); | |
253 #if __DMC__ | |
254 fprintf(fp, "#pragma once\n"); | |
255 #endif | |
256 fprintf(fp, "#ifndef DMD_ID_H\n"); | |
257 fprintf(fp, "#define DMD_ID_H 1\n"); | |
258 fprintf(fp, "struct Identifier;\n"); | |
259 fprintf(fp, "struct Id\n"); | |
260 fprintf(fp, "{\n"); | |
261 | |
262 for (i = 0; i < sizeof(msgtable) / sizeof(msgtable[0]); i++) | |
658
50383e476c7e
Upgraded frontend to DMD 1.035
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
263 { const char *id = msgtable[i].ident; |
336 | 264 |
265 fprintf(fp," static Identifier *%s;\n", id); | |
266 } | |
267 | |
268 fprintf(fp, " static void initialize();\n"); | |
269 fprintf(fp, "};\n"); | |
270 fprintf(fp, "#endif\n"); | |
271 | |
272 fclose(fp); | |
273 } | |
274 | |
275 { | |
276 fp = fopen("id.c","w"); | |
277 if (!fp) | |
278 { printf("can't open id.c\n"); | |
279 exit(EXIT_FAILURE); | |
280 } | |
281 | |
282 fprintf(fp, "// File generated by idgen.c\n"); | |
283 fprintf(fp, "#include \"id.h\"\n"); | |
284 fprintf(fp, "#include \"identifier.h\"\n"); | |
285 fprintf(fp, "#include \"lexer.h\"\n"); | |
286 | |
287 for (i = 0; i < sizeof(msgtable) / sizeof(msgtable[0]); i++) | |
658
50383e476c7e
Upgraded frontend to DMD 1.035
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
288 { const char *id = msgtable[i].ident; |
50383e476c7e
Upgraded frontend to DMD 1.035
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
289 const char *p = msgtable[i].name; |
336 | 290 |
291 if (!p) | |
292 p = id; | |
293 fprintf(fp,"Identifier *Id::%s;\n", id); | |
294 } | |
295 | |
296 fprintf(fp, "void Id::initialize()\n"); | |
297 fprintf(fp, "{\n"); | |
298 | |
299 for (i = 0; i < sizeof(msgtable) / sizeof(msgtable[0]); i++) | |
658
50383e476c7e
Upgraded frontend to DMD 1.035
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
300 { const char *id = msgtable[i].ident; |
50383e476c7e
Upgraded frontend to DMD 1.035
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
301 const char *p = msgtable[i].name; |
336 | 302 |
303 if (!p) | |
304 p = id; | |
305 fprintf(fp," %s = Lexer::idPool(\"%s\");\n", id, p); | |
306 } | |
307 | |
308 fprintf(fp, "}\n"); | |
309 | |
310 fclose(fp); | |
311 } | |
312 | |
313 return EXIT_SUCCESS; | |
314 } |