comparison dmd/Lexer.d @ 162:438eaa11eed4

updated build script to use dmd2.039 some missing methods implemented
author korDen
date Tue, 21 Sep 2010 14:59:56 +0400
parents b7b61140701d
children fe932c1a9563
comparison
equal deleted inserted replaced
161:584dc990e12f 162:438eaa11eed4
33 extern (C) extern 33 extern (C) extern
34 { 34 {
35 __gshared char* __locale_decpoint; 35 __gshared char* __locale_decpoint;
36 } 36 }
37 37
38 int isUniAlpha(uint u) 38 bool isUniAlpha(uint u)
39 { 39 {
40 assert(false); 40 static ushort table[][2] =
41 [
42 [ 0x00AA, 0x00AA ],
43 [ 0x00B5, 0x00B5 ],
44 [ 0x00B7, 0x00B7 ],
45 [ 0x00BA, 0x00BA ],
46 [ 0x00C0, 0x00D6 ],
47 [ 0x00D8, 0x00F6 ],
48 [ 0x00F8, 0x01F5 ],
49 [ 0x01FA, 0x0217 ],
50 [ 0x0250, 0x02A8 ],
51 [ 0x02B0, 0x02B8 ],
52 [ 0x02BB, 0x02BB ],
53 [ 0x02BD, 0x02C1 ],
54 [ 0x02D0, 0x02D1 ],
55 [ 0x02E0, 0x02E4 ],
56 [ 0x037A, 0x037A ],
57 [ 0x0386, 0x0386 ],
58 [ 0x0388, 0x038A ],
59 [ 0x038C, 0x038C ],
60 [ 0x038E, 0x03A1 ],
61 [ 0x03A3, 0x03CE ],
62 [ 0x03D0, 0x03D6 ],
63 [ 0x03DA, 0x03DA ],
64 [ 0x03DC, 0x03DC ],
65 [ 0x03DE, 0x03DE ],
66 [ 0x03E0, 0x03E0 ],
67 [ 0x03E2, 0x03F3 ],
68 [ 0x0401, 0x040C ],
69 [ 0x040E, 0x044F ],
70 [ 0x0451, 0x045C ],
71 [ 0x045E, 0x0481 ],
72 [ 0x0490, 0x04C4 ],
73 [ 0x04C7, 0x04C8 ],
74 [ 0x04CB, 0x04CC ],
75 [ 0x04D0, 0x04EB ],
76 [ 0x04EE, 0x04F5 ],
77 [ 0x04F8, 0x04F9 ],
78 [ 0x0531, 0x0556 ],
79 [ 0x0559, 0x0559 ],
80 [ 0x0561, 0x0587 ],
81 [ 0x05B0, 0x05B9 ],
82 [ 0x05BB, 0x05BD ],
83 [ 0x05BF, 0x05BF ],
84 [ 0x05C1, 0x05C2 ],
85 [ 0x05D0, 0x05EA ],
86 [ 0x05F0, 0x05F2 ],
87 [ 0x0621, 0x063A ],
88 [ 0x0640, 0x0652 ],
89 [ 0x0660, 0x0669 ],
90 [ 0x0670, 0x06B7 ],
91 [ 0x06BA, 0x06BE ],
92 [ 0x06C0, 0x06CE ],
93 [ 0x06D0, 0x06DC ],
94 [ 0x06E5, 0x06E8 ],
95 [ 0x06EA, 0x06ED ],
96 [ 0x06F0, 0x06F9 ],
97 [ 0x0901, 0x0903 ],
98 [ 0x0905, 0x0939 ],
99 [ 0x093D, 0x093D ],
100 [ 0x093E, 0x094D ],
101 [ 0x0950, 0x0952 ],
102 [ 0x0958, 0x0963 ],
103 [ 0x0966, 0x096F ],
104 [ 0x0981, 0x0983 ],
105 [ 0x0985, 0x098C ],
106 [ 0x098F, 0x0990 ],
107 [ 0x0993, 0x09A8 ],
108 [ 0x09AA, 0x09B0 ],
109 [ 0x09B2, 0x09B2 ],
110 [ 0x09B6, 0x09B9 ],
111 [ 0x09BE, 0x09C4 ],
112 [ 0x09C7, 0x09C8 ],
113 [ 0x09CB, 0x09CD ],
114 [ 0x09DC, 0x09DD ],
115 [ 0x09DF, 0x09E3 ],
116 [ 0x09E6, 0x09EF ],
117 [ 0x09F0, 0x09F1 ],
118 [ 0x0A02, 0x0A02 ],
119 [ 0x0A05, 0x0A0A ],
120 [ 0x0A0F, 0x0A10 ],
121 [ 0x0A13, 0x0A28 ],
122 [ 0x0A2A, 0x0A30 ],
123 [ 0x0A32, 0x0A33 ],
124 [ 0x0A35, 0x0A36 ],
125 [ 0x0A38, 0x0A39 ],
126 [ 0x0A3E, 0x0A42 ],
127 [ 0x0A47, 0x0A48 ],
128 [ 0x0A4B, 0x0A4D ],
129 [ 0x0A59, 0x0A5C ],
130 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 ],
177 [ 0x0C05, 0x0C0C ],
178 [ 0x0C0E, 0x0C10 ],
179 [ 0x0C12, 0x0C28 ],
180 [ 0x0C2A, 0x0C33 ],
181 [ 0x0C35, 0x0C39 ],
182 [ 0x0C3E, 0x0C44 ],
183 [ 0x0C46, 0x0C48 ],
184 [ 0x0C4A, 0x0C4D ],
185 [ 0x0C60, 0x0C61 ],
186 [ 0x0C66, 0x0C6F ],
187 [ 0x0C82, 0x0C83 ],
188 [ 0x0C85, 0x0C8C ],
189 [ 0x0C8E, 0x0C90 ],
190 [ 0x0C92, 0x0CA8 ],
191 [ 0x0CAA, 0x0CB3 ],
192 [ 0x0CB5, 0x0CB9 ],
193 [ 0x0CBE, 0x0CC4 ],
194 [ 0x0CC6, 0x0CC8 ],
195 [ 0x0CCA, 0x0CCD ],
196 [ 0x0CDE, 0x0CDE ],
197 [ 0x0CE0, 0x0CE1 ],
198 [ 0x0CE6, 0x0CEF ],
199 [ 0x0D02, 0x0D03 ],
200 [ 0x0D05, 0x0D0C ],
201 [ 0x0D0E, 0x0D10 ],
202 [ 0x0D12, 0x0D28 ],
203 [ 0x0D2A, 0x0D39 ],
204 [ 0x0D3E, 0x0D43 ],
205 [ 0x0D46, 0x0D48 ],
206 [ 0x0D4A, 0x0D4D ],
207 [ 0x0D60, 0x0D61 ],
208 [ 0x0D66, 0x0D6F ],
209 [ 0x0E01, 0x0E3A ],
210 [ 0x0E40, 0x0E5B ],
211 // { 0x0E50, 0x0E59 },
212 [ 0x0E81, 0x0E82 ],
213 [ 0x0E84, 0x0E84 ],
214 [ 0x0E87, 0x0E88 ],
215 [ 0x0E8A, 0x0E8A ],
216 [ 0x0E8D, 0x0E8D ],
217 [ 0x0E94, 0x0E97 ],
218 [ 0x0E99, 0x0E9F ],
219 [ 0x0EA1, 0x0EA3 ],
220 [ 0x0EA5, 0x0EA5 ],
221 [ 0x0EA7, 0x0EA7 ],
222 [ 0x0EAA, 0x0EAB ],
223 [ 0x0EAD, 0x0EAE ],
224 [ 0x0EB0, 0x0EB9 ],
225 [ 0x0EBB, 0x0EBD ],
226 [ 0x0EC0, 0x0EC4 ],
227 [ 0x0EC6, 0x0EC6 ],
228 [ 0x0EC8, 0x0ECD ],
229 [ 0x0ED0, 0x0ED9 ],
230 [ 0x0EDC, 0x0EDD ],
231 [ 0x0F00, 0x0F00 ],
232 [ 0x0F18, 0x0F19 ],
233 [ 0x0F20, 0x0F33 ],
234 [ 0x0F35, 0x0F35 ],
235 [ 0x0F37, 0x0F37 ],
236 [ 0x0F39, 0x0F39 ],
237 [ 0x0F3E, 0x0F47 ],
238 [ 0x0F49, 0x0F69 ],
239 [ 0x0F71, 0x0F84 ],
240 [ 0x0F86, 0x0F8B ],
241 [ 0x0F90, 0x0F95 ],
242 [ 0x0F97, 0x0F97 ],
243 [ 0x0F99, 0x0FAD ],
244 [ 0x0FB1, 0x0FB7 ],
245 [ 0x0FB9, 0x0FB9 ],
246 [ 0x10A0, 0x10C5 ],
247 [ 0x10D0, 0x10F6 ],
248 [ 0x1E00, 0x1E9B ],
249 [ 0x1EA0, 0x1EF9 ],
250 [ 0x1F00, 0x1F15 ],
251 [ 0x1F18, 0x1F1D ],
252 [ 0x1F20, 0x1F45 ],
253 [ 0x1F48, 0x1F4D ],
254 [ 0x1F50, 0x1F57 ],
255 [ 0x1F59, 0x1F59 ],
256 [ 0x1F5B, 0x1F5B ],
257 [ 0x1F5D, 0x1F5D ],
258 [ 0x1F5F, 0x1F7D ],
259 [ 0x1F80, 0x1FB4 ],
260 [ 0x1FB6, 0x1FBC ],
261 [ 0x1FBE, 0x1FBE ],
262 [ 0x1FC2, 0x1FC4 ],
263 [ 0x1FC6, 0x1FCC ],
264 [ 0x1FD0, 0x1FD3 ],
265 [ 0x1FD6, 0x1FDB ],
266 [ 0x1FE0, 0x1FEC ],
267 [ 0x1FF2, 0x1FF4 ],
268 [ 0x1FF6, 0x1FFC ],
269 [ 0x203F, 0x2040 ],
270 [ 0x207F, 0x207F ],
271 [ 0x2102, 0x2102 ],
272 [ 0x2107, 0x2107 ],
273 [ 0x210A, 0x2113 ],
274 [ 0x2115, 0x2115 ],
275 [ 0x2118, 0x211D ],
276 [ 0x2124, 0x2124 ],
277 [ 0x2126, 0x2126 ],
278 [ 0x2128, 0x2128 ],
279 [ 0x212A, 0x2131 ],
280 [ 0x2133, 0x2138 ],
281 [ 0x2160, 0x2182 ],
282 [ 0x3005, 0x3007 ],
283 [ 0x3021, 0x3029 ],
284 [ 0x3041, 0x3093 ],
285 [ 0x309B, 0x309C ],
286 [ 0x30A1, 0x30F6 ],
287 [ 0x30FB, 0x30FC ],
288 [ 0x3105, 0x312C ],
289 [ 0x4E00, 0x9FA5 ],
290 [ 0xAC00, 0xD7A3 ],
291 ];
292
293 debug {
294 for (int i = 0; i < table.length; i++)
295 {
296 //printf("%x\n", table[i][0]);
297 assert(table[i][0] <= table[i][1]);
298 if (i < table.length - 1)
299 assert(table[i][1] < table[i + 1][0]);
300 }
301 }
302
303 if (u > 0xD7A3)
304 goto Lisnot;
305
306 // Binary search
307 int mid;
308 int low;
309 int high;
310
311 low = 0;
312 high = table.length - 1;
313 while (low <= high)
314 {
315 mid = (low + high) >> 1;
316 if (u < table[mid][0])
317 high = mid - 1;
318 else if (u > table[mid][1])
319 low = mid + 1;
320 else
321 goto Lis;
322 }
323
324 Lisnot:
325 debug {
326 for (int i = 0; i < table.length; i++)
327 {
328 assert(u < table[i][0] || u > table[i][1]);
329 }
330 }
331 return false;
332
333 Lis:
334 debug {
335 for (int i = 0; i < table.length; i++)
336 {
337 if (u >= table[i][0] && u <= table[i][1])
338 return 1;
339 }
340 assert(0); // should have been in table
341 }
342 return true;
41 } 343 }
42 344
43 class Lexer 345 class Lexer
44 { 346 {
45 static StringTable stringtable; 347 static StringTable stringtable;
2744 } 3046 }
2745 3047
2746 global.errors++; 3048 global.errors++;
2747 } 3049 }
2748 3050
3051 /*********************************************
3052 * Do pragma.
3053 * Currently, the only pragma supported is:
3054 * #line linnum [filespec]
3055 */
2749 void pragma_() 3056 void pragma_()
2750 { 3057 {
2751 assert(false); 3058 Token tok;
3059 int linnum;
3060 string filespec = null;
3061 Loc loc = this.loc;
3062
3063 scan(&tok);
3064 if (tok.value != TOKidentifier || tok.ident != Id.line)
3065 goto Lerr;
3066
3067 scan(&tok);
3068 if (tok.value == TOKint32v || tok.value == TOKint64v)
3069 linnum = cast(int)(tok.uns64value - 1); ///
3070 else
3071 goto Lerr;
3072
3073 while (1)
3074 {
3075 switch (*p)
3076 {
3077 case 0:
3078 case 0x1A:
3079 case '\n':
3080 Lnewline:
3081 this.loc.linnum = linnum;
3082 if (filespec != null)
3083 this.loc.filename = filespec;
3084 return;
3085
3086 case '\r':
3087 p++;
3088 if (*p != '\n')
3089 { p--;
3090 goto Lnewline;
3091 }
3092 continue;
3093
3094 case ' ':
3095 case '\t':
3096 case '\v':
3097 case '\f':
3098 p++;
3099 continue; // skip white space
3100
3101 case '_':
3102 if (mod && memcmp(p, "__FILE__".ptr, 8) == 0)
3103 {
3104 p += 8;
3105 filespec = (loc.filename ? loc.filename : mod.ident.toChars());
3106 }
3107 continue;
3108
3109 case '"':
3110 if (filespec)
3111 goto Lerr;
3112 stringbuffer.reset();
3113 p++;
3114 while (1)
3115 {
3116 uint c;
3117
3118 c = *p;
3119 switch (c)
3120 {
3121 case '\n':
3122 case '\r':
3123 case 0:
3124 case 0x1A:
3125 goto Lerr;
3126
3127 case '"':
3128 stringbuffer.writeByte(0);
3129 filespec = stringbuffer.extractString(); ///
3130 p++;
3131 break;
3132
3133 default:
3134 if (c & 0x80)
3135 {
3136 uint u = decodeUTF();
3137 if (u == PS || u == LS)
3138 goto Lerr;
3139 }
3140 stringbuffer.writeByte(c);
3141 p++;
3142 continue;
3143 }
3144 break;
3145 }
3146 continue;
3147
3148 default:
3149 if (*p & 0x80)
3150 {
3151 uint u = decodeUTF();
3152 if (u == PS || u == LS)
3153 goto Lnewline;
3154 }
3155 goto Lerr;
3156 }
3157 }
3158
3159 Lerr:
3160 error(loc, "#line integer [\"filespec\"]\\n expected");
2752 } 3161 }
2753 3162
2754 /******************************************** 3163 /********************************************
2755 * Decode UTF character. 3164 * Decode UTF character.
2756 * Issue error messages for invalid sequences. 3165 * Issue error messages for invalid sequences.