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