Mercurial > projects > ddmd
annotate dmd/Dsymbol.d @ 137:09c858522d55
merge
author | Trass3r |
---|---|
date | Mon, 13 Sep 2010 23:29:00 +0200 |
parents | 010eb8f0e18d |
children | e3afd1303184 |
rev | line source |
---|---|
0 | 1 module dmd.Dsymbol; |
2 | |
114 | 3 import dmd.common; |
0 | 4 import dmd.Loc; |
5 import dmd.STC; | |
6 import dmd.Scope; | |
7 import dmd.Lexer; | |
8 import dmd.Module; | |
9 import dmd.Array; | |
10 import dmd.ScopeDsymbol; | |
11 import dmd.OutBuffer; | |
12 import dmd.Id; | |
13 import dmd.Identifier; | |
14 import dmd.TemplateInstance; | |
15 import dmd.HdrGenState; | |
16 import dmd.AggregateDeclaration; | |
17 import dmd.ClassDeclaration; | |
18 import dmd.LabelDsymbol; | |
19 import dmd.Type; | |
20 import dmd.PROT; | |
21 import dmd.ArrayTypes; | |
22 import dmd.Package; | |
23 import dmd.EnumMember; | |
24 import dmd.TemplateDeclaration; | |
25 import dmd.TemplateMixin; | |
26 import dmd.Declaration; | |
27 import dmd.ThisDeclaration; | |
28 import dmd.TupleDeclaration; | |
29 import dmd.TypedefDeclaration; | |
30 import dmd.AliasDeclaration; | |
31 import dmd.FuncDeclaration; | |
32 import dmd.FuncAliasDeclaration; | |
33 import dmd.FuncLiteralDeclaration; | |
34 import dmd.CtorDeclaration; | |
35 import dmd.PostBlitDeclaration; | |
36 import dmd.DtorDeclaration; | |
37 import dmd.StaticCtorDeclaration; | |
38 import dmd.StaticDtorDeclaration; | |
39 import dmd.InvariantDeclaration; | |
40 import dmd.UnitTestDeclaration; | |
41 import dmd.NewDeclaration; | |
42 import dmd.VarDeclaration; | |
43 import dmd.StructDeclaration; | |
44 import dmd.UnionDeclaration; | |
45 import dmd.InterfaceDeclaration; | |
46 import dmd.WithScopeSymbol; | |
47 import dmd.ArrayScopeSymbol; | |
48 import dmd.Import; | |
49 import dmd.EnumDeclaration; | |
50 import dmd.DeleteDeclaration; | |
51 import dmd.SymbolDeclaration; | |
52 import dmd.AttribDeclaration; | |
53 import dmd.OverloadSet; | |
54 import dmd.DYNCAST; | |
55 import dmd.Global; | |
56 import dmd.Expression; | |
57 import dmd.TOK; | |
58 import dmd.VarExp; | |
59 import dmd.FuncExp; | |
60 | |
61 import dmd.backend.Symbol; | |
62 import dmd.backend.TYPE; | |
63 import dmd.backend.Util; | |
64 import dmd.backend.mTYman; | |
65 import dmd.backend.TYFL; | |
66 import dmd.backend.TYM; | |
67 import dmd.backend.mTY; | |
68 import dmd.backend.SC; | |
69 import dmd.backend.FL; | |
70 import dmd.backend.LIST; | |
99 | 71 public import dmd.PASS; |
0 | 72 |
73 import core.stdc.string : strcmp, memcpy, strlen; | |
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
|
74 version (Bug4054) import core.memory; |
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
|
75 else import core.stdc.stdlib : alloca; |
0 | 76 |
77 import std.stdio; | |
78 | |
79 // TODO: remove dependencies on these | |
80 Expression isExpression(Object o) | |
81 { | |
82 return cast(Expression)o; | |
83 } | |
84 | |
85 Dsymbol isDsymbol(Object o) | |
86 { | |
87 return cast(Dsymbol)o; | |
88 } | |
89 | |
90 Type isType(Object o) | |
91 { | |
92 return cast(Type)o; | |
93 } | |
94 | |
17
ddae60498573
Implemented mixin statements, DefaultInitExps, FileInitExps, LineInitExps and __traits.
Robert Clipsham <robert@octarineparrot.com>
parents:
14
diff
changeset
|
95 /*********************** |
ddae60498573
Implemented mixin statements, DefaultInitExps, FileInitExps, LineInitExps and __traits.
Robert Clipsham <robert@octarineparrot.com>
parents:
14
diff
changeset
|
96 * Try to get arg as a type. |
ddae60498573
Implemented mixin statements, DefaultInitExps, FileInitExps, LineInitExps and __traits.
Robert Clipsham <robert@octarineparrot.com>
parents:
14
diff
changeset
|
97 */ |
ddae60498573
Implemented mixin statements, DefaultInitExps, FileInitExps, LineInitExps and __traits.
Robert Clipsham <robert@octarineparrot.com>
parents:
14
diff
changeset
|
98 |
ddae60498573
Implemented mixin statements, DefaultInitExps, FileInitExps, LineInitExps and __traits.
Robert Clipsham <robert@octarineparrot.com>
parents:
14
diff
changeset
|
99 Type getType(Object o) |
ddae60498573
Implemented mixin statements, DefaultInitExps, FileInitExps, LineInitExps and __traits.
Robert Clipsham <robert@octarineparrot.com>
parents:
14
diff
changeset
|
100 { |
ddae60498573
Implemented mixin statements, DefaultInitExps, FileInitExps, LineInitExps and __traits.
Robert Clipsham <robert@octarineparrot.com>
parents:
14
diff
changeset
|
101 Type t = isType(o); |
ddae60498573
Implemented mixin statements, DefaultInitExps, FileInitExps, LineInitExps and __traits.
Robert Clipsham <robert@octarineparrot.com>
parents:
14
diff
changeset
|
102 if (!t) |
ddae60498573
Implemented mixin statements, DefaultInitExps, FileInitExps, LineInitExps and __traits.
Robert Clipsham <robert@octarineparrot.com>
parents:
14
diff
changeset
|
103 { Expression e = isExpression(o); |
ddae60498573
Implemented mixin statements, DefaultInitExps, FileInitExps, LineInitExps and __traits.
Robert Clipsham <robert@octarineparrot.com>
parents:
14
diff
changeset
|
104 if (e) |
ddae60498573
Implemented mixin statements, DefaultInitExps, FileInitExps, LineInitExps and __traits.
Robert Clipsham <robert@octarineparrot.com>
parents:
14
diff
changeset
|
105 t = e.type; |
ddae60498573
Implemented mixin statements, DefaultInitExps, FileInitExps, LineInitExps and __traits.
Robert Clipsham <robert@octarineparrot.com>
parents:
14
diff
changeset
|
106 } |
ddae60498573
Implemented mixin statements, DefaultInitExps, FileInitExps, LineInitExps and __traits.
Robert Clipsham <robert@octarineparrot.com>
parents:
14
diff
changeset
|
107 return t; |
ddae60498573
Implemented mixin statements, DefaultInitExps, FileInitExps, LineInitExps and __traits.
Robert Clipsham <robert@octarineparrot.com>
parents:
14
diff
changeset
|
108 } |
ddae60498573
Implemented mixin statements, DefaultInitExps, FileInitExps, LineInitExps and __traits.
Robert Clipsham <robert@octarineparrot.com>
parents:
14
diff
changeset
|
109 |
ddae60498573
Implemented mixin statements, DefaultInitExps, FileInitExps, LineInitExps and __traits.
Robert Clipsham <robert@octarineparrot.com>
parents:
14
diff
changeset
|
110 |
0 | 111 Dsymbol getDsymbol(Object oarg) |
112 { | |
113 Dsymbol sa; | |
114 Expression ea = isExpression(oarg); | |
115 if (ea) | |
116 { // Try to convert Expression to symbol | |
117 if (ea.op == TOK.TOKvar) | |
118 sa = (cast(VarExp)ea).var; | |
119 else if (ea.op == TOK.TOKfunction) | |
120 sa = (cast(FuncExp)ea).fd; | |
121 else | |
122 sa = null; | |
123 } | |
124 else | |
125 { // Try to convert Type to symbol | |
126 Type ta = isType(oarg); | |
127 if (ta) | |
128 sa = ta.toDsymbol(null); | |
129 else | |
130 sa = isDsymbol(oarg); // if already a symbol | |
131 } | |
132 return sa; | |
133 } | |
134 | |
79 | 135 alias Vector!Dsymbol Dsymbols; |
136 | |
0 | 137 class Dsymbol |
138 { | |
139 Identifier ident; | |
140 Identifier c_ident; | |
141 Dsymbol parent; | |
142 Symbol* csym; // symbol for code generator | |
143 Symbol* isym; // import version of csym | |
79 | 144 string comment; // documentation comment for this Dsymbol |
0 | 145 Loc loc; // where defined |
146 Scope scope_; // !=null means context to use for semantic() | |
147 | |
148 this() | |
149 { | |
150 // do nothing | |
151 } | |
152 | |
153 this(Identifier ident) | |
154 { | |
155 this.ident = ident; | |
156 } | |
157 | |
158 string toChars() | |
159 { | |
160 return ident ? ident.toChars() : "__anonymous"; | |
161 } | |
162 | |
163 string locToChars() | |
164 { | |
165 scope OutBuffer buf = new OutBuffer(); | |
166 Module m = getModule(); | |
167 | |
168 if (m && m.srcfile) | |
169 loc.filename = m.srcfile.toChars(); | |
170 | |
171 return loc.toChars(); | |
172 } | |
173 | |
45 | 174 bool equals(Object o) |
0 | 175 { |
58 | 176 Dsymbol s; |
177 | |
178 if (this is o) | |
179 return true; | |
180 | |
181 s = cast(Dsymbol)(o); | |
182 if (s && ident.equals(s.ident)) | |
183 return true; | |
184 | |
185 return false; | |
0 | 186 } |
187 | |
188 bool isAnonymous() | |
189 { | |
190 return ident ? 0 : 1; | |
191 } | |
192 | |
193 void error(T...)(Loc loc, string format, T t) | |
194 { | |
195 if (!global.gag) | |
196 { | |
197 string p = loc.toChars(); | |
198 if (p.length == 0) | |
199 p = locToChars(); | |
200 | |
201 if (p.length != 0) { | |
202 writef("%s: ", p); | |
203 } | |
204 | |
205 write("Error: "); | |
206 writef("%s %s ", kind(), toPrettyChars()); | |
207 | |
208 writefln(format, t); | |
209 } | |
210 | |
211 global.errors++; | |
212 | |
213 //fatal(); | |
214 } | |
215 | |
216 void error(T...)(string format, T t) | |
217 { | |
218 //printf("Dsymbol.error()\n"); | |
219 if (!global.gag) | |
220 { | |
221 string p = loc.toChars(); | |
222 | |
223 if (p.length != 0) { | |
224 writef("%s: ", p); | |
225 } | |
226 | |
227 write("Error: "); | |
228 if (isAnonymous()) { | |
229 writef("%s ", kind()); | |
230 } else { | |
231 writef("%s %s ", kind(), toPrettyChars()); | |
232 } | |
233 | |
234 writefln(format, t); | |
235 } | |
236 global.errors++; | |
237 | |
238 //fatal(); | |
239 } | |
240 | |
241 void checkDeprecated(Loc loc, Scope sc) | |
242 { | |
243 if (!global.params.useDeprecated && isDeprecated()) | |
244 { | |
245 // Don't complain if we're inside a deprecated symbol's scope | |
246 for (Dsymbol sp = sc.parent; sp; sp = sp.parent) | |
247 { | |
248 if (sp.isDeprecated()) | |
249 return; | |
250 } | |
251 | |
252 for (; sc; sc = sc.enclosing) | |
253 { | |
254 if (sc.scopesym && sc.scopesym.isDeprecated()) | |
255 return; | |
256 | |
257 // If inside a StorageClassDeclaration that is deprecated | |
258 if (sc.stc & STC.STCdeprecated) | |
259 return; | |
260 } | |
261 | |
262 error(loc, "is deprecated"); | |
263 } | |
264 } | |
265 | |
266 Module getModule() | |
267 { | |
268 //printf("Dsymbol.getModule()\n"); | |
269 Dsymbol s = this; | |
270 while (s) | |
271 { | |
272 //printf("\ts = '%s'\n", s.toChars()); | |
273 Module m = s.isModule(); | |
274 if (m) | |
275 return m; | |
276 s = s.parent; | |
277 } | |
278 | |
279 return null; | |
280 } | |
281 | |
282 Dsymbol pastMixin() | |
283 { | |
284 Dsymbol s = this; | |
285 //printf("Dsymbol::pastMixin() %s\n", toChars()); | |
286 while (s && s.isTemplateMixin()) | |
287 s = s.parent; | |
288 return s; | |
289 } | |
290 | |
291 Dsymbol toParent() | |
292 { | |
293 return parent ? parent.pastMixin() : null; | |
294 } | |
295 | |
296 /********************************** | |
297 * Use this instead of toParent() when looking for the | |
298 * 'this' pointer of the enclosing function/class. | |
299 */ | |
300 Dsymbol toParent2() | |
301 { | |
302 Dsymbol s = parent; | |
303 while (s && s.isTemplateInstance()) | |
304 s = s.parent; | |
305 return s; | |
306 } | |
307 | |
308 TemplateInstance inTemplateInstance() | |
309 { | |
310 for (Dsymbol parent = this.parent; parent; parent = parent.parent) | |
311 { | |
312 TemplateInstance ti = parent.isTemplateInstance(); | |
313 if (ti) | |
314 return ti; | |
315 } | |
316 | |
317 return null; | |
318 } | |
319 | |
320 DYNCAST dyncast() { return DYNCAST.DYNCAST_DSYMBOL; } // kludge for template.isSymbol() | |
321 | |
322 /************************************* | |
323 * Do syntax copy of an array of Dsymbol's. | |
324 */ | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
73
diff
changeset
|
325 static Vector!Dsymbol arraySyntaxCopy(Vector!Dsymbol a) |
0 | 326 { |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
73
diff
changeset
|
327 Vector!Dsymbol b = null; |
0 | 328 if (a) |
329 { | |
330 b = a.copy(); | |
331 for (int i = 0; i < b.dim; i++) | |
332 { | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
73
diff
changeset
|
333 auto s = b[i]; |
0 | 334 |
335 s = s.syntaxCopy(null); | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
73
diff
changeset
|
336 b[i] = s; |
0 | 337 } |
338 } | |
339 return b; | |
340 } | |
341 | |
342 string toPrettyChars() | |
343 { | |
344 //printf("Dsymbol.toPrettyChars() '%s'\n", toChars()); | |
345 if (!parent) { | |
346 return toChars(); | |
347 } | |
348 | |
349 size_t len = 0; | |
350 for (Dsymbol p = this; p; p = p.parent) { | |
351 len += p.toChars().length + 1; | |
352 } | |
353 --len; | |
354 | |
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
|
355 version (Bug4054) |
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
|
356 char* s = cast(char*)GC.malloc(len); |
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
|
357 else |
0 | 358 char* s = cast(char*)alloca(len); |
359 char* q = s + len; | |
360 | |
361 for (Dsymbol p = this; p; p = p.parent) | |
362 { | |
363 string t = p.toChars(); | |
364 size_t length = t.length; | |
365 q -= length; | |
366 | |
367 memcpy(q, t.ptr, length); | |
368 if (q is s) | |
369 break; | |
370 | |
371 q--; | |
372 version (TARGET_NET) { | |
373 if (AggregateDeclaration ad = p.isAggregateDeclaration()) | |
374 { | |
375 if (ad.isNested() && p.parent && p.parent.isAggregateDeclaration()) | |
376 { | |
377 *q = '/'; | |
378 continue; | |
379 } | |
380 } | |
381 } | |
382 *q = '.'; | |
383 } | |
384 | |
385 return s[0..len].idup; | |
386 } | |
387 | |
388 string kind() | |
389 { | |
390 assert(false); | |
391 } | |
392 | |
393 /********************************* | |
394 * If this symbol is really an alias for another, | |
395 * return that other. | |
396 */ | |
397 Dsymbol toAlias() // resolve real symbol | |
398 { | |
399 return this; | |
400 } | |
401 | |
13 | 402 bool addMember(Scope sc, ScopeDsymbol sd, bool memnum) |
0 | 403 { |
404 //printf("Dsymbol.addMember('%s')\n", toChars()); | |
405 //printf("Dsymbol.addMember(this = %p, '%s' scopesym = '%s')\n", this, toChars(), sd.toChars()); | |
406 assert(sd !is null); | |
407 parent = sd; | |
408 if (!isAnonymous()) // no name, so can't add it to symbol table | |
409 { | |
79 | 410 if (!sd.symtabInsert(this)) // if name is already defined |
0 | 411 { |
412 Dsymbol s2 = sd.symtab.lookup(ident); | |
413 if (!s2.overloadInsert(this)) | |
414 { | |
415 sd.multiplyDefined(Loc(0), this, s2); | |
416 } | |
417 } | |
418 if (sd.isAggregateDeclaration() || sd.isEnumDeclaration()) | |
419 { | |
420 if (ident is Id.__sizeof || ident is Id.alignof_ || ident is Id.mangleof_) | |
421 error(".%s property cannot be redefined", ident.toChars()); | |
422 } | |
423 return true; | |
424 } | |
425 | |
426 return false; | |
427 } | |
428 | |
429 void setScope(Scope sc) | |
430 { | |
431 //printf("Dsymbol.setScope() %p %s\n", this, toChars()); | |
432 if (!sc.nofree) | |
433 sc.setNoFree(); // may need it even after semantic() finishes | |
434 scope_ = sc; | |
435 } | |
79 | 436 |
437 void importAll(Scope sc) | |
438 { | |
439 } | |
0 | 440 |
441 void semantic(Scope sc) | |
442 { | |
79 | 443 error("%p has no semantic routine", this); |
0 | 444 } |
445 | |
446 /************************************* | |
447 * Does semantic analysis on initializers and members of aggregates. | |
448 */ | |
449 void semantic2(Scope sc) | |
450 { | |
451 // Most Dsymbols have no further semantic analysis needed | |
452 } | |
453 | |
454 /************************************* | |
455 * Does semantic analysis on function bodies. | |
456 */ | |
457 void semantic3(Scope sc) | |
458 { | |
459 // Most Dsymbols have no further semantic analysis needed | |
460 } | |
461 | |
462 /************************************* | |
463 * Look for function inlining possibilities. | |
464 */ | |
465 void inlineScan() | |
466 { | |
467 // Most Dsymbols aren't functions | |
468 } | |
469 | |
50 | 470 /********************************************* |
471 * Search for ident as member of s. | |
472 * Input: | |
473 * flags: 1 don't find private members | |
474 * 2 don't give error messages | |
475 * 4 return null if ambiguous | |
476 * Returns: | |
477 * null if not found | |
478 */ | |
0 | 479 Dsymbol search(Loc loc, Identifier ident, int flags) |
480 { | |
50 | 481 //printf("Dsymbol.search(this=%p,%s, ident='%s')\n", this, toChars(), ident.toChars()); |
482 return null; | |
0 | 483 } |
484 | |
485 /*************************************** | |
486 * Search for identifier id as a member of 'this'. | |
487 * id may be a template instance. | |
488 * Returns: | |
489 * symbol found, null if not | |
490 */ | |
56 | 491 Dsymbol searchX(Loc loc, Scope sc, Object o) |
0 | 492 { |
493 //printf("Dsymbol::searchX(this=%p,%s, ident='%s')\n", this, toChars(), ident.toChars()); | |
494 Dsymbol s = toAlias(); | |
495 Dsymbol sm; | |
496 | |
56 | 497 if (auto ident = cast(Identifier)o) |
498 { | |
499 sm = s.search(loc, ident, 0); | |
500 } | |
501 else if (auto st = cast(Dsymbol)o) | |
0 | 502 { |
56 | 503 // It's a template instance |
504 //printf("\ttemplate instance id\n"); | |
505 TemplateInstance ti = st.isTemplateInstance(); | |
506 Identifier id = ti.name; | |
507 sm = s.search(loc, cast(Identifier)id, 0); | |
508 if (!sm) | |
509 { | |
510 error("template identifier %s is not a member of %s %s", id.toChars(), s.kind(), s.toChars()); | |
511 return null; | |
512 } | |
513 sm = sm.toAlias(); | |
514 TemplateDeclaration td = sm.isTemplateDeclaration(); | |
515 if (!td) | |
516 { | |
517 error("%s is not a template, it is a %s", id.toChars(), sm.kind()); | |
518 return null; | |
0 | 519 } |
520 | |
56 | 521 ti.tempdecl = td; |
522 if (!ti.semanticRun) | |
523 ti.semantic(sc); | |
524 | |
525 sm = ti.toAlias(); | |
526 } | |
527 else | |
528 { | |
529 assert(0); | |
0 | 530 } |
531 return sm; | |
532 } | |
533 | |
534 bool overloadInsert(Dsymbol s) | |
535 { | |
536 assert(false); | |
537 } | |
538 | |
79 | 539 version (_DH) |
540 { | |
0 | 541 char* toHChars() |
542 { | |
543 assert(false); | |
544 } | |
545 | |
546 void toHBuffer(OutBuffer buf, HdrGenState* hgs) | |
547 { | |
548 assert(false); | |
549 } | |
550 } | |
551 void toCBuffer(OutBuffer buf, HdrGenState* hgs) | |
552 { | |
553 assert(false); | |
554 } | |
555 | |
556 void toDocBuffer(OutBuffer buf) | |
557 { | |
558 assert(false); | |
559 } | |
79 | 560 |
561 void toJsonBuffer(OutBuffer buf) | |
562 { | |
563 } | |
0 | 564 |
565 uint size(Loc loc) | |
566 { | |
567 assert(false); | |
568 } | |
569 | |
570 int isforwardRef() | |
571 { | |
572 assert(false); | |
573 } | |
574 | |
575 void defineRef(Dsymbol s) | |
576 { | |
577 assert(false); | |
578 } | |
579 | |
580 AggregateDeclaration isThis() // is a 'this' required to access the member | |
581 { | |
129 | 582 return null; |
0 | 583 } |
584 | |
585 ClassDeclaration isClassMember() // are we a member of a class? | |
586 { | |
587 Dsymbol parent = toParent(); | |
588 if (parent && parent.isClassDeclaration()) | |
589 return cast(ClassDeclaration)parent; | |
590 return null; | |
591 } | |
592 | |
593 bool isExport() // is Dsymbol exported? | |
594 { | |
595 return false; | |
596 } | |
597 | |
598 bool isImportedSymbol() // is Dsymbol imported? | |
599 { | |
600 return false; | |
601 } | |
602 | |
603 bool isDeprecated() // is Dsymbol deprecated? | |
604 { | |
605 return false; | |
606 } | |
607 | |
608 version (DMDV2) { | |
609 bool isOverloadable() | |
610 { | |
611 return false; | |
612 } | |
613 } | |
614 | |
615 LabelDsymbol isLabel() // is this a LabelDsymbol? | |
616 { | |
617 return null; | |
618 } | |
619 | |
620 AggregateDeclaration isMember() // is this symbol a member of an AggregateDeclaration? | |
621 { | |
622 //printf("Dsymbol::isMember() %s\n", toChars()); | |
623 Dsymbol parent = toParent(); | |
624 //printf("parent is %s %s\n", parent.kind(), parent.toChars()); | |
625 return parent ? parent.isAggregateDeclaration() : null; | |
626 } | |
627 | |
628 Type getType() // is this a type? | |
629 { | |
630 return null; | |
631 } | |
632 | |
633 string mangle() | |
634 { | |
635 OutBuffer buf = new OutBuffer(); | |
636 string id; | |
637 | |
638 static if (false) { | |
639 printf("Dsymbol::mangle() '%s'", toChars()); | |
640 if (parent) | |
641 printf(" parent = %s %s", parent.kind(), parent.toChars()); | |
642 printf("\n"); | |
643 } | |
644 id = ident ? ident.toChars() : toChars(); | |
645 if (parent) | |
646 { | |
647 string p = parent.mangle(); | |
648 if (p[0] == '_' && p[1] == 'D') | |
649 p = p[2..$]; | |
650 buf.writestring(p); | |
651 } | |
652 ///buf.printf("%zu%s", id.length, id); | |
653 buf.printf("%d%s", id.length, id); | |
654 id = buf.toChars(); | |
655 buf.data = null; | |
656 //printf("Dsymbol::mangle() %s = %s\n", toChars(), id); | |
657 return id; | |
658 } | |
659 | |
660 bool needThis() // need a 'this' pointer? | |
661 { | |
662 return false; | |
663 } | |
664 | |
665 PROT prot() | |
666 { | |
667 assert(false); | |
668 } | |
669 | |
670 Dsymbol syntaxCopy(Dsymbol s) // copy only syntax trees | |
671 { | |
672 assert(false); | |
673 } | |
674 | |
675 /************************************** | |
676 * Determine if this symbol is only one. | |
677 * Returns: | |
678 * false, *ps = null: There are 2 or more symbols | |
679 * true, *ps = null: There are zero symbols | |
680 * true, *ps = symbol: The one and only one symbol | |
681 */ | |
682 bool oneMember(Dsymbol* ps) | |
683 { | |
684 //printf("Dsymbol::oneMember()\n"); | |
685 *ps = this; | |
686 return true; | |
687 } | |
688 | |
689 /***************************************** | |
690 * Same as Dsymbol::oneMember(), but look at an array of Dsymbols. | |
691 */ | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
73
diff
changeset
|
692 static bool oneMembers(Dsymbols members, Dsymbol* ps) |
0 | 693 { |
694 //printf("Dsymbol::oneMembers() %d\n", members ? members->dim : 0); | |
695 Dsymbol s = null; | |
696 | |
697 if (members) | |
698 { | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
73
diff
changeset
|
699 foreach(sx; members) |
0 | 700 { |
701 bool x = sx.oneMember(ps); | |
702 //printf("\t[%d] kind %s = %d, s = %p\n", i, sx->kind(), x, *ps); | |
703 if (!x) | |
704 { | |
705 //printf("\tfalse 1\n"); | |
706 assert(*ps is null); | |
707 return false; | |
708 } | |
709 if (*ps) | |
710 { | |
711 if (s) // more than one symbol | |
712 { | |
713 *ps = null; | |
714 //printf("\tfalse 2\n"); | |
715 return false; | |
716 } | |
717 s = *ps; | |
718 } | |
719 } | |
720 } | |
721 | |
722 *ps = s; // s is the one symbol, null if none | |
723 //printf("\ttrue\n"); | |
724 return true; | |
725 } | |
726 | |
727 /***************************************** | |
728 * Is Dsymbol a variable that contains pointers? | |
729 */ | |
730 bool hasPointers() | |
731 { | |
732 //printf("Dsymbol::hasPointers() %s\n", toChars()); | |
733 return 0; | |
734 } | |
735 | |
736 void addLocalClass(ClassDeclarations) { } | |
737 void checkCtorConstInit() { } | |
738 | |
79 | 739 // since comment is stored immutable string is correct here |
740 void addComment(string comment) | |
0 | 741 { |
742 //if (comment) | |
79 | 743 //writef("adding comment '%s' to symbol %p '%s'\n", comment, this, toChars()); |
0 | 744 |
79 | 745 if (this.comment is null) |
746 { | |
0 | 747 this.comment = comment; |
79 | 748 } |
749 else | |
750 { | |
751 static if (true) | |
752 { | |
753 if (comment !is null && comment != this.comment) | |
0 | 754 { // Concatenate the two |
755 this.comment = Lexer.combineComments(this.comment, comment); | |
756 } | |
757 } | |
758 } | |
759 } | |
760 | |
761 void emitComment(Scope sc) | |
762 { | |
763 assert(false); | |
764 } | |
765 | |
766 void emitDitto(Scope sc) | |
767 { | |
768 assert(false); | |
769 } | |
770 | |
771 // Backend | |
772 | |
773 Symbol* toSymbol() // to backend symbol | |
774 { | |
775 assert(false); | |
776 } | |
777 | |
778 void toObjFile(int multiobj) // compile to .obj file | |
779 { | |
780 //printf("Dsymbol::toObjFile('%s')\n", toChars()); | |
781 // ignore | |
782 } | |
783 | |
784 int cvMember(ubyte* p) // emit cv debug info for member | |
785 { | |
786 assert(false); | |
787 } | |
788 | |
789 /********************************* | |
790 * Generate import symbol from symbol. | |
791 */ | |
792 Symbol* toImport() // to backend import symbol | |
793 { | |
794 if (!isym) | |
795 { | |
796 if (!csym) | |
797 csym = toSymbol(); | |
798 isym = toImport(csym); | |
799 } | |
800 | |
801 return isym; | |
802 } | |
803 | |
804 static Symbol* toImport(Symbol* sym) // to backend import symbol | |
805 { | |
806 char* id; | |
807 char* n; | |
808 Symbol* s; | |
809 type* t; | |
810 | |
811 //printf("Dsymbol::toImport('%s')\n", sym->Sident); | |
812 n = sym.Sident.ptr; | |
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
|
813 version (Bug4054) |
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
|
814 id = cast(char*) GC.malloc(6 + strlen(n) + 1 + (type_paramsize_i(sym.Stype)).sizeof*3 + 1); |
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
|
815 else |
0 | 816 id = cast(char*) alloca(6 + strlen(n) + 1 + (type_paramsize_i(sym.Stype)).sizeof*3 + 1); |
817 if (sym.Stype.Tmangle == mTYman_std && tyfunc(sym.Stype.Tty)) | |
818 { | |
819 sprintf(id, "_imp__%s@%lu", n, type_paramsize_i(sym.Stype)); | |
820 } | |
821 else if (sym.Stype.Tmangle == mTYman_d) | |
822 sprintf(id,"_imp_%s",n); | |
823 else | |
824 sprintf(id,"_imp__%s",n); | |
825 t = type_alloc(TYnptr | mTYconst); | |
826 t.Tnext = sym.Stype; | |
827 t.Tnext.Tcount++; | |
828 t.Tmangle = mTYman_c; | |
829 t.Tcount++; | |
830 s = symbol_calloc(id); | |
831 s.Stype = t; | |
832 s.Sclass = SCextern; | |
833 s.Sfl = FLextern; | |
834 slist_add(s); | |
835 | |
836 return s; | |
837 } | |
838 | |
839 Symbol* toSymbolX(string prefix, int sclass, TYPE* t, string suffix) // helper | |
840 { | |
841 Symbol* s; | |
842 char* id; | |
843 string n; | |
844 size_t nlen; | |
845 | |
846 //writef("Dsymbol::toSymbolX('%s', '%s')\n", prefix, this.classinfo.name); | |
847 n = mangle(); | |
848 assert(n.length != 0); | |
849 | |
850 nlen = n.length; | |
851 static if (false) { | |
852 if (nlen > 2 && n[0] == '_' && n[1] == 'D') | |
853 { | |
854 nlen -= 2; | |
855 n += 2; | |
856 } | |
857 } | |
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
|
858 version (Bug4054) |
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
|
859 id = cast(char*) GC.malloc(2 + nlen + size_t.sizeof * 3 + prefix.length + suffix.length + 1); |
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
|
860 else |
0 | 861 id = cast(char*) alloca(2 + nlen + size_t.sizeof * 3 + prefix.length + suffix.length + 1); |
73 | 862 sprintf(id, "_D%.*s%zu%.*s%.*s", n, prefix.length, prefix, suffix); |
0 | 863 |
864 static if (false) { | |
865 if (global.params.isWindows && (type_mangle(t) == mTYman.mTYman_c || type_mangle(t) == mTYman.mTYman_std)) | |
866 id++; // Windows C mangling will put the '_' back in | |
867 } | |
868 s = symbol_name(id, sclass, t); | |
869 | |
870 //printf("-Dsymbol::toSymbolX() %s\n", id); | |
871 return s; | |
872 } | |
873 | |
874 // Eliminate need for dynamic_cast | |
875 Package isPackage() { return null; } | |
876 Module isModule() { return null; } | |
877 EnumMember isEnumMember() { return null; } | |
878 TemplateDeclaration isTemplateDeclaration() { return null; } | |
879 TemplateInstance isTemplateInstance() { return null; } | |
880 TemplateMixin isTemplateMixin() { return null; } | |
881 Declaration isDeclaration() { return null; } | |
882 ThisDeclaration isThisDeclaration() { return null; } | |
883 TupleDeclaration isTupleDeclaration() { return null; } | |
884 TypedefDeclaration isTypedefDeclaration() { return null; } | |
885 AliasDeclaration isAliasDeclaration() { return null; } | |
886 AggregateDeclaration isAggregateDeclaration() { return null; } | |
887 FuncDeclaration isFuncDeclaration() { return null; } | |
888 FuncAliasDeclaration isFuncAliasDeclaration() { return null; } | |
889 FuncLiteralDeclaration isFuncLiteralDeclaration() { return null; } | |
890 CtorDeclaration isCtorDeclaration() { return null; } | |
891 PostBlitDeclaration isPostBlitDeclaration() { return null; } | |
892 DtorDeclaration isDtorDeclaration() { return null; } | |
893 StaticCtorDeclaration isStaticCtorDeclaration() { return null; } | |
894 StaticDtorDeclaration isStaticDtorDeclaration() { return null; } | |
895 InvariantDeclaration isInvariantDeclaration() { return null; } | |
896 UnitTestDeclaration isUnitTestDeclaration() { return null; } | |
897 NewDeclaration isNewDeclaration() { return null; } | |
898 VarDeclaration isVarDeclaration() { return null; } | |
899 ClassDeclaration isClassDeclaration() { return null; } | |
900 StructDeclaration isStructDeclaration() { return null; } | |
901 UnionDeclaration isUnionDeclaration() { return null; } | |
902 InterfaceDeclaration isInterfaceDeclaration() { return null; } | |
903 ScopeDsymbol isScopeDsymbol() { return null; } | |
904 WithScopeSymbol isWithScopeSymbol() { return null; } | |
905 ArrayScopeSymbol isArrayScopeSymbol() { return null; } | |
906 Import isImport() { return null; } | |
907 EnumDeclaration isEnumDeclaration() { return null; } | |
79 | 908 version (_DH) |
909 { | |
0 | 910 DeleteDeclaration isDeleteDeclaration() { return null; } |
911 } | |
912 SymbolDeclaration isSymbolDeclaration() { return null; } | |
913 AttribDeclaration isAttribDeclaration() { return null; } | |
914 OverloadSet isOverloadSet() { return null; } | |
79 | 915 version (TARGET_NET) |
916 { | |
0 | 917 PragmaScope isPragmaScope() { return null; } |
918 } | |
79 | 919 } |