Mercurial > projects > ldc
comparison dmd2/class.c @ 1526:54b3c1394d62
Merged dmdfe 2.031.
author | Robert Clipsham <robert@octarineparrot.com> |
---|---|
date | Tue, 07 Jul 2009 02:26:11 +0100 |
parents | 638d16625da2 |
children | e4f7b5d9c68a |
comparison
equal
deleted
inserted
replaced
1525:d28cd7c45267 | 1526:54b3c1394d62 |
---|---|
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. |
231 { const char *id = "__anonclass"; | 231 { const char *id = "__anonclass"; |
232 | 232 |
233 ident = Identifier::generateId(id); | 233 ident = Identifier::generateId(id); |
234 } | 234 } |
235 | 235 |
236 if (!scope) | 236 if (!sc) |
237 { | 237 sc = scope; |
238 if (!parent && sc->parent && !sc->parent->isModule()) | 238 if (!parent && sc->parent && !sc->parent->isModule()) |
239 parent = sc->parent; | 239 parent = sc->parent; |
240 | 240 |
241 type = type->semantic(loc, sc); | 241 type = type->semantic(loc, sc); |
242 handle = handle->semantic(loc, sc); | 242 handle = type; |
243 } | 243 |
244 if (!members) // if forward reference | 244 if (!members) // if forward reference |
245 { //printf("\tclass '%s' is forward referenced\n", toChars()); | 245 { //printf("\tclass '%s' is forward referenced\n", toChars()); |
246 return; | 246 return; |
247 } | 247 } |
248 if (symtab) | 248 if (symtab) |
273 error("cannot create C++ classes"); | 273 error("cannot create C++ classes"); |
274 | 274 |
275 // Expand any tuples in baseclasses[] | 275 // Expand any tuples in baseclasses[] |
276 for (i = 0; i < baseclasses.dim; ) | 276 for (i = 0; i < baseclasses.dim; ) |
277 { BaseClass *b = (BaseClass *)baseclasses.data[i]; | 277 { BaseClass *b = (BaseClass *)baseclasses.data[i]; |
278 //printf("test1 %s %s\n", toChars(), b->type->toChars()); | |
278 b->type = b->type->semantic(loc, sc); | 279 b->type = b->type->semantic(loc, sc); |
280 //printf("test2\n"); | |
279 Type *tb = b->type->toBasetype(); | 281 Type *tb = b->type->toBasetype(); |
280 | 282 |
281 if (tb->ty == Ttuple) | 283 if (tb->ty == Ttuple) |
282 { TypeTuple *tup = (TypeTuple *)tb; | 284 { TypeTuple *tup = (TypeTuple *)tb; |
283 enum PROT protection = b->protection; | 285 enum PROT protection = b->protection; |
332 error("circular inheritance"); | 334 error("circular inheritance"); |
333 baseclasses.remove(0); | 335 baseclasses.remove(0); |
334 goto L7; | 336 goto L7; |
335 } | 337 } |
336 } | 338 } |
339 if (!tc->sym->symtab || tc->sym->sizeok == 0) | |
340 { // Try to resolve forward reference | |
341 if (sc->mustsemantic && tc->sym->scope) | |
342 tc->sym->semantic(NULL); | |
343 } | |
337 if (!tc->sym->symtab || tc->sym->scope || tc->sym->sizeok == 0) | 344 if (!tc->sym->symtab || tc->sym->scope || tc->sym->sizeok == 0) |
338 { | 345 { |
346 //printf("%s: forward reference of base class %s\n", toChars(), tc->sym->toChars()); | |
339 //error("forward reference of base class %s", baseClass->toChars()); | 347 //error("forward reference of base class %s", baseClass->toChars()); |
340 // Forward reference of base class, try again later | 348 // Forward reference of base class, try again later |
341 //printf("\ttry later, forward reference of base class %s\n", tc->sym->toChars()); | 349 //printf("\ttry later, forward reference of base class %s\n", tc->sym->toChars()); |
342 scope = scx ? scx : new Scope(*sc); | 350 scope = scx ? scx : new Scope(*sc); |
343 scope->setNoFree(); | 351 scope->setNoFree(); |
791 { | 799 { |
792 Dsymbol *s; | 800 Dsymbol *s; |
793 | 801 |
794 //printf("%s.ClassDeclaration::search('%s')\n", toChars(), ident->toChars()); | 802 //printf("%s.ClassDeclaration::search('%s')\n", toChars(), ident->toChars()); |
795 if (scope) | 803 if (scope) |
796 semantic(scope); | 804 { Scope *sc = scope; |
805 sc->mustsemantic++; | |
806 semantic(sc); | |
807 sc->mustsemantic--; | |
808 } | |
797 | 809 |
798 if (!members || !symtab || scope) | 810 if (!members || !symtab || scope) |
799 { error("is forward referenced when looking for '%s'", ident->toChars()); | 811 { |
812 error("is forward referenced when looking for '%s'", ident->toChars()); | |
800 //*(char*)0=0; | 813 //*(char*)0=0; |
801 return NULL; | 814 return NULL; |
802 } | 815 } |
803 | 816 |
804 s = ScopeDsymbol::search(loc, ident, flags); | 817 s = ScopeDsymbol::search(loc, ident, flags); |
1035 { int i; | 1048 { int i; |
1036 | 1049 |
1037 //printf("InterfaceDeclaration::semantic(%s), type = %p\n", toChars(), type); | 1050 //printf("InterfaceDeclaration::semantic(%s), type = %p\n", toChars(), type); |
1038 if (inuse) | 1051 if (inuse) |
1039 return; | 1052 return; |
1040 if (!scope) | 1053 |
1041 { type = type->semantic(loc, sc); | 1054 if (!sc) |
1042 handle = handle->semantic(loc, sc); | 1055 sc = scope; |
1043 } | 1056 if (!parent && sc->parent && !sc->parent->isModule()) |
1057 parent = sc->parent; | |
1058 | |
1059 type = type->semantic(loc, sc); | |
1060 handle = type; | |
1061 | |
1044 if (!members) // if forward reference | 1062 if (!members) // if forward reference |
1045 { //printf("\tinterface '%s' is forward referenced\n", toChars()); | 1063 { //printf("\tinterface '%s' is forward referenced\n", toChars()); |
1046 return; | 1064 return; |
1047 } | 1065 } |
1048 if (symtab) // if already done | 1066 if (symtab) // if already done |