Mercurial > projects > ddmd
annotate dmd/AttribDeclaration.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 | 206db751bd4c |
children | b0d41ff5e0df |
rev | line source |
---|---|
0 | 1 module dmd.AttribDeclaration; |
2 | |
114 | 3 import dmd.common; |
0 | 4 import dmd.Dsymbol; |
5 import dmd.Array; | |
6 import dmd.Scope; | |
7 import dmd.ScopeDsymbol; | |
8 import dmd.LINK; | |
9 import dmd.STC; | |
10 import dmd.PROT; | |
11 import dmd.ArrayTypes; | |
12 import dmd.OutBuffer; | |
13 import dmd.HdrGenState; | |
14 | |
15 class AttribDeclaration : Dsymbol | |
16 { | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
17 Dsymbols decl; // array of Dsymbol's |
0 | 18 |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
19 this(Dsymbols decl) |
0 | 20 { |
178 | 21 register(); |
22 | |
0 | 23 this.decl = decl; |
24 } | |
25 | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
26 Dsymbols include(Scope sc, ScopeDsymbol sd) |
0 | 27 { |
28 return decl; | |
29 } | |
30 | |
72 | 31 override bool addMember(Scope sc, ScopeDsymbol sd, bool memnum) |
0 | 32 { |
33 bool m = false; | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
34 auto d = include(sc, sd); |
0 | 35 |
36 if (d) | |
37 { | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
38 foreach(s; d) |
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
39 m |= s.addMember(sc, sd, m | memnum); |
0 | 40 } |
41 | |
42 return m; | |
43 } | |
44 | |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
45 void setScopeNewSc(Scope sc, StorageClass stc, LINK linkage, PROT protection, int explicitProtection, uint structalign) |
0 | 46 { |
47 if (decl) | |
48 { | |
49 Scope newsc = sc; | |
50 if (stc != sc.stc || linkage != sc.linkage || protection != sc.protection || explicitProtection != sc.explicitProtection || structalign != sc.structalign) | |
51 { | |
52 // create new one for changes | |
82 | 53 newsc = sc.clone(); |
0 | 54 newsc.flags &= ~SCOPE.SCOPEfree; |
55 newsc.stc = stc; | |
56 newsc.linkage = linkage; | |
57 newsc.protection = protection; | |
58 newsc.explicitProtection = explicitProtection; | |
59 newsc.structalign = structalign; | |
60 } | |
77
ad4792a1cfd6
more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
74
diff
changeset
|
61 foreach(Dsymbol s; decl) |
0 | 62 s.setScope(newsc); // yes, the only difference from semanticNewSc() |
63 if (newsc != sc) | |
64 { | |
65 sc.offset = newsc.offset; | |
66 newsc.pop(); | |
67 } | |
68 } | |
69 } | |
70 | |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
71 void semanticNewSc(Scope sc, StorageClass stc, LINK linkage, PROT protection, int explicitProtection, uint structalign) |
0 | 72 { |
73 if (decl) | |
74 { | |
75 Scope newsc = sc; | |
76 if (stc != sc.stc || linkage != sc.linkage || protection != sc.protection || explicitProtection != sc.explicitProtection || structalign != sc.structalign) | |
77 { | |
78 // create new one for changes | |
82 | 79 newsc = sc.clone(); |
0 | 80 newsc.flags &= ~SCOPE.SCOPEfree; |
81 newsc.stc = stc; | |
82 newsc.linkage = linkage; | |
83 newsc.protection = protection; | |
84 newsc.explicitProtection = explicitProtection; | |
85 newsc.structalign = structalign; | |
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 s.semantic(newsc); |
89 if (newsc != sc) | |
90 { | |
91 sc.offset = newsc.offset; | |
92 newsc.pop(); | |
93 } | |
94 } | |
95 } | |
96 | |
72 | 97 override void semantic(Scope sc) |
0 | 98 { |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
99 auto d = include(sc, null); |
0 | 100 |
101 //printf("\tAttribDeclaration::semantic '%s', d = %p\n",toChars(), d); | |
102 if (d) | |
103 { | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
104 foreach(s; d) |
0 | 105 s.semantic(sc); |
106 } | |
107 } | |
108 | |
72 | 109 override void semantic2(Scope sc) |
0 | 110 { |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
111 auto d = include(sc, null); |
0 | 112 |
113 if (d) | |
114 { | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
115 foreach(s; d) |
0 | 116 s.semantic2(sc); |
117 } | |
118 } | |
119 | |
72 | 120 override void semantic3(Scope sc) |
0 | 121 { |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
122 auto d = include(sc, null); |
0 | 123 |
124 if (d) | |
125 { | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
126 foreach(s; d) |
0 | 127 s.semantic3(sc); |
128 } | |
129 } | |
130 | |
72 | 131 override void inlineScan() |
0 | 132 { |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
133 auto d = include(null, null); |
0 | 134 |
135 if (d) | |
136 { | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
137 foreach(s; d) |
0 | 138 { |
139 //printf("AttribDeclaration.inlineScan %s\n", s.toChars()); | |
140 s.inlineScan(); | |
141 } | |
142 } | |
143 } | |
144 | |
79 | 145 override void addComment(string comment) |
0 | 146 { |
147 if (comment !is null) | |
148 { | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
149 auto d = include(null, null); |
0 | 150 if (d) |
151 { | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
152 foreach(s; d) |
0 | 153 { |
154 //printf("AttribDeclaration::addComment %s\n", s.toChars()); | |
155 s.addComment(comment); | |
156 } | |
157 } | |
158 } | |
159 } | |
160 | |
72 | 161 override void emitComment(Scope sc) |
0 | 162 { |
163 assert(false); | |
164 } | |
165 | |
72 | 166 override string kind() |
0 | 167 { |
168 assert(false); | |
169 } | |
170 | |
72 | 171 override bool oneMember(Dsymbol* ps) |
0 | 172 { |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
173 auto d = include(null, null); |
49 | 174 |
175 return Dsymbol.oneMembers(d, ps); | |
0 | 176 } |
177 | |
72 | 178 override bool hasPointers() |
0 | 179 { |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
180 auto d = include(null, null); |
0 | 181 |
182 if (d) | |
183 { | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
184 foreach(s; d) |
0 | 185 { |
186 if (s.hasPointers()) | |
187 return true; | |
188 } | |
189 } | |
190 | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
191 return false; |
0 | 192 } |
193 | |
72 | 194 override void checkCtorConstInit() |
0 | 195 { |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
196 auto d = include(null, null); |
0 | 197 if (d) |
198 { | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
199 foreach(s; d) |
0 | 200 s.checkCtorConstInit(); |
201 } | |
202 } | |
203 | |
72 | 204 override void addLocalClass(ClassDeclarations aclasses) |
0 | 205 { |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
206 auto d = include(null, null); |
0 | 207 if (d) |
208 { | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
209 foreach(s; d) |
0 | 210 s.addLocalClass(aclasses); |
211 } | |
212 } | |
213 | |
72 | 214 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 215 { |
216 assert(false); | |
217 } | |
79 | 218 |
219 override void toJsonBuffer(OutBuffer buf) | |
220 { | |
221 //writef("AttribDeclaration.toJsonBuffer()\n"); | |
222 | |
223 Dsymbols d = include(null, null); | |
224 | |
225 if (d) | |
226 { | |
227 foreach (Dsymbol s; d) | |
228 { | |
229 //writef("AttribDeclaration.toJsonBuffer %s\n", s.toChars()); | |
230 s.toJsonBuffer(buf); | |
231 } | |
232 } | |
233 } | |
234 | |
72 | 235 override AttribDeclaration isAttribDeclaration() { return this; } |
0 | 236 |
72 | 237 override void toObjFile(int multiobj) // compile to .obj file |
0 | 238 { |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
239 auto d = include(null, null); |
0 | 240 |
241 if (d) | |
242 { | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
243 foreach(s; d) |
0 | 244 s.toObjFile(multiobj); |
245 } | |
246 } | |
247 | |
72 | 248 override int cvMember(ubyte* p) |
0 | 249 { |
250 assert(false); | |
251 } | |
72 | 252 } |