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