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