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