comparison dmd/mtype.c @ 92:70d6113eeb8c trunk

[svn r96] Updated to DMD 1.023. Regular bugfixes.
author lindquist
date Thu, 08 Nov 2007 19:13:28 +0100
parents 3cfcb944304e
children 61615fa85940
comparison
equal deleted inserted replaced
91:3f949c6e2e9d 92:70d6113eeb8c
487 s->checkDeprecated(loc, sc); 487 s->checkDeprecated(loc, sc);
488 } 488 }
489 } 489 }
490 490
491 491
492 Expression *Type::defaultInit() 492 Expression *Type::defaultInit(Loc loc)
493 { 493 {
494 #if LOGDEFAULTINIT 494 #if LOGDEFAULTINIT
495 printf("Type::defaultInit() '%s'\n", toChars()); 495 printf("Type::defaultInit() '%s'\n", toChars());
496 #endif 496 #endif
497 return NULL; 497 return NULL;
554 } 554 }
555 else if (ident == Id::init) 555 else if (ident == Id::init)
556 { 556 {
557 if (ty == Tvoid) 557 if (ty == Tvoid)
558 error(loc, "void does not have an initializer"); 558 error(loc, "void does not have an initializer");
559 e = defaultInit(); 559 e = defaultInit(loc);
560 e->loc = loc;
561 } 560 }
562 else if (ident == Id::mangleof) 561 else if (ident == Id::mangleof)
563 { 562 {
564 assert(deco); 563 assert(deco);
565 e = new StringExp(loc, deco, strlen(deco), 'c'); 564 e = new StringExp(loc, deco, strlen(deco), 'c');
632 */ 631 */
633 if (e->type == Type::tint32 && 632 if (e->type == Type::tint32 &&
634 e->isBool(0) && 633 e->isBool(0) &&
635 v->type->toBasetype()->ty == Tstruct) 634 v->type->toBasetype()->ty == Tstruct)
636 { 635 {
637 e = v->type->defaultInit(); 636 e = v->type->defaultInit(loc);
638 } 637 }
639 } 638 }
640 e = e->optimize(WANTvalue | WANTinterpret); 639 e = e->optimize(WANTvalue | WANTinterpret);
641 // if (!e->isConst()) 640 // if (!e->isConst())
642 // error(loc, ".init cannot be evaluated at compile time"); 641 // error(loc, ".init cannot be evaluated at compile time");
643 } 642 }
644 return e; 643 return e;
645 } 644 }
646 #endif 645 #endif
647 Expression *ex = defaultInit(); 646 Expression *ex = defaultInit(e->loc);
648 ex->loc = e->loc;
649 return ex; 647 return ex;
650 } 648 }
651 } 649 }
652 if (ident == Id::typeinfo) 650 if (ident == Id::typeinfo)
653 { 651 {
1325 return Type::dotExp(sc, e, ident); 1323 return Type::dotExp(sc, e, ident);
1326 } 1324 }
1327 return e; 1325 return e;
1328 } 1326 }
1329 1327
1330 Expression *TypeBasic::defaultInit() 1328 Expression *TypeBasic::defaultInit(Loc loc)
1331 { integer_t value = 0; 1329 { integer_t value = 0;
1332 1330
1333 #if LOGDEFAULTINIT 1331 #if LOGDEFAULTINIT
1334 printf("TypeBasic::defaultInit() '%s'\n", toChars()); 1332 printf("TypeBasic::defaultInit() '%s'\n", toChars());
1335 #endif 1333 #endif
1351 case Tfloat64: 1349 case Tfloat64:
1352 case Tfloat80: 1350 case Tfloat80:
1353 case Tcomplex32: 1351 case Tcomplex32:
1354 case Tcomplex64: 1352 case Tcomplex64:
1355 case Tcomplex80: 1353 case Tcomplex80:
1356 return getProperty(0, Id::nan); 1354 return getProperty(loc, Id::nan);
1357 } 1355 }
1358 return new IntegerExp(0, value, this); 1356 return new IntegerExp(loc, value, this);
1359 } 1357 }
1360 1358
1361 int TypeBasic::isZeroInit() 1359 int TypeBasic::isZeroInit()
1362 { 1360 {
1363 switch (ty) 1361 switch (ty)
1823 { integer_t n, n2; 1821 { integer_t n, n2;
1824 1822
1825 dim = semanticLength(sc, tbn, dim); 1823 dim = semanticLength(sc, tbn, dim);
1826 1824
1827 dim = dim->optimize(WANTvalue | WANTinterpret); 1825 dim = dim->optimize(WANTvalue | WANTinterpret);
1826 if (sc->parameterSpecialization && dim->op == TOKvar &&
1827 ((VarExp *)dim)->var->storage_class & STCtemplateparameter)
1828 {
1829 /* It could be a template parameter N which has no value yet:
1830 * template Foo(T : T[N], size_t N);
1831 */
1832 return this;
1833 }
1828 integer_t d1 = dim->toInteger(); 1834 integer_t d1 = dim->toInteger();
1829 dim = dim->castTo(sc, tsize_t); 1835 dim = dim->castTo(sc, tsize_t);
1830 dim = dim->optimize(WANTvalue); 1836 dim = dim->optimize(WANTvalue);
1831 integer_t d2 = dim->toInteger(); 1837 integer_t d2 = dim->toInteger();
1832 1838
1967 } 1973 }
1968 #endif 1974 #endif
1969 return Type::implicitConvTo(to); 1975 return Type::implicitConvTo(to);
1970 } 1976 }
1971 1977
1972 Expression *TypeSArray::defaultInit() 1978 Expression *TypeSArray::defaultInit(Loc loc)
1973 { 1979 {
1974 #if LOGDEFAULTINIT 1980 #if LOGDEFAULTINIT
1975 printf("TypeSArray::defaultInit() '%s'\n", toChars()); 1981 printf("TypeSArray::defaultInit() '%s'\n", toChars());
1976 #endif 1982 #endif
1977 return next->defaultInit(); 1983 return next->defaultInit(loc);
1978 } 1984 }
1979 1985
1980 int TypeSArray::isZeroInit() 1986 int TypeSArray::isZeroInit()
1981 { 1987 {
1982 return next->isZeroInit(); 1988 return next->isZeroInit();
2125 return MATCHconvert; 2131 return MATCHconvert;
2126 } 2132 }
2127 return Type::implicitConvTo(to); 2133 return Type::implicitConvTo(to);
2128 } 2134 }
2129 2135
2130 Expression *TypeDArray::defaultInit() 2136 Expression *TypeDArray::defaultInit(Loc loc)
2131 { 2137 {
2132 #if LOGDEFAULTINIT 2138 #if LOGDEFAULTINIT
2133 printf("TypeDArray::defaultInit() '%s'\n", toChars()); 2139 printf("TypeDArray::defaultInit() '%s'\n", toChars());
2134 #endif 2140 #endif
2135 Expression *e; 2141 Expression *e;
2136 e = new NullExp(0); 2142 e = new NullExp(loc);
2137 e->type = this; 2143 e->type = this;
2138 return e; 2144 return e;
2139 } 2145 }
2140 2146
2141 int TypeDArray::isZeroInit() 2147 int TypeDArray::isZeroInit()
2339 buf->write(&ibuf); 2345 buf->write(&ibuf);
2340 } 2346 }
2341 buf->writeByte(']'); 2347 buf->writeByte(']');
2342 } 2348 }
2343 2349
2344 Expression *TypeAArray::defaultInit() 2350 Expression *TypeAArray::defaultInit(Loc loc)
2345 { 2351 {
2346 #if LOGDEFAULTINIT 2352 #if LOGDEFAULTINIT
2347 printf("TypeAArray::defaultInit() '%s'\n", toChars()); 2353 printf("TypeAArray::defaultInit() '%s'\n", toChars());
2348 #endif 2354 #endif
2349 Expression *e; 2355 Expression *e;
2350 e = new NullExp(0); 2356 e = new NullExp(loc);
2351 e->type = this; 2357 e->type = this;
2352 return e; 2358 return e;
2353 } 2359 }
2354 2360
2355 int TypeAArray::checkBoolean() 2361 int TypeAArray::checkBoolean()
2447 int TypePointer::isscalar() 2453 int TypePointer::isscalar()
2448 { 2454 {
2449 return TRUE; 2455 return TRUE;
2450 } 2456 }
2451 2457
2452 Expression *TypePointer::defaultInit() 2458 Expression *TypePointer::defaultInit(Loc loc)
2453 { 2459 {
2454 #if LOGDEFAULTINIT 2460 #if LOGDEFAULTINIT
2455 printf("TypePointer::defaultInit() '%s'\n", toChars()); 2461 printf("TypePointer::defaultInit() '%s'\n", toChars());
2456 #endif 2462 #endif
2457 Expression *e; 2463 Expression *e;
2458 e = new NullExp(0); 2464 e = new NullExp(loc);
2459 e->type = this; 2465 e->type = this;
2460 return e; 2466 return e;
2461 } 2467 }
2462 2468
2463 int TypePointer::isZeroInit() 2469 int TypePointer::isZeroInit()
2514 2520
2515 // References just forward things along 2521 // References just forward things along
2516 return next->dotExp(sc, e, ident); 2522 return next->dotExp(sc, e, ident);
2517 } 2523 }
2518 2524
2519 Expression *TypeReference::defaultInit() 2525 Expression *TypeReference::defaultInit(Loc loc)
2520 { 2526 {
2521 #if LOGDEFAULTINIT 2527 #if LOGDEFAULTINIT
2522 printf("TypeReference::defaultInit() '%s'\n", toChars()); 2528 printf("TypeReference::defaultInit() '%s'\n", toChars());
2523 #endif 2529 #endif
2524 Expression *e; 2530 Expression *e;
2525 e = new NullExp(0); 2531 e = new NullExp(loc);
2526 e->type = this; 2532 e->type = this;
2527 return e; 2533 return e;
2528 } 2534 }
2529 2535
2530 int TypeReference::isZeroInit() 2536 int TypeReference::isZeroInit()
2998 buf->writestring(ident->toChars()); 3004 buf->writestring(ident->toChars());
2999 } 3005 }
3000 #endif 3006 #endif
3001 } 3007 }
3002 3008
3003 Expression *TypeDelegate::defaultInit() 3009 Expression *TypeDelegate::defaultInit(Loc loc)
3004 { 3010 {
3005 #if LOGDEFAULTINIT 3011 #if LOGDEFAULTINIT
3006 printf("TypeDelegate::defaultInit() '%s'\n", toChars()); 3012 printf("TypeDelegate::defaultInit() '%s'\n", toChars());
3007 #endif 3013 #endif
3008 Expression *e; 3014 Expression *e;
3009 e = new NullExp(0); 3015 e = new NullExp(loc);
3010 e->type = this; 3016 e->type = this;
3011 return e; 3017 return e;
3012 } 3018 }
3013 3019
3014 int TypeDelegate::isZeroInit() 3020 int TypeDelegate::isZeroInit()
3798 } 3804 }
3799 else if (ident == Id::init) 3805 else if (ident == Id::init)
3800 { 3806 {
3801 if (!sym->symtab) 3807 if (!sym->symtab)
3802 goto Lfwd; 3808 goto Lfwd;
3803 e = defaultInit(); 3809 e = defaultInit(loc);
3804 } 3810 }
3805 else 3811 else
3806 { 3812 {
3807 if (!sym->memtype) 3813 if (!sym->memtype)
3808 goto Lfwd; 3814 goto Lfwd;
3847 else 3853 else
3848 m = MATCHnomatch; // no match 3854 m = MATCHnomatch; // no match
3849 return m; 3855 return m;
3850 } 3856 }
3851 3857
3852 Expression *TypeEnum::defaultInit() 3858 Expression *TypeEnum::defaultInit(Loc loc)
3853 { 3859 {
3854 #if LOGDEFAULTINIT 3860 #if LOGDEFAULTINIT
3855 printf("TypeEnum::defaultInit() '%s'\n", toChars()); 3861 printf("TypeEnum::defaultInit() '%s'\n", toChars());
3856 #endif 3862 #endif
3857 // Initialize to first member of enum 3863 // Initialize to first member of enum
3858 Expression *e; 3864 Expression *e;
3859 e = new IntegerExp(0, sym->defaultval, this); 3865 e = new IntegerExp(loc, sym->defaultval, this);
3860 return e; 3866 return e;
3861 } 3867 }
3862 3868
3863 int TypeEnum::isZeroInit() 3869 int TypeEnum::isZeroInit()
3864 { 3870 {
4022 else 4028 else
4023 m = MATCHnomatch; // no match 4029 m = MATCHnomatch; // no match
4024 return m; 4030 return m;
4025 } 4031 }
4026 4032
4027 Expression *TypeTypedef::defaultInit() 4033 Expression *TypeTypedef::defaultInit(Loc loc)
4028 { Expression *e; 4034 { Expression *e;
4029 Type *bt; 4035 Type *bt;
4030 4036
4031 #if LOGDEFAULTINIT 4037 #if LOGDEFAULTINIT
4032 printf("TypeTypedef::defaultInit() '%s'\n", toChars()); 4038 printf("TypeTypedef::defaultInit() '%s'\n", toChars());
4035 { 4041 {
4036 //sym->init->toExpression()->print(); 4042 //sym->init->toExpression()->print();
4037 return sym->init->toExpression(); 4043 return sym->init->toExpression();
4038 } 4044 }
4039 bt = sym->basetype; 4045 bt = sym->basetype;
4040 e = bt->defaultInit(); 4046 e = bt->defaultInit(loc);
4041 e->type = this; 4047 e->type = this;
4042 while (bt->ty == Tsarray) 4048 while (bt->ty == Tsarray)
4043 { 4049 {
4044 e->type = bt->next; 4050 e->type = bt->next;
4045 bt = bt->next->toBasetype(); 4051 bt = bt->next->toBasetype();
4314 { 4320 {
4315 sym->size(0); // give error for forward references 4321 sym->size(0); // give error for forward references
4316 return sym->structalign; 4322 return sym->structalign;
4317 } 4323 }
4318 4324
4319 Expression *TypeStruct::defaultInit() 4325 Expression *TypeStruct::defaultInit(Loc loc)
4320 { Symbol *s; 4326 { Symbol *s;
4321 Declaration *d; 4327 Declaration *d;
4322 4328
4323 #if LOGDEFAULTINIT 4329 #if LOGDEFAULTINIT
4324 printf("TypeStruct::defaultInit() '%s'\n", toChars()); 4330 printf("TypeStruct::defaultInit() '%s'\n", toChars());
4699 } 4705 }
4700 4706
4701 return MATCHnomatch; 4707 return MATCHnomatch;
4702 } 4708 }
4703 4709
4704 Expression *TypeClass::defaultInit() 4710 Expression *TypeClass::defaultInit(Loc loc)
4705 { 4711 {
4706 #if LOGDEFAULTINIT 4712 #if LOGDEFAULTINIT
4707 printf("TypeClass::defaultInit() '%s'\n", toChars()); 4713 printf("TypeClass::defaultInit() '%s'\n", toChars());
4708 #endif 4714 #endif
4709 Expression *e; 4715 Expression *e;
4710 e = new NullExp(0); 4716 e = new NullExp(loc);
4711 e->type = this; 4717 e->type = this;
4712 return e; 4718 return e;
4713 } 4719 }
4714 4720
4715 int TypeClass::isZeroInit() 4721 int TypeClass::isZeroInit()