annotate dmd/TypeTypeof.d @ 178:e3afd1303184

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