annotate dmd/ClassDeclaration.d @ 53:a8b50ff7f201

ForeachStatement.syntaxCopy SliceExp.syntaxCopy AnonDeclaration.syntaxCopy SwitchStatement.syntaxCopy CaseStatement.syntaxCopy BreakStatement.syntaxCopy ThrowStatement.syntaxCopy NewExp.syntaxCopy DefaultStatement.syntaxCopy AssertExp.syntaxCopy ClassDeclaration.syntaxCopy TypeTypedef.constConv eval_builtin ComplexExp.isConst DVCondition.syntaxCopy OrExp.getIntRange AndExp.getIntRange getMask IntegerExp.getIntRange Type.sizemask CastExp.getIntRange Expression.getIntRange
author korDen
date Sat, 21 Aug 2010 12:15:47 +0400
parents 460959608115
children 2e2a5c3f943a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.ClassDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3 import dmd.AggregateDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.InterfaceDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.ThisDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.CompoundStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.DeleteDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.NewDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.CtorDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.TypeIdentifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.STC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.Argument;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.TypeTuple;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.LINK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.DsymbolTable;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.FuncDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.Array;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.TypeClass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.Module;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.Id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.OverloadSet;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.ArrayTypes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.BaseClass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import dmd.ClassInfoDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 import dmd.TypeFunction;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 import dmd.VarDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 import dmd.Initializer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 import dmd.ExpInitializer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 import dmd.TypeSArray;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 import dmd.ScopeDsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 import dmd.PROT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 import dmd.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 import dmd.Global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 import dmd.expression.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 import dmd.backend.Symbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 import dmd.backend.dt_t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 import dmd.backend.TYPE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 import dmd.backend.FL;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 import dmd.backend.SFL;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 import dmd.backend.mTY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 import dmd.backend.SC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 import dmd.backend.mTYman;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 import dmd.backend.TYM;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 import dmd.backend.Classsym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 import dmd.backend.glue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 import dmd.backend.RTLSYM;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 import dmd.backend.LIST;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 import dmd.codegen.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 import std.string;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 enum CLASSINFO_SIZE = (0x3C+16+4); // value of ClassInfo.size
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 enum CLASSINFO_SIZE = (0x3C+12+4); // value of ClassInfo.size
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 enum OFFSET_RUNTIME = 0x76543210;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 struct Param
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 {
17
ddae60498573 Implemented mixin statements, DefaultInitExps, FileInitExps, LineInitExps and __traits.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
74 int isf(void*, FuncDeclaration fd2)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 //printf("param = %p, fd = %p %s\n", param, fd, fd.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 return fd is fd2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 FuncDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 class ClassDeclaration : AggregateDeclaration
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 static __gshared ClassDeclaration object;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 static __gshared ClassDeclaration classinfo;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 ClassDeclaration baseClass; // null only if this is Object
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 FuncDeclaration staticCtor;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 FuncDeclaration staticDtor;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 Array vtbl; // Array of FuncDeclaration's making up the vtbl[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 Array vtblFinal; // More FuncDeclaration's that aren't in vtbl[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 BaseClasses baseclasses; // Array of BaseClass's; first is super,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 // rest are Interface's
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 int interfaces_dim;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 BaseClass* interfaces; // interfaces[interfaces_dim] for this class
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 // (does not include baseClass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 BaseClasses vtblInterfaces; // array of base interfaces that have
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 // their own vtbl[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 ClassInfoDeclaration vclassinfo; // the ClassInfo object for this ClassDeclaration
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 bool com; // true if this is a COM class (meaning
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 // it derives from IUnknown)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 bool isauto; // true if this is an auto class
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 bool isabstract; // true if abstract class
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 int inuse; // to prevent recursive attempts
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 this(Loc loc, Identifier id, BaseClasses baseclasses)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 super(loc, id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 vtbl = new Array();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 vtblFinal = new Array();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 enum msg = "only object.d can define this reserved class name";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 if (baseclasses) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 this.baseclasses = baseclasses;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 this.baseclasses = new BaseClasses();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 //printf("ClassDeclaration(%s), dim = %d\n", id.toChars(), this.baseclasses.dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 // For forward references
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 type = new TypeClass(this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 if (id)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 // Look for special class names
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 if (id is Id.__sizeof || id is Id.alignof_ || id is Id.mangleof_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 error("illegal class name");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 // BUG: What if this is the wrong TypeInfo, i.e. it is nested?
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 if (id.toChars()[0] == 'T')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 if (id is Id.TypeInfo)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 if (Type.typeinfo)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 Type.typeinfo.error("%s", msg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 Type.typeinfo = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 if (id is Id.TypeInfo_Class)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 if (Type.typeinfoclass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 Type.typeinfoclass.error("%s", msg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 Type.typeinfoclass = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 if (id is Id.TypeInfo_Interface)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 if (Type.typeinfointerface)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 Type.typeinfointerface.error("%s", msg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 Type.typeinfointerface = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 if (id is Id.TypeInfo_Struct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 if (Type.typeinfostruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 Type.typeinfostruct.error("%s", msg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 Type.typeinfostruct = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 if (id is Id.TypeInfo_Typedef)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 if (Type.typeinfotypedef)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 Type.typeinfotypedef.error("%s", msg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 Type.typeinfotypedef = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 if (id is Id.TypeInfo_Pointer)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 if (Type.typeinfopointer)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 Type.typeinfopointer.error("%s", msg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 Type.typeinfopointer = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 if (id is Id.TypeInfo_Array)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 if (Type.typeinfoarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 Type.typeinfoarray.error("%s", msg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 Type.typeinfoarray = this;
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 (id is Id.TypeInfo_StaticArray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 { //if (Type.typeinfostaticarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 //Type.typeinfostaticarray.error("%s", msg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194 Type.typeinfostaticarray = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 if (id is Id.TypeInfo_AssociativeArray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 if (Type.typeinfoassociativearray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 Type.typeinfoassociativearray.error("%s", msg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201 Type.typeinfoassociativearray = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 if (id is Id.TypeInfo_Enum)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 if (Type.typeinfoenum)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207 Type.typeinfoenum.error("%s", msg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208 Type.typeinfoenum = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211 if (id is Id.TypeInfo_Function)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213 if (Type.typeinfofunction)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 Type.typeinfofunction.error("%s", msg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215 Type.typeinfofunction = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218 if (id is Id.TypeInfo_Delegate)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220 if (Type.typeinfodelegate)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221 Type.typeinfodelegate.error("%s", msg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222 Type.typeinfodelegate = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 if (id is Id.TypeInfo_Tuple)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 if (Type.typeinfotypelist)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228 Type.typeinfotypelist.error("%s", msg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 Type.typeinfotypelist = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233 if (id is Id.TypeInfo_Const)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 if (Type.typeinfoconst)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236 Type.typeinfoconst.error("%s", msg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237 Type.typeinfoconst = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240 if (id is Id.TypeInfo_Invariant)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242 if (Type.typeinfoinvariant)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243 Type.typeinfoinvariant.error("%s", msg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244 Type.typeinfoinvariant = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 if (id is Id.TypeInfo_Shared)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 if (Type.typeinfoshared)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250 Type.typeinfoshared.error("%s", msg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 Type.typeinfoshared = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 if (id is Id.Object_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258 if (object)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 object.error("%s", msg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 object = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 if (id is Id.ClassInfo)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 if (classinfo)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 classinfo.error("%s", msg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 classinfo = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270 if (id is Id.ModuleInfo)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272 if (Module.moduleinfo)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273 Module.moduleinfo.error("%s", msg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274 Module.moduleinfo = this;
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 com = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279 isauto = false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280 isabstract = false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281 inuse = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
284 Dsymbol syntaxCopy(Dsymbol s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
285 {
53
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 23
diff changeset
286 ClassDeclaration cd;
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 23
diff changeset
287
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 23
diff changeset
288 //printf("ClassDeclaration.syntaxCopy('%s')\n", toChars());
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 23
diff changeset
289 if (s)
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 23
diff changeset
290 cd = cast(ClassDeclaration)s;
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 23
diff changeset
291 else
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 23
diff changeset
292 cd = new ClassDeclaration(loc, ident, null);
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 23
diff changeset
293
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 23
diff changeset
294 cd.storage_class |= storage_class;
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 23
diff changeset
295
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 23
diff changeset
296 cd.baseclasses.setDim(this.baseclasses.dim);
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 23
diff changeset
297 for (int i = 0; i < cd.baseclasses.dim; i++)
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 23
diff changeset
298 {
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 23
diff changeset
299 BaseClass b = cast(BaseClass)this.baseclasses.data[i];
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 23
diff changeset
300 BaseClass b2 = new BaseClass(b.type.syntaxCopy(), b.protection);
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 23
diff changeset
301 cd.baseclasses.data[i] = cast(void*)b2;
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 23
diff changeset
302 }
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 23
diff changeset
303
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 23
diff changeset
304 ScopeDsymbol.syntaxCopy(cd);
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 23
diff changeset
305 return cd;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308 void semantic(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310 int i;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
311 uint offset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
312
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313 //printf("ClassDeclaration.semantic(%s), type = %p, sizeok = %d, this = %p\n", toChars(), type, sizeok, this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314 //printf("\tparent = %p, '%s'\n", sc.parent, sc.parent ? sc.parent.toChars() : "");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
315 //printf("sc.stc = %x\n", sc.stc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317 //{ static int n; if (++n == 20) *(char*)0=0; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319 if (!ident) // if anonymous class
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
320 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321 string id = "__anonclass";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322 ident = Identifier.generateId(id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
323 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
324
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
325 if (!sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
326 sc = scope_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
327
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
328 if (!parent && sc.parent && !sc.parent.isModule())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
329 parent = sc.parent;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
330
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
331 type = type.semantic(loc, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
332 handle = type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
333
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
334 if (!members) // if forward reference
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
336 //printf("\tclass '%s' is forward referenced\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
338 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
339 if (symtab)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
340 { if (!scope_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
341 { //printf("\tsemantic for '%s' is already completed\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
342 return; // semantic() already completed
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
343 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
344 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
345 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
346 symtab = new DsymbolTable();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
347
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
348 Scope scx = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
349 if (scope_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
350 { sc = scope_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
351 scx = scope_; // save so we don't make redundant copies
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
352 scope_ = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
353 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
354 version (IN_GCC) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
355 methods.setDim(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
356 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
357
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
358 if (sc.stc & STC.STCdeprecated)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
359 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
360 isdeprecated = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
361 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
362
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
363 if (sc.linkage == LINK.LINKcpp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
364 error("cannot create C++ classes");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
365
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
366 // Expand any tuples in baseclasses[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
367 for (i = 0; i < baseclasses.dim; )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
368 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
369 BaseClass b = cast(BaseClass)baseclasses.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
370 //printf("test1 %s %s\n", toChars(), b.type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
371 b.type = b.type.semantic(loc, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
372 //printf("test2\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
373 Type tb = b.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
374
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
375 if (tb.ty == TY.Ttuple)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
376 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
377 TypeTuple tup = cast(TypeTuple)tb;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
378 enum PROT protection = b.protection;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
379 baseclasses.remove(i);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
380 size_t dim = Argument.dim(tup.arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
381 for (size_t j = 0; j < dim; j++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
382 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
383 Argument arg = Argument.getNth(tup.arguments, j);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
384 b = new BaseClass(arg.type, protection);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
385 baseclasses.insert(i + j, cast(void*)b);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
386 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
387 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
388 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
389 i++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
390 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
391
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
392 // See if there's a base class as first in baseclasses[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
393 if (baseclasses.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
394 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
395 TypeClass tc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
396 BaseClass b;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
397 Type tb;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
398
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
399 b = cast(BaseClass)baseclasses.data[0];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
400 //b.type = b.type.semantic(loc, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
401 tb = b.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
402 if (tb.ty != TY.Tclass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
403 { error("base type must be class or interface, not %s", b.type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
404 baseclasses.remove(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
405 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
406 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
407 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
408 tc = cast(TypeClass)(tb);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
409
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
410 if (tc.sym.isDeprecated())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
411 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
412 if (!isDeprecated())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
413 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
414 // Deriving from deprecated class makes this one deprecated too
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
415 isdeprecated = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
416
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
417 tc.checkDeprecated(loc, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
418 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
419 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
420
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
421 if (tc.sym.isInterfaceDeclaration()) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
422 ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
423 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
424 for (ClassDeclaration cdb = tc.sym; cdb; cdb = cdb.baseClass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
425 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
426 if (cdb == this)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
427 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
428 error("circular inheritance");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
429 baseclasses.remove(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
430 goto L7;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
431 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
432 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
433 if (!tc.sym.symtab || tc.sym.sizeok == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
434 { // Try to resolve forward reference
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
435 if (sc.mustsemantic && tc.sym.scope_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
436 tc.sym.semantic(null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
437 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
438 if (!tc.sym.symtab || tc.sym.scope_ || tc.sym.sizeok == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
439 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
440 //printf("%s: forward reference of base class %s\n", toChars(), tc.sym.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
441 //error("forward reference of base class %s", baseClass.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
442 // Forward reference of base class, try again later
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
443 //printf("\ttry later, forward reference of base class %s\n", tc.sym.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
444 scope_ = scx ? scx : new Scope(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
445 scope_.setNoFree();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
446 if (tc.sym.scope_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
447 tc.sym.scope_.module_.addDeferredSemantic(tc.sym);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
448 scope_.module_.addDeferredSemantic(this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
449 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
450 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
451 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
452 { baseClass = tc.sym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
453 b.base = baseClass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
454 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
455 L7: ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
456 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
457 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
458 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
459
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
460 // Treat the remaining entries in baseclasses as interfaces
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
461 // Check for errors, handle forward references
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
462 for (i = (baseClass ? 1 : 0); i < baseclasses.dim; )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
463 { TypeClass tc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
464 BaseClass b;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
465 Type tb;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
466
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
467 b = cast(BaseClass)baseclasses.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
468 b.type = b.type.semantic(loc, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
469 tb = b.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
470 if (tb.ty == TY.Tclass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
471 tc = cast(TypeClass)tb;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
472 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
473 tc = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
474 if (!tc || !tc.sym.isInterfaceDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
475 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
476 error("base type must be interface, not %s", b.type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
477 baseclasses.remove(i);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
478 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
479 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
480 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
481 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
482 if (tc.sym.isDeprecated())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
483 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
484 if (!isDeprecated())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
485 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
486 // Deriving from deprecated class makes this one deprecated too
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
487 isdeprecated = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
488
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
489 tc.checkDeprecated(loc, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
490 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
491 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
492
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
493 // Check for duplicate interfaces
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
494 for (size_t j = (baseClass ? 1 : 0); j < i; j++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
495 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
496 BaseClass b2 = cast(BaseClass)baseclasses.data[j];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
497 if (b2.base == tc.sym)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
498 error("inherits from duplicate interface %s", b2.base.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
499 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
500
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
501 if (!tc.sym.symtab)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
502 { // Try to resolve forward reference
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
503 if (sc.mustsemantic && tc.sym.scope_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
504 tc.sym.semantic(null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
505 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
506
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
507 b.base = tc.sym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
508 if (!b.base.symtab || b.base.scope_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
509 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
510 //error("forward reference of base class %s", baseClass.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
511 // Forward reference of base, try again later
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
512 //printf("\ttry later, forward reference of base %s\n", baseClass.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
513 scope_ = scx ? scx : new Scope(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
514 scope_.setNoFree();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
515 if (tc.sym.scope_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
516 tc.sym.scope_.module_.addDeferredSemantic(tc.sym);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
517 scope_.module_.addDeferredSemantic(this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
518 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
519 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
520 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
521 i++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
522 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
523
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
524
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
525 // If no base class, and this is not an Object, use Object as base class
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
526 if (!baseClass && ident !is Id.Object_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
527 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
528 // BUG: what if Object is redefined in an inner scope?
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
529 Type tbase = new TypeIdentifier(Loc(0), Id.Object_);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
530 BaseClass b;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
531 TypeClass tc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
532 Type bt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
533
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
534 if (!object)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
535 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
536 error("missing or corrupt object.d");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
537 fatal();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
538 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
539 bt = tbase.semantic(loc, sc).toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
540 b = new BaseClass(bt, PROT.PROTpublic);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
541 baseclasses.shift(cast(void*)b);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
542 assert(b.type.ty == TY.Tclass);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
543 tc = cast(TypeClass)(b.type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
544 baseClass = tc.sym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
545 assert(!baseClass.isInterfaceDeclaration());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
546 b.base = baseClass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
547 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
548
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
549 interfaces_dim = baseclasses.dim;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
550 interfaces = cast(BaseClass*)baseclasses.data;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
551
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
552 if (baseClass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
553 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
554 if (baseClass.storage_class & STC.STCfinal)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
555 error("cannot inherit from final class %s", baseClass.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
556
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
557 interfaces_dim--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
558 interfaces++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
559
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
560 // Copy vtbl[] from base class
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
561 vtbl.setDim(baseClass.vtbl.dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
562 memcpy(vtbl.data, baseClass.vtbl.data, (void*).sizeof * vtbl.dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
563
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
564 // Inherit properties from base class
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
565 com = baseClass.isCOMclass();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
566 isauto = baseClass.isauto;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
567 vthis = baseClass.vthis;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
568 storage_class |= baseClass.storage_class & STC.STC_TYPECTOR;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
569 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
570 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
571 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
572 // No base class, so this is the root of the class hierarchy
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
573 vtbl.setDim(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
574 vtbl.push(cast(void*)this); // leave room for classinfo as first member
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
575 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
576
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
577 protection = sc.protection;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
578 storage_class |= sc.stc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
579
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
580 if (sizeok == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
581 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
582 interfaceSemantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
583
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
584 for (i = 0; i < members.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
585 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
586 Dsymbol s = cast(Dsymbol)members.data[i];
13
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 0
diff changeset
587 s.addMember(sc, this, true);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
588 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
589
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
590 /* If this is a nested class, add the hidden 'this'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
591 * member which is a pointer to the enclosing scope.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
592 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
593 if (vthis) // if inheriting from nested class
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
594 { // Use the base class's 'this' member
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
595 isnested = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
596 if (storage_class & STC.STCstatic)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
597 error("static class cannot inherit from nested class %s", baseClass.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
598 if (toParent2() != baseClass.toParent2())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
599 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
600 if (toParent2())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
601 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
602 error("is nested within %s, but super class %s is nested within %s",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
603 toParent2().toChars(),
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
604 baseClass.toChars(),
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
605 baseClass.toParent2().toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
606 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
607 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
608 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
609 error("is not nested, but super class %s is nested within %s",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
610 baseClass.toChars(),
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
611 baseClass.toParent2().toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
612 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
613 isnested = false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
614 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
615 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
616 else if (!(storage_class & STC.STCstatic))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
617 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
618 Dsymbol s = toParent2();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
619 if (s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
620 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
621 AggregateDeclaration ad = s.isClassDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
622 FuncDeclaration fd = s.isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
623
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
624 if (ad || fd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
625 { isnested = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
626 Type t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
627 if (ad)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
628 t = ad.handle;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
629 else if (fd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
630 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
631 AggregateDeclaration ad2 = fd.isMember2();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
632 if (ad2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
633 t = ad2.handle;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
634 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
635 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
636 t = Type.tvoidptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
637 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
638 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
639 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
640 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
641 if (t.ty == TY.Tstruct) // ref to struct
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
642 t = Type.tvoidptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
643 assert(!vthis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
644 vthis = new ThisDeclaration(loc, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
645 members.push(cast(void*)vthis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
646 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
647 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
648 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
649 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
650
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
651 if (storage_class & (STC.STCauto | STC.STCscope))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
652 isauto = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
653 if (storage_class & STC.STCabstract)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
654 isabstract = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
655 if (storage_class & STC.STCimmutable)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
656 type = type.invariantOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
657 else if (storage_class & STC.STCconst)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
658 type = type.constOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
659 else if (storage_class & STC.STCshared)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
660 type = type.sharedOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
661
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
662 sc = sc.push(this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
663 sc.stc &= ~(STC.STCfinal | STC.STCauto | STC.STCscope | STC.STCstatic |
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
664 STC.STCabstract | STC.STCdeprecated | STC.STC_TYPECTOR | STC.STCtls | STC.STCgshared);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
665 sc.stc |= storage_class & STC.STC_TYPECTOR;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
666 sc.parent = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
667 sc.inunion = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
668
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
669 if (isCOMclass())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
670 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
671 version (_WIN32) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
672 sc.linkage = LINK.LINKwindows;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
673 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
674 /* This enables us to use COM objects under Linux and
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
675 * work with things like XPCOM
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
676 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
677 sc.linkage = LINK.LINKc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
678 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
679 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
680 sc.protection = PROT.PROTpublic;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
681 sc.explicitProtection = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
682 sc.structalign = 8;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
683 structalign = sc.structalign;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
684 if (baseClass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
685 { sc.offset = baseClass.structsize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
686 alignsize = baseClass.alignsize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
687 // if (isnested)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
688 // sc.offset += PTRSIZE; // room for uplevel context pointer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
689 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
690 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
691 { sc.offset = PTRSIZE * 2; // allow room for __vptr and __monitor
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
692 alignsize = PTRSIZE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
693 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
694 structsize = sc.offset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
695 Scope scsave = sc; /// a copy must be created?
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
696 int members_dim = members.dim;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
697 sizeok = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
698 for (i = 0; i < members_dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
699 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
700 Dsymbol s = cast(Dsymbol)members.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
701 s.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
702 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
703
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
704 if (sizeok == 2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
705 { // semantic() failed because of forward references.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
706 // Unwind what we did, and defer it for later
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
707 fields.setDim(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
708 structsize = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
709 alignsize = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
710 structalign = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
711
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
712 sc = sc.pop();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
713
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
714 scope_ = scx ? scx : new Scope(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
715 scope_.setNoFree();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
716 scope_.module_.addDeferredSemantic(this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
717
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
718 //printf("\tsemantic('%s') failed due to forward references\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
719 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
720 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
721
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
722 //printf("\tsemantic('%s') successful\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
723
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
724 structsize = sc.offset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
725 //members.print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
726
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
727 /* Look for special member functions.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
728 * They must be in this class, not in a base class.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
729 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
730 ctor = cast(CtorDeclaration)search(Loc(0), Id.ctor, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
731 if (ctor && (ctor.toParent() != this || !ctor.isCtorDeclaration()))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
732 ctor = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
733
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
734 // dtor = (DtorDeclaration *)search(Id.dtor, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
735 // if (dtor && dtor.toParent() != this)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
736 // dtor = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
737
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
738 // inv = (InvariantDeclaration *)search(Id.classInvariant, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
739 // if (inv && inv.toParent() != this)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
740 // inv = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
741
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
742 // Can be in base class
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
743 aggNew = cast(NewDeclaration)search(Loc(0), Id.classNew, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
744 aggDelete = cast(DeleteDeclaration)search(Loc(0), Id.classDelete, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
745
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
746 // If this class has no constructor, but base class does, create
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
747 // a constructor:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
748 // this() { }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
749 if (!ctor && baseClass && baseClass.ctor)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
750 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
751 //printf("Creating default this(){} for class %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
752 CtorDeclaration ctor = new CtorDeclaration(loc, Loc(0), null, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
753 ctor.fbody = new CompoundStatement(Loc(0), new Statements());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
754 members.push(cast(void*)ctor);
13
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 0
diff changeset
755 ctor.addMember(sc, this, true);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
756 sc = scsave; // why? What about sc.nofree? ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
757 sc.offset = structsize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
758 ctor.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
759 this.ctor = ctor;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
760 defaultCtor = ctor;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
761 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
762
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
763 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
764 if (baseClass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
765 { if (!aggDelete)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
766 aggDelete = baseClass.aggDelete;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
767 if (!aggNew)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
768 aggNew = baseClass.aggNew;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
769 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
770 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
771
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
772 // Allocate instance of each new interface
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
773 for (i = 0; i < vtblInterfaces.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
774 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
775 BaseClass b = cast(BaseClass)vtblInterfaces.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
776 uint thissize = PTRSIZE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
777
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
778 alignmember(structalign, thissize, &sc.offset);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
779 assert(b.offset == 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
780 b.offset = sc.offset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
781
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
782 // Take care of single inheritance offsets
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
783 while (b.baseInterfaces.length)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
784 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
785 b = b.baseInterfaces[0];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
786 b.offset = sc.offset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
787 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
788
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
789 sc.offset += thissize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
790 if (alignsize < thissize)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
791 alignsize = thissize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
792 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
793 structsize = sc.offset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
794 sizeok = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
795 Module.dprogress++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
796
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
797 dtor = buildDtor(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
798
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
799 sc.pop();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
800
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
801 static if (false) { // Do not call until toObjfile() because of forward references
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
802 // Fill in base class vtbl[]s
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
803 for (i = 0; i < vtblInterfaces.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
804 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
805 BaseClass b = cast(BaseClass)vtblInterfaces.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
806
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
807 //b.fillVtbl(this, &b.vtbl, 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
808 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
809 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
810 //printf("-ClassDeclaration.semantic(%s), type = %p\n", toChars(), type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
811 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
812
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
813 void toCBuffer(OutBuffer buf, HdrGenState* hgs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
814 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
815 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
816 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
817
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
818 /*********************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
819 * Determine if 'this' is a base class of cd.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
820 * This is used to detect circular inheritance only.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
821 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
822 int isBaseOf2(ClassDeclaration cd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
823 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
824 if (!cd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
825 return 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
826 //printf("ClassDeclaration::isBaseOf2(this = '%s', cd = '%s')\n", toChars(), cd.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
827 for (int i = 0; i < cd.baseclasses.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
828 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
829 BaseClass b = cast(BaseClass)cd.baseclasses.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
830
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
831 if (b.base is this || isBaseOf2(b.base))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
832 return 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
833 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
834 return 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
835 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
836
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
837 /*******************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
838 * Determine if 'this' is a base class of cd.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
839 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
840 /// #define OFFSET_RUNTIME 0x76543210
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
841 bool isBaseOf(ClassDeclaration cd, int* poffset)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
842 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
843 if (!cd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
844 return 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
845 //printf("ClassDeclaration::isBaseOf2(this = '%s', cd = '%s')\n", toChars(), cd.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
846 for (int i = 0; i < cd.baseclasses.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
847 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
848 BaseClass b = cast(BaseClass)cd.baseclasses.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
849
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
850 if (b.base == this || isBaseOf2(b.base))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
851 return 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
852 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
853
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
854 return 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
855 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
856
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
857 Dsymbol search(Loc, Identifier ident, int flags)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
858 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
859 Dsymbol s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
860 //printf("%s.ClassDeclaration.search('%s')\n", toChars(), ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
861
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
862 if (scope_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
863 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
864 Scope sc = scope_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
865 sc.mustsemantic++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
866 semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
867 sc.mustsemantic--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
868 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
869
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
870 if (!members || !symtab || scope_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
871 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
872 error("is forward referenced when looking for '%s'", ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
873 //*(char*)0=0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
874 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
875 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
876
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
877 s = ScopeDsymbol.search(loc, ident, flags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
878 if (!s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
879 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
880 // Search bases classes in depth-first, left to right order
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
881
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
882 int i;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
883
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
884 for (i = 0; i < baseclasses.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
885 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
886 BaseClass b = cast(BaseClass)baseclasses.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
887
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
888 if (b.base)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
889 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
890 if (!b.base.symtab)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
891 error("base %s is forward referenced", b.base.ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
892 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
893 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
894 s = b.base.search(loc, ident, flags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
895 if (s is this) // happens if s is nested in this and derives from this
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
896 s = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
897 else if (s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
898 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
899 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
900 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
901 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
902 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
903 return s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
904 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
905
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
906 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
907 bool isFuncHidden(FuncDeclaration fd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
908 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
909 //printf("ClassDeclaration::isFuncHidden(class = %s, fd = %s)\n", toChars(), fd.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
910 Dsymbol s = search(Loc(0), fd.ident, 4|2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
911 if (!s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
912 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
913 //printf("not found\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
914 /* Because, due to a hack, if there are multiple definitions
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
915 * of fd.ident, null is returned.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
916 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
917 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
918 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
919
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
920 Param p; p.fd = fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
921
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
922 s = s.toAlias();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
923 OverloadSet os = s.isOverloadSet();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
924 if (os)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
925 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
926 for (int i = 0; i < os.a.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
927 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
928 Dsymbol s2 = cast(Dsymbol)os.a.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
929 FuncDeclaration f2 = s2.isFuncDeclaration();
17
ddae60498573 Implemented mixin statements, DefaultInitExps, FileInitExps, LineInitExps and __traits.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
930 if (f2 && overloadApply(f2, &p.isf, &p))
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
931 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
932 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
933 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
934 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
935 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
936 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
937 FuncDeclaration fdstart = s.isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
938 //printf("%s fdstart = %p\n", s.kind(), fdstart);
17
ddae60498573 Implemented mixin statements, DefaultInitExps, FileInitExps, LineInitExps and __traits.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
939 return !overloadApply(fdstart, &p.isf, &p);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
940 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
941 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
942 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
943 FuncDeclaration findFunc(Identifier ident, TypeFunction tf)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
944 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
945 //printf("ClassDeclaration.findFunc(%s, %s) %s\n", ident.toChars(), tf.toChars(), toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
946
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
947 ClassDeclaration cd = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
948 Array vtbl = cd.vtbl;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
949 while (true)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
950 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
951 for (size_t i = 0; i < vtbl.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
952 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
953 FuncDeclaration fd = (cast(Dsymbol)vtbl.data[i]).isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
954 if (!fd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
955 continue; // the first entry might be a ClassInfo
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
956
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
957 //printf("\t[%d] = %s\n", i, fd.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
958 if (ident == fd.ident &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
959 //tf.equals(fd.type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
960 fd.type.covariant(tf) == 1
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
961 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
962 { //printf("\t\tfound\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
963 return fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
964 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
965 //else printf("\t\t%d\n", fd.type.covariant(tf));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
966 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
967 if (!cd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
968 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
969
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
970 vtbl = cd.vtblFinal;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
971 cd = cd.baseClass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
972 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
973
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
974 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
975 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
976
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
977 void interfaceSemantic(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
978 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
979 InterfaceDeclaration id = isInterfaceDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
980
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
981 vtblInterfaces = new BaseClasses();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
982 vtblInterfaces.reserve(interfaces_dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
983
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
984 for (size_t i = 0; i < interfaces_dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
985 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
986 BaseClass b = interfaces[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
987
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
988 // If this is an interface, and it derives from a COM interface,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
989 // then this is a COM interface too.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
990 if (b.base.isCOMinterface())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
991 com = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
992
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
993 if (b.base.isCPPinterface() && id)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
994 id.cpp = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
995
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
996 vtblInterfaces.push(cast(void*)b);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
997 b.copyBaseInterfaces(vtblInterfaces);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
998 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
999 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1000
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1001 bool isCOMclass()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1002 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1003 return com;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1004 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1005
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1006 bool isCOMinterface()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1007 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1008 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1009 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1010
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1011 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1012 bool isCPPinterface()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1013 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1014 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1015 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1016 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1017 bool isAbstract()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1018 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1019 if (isabstract)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1020 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1021
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1022 for (int i = 1; i < vtbl.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1023 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1024 FuncDeclaration fd = (cast(Dsymbol)vtbl.data[i]).isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1025
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1026 //printf("\tvtbl[%d] = %p\n", i, fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1027 if (!fd || fd.isAbstract())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1028 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1029 isabstract = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1030 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1031 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1032 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1033
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1034 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1035 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1036
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1037 int vtblOffset()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1038 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1039 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1040 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1041
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1042 string kind()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1043 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1044 return "class";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1045 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1046
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1047 string mangle()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1048 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1049 Dsymbol parentsave = parent;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1050
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1051 //printf("ClassDeclaration.mangle() %s.%s\n", parent.toChars(), toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1052
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1053 /* These are reserved to the compiler, so keep simple
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1054 * names for them.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1055 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1056 if (ident is Id.Exception)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1057 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1058 if (parent.ident is Id.object)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1059 parent = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1060 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1061 else if (ident is Id.TypeInfo ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1062 // ident is Id.Exception ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1063 ident is Id.TypeInfo_Struct ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1064 ident is Id.TypeInfo_Class ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1065 ident is Id.TypeInfo_Typedef ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1066 ident is Id.TypeInfo_Tuple ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1067 this is object ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1068 this is classinfo ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1069 this is Module.moduleinfo ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1070 ident.toChars().startsWith("TypeInfo_")
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1071 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1072 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1073 parent = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1074 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1075
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1076 string id = Dsymbol.mangle();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1077 parent = parentsave;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1078 return id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1079 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1080
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1081 void toDocBuffer(OutBuffer buf)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1082 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1083 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1084 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1085
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1086 PROT getAccess(Dsymbol smember) // determine access to smember
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1087 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1088 PROT access_ret = PROT.PROTnone;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1089
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1090 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1091 printf("+ClassDeclaration::getAccess(this = '%s', smember = '%s')\n",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1092 toChars(), smember.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1093 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1094 if (smember.toParent() is this)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1095 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1096 access_ret = smember.prot();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1097 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1098 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1099 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1100 PROT access;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1101 int i;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1102
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1103 if (smember.isDeclaration().isStatic())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1104 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1105 access_ret = smember.prot();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1106 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1107
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1108 for (i = 0; i < baseclasses.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1109 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1110 BaseClass b = cast(BaseClass)baseclasses.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1111
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1112 access = b.base.getAccess(smember);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1113 switch (access)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1114 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1115 case PROT.PROTnone:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1116 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1117
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1118 case PROT.PROTprivate:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1119 access = PROT.PROTnone; // private members of base class not accessible
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1120 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1121
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1122 case PROT.PROTpackage:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1123 case PROT.PROTprotected:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1124 case PROT.PROTpublic:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1125 case PROT.PROTexport:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1126 // If access is to be tightened
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1127 if (b.protection < access)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1128 access = b.protection;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1129
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1130 // Pick path with loosest access
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1131 if (access > access_ret)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1132 access_ret = access;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1133 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1134
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1135 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1136 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1137 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1138 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1139 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1140
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1141 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1142 printf("-ClassDeclaration::getAccess(this = '%s', smember = '%s') = %d\n",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1143 toChars(), smember.toChars(), access_ret);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1144 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1145
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1146 return access_ret;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1147 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1148
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1149 void addLocalClass(ClassDeclarations aclasses)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1150 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1151 aclasses.push(cast(void*)this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1152 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1153
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1154 // Back end
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1155 void toObjFile(int multiobj) // compile to .obj file
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1156 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1157 uint i;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1158 uint offset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1159 Symbol* sinit;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1160 enum_SC scclass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1161
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1162 //printf("ClassDeclaration.toObjFile('%s')\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1163
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1164 if (!members)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1165 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1166
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1167 if (multiobj)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1168 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1169 obj_append(this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1170 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1171 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1172
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1173 if (global.params.symdebug)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1174 toDebug();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1175
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1176 assert(!scope_); // semantic() should have been run to completion
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1177
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1178 scclass = SCglobal;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1179 if (inTemplateInstance())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1180 scclass = SCcomdat;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1181
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1182 // Put out the members
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1183 for (i = 0; i < members.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1184 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1185 Dsymbol member;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1186
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1187 member = cast(Dsymbol)members.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1188 member.toObjFile(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1189 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1190
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1191 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1192 // Build destructor by aggregating dtors[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1193 Symbol* sdtor;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1194 switch (dtors.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1195 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1196 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1197 // No destructors for this class
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1198 sdtor = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1199 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1200
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1201 case 1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1202 // One destructor, just use it directly
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1203 sdtor = (cast(DtorDeclaration)dtors.data[0]).toSymbol();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1204 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1205
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1206 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1207 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1208 /* Build a destructor that calls all the
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1209 * other destructors in dtors[].
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1210 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1211
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1212 elem* edtor = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1213
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1214 // Declare 'this' pointer for our new destructor
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1215 Symbol* sthis = symbol_calloc("this");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1216 sthis.Stype = type_fake(TYnptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1217 sthis.Stype.Tcount++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1218 sthis.Sclass = SCfastpar;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1219 sthis.Spreg = AX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1220 sthis.Sfl = FLauto;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1221
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1222 // Call each of the destructors in dtors[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1223 // in reverse order
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1224 for (i = 0; i < dtors.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1225 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1226 DtorDeclaration d = cast(DtorDeclaration)dtors.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1227 Symbol* s = d.toSymbol();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1228 elem* e = el_bin(OPcall, TYvoid, el_var(s), el_var(sthis));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1229 edtor = el_combine(e, edtor);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1230 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1231
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1232 // Create type for the function
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1233 .type* t = type_alloc(TYjfunc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1234 t.Tflags |= TFprototype | TFfixed;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1235 t.Tmangle = mTYman_d;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1236 t.Tnext = tsvoid;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1237 tsvoid.Tcount++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1238
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1239 // Create the function, sdtor, and write it out
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1240 localgot = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1241 sdtor = toSymbolX("__dtor", SCglobal, t, "FZv");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1242 block* b = block_calloc();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1243 b.BC = BCret;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1244 b.Belem = edtor;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1245 sdtor.Sfunc.Fstartblock = b;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1246 cstate.CSpsymtab = &sdtor.Sfunc.Flocsym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1247 symbol_add(sthis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1248 writefunc(sdtor);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1249 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1250 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1251 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1252
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1253 // Generate C symbols
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1254 toSymbol();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1255 toVtblSymbol();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1256 sinit = toInitializer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1257
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1258 //////////////////////////////////////////////
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1259
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1260 // Generate static initializer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1261 sinit.Sclass = scclass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1262 sinit.Sfl = FLdata;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1263 version (ELFOBJ) { // Burton
22
fd4acc376c45 Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents: 17
diff changeset
1264 sinit.Sseg = Segment.CDATA;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1265 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1266 version (MACHOBJ) {
22
fd4acc376c45 Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents: 17
diff changeset
1267 sinit.Sseg = Segment.DATA;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1268 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1269 toDt(&sinit.Sdt);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1270 outdata(sinit);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1271
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1272 //////////////////////////////////////////////
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1273
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1274 // Put out the TypeInfo
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1275 type.getTypeInfo(null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1276 type.vtinfo.toObjFile(multiobj);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1277
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1278 //////////////////////////////////////////////
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1279
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1280 // Put out the ClassInfo
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1281 csym.Sclass = scclass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1282 csym.Sfl = FLdata;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1283
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1284 /* The layout is:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1285 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1286 void **vptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1287 monitor_t monitor;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1288 byte[] initializer; // static initialization data
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1289 char[] name; // class name
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1290 void *[] vtbl;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1291 Interface[] interfaces;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1292 ClassInfo *base; // base class
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1293 void *destructor;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1294 void *invariant; // class invariant
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1295 uint flags;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1296 void *deallocator;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1297 OffsetTypeInfo[] offTi;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1298 void *defaultConstructor;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1299 const(MemberInfo[]) function(string) xgetMembers; // module getMembers() function
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1300 TypeInfo typeinfo;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1301 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1302 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1303 dt_t* dt = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1304 offset = CLASSINFO_SIZE; // must be ClassInfo.size
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1305 if (classinfo)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1306 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1307 if (classinfo.structsize != CLASSINFO_SIZE)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1308 error("D compiler and phobos' object.d are mismatched");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1309 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1310
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1311 if (classinfo)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1312 dtxoff(&dt, classinfo.toVtblSymbol(), 0, TYnptr); // vtbl for ClassInfo
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1313 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1314 dtdword(&dt, 0); // BUG: should be an assert()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1315
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1316 dtdword(&dt, 0); // monitor
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1317
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1318 // initializer[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1319 assert(structsize >= 8);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1320 dtdword(&dt, structsize); // size
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1321 dtxoff(&dt, sinit, 0, TYnptr); // initializer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1322
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1323 // name[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1324 string name = ident.toChars();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1325 size_t namelen = name.length;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1326 if (!(namelen > 9 && name[0..9] == "TypeInfo_"))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1327 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1328 name = toPrettyChars();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1329 namelen = name.length;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1330 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1331 dtdword(&dt, namelen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1332 dtabytes(&dt, TYnptr, 0, namelen + 1, toStringz(name));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1333
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1334 // vtbl[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1335 dtdword(&dt, vtbl.dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1336 dtxoff(&dt, vtblsym, 0, TYnptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1337
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1338 // interfaces[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1339 dtdword(&dt, vtblInterfaces.dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1340 if (vtblInterfaces.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1341 dtxoff(&dt, csym, offset, TYnptr); // (*)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1342 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1343 dtdword(&dt, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1344
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1345 // base
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1346 if (baseClass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1347 dtxoff(&dt, baseClass.toSymbol(), 0, TYnptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1348 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1349 dtdword(&dt, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1350
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1351 // destructor
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1352 if (dtor)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1353 dtxoff(&dt, dtor.toSymbol(), 0, TYnptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1354 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1355 dtdword(&dt, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1356
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1357 // invariant
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1358 if (inv)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1359 dtxoff(&dt, inv.toSymbol(), 0, TYnptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1360 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1361 dtdword(&dt, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1362
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1363 // flags
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1364 int flags = 4 | isCOMclass();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1365 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1366 flags |= 16;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1367 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1368 flags |= 32;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1369
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1370 if (ctor)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1371 flags |= 8;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1372 for (ClassDeclaration cd = this; cd; cd = cd.baseClass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1373 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1374 if (cd.members)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1375 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1376 for (size_t j = 0; j < cd.members.dim; j++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1377 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1378 Dsymbol sm = cast(Dsymbol)cd.members.data[j];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1379 //printf("sm = %s %s\n", sm.kind(), sm.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1380 if (sm.hasPointers())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1381 goto L2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1382 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1383 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1384 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1385 flags |= 2; // no pointers
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1386 L2:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1387 dtdword(&dt, flags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1388
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1389
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1390 // deallocator
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1391 if (aggDelete)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1392 dtxoff(&dt, aggDelete.toSymbol(), 0, TYnptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1393 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1394 dtdword(&dt, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1395
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1396 // offTi[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1397 dtdword(&dt, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1398 dtdword(&dt, 0); // null for now, fix later
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1399
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1400 // defaultConstructor
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1401 if (defaultCtor)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1402 dtxoff(&dt, defaultCtor.toSymbol(), 0, TYnptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1403 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1404 dtdword(&dt, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1405
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1406 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1407 FuncDeclaration sgetmembers = findGetMembers();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1408 if (sgetmembers)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1409 dtxoff(&dt, sgetmembers.toSymbol(), 0, TYnptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1410 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1411 dtdword(&dt, 0); // module getMembers() function
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1412 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1413
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1414 dtxoff(&dt, type.vtinfo.toSymbol(), 0, TYnptr); // typeinfo
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1415 //dtdword(&dt, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1416
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1417 //////////////////////////////////////////////
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1418
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1419 // Put out vtblInterfaces.data[]. Must immediately follow csym, because
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1420 // of the fixup (*)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1421
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1422 offset += vtblInterfaces.dim * (4 * PTRSIZE);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1423 for (i = 0; i < vtblInterfaces.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1424 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1425 BaseClass b = cast(BaseClass)vtblInterfaces.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1426 ClassDeclaration id = b.base;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1427
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1428 /* The layout is:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1429 * {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1430 * ClassInfo *interface;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1431 * void *[] vtbl;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1432 * unsigned offset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1433 * }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1434 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1435
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1436 // Fill in vtbl[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1437 b.fillVtbl(this, b.vtbl, 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1438
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1439 dtxoff(&dt, id.toSymbol(), 0, TYnptr); // ClassInfo
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1440
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1441 // vtbl[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1442 dtdword(&dt, id.vtbl.dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1443 dtxoff(&dt, csym, offset, TYnptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1444
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1445 dtdword(&dt, b.offset); // this offset
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1446
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1447 offset += id.vtbl.dim * PTRSIZE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1448 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1449
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1450 // Put out the vtblInterfaces.data[].vtbl[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1451 // This must be mirrored with ClassDeclaration.baseVtblOffset()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1452 //printf("putting out %d interface vtbl[]s for '%s'\n", vtblInterfaces.dim, toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1453 for (i = 0; i < vtblInterfaces.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1454 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1455 BaseClass b = cast(BaseClass)vtblInterfaces.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1456 ClassDeclaration id = b.base;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1457 int j;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1458
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1459 //printf(" interface[%d] is '%s'\n", i, id.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1460 j = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1461 if (id.vtblOffset())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1462 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1463 // First entry is ClassInfo reference
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1464 //dtxoff(&dt, id.toSymbol(), 0, TYnptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1465
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1466 // First entry is struct Interface reference
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1467 dtxoff(&dt, csym, CLASSINFO_SIZE + i * (4 * PTRSIZE), TYnptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1468 j = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1469 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1470
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1471 assert(id.vtbl.dim == b.vtbl.dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1472 for (; j < id.vtbl.dim; j++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1473 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1474 FuncDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1475
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1476 assert(j < b.vtbl.dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1477 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1478 Object o = cast(Object)b.vtbl.data[j];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1479 if (o)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1480 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1481 printf("o = %p\n", o);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1482 assert(o.dyncast() == DYNCAST_DSYMBOL);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1483 Dsymbol s = cast(Dsymbol)o;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1484 printf("s.kind() = '%s'\n", s.kind());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1485 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1486 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1487 fd = cast(FuncDeclaration)b.vtbl.data[j];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1488 if (fd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1489 dtxoff(&dt, fd.toThunkSymbol(b.offset), 0, TYnptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1490 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1491 dtdword(&dt, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1492 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1493 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1494
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1495 static if (true) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1496 // Put out the overriding interface vtbl[]s.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1497 // This must be mirrored with ClassDeclaration.baseVtblOffset()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1498 //printf("putting out overriding interface vtbl[]s for '%s' at offset x%x\n", toChars(), offset);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1499 ClassDeclaration cd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1500 scope Array bvtbl = new Array();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1501
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1502 for (cd = this.baseClass; cd; cd = cd.baseClass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1503 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1504 for (int k = 0; k < cd.vtblInterfaces.dim; k++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1505 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1506 BaseClass bs = cast(BaseClass)cd.vtblInterfaces.data[k];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1507
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1508 if (bs.fillVtbl(this, bvtbl, 0))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1509 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1510 //printf("\toverriding vtbl[] for %s\n", bs.base.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1511 ClassDeclaration id = bs.base;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1512 int j;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1513
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1514 j = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1515 if (id.vtblOffset())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1516 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1517 // First entry is ClassInfo reference
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1518 //dtxoff(&dt, id.toSymbol(), 0, TYnptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1519
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1520 // First entry is struct Interface reference
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1521 dtxoff(&dt, cd.toSymbol(), CLASSINFO_SIZE + k * (4 * PTRSIZE), TYnptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1522 j = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1523 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1524
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1525 for (; j < id.vtbl.dim; j++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1526 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1527 assert(j < bvtbl.dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1528 FuncDeclaration fd = cast(FuncDeclaration)bvtbl.data[j];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1529 if (fd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1530 dtxoff(&dt, fd.toThunkSymbol(bs.offset), 0, TYnptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1531 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1532 dtdword(&dt, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1533 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1534 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1535 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1536 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1537 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1538
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1539 version (INTERFACE_VIRTUAL) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1540 // Put out the overriding interface vtbl[]s.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1541 // This must be mirrored with ClassDeclaration.baseVtblOffset()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1542 //printf("putting out overriding interface vtbl[]s for '%s' at offset x%x\n", toChars(), offset);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1543 for (i = 0; i < vtblInterfaces.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1544 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1545 BaseClass b = cast(BaseClass)vtblInterfaces.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1546 ClassDeclaration cd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1547
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1548 for (cd = this.baseClass; cd; cd = cd.baseClass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1549 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1550 for (int k = 0; k < cd.vtblInterfaces.dim; k++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1551 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1552 BaseClass bs = cast(BaseClass)cd.vtblInterfaces.data[k];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1553
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1554 if (b.base == bs.base)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1555 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1556 //printf("\toverriding vtbl[] for %s\n", b.base.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1557 ClassDeclaration id = b.base;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1558 int j;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1559
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1560 j = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1561 if (id.vtblOffset())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1562 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1563 // First entry is ClassInfo reference
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1564 //dtxoff(&dt, id.toSymbol(), 0, TYnptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1565
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1566 // First entry is struct Interface reference
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1567 dtxoff(&dt, cd.toSymbol(), CLASSINFO_SIZE + k * (4 * PTRSIZE), TYnptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1568 j = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1569 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1570
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1571 for (; j < id.vtbl.dim; j++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1572 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1573 assert(j < b.vtbl.dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1574 FuncDeclaration fd = cast(FuncDeclaration)b.vtbl.data[j];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1575 if (fd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1576 dtxoff(&dt, fd.toThunkSymbol(bs.offset), 0, TYnptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1577 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1578 dtdword(&dt, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1579 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1580 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1581 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1582 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1583 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1584 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1585
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1586
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1587 csym.Sdt = dt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1588 version (ELFOBJ_OR_MACHOBJ) { // Burton
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1589 // ClassInfo cannot be const data, because we use the monitor on it
22
fd4acc376c45 Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents: 17
diff changeset
1590 csym.Sseg = Segment.DATA;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1591 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1592 outdata(csym);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1593 if (isExport())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1594 obj_export(csym,0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1595
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1596 //////////////////////////////////////////////
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1597
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1598 // Put out the vtbl[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1599 //printf("putting out %s.vtbl[]\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1600 dt = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1601 if (0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1602 i = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1603 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1604 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1605 dtxoff(&dt, csym, 0, TYnptr); // first entry is ClassInfo reference
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1606 i = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1607 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1608 for (; i < vtbl.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1609 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1610 FuncDeclaration fd = (cast(Dsymbol)vtbl.data[i]).isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1611
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1612 //printf("\tvtbl[%d] = %p\n", i, fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1613 if (fd && (fd.fbody || !isAbstract()))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1614 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1615 Symbol* s = fd.toSymbol();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1616
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1617 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1618 if (isFuncHidden(fd))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1619 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1620 /* fd is hidden from the view of this class.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1621 * If fd overlaps with any function in the vtbl[], then
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1622 * issue 'hidden' error.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1623 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1624 for (int j = 1; j < vtbl.dim; j++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1625 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1626 if (j == i)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1627 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1628 FuncDeclaration fd2 = (cast(Dsymbol)vtbl.data[j]).isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1629 if (!fd2.ident.equals(fd.ident))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1630 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1631 if (fd.leastAsSpecialized(fd2) || fd2.leastAsSpecialized(fd))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1632 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1633 if (global.params.warnings)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1634 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1635 TypeFunction tf = cast(TypeFunction)fd.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1636 if (tf.ty == Tfunction)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1637 warning("%s%s is hidden by %s\n", fd.toPrettyChars(), Argument.argsTypesToChars(tf.parameters, tf.varargs), toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1638 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1639 warning("%s is hidden by %s\n", fd.toPrettyChars(), toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1640 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1641 s = rtlsym[RTLSYM_DHIDDENFUNC];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1642 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1643 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1644 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1645 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1646 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1647 dtxoff(&dt, s, 0, TYnptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1648 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1649 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1650 dtdword(&dt, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1651 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1652
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1653 vtblsym.Sdt = dt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1654 vtblsym.Sclass = scclass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1655 vtblsym.Sfl = FLdata;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1656 version (ELFOBJ) {
22
fd4acc376c45 Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents: 17
diff changeset
1657 vtblsym.Sseg = Segment.CDATA;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1658 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1659 version (MACHOBJ) {
22
fd4acc376c45 Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents: 17
diff changeset
1660 vtblsym.Sseg = Segment.DATA;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1661 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1662 outdata(vtblsym);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1663 if (isExport())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1664 obj_export(vtblsym,0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1665 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1666
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1667 void toDebug()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1668 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1669 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1670 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1671
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1672 /******************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1673 * Get offset of base class's vtbl[] initializer from start of csym.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1674 * Returns ~0 if not this csym.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1675 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1676 uint baseVtblOffset(BaseClass bc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1677 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1678 uint csymoffset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1679 int i;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1680
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1681 //printf("ClassDeclaration.baseVtblOffset('%s', bc = %p)\n", toChars(), bc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1682 csymoffset = CLASSINFO_SIZE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1683 csymoffset += vtblInterfaces.dim * (4 * PTRSIZE);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1684
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1685 for (i = 0; i < vtblInterfaces.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1686 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1687 BaseClass b = cast(BaseClass)vtblInterfaces.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1688
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1689 if (b == bc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1690 return csymoffset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1691 csymoffset += b.base.vtbl.dim * PTRSIZE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1692 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1693
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1694 static if (true) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1695 // Put out the overriding interface vtbl[]s.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1696 // This must be mirrored with ClassDeclaration.baseVtblOffset()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1697 //printf("putting out overriding interface vtbl[]s for '%s' at offset x%x\n", toChars(), offset);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1698 ClassDeclaration cd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1699 Array bvtbl;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1700
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1701 for (cd = this.baseClass; cd; cd = cd.baseClass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1702 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1703 for (int k = 0; k < cd.vtblInterfaces.dim; k++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1704 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1705 BaseClass bs = cast(BaseClass)cd.vtblInterfaces.data[k];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1706
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1707 if (bs.fillVtbl(this, null, 0))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1708 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1709 if (bc == bs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1710 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1711 //printf("\tcsymoffset = x%x\n", csymoffset);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1712 return csymoffset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1713 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1714 csymoffset += bs.base.vtbl.dim * PTRSIZE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1715 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1716 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1717 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1718 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1719 version (INTERFACE_VIRTUAL) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1720 for (i = 0; i < vtblInterfaces.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1721 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1722 BaseClass b = cast(BaseClass)vtblInterfaces.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1723 ClassDeclaration cd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1724
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1725 for (cd = this.baseClass; cd; cd = cd.baseClass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1726 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1727 //printf("\tbase class %s\n", cd.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1728 for (int k = 0; k < cd.vtblInterfaces.dim; k++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1729 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1730 BaseClass bs = cast(BaseClass)cd.vtblInterfaces.data[k];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1731
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1732 if (bc == bs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1733 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1734 //printf("\tcsymoffset = x%x\n", csymoffset);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1735 return csymoffset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1736 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1737 if (b.base == bs.base)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1738 csymoffset += bs.base.vtbl.dim * PTRSIZE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1739 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1740 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1741 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1742 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1743
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1744 return ~0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1745 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1746
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1747 static private __gshared Classsym* scc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1748
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1749 /*************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1750 * Create the "ClassInfo" symbol
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1751 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1752 Symbol* toSymbol()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1753 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1754 if (!csym)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1755 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1756 Symbol* s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1757
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1758 if (!scc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1759 scc = fake_classsym(Id.ClassInfo);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1760
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1761 s = toSymbolX("__Class", SC.SCextern, scc.Stype, "Z");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1762 s.Sfl = FL.FLextern;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1763 s.Sflags |= SFL.SFLnodebug;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1764 csym = s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1765 slist_add(s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1766 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1767
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1768 return csym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1769 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1770
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1771 /*************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1772 * This is accessible via the ClassData, but since it is frequently
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1773 * needed directly (like for rtti comparisons), make it directly accessible.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1774 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1775 Symbol* toVtblSymbol()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1776 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1777 if (!vtblsym)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1778 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1779 if (!csym)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1780 toSymbol();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1781
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1782 TYPE* t = type_alloc(TYM.TYnptr | mTY.mTYconst);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1783 t.Tnext = tsvoid;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1784 t.Tnext.Tcount++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1785 t.Tmangle = mTYman.mTYman_d;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1786
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1787 Symbol* s = toSymbolX("__vtbl", SC.SCextern, t, "Z");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1788 s.Sflags |= SFL.SFLnodebug;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1789 s.Sfl = FL.FLextern;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1790 vtblsym = s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1791 slist_add(s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1792 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1793 return vtblsym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1794 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1795
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1796 // Generate the data for the static initializer.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1797 void toDt(dt_t **pdt)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1798 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1799 //printf("ClassDeclaration.toDt(this = '%s')\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1800
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1801 // Put in first two members, the vtbl[] and the monitor
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1802 dtxoff(pdt, toVtblSymbol(), 0, TYnptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1803 dtdword(pdt, 0); // monitor
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1804
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1805 // Put in the rest
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1806 toDt2(pdt, this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1807
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1808 //printf("-ClassDeclaration.toDt(this = '%s')\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1809 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1810
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1811 void toDt2(dt_t** pdt, ClassDeclaration cd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1812 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1813 uint offset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1814 uint i;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1815 dt_t* dt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1816 uint csymoffset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1817
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1818 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1819 printf("ClassDeclaration.toDt2(this = '%s', cd = '%s')\n", toChars(), cd.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1820 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1821 if (baseClass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1822 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1823 baseClass.toDt2(pdt, cd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1824 offset = baseClass.structsize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1825 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1826 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1827 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1828 offset = 8;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1829 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1830
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1831 // Note equivalence of this loop to struct's
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1832 for (i = 0; i < fields.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1833 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1834 VarDeclaration v = cast(VarDeclaration)fields.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1835 Initializer init;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1836
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1837 //printf("\t\tv = '%s' v.offset = %2d, offset = %2d\n", v.toChars(), v.offset, offset);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1838 dt = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1839 init = v.init;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1840 if (init)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1841 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1842 //printf("\t\t%s has initializer %s\n", v.toChars(), init.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1843 ExpInitializer ei = init.isExpInitializer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1844 Type tb = v.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1845 if (ei && tb.ty == Tsarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1846 (cast(TypeSArray)tb).toDtElem(&dt, ei.exp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1847 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1848 dt = init.toDt();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1849 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1850 else if (v.offset >= offset)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1851 { //printf("\t\tdefault initializer\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1852 v.type.toDt(&dt);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1853 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1854 if (dt)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1855 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1856 if (v.offset < offset)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1857 error("duplicated union initialization for %s", v.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1858 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1859 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1860 if (offset < v.offset)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1861 dtnzeros(pdt, v.offset - offset);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1862 dtcat(pdt, dt);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1863 offset = v.offset + cast(uint)v.type.size();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1864 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1865 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1866 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1867
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1868 // Interface vptr initializations
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1869 toSymbol(); // define csym
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1870
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1871 for (i = 0; i < vtblInterfaces.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1872 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1873 BaseClass b = cast(BaseClass)vtblInterfaces.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1874
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1875 /// version (1 || INTERFACE_VIRTUAL) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1876 for (ClassDeclaration cd2 = cd; 1; cd2 = cd2.baseClass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1877 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1878 assert(cd2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1879 csymoffset = cd2.baseVtblOffset(b);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1880 if (csymoffset != ~0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1881 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1882 if (offset < b.offset)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1883 dtnzeros(pdt, b.offset - offset);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1884 dtxoff(pdt, cd2.toSymbol(), csymoffset, TYnptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1885 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1886 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1887 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1888 /// } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1889 /// csymoffset = baseVtblOffset(b);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1890 /// assert(csymoffset != ~0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1891 /// dtxoff(pdt, csym, csymoffset, TYnptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1892 /// }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1893 offset = b.offset + 4;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1894 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1895
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1896 if (offset < structsize)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1897 dtnzeros(pdt, structsize - offset);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1898 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1899
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1900 Symbol* vtblsym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1901
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1902 ///ClassDeclaration isClassDeclaration() { return cast(ClassDeclaration)this; } /// huh?
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1903 ClassDeclaration isClassDeclaration() { return this; }
17
ddae60498573 Implemented mixin statements, DefaultInitExps, FileInitExps, LineInitExps and __traits.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
1904 }