comparison dmd/class.c @ 1587:def7a1d494fd

Merge DMD 1.051
author Christian Kamm <kamm incasoftware de>
date Fri, 06 Nov 2009 23:58:01 +0100
parents 05c235309d6f
children 207a8a438dea
comparison
equal deleted inserted replaced
1586:7f728c52e63c 1587:def7a1d494fd
1 1
2 // Compiler implementation of the D programming language 2 // Compiler implementation of the D programming language
3 // Copyright (c) 1999-2008 by Digital Mars 3 // Copyright (c) 1999-2009 by Digital Mars
4 // All Rights Reserved 4 // All Rights Reserved
5 // written by Walter Bright 5 // written by Walter Bright
6 // http://www.digitalmars.com 6 // http://www.digitalmars.com
7 // License for redistribution is by either the Artistic License 7 // License for redistribution is by either the Artistic License
8 // in artistic.txt, or the GNU General Public License in gnu.txt. 8 // in artistic.txt, or the GNU General Public License in gnu.txt.
159 if (id == Id::TypeInfo_Invariant) 159 if (id == Id::TypeInfo_Invariant)
160 { if (Type::typeinfoinvariant) 160 { if (Type::typeinfoinvariant)
161 Type::typeinfoinvariant->error("%s", msg); 161 Type::typeinfoinvariant->error("%s", msg);
162 Type::typeinfoinvariant = this; 162 Type::typeinfoinvariant = this;
163 } 163 }
164
165 if (id == Id::TypeInfo_Shared)
166 { if (Type::typeinfoshared)
167 Type::typeinfoshared->error("%s", msg);
168 Type::typeinfoshared = this;
169 }
164 #endif 170 #endif
165 } 171 }
166 172
167 if (id == Id::Object) 173 if (id == Id::Object)
168 { if (object) 174 { if (object)
224 //printf("sc->stc = %x\n", sc->stc); 230 //printf("sc->stc = %x\n", sc->stc);
225 231
226 //{ static int n; if (++n == 20) *(char*)0=0; } 232 //{ static int n; if (++n == 20) *(char*)0=0; }
227 233
228 if (!ident) // if anonymous class 234 if (!ident) // if anonymous class
229 { char *id = "__anonclass"; 235 { const char *id = "__anonclass";
230 236
231 ident = Identifier::generateId(id); 237 ident = Identifier::generateId(id);
232 } 238 }
233 239
234 if (!scope) 240 if (!sc)
235 { 241 sc = scope;
236 if (!parent && sc->parent && !sc->parent->isModule()) 242 if (!parent && sc->parent && !sc->parent->isModule())
237 parent = sc->parent; 243 parent = sc->parent;
238 244
239 type = type->semantic(loc, sc); 245 type = type->semantic(loc, sc);
240 handle = handle->semantic(loc, sc); 246 handle = type;
241 } 247
242 if (!members) // if forward reference 248 if (!members) // if forward reference
243 { //printf("\tclass '%s' is forward referenced\n", toChars()); 249 { //printf("\tclass '%s' is forward referenced\n", toChars());
244 return; 250 return;
245 } 251 }
246 if (symtab) 252 if (symtab)
327 error("circular inheritance"); 333 error("circular inheritance");
328 baseclasses.remove(0); 334 baseclasses.remove(0);
329 goto L7; 335 goto L7;
330 } 336 }
331 } 337 }
338 if (!tc->sym->symtab || tc->sym->sizeok == 0)
339 { // Try to resolve forward reference
340 if (sc->mustsemantic && tc->sym->scope)
341 tc->sym->semantic(NULL);
342 }
332 if (!tc->sym->symtab || tc->sym->scope || tc->sym->sizeok == 0) 343 if (!tc->sym->symtab || tc->sym->scope || tc->sym->sizeok == 0)
333 { 344 {
345 //printf("%s: forward reference of base class %s\n", toChars(), tc->sym->toChars());
334 //error("forward reference of base class %s", baseClass->toChars()); 346 //error("forward reference of base class %s", baseClass->toChars());
335 // Forward reference of base class, try again later 347 // Forward reference of base class, try again later
336 //printf("\ttry later, forward reference of base class %s\n", tc->sym->toChars()); 348 //printf("\ttry later, forward reference of base class %s\n", tc->sym->toChars());
337 scope = scx ? scx : new Scope(*sc); 349 scope = scx ? scx : new Scope(*sc);
338 scope->setNoFree(); 350 scope->setNoFree();
351 if (tc->sym->scope)
352 tc->sym->scope->module->addDeferredSemantic(tc->sym);
339 scope->module->addDeferredSemantic(this); 353 scope->module->addDeferredSemantic(this);
340 return; 354 return;
341 } 355 }
342 else 356 else
343 { baseClass = tc->sym; 357 { baseClass = tc->sym;
387 BaseClass *b2 = (BaseClass *)baseclasses.data[j]; 401 BaseClass *b2 = (BaseClass *)baseclasses.data[j];
388 if (b2->base == tc->sym) 402 if (b2->base == tc->sym)
389 error("inherits from duplicate interface %s", b2->base->toChars()); 403 error("inherits from duplicate interface %s", b2->base->toChars());
390 } 404 }
391 405
406 if (!tc->sym->symtab)
407 { // Try to resolve forward reference
408 if (sc->mustsemantic && tc->sym->scope)
409 tc->sym->semantic(NULL);
410 }
411
392 b->base = tc->sym; 412 b->base = tc->sym;
393 if (!b->base->symtab || b->base->scope) 413 if (!b->base->symtab || b->base->scope)
394 { 414 {
395 //error("forward reference of base class %s", baseClass->toChars()); 415 //error("forward reference of base class %s", baseClass->toChars());
396 // Forward reference of base, try again later 416 // Forward reference of base, try again later
397 //printf("\ttry later, forward reference of base %s\n", baseClass->toChars()); 417 //printf("\ttry later, forward reference of base %s\n", baseClass->toChars());
398 scope = scx ? scx : new Scope(*sc); 418 scope = scx ? scx : new Scope(*sc);
399 scope->setNoFree(); 419 scope->setNoFree();
420 if (tc->sym->scope)
421 tc->sym->scope->module->addDeferredSemantic(tc->sym);
400 scope->module->addDeferredSemantic(this); 422 scope->module->addDeferredSemantic(this);
401 return; 423 return;
402 } 424 }
403 } 425 }
404 i++; 426 i++;
498 } 520 }
499 else if (!(storage_class & STCstatic)) 521 else if (!(storage_class & STCstatic))
500 { Dsymbol *s = toParent2(); 522 { Dsymbol *s = toParent2();
501 if (s) 523 if (s)
502 { 524 {
503 ClassDeclaration *cd = s->isClassDeclaration(); 525 AggregateDeclaration *ad = s->isClassDeclaration();
504 FuncDeclaration *fd = s->isFuncDeclaration(); 526 FuncDeclaration *fd = s->isFuncDeclaration();
505 527
506 528
507 if (cd || fd) 529 if (ad || fd)
508 { isnested = 1; 530 { isnested = 1;
509 Type *t; 531 Type *t;
510 if (cd) 532 if (ad)
511 t = cd->type; 533 t = ad->handle;
512 else if (fd) 534 else if (fd)
513 { AggregateDeclaration *ad = fd->isMember2(); 535 { AggregateDeclaration *ad = fd->isMember2();
514 if (ad) 536 if (ad)
515 t = ad->handle; 537 t = ad->handle;
516 else 538 else
562 alignsize = baseClass->alignsize; 584 alignsize = baseClass->alignsize;
563 // if (isnested) 585 // if (isnested)
564 // sc->offset += PTRSIZE; // room for uplevel context pointer 586 // sc->offset += PTRSIZE; // room for uplevel context pointer
565 } 587 }
566 else 588 else
567 { sc->offset = PTRSIZE * 2; // allow room for vptr[] and monitor 589 { sc->offset = PTRSIZE * 2; // allow room for __vptr and __monitor
568 alignsize = PTRSIZE; 590 alignsize = PTRSIZE;
569 } 591 }
570 structsize = sc->offset; 592 structsize = sc->offset;
571 Scope scsave = *sc; 593 Scope scsave = *sc;
572 int members_dim = members->dim; 594 int members_dim = members->dim;
701 if (i) 723 if (i)
702 buf->writeByte(','); 724 buf->writeByte(',');
703 //buf->writestring(b->base->ident->toChars()); 725 //buf->writestring(b->base->ident->toChars());
704 b->type->toCBuffer(buf, NULL, hgs); 726 b->type->toCBuffer(buf, NULL, hgs);
705 } 727 }
706 buf->writenl(); 728 if (members)
707 buf->writeByte('{'); 729 {
708 buf->writenl(); 730 buf->writenl();
709 for (int i = 0; i < members->dim; i++) 731 buf->writeByte('{');
710 { 732 buf->writenl();
711 Dsymbol *s = (Dsymbol *)members->data[i]; 733 for (int i = 0; i < members->dim; i++)
712 734 {
713 buf->writestring(" "); 735 Dsymbol *s = (Dsymbol *)members->data[i];
714 s->toCBuffer(buf, hgs); 736
715 } 737 buf->writestring(" ");
716 buf->writestring("}"); 738 s->toCBuffer(buf, hgs);
739 }
740 buf->writestring("}");
741 }
742 else
743 buf->writeByte(';');
717 buf->writenl(); 744 buf->writenl();
718 } 745 }
719 746
720 #if 0 747 #if 0
721 void ClassDeclaration::defineRef(Dsymbol *s) 748 void ClassDeclaration::defineRef(Dsymbol *s)
775 } 802 }
776 803
777 Dsymbol *ClassDeclaration::search(Loc loc, Identifier *ident, int flags) 804 Dsymbol *ClassDeclaration::search(Loc loc, Identifier *ident, int flags)
778 { 805 {
779 Dsymbol *s; 806 Dsymbol *s;
780
781 //printf("%s.ClassDeclaration::search('%s')\n", toChars(), ident->toChars()); 807 //printf("%s.ClassDeclaration::search('%s')\n", toChars(), ident->toChars());
808
782 if (scope) 809 if (scope)
783 semantic(scope); 810 { Scope *sc = scope;
811 sc->mustsemantic++;
812 semantic(sc);
813 sc->mustsemantic--;
814 }
784 815
785 if (!members || !symtab || scope) 816 if (!members || !symtab || scope)
786 { error("is forward referenced when looking for '%s'", ident->toChars()); 817 {
818 error("is forward referenced when looking for '%s'", ident->toChars());
787 //*(char*)0=0; 819 //*(char*)0=0;
788 return NULL; 820 return NULL;
789 } 821 }
790 822
791 s = ScopeDsymbol::search(loc, ident, flags); 823 s = ScopeDsymbol::search(loc, ident, flags);
829 return param == fd; 861 return param == fd;
830 } 862 }
831 863
832 int ClassDeclaration::isFuncHidden(FuncDeclaration *fd) 864 int ClassDeclaration::isFuncHidden(FuncDeclaration *fd)
833 { 865 {
834 //printf("ClassDeclaration::isFuncHidden(%s)\n", fd->toChars()); 866 //printf("ClassDeclaration::isFuncHidden(class = %s, fd = %s)\n", toChars(), fd->toChars());
835 Dsymbol *s = search(0, fd->ident, 4|2); 867 Dsymbol *s = search(0, fd->ident, 4|2);
836 if (!s) 868 if (!s)
837 { //printf("not found\n"); 869 { //printf("not found\n");
838 /* Because, due to a hack, if there are multiple definitions 870 /* Because, due to a hack, if there are multiple definitions
839 * of fd->ident, NULL is returned. 871 * of fd->ident, NULL is returned.
914 int ClassDeclaration::isCOMinterface() 946 int ClassDeclaration::isCOMinterface()
915 { 947 {
916 return 0; 948 return 0;
917 } 949 }
918 950
951 #if DMDV2
952 int ClassDeclaration::isCPPinterface()
953 {
954 return 0;
955 }
956 #endif
957
919 958
920 /**************************************** 959 /****************************************
921 */ 960 */
922 961
923 int ClassDeclaration::isAbstract() 962 int ClassDeclaration::isAbstract()
1004 { int i; 1043 { int i;
1005 1044
1006 //printf("InterfaceDeclaration::semantic(%s), type = %p\n", toChars(), type); 1045 //printf("InterfaceDeclaration::semantic(%s), type = %p\n", toChars(), type);
1007 if (inuse) 1046 if (inuse)
1008 return; 1047 return;
1009 if (!scope) 1048
1010 { type = type->semantic(loc, sc); 1049 if (!sc)
1011 handle = handle->semantic(loc, sc); 1050 sc = scope;
1012 } 1051 if (!parent && sc->parent && !sc->parent->isModule())
1052 parent = sc->parent;
1053
1054 type = type->semantic(loc, sc);
1055 handle = type;
1056
1013 if (!members) // if forward reference 1057 if (!members) // if forward reference
1014 { //printf("\tinterface '%s' is forward referenced\n", toChars()); 1058 { //printf("\tinterface '%s' is forward referenced\n", toChars());
1015 return; 1059 return;
1016 } 1060 }
1017 if (symtab) // if already done 1061 if (symtab) // if already done
1087 if (b->base == this || isBaseOf2(b->base)) 1131 if (b->base == this || isBaseOf2(b->base))
1088 { 1132 {
1089 error("circular inheritance of interface"); 1133 error("circular inheritance of interface");
1090 baseclasses.remove(i); 1134 baseclasses.remove(i);
1091 continue; 1135 continue;
1136 }
1137 if (!b->base->symtab)
1138 { // Try to resolve forward reference
1139 if (sc->mustsemantic && b->base->scope)
1140 b->base->semantic(NULL);
1092 } 1141 }
1093 if (!b->base->symtab || b->base->scope || b->base->inuse) 1142 if (!b->base->symtab || b->base->scope || b->base->inuse)
1094 { 1143 {
1095 //error("forward reference of base class %s", baseClass->toChars()); 1144 //error("forward reference of base class %s", baseClass->toChars());
1096 // Forward reference of base, try again later 1145 // Forward reference of base, try again later
1260 int InterfaceDeclaration::isCOMinterface() 1309 int InterfaceDeclaration::isCOMinterface()
1261 { 1310 {
1262 return com; 1311 return com;
1263 } 1312 }
1264 1313
1314 #if DMDV2
1315 int InterfaceDeclaration::isCPPinterface()
1316 {
1317 return cpp;
1318 }
1319 #endif
1320
1265 /******************************************* 1321 /*******************************************
1266 */ 1322 */
1267 1323
1268 const char *InterfaceDeclaration::kind() 1324 const char *InterfaceDeclaration::kind()
1269 { 1325 {