Mercurial > projects > ddmd
comparison 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 |
comparison
equal
deleted
inserted
replaced
129:010eb8f0e18d | 130:60bb0fe4563e |
---|---|
9 import dmd.HdrGenState; | 9 import dmd.HdrGenState; |
10 import dmd.TOK; | 10 import dmd.TOK; |
11 | 11 |
12 class TypeidExp : Expression | 12 class TypeidExp : Expression |
13 { | 13 { |
14 Type typeidType; | 14 Object *obj; |
15 | 15 |
16 this(Loc loc, Type typeidType) | 16 this(Loc loc, Object o) |
17 { | 17 { |
18 super(loc, TOK.TOKtypeid, TypeidExp.sizeof); | 18 super(loc, TOK.TOKtypeid, TypeidExp.sizeof); |
19 this.typeidType = typeidType; | 19 this.obj = o; |
20 } | 20 } |
21 | 21 |
22 version (DumbClone) { | 22 version (DumbClone) { |
23 } else { | 23 } else { |
24 Type clone() | 24 Type clone() |
26 assert(false); | 26 assert(false); |
27 } | 27 } |
28 } | 28 } |
29 override Expression syntaxCopy() | 29 override Expression syntaxCopy() |
30 { | 30 { |
31 return new TypeidExp(loc, typeidType.syntaxCopy()); | 31 return new TypeidExp(loc, objectSyntaxCopy(obj)); |
32 } | 32 } |
33 | 33 |
34 override Expression semantic(Scope sc) | 34 override Expression semantic(Scope sc) |
35 { | 35 { |
36 Expression e; | 36 Expression e; |
37 | 37 |
38 version (LOGSEMANTIC) { | 38 version (LOGSEMANTIC) { |
39 printf("TypeidExp.semantic()\n"); | 39 printf("TypeidExp.semantic()\n"); |
40 } | 40 } |
41 typeidType = typeidType.semantic(loc, sc); | 41 Type ta = isType(obj); |
42 e = typeidType.getTypeInfo(sc); | 42 Expression ea = isExpression(obj); |
43 if (e.loc.linnum == 0) | 43 Dsymbol sa = isDsymbol(obj); |
44 e.loc = loc; // so there's at least some line number info | 44 |
45 if (ta) | |
46 { | |
47 ta.resolve(loc, sc, &ea, &ta, &sa); | |
48 } | |
49 if (ea) | |
50 { | |
51 ea = ea.semantic(sc); | |
52 ea = resolveProperties(sc, ea); | |
53 ta = ea.type; | |
54 if (ea.op == TOKtype) | |
55 ea = null; | |
56 } | |
57 | |
58 if (!ta) | |
59 { error("no type for typeid(%s)", ea ? ea.toChars() : (sa ? sa.toChars() : "")); | |
60 return new ErrorExp(); | |
61 } | |
62 | |
63 if (ea && ta.toBasetype().ty == Tclass) | |
64 { /* Get the dynamic type, which is .classinfo | |
65 */ | |
66 e = new DotIdExp(ea.loc, ea, Id.classinfo); | |
67 e = e.semantic(sc); | |
68 } | |
69 else | |
70 { /* Get the static type | |
71 */ | |
72 e = ta.getTypeInfo(sc); | |
73 if (e.loc.linnum == 0) | |
74 e.loc = loc; // so there's at least some line number info | |
75 if (ea) | |
76 { | |
77 e = new CommaExp(loc, ea, e); // execute ea | |
78 e = e.semantic(sc); | |
79 } | |
80 } | |
45 return e; | 81 return e; |
46 } | 82 } |
47 | 83 |
48 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) | 84 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
49 { | 85 { |