annotate dmd/TypeClass.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.TypeClass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 84
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.ClassDeclaration;
64
4290d870944a More fixes
korDen
parents: 56
diff changeset
6 import dmd.TypeInstance;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.MATCH;
64
4290d870944a More fixes
korDen
parents: 56
diff changeset
15 import dmd.DYNCAST;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.CppMangleState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.ArrayTypes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.TypeInfoDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.MOD;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.Global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.TypePointer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.Declaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.VarDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import dmd.DotExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.Id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 import dmd.ScopeExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 import dmd.DotVarExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 import dmd.VarExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 import dmd.PtrExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 import dmd.AddExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 import dmd.IntegerExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 import dmd.DotIdExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 import dmd.EnumMember;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 import dmd.TemplateMixin;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 import dmd.TemplateDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 import dmd.TemplateInstance;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 import dmd.OverloadSet;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 import dmd.DotTypeExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 import dmd.TupleExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 import dmd.ClassInfoDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 import dmd.TypeInfoInterfaceDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 import dmd.TypeInfoClassDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 import dmd.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 import dmd.NullExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 import dmd.TypeExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 import dmd.DotTemplateExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 import dmd.ErrorExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 import dmd.ThisExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 import dmd.CommaExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 import dmd.expression.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 import dmd.backend.Symbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 import dmd.backend.TYPE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 import dmd.backend.SC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 import dmd.backend.STR;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 import dmd.backend.TYM;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 import dmd.backend.LIST;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 import dmd.backend.Classsym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 import std.string : toStringz;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 178
diff changeset
65 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
66
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 class TypeClass : Type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 {
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 178
diff changeset
69 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
70
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 ClassDeclaration sym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 this(ClassDeclaration sym)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 176
diff changeset
75 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 super(TY.Tclass);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 this.sym = sym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
80 override ulong size(Loc loc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 return PTRSIZE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
85 override string toChars()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 if (mod)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 return Type.toChars();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 return sym.toPrettyChars();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
92 override Type syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
97 override Type semantic(Loc loc, Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 //printf("TypeClass.semantic(%s)\n", sym.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 if (deco)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 //printf("\t%s\n", merge().deco);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 return merge();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
106 override Dsymbol toDsymbol(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 return sym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
111 override void toDecoBuffer(OutBuffer buf, int flag)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 string name = sym.mangle();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 //printf("TypeClass.toDecoBuffer('%s' flag=%d mod=%x) = '%s'\n", toChars(), flag, mod, name);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 Type.toDecoBuffer(buf, flag);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 buf.printf("%s", name);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
119 override void toCBuffer2(OutBuffer buf, HdrGenState* hgs, MOD mod)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 if (mod != this.mod)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 toCBuffer3(buf, hgs, mod);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 buf.writestring(sym.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
129 override Expression dotExp(Scope sc, Expression e, Identifier ident)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 uint offset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 Expression b;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 VarDeclaration v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 Dsymbol s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 version (LOGDOTEXP) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 printf("TypeClass.dotExp(e='%s', ident='%s')\n", e.toChars(), ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 if (e.op == TOK.TOKdotexp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 DotExp de = cast(DotExp)e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 if (de.e1.op == TOK.TOKimport)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 ScopeExp se = cast(ScopeExp)de.e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 s = se.sds.search(e.loc, ident, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 e = de.e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 if (ident is Id.tupleof_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 /* Create a TupleExp
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 e = e.semantic(sc); // do this before turning on noaccesscheck
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 Expressions exps = new Expressions;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 exps.reserve(sym.fields.dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 for (size_t i = 0; i < sym.fields.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
164 VarDeclaration v2 = cast(VarDeclaration)sym.fields[i];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 Expression fe = new DotVarExp(e.loc, e, v2);
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
166 exps.push(fe);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 e = new TupleExp(e.loc, exps);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 sc = sc.push();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 sc.noaccesscheck = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 sc.pop();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 s = sym.search(e.loc, ident, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 if (!s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 // See if it's a base class
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 ClassDeclaration cbase;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 for (cbase = sym.baseClass; cbase; cbase = cbase.baseClass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 if (cbase.ident.equals(ident))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 e = new DotTypeExp(Loc(0), e, cbase);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 if (ident is Id.classinfo_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 {
166
d8565fbd755c Moved object and classinfo from ClassDeclaration to Global (as part of getting rid of the global state)
korDen
parents: 135
diff changeset
193 assert(global.classinfo);
d8565fbd755c Moved object and classinfo from ClassDeclaration to Global (as part of getting rid of the global state)
korDen
parents: 135
diff changeset
194 Type t = global.classinfo.type;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 if (e.op == TOK.TOKtype || e.op == TOK.TOKdottype)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 /* For type.classinfo, we know the classinfo
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 * at compile time.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 if (!sym.vclassinfo)
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
201 sym.vclassinfo = new TypeInfoClassDeclaration(sym.type);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 e = new VarExp(e.loc, sym.vclassinfo);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 e = e.addressOf(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 e.type = t; // do this so we don't get redundant dereference
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209 /* For class objects, the classinfo reference is the first
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210 * entry in the vtbl[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212 e = new PtrExp(e.loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213 e.type = t.pointerTo();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 if (sym.isInterfaceDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216 if (sym.isCPPinterface())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218 /* C++ interface vtbl[]s are different in that the
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 * first entry is always pointer to the first virtual
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220 * function, not classinfo.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221 * We can't get a .classinfo for it.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223 error(e.loc, "no .classinfo for C++ interface objects");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 /* For an interface, the first entry in the vtbl[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226 * is actually a pointer to an instance of struct Interface.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 * The first member of Interface is the .classinfo,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228 * so add an extra pointer indirection.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230 e.type = e.type.pointerTo();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 e = new PtrExp(e.loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 e.type = t.pointerTo();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234 e = new PtrExp(e.loc, e, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239 if (ident is Id.__vptr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241 /* The pointer to the vtbl[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242 * *cast(invariant(void*)**)e
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243 */
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 166
diff changeset
244 e = e.castTo(sc, global.tvoidptr.invariantOf().pointerTo().pointerTo());
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245 e = new PtrExp(e.loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250 if (ident is Id.__monitor)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 { /* The handle to the monitor (call it a void*)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 * *(cast(void**)e + 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253 */
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 166
diff changeset
254 e = e.castTo(sc, global.tvoidptr.pointerTo());
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255 e = new AddExp(e.loc, e, new IntegerExp(1));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 e = new PtrExp(e.loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 if (ident is Id.typeinfo_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 if (!global.params.useDeprecated)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 error(e.loc, ".typeinfo deprecated, use typeid(type)");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 return getTypeInfo(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 if (ident is Id.outer && sym.vthis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270 s = sym.vthis;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273 {
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
274 return noMember(sc, e, ident);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278 if (!s.isFuncDeclaration()) // because of overloading
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279 s.checkDeprecated(e.loc, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281 s = s.toAlias();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282 v = s.isVarDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
284 if (v && !v.isDataseg())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
285 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
286 Expression ei = v.getConstInitializer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
287
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288 if (ei)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
289 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290 e = ei.copy(); // need to copy it if it's a StringExp
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
292 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296 if (s.getType())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
297 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298 // if (e.op == TOKtype)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299 return new TypeExp(e.loc, s.getType());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300 // return new DotTypeExp(e.loc, e, s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
301 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
302
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303 EnumMember em = s.isEnumMember();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304 if (em)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306 assert(em.value);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307 return em.value.copy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310 TemplateMixin tm = s.isTemplateMixin();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
311 if (tm)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
312 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313 Expression de = new DotExp(e.loc, e, new ScopeExp(e.loc, tm));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314 de.type = e.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
315 return de;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318 TemplateDeclaration td = s.isTemplateDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319 if (td)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
320 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321 e = new DotTemplateExp(e.loc, e, td);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322 e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
323 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
324 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
325
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
326 TemplateInstance ti = s.isTemplateInstance();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
327 if (ti)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
328 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
329 if (!ti.semanticRun)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
330 ti.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
331 s = ti.inst.toAlias();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
332 if (!s.isTemplateInstance())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
333 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
334 Expression de = new DotExp(e.loc, e, new ScopeExp(e.loc, ti));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335 de.type = e.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
336 return de;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
338
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
339 OverloadSet o = s.isOverloadSet();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
340 if (o)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
341 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
342 /* We really should allow this
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
343 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
344 error(e.loc, "overload set for %s.%s not allowed in struct declaration", e.toChars(), ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
345 return new ErrorExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
346 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
347
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
348 Declaration d = s.isDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
349 if (!d)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
350 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
351 e.error("%s.%s is not a declaration", e.toChars(), ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
352 return new ErrorExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
353 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
354
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
355 if (e.op == TOK.TOKtype)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
356 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
357 /* It's:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
358 * Class.d
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
359 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
360 if (d.isTupleDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
361 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
362 e = new TupleExp(e.loc, d.isTupleDeclaration());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
363 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
364 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
365 }
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
366 else if (d.needThis() && (hasThis(sc) || !(sc.intypeof || d.isFuncDeclaration())))
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
367 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
368 if (sc.func)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
369 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
370 ClassDeclaration thiscd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
371 thiscd = sc.func.toParent().isClassDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
372
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
373 if (thiscd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
374 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
375 ClassDeclaration cd = e.type.isClassHandle();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
376
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
377 if (cd is thiscd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
378 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
379 e = new ThisExp(e.loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
380 e = new DotTypeExp(e.loc, e, cd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
381 DotVarExp de = new DotVarExp(e.loc, e, d);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
382 e = de.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
383 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
384 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
385 else if ((!cd || !cd.isBaseOf(thiscd, null)) && !d.isFuncDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
386 e.error("'this' is required, but %s is not a base class of %s", e.type.toChars(), thiscd.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
387 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
388 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
389
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
390 /* Rewrite as:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
391 * this.d
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
392 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
393 DotVarExp de = new DotVarExp(e.loc, new ThisExp(e.loc), d);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
394 e = de.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
395 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
396 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
397 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
398 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
399 VarExp ve = new VarExp(e.loc, d, 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
400 return ve;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
401 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
402 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
403
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
404 if (d.isDataseg())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
405 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
406 // (e, d)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
407 accessCheck(e.loc, sc, e, d);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
408 VarExp ve = new VarExp(e.loc, d);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
409 e = new CommaExp(e.loc, e, ve);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
410 e.type = d.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
411 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
412 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
413
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
414 if (d.parent && d.toParent().isModule())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
415 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
416 // (e, d)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
417 VarExp ve = new VarExp(e.loc, d, 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
418 e = new CommaExp(e.loc, e, ve);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
419 e.type = d.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
420 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
421 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
422
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
423 DotVarExp de = new DotVarExp(e.loc, e, d);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
424 return de.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
425 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
426
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
427 override ClassDeclaration isClassHandle()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
428 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
429 return sym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
430 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
431
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
432 override bool isBaseOf(Type t, int* poffset)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
433 {
56
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
434 if (t.ty == Tclass)
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
435 {
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
436 ClassDeclaration cd;
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
437
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
438 cd = (cast(TypeClass)t).sym;
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
439 if (sym.isBaseOf(cd, poffset))
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
440 return true;
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
441 }
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
442
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
443 return false;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
444 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
445
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
446 override MATCH implicitConvTo(Type to)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
447 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
448 //printf("TypeClass.implicitConvTo(to = '%s') %s\n", to.toChars(), toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
449 MATCH m = constConv(to);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
450 if (m != MATCH.MATCHnomatch)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
451 return m;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
452
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
453 ClassDeclaration cdto = to.isClassHandle();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
454 if (cdto && cdto.isBaseOf(sym, null))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
455 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
456 //printf("'to' is base\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
457 return MATCH.MATCHconvert;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
458 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
459
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
460 if (global.params.Dversion == 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
461 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
462 // Allow conversion to (void *)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
463 if (to.ty == TY.Tpointer && (cast(TypePointer)to).next.ty == TY.Tvoid)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
464 return MATCH.MATCHconvert;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
465 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
466
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
467 m = MATCH.MATCHnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
468 if (sym.aliasthis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
469 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
470 Declaration d = sym.aliasthis.isDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
471 if (d)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
472 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
473 assert(d.type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
474 Type t = d.type.addMod(mod);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
475 m = t.implicitConvTo(to);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
476 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
477 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
478
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
479 return m;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
480 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
481
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
482 override Expression defaultInit(Loc loc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
483 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
484 version (LOGDEFAULTINIT) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
485 printf("TypeClass::defaultInit() '%s'\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
486 }
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
487 return new NullExp(loc, this);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
488 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
489
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
490 override bool isZeroInit(Loc loc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
491 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
492 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
493 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
494
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
495 override MATCH deduceType(Scope sc, Type tparam, TemplateParameters parameters, Objects dedtypes)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
496 {
64
4290d870944a More fixes
korDen
parents: 56
diff changeset
497 //printf("TypeClass.deduceType(this = %s)\n", toChars());
4290d870944a More fixes
korDen
parents: 56
diff changeset
498
4290d870944a More fixes
korDen
parents: 56
diff changeset
499 /* If this class is a template class, and we're matching
4290d870944a More fixes
korDen
parents: 56
diff changeset
500 * it against a template instance, convert the class type
4290d870944a More fixes
korDen
parents: 56
diff changeset
501 * to a template instance, too, and try again.
4290d870944a More fixes
korDen
parents: 56
diff changeset
502 */
4290d870944a More fixes
korDen
parents: 56
diff changeset
503 TemplateInstance ti = sym.parent.isTemplateInstance();
4290d870944a More fixes
korDen
parents: 56
diff changeset
504
4290d870944a More fixes
korDen
parents: 56
diff changeset
505 if (tparam && tparam.ty == Tinstance)
4290d870944a More fixes
korDen
parents: 56
diff changeset
506 {
4290d870944a More fixes
korDen
parents: 56
diff changeset
507 if (ti && ti.toAlias() == sym)
4290d870944a More fixes
korDen
parents: 56
diff changeset
508 {
4290d870944a More fixes
korDen
parents: 56
diff changeset
509 TypeInstance t = new TypeInstance(Loc(0), ti);
4290d870944a More fixes
korDen
parents: 56
diff changeset
510 return t.deduceType(sc, tparam, parameters, dedtypes);
4290d870944a More fixes
korDen
parents: 56
diff changeset
511 }
4290d870944a More fixes
korDen
parents: 56
diff changeset
512
4290d870944a More fixes
korDen
parents: 56
diff changeset
513 /* Match things like:
4290d870944a More fixes
korDen
parents: 56
diff changeset
514 * S!(T).foo
4290d870944a More fixes
korDen
parents: 56
diff changeset
515 */
4290d870944a More fixes
korDen
parents: 56
diff changeset
516 TypeInstance tpi = cast(TypeInstance)tparam;
4290d870944a More fixes
korDen
parents: 56
diff changeset
517 if (tpi.idents.dim)
4290d870944a More fixes
korDen
parents: 56
diff changeset
518 { Identifier id = cast(Identifier)tpi.idents.data[tpi.idents.dim - 1];
4290d870944a More fixes
korDen
parents: 56
diff changeset
519 if (id.dyncast() == DYNCAST.DYNCAST_IDENTIFIER && sym.ident.equals(id))
4290d870944a More fixes
korDen
parents: 56
diff changeset
520 {
4290d870944a More fixes
korDen
parents: 56
diff changeset
521 Type tparent = sym.parent.getType();
4290d870944a More fixes
korDen
parents: 56
diff changeset
522 if (tparent)
4290d870944a More fixes
korDen
parents: 56
diff changeset
523 {
4290d870944a More fixes
korDen
parents: 56
diff changeset
524 /* Slice off the .foo in S!(T).foo
4290d870944a More fixes
korDen
parents: 56
diff changeset
525 */
4290d870944a More fixes
korDen
parents: 56
diff changeset
526 tpi.idents.dim--;
4290d870944a More fixes
korDen
parents: 56
diff changeset
527 MATCH m = tparent.deduceType(sc, tpi, parameters, dedtypes);
4290d870944a More fixes
korDen
parents: 56
diff changeset
528 tpi.idents.dim++;
4290d870944a More fixes
korDen
parents: 56
diff changeset
529 return m;
4290d870944a More fixes
korDen
parents: 56
diff changeset
530 }
4290d870944a More fixes
korDen
parents: 56
diff changeset
531 }
4290d870944a More fixes
korDen
parents: 56
diff changeset
532 }
4290d870944a More fixes
korDen
parents: 56
diff changeset
533 }
4290d870944a More fixes
korDen
parents: 56
diff changeset
534
4290d870944a More fixes
korDen
parents: 56
diff changeset
535 // Extra check
4290d870944a More fixes
korDen
parents: 56
diff changeset
536 if (tparam && tparam.ty == Tclass)
4290d870944a More fixes
korDen
parents: 56
diff changeset
537 {
4290d870944a More fixes
korDen
parents: 56
diff changeset
538 TypeClass tp = cast(TypeClass)tparam;
4290d870944a More fixes
korDen
parents: 56
diff changeset
539
4290d870944a More fixes
korDen
parents: 56
diff changeset
540 //printf("\t%d\n", (MATCH) implicitConvTo(tp));
4290d870944a More fixes
korDen
parents: 56
diff changeset
541 return implicitConvTo(tp);
4290d870944a More fixes
korDen
parents: 56
diff changeset
542 }
4290d870944a More fixes
korDen
parents: 56
diff changeset
543 return Type.deduceType(sc, tparam, parameters, dedtypes);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
544 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
545
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
546 override bool isauto()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
547 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
548 return sym.isauto;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
549 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
550
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
551 override bool checkBoolean()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
552 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
553 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
554 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
555
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
556 override TypeInfoDeclaration getTypeInfoDeclaration()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
557 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
558 if (sym.isInterfaceDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
559 return new TypeInfoInterfaceDeclaration(this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
560 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
561 return new TypeInfoClassDeclaration(this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
562 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
563
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
564 override bool hasPointers()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
565 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
566 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
567 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
568
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
569 override bool builtinTypeInfo()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
570 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
571 /* This is statically put out with the ClassInfo, so
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
572 * claim it is built in so it isn't regenerated by each module.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
573 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
574 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
575 return mod ? false : true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
576 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
577 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
578 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
579 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
580
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
581 version (DMDV2) {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
582 override Type toHeadMutable()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
583 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
584 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
585 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
586
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
587 override MATCH constConv(Type to)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
588 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
589 if (equals(to))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
590 return MATCH.MATCHexact;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
591
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
592 if (ty == to.ty && sym == (cast(TypeClass)to).sym && to.mod == MOD.MODconst)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
593 return MATCH.MATCHconst;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
594
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
595 return MATCH.MATCHnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
596 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
597
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
598 version (CPP_MANGLE) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
599 void toCppMangle(OutBuffer buf, CppMangleState* cms)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
600 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
601 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
602 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
603 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
604 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
605
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
606 override type* toCtype()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
607 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
608 type* t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
609 Symbol* s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
610
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
611 //printf("TypeClass.toCtype() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
612 if (ctype)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
613 return ctype;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
614
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
615 /* Need this symbol to do C++ name mangling
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
616 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
617 string name = sym.isCPPinterface() ? sym.ident.toChars() : sym.toPrettyChars();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
618 s = symbol_calloc(toStringz(name));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
619 s.Sclass = SC.SCstruct;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
620 s.Sstruct = struct_calloc();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
621 s.Sstruct.Sflags |= STR.STRclass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
622 s.Sstruct.Salignsize = sym.alignsize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
623 s.Sstruct.Sstructalign = cast(ubyte)sym.structalign;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
624 s.Sstruct.Sstructsize = sym.structsize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
625
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
626 t = type_alloc(TYM.TYstruct);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
627 t.Ttag = cast(Classsym*)s; // structure tag name
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
628 t.Tcount++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
629 s.Stype = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
630 slist_add(s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
631
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
632 t = type_allocn(TYM.TYnptr, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
633
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
634 t.Tcount++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
635 ctype = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
636
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
637 /* Add in fields of the class
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
638 * (after setting ctype to avoid infinite recursion)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
639 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
640 if (global.params.symdebug)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
641 for (int i = 0; i < sym.fields.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
642 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
643 VarDeclaration v = cast(VarDeclaration)sym.fields[i];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
644
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
645 Symbol* s2 = symbol_name(toStringz(v.ident.toChars()), SC.SCmember, v.type.toCtype());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
646 s2.Smemoff = v.offset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
647 list_append(&s.Sstruct.Sfldlst, s2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
648 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
649
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
650 return t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
651 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
652
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
653 override Symbol* toSymbol()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
654 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
655 return sym.toSymbol();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
656 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
657 }