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