Mercurial > projects > ddmd
annotate dmd/Declaration.d @ 72:2e2a5c3f943a
reduced warnings by adding override to the methods
think this also normalizes different line endings used all over the place
author | Trass3r |
---|---|
date | Sat, 28 Aug 2010 16:19:48 +0200 |
parents | ee3a9f34dc48 |
children | 43073c7c7769 |
rev | line source |
---|---|
0 | 1 module dmd.Declaration; |
2 | |
3 import dmd.Dsymbol; | |
4 import dmd.Type; | |
5 import dmd.PROT; | |
6 import dmd.LINK; | |
7 import dmd.Identifier; | |
8 import dmd.Scope; | |
9 import dmd.Loc; | |
10 import dmd.STC; | |
11 import dmd.FuncDeclaration; | |
12 import dmd.VarDeclaration; | |
13 import dmd.OutBuffer; | |
14 | |
15 import std.stdio : writef; | |
16 | |
17 import core.stdc.ctype; | |
18 import core.stdc.stdio : sprintf; | |
19 | |
20 string mangle(Declaration sthis) | |
21 { | |
22 scope OutBuffer buf = new OutBuffer(); | |
23 | |
24 string id; | |
25 Dsymbol s = sthis; | |
26 | |
27 //printf(".mangle(%s)\n", sthis.toChars()); | |
28 do | |
29 { | |
30 //printf("mangle: s = %p, '%s', parent = %p\n", s, s.toChars(), s.parent); | |
31 if (s.ident) | |
32 { | |
33 FuncDeclaration fd = s.isFuncDeclaration(); | |
34 if (s !is sthis && fd) | |
35 { | |
36 id = mangle(fd); | |
37 buf.prependstring(id); | |
38 goto L1; | |
39 } | |
40 else | |
41 { | |
42 id = s.ident.toChars(); | |
43 int len = id.length; | |
44 char tmp[len.sizeof * 3 + 1]; | |
45 buf.prependstring(id); | |
46 len = sprintf(tmp.ptr, "%d".ptr, len); | |
47 buf.prependstring(tmp[0..len]); | |
48 } | |
49 } | |
50 else | |
51 buf.prependstring("0"); | |
52 s = s.parent; | |
53 } while (s); | |
54 | |
55 // buf.prependstring("_D"); | |
56 L1: | |
57 //printf("deco = '%s'\n", sthis.type.deco ? sthis.type.deco : "null"); | |
58 //printf("sthis.type = %s\n", sthis.type.toChars()); | |
59 FuncDeclaration fd = sthis.isFuncDeclaration(); | |
60 if (fd && (fd.needThis() || fd.isNested())) | |
61 buf.writeByte(Type.needThisPrefix()); | |
62 if (sthis.type.deco) | |
63 buf.writestring(sthis.type.deco); | |
64 else | |
65 { | |
66 debug { | |
67 if (!fd.inferRetType) | |
68 writef("%s\n", fd.toChars()); | |
69 } | |
70 assert(fd.inferRetType); | |
71 } | |
72 | |
73 id = buf.extractString(); | |
74 return id; | |
75 } | |
76 | |
77 class Declaration : Dsymbol | |
78 { | |
79 Type type; | |
80 Type originalType; // before semantic analysis | |
81 STC storage_class = STC.STCundefined; | |
82 PROT protection = PROT.PROTundefined; | |
83 LINK linkage = LINK.LINKdefault; | |
84 int inuse; // used to detect cycles | |
85 | |
86 this(Identifier id) | |
87 { | |
88 super(id); | |
89 } | |
90 | |
72 | 91 override void semantic(Scope sc) |
0 | 92 { |
93 } | |
94 | |
72 | 95 override string kind() |
0 | 96 { |
97 assert(false); | |
98 } | |
99 | |
72 | 100 override uint size(Loc loc) |
0 | 101 { |
102 assert(false); | |
103 } | |
104 | |
105 /************************************* | |
106 * Check to see if declaration can be modified in this context (sc). | |
107 * Issue error if not. | |
108 */ | |
109 void checkModify(Loc loc, Scope sc, Type t) | |
110 { | |
111 if (sc.incontract && isParameter()) | |
112 error(loc, "cannot modify parameter '%s' in contract", toChars()); | |
113 | |
114 if (isCtorinit()) | |
115 { | |
116 // It's only modifiable if inside the right constructor | |
117 Dsymbol s = sc.func; | |
118 while (true) | |
119 { | |
120 FuncDeclaration fd = null; | |
121 if (s) | |
122 fd = s.isFuncDeclaration(); | |
123 if (fd && ((fd.isCtorDeclaration() && storage_class & STC.STCfield) || | |
124 (fd.isStaticCtorDeclaration() && !(storage_class & STC.STCfield))) && | |
125 fd.toParent() == toParent() | |
126 ) | |
127 { | |
128 VarDeclaration v = isVarDeclaration(); | |
129 assert(v); | |
130 v.ctorinit = 1; | |
131 //printf("setting ctorinit\n"); | |
132 } | |
133 else | |
134 { | |
135 if (s) | |
136 { | |
137 s = s.toParent2(); | |
138 continue; | |
139 } | |
140 else | |
141 { | |
142 string p = isStatic() ? "static " : ""; | |
143 error(loc, "can only initialize %sconst %s inside %sconstructor", p, toChars(), p); | |
144 } | |
145 } | |
146 break; | |
147 } | |
148 } | |
149 else | |
150 { | |
151 VarDeclaration v = isVarDeclaration(); | |
152 if (v && v.canassign == 0) | |
153 { | |
154 string p = null; | |
155 if (isConst()) | |
156 p = "const"; | |
157 else if (isInvariant()) | |
158 p = "immutable"; | |
159 else if (storage_class & STC.STCmanifest) | |
160 p = "enum"; | |
161 else if (!t.isAssignable()) | |
162 p = "struct with immutable members"; | |
163 if (p) | |
164 { | |
165 error(loc, "cannot modify %s", p); | |
166 } | |
167 } | |
168 } | |
169 } | |
170 | |
72 | 171 override void emitComment(Scope sc) |
0 | 172 { |
173 assert(false); | |
174 } | |
175 | |
72 | 176 override void toDocBuffer(OutBuffer buf) |
0 | 177 { |
178 assert(false); | |
179 } | |
180 | |
72 | 181 override string mangle() |
14
2cc604139636
Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
182 /+out (result) |
0 | 183 { |
184 try | |
185 { | |
186 int len = result.length; | |
187 | |
188 assert(len > 0); | |
189 //printf("mangle: '%s' => '%s'\n", toChars(), result); | |
190 for (int i = 0; i < len; i++) | |
191 { | |
192 assert(result[i] == '_' || result[i] == '@' || isalnum(result[i]) || result[i] & 0x80); | |
193 } | |
194 } catch { | |
195 writef("Incorrect mangle: '%s'\n", result); | |
196 assert(false); | |
197 } | |
198 } | |
14
2cc604139636
Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
199 body+/ |
0 | 200 { |
22
fd4acc376c45
Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents:
16
diff
changeset
|
201 version(Bug3602) { writef( "Bug3602: Uncomment outblock when fixed\n" ); } |
0 | 202 //writef("Declaration.mangle(this = %p, '%s', parent = '%s', linkage = %d)\n", this, toChars(), parent ? parent.toChars() : "null", linkage); |
203 if (!parent || parent.isModule() || linkage == LINK.LINKcpp) // if at global scope | |
204 { | |
205 // If it's not a D declaration, no mangling | |
206 switch (linkage) | |
207 { | |
208 case LINK.LINKd: | |
209 break; | |
210 | |
211 case LINK.LINKc: | |
212 case LINK.LINKwindows: | |
213 case LINK.LINKpascal: | |
214 return ident.toChars(); | |
215 | |
216 case LINK.LINKcpp: | |
217 version (CPP_MANGLE) { | |
218 return cpp_mangle(this); | |
219 } else { | |
220 // Windows C++ mangling is done by C++ back end | |
221 return ident.toChars(); | |
222 } | |
223 | |
224 case LINK.LINKdefault: | |
225 assert(false); | |
226 error("forward declaration"); | |
227 return ident.toChars(); | |
228 | |
229 default: | |
230 writef("'%s', linkage = %d\n", toChars(), linkage); | |
231 assert(0); | |
232 } | |
233 } | |
234 | |
235 string p = .mangle(this); | |
236 scope OutBuffer buf = new OutBuffer(); | |
237 buf.writestring("_D"); | |
238 buf.writestring(p); | |
239 p = buf.toChars(); | |
240 buf.data = null; | |
241 //writef("Declaration.mangle(this = %p, '%s', parent = '%s', linkage = %d) = %s\n", this, toChars(), parent ? parent.toChars() : "null", linkage, p); | |
242 return p; | |
243 } | |
244 | |
245 int isStatic() { return storage_class & STC.STCstatic; } | |
246 | |
247 bool isStaticConstructor() | |
248 { | |
249 return false; | |
250 } | |
251 | |
252 bool isStaticDestructor() | |
253 { | |
254 return false; | |
255 } | |
256 | |
257 bool isDelete() | |
258 { | |
259 return false; | |
260 } | |
261 | |
262 bool isDataseg() | |
263 { | |
264 return false; | |
265 } | |
266 | |
267 bool isThreadlocal() | |
268 { | |
68
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
22
diff
changeset
|
269 return false; |
0 | 270 } |
271 | |
272 bool isCodeseg() | |
273 { | |
274 return false; | |
275 } | |
276 | |
277 int isCtorinit() { return storage_class & STC.STCctorinit; } | |
278 | |
279 int isFinal() { return storage_class & STC.STCfinal; } | |
280 | |
281 bool isAbstract() { return (storage_class & STC.STCabstract) != 0; } | |
282 | |
283 bool isConst() { return (storage_class & STC.STCconst) != 0; } | |
284 | |
285 int isInvariant() { return storage_class & STC.STCinvariant; } | |
286 | |
287 int isAuto() { return storage_class & STC.STCauto; } | |
288 | |
289 int isScope() { return storage_class & (STC.STCscope | STC.STCauto); } | |
290 | |
291 int isSynchronized() { return storage_class & STC.STCsynchronized; } | |
292 | |
293 int isParameter() { return storage_class & STC.STCparameter; } | |
294 | |
72 | 295 override bool isDeprecated() { return (storage_class & STC.STCdeprecated) != 0; } |
0 | 296 |
297 int isOverride() { return storage_class & STC.STCoverride; } | |
298 | |
299 int isIn() { return storage_class & STC.STCin; } | |
300 | |
301 int isOut() { return storage_class & STC.STCout; } | |
302 | |
303 int isRef() { return storage_class & STC.STCref; } | |
304 | |
72 | 305 override PROT prot() |
0 | 306 { |
307 return protection; | |
308 } | |
309 | |
72 | 310 override Declaration isDeclaration() { return this; } |
14
2cc604139636
Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
311 } |