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