annotate dmd/TypeTypeof.d @ 114:e28b18c23469

added a module dmd.common for commonly used stuff it currently holds code for consistency checking of predefined versions also added a VisualD project file
author Trass3r
date Wed, 01 Sep 2010 18:21:58 +0200
parents acd69f84627e
children 60bb0fe4563e
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
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 96
diff changeset
3 import dmd.common;
96
acd69f84627e further work
Trass3r
parents: 72
diff changeset
4 import dmd.TypeFunction;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.TypeQualified;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.MOD;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 class TypeTypeof : TypeQualified
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 Expression exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 this(Loc loc, Expression exp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 super(TY.Ttypeof, loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 this.exp = exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 version (DumbClone) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 Type clone()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 60
diff changeset
37 override Type syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 {
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 0
diff changeset
39 //printf("TypeTypeof.syntaxCopy() %s\n", toChars());
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 0
diff changeset
40 TypeTypeof t;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 0
diff changeset
41
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 0
diff changeset
42 t = new TypeTypeof(loc, exp.syntaxCopy());
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 0
diff changeset
43 t.syntaxCopyHelper(this);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 0
diff changeset
44 t.mod = mod;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 0
diff changeset
45 return t;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 60
diff changeset
48 override Dsymbol toDsymbol(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 Type t = semantic(loc, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 if (t is this)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 return t.toDsymbol(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 60
diff changeset
57 override void toCBuffer2(OutBuffer buf, HdrGenState* hgs, MOD mod)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 {
60
a8740d0dbea4 TypeTypeof.toCBuffer2
korDen
parents: 51
diff changeset
59 if (mod != this.mod)
a8740d0dbea4 TypeTypeof.toCBuffer2
korDen
parents: 51
diff changeset
60 {
a8740d0dbea4 TypeTypeof.toCBuffer2
korDen
parents: 51
diff changeset
61 toCBuffer3(buf, hgs, mod);
a8740d0dbea4 TypeTypeof.toCBuffer2
korDen
parents: 51
diff changeset
62 return;
a8740d0dbea4 TypeTypeof.toCBuffer2
korDen
parents: 51
diff changeset
63 }
a8740d0dbea4 TypeTypeof.toCBuffer2
korDen
parents: 51
diff changeset
64 buf.writestring("typeof(");
a8740d0dbea4 TypeTypeof.toCBuffer2
korDen
parents: 51
diff changeset
65 exp.toCBuffer(buf, hgs);
a8740d0dbea4 TypeTypeof.toCBuffer2
korDen
parents: 51
diff changeset
66 buf.writeByte(')');
a8740d0dbea4 TypeTypeof.toCBuffer2
korDen
parents: 51
diff changeset
67 toCBuffer2Helper(buf, hgs);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 60
diff changeset
70 override Type semantic(Loc loc, Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 Type t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74
60
a8740d0dbea4 TypeTypeof.toCBuffer2
korDen
parents: 51
diff changeset
75 //printf("TypeTypeof.semantic() %.*s\n", toChars());
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 //static int nest; if (++nest == 50) *(char*)0=0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 /+static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 /* Special case for typeof(this) and typeof(super) since both
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 * should work even if they are not inside a non-static member function
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 if (exp.op == TOK.TOKthis || exp.op == TOK.TOKsuper)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 / / Find enclosing struct or class
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 for (Dsymbol *s = sc.parent; 1; s = s.parent)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 ClassDeclaration *cd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 StructDeclaration *sd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 if (!s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 error(loc, "%s is not in a struct or class scope", exp.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 cd = s.isClassDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 if (cd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 if (exp.op == TOK.TOKsuper)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 cd = cd.baseClass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 if (!cd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 { error(loc, "class %s has no 'super'", s.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 t = cd.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 sd = s.isStructDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 if (sd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 if (exp.op == TOK.TOKsuper)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 error(loc, "struct %s has no 'super'", sd.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 t = sd.type.pointerTo();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 }+/
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 sc.intypeof++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 exp = exp.semantic(sc);
96
acd69f84627e further work
Trass3r
parents: 72
diff changeset
128 if (exp.type && exp.type.ty == Tfunction &&
acd69f84627e further work
Trass3r
parents: 72
diff changeset
129 (cast(TypeFunction)exp.type).isproperty)
acd69f84627e further work
Trass3r
parents: 72
diff changeset
130 exp = resolveProperties(sc, exp);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 sc.intypeof--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 if (exp.op == TOK.TOKtype)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 error(loc, "argument %s to typeof is not an expression", exp.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 t = exp.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 if (!t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 error(loc, "expression (%s) has no type", exp.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 if (t.ty == TY.Ttypeof)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 error(loc, "forward reference to %s", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 /* typeof should reflect the true type,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 * not what 'auto' would have gotten us.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 //t = t.toHeadMutable();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 if (idents.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 Dsymbol s = t.toDsymbol(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 for (size_t i = 0; i < idents.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 if (!s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 Identifier id = cast(Identifier)idents.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 s = s.searchX(loc, sc, id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 if (s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 t = s.getType();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 if (!t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 error(loc, "%s is not a type", s.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 error(loc, "cannot resolve .property for %s", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 goto Lerr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 return t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 Lerr:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 return tvoid;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 60
diff changeset
182 override ulong size(Loc loc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 60
diff changeset
186 }