annotate dmd/AggregateDeclaration.d @ 84:be2ab491772e

Expressions -> Vector!Expression
author Eldar Insafutdinov <e.insafutdinov@gmail.com>
date Mon, 30 Aug 2010 16:12:19 +0100
parents 43073c7c7769
children 37b95c347975
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.AggregateDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3 import dmd.ScopeDsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.Id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.ExpStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.AddrExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.CastExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.TypeSArray;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.DotVarExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.TypeStruct;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.StructDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.Declaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.TypeClass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.ThisExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.PROT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.STC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.DotIdExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.CallExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.DtorDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.Lexer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.Array;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import dmd.ArrayTypes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.VarDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 import dmd.InvariantDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 import dmd.NewDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 import dmd.DeleteDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 import dmd.CtorDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 import dmd.FuncDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 import dmd.Identifier;
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
34 import dmd.Json;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 import dmd.ClassDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 import dmd.BaseClass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 import dmd.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 import dmd.backend.Symbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 import dmd.backend.Classsym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 import dmd.backend.LIST;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 import dmd.backend.SC;
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.codegen.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 /****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 * Determine if scope sc has package level access to s.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 bool hasPackageAccess(Scope sc, Dsymbol s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 printf("hasPackageAccess(s = '%s', sc = '%p')\n", s.toChars(), sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 for (; s; s = s.parent)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 if (s.isPackage() && !s.isModule())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 if (s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 printf("\tthis is in package '%s'\n", s.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 if (s && s == sc.module_.parent)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 printf("\ts is in same package as sc\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 printf("\tno package access\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 /********************************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 * Helper function for ClassDeclaration.accessCheck()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 * Returns:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 * 0 no access
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 * 1 access
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 bool accessCheckX(Dsymbol smember, Dsymbol sfunc, AggregateDeclaration dthis, AggregateDeclaration cdscope)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 assert(dthis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 writef("accessCheckX for %s.%s in function %s() in scope %s\n", dthis.toChars(), smember.toChars(), sfunc ? sfunc.toChars() : "null", cdscope ? cdscope.toChars() : "null");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 if (dthis.hasPrivateAccess(sfunc) || dthis.isFriendOf(cdscope))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 if (smember.toParent() == dthis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 ClassDeclaration cdthis = dthis.isClassDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 if (cdthis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 for (int i = 0; i < cdthis.baseclasses.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 BaseClass b = cast(BaseClass)cdthis.baseclasses.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 PROT access = b.base.getAccess(smember);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 if (access >= PROT.PROTprotected || accessCheckX(smember, sfunc, b.base, cdscope))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 if (smember.toParent() != dthis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 ClassDeclaration cdthis = dthis.isClassDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 if (cdthis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 for (int i = 0; i < cdthis.baseclasses.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 BaseClass b = cast(BaseClass)cdthis.baseclasses.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 if (accessCheckX(smember, sfunc, b.base, cdscope))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 class AggregateDeclaration : ScopeDsymbol
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 Type type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 uint storage_class;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 PROT protection = PROT.PROTpublic;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 Type handle; // 'this' type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 uint structsize; // size of struct
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 uint alignsize; // size of struct for alignment purposes
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 uint structalign; // struct member alignment in effect
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 int hasUnions; // set if aggregate has overlapping fields
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
153 VarDeclarations fields; // VarDeclaration fields
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 uint sizeok; // set when structsize contains valid data
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 // 0: no size
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 // 1: size is correct
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 // 2: cannot determine size; fwd referenced
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 bool isdeprecated; // true if deprecated
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 bool isnested; // true if is nested
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 VarDeclaration vthis; // 'this' parameter if this aggregate is nested
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 // Special member functions
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 InvariantDeclaration inv; // invariant
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 NewDeclaration aggNew; // allocator
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 DeleteDeclaration aggDelete; // deallocator
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 //CtorDeclaration *ctor;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 Dsymbol ctor; // CtorDeclaration or TemplateDeclaration
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 CtorDeclaration defaultCtor; // default constructor
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 Dsymbol aliasthis; // forward unresolved lookups to aliasthis
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 FuncDeclarations dtors; // Array of destructors
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 FuncDeclaration dtor; // aggregate destructor
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 version (IN_GCC) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 Array methods; // flat list of all methods for debug information
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 this(Loc loc, Identifier id)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 super(id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 this.loc = loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
187 fields = new VarDeclarations(); ///
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 dtors = new FuncDeclarations();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 16
diff changeset
191 override void semantic2(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 //printf("AggregateDeclaration.semantic2(%s)\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194 if (scope_ && members)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196 error("has forward references");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 if (members)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201 sc = sc.push(this);
77
ad4792a1cfd6 more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 74
diff changeset
202 foreach(Dsymbol s; members)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 s.semantic2(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 sc.pop();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 16
diff changeset
208 override void semantic3(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210 int i;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212 //printf("AggregateDeclaration.semantic3(%s)\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213 if (members)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215 sc = sc.push(this);
77
ad4792a1cfd6 more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 74
diff changeset
216 foreach(Dsymbol s; members)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217 s.semantic3(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218 sc.pop();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 16
diff changeset
222 override void inlineScan()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 int i;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226 //printf("AggregateDeclaration.inlineScan(%s)\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 if (members)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228 {
77
ad4792a1cfd6 more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 74
diff changeset
229 foreach(Dsymbol s; members)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 //printf("inline scan aggregate symbol '%s'\n", s.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 s.inlineScan();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 16
diff changeset
237 override uint size(Loc loc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239 //printf("AggregateDeclaration.size() = %d\n", structsize);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240 if (!members)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241 error(loc, "unknown size");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243 if (sizeok != 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245 error(loc, "no size yet for forward reference");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246 //*(char*)0=0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 return structsize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 /****************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253 * Do byte or word alignment as necessary.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 * Align sizes of 0, as we may not know array sizes yet.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 static void alignmember(uint salign, uint size, uint* poffset)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258 //printf("salign = %d, size = %d, offset = %d\n",salign,size,offset);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 if (salign > 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 assert(size != 3);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 int sa = size;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 if (sa == 0 || salign < sa)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 sa = salign;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 *poffset = (*poffset + sa - 1) & ~(sa - 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 //printf("result = %d\n",offset);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 16
diff changeset
270 override Type getType()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272 return type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275 void addField(Scope sc, VarDeclaration v)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277 uint memsize; // size of member
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278 uint memalignsize; // size of member for alignment purposes
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279 uint xalign; // alignment boundaries
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281 //printf("AggregateDeclaration.addField('%s') %s\n", v.toChars(), toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282 assert(!(v.storage_class & (STC.STCstatic | STC.STCextern | STC.STCparameter | STC.STCtls)));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
284 // Check for forward referenced types which will fail the size() call
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
285 Type t = v.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
286 if (v.storage_class & STC.STCref)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
287 { // References are the size of a pointer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288 t = Type.tvoidptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
289 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290 if (t.ty == TY.Tstruct /*&& isStructDeclaration()*/)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291 { TypeStruct ts = cast(TypeStruct)t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
292 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293 if (ts.sym == this)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295 error("cannot have field %s with same struct type", v.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
297 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299 if (ts.sym.sizeok != 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
301 sizeok = 2; // cannot finish; flag as forward referenced
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
302 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305 if (t.ty == TY.Tident)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307 sizeok = 2; // cannot finish; flag as forward referenced
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
311 memsize = cast(uint)t.size(loc); ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
312 memalignsize = t.alignsize();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313 xalign = t.memalign(sc.structalign);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314 alignmember(xalign, memalignsize, &sc.offset);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
315 v.offset = sc.offset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316 sc.offset += memsize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317 if (sc.offset > structsize)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318 structsize = sc.offset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319 if (sc.structalign < memalignsize)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
320 memalignsize = sc.structalign;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321 if (alignsize < memalignsize)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322 alignsize = memalignsize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
323 //printf("\talignsize = %d\n", alignsize);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
324
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
325 v.storage_class |= STC.STCfield;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
326 //printf(" addField '%s' to '%s' at offset %d, size = %d\n", v.toChars(), toChars(), v.offset, memsize);
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
327 fields.push(v);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
328 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
329
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 16
diff changeset
330 override bool isDeprecated() // is aggregate deprecated?
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
331 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
332 return isdeprecated;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
333 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
334
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335 /*****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
336 * Create inclusive destructor for struct/class by aggregating
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337 * all the destructors in dtors[] with the destructors for
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
338 * all the members.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
339 * Note the close similarity with StructDeclaration.buildPostBlit(),
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
340 * and the ordering changes (runs backward instead of forwards).
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
341 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
342 FuncDeclaration buildDtor(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
343 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
344 //printf("AggregateDeclaration.buildDtor() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
345 Expression e = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
346
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
347 version (DMDV2)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
348 {
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
349 foreach (size_t i, VarDeclaration v; fields)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
350 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
351 assert(v && v.storage_class & STC.STCfield);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
352 if (v.storage_class & STC.STCref)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
353 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
354 Type tv = v.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
355 size_t dim = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
356 while (tv.ty == TY.Tsarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
357 { TypeSArray ta = cast(TypeSArray)tv;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
358 dim *= (cast(TypeSArray)tv).dim.toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
359 tv = tv.nextOf().toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
360 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
361 if (tv.ty == TY.Tstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
362 { TypeStruct ts = cast(TypeStruct)tv;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
363 StructDeclaration sd = ts.sym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
364 if (sd.dtor)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
365 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
366 Expression ex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
367
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
368 // this.v
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
369 ex = new ThisExp(Loc(0));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
370 ex = new DotVarExp(Loc(0), ex, v, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
371
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
372 if (dim == 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
373 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
374 // this.v.dtor()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
375 ex = new DotVarExp(Loc(0), ex, sd.dtor, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
376 ex = new CallExp(Loc(0), ex);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
377 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
378 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
379 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
380 // Typeinfo.destroy(cast(void*)&this.v);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
381 Expression ea = new AddrExp(Loc(0), ex);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
382 ea = new CastExp(Loc(0), ea, Type.tvoid.pointerTo());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
383
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
384 Expression et = v.type.getTypeInfo(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
385 et = new DotIdExp(Loc(0), et, Id.destroy);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
386
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
387 ex = new CallExp(Loc(0), et, ea);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
388 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
389 e = Expression.combine(ex, e); // combine in reverse order
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
390 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
391 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
392 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
393
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
394 /* Build our own "destructor" which executes e
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
395 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
396 if (e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
397 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
398 //printf("Building __fieldDtor()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
399 DtorDeclaration dd = new DtorDeclaration(Loc(0), Loc(0), Lexer.idPool("__fieldDtor"));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
400 dd.fbody = new ExpStatement(Loc(0), e);
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
401 dtors.shift(dd);
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
402 members.push(dd);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
403 dd.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
404 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
405 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
406
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
407 switch (dtors.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
408 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
409 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
410 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
411
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
412 case 1:
77
ad4792a1cfd6 more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 74
diff changeset
413 return cast(FuncDeclaration)dtors[0];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
414
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
415 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
416 e = null;
77
ad4792a1cfd6 more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 74
diff changeset
417 foreach(FuncDeclaration fd; dtors)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
418 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
419 Expression ex = new ThisExp(Loc(0));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
420 ex = new DotVarExp(Loc(0), ex, fd, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
421 ex = new CallExp(Loc(0), ex);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
422 e = Expression.combine(ex, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
423 }
77
ad4792a1cfd6 more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 74
diff changeset
424 auto dd = new DtorDeclaration(Loc(0), Loc(0), Lexer.idPool("__aggrDtor"));
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
425 dd.fbody = new ExpStatement(Loc(0), e);
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
426 members.push(dd);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
427 dd.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
428 return dd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
429 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
430 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
431
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
432 /****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
433 * Returns true if there's an extra member which is the 'this'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
434 * pointer to the enclosing context (enclosing aggregate or function)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
435 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
436 bool isNested()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
437 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
438 return isnested;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
439 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
440
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 16
diff changeset
441 override void emitComment(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
442 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
443 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
444 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
445
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
446 override void toJsonBuffer(OutBuffer buf)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
447 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
448 //writef("AggregateDeclaration.toJsonBuffer()\n");
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
449 buf.writestring("{\n");
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
450
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
451 JsonProperty(buf, Pname, toChars());
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
452 JsonProperty(buf, Pkind, kind());
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
453 if (comment)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
454 JsonProperty(buf, Pcomment, comment);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
455 if (loc.linnum)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
456 JsonProperty(buf, Pline, loc.linnum);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
457
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
458 ClassDeclaration cd = isClassDeclaration();
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
459 if (cd)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
460 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
461 if (cd.baseClass)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
462 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
463 JsonProperty(buf, "base", cd.baseClass.toChars());
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
464 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
465 if (cd.interfaces_dim)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
466 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
467 JsonString(buf, "interfaces");
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
468 buf.writestring(" : [\n");
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
469 size_t offset = buf.offset;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
470 for (int i = 0; i < cd.interfaces_dim; i++)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
471 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
472 BaseClass b = cd.interfaces[i];
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
473 if (offset != buf.offset)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
474 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
475 buf.writestring(",");
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
476 offset = buf.offset;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
477 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
478 JsonString(buf, b.base.toChars());
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
479 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
480 buf.writestring("],\n");
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
481 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
482 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
483
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
484 JsonString(buf, Pmembers);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
485 buf.writestring(" : [\n");
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
486 size_t offset = buf.offset;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
487 foreach (Dsymbol s; members)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
488 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
489 if (offset != buf.offset)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
490 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
491 buf.writestring(",");
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
492 offset = buf.offset;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
493 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
494 s.toJsonBuffer(buf);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
495 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
496 buf.writestring("]\n");
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
497
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
498 buf.writestring("}\n");
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
499 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
500
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 16
diff changeset
501 override void toDocBuffer(OutBuffer buf)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
502 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
503 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
504 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
505
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
506 // For access checking
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
507 PROT getAccess(Dsymbol smember) // determine access to smember
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
508 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
509 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
510 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
511
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
512 /****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
513 * Determine if this is the same or friend of cd.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
514 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
515 bool isFriendOf(AggregateDeclaration cd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
516 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
517 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
518 printf("AggregateDeclaration.isFriendOf(this = '%s', cd = '%s')\n", toChars(), cd ? cd.toChars() : "null");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
519 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
520 if (this is cd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
521 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
522
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
523 // Friends if both are in the same module
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
524 //if (toParent() == cd.toParent())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
525 if (cd && getModule() == cd.getModule())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
526 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
527 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
528 printf("\tin same module\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
529 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
530 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
531 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
532
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
533 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
534 printf("\tnot friend\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
535 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
536 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
537 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
538
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
539 /**********************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
540 * Determine if smember has access to private members of this declaration.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
541 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
542 bool hasPrivateAccess(Dsymbol smember) // does smember have private access to members of this class?
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
543 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
544 if (smember)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
545 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
546 AggregateDeclaration cd = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
547 Dsymbol smemberparent = smember.toParent();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
548 if (smemberparent)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
549 cd = smemberparent.isAggregateDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
550
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
551 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
552 printf("AggregateDeclaration::hasPrivateAccess(class %s, member %s)\n", toChars(), smember.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
553 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
554
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
555 if (this == cd) // smember is a member of this class
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
556 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
557 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
558 printf("\tyes 1\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
559 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
560 return true; // so we get private access
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
561 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
562
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
563 // If both are members of the same module, grant access
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
564 while (true)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
565 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
566 Dsymbol sp = smember.toParent();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
567 if (sp.isFuncDeclaration() && smember.isFuncDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
568 smember = sp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
569 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
570 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
571 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
572 if (!cd && toParent() == smember.toParent())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
573 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
574 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
575 printf("\tyes 2\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
576 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
577 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
578 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
579 if (!cd && getModule() == smember.getModule())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
580 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
581 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
582 printf("\tyes 3\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
583 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
584 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
585 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
586 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
587 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
588 printf("\tno\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
589 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
590 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
591 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
592
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
593 /*******************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
594 * Do access check for member of this class, this class being the
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
595 * type of the 'this' pointer used to access smember.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
596 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
597 void accessCheck(Loc loc, Scope sc, Dsymbol smember)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
598 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
599 bool result;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
600
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
601 FuncDeclaration f = sc.func;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
602 AggregateDeclaration cdscope = sc.getStructClassScope();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
603 PROT access;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
604
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
605 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
606 printf("AggregateDeclaration.accessCheck() for %s.%s in function %s() in scope %s\n", toChars(), smember.toChars(), f ? f.toChars() : null, cdscope ? cdscope.toChars() : null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
607 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
608
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
609 Dsymbol smemberparent = smember.toParent();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
610 if (!smemberparent || !smemberparent.isAggregateDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
611 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
612 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
613 printf("not an aggregate member\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
614 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
615 return; // then it is accessible
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
616 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
617
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
618 // BUG: should enable this check
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
619 //assert(smember.parent.isBaseOf(this, null));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
620
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
621 if (smemberparent == this)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
622 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
623 PROT access2 = smember.prot();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
624
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
625 result = access2 >= PROT.PROTpublic ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
626 hasPrivateAccess(f) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
627 isFriendOf(cdscope) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
628 (access2 == PROT.PROTpackage && hasPackageAccess(sc, this));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
629
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
630 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
631 printf("result1 = %d\n", result);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
632 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
633 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
634 else if ((access = this.getAccess(smember)) >= PROT.PROTpublic)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
635 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
636 result = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
637 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
638 printf("result2 = %d\n", result);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
639 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
640 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
641 else if (access == PROT.PROTpackage && hasPackageAccess(sc, this))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
642 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
643 result = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
644 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
645 printf("result3 = %d\n", result);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
646 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
647 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
648 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
649 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
650 result = accessCheckX(smember, f, this, cdscope);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
651 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
652 printf("result4 = %d\n", result);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
653 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
654 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
655 if (!result)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
656 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
657 error(loc, "member %s is not accessible", smember.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
658 halt();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
659 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
660 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
661
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 16
diff changeset
662 override PROT prot()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
663 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
664 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
665 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
666
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
667 // Back end
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
668 Symbol* stag; // tag symbol for debug data
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
669 Symbol* sinit;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
670
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
671 Symbol* toInitializer()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
672 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
673 Symbol* s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
674 Classsym* stag;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
675
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
676 if (!sinit)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
677 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
678 stag = fake_classsym(Id.ClassInfo);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
679 s = toSymbolX("__init", SC.SCextern, stag.Stype, "Z");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
680 s.Sfl = FL.FLextern;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
681 s.Sflags |= SFL.SFLnodebug;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
682 slist_add(s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
683 sinit = s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
684 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
685
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
686 return sinit;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
687 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
688
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 16
diff changeset
689 override AggregateDeclaration isAggregateDeclaration() { return this; }
16
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
690 }