comparison dmd2/class.c @ 1452:638d16625da2

LDC 2 compiles again.
author Robert Clipsham <robert@octarineparrot.com>
date Sat, 30 May 2009 17:23:32 +0100
parents 69a5e4a6fc0f
children 54b3c1394d62
comparison
equal deleted inserted replaced
1423:42bd767ec5a4 1452:638d16625da2
11 #include <stdio.h> 11 #include <stdio.h>
12 #include <stdlib.h> 12 #include <stdlib.h>
13 #include <assert.h> 13 #include <assert.h>
14 14
15 #include "root.h" 15 #include "root.h"
16 #include "mem.h" 16 #include "rmem.h"
17 17
18 #include "enum.h" 18 #include "enum.h"
19 #include "init.h" 19 #include "init.h"
20 #include "attrib.h" 20 #include "attrib.h"
21 #include "declaration.h" 21 #include "declaration.h"
53 handle = type; 53 handle = type;
54 54
55 staticCtor = NULL; 55 staticCtor = NULL;
56 staticDtor = NULL; 56 staticDtor = NULL;
57 57
58 #if IN_DMD
58 vtblsym = NULL; 59 vtblsym = NULL;
60 #endif
59 vclassinfo = NULL; 61 vclassinfo = NULL;
60 62
61 if (id) 63 if (id)
62 { // Look for special class names 64 { // Look for special class names
63 65
155 if (id == Id::TypeInfo_Invariant) 157 if (id == Id::TypeInfo_Invariant)
156 { if (Type::typeinfoinvariant) 158 { if (Type::typeinfoinvariant)
157 Type::typeinfoinvariant->error("%s", msg); 159 Type::typeinfoinvariant->error("%s", msg);
158 Type::typeinfoinvariant = this; 160 Type::typeinfoinvariant = this;
159 } 161 }
162
163 if (id == Id::TypeInfo_Shared)
164 { if (Type::typeinfoshared)
165 Type::typeinfoshared->error("%s", msg);
166 Type::typeinfoshared = this;
167 }
160 #endif 168 #endif
161 } 169 }
162 170
163 if (id == Id::Object) 171 if (id == Id::Object)
164 { if (object) 172 { if (object)
180 } 188 }
181 189
182 com = 0; 190 com = 0;
183 isauto = 0; 191 isauto = 0;
184 isabstract = 0; 192 isabstract = 0;
185 isnested = 0;
186 vthis = NULL;
187 inuse = 0; 193 inuse = 0;
188 } 194 }
189 195
190 Dsymbol *ClassDeclaration::syntaxCopy(Dsymbol *s) 196 Dsymbol *ClassDeclaration::syntaxCopy(Dsymbol *s)
191 { 197 {
446 452
447 // Inherit properties from base class 453 // Inherit properties from base class
448 com = baseClass->isCOMclass(); 454 com = baseClass->isCOMclass();
449 isauto = baseClass->isauto; 455 isauto = baseClass->isauto;
450 vthis = baseClass->vthis; 456 vthis = baseClass->vthis;
451 storage_class |= baseClass->storage_class & (STCconst | STCinvariant); 457 storage_class |= baseClass->storage_class & STC_TYPECTOR;
452 } 458 }
453 else 459 else
454 { 460 {
455 // No base class, so this is the root of the class hierarchy 461 // No base class, so this is the root of the class hierarchy
456 vtbl.setDim(0); 462 vtbl.setDim(0);
498 } 504 }
499 else if (!(storage_class & STCstatic)) 505 else if (!(storage_class & STCstatic))
500 { Dsymbol *s = toParent2(); 506 { Dsymbol *s = toParent2();
501 if (s) 507 if (s)
502 { 508 {
503 ClassDeclaration *cd = s->isClassDeclaration(); 509 AggregateDeclaration *ad = s->isClassDeclaration();
504 FuncDeclaration *fd = s->isFuncDeclaration(); 510 FuncDeclaration *fd = s->isFuncDeclaration();
505 511
506 512
507 if (cd || fd) 513 if (ad || fd)
508 { isnested = 1; 514 { isnested = 1;
509 Type *t; 515 Type *t;
510 if (cd) 516 if (ad)
511 t = cd->type; 517 t = ad->handle;
512 else if (fd) 518 else if (fd)
513 { AggregateDeclaration *ad = fd->isMember2(); 519 { AggregateDeclaration *ad = fd->isMember2();
514 if (ad) 520 if (ad)
515 t = ad->handle; 521 t = ad->handle;
516 else 522 else
517 { 523 {
518 t = new TypePointer(Type::tvoid); 524 t = Type::tvoidptr;
519 t = t->semantic(0, sc);
520 } 525 }
521 } 526 }
522 else 527 else
523 assert(0); 528 assert(0);
529 if (t->ty == Tstruct) // ref to struct
530 t = Type::tvoidptr;
524 assert(!vthis); 531 assert(!vthis);
525 vthis = new ThisDeclaration(t); 532 vthis = new ThisDeclaration(loc, t);
526 members->push(vthis); 533 members->push(vthis);
527 } 534 }
528 } 535 }
529 } 536 }
530 } 537 }
531 538
532 if (storage_class & (STCauto | STCscope)) 539 if (storage_class & (STCauto | STCscope))
533 isauto = 1; 540 isauto = 1;
534 if (storage_class & STCabstract) 541 if (storage_class & STCabstract)
535 isabstract = 1; 542 isabstract = 1;
536 if (storage_class & STCinvariant) 543 if (storage_class & STCimmutable)
537 type = type->invariantOf(); 544 type = type->invariantOf();
538 else if (storage_class & STCconst) 545 else if (storage_class & STCconst)
539 type = type->constOf(); 546 type = type->constOf();
547 else if (storage_class & STCshared)
548 type = type->sharedOf();
540 549
541 sc = sc->push(this); 550 sc = sc->push(this);
542 sc->stc &= ~(STCfinal | STCauto | STCscope | STCstatic | 551 sc->stc &= ~(STCfinal | STCauto | STCscope | STCstatic |
543 STCabstract | STCdeprecated | STCconst | STCinvariant | STCtls); 552 STCabstract | STCdeprecated | STC_TYPECTOR | STCtls | STCgshared);
544 sc->stc |= storage_class & (STCconst | STCinvariant); 553 sc->stc |= storage_class & STC_TYPECTOR;
545 sc->parent = this; 554 sc->parent = this;
546 sc->inunion = 0; 555 sc->inunion = 0;
547 556
548 if (isCOMclass()) 557 if (isCOMclass())
558 {
559 #if _WIN32
549 sc->linkage = LINKwindows; 560 sc->linkage = LINKwindows;
561 #else
562 /* This enables us to use COM objects under Linux and
563 * work with things like XPCOM
564 */
565 sc->linkage = LINKc;
566 #endif
567 }
550 sc->protection = PROTpublic; 568 sc->protection = PROTpublic;
551 sc->explicitProtection = 0; 569 sc->explicitProtection = 0;
552 sc->structalign = 8; 570 sc->structalign = 8;
553 structalign = sc->structalign; 571 structalign = sc->structalign;
554 if (baseClass) 572 if (baseClass)
617 // a constructor: 635 // a constructor:
618 // this() { } 636 // this() { }
619 if (!ctor && baseClass && baseClass->ctor) 637 if (!ctor && baseClass && baseClass->ctor)
620 { 638 {
621 //printf("Creating default this(){} for class %s\n", toChars()); 639 //printf("Creating default this(){} for class %s\n", toChars());
622 ctor = new CtorDeclaration(loc, 0, NULL, 0); 640 CtorDeclaration *ctor = new CtorDeclaration(loc, 0, NULL, 0);
623 ctor->fbody = new CompoundStatement(0, new Statements()); 641 ctor->fbody = new CompoundStatement(0, new Statements());
624 members->push(ctor); 642 members->push(ctor);
625 ctor->addMember(sc, this, 1); 643 ctor->addMember(sc, this, 1);
626 *sc = scsave; // why? What about sc->nofree? 644 *sc = scsave; // why? What about sc->nofree?
627 sc->offset = structsize; 645 sc->offset = structsize;
628 ctor->semantic(sc); 646 ctor->semantic(sc);
647 this->ctor = ctor;
629 defaultCtor = ctor; 648 defaultCtor = ctor;
630 } 649 }
631 650
632 #if 0 651 #if 0
633 if (baseClass) 652 if (baseClass)
839 if (os) 858 if (os)
840 { 859 {
841 for (int i = 0; i < os->a.dim; i++) 860 for (int i = 0; i < os->a.dim; i++)
842 { Dsymbol *s = (Dsymbol *)os->a.data[i]; 861 { Dsymbol *s = (Dsymbol *)os->a.data[i];
843 FuncDeclaration *f2 = s->isFuncDeclaration(); 862 FuncDeclaration *f2 = s->isFuncDeclaration();
844 if (f2 && overloadApply(f2, &isf, fd)) 863 if (f2 && overloadApply(getModule(), f2, &isf, fd))
845 return 0; 864 return 0;
846 } 865 }
847 return 1; 866 return 1;
848 } 867 }
849 else 868 else
850 { 869 {
851 FuncDeclaration *fdstart = s->isFuncDeclaration(); 870 FuncDeclaration *fdstart = s->isFuncDeclaration();
852 //printf("%s fdstart = %p\n", s->kind(), fdstart); 871 //printf("%s fdstart = %p\n", s->kind(), fdstart);
853 return !overloadApply(fdstart, &isf, fd); 872 return !overloadApply(getModule(), fdstart, &isf, fd);
854 } 873 }
855 } 874 }
856 #endif 875 #endif
857 876
858 /**************** 877 /****************
868 Array *vtbl = &cd->vtbl; 887 Array *vtbl = &cd->vtbl;
869 while (1) 888 while (1)
870 { 889 {
871 for (size_t i = 0; i < vtbl->dim; i++) 890 for (size_t i = 0; i < vtbl->dim; i++)
872 { 891 {
873 FuncDeclaration *fd = (FuncDeclaration *)vtbl->data[i]; 892 FuncDeclaration *fd = ((Dsymbol*)vtbl->data[i])->isFuncDeclaration();
893 if (!fd)
894 continue; // the first entry might be a ClassInfo
874 895
875 //printf("\t[%d] = %s\n", i, fd->toChars()); 896 //printf("\t[%d] = %s\n", i, fd->toChars());
876 if (ident == fd->ident && 897 if (ident == fd->ident &&
877 //tf->equals(fd->type) 898 //tf->equals(fd->type)
878 fd->type->covariant(tf) == 1 899 fd->type->covariant(tf) == 1
953 } 974 }
954 } 975 }
955 return FALSE; 976 return FALSE;
956 } 977 }
957 978
958
959 /****************************************
960 * Returns !=0 if there's an extra member which is the 'this'
961 * pointer to the enclosing context (enclosing class or function)
962 */
963
964 int ClassDeclaration::isNested()
965 {
966 return isnested;
967 }
968 979
969 /**************************************** 980 /****************************************
970 * Determine if slot 0 of the vtbl[] is reserved for something else. 981 * Determine if slot 0 of the vtbl[] is reserved for something else.
971 * For class objects, yes, this is where the classinfo ptr goes. 982 * For class objects, yes, this is where the classinfo ptr goes.
972 * For COM interfaces, no. 983 * For COM interfaces, no.
1124 return; 1135 return;
1125 } 1136 }
1126 } 1137 }
1127 #if 0 1138 #if 0
1128 // Inherit const/invariant from base class 1139 // Inherit const/invariant from base class
1129 storage_class |= b->base->storage_class & (STCconst | STCinvariant); 1140 storage_class |= b->base->storage_class & STC_TYPECTOR;
1130 #endif 1141 #endif
1131 i++; 1142 i++;
1132 } 1143 }
1133 1144
1134 interfaces_dim = baseclasses.dim; 1145 interfaces_dim = baseclasses.dim;
1168 Lcontinue: 1179 Lcontinue:
1169 ; 1180 ;
1170 } 1181 }
1171 1182
1172 protection = sc->protection; 1183 protection = sc->protection;
1173 storage_class |= sc->stc & (STCconst | STCinvariant); 1184 storage_class |= sc->stc & STC_TYPECTOR;
1174 1185
1175 for (i = 0; i < members->dim; i++) 1186 for (i = 0; i < members->dim; i++)
1176 { 1187 {
1177 Dsymbol *s = (Dsymbol *)members->data[i]; 1188 Dsymbol *s = (Dsymbol *)members->data[i];
1178 s->addMember(sc, this, 1); 1189 s->addMember(sc, this, 1);
1179 } 1190 }
1180 1191
1181 sc = sc->push(this); 1192 sc = sc->push(this);
1182 sc->stc &= ~(STCfinal | STCauto | STCscope | STCstatic | 1193 sc->stc &= ~(STCfinal | STCauto | STCscope | STCstatic |
1183 STCabstract | STCdeprecated | STCconst | STCinvariant | STCtls); 1194 STCabstract | STCdeprecated | STC_TYPECTOR | STCtls | STCgshared);
1184 sc->stc |= storage_class & (STCconst | STCinvariant); 1195 sc->stc |= storage_class & STC_TYPECTOR;
1185 sc->parent = this; 1196 sc->parent = this;
1186 if (isCOMinterface()) 1197 if (isCOMinterface())
1187 sc->linkage = LINKwindows; 1198 sc->linkage = LINKwindows;
1188 else if (isCPPinterface()) 1199 else if (isCPPinterface())
1189 sc->linkage = LINKcpp; 1200 sc->linkage = LINKcpp;
1260 1271
1261 if (this == b->base) 1272 if (this == b->base)
1262 { 1273 {
1263 if (poffset) 1274 if (poffset)
1264 { *poffset = b->offset; 1275 { *poffset = b->offset;
1276 if (j && bc->base->isInterfaceDeclaration())
1277 *poffset = OFFSET_RUNTIME;
1265 } 1278 }
1266 return 1; 1279 return 1;
1267 } 1280 }
1268 if (isBaseOf(b, poffset)) 1281 if (isBaseOf(b, poffset))
1269 { 1282 { if (j && poffset && bc->base->isInterfaceDeclaration())
1283 *poffset = OFFSET_RUNTIME;
1270 return 1; 1284 return 1;
1271 } 1285 }
1272 } 1286 }
1273 if (poffset) 1287 if (poffset)
1274 *poffset = 0; 1288 *poffset = 0;