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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 53
diff changeset
1 module dmd.AnonDeclaration;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 53
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 88
diff changeset
3 import dmd.common;
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 53
diff changeset
4 import dmd.OutBuffer;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 53
diff changeset
5 import dmd.Loc;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 53
diff changeset
6 import dmd.Scope;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 53
diff changeset
7 import dmd.Array;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 53
diff changeset
8 import dmd.AttribDeclaration;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 53
diff changeset
9 import dmd.HdrGenState;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.AggregateDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.AnonymousAggregateDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.STC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.Module;
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 53
diff changeset
15 import dmd.VarDeclaration;
169
e7769d53e750 Moves static variables from Module to Global
korDen
parents: 114
diff changeset
16 import dmd.Global;
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 53
diff changeset
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 class AnonDeclaration : AttribDeclaration
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 int isunion;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 int sem = 0; // 1 if successful semantic()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
29 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 super(decl);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 this.loc = loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 this.isunion = isunion;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 53
diff changeset
35 override Dsymbol syntaxCopy(Dsymbol s)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 53
diff changeset
37 AnonDeclaration ad;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 53
diff changeset
38
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 53
diff changeset
39 assert(!s);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 53
diff changeset
40 ad = new AnonDeclaration(loc, isunion, Dsymbol.arraySyntaxCopy(decl));
53
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 0
diff changeset
41 return ad;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 53
diff changeset
44 override void semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 //printf("\tAnonDeclaration::semantic %s %p\n", isunion ? "union" : "struct", this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 Scope scx = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 if (scope_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 sc = scope_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 scx = scope_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 scope_ = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 }
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
55
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
56 uint dprogress_save = global.dprogress;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 assert(sc.parent);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 Dsymbol parent = sc.parent.pastMixin();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 AggregateDeclaration ad = parent.isAggregateDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 if (!ad || (!ad.isStructDeclaration() && !ad.isClassDeclaration()))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 error("can only be a part of an aggregate");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 if (decl)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 AnonymousAggregateDeclaration aad = new AnonymousAggregateDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 int adisunion;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 if (sc.anonAgg)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 ad = sc.anonAgg;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 adisunion = sc.inunion;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 adisunion = ad.isUnionDeclaration() !is null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 // printf("\tsc.anonAgg = %p\n", sc.anonAgg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 // printf("\tad = %p\n", ad);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 // printf("\taad = %p\n", &aad);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 sc = sc.push();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 sc.anonAgg = aad;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 sc.stc &= ~(STCauto | STCscope | STCstatic | STCtls | STCgshared);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 sc.inunion = isunion;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 sc.offset = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 sc.flags = cast(SCOPE)0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 aad.structalign = sc.structalign;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 aad.parent = ad;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94
77
ad4792a1cfd6 more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 74
diff changeset
95 foreach(Dsymbol s; decl)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 s.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 if (isunion)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 sc.offset = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 if (aad.sizeok == 2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 sc = sc.pop();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 // If failed due to forward references, unwind and try again later
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 if (aad.sizeok == 2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 ad.sizeok = 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 //printf("\tsetting ad.sizeok %p to 2\n", ad);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 if (!sc.anonAgg)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 scope_.setNoFree();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 scope_.module_.addDeferredSemantic(this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 }
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
116 global.dprogress = dprogress_save;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 //printf("\tforward reference %p\n", this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 if (sem == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 {
169
e7769d53e750 Moves static variables from Module to Global
korDen
parents: 114
diff changeset
122 global.dprogress++;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 sem = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 //printf("\tcompleted %p\n", this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 ;//printf("\talready completed %p\n", this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 // 0 sized structs are set to 1 byte
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 if (aad.structsize == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 aad.structsize = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 aad.alignsize = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 // Align size of anonymous aggregate
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 //printf("aad.structalign = %d, aad.alignsize = %d, sc.offset = %d\n", aad.structalign, aad.alignsize, sc.offset);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 ad.alignmember(aad.structalign, aad.alignsize, &sc.offset);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 //ad.structsize = sc.offset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 //printf("sc.offset = %d\n", sc.offset);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 // Add members of aad to ad
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 //printf("\tadding members of aad to '%s'\n", ad.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 for (uint i = 0; i < aad.fields.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 {
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
147 auto v = aad.fields[i];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 v.offset += sc.offset;
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
150 ad.fields.push(v);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 // Add size of aad to ad
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 if (adisunion)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 if (aad.structsize > ad.structsize)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 ad.structsize = aad.structsize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 sc.offset = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 ad.structsize = sc.offset + aad.structsize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 sc.offset = ad.structsize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 if (ad.alignsize < aad.alignsize)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 ad.alignsize = aad.alignsize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 53
diff changeset
171 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 53
diff changeset
176 override string kind()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181