Mercurial > projects > ddmd
comparison dmd/TypeStruct.d @ 55:8c2c7b7579f8
Expression.toMangleBuffer
Expression.toDelegate
Expression.scanForNestedRef
TypeStruct.deduceType
TypeStruct.toChars
DefaultInitExp wrong TOK bug fixed
author | korDen |
---|---|
date | Sat, 21 Aug 2010 13:28:16 +0400 |
parents | 10317f0c89a5 |
children | 2e2a5c3f943a |
comparison
equal
deleted
inserted
replaced
54:f95140b40251 | 55:8c2c7b7579f8 |
---|---|
1 module dmd.TypeStruct; | 1 module dmd.TypeStruct; |
2 | 2 |
3 import dmd.Type; | 3 import dmd.Type; |
4 import dmd.TypeInstance; | |
4 import dmd.StructDeclaration; | 5 import dmd.StructDeclaration; |
5 import dmd.Declaration; | 6 import dmd.Declaration; |
6 import dmd.STC; | 7 import dmd.STC; |
7 import dmd.MOD; | 8 import dmd.MOD; |
8 import dmd.OutBuffer; | 9 import dmd.OutBuffer; |
27 import dmd.HdrGenState; | 28 import dmd.HdrGenState; |
28 import dmd.Expression; | 29 import dmd.Expression; |
29 import dmd.Identifier; | 30 import dmd.Identifier; |
30 import dmd.MATCH; | 31 import dmd.MATCH; |
31 import dmd.ArrayTypes; | 32 import dmd.ArrayTypes; |
33 import dmd.DYNCAST; | |
32 import dmd.TemplateInstance; | 34 import dmd.TemplateInstance; |
33 import dmd.FuncDeclaration; | 35 import dmd.FuncDeclaration; |
34 import dmd.VarExp; | 36 import dmd.VarExp; |
35 import dmd.CommaExp; | 37 import dmd.CommaExp; |
36 import dmd.ThisExp; | 38 import dmd.ThisExp; |
96 return sz; | 98 return sz; |
97 } | 99 } |
98 | 100 |
99 string toChars() | 101 string toChars() |
100 { | 102 { |
101 assert(false); | 103 //printf("sym.parent: %s, deco = %s\n", sym.parent.toChars(), deco); |
104 if (mod) | |
105 return Type.toChars(); | |
106 TemplateInstance ti = sym.parent.isTemplateInstance(); | |
107 if (ti && ti.toAlias() == sym) | |
108 { | |
109 return ti.toChars(); | |
110 } | |
111 return sym.toChars(); | |
102 } | 112 } |
103 | 113 |
104 Type syntaxCopy() | 114 Type syntaxCopy() |
105 { | 115 { |
106 assert(false); | 116 assert(false); |
443 return pdt; | 453 return pdt; |
444 } | 454 } |
445 | 455 |
446 MATCH deduceType(Scope sc, Type tparam, TemplateParameters parameters, Objects dedtypes) | 456 MATCH deduceType(Scope sc, Type tparam, TemplateParameters parameters, Objects dedtypes) |
447 { | 457 { |
448 assert(false); | 458 //printf("TypeStruct.deduceType()\n"); |
459 //printf("\tthis.parent = %s, ", sym.parent.toChars()); print(); | |
460 //printf("\ttparam = %d, ", tparam.ty); tparam.print(); | |
461 | |
462 /* If this struct is a template struct, and we're matching | |
463 * it against a template instance, convert the struct type | |
464 * to a template instance, too, and try again. | |
465 */ | |
466 TemplateInstance ti = sym.parent.isTemplateInstance(); | |
467 | |
468 if (tparam && tparam.ty == Tinstance) | |
469 { | |
470 if (ti && ti.toAlias() == sym) | |
471 { | |
472 TypeInstance t = new TypeInstance(Loc(0), ti); | |
473 return t.deduceType(sc, tparam, parameters, dedtypes); | |
474 } | |
475 | |
476 /* Match things like: | |
477 * S!(T).foo | |
478 */ | |
479 TypeInstance tpi = cast(TypeInstance)tparam; | |
480 if (tpi.idents.dim) | |
481 { Identifier id = cast(Identifier)tpi.idents.data[tpi.idents.dim - 1]; | |
482 if (id.dyncast() == DYNCAST.DYNCAST_IDENTIFIER && sym.ident.equals(id)) | |
483 { | |
484 Type tparent = sym.parent.getType(); | |
485 if (tparent) | |
486 { | |
487 /* Slice off the .foo in S!(T).foo | |
488 */ | |
489 tpi.idents.dim--; | |
490 MATCH m = tparent.deduceType(sc, tpi, parameters, dedtypes); | |
491 tpi.idents.dim++; | |
492 return m; | |
493 } | |
494 } | |
495 } | |
496 } | |
497 | |
498 // Extra check | |
499 if (tparam && tparam.ty == Tstruct) | |
500 { | |
501 TypeStruct tp = cast(TypeStruct)tparam; | |
502 | |
503 if (sym != tp.sym) | |
504 return MATCHnomatch; | |
505 } | |
506 return Type.deduceType(sc, tparam, parameters, dedtypes); | |
449 } | 507 } |
450 | 508 |
451 TypeInfoDeclaration getTypeInfoDeclaration() | 509 TypeInfoDeclaration getTypeInfoDeclaration() |
452 { | 510 { |
453 return new TypeInfoStructDeclaration(this); | 511 return new TypeInfoStructDeclaration(this); |