annotate dmd/TypeClass.d @ 56:51605de93870

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