comparison dmd/expression.c @ 35:3cfcb944304e trunk

[svn r39] * Updated to DMD 1.022 with the exception of: Bugzilla 278: dmd.conf search path doesn't work This fix was causing crashes for me :/ So for it's the old behaviour
author lindquist
date Tue, 09 Oct 2007 06:21:30 +0200
parents 788401029ecf
children 0b9b286b67b6
comparison
equal deleted inserted replaced
34:4648206ca213 35:3cfcb944304e
2352 int StringExp::isBool(int result) 2352 int StringExp::isBool(int result)
2353 { 2353 {
2354 return result ? TRUE : FALSE; 2354 return result ? TRUE : FALSE;
2355 } 2355 }
2356 2356
2357 unsigned StringExp::charAt(size_t i)
2358 { unsigned value;
2359
2360 switch (sz)
2361 {
2362 case 1:
2363 value = ((unsigned char *)string)[i];
2364 break;
2365
2366 case 2:
2367 value = ((unsigned short *)string)[i];
2368 break;
2369
2370 case 4:
2371 value = ((unsigned int *)string)[i];
2372 break;
2373
2374 default:
2375 assert(0);
2376 break;
2377 }
2378 return value;
2379 }
2380
2357 void StringExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) 2381 void StringExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
2358 { 2382 {
2359 buf->writeByte('"'); 2383 buf->writeByte('"');
2360 for (size_t i = 0; i < len; i++) 2384 for (size_t i = 0; i < len; i++)
2361 { unsigned c; 2385 { unsigned c = charAt(i);
2362 2386
2363 switch (sz)
2364 {
2365 case 1:
2366 c = ((unsigned char *)string)[i];
2367 break;
2368 case 2:
2369 c = ((unsigned short *)string)[i];
2370 break;
2371 case 4:
2372 c = ((unsigned *)string)[i];
2373 break;
2374 default:
2375 assert(0);
2376 }
2377 switch (c) 2387 switch (c)
2378 { 2388 {
2379 case '"': 2389 case '"':
2380 case '\\': 2390 case '\\':
2381 if (!hgs->console) 2391 if (!hgs->console)
4931 4941
4932 if (!var->isFuncDeclaration()) // for functions, do checks after overload resolution 4942 if (!var->isFuncDeclaration()) // for functions, do checks after overload resolution
4933 { 4943 {
4934 AggregateDeclaration *ad = var->toParent()->isAggregateDeclaration(); 4944 AggregateDeclaration *ad = var->toParent()->isAggregateDeclaration();
4935 L1: 4945 L1:
4936 Type *t = e1->type; 4946 Type *t = e1->type->toBasetype();
4937 4947
4938 if (ad && 4948 if (ad &&
4939 !(t->ty == Tpointer && t->next->ty == Tstruct && 4949 !(t->ty == Tpointer && t->next->ty == Tstruct &&
4940 ((TypeStruct *)t->next)->sym == ad) 4950 ((TypeStruct *)t->next)->sym == ad)
4941 && 4951 &&
5465 error("%s %s does not overload ()", ad->kind(), ad->toChars()); 5475 error("%s %s does not overload ()", ad->kind(), ad->toChars());
5466 /* It's a struct literal 5476 /* It's a struct literal
5467 */ 5477 */
5468 Expression *e = new StructLiteralExp(loc, (StructDeclaration *)ad, arguments); 5478 Expression *e = new StructLiteralExp(loc, (StructDeclaration *)ad, arguments);
5469 e = e->semantic(sc); 5479 e = e->semantic(sc);
5480 e->type = e1->type; // in case e1->type was a typedef
5470 return e; 5481 return e;
5471 } 5482 }
5472 else if (t1->ty == Tclass) 5483 else if (t1->ty == Tclass)
5473 { 5484 {
5474 ad = ((TypeClass *)t1)->sym; 5485 ad = ((TypeClass *)t1)->sym;
6085 switch (tb->ty) 6096 switch (tb->ty)
6086 { case Tclass: 6097 { case Tclass:
6087 { TypeClass *tc = (TypeClass *)tb; 6098 { TypeClass *tc = (TypeClass *)tb;
6088 ClassDeclaration *cd = tc->sym; 6099 ClassDeclaration *cd = tc->sym;
6089 6100
6090 if (cd->isInterfaceDeclaration() && cd->isCOMclass()) 6101 if (cd->isCOMinterface())
6102 { /* Because COM classes are deleted by IUnknown.Release()
6103 */
6091 error("cannot delete instance of COM interface %s", cd->toChars()); 6104 error("cannot delete instance of COM interface %s", cd->toChars());
6105 }
6092 break; 6106 break;
6093 } 6107 }
6094 case Tpointer: 6108 case Tpointer:
6095 tb = tb->next->toBasetype(); 6109 tb = tb->next->toBasetype();
6096 if (tb->ty == Tstruct) 6110 if (tb->ty == Tstruct)