Mercurial > projects > ldc
comparison dmd/class.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 | c53b6e3fe49a |
children | 5acec6b2eef8 |
comparison
equal
deleted
inserted
replaced
34:4648206ca213 | 35:3cfcb944304e |
---|---|
1 | 1 |
2 // Compiler implementation of the D programming language | 2 // Compiler implementation of the D programming language |
3 // Copyright (c) 1999-2006 by Digital Mars | 3 // Copyright (c) 1999-2007 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. |
144 if (id == Id::TypeInfo_Tuple) | 144 if (id == Id::TypeInfo_Tuple) |
145 { if (Type::typeinfotypelist) | 145 { if (Type::typeinfotypelist) |
146 Type::typeinfotypelist->error("%s", msg); | 146 Type::typeinfotypelist->error("%s", msg); |
147 Type::typeinfotypelist = this; | 147 Type::typeinfotypelist = this; |
148 } | 148 } |
149 | |
150 #if V2 | |
151 if (id == Id::TypeInfo_Const) | |
152 { if (Type::typeinfoconst) | |
153 Type::typeinfoconst->error("%s", msg); | |
154 Type::typeinfoconst = this; | |
155 } | |
156 | |
157 if (id == Id::TypeInfo_Invariant) | |
158 { if (Type::typeinfoinvariant) | |
159 Type::typeinfoinvariant->error("%s", msg); | |
160 Type::typeinfoinvariant = this; | |
161 } | |
162 #endif | |
149 } | 163 } |
150 | 164 |
151 if (id == Id::Object) | 165 if (id == Id::Object) |
152 { if (object) | 166 { if (object) |
153 object->error("%s", msg); | 167 object->error("%s", msg); |
166 Module::moduleinfo = this; | 180 Module::moduleinfo = this; |
167 } | 181 } |
168 } | 182 } |
169 | 183 |
170 com = 0; | 184 com = 0; |
171 #if 0 | |
172 if (id == Id::IUnknown) // IUnknown is the root of all COM objects | |
173 com = 1; | |
174 #endif | |
175 isauto = 0; | 185 isauto = 0; |
176 isabstract = 0; | 186 isabstract = 0; |
177 isnested = 0; | 187 isnested = 0; |
178 vthis = NULL; | 188 vthis = NULL; |
179 } | 189 } |
246 scope = NULL; | 256 scope = NULL; |
247 } | 257 } |
248 #ifdef IN_GCC | 258 #ifdef IN_GCC |
249 methods.setDim(0); | 259 methods.setDim(0); |
250 #endif | 260 #endif |
261 | |
262 if (sc->stc & STCdeprecated) | |
263 { //printf("test1: %s is deprecated\n", toChars()); | |
264 isdeprecated = 1; | |
265 } | |
251 | 266 |
252 // Expand any tuples in baseclasses[] | 267 // Expand any tuples in baseclasses[] |
253 for (i = 0; i < baseclasses.dim; ) | 268 for (i = 0; i < baseclasses.dim; ) |
254 { BaseClass *b = (BaseClass *)baseclasses.data[i]; | 269 { BaseClass *b = (BaseClass *)baseclasses.data[i]; |
255 b->type = b->type->semantic(loc, sc); | 270 b->type = b->type->semantic(loc, sc); |
284 baseclasses.remove(0); | 299 baseclasses.remove(0); |
285 } | 300 } |
286 else | 301 else |
287 { | 302 { |
288 tc = (TypeClass *)(tb); | 303 tc = (TypeClass *)(tb); |
304 if (tc->sym->isDeprecated()) | |
305 { | |
306 if (!isDeprecated()) | |
307 { | |
308 // Deriving from deprecated class makes this one deprecated too | |
309 isdeprecated = 1; | |
310 | |
311 tc->checkDeprecated(loc, sc); | |
312 } | |
313 } | |
314 | |
289 if (tc->sym->isInterfaceDeclaration()) | 315 if (tc->sym->isInterfaceDeclaration()) |
290 ; | 316 ; |
291 else | 317 else |
292 { | 318 { |
293 for (ClassDeclaration *cdb = tc->sym; cdb; cdb = cdb->baseClass) | 319 for (ClassDeclaration *cdb = tc->sym; cdb; cdb = cdb->baseClass) |
338 baseclasses.remove(i); | 364 baseclasses.remove(i); |
339 continue; | 365 continue; |
340 } | 366 } |
341 else | 367 else |
342 { | 368 { |
369 if (tc->sym->isDeprecated()) | |
370 { | |
371 if (!isDeprecated()) | |
372 { | |
373 // Deriving from deprecated class makes this one deprecated too | |
374 isdeprecated = 1; | |
375 | |
376 tc->checkDeprecated(loc, sc); | |
377 } | |
378 } | |
379 | |
343 // Check for duplicate interfaces | 380 // Check for duplicate interfaces |
344 for (size_t j = (baseClass ? 1 : 0); j < i; j++) | 381 for (size_t j = (baseClass ? 1 : 0); j < i; j++) |
345 { | 382 { |
346 BaseClass *b2 = (BaseClass *)baseclasses.data[j]; | 383 BaseClass *b2 = (BaseClass *)baseclasses.data[j]; |
347 if (b2->base == tc->sym) | 384 if (b2->base == tc->sym) |
478 | 515 |
479 if (storage_class & (STCauto | STCscope)) | 516 if (storage_class & (STCauto | STCscope)) |
480 isauto = 1; | 517 isauto = 1; |
481 if (storage_class & STCabstract) | 518 if (storage_class & STCabstract) |
482 isabstract = 1; | 519 isabstract = 1; |
483 if (storage_class & STCdeprecated) | |
484 isdeprecated = 1; | |
485 | 520 |
486 sc = sc->push(this); | 521 sc = sc->push(this); |
487 sc->stc &= ~(STCfinal | STCauto | STCscope | STCstatic | | 522 sc->stc &= ~(STCfinal | STCauto | STCscope | STCstatic | |
488 STCabstract | STCdeprecated); | 523 STCabstract | STCdeprecated); |
489 sc->parent = this; | 524 sc->parent = this; |
565 //printf("Creating default this(){} for class %s\n", toChars()); | 600 //printf("Creating default this(){} for class %s\n", toChars()); |
566 ctor = new CtorDeclaration(0, 0, NULL, 0); | 601 ctor = new CtorDeclaration(0, 0, NULL, 0); |
567 ctor->fbody = new CompoundStatement(0, new Statements()); | 602 ctor->fbody = new CompoundStatement(0, new Statements()); |
568 members->push(ctor); | 603 members->push(ctor); |
569 ctor->addMember(sc, this, 1); | 604 ctor->addMember(sc, this, 1); |
570 *sc = scsave; | 605 *sc = scsave; // why? What about sc->nofree? |
571 sc->offset = structsize; | 606 sc->offset = structsize; |
572 ctor->semantic(sc); | 607 ctor->semantic(sc); |
573 defaultCtor = ctor; | 608 defaultCtor = ctor; |
574 } | 609 } |
575 | 610 |
752 } | 787 } |
753 } | 788 } |
754 return s; | 789 return s; |
755 } | 790 } |
756 | 791 |
792 /********************************************************** | |
793 * fd is in the vtbl[] for this class. | |
794 * Return 1 if function is hidden (not findable through search). | |
795 */ | |
796 | |
797 #if V2 | |
798 int isf(void *param, FuncDeclaration *fd) | |
799 { | |
800 //printf("param = %p, fd = %p %s\n", param, fd, fd->toChars()); | |
801 return param == fd; | |
802 } | |
803 | |
804 int ClassDeclaration::isFuncHidden(FuncDeclaration *fd) | |
805 { | |
806 //printf("ClassDeclaration::isFuncHidden(%s)\n", fd->toChars()); | |
807 Dsymbol *s = search(0, fd->ident, 4|2); | |
808 if (!s) | |
809 { //printf("not found\n"); | |
810 /* Because, due to a hack, if there are multiple definitions | |
811 * of fd->ident, NULL is returned. | |
812 */ | |
813 return 0; | |
814 } | |
815 FuncDeclaration *fdstart = s->toAlias()->isFuncDeclaration(); | |
816 //printf("%s fdstart = %p\n", s->kind(), fdstart); | |
817 return !overloadApply(fdstart, &isf, fd); | |
818 } | |
819 #endif | |
820 | |
757 /**************** | 821 /**************** |
758 * Find virtual function matching identifier and type. | 822 * Find virtual function matching identifier and type. |
759 * Used to build virtual function tables for interface implementations. | 823 * Used to build virtual function tables for interface implementations. |
760 */ | 824 */ |
761 | 825 |
800 { | 864 { |
801 BaseClass *b = interfaces[i]; | 865 BaseClass *b = interfaces[i]; |
802 | 866 |
803 // If this is an interface, and it derives from a COM interface, | 867 // If this is an interface, and it derives from a COM interface, |
804 // then this is a COM interface too. | 868 // then this is a COM interface too. |
805 if (b->base->isCOMclass()) | 869 if (b->base->isCOMinterface()) |
806 com = 1; | 870 com = 1; |
807 | 871 |
808 vtblInterfaces->push(b); | 872 vtblInterfaces->push(b); |
809 b->copyBaseInterfaces(vtblInterfaces); | 873 b->copyBaseInterfaces(vtblInterfaces); |
810 } | 874 } |
814 */ | 878 */ |
815 | 879 |
816 int ClassDeclaration::isCOMclass() | 880 int ClassDeclaration::isCOMclass() |
817 { | 881 { |
818 return com; | 882 return com; |
883 } | |
884 | |
885 int ClassDeclaration::isCOMinterface() | |
886 { | |
887 return 0; | |
819 } | 888 } |
820 | 889 |
821 | 890 |
822 /**************************************** | 891 /**************************************** |
823 */ | 892 */ |
923 Scope *scx = NULL; | 992 Scope *scx = NULL; |
924 if (scope) | 993 if (scope) |
925 { sc = scope; | 994 { sc = scope; |
926 scx = scope; // save so we don't make redundant copies | 995 scx = scope; // save so we don't make redundant copies |
927 scope = NULL; | 996 scope = NULL; |
997 } | |
998 | |
999 if (sc->stc & STCdeprecated) | |
1000 { | |
1001 isdeprecated = 1; | |
928 } | 1002 } |
929 | 1003 |
930 // Expand any tuples in baseclasses[] | 1004 // Expand any tuples in baseclasses[] |
931 for (i = 0; i < baseclasses.dim; ) | 1005 for (i = 0; i < baseclasses.dim; ) |
932 { BaseClass *b = (BaseClass *)baseclasses.data[0]; | 1006 { BaseClass *b = (BaseClass *)baseclasses.data[0]; |
1042 s->addMember(sc, this, 1); | 1116 s->addMember(sc, this, 1); |
1043 } | 1117 } |
1044 | 1118 |
1045 sc = sc->push(this); | 1119 sc = sc->push(this); |
1046 sc->parent = this; | 1120 sc->parent = this; |
1047 if (isCOMclass()) | 1121 if (isCOMinterface()) |
1048 sc->linkage = LINKwindows; | 1122 sc->linkage = LINKwindows; |
1049 sc->structalign = 8; | 1123 sc->structalign = 8; |
1050 structalign = sc->structalign; | 1124 structalign = sc->structalign; |
1051 sc->offset = 8; | 1125 sc->offset = 8; |
1052 for (i = 0; i < members->dim; i++) | 1126 for (i = 0; i < members->dim; i++) |
1132 return 0; | 1206 return 0; |
1133 } | 1207 } |
1134 | 1208 |
1135 /**************************************** | 1209 /**************************************** |
1136 * Determine if slot 0 of the vtbl[] is reserved for something else. | 1210 * Determine if slot 0 of the vtbl[] is reserved for something else. |
1137 * For class objects, yes, this is where the classinfo ptr goes. | 1211 * For class objects, yes, this is where the ClassInfo ptr goes. |
1138 * For COM interfaces, no. | 1212 * For COM interfaces, no. |
1139 * For non-COM interfaces, yes, this is where the Interface ptr goes. | 1213 * For non-COM interfaces, yes, this is where the Interface ptr goes. |
1140 */ | 1214 */ |
1141 | 1215 |
1142 int InterfaceDeclaration::vtblOffset() | 1216 int InterfaceDeclaration::vtblOffset() |
1143 { | 1217 { |
1144 if (isCOMclass()) | 1218 if (isCOMinterface()) |
1145 return 0; | 1219 return 0; |
1146 return 1; | 1220 return 1; |
1221 } | |
1222 | |
1223 int InterfaceDeclaration::isCOMinterface() | |
1224 { | |
1225 return com; | |
1147 } | 1226 } |
1148 | 1227 |
1149 /******************************************* | 1228 /******************************************* |
1150 */ | 1229 */ |
1151 | 1230 |