comparison dmd/TypeClass.d @ 64:4290d870944a

More fixes
author korDen
date Mon, 23 Aug 2010 20:29:15 +0400
parents 51605de93870
children 2e2a5c3f943a
comparison
equal deleted inserted replaced
63:cab4c37afb89 64:4290d870944a
1 module dmd.TypeClass; 1 module dmd.TypeClass;
2 2
3 import dmd.Type; 3 import dmd.Type;
4 import dmd.ClassDeclaration; 4 import dmd.ClassDeclaration;
5 import dmd.TypeInstance;
5 import dmd.Loc; 6 import dmd.Loc;
6 import dmd.Dsymbol; 7 import dmd.Dsymbol;
7 import dmd.Scope; 8 import dmd.Scope;
8 import dmd.OutBuffer; 9 import dmd.OutBuffer;
9 import dmd.HdrGenState; 10 import dmd.HdrGenState;
10 import dmd.Expression; 11 import dmd.Expression;
11 import dmd.Identifier; 12 import dmd.Identifier;
12 import dmd.MATCH; 13 import dmd.MATCH;
14 import dmd.DYNCAST;
13 import dmd.CppMangleState; 15 import dmd.CppMangleState;
14 import dmd.ArrayTypes; 16 import dmd.ArrayTypes;
15 import dmd.TypeInfoDeclaration; 17 import dmd.TypeInfoDeclaration;
16 import dmd.TY; 18 import dmd.TY;
17 import dmd.MOD; 19 import dmd.MOD;
527 return true; 529 return true;
528 } 530 }
529 531
530 MATCH deduceType(Scope sc, Type tparam, TemplateParameters parameters, Objects dedtypes) 532 MATCH deduceType(Scope sc, Type tparam, TemplateParameters parameters, Objects dedtypes)
531 { 533 {
532 assert(false); 534 //printf("TypeClass.deduceType(this = %s)\n", toChars());
535
536 /* If this class is a template class, and we're matching
537 * it against a template instance, convert the class type
538 * to a template instance, too, and try again.
539 */
540 TemplateInstance ti = sym.parent.isTemplateInstance();
541
542 if (tparam && tparam.ty == Tinstance)
543 {
544 if (ti && ti.toAlias() == sym)
545 {
546 TypeInstance t = new TypeInstance(Loc(0), ti);
547 return t.deduceType(sc, tparam, parameters, dedtypes);
548 }
549
550 /* Match things like:
551 * S!(T).foo
552 */
553 TypeInstance tpi = cast(TypeInstance)tparam;
554 if (tpi.idents.dim)
555 { Identifier id = cast(Identifier)tpi.idents.data[tpi.idents.dim - 1];
556 if (id.dyncast() == DYNCAST.DYNCAST_IDENTIFIER && sym.ident.equals(id))
557 {
558 Type tparent = sym.parent.getType();
559 if (tparent)
560 {
561 /* Slice off the .foo in S!(T).foo
562 */
563 tpi.idents.dim--;
564 MATCH m = tparent.deduceType(sc, tpi, parameters, dedtypes);
565 tpi.idents.dim++;
566 return m;
567 }
568 }
569 }
570 }
571
572 // Extra check
573 if (tparam && tparam.ty == Tclass)
574 {
575 TypeClass tp = cast(TypeClass)tparam;
576
577 //printf("\t%d\n", (MATCH) implicitConvTo(tp));
578 return implicitConvTo(tp);
579 }
580 return Type.deduceType(sc, tparam, parameters, dedtypes);
533 } 581 }
534 582
535 bool isauto() 583 bool isauto()
536 { 584 {
537 return sym.isauto; 585 return sym.isauto;