Mercurial > projects > ddmd
view dmd/TupleDeclaration.d @ 32:81796b717a39
A few bad cast fixed. TODO: either get rid of dyncast(), or derive all objects from intermediate supertype.
author | korDen |
---|---|
date | Tue, 18 May 2010 17:51:46 +0400 |
parents | 460959608115 |
children | 2e2a5c3f943a |
line wrap: on
line source
module dmd.TupleDeclaration; import dmd.Declaration; import dmd.Argument; import dmd.ArrayTypes; import dmd.TypeTuple; import dmd.Loc; import dmd.STC; import dmd.TOK; import dmd.Identifier; import dmd.Dsymbol; import dmd.Type; import dmd.DYNCAST; import dmd.OutBuffer; import dmd.Expression; import dmd.DsymbolExp; class TupleDeclaration : Declaration { Objects objects; int isexp; // 1: expression tuple TypeTuple tupletype; // !=NULL if this is a type tuple this(Loc loc, Identifier ident, Objects objects) { super(ident); this.type = null; this.objects = objects; this.isexp = 0; this.tupletype = null; } Dsymbol syntaxCopy(Dsymbol) { assert(false); } string kind() { return "tuple"; } Type getType() { /* If this tuple represents a type, return that type */ //printf("TupleDeclaration::getType() %s\n", toChars()); if (isexp) return null; if (!tupletype) { /* It's only a type tuple if all the Object's are types */ for (size_t i = 0; i < objects.dim; i++) { Object o = cast(Object)objects.data[i]; if (cast(Type)o is null) { //printf("\tnot[%d], %p, %d\n", i, o, o->dyncast()); return null; } } /* We know it's a type tuple, so build the TypeTuple */ Arguments args = new Arguments(); args.setDim(objects.dim); OutBuffer buf = new OutBuffer(); for (size_t i = 0; i < objects.dim; i++) { Type t = cast(Type)objects.data[i]; //printf("type = %s\n", t->toChars()); static if (0) { buf.printf("_%s_%d", ident.toChars(), i); char *name = cast(char *)buf.extractData(); Identifier id = new Identifier(name, TOKidentifier); Argument arg = new Argument(STCin, t, id, null); } else { Argument arg = new Argument(STCundefined, t, null, null); } args.data[i] = cast(void *)arg; } tupletype = new TypeTuple(args); } return tupletype; } bool needThis() { //printf("TupleDeclaration::needThis(%s)\n", toChars()); for (size_t i = 0; i < objects.dim; i++) { Object o = cast(Object)objects.data[i]; if (auto e = cast(Expression)o) { if (e.op == TOKdsymbol) { DsymbolExp ve = cast(DsymbolExp)e; Declaration d = ve.s.isDeclaration(); if (d && d.needThis()) { return 1; } } } } return 0; } TupleDeclaration isTupleDeclaration() { return this; } }