annotate dmd/AnonDeclaration.d @ 178:e3afd1303184

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