Mercurial > projects > ddmd
view dmd/TypeidExp.d @ 130:60bb0fe4563e
dmdfe 2.037 first main iteration
author | Eldar Insafutdinov <e.insafutdinov@gmail.com> |
---|---|
date | Thu, 09 Sep 2010 22:51:44 +0100 |
parents | e28b18c23469 |
children | 206db751bd4c |
line wrap: on
line source
module dmd.TypeidExp; import dmd.common; import dmd.Expression; import dmd.Type; import dmd.OutBuffer; import dmd.Loc; import dmd.Scope; import dmd.HdrGenState; import dmd.TOK; class TypeidExp : Expression { Object *obj; this(Loc loc, Object o) { super(loc, TOK.TOKtypeid, TypeidExp.sizeof); this.obj = o; } version (DumbClone) { } else { Type clone() { assert(false); } } override Expression syntaxCopy() { return new TypeidExp(loc, objectSyntaxCopy(obj)); } override Expression semantic(Scope sc) { Expression e; version (LOGSEMANTIC) { printf("TypeidExp.semantic()\n"); } Type ta = isType(obj); Expression ea = isExpression(obj); Dsymbol sa = isDsymbol(obj); if (ta) { ta.resolve(loc, sc, &ea, &ta, &sa); } if (ea) { ea = ea.semantic(sc); ea = resolveProperties(sc, ea); ta = ea.type; if (ea.op == TOKtype) ea = null; } if (!ta) { error("no type for typeid(%s)", ea ? ea.toChars() : (sa ? sa.toChars() : "")); return new ErrorExp(); } if (ea && ta.toBasetype().ty == Tclass) { /* Get the dynamic type, which is .classinfo */ e = new DotIdExp(ea.loc, ea, Id.classinfo); e = e.semantic(sc); } else { /* Get the static type */ e = ta.getTypeInfo(sc); if (e.loc.linnum == 0) e.loc = loc; // so there's at least some line number info if (ea) { e = new CommaExp(loc, ea, e); // execute ea e = e.semantic(sc); } } return e; } override void toCBuffer(OutBuffer buf, HdrGenState* hgs) { assert(false); } }