Mercurial > projects > ddmd
annotate dmd/Dsymbol.d @ 45:ccbc1e0bb3f0
StringExp.equals implemented
int equals(Object o) -> bool equals(Object o)
author | korDen |
---|---|
date | Sat, 21 Aug 2010 07:26:20 +0400 |
parents | 460959608115 |
children | adf6f7f216ea |
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 | |
453 Dsymbol search(Loc loc, Identifier ident, int flags) | |
454 { | |
455 assert(false); | |
456 } | |
457 | |
458 /*************************************** | |
459 * Search for identifier id as a member of 'this'. | |
460 * id may be a template instance. | |
461 * Returns: | |
462 * symbol found, null if not | |
463 */ | |
464 Dsymbol searchX(Loc loc, Scope sc, Identifier id) | |
465 { | |
466 //printf("Dsymbol::searchX(this=%p,%s, ident='%s')\n", this, toChars(), ident.toChars()); | |
467 Dsymbol s = toAlias(); | |
468 Dsymbol sm; | |
469 | |
470 /// HUH???? | |
471 switch (id.dyncast()) | |
472 { | |
473 case DYNCAST.DYNCAST_IDENTIFIER: | |
474 sm = s.search(loc, id, 0); | |
475 break; | |
476 | |
477 case DYNCAST.DYNCAST_DSYMBOL: | |
478 { | |
479 assert(false); /// how can it happen? | |
480 // It's a template instance | |
481 //printf("\ttemplate instance id\n"); | |
482 Dsymbol st = cast(Dsymbol)id; | |
483 TemplateInstance ti = st.isTemplateInstance(); | |
484 id = ti.name; | |
485 sm = s.search(loc, id, 0); | |
486 if (!sm) | |
487 { | |
488 error("template identifier %s is not a member of %s %s", id.toChars(), s.kind(), s.toChars()); | |
489 return null; | |
490 } | |
491 sm = sm.toAlias(); | |
492 TemplateDeclaration td = sm.isTemplateDeclaration(); | |
493 if (!td) | |
494 { | |
495 error("%s is not a template, it is a %s", id.toChars(), sm.kind()); | |
496 return null; | |
497 } | |
498 | |
499 ti.tempdecl = td; | |
500 if (!ti.semanticRun) | |
501 ti.semantic(sc); | |
502 | |
503 sm = ti.toAlias(); | |
504 break; | |
505 } | |
506 | |
507 default: | |
508 assert(0); | |
509 } | |
510 return sm; | |
511 } | |
512 | |
513 bool overloadInsert(Dsymbol s) | |
514 { | |
515 assert(false); | |
516 } | |
517 | |
518 version (_DH) { | |
519 char* toHChars() | |
520 { | |
521 assert(false); | |
522 } | |
523 | |
524 void toHBuffer(OutBuffer buf, HdrGenState* hgs) | |
525 { | |
526 assert(false); | |
527 } | |
528 } | |
529 void toCBuffer(OutBuffer buf, HdrGenState* hgs) | |
530 { | |
531 assert(false); | |
532 } | |
533 | |
534 void toDocBuffer(OutBuffer buf) | |
535 { | |
536 assert(false); | |
537 } | |
538 | |
539 uint size(Loc loc) | |
540 { | |
541 assert(false); | |
542 } | |
543 | |
544 int isforwardRef() | |
545 { | |
546 assert(false); | |
547 } | |
548 | |
549 void defineRef(Dsymbol s) | |
550 { | |
551 assert(false); | |
552 } | |
553 | |
554 AggregateDeclaration isThis() // is a 'this' required to access the member | |
555 { | |
556 assert(false); | |
557 } | |
558 | |
559 ClassDeclaration isClassMember() // are we a member of a class? | |
560 { | |
561 Dsymbol parent = toParent(); | |
562 if (parent && parent.isClassDeclaration()) | |
563 return cast(ClassDeclaration)parent; | |
564 return null; | |
565 } | |
566 | |
567 bool isExport() // is Dsymbol exported? | |
568 { | |
569 return false; | |
570 } | |
571 | |
572 bool isImportedSymbol() // is Dsymbol imported? | |
573 { | |
574 return false; | |
575 } | |
576 | |
577 bool isDeprecated() // is Dsymbol deprecated? | |
578 { | |
579 return false; | |
580 } | |
581 | |
582 version (DMDV2) { | |
583 bool isOverloadable() | |
584 { | |
585 return false; | |
586 } | |
587 } | |
588 | |
589 LabelDsymbol isLabel() // is this a LabelDsymbol? | |
590 { | |
591 return null; | |
592 } | |
593 | |
594 AggregateDeclaration isMember() // is this symbol a member of an AggregateDeclaration? | |
595 { | |
596 //printf("Dsymbol::isMember() %s\n", toChars()); | |
597 Dsymbol parent = toParent(); | |
598 //printf("parent is %s %s\n", parent.kind(), parent.toChars()); | |
599 return parent ? parent.isAggregateDeclaration() : null; | |
600 } | |
601 | |
602 Type getType() // is this a type? | |
603 { | |
604 return null; | |
605 } | |
606 | |
607 string mangle() | |
608 { | |
609 OutBuffer buf = new OutBuffer(); | |
610 string id; | |
611 | |
612 static if (false) { | |
613 printf("Dsymbol::mangle() '%s'", toChars()); | |
614 if (parent) | |
615 printf(" parent = %s %s", parent.kind(), parent.toChars()); | |
616 printf("\n"); | |
617 } | |
618 id = ident ? ident.toChars() : toChars(); | |
619 if (parent) | |
620 { | |
621 string p = parent.mangle(); | |
622 if (p[0] == '_' && p[1] == 'D') | |
623 p = p[2..$]; | |
624 buf.writestring(p); | |
625 } | |
626 ///buf.printf("%zu%s", id.length, id); | |
627 buf.printf("%d%s", id.length, id); | |
628 id = buf.toChars(); | |
629 buf.data = null; | |
630 //printf("Dsymbol::mangle() %s = %s\n", toChars(), id); | |
631 return id; | |
632 } | |
633 | |
634 bool needThis() // need a 'this' pointer? | |
635 { | |
636 return false; | |
637 } | |
638 | |
639 PROT prot() | |
640 { | |
641 assert(false); | |
642 } | |
643 | |
644 Dsymbol syntaxCopy(Dsymbol s) // copy only syntax trees | |
645 { | |
646 assert(false); | |
647 } | |
648 | |
649 /************************************** | |
650 * Determine if this symbol is only one. | |
651 * Returns: | |
652 * false, *ps = null: There are 2 or more symbols | |
653 * true, *ps = null: There are zero symbols | |
654 * true, *ps = symbol: The one and only one symbol | |
655 */ | |
656 bool oneMember(Dsymbol* ps) | |
657 { | |
658 //printf("Dsymbol::oneMember()\n"); | |
659 *ps = this; | |
660 return true; | |
661 } | |
662 | |
663 /***************************************** | |
664 * Same as Dsymbol::oneMember(), but look at an array of Dsymbols. | |
665 */ | |
666 static bool oneMembers(Array members, Dsymbol* ps) | |
667 { | |
668 //printf("Dsymbol::oneMembers() %d\n", members ? members->dim : 0); | |
669 Dsymbol s = null; | |
670 | |
671 if (members) | |
672 { | |
673 for (int i = 0; i < members.dim; i++) | |
674 { | |
675 Dsymbol sx = cast(Dsymbol)members.data[i]; | |
676 | |
677 bool x = sx.oneMember(ps); | |
678 //printf("\t[%d] kind %s = %d, s = %p\n", i, sx->kind(), x, *ps); | |
679 if (!x) | |
680 { | |
681 //printf("\tfalse 1\n"); | |
682 assert(*ps is null); | |
683 return false; | |
684 } | |
685 if (*ps) | |
686 { | |
687 if (s) // more than one symbol | |
688 { | |
689 *ps = null; | |
690 //printf("\tfalse 2\n"); | |
691 return false; | |
692 } | |
693 s = *ps; | |
694 } | |
695 } | |
696 } | |
697 | |
698 *ps = s; // s is the one symbol, null if none | |
699 //printf("\ttrue\n"); | |
700 return true; | |
701 } | |
702 | |
703 /***************************************** | |
704 * Is Dsymbol a variable that contains pointers? | |
705 */ | |
706 bool hasPointers() | |
707 { | |
708 //printf("Dsymbol::hasPointers() %s\n", toChars()); | |
709 return 0; | |
710 } | |
711 | |
712 void addLocalClass(ClassDeclarations) { } | |
713 void checkCtorConstInit() { } | |
714 | |
715 void addComment(ubyte* comment) | |
716 { | |
717 //if (comment) | |
718 //printf("adding comment '%s' to symbol %p '%s'\n", comment, this, toChars()); | |
719 | |
720 if (this.comment is null) { | |
721 this.comment = comment; | |
722 } else { | |
723 static if (true) { | |
724 if (comment !is null && strcmp(cast(char*)comment, cast(char*)this.comment) != 0) | |
725 { // Concatenate the two | |
726 this.comment = Lexer.combineComments(this.comment, comment); | |
727 } | |
728 } | |
729 } | |
730 } | |
731 | |
732 void emitComment(Scope sc) | |
733 { | |
734 assert(false); | |
735 } | |
736 | |
737 void emitDitto(Scope sc) | |
738 { | |
739 assert(false); | |
740 } | |
741 | |
742 // Backend | |
743 | |
744 Symbol* toSymbol() // to backend symbol | |
745 { | |
746 assert(false); | |
747 } | |
748 | |
749 void toObjFile(int multiobj) // compile to .obj file | |
750 { | |
751 //printf("Dsymbol::toObjFile('%s')\n", toChars()); | |
752 // ignore | |
753 } | |
754 | |
755 int cvMember(ubyte* p) // emit cv debug info for member | |
756 { | |
757 assert(false); | |
758 } | |
759 | |
760 /********************************* | |
761 * Generate import symbol from symbol. | |
762 */ | |
763 Symbol* toImport() // to backend import symbol | |
764 { | |
765 if (!isym) | |
766 { | |
767 if (!csym) | |
768 csym = toSymbol(); | |
769 isym = toImport(csym); | |
770 } | |
771 | |
772 return isym; | |
773 } | |
774 | |
775 static Symbol* toImport(Symbol* sym) // to backend import symbol | |
776 { | |
777 char* id; | |
778 char* n; | |
779 Symbol* s; | |
780 type* t; | |
781 | |
782 //printf("Dsymbol::toImport('%s')\n", sym->Sident); | |
783 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
|
784 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
|
785 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
|
786 else |
0 | 787 id = cast(char*) alloca(6 + strlen(n) + 1 + (type_paramsize_i(sym.Stype)).sizeof*3 + 1); |
788 if (sym.Stype.Tmangle == mTYman_std && tyfunc(sym.Stype.Tty)) | |
789 { | |
790 sprintf(id, "_imp__%s@%lu", n, type_paramsize_i(sym.Stype)); | |
791 } | |
792 else if (sym.Stype.Tmangle == mTYman_d) | |
793 sprintf(id,"_imp_%s",n); | |
794 else | |
795 sprintf(id,"_imp__%s",n); | |
796 t = type_alloc(TYnptr | mTYconst); | |
797 t.Tnext = sym.Stype; | |
798 t.Tnext.Tcount++; | |
799 t.Tmangle = mTYman_c; | |
800 t.Tcount++; | |
801 s = symbol_calloc(id); | |
802 s.Stype = t; | |
803 s.Sclass = SCextern; | |
804 s.Sfl = FLextern; | |
805 slist_add(s); | |
806 | |
807 return s; | |
808 } | |
809 | |
810 Symbol* toSymbolX(string prefix, int sclass, TYPE* t, string suffix) // helper | |
811 { | |
812 Symbol* s; | |
813 char* id; | |
814 string n; | |
815 size_t nlen; | |
816 | |
817 //writef("Dsymbol::toSymbolX('%s', '%s')\n", prefix, this.classinfo.name); | |
818 n = mangle(); | |
819 assert(n.length != 0); | |
820 | |
821 nlen = n.length; | |
822 static if (false) { | |
823 if (nlen > 2 && n[0] == '_' && n[1] == 'D') | |
824 { | |
825 nlen -= 2; | |
826 n += 2; | |
827 } | |
828 } | |
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
|
829 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
|
830 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
|
831 else |
0 | 832 id = cast(char*) alloca(2 + nlen + size_t.sizeof * 3 + prefix.length + suffix.length + 1); |
833 sprintf(id, "_D%.*s%lu%.*s%.*s", n, prefix.length, prefix, suffix); | |
834 | |
835 static if (false) { | |
836 if (global.params.isWindows && (type_mangle(t) == mTYman.mTYman_c || type_mangle(t) == mTYman.mTYman_std)) | |
837 id++; // Windows C mangling will put the '_' back in | |
838 } | |
839 s = symbol_name(id, sclass, t); | |
840 | |
841 //printf("-Dsymbol::toSymbolX() %s\n", id); | |
842 return s; | |
843 } | |
844 | |
845 // Eliminate need for dynamic_cast | |
846 Package isPackage() { return null; } | |
847 Module isModule() { return null; } | |
848 EnumMember isEnumMember() { return null; } | |
849 TemplateDeclaration isTemplateDeclaration() { return null; } | |
850 TemplateInstance isTemplateInstance() { return null; } | |
851 TemplateMixin isTemplateMixin() { return null; } | |
852 Declaration isDeclaration() { return null; } | |
853 ThisDeclaration isThisDeclaration() { return null; } | |
854 TupleDeclaration isTupleDeclaration() { return null; } | |
855 TypedefDeclaration isTypedefDeclaration() { return null; } | |
856 AliasDeclaration isAliasDeclaration() { return null; } | |
857 AggregateDeclaration isAggregateDeclaration() { return null; } | |
858 FuncDeclaration isFuncDeclaration() { return null; } | |
859 FuncAliasDeclaration isFuncAliasDeclaration() { return null; } | |
860 FuncLiteralDeclaration isFuncLiteralDeclaration() { return null; } | |
861 CtorDeclaration isCtorDeclaration() { return null; } | |
862 PostBlitDeclaration isPostBlitDeclaration() { return null; } | |
863 DtorDeclaration isDtorDeclaration() { return null; } | |
864 StaticCtorDeclaration isStaticCtorDeclaration() { return null; } | |
865 StaticDtorDeclaration isStaticDtorDeclaration() { return null; } | |
866 InvariantDeclaration isInvariantDeclaration() { return null; } | |
867 UnitTestDeclaration isUnitTestDeclaration() { return null; } | |
868 NewDeclaration isNewDeclaration() { return null; } | |
869 VarDeclaration isVarDeclaration() { return null; } | |
870 ClassDeclaration isClassDeclaration() { return null; } | |
871 StructDeclaration isStructDeclaration() { return null; } | |
872 UnionDeclaration isUnionDeclaration() { return null; } | |
873 InterfaceDeclaration isInterfaceDeclaration() { return null; } | |
874 ScopeDsymbol isScopeDsymbol() { return null; } | |
875 WithScopeSymbol isWithScopeSymbol() { return null; } | |
876 ArrayScopeSymbol isArrayScopeSymbol() { return null; } | |
877 Import isImport() { return null; } | |
878 EnumDeclaration isEnumDeclaration() { return null; } | |
879 version (_DH) { | |
880 DeleteDeclaration isDeleteDeclaration() { return null; } | |
881 } | |
882 SymbolDeclaration isSymbolDeclaration() { return null; } | |
883 AttribDeclaration isAttribDeclaration() { return null; } | |
884 OverloadSet isOverloadSet() { return null; } | |
885 version (TARGET_NET) { | |
886 PragmaScope isPragmaScope() { return null; } | |
887 } | |
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
|
888 } |