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