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