Mercurial > projects > ddmd
comparison dmd/TraitsExp.d @ 113:3482c73a991b
More cleanup for arrays
author | Eldar Insafutdinov <e.insafutdinov@gmail.com> |
---|---|
date | Tue, 31 Aug 2010 23:57:32 +0100 |
parents | ae5b11064a9a |
children | e28b18c23469 |
comparison
equal
deleted
inserted
replaced
112:3f02152c5e68 | 113:3482c73a991b |
---|---|
95 | 95 |
96 string ISTYPE(string cond) | 96 string ISTYPE(string cond) |
97 { | 97 { |
98 return ` | 98 return ` |
99 for (size_t i = 0; i < dim; i++) | 99 for (size_t i = 0; i < dim; i++) |
100 { Type t = getType(cast(Object)args.data[i]); | 100 { Type t = getType(args[i]); |
101 if (!t) | 101 if (!t) |
102 goto Lfalse; | 102 goto Lfalse; |
103 if (!(`~cond~`)) | 103 if (!(`~cond~`)) |
104 goto Lfalse; | 104 goto Lfalse; |
105 } | 105 } |
110 } | 110 } |
111 | 111 |
112 string ISDSYMBOL(string cond) | 112 string ISDSYMBOL(string cond) |
113 { | 113 { |
114 return `for (size_t i = 0; i < dim; i++) | 114 return `for (size_t i = 0; i < dim; i++) |
115 { Dsymbol s = getDsymbol(cast(Object)args.data[i]); | 115 { Dsymbol s = getDsymbol(args[i]); |
116 if (!s) | 116 if (!s) |
117 goto Lfalse; | 117 goto Lfalse; |
118 if (!(`~cond~`)) | 118 if (!(`~cond~`)) |
119 goto Lfalse; | 119 goto Lfalse; |
120 } | 120 } |
175 ident == Id.getMember || | 175 ident == Id.getMember || |
176 ident == Id.getVirtualFunctions) | 176 ident == Id.getVirtualFunctions) |
177 { | 177 { |
178 if (dim != 2) | 178 if (dim != 2) |
179 goto Ldimerror; | 179 goto Ldimerror; |
180 Object o_ = cast(Object)args.data[0]; | 180 auto o_ = args[0]; |
181 Expression e = isExpression(cast(Object)args.data[1]); | 181 Expression e = isExpression(args[1]); |
182 if (!e) | 182 if (!e) |
183 { error("expression expected as second argument of __traits %s", ident.toChars()); | 183 { error("expression expected as second argument of __traits %s", ident.toChars()); |
184 goto Lfalse; | 184 goto Lfalse; |
185 } | 185 } |
186 e = e.optimize(WANT.WANTvalue | WANT.WANTinterpret); | 186 e = e.optimize(WANT.WANTvalue | WANT.WANTinterpret); |
187 if (e.op != TOKstring) | 187 if (e.op != TOKstring) |
188 { error("string expected as second argument of __traits %s instead of %s", ident.toChars(), e.toChars()); | 188 { error("string expected as second argument of __traits %s instead of %s", ident.toChars(), e.toChars()); |
189 goto Lfalse; | 189 goto Lfalse; |
190 } | 190 } |
191 StringExp se = cast(StringExp)e; | 191 auto se = cast(StringExp)e; |
192 se = se.toUTF8(sc); | 192 se = se.toUTF8(sc); |
193 if (se.sz != 1) | 193 if (se.sz != 1) |
194 { error("string must be chars"); | 194 { error("string must be chars"); |
195 goto Lfalse; | 195 goto Lfalse; |
196 } | 196 } |
265 } | 265 } |
266 else if (ident == Id.classInstanceSize) | 266 else if (ident == Id.classInstanceSize) |
267 { | 267 { |
268 if (dim != 1) | 268 if (dim != 1) |
269 goto Ldimerror; | 269 goto Ldimerror; |
270 Object o_ = cast(Object)args.data[0]; | 270 Object o_ = args[0]; |
271 Dsymbol s = getDsymbol(o_); | 271 Dsymbol s = getDsymbol(o_); |
272 ClassDeclaration cd; | 272 ClassDeclaration cd; |
273 if (!s || (cd = s.isClassDeclaration()) is null) | 273 if (!s || (cd = s.isClassDeclaration()) is null) |
274 { | 274 { |
275 error("first argument is not a class"); | 275 error("first argument is not a class"); |
279 } | 279 } |
280 else if (ident == Id.allMembers || ident == Id.derivedMembers) | 280 else if (ident == Id.allMembers || ident == Id.derivedMembers) |
281 { | 281 { |
282 if (dim != 1) | 282 if (dim != 1) |
283 goto Ldimerror; | 283 goto Ldimerror; |
284 Object o_ = cast(Object)args.data[0]; | 284 Object o_ = args[0]; |
285 Dsymbol s = getDsymbol(o_); | 285 Dsymbol s = getDsymbol(o_); |
286 ScopeDsymbol sd; | 286 ScopeDsymbol sd; |
287 if (!s) | 287 if (!s) |
288 { | 288 { |
289 error("argument has no members"); | 289 error("argument has no members"); |
337 */ | 337 */ |
338 if (!dim) | 338 if (!dim) |
339 goto Lfalse; | 339 goto Lfalse; |
340 | 340 |
341 for (size_t i = 0; i < dim; i++) | 341 for (size_t i = 0; i < dim; i++) |
342 { Object o_ = cast(Object)args.data[i]; | 342 { Object o_ = args[i]; |
343 Expression e; | 343 Expression e; |
344 | 344 |
345 uint errors = global.errors; | 345 uint errors = global.errors; |
346 global.gag++; | 346 global.gag++; |
347 | 347 |
373 { /* Determine if two symbols are the same | 373 { /* Determine if two symbols are the same |
374 */ | 374 */ |
375 if (dim != 2) | 375 if (dim != 2) |
376 goto Ldimerror; | 376 goto Ldimerror; |
377 TemplateInstance.semanticTiargs(loc, sc, args, 0); | 377 TemplateInstance.semanticTiargs(loc, sc, args, 0); |
378 Object o1 = cast(Object)args.data[0]; | 378 Object o1 = args[0]; |
379 Object o2 = cast(Object)args.data[1]; | 379 Object o2 = args[1]; |
380 Dsymbol s1 = getDsymbol(o1); | 380 Dsymbol s1 = getDsymbol(o1); |
381 Dsymbol s2 = getDsymbol(o2); | 381 Dsymbol s2 = getDsymbol(o2); |
382 | 382 |
383 // writef("isSame: %s, %s\n", o1.toChars(), o2.toChars()); | 383 // writef("isSame: %s, %s\n", o1.toChars(), o2.toChars()); |
384 static if (0) | 384 static if (0) |
445 if (args) | 445 if (args) |
446 { | 446 { |
447 for (int i = 0; i < args.dim; i++) | 447 for (int i = 0; i < args.dim; i++) |
448 { | 448 { |
449 buf.writeByte(','); | 449 buf.writeByte(','); |
450 Object oarg = cast(Object)args.data[i]; | 450 Object oarg = args[i]; |
451 ObjectToCBuffer(buf, hgs, oarg); | 451 ObjectToCBuffer(buf, hgs, oarg); |
452 } | 452 } |
453 } | 453 } |
454 buf.writeByte(')'); | 454 buf.writeByte(')'); |
455 } | 455 } |