Mercurial > projects > ddmd
annotate dmd/AnonDeclaration.d @ 87:b17640f0e4e8
Fixed a bug with a Scope.this(Scope enclosing) being called instead of Scope.clone() method (as a copy ctor replacement)
author | korDen |
---|---|
date | Mon, 30 Aug 2010 19:56:27 +0400 |
parents | 43073c7c7769 |
children | 23280d154c5b |
rev | line source |
---|---|
72 | 1 module dmd.AnonDeclaration; |
2 | |
3 import dmd.OutBuffer; | |
4 import dmd.Loc; | |
5 import dmd.Scope; | |
6 import dmd.Array; | |
7 import dmd.AttribDeclaration; | |
8 import dmd.HdrGenState; | |
0 | 9 import dmd.Dsymbol; |
10 import dmd.AggregateDeclaration; | |
11 import dmd.AnonymousAggregateDeclaration; | |
12 import dmd.STC; | |
13 import dmd.Module; | |
72 | 14 import dmd.VarDeclaration; |
15 | |
0 | 16 class AnonDeclaration : AttribDeclaration |
17 { | |
18 int isunion; | |
19 int sem = 0; // 1 if successful semantic() | |
20 | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
21 this(Loc loc, int isunion, Dsymbols decl) |
0 | 22 { |
23 super(decl); | |
24 this.loc = loc; | |
25 this.isunion = isunion; | |
26 } | |
27 | |
72 | 28 override Dsymbol syntaxCopy(Dsymbol s) |
0 | 29 { |
72 | 30 AnonDeclaration ad; |
31 | |
32 assert(!s); | |
33 ad = new AnonDeclaration(loc, isunion, Dsymbol.arraySyntaxCopy(decl)); | |
53 | 34 return ad; |
0 | 35 } |
36 | |
72 | 37 override void semantic(Scope sc) |
0 | 38 { |
39 //printf("\tAnonDeclaration::semantic %s %p\n", isunion ? "union" : "struct", this); | |
40 | |
41 Scope scx = null; | |
42 if (scope_) | |
43 { | |
44 sc = scope_; | |
45 scx = scope_; | |
46 scope_ = null; | |
47 } | |
48 | |
49 assert(sc.parent); | |
50 | |
51 Dsymbol parent = sc.parent.pastMixin(); | |
52 AggregateDeclaration ad = parent.isAggregateDeclaration(); | |
53 | |
54 if (!ad || (!ad.isStructDeclaration() && !ad.isClassDeclaration())) | |
55 { | |
56 error("can only be a part of an aggregate"); | |
57 return; | |
58 } | |
59 | |
60 if (decl) | |
61 { | |
62 AnonymousAggregateDeclaration aad = new AnonymousAggregateDeclaration(); | |
63 int adisunion; | |
64 | |
65 if (sc.anonAgg) | |
66 { | |
67 ad = sc.anonAgg; | |
68 adisunion = sc.inunion; | |
69 } | |
70 else | |
71 adisunion = ad.isUnionDeclaration() !is null; | |
72 | |
73 // printf("\tsc.anonAgg = %p\n", sc.anonAgg); | |
74 // printf("\tad = %p\n", ad); | |
75 // printf("\taad = %p\n", &aad); | |
76 | |
77 sc = sc.push(); | |
78 sc.anonAgg = aad; | |
79 sc.stc &= ~(STCauto | STCscope | STCstatic | STCtls | STCgshared); | |
80 sc.inunion = isunion; | |
81 sc.offset = 0; | |
82 sc.flags = cast(SCOPE)0; | |
83 aad.structalign = sc.structalign; | |
84 aad.parent = ad; | |
85 | |
77
ad4792a1cfd6
more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
74
diff
changeset
|
86 foreach(Dsymbol s; decl) |
0 | 87 { |
88 s.semantic(sc); | |
89 if (isunion) | |
90 sc.offset = 0; | |
91 if (aad.sizeok == 2) | |
92 break; | |
93 } | |
94 sc = sc.pop(); | |
95 | |
96 // If failed due to forward references, unwind and try again later | |
97 if (aad.sizeok == 2) | |
98 { | |
99 ad.sizeok = 2; | |
100 //printf("\tsetting ad.sizeok %p to 2\n", ad); | |
101 if (!sc.anonAgg) | |
102 { | |
87
b17640f0e4e8
Fixed a bug with a Scope.this(Scope enclosing) being called instead of Scope.clone() method (as a copy ctor replacement)
korDen
parents:
79
diff
changeset
|
103 scope_ = scx ? scx : sc.clone(); |
0 | 104 scope_.setNoFree(); |
105 scope_.module_.addDeferredSemantic(this); | |
106 } | |
107 //printf("\tforward reference %p\n", this); | |
108 return; | |
109 } | |
110 if (sem == 0) | |
111 { | |
112 Module.dprogress++; | |
113 sem = 1; | |
114 //printf("\tcompleted %p\n", this); | |
115 } | |
116 else { | |
117 ;//printf("\talready completed %p\n", this); | |
118 } | |
119 | |
120 // 0 sized structs are set to 1 byte | |
121 if (aad.structsize == 0) | |
122 { | |
123 aad.structsize = 1; | |
124 aad.alignsize = 1; | |
125 } | |
126 | |
127 // Align size of anonymous aggregate | |
128 //printf("aad.structalign = %d, aad.alignsize = %d, sc.offset = %d\n", aad.structalign, aad.alignsize, sc.offset); | |
129 ad.alignmember(aad.structalign, aad.alignsize, &sc.offset); | |
130 //ad.structsize = sc.offset; | |
131 //printf("sc.offset = %d\n", sc.offset); | |
132 | |
133 // Add members of aad to ad | |
134 //printf("\tadding members of aad to '%s'\n", ad.toChars()); | |
135 for (uint i = 0; i < aad.fields.dim; i++) | |
136 { | |
79 | 137 VarDeclaration v = cast(VarDeclaration)aad.fields[i]; |
0 | 138 |
139 v.offset += sc.offset; | |
79 | 140 ad.fields.push(v); |
0 | 141 } |
142 | |
143 // Add size of aad to ad | |
144 if (adisunion) | |
145 { | |
146 if (aad.structsize > ad.structsize) | |
147 ad.structsize = aad.structsize; | |
148 sc.offset = 0; | |
149 } | |
150 else | |
151 { | |
152 ad.structsize = sc.offset + aad.structsize; | |
153 sc.offset = ad.structsize; | |
154 } | |
155 | |
156 if (ad.alignsize < aad.alignsize) | |
157 ad.alignsize = aad.alignsize; | |
158 } | |
159 } | |
160 | |
72 | 161 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 162 { |
163 assert(false); | |
164 } | |
165 | |
72 | 166 override string kind() |
0 | 167 { |
168 assert(false); | |
169 } | |
170 } | |
171 |