comparison tango/lib/compiler/llvmdc/switch.d @ 271:1e6e2b5d5bfe trunk

[svn r292] Fixed: string switch was broken in several ways. Fixed: TypeInfo_Typedef.next was incorrect (return base of base instead of just base). Fixed: ClassInfo offset type info (offTi) had invalid offsets.
author lindquist
date Wed, 18 Jun 2008 21:31:05 +0200
parents 1700239cab2e
children
comparison
equal deleted inserted replaced
270:d9d5d59873d8 271:1e6e2b5d5bfe
24 /* 24 /*
25 * Modified by Sean Kelly <sean@f4.ca> for use with Tango. 25 * Modified by Sean Kelly <sean@f4.ca> for use with Tango.
26 */ 26 */
27 27
28 private import tango.stdc.string; 28 private import tango.stdc.string;
29 //private import tango.stdc.stdio;
29 30
30 /****************************************************** 31 /******************************************************
31 * Support for switch statements switching on strings. 32 * Support for switch statements switching on strings.
32 * Input: 33 * Input:
33 * table[] sorted array of strings generated by compiler 34 * table[] sorted array of strings generated by compiler
99 } 100 }
100 } 101 }
101 } 102 }
102 body 103 body
103 { 104 {
104 //printf("body _d_switch_string(%.*s)\n", ca); 105 //printf("body _d_switch_string(%.*s)\n", ca.length, ca.ptr);
105 size_t low; 106 size_t low;
106 size_t high; 107 size_t high;
107 size_t mid; 108 size_t mid;
108 size_t c; 109 ptrdiff_t c;
109 char[] pca; 110 char[] pca;
110 111
111 low = 0; 112 low = 0;
112 high = table.length; 113 high = table.length;
113 114
134 // Do binary search 135 // Do binary search
135 while (low < high) 136 while (low < high)
136 { 137 {
137 mid = (low + high) >> 1; 138 mid = (low + high) >> 1;
138 pca = table[mid]; 139 pca = table[mid];
139 c = ca.length - pca.length; 140 c = cast(ptrdiff_t)(ca.length - pca.length);
140 if (c == 0) 141 if (c == 0)
141 { 142 {
142 c = cast(ubyte)c1 - cast(ubyte)pca[0]; 143 c = cast(ubyte)c1 - cast(ubyte)pca[0];
143 if (c == 0) 144 if (c == 0)
144 { 145 {
242 { 243 {
243 //printf("body _d_switch_ustring()\n"); 244 //printf("body _d_switch_ustring()\n");
244 size_t low; 245 size_t low;
245 size_t high; 246 size_t high;
246 size_t mid; 247 size_t mid;
247 size_t c; 248 ptrdiff_t c;
248 wchar[] pca; 249 wchar[] pca;
249 250
250 low = 0; 251 low = 0;
251 high = table.length; 252 high = table.length;
252 253
263 // Do binary search 264 // Do binary search
264 while (low < high) 265 while (low < high)
265 { 266 {
266 mid = (low + high) >> 1; 267 mid = (low + high) >> 1;
267 pca = table[mid]; 268 pca = table[mid];
268 c = ca.length - pca.length; 269 c = cast(ptrdiff_t)(ca.length - pca.length);
269 if (c == 0) 270 if (c == 0)
270 { 271 {
271 c = memcmp(ca.ptr, pca.ptr, ca.length * wchar.sizeof); 272 c = memcmp(ca.ptr, pca.ptr, ca.length * wchar.sizeof);
272 if (c == 0) 273 if (c == 0)
273 { //printf("found %d\n", mid); 274 { //printf("found %d\n", mid);
367 { 368 {
368 //printf("body _d_switch_ustring()\n"); 369 //printf("body _d_switch_ustring()\n");
369 size_t low; 370 size_t low;
370 size_t high; 371 size_t high;
371 size_t mid; 372 size_t mid;
372 size_t c; 373 ptrdiff_t c;
373 dchar[] pca; 374 dchar[] pca;
374 375
375 low = 0; 376 low = 0;
376 high = table.length; 377 high = table.length;
377 378
388 // Do binary search 389 // Do binary search
389 while (low < high) 390 while (low < high)
390 { 391 {
391 mid = (low + high) >> 1; 392 mid = (low + high) >> 1;
392 pca = table[mid]; 393 pca = table[mid];
393 c = ca.length - pca.length; 394 c = cast(ptrdiff_t)(ca.length - pca.length);
394 if (c == 0) 395 if (c == 0)
395 { 396 {
396 c = memcmp(ca.ptr, pca.ptr, ca.length * dchar.sizeof); 397 c = memcmp(ca.ptr, pca.ptr, ca.length * dchar.sizeof);
397 if (c == 0) 398 if (c == 0)
398 { //printf("found %d\n", mid); 399 { //printf("found %d\n", mid);