annotate dmd/TypeTypeof.d @ 187:b0d41ff5e0df

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