annotate dmd/TypeTypeof.d @ 51:b7d29f613539

StaticAssertStatement.syntaxCopy IfStatement.syntaxCopy CompoundDeclarationStatement.syntaxCopy VoidInitializer.syntaxCopy TypeAArray.syntaxCopy TypeTypeof.syntaxCopy TypeAArray.resolve TypeSArray.deduceType TypeAArray.deduceType TypeAArray.implicitConvTo TemplateDeclaration.leastAsSpecialized TemplateTypeParameter.dummyArg TypeIdentifier.deduceType TemplateTypeParameter.syntaxCopy Lexer.hexStringConstant Lexer.delimitedStringConstant GotoDefaultStatement.ctor CaseRangeStatement.ctor Type.castMod StorageClassDeclaration.syntaxCopy TemplateDeclaration.syntaxCopy
author korDen
date Sat, 21 Aug 2010 11:17:42 +0400
parents 10317f0c89a5
children a8740d0dbea4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.TypeTypeof;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3 import dmd.TypeQualified;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.MOD;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 class TypeTypeof : TypeQualified
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 Expression exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 this(Loc loc, Expression exp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 super(TY.Ttypeof, loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 this.exp = exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 version (DumbClone) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 Type clone()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 Type syntaxCopy()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 {
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 0
diff changeset
37 //printf("TypeTypeof.syntaxCopy() %s\n", toChars());
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 0
diff changeset
38 TypeTypeof t;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 0
diff changeset
39
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 0
diff changeset
40 t = new TypeTypeof(loc, exp.syntaxCopy());
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 0
diff changeset
41 t.syntaxCopyHelper(this);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 0
diff changeset
42 t.mod = mod;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 0
diff changeset
43 return t;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 Dsymbol toDsymbol(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 Type t = semantic(loc, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 if (t is this)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 return t.toDsymbol(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 void toCBuffer2(OutBuffer buf, HdrGenState* hgs, MOD mod)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 Type semantic(Loc loc, Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 Type t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 //printf("TypeTypeof.semantic() %p\n", this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 //static int nest; if (++nest == 50) *(char*)0=0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 /+static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 /* Special case for typeof(this) and typeof(super) since both
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 * should work even if they are not inside a non-static member function
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 if (exp.op == TOK.TOKthis || exp.op == TOK.TOKsuper)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 / / Find enclosing struct or class
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 for (Dsymbol *s = sc.parent; 1; s = s.parent)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 ClassDeclaration *cd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 StructDeclaration *sd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 if (!s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 error(loc, "%s is not in a struct or class scope", exp.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 cd = s.isClassDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 if (cd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 if (exp.op == TOK.TOKsuper)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 cd = cd.baseClass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 if (!cd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 { error(loc, "class %s has no 'super'", s.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 t = cd.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 sd = s.isStructDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 if (sd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 if (exp.op == TOK.TOKsuper)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 error(loc, "struct %s has no 'super'", sd.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 t = sd.type.pointerTo();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 }+/
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 sc.intypeof++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 exp = exp.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 sc.intypeof--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 if (exp.op == TOK.TOKtype)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 error(loc, "argument %s to typeof is not an expression", exp.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 t = exp.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 if (!t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 error(loc, "expression (%s) has no type", exp.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 if (t.ty == TY.Ttypeof)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 error(loc, "forward reference to %s", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 /* typeof should reflect the true type,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 * not what 'auto' would have gotten us.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 //t = t.toHeadMutable();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 if (idents.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 Dsymbol s = t.toDsymbol(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 for (size_t i = 0; i < idents.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 if (!s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 Identifier id = cast(Identifier)idents.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 s = s.searchX(loc, sc, id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 if (s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 t = s.getType();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 if (!t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 error(loc, "%s is not a type", s.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 error(loc, "cannot resolve .property for %s", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 return t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 Lerr:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 return tvoid;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 ulong size(Loc loc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 }