Mercurial > projects > ldc
annotate dmd/dsymbol.c @ 1587:def7a1d494fd
Merge DMD 1.051
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Fri, 06 Nov 2009 23:58:01 +0100 |
parents | 78038e540342 |
children | 207a8a438dea |
rev | line source |
---|---|
159 | 1 |
2 // Compiler implementation of the D programming language | |
1587 | 3 // Copyright (c) 1999-2009 by Digital Mars |
159 | 4 // All Rights Reserved |
5 // written by Walter Bright | |
6 // http://www.digitalmars.com | |
7 // License for redistribution is by either the Artistic License | |
8 // in artistic.txt, or the GNU General Public License in gnu.txt. | |
9 // See the included readme.txt for details. | |
10 | |
11 #include <stdio.h> | |
12 #include <string.h> | |
13 #include <assert.h> | |
14 | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
946
diff
changeset
|
15 #include "rmem.h" |
159 | 16 |
17 #include "mars.h" | |
18 #include "dsymbol.h" | |
19 #include "aggregate.h" | |
20 #include "identifier.h" | |
21 #include "module.h" | |
22 #include "mtype.h" | |
23 #include "expression.h" | |
24 #include "statement.h" | |
25 #include "declaration.h" | |
26 #include "id.h" | |
27 #include "scope.h" | |
28 #include "init.h" | |
29 #include "import.h" | |
30 #include "template.h" | |
1587 | 31 #include "attrib.h" |
159 | 32 #include "../gen/enums.h" |
33 | |
34 /****************************** Dsymbol ******************************/ | |
35 | |
36 Dsymbol::Dsymbol() | |
37 { | |
38 //printf("Dsymbol::Dsymbol(%p)\n", this); | |
39 this->ident = NULL; | |
40 this->c_ident = NULL; | |
41 this->parent = NULL; | |
1146
1860414bf3b7
* Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1103
diff
changeset
|
42 #if IN_DMD |
159 | 43 this->csym = NULL; |
44 this->isym = NULL; | |
1146
1860414bf3b7
* Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1103
diff
changeset
|
45 #endif |
159 | 46 this->loc = 0; |
47 this->comment = NULL; | |
1587 | 48 this->scope = NULL; |
1146
1860414bf3b7
* Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1103
diff
changeset
|
49 #if IN_LLVM |
159 | 50 this->llvmInternal = LLVMnone; |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
51 this->irsym = NULL; |
1146
1860414bf3b7
* Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1103
diff
changeset
|
52 #endif |
159 | 53 } |
54 | |
55 Dsymbol::Dsymbol(Identifier *ident) | |
56 { | |
57 //printf("Dsymbol::Dsymbol(%p, ident)\n", this); | |
58 this->ident = ident; | |
59 this->c_ident = NULL; | |
60 this->parent = NULL; | |
1146
1860414bf3b7
* Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1103
diff
changeset
|
61 #if IN_DMD |
159 | 62 this->csym = NULL; |
63 this->isym = NULL; | |
1146
1860414bf3b7
* Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1103
diff
changeset
|
64 #endif |
159 | 65 this->loc = 0; |
66 this->comment = NULL; | |
1587 | 67 this->scope = NULL; |
1146
1860414bf3b7
* Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1103
diff
changeset
|
68 #if IN_LLVM |
159 | 69 this->llvmInternal = LLVMnone; |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
70 this->irsym = NULL; |
1146
1860414bf3b7
* Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1103
diff
changeset
|
71 #endif |
159 | 72 } |
73 | |
74 int Dsymbol::equals(Object *o) | |
75 { Dsymbol *s; | |
76 | |
77 if (this == o) | |
78 return TRUE; | |
79 s = (Dsymbol *)(o); | |
80 if (s && ident->equals(s->ident)) | |
81 return TRUE; | |
82 return FALSE; | |
83 } | |
84 | |
85 /************************************** | |
86 * Copy the syntax. | |
87 * Used for template instantiations. | |
88 * If s is NULL, allocate the new object, otherwise fill it in. | |
89 */ | |
90 | |
91 Dsymbol *Dsymbol::syntaxCopy(Dsymbol *s) | |
92 { | |
93 print(); | |
94 printf("%s %s\n", kind(), toChars()); | |
95 assert(0); | |
96 return NULL; | |
97 } | |
98 | |
99 /************************************** | |
100 * Determine if this symbol is only one. | |
101 * Returns: | |
102 * FALSE, *ps = NULL: There are 2 or more symbols | |
103 * TRUE, *ps = NULL: There are zero symbols | |
104 * TRUE, *ps = symbol: The one and only one symbol | |
105 */ | |
106 | |
107 int Dsymbol::oneMember(Dsymbol **ps) | |
108 { | |
109 //printf("Dsymbol::oneMember()\n"); | |
110 *ps = this; | |
111 return TRUE; | |
112 } | |
113 | |
114 /***************************************** | |
115 * Same as Dsymbol::oneMember(), but look at an array of Dsymbols. | |
116 */ | |
117 | |
118 int Dsymbol::oneMembers(Array *members, Dsymbol **ps) | |
119 { | |
120 //printf("Dsymbol::oneMembers() %d\n", members ? members->dim : 0); | |
121 Dsymbol *s = NULL; | |
122 | |
123 if (members) | |
124 { | |
125 for (int i = 0; i < members->dim; i++) | |
126 { Dsymbol *sx = (Dsymbol *)members->data[i]; | |
127 | |
128 int x = sx->oneMember(ps); | |
129 //printf("\t[%d] kind %s = %d, s = %p\n", i, sx->kind(), x, *ps); | |
130 if (!x) | |
131 { | |
132 //printf("\tfalse 1\n"); | |
133 assert(*ps == NULL); | |
134 return FALSE; | |
135 } | |
136 if (*ps) | |
137 { | |
138 if (s) // more than one symbol | |
139 { *ps = NULL; | |
140 //printf("\tfalse 2\n"); | |
141 return FALSE; | |
142 } | |
143 s = *ps; | |
144 } | |
145 } | |
146 } | |
147 *ps = s; // s is the one symbol, NULL if none | |
148 //printf("\ttrue\n"); | |
149 return TRUE; | |
150 } | |
151 | |
152 /***************************************** | |
153 * Is Dsymbol a variable that contains pointers? | |
154 */ | |
155 | |
156 int Dsymbol::hasPointers() | |
157 { | |
158 //printf("Dsymbol::hasPointers() %s\n", toChars()); | |
159 return 0; | |
160 } | |
161 | |
162 char *Dsymbol::toChars() | |
163 { | |
164 return ident ? ident->toChars() : (char *)"__anonymous"; | |
165 } | |
166 | |
1587 | 167 const char *Dsymbol::toPrettyChars() |
159 | 168 { Dsymbol *p; |
169 char *s; | |
170 char *q; | |
171 size_t len; | |
172 | |
173 //printf("Dsymbol::toPrettyChars() '%s'\n", toChars()); | |
174 if (!parent) | |
175 return toChars(); | |
176 | |
177 len = 0; | |
178 for (p = this; p; p = p->parent) | |
179 len += strlen(p->toChars()) + 1; | |
180 | |
181 s = (char *)mem.malloc(len); | |
182 q = s + len - 1; | |
183 *q = 0; | |
184 for (p = this; p; p = p->parent) | |
185 { | |
186 char *t = p->toChars(); | |
187 len = strlen(t); | |
188 q -= len; | |
189 memcpy(q, t, len); | |
190 if (q == s) | |
191 break; | |
192 q--; | |
1587 | 193 #if TARGET_NET |
194 if (AggregateDeclaration* ad = p->isAggregateDeclaration()) | |
195 { | |
196 if (ad->isNested() && p->parent && p->parent->isAggregateDeclaration()) | |
197 { | |
198 *q = '/'; | |
199 continue; | |
200 } | |
201 } | |
202 #endif | |
159 | 203 *q = '.'; |
204 } | |
205 return s; | |
206 } | |
207 | |
208 char *Dsymbol::locToChars() | |
209 { | |
210 OutBuffer buf; | |
211 char *p; | |
212 | |
213 Module *m = getModule(); | |
214 | |
215 if (m && m->srcfile) | |
216 loc.filename = m->srcfile->toChars(); | |
217 return loc.toChars(); | |
218 } | |
219 | |
336 | 220 const char *Dsymbol::kind() |
159 | 221 { |
222 return "symbol"; | |
223 } | |
224 | |
225 /********************************* | |
226 * If this symbol is really an alias for another, | |
227 * return that other. | |
228 */ | |
229 | |
230 Dsymbol *Dsymbol::toAlias() | |
231 { | |
232 return this; | |
233 } | |
234 | |
235 Dsymbol *Dsymbol::toParent() | |
236 { | |
237 return parent ? parent->pastMixin() : NULL; | |
238 } | |
239 | |
240 Dsymbol *Dsymbol::pastMixin() | |
241 { | |
242 Dsymbol *s = this; | |
243 | |
244 //printf("Dsymbol::pastMixin() %s\n", toChars()); | |
245 while (s && s->isTemplateMixin()) | |
246 s = s->parent; | |
247 return s; | |
248 } | |
249 | |
250 /********************************** | |
251 * Use this instead of toParent() when looking for the | |
252 * 'this' pointer of the enclosing function/class. | |
253 */ | |
254 | |
255 Dsymbol *Dsymbol::toParent2() | |
256 { | |
257 Dsymbol *s = parent; | |
258 while (s && s->isTemplateInstance()) | |
259 s = s->parent; | |
260 return s; | |
261 } | |
262 | |
336 | 263 TemplateInstance *Dsymbol::inTemplateInstance() |
264 { | |
265 for (Dsymbol *parent = this->parent; parent; parent = parent->parent) | |
266 { | |
267 TemplateInstance *ti = parent->isTemplateInstance(); | |
268 if (ti) | |
269 return ti; | |
270 } | |
271 return NULL; | |
272 } | |
159 | 273 |
274 int Dsymbol::isAnonymous() | |
275 { | |
276 return ident ? 0 : 1; | |
277 } | |
278 | |
1587 | 279 /************************************* |
280 * Set scope for future semantic analysis so we can | |
281 * deal better with forward references. | |
282 */ | |
283 | |
284 void Dsymbol::setScope(Scope *sc) | |
285 { | |
286 //printf("Dsymbol::setScope() %p %s\n", this, toChars()); | |
287 if (!sc->nofree) | |
288 sc->setNoFree(); // may need it even after semantic() finishes | |
289 scope = sc; | |
290 } | |
291 | |
292 void Dsymbol::importAll(Scope *sc) | |
293 { | |
294 } | |
295 | |
296 /************************************* | |
297 * Does semantic analysis on the public face of declarations. | |
298 */ | |
299 | |
159 | 300 void Dsymbol::semantic(Scope *sc) |
301 { | |
302 error("%p has no semantic routine", this); | |
303 } | |
304 | |
1587 | 305 /************************************* |
306 * Does semantic analysis on initializers and members of aggregates. | |
307 */ | |
308 | |
159 | 309 void Dsymbol::semantic2(Scope *sc) |
310 { | |
311 // Most Dsymbols have no further semantic analysis needed | |
312 } | |
313 | |
1587 | 314 /************************************* |
315 * Does semantic analysis on function bodies. | |
316 */ | |
317 | |
159 | 318 void Dsymbol::semantic3(Scope *sc) |
319 { | |
320 // Most Dsymbols have no further semantic analysis needed | |
321 } | |
322 | |
1587 | 323 /************************************* |
324 * Look for function inlining possibilities. | |
325 */ | |
326 | |
159 | 327 void Dsymbol::inlineScan() |
328 { | |
1587 | 329 // Most Dsymbols aren't functions |
159 | 330 } |
331 | |
336 | 332 /********************************************* |
333 * Search for ident as member of s. | |
334 * Input: | |
335 * flags: 1 don't find private members | |
336 * 2 don't give error messages | |
337 * 4 return NULL if ambiguous | |
338 * Returns: | |
339 * NULL if not found | |
340 */ | |
341 | |
159 | 342 Dsymbol *Dsymbol::search(Loc loc, Identifier *ident, int flags) |
343 { | |
344 //printf("Dsymbol::search(this=%p,%s, ident='%s')\n", this, toChars(), ident->toChars()); | |
345 return NULL; | |
346 } | |
347 | |
348 /*************************************** | |
349 * Search for identifier id as a member of 'this'. | |
350 * id may be a template instance. | |
351 * Returns: | |
352 * symbol found, NULL if not | |
353 */ | |
354 | |
355 Dsymbol *Dsymbol::searchX(Loc loc, Scope *sc, Identifier *id) | |
356 { | |
357 //printf("Dsymbol::searchX(this=%p,%s, ident='%s')\n", this, toChars(), ident->toChars()); | |
358 Dsymbol *s = toAlias(); | |
359 Dsymbol *sm; | |
360 | |
361 switch (id->dyncast()) | |
362 { | |
363 case DYNCAST_IDENTIFIER: | |
364 sm = s->search(loc, id, 0); | |
365 break; | |
366 | |
367 case DYNCAST_DSYMBOL: | |
368 { // It's a template instance | |
369 //printf("\ttemplate instance id\n"); | |
370 Dsymbol *st = (Dsymbol *)id; | |
371 TemplateInstance *ti = st->isTemplateInstance(); | |
372 id = ti->name; | |
373 sm = s->search(loc, id, 0); | |
374 if (!sm) | |
375 { error("template identifier %s is not a member of %s %s", | |
376 id->toChars(), s->kind(), s->toChars()); | |
377 return NULL; | |
378 } | |
379 sm = sm->toAlias(); | |
380 TemplateDeclaration *td = sm->isTemplateDeclaration(); | |
381 if (!td) | |
382 { | |
383 error("%s is not a template, it is a %s", id->toChars(), sm->kind()); | |
384 return NULL; | |
385 } | |
386 ti->tempdecl = td; | |
1587 | 387 if (!ti->semanticRun) |
159 | 388 ti->semantic(sc); |
389 sm = ti->toAlias(); | |
390 break; | |
391 } | |
392 | |
393 default: | |
394 assert(0); | |
395 } | |
396 return sm; | |
397 } | |
398 | |
399 int Dsymbol::overloadInsert(Dsymbol *s) | |
400 { | |
401 //printf("Dsymbol::overloadInsert('%s')\n", s->toChars()); | |
402 return FALSE; | |
403 } | |
404 | |
405 void Dsymbol::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
406 { | |
407 buf->writestring(toChars()); | |
408 } | |
409 | |
410 unsigned Dsymbol::size(Loc loc) | |
411 { | |
412 error("Dsymbol '%s' has no size\n", toChars()); | |
413 return 0; | |
414 } | |
415 | |
416 int Dsymbol::isforwardRef() | |
417 { | |
418 return FALSE; | |
419 } | |
420 | |
421 AggregateDeclaration *Dsymbol::isThis() | |
422 { | |
423 return NULL; | |
424 } | |
425 | |
426 ClassDeclaration *Dsymbol::isClassMember() // are we a member of a class? | |
427 { | |
428 Dsymbol *parent = toParent(); | |
429 if (parent && parent->isClassDeclaration()) | |
430 return (ClassDeclaration *)parent; | |
431 return NULL; | |
432 } | |
433 | |
434 void Dsymbol::defineRef(Dsymbol *s) | |
435 { | |
436 assert(0); | |
437 } | |
438 | |
439 int Dsymbol::isExport() | |
440 { | |
441 return FALSE; | |
442 } | |
443 | |
444 int Dsymbol::isImportedSymbol() | |
445 { | |
446 return FALSE; | |
447 } | |
448 | |
449 int Dsymbol::isDeprecated() | |
450 { | |
451 return FALSE; | |
452 } | |
453 | |
1587 | 454 #if DMDV2 |
455 int Dsymbol::isOverloadable() | |
456 { | |
457 return 0; | |
458 } | |
459 #endif | |
460 | |
159 | 461 LabelDsymbol *Dsymbol::isLabel() // is this a LabelDsymbol()? |
462 { | |
463 return NULL; | |
464 } | |
465 | |
466 AggregateDeclaration *Dsymbol::isMember() // is this a member of an AggregateDeclaration? | |
467 { | |
336 | 468 //printf("Dsymbol::isMember() %s\n", toChars()); |
159 | 469 Dsymbol *parent = toParent(); |
336 | 470 //printf("parent is %s %s\n", parent->kind(), parent->toChars()); |
159 | 471 return parent ? parent->isAggregateDeclaration() : NULL; |
472 } | |
473 | |
474 Type *Dsymbol::getType() | |
475 { | |
476 return NULL; | |
477 } | |
478 | |
479 int Dsymbol::needThis() | |
480 { | |
481 return FALSE; | |
482 } | |
483 | |
484 int Dsymbol::addMember(Scope *sc, ScopeDsymbol *sd, int memnum) | |
485 { | |
486 //printf("Dsymbol::addMember('%s')\n", toChars()); | |
487 //printf("Dsymbol::addMember(this = %p, '%s' scopesym = '%s')\n", this, toChars(), sd->toChars()); | |
488 //printf("Dsymbol::addMember(this = %p, '%s' sd = %p, sd->symtab = %p)\n", this, toChars(), sd, sd->symtab); | |
489 parent = sd; | |
490 if (!isAnonymous()) // no name, so can't add it to symbol table | |
491 { | |
1587 | 492 if (!sd->symtabInsert(this)) // if name is already defined |
159 | 493 { |
494 Dsymbol *s2; | |
495 | |
496 s2 = sd->symtab->lookup(ident); | |
497 if (!s2->overloadInsert(this)) | |
498 { | |
499 sd->multiplyDefined(0, this, s2); | |
500 } | |
501 } | |
502 if (sd->isAggregateDeclaration() || sd->isEnumDeclaration()) | |
503 { | |
504 if (ident == Id::__sizeof || ident == Id::alignof || ident == Id::mangleof) | |
505 error(".%s property cannot be redefined", ident->toChars()); | |
506 } | |
507 return 1; | |
508 } | |
509 return 0; | |
510 } | |
511 | |
512 void Dsymbol::error(const char *format, ...) | |
513 { | |
514 //printf("Dsymbol::error()\n"); | |
515 if (!global.gag) | |
516 { | |
517 char *p = locToChars(); | |
518 | |
519 if (*p) | |
520 fprintf(stdmsg, "%s: ", p); | |
521 mem.free(p); | |
522 | |
427
f1d37dc5d354
Give errors originating from Dsymbol::error the proper 'Error:' heading.
Christian Kamm <kamm incasoftware de>
parents:
336
diff
changeset
|
523 fprintf(stdmsg, "Error: "); |
159 | 524 if (isAnonymous()) |
525 fprintf(stdmsg, "%s ", kind()); | |
526 else | |
527 fprintf(stdmsg, "%s %s ", kind(), toPrettyChars()); | |
528 | |
529 va_list ap; | |
530 va_start(ap, format); | |
531 vfprintf(stdmsg, format, ap); | |
532 va_end(ap); | |
533 | |
534 fprintf(stdmsg, "\n"); | |
535 fflush(stdmsg); | |
536 } | |
537 global.errors++; | |
538 | |
539 //fatal(); | |
540 } | |
541 | |
542 void Dsymbol::error(Loc loc, const char *format, ...) | |
543 { | |
544 if (!global.gag) | |
545 { | |
546 char *p = loc.toChars(); | |
547 if (!*p) | |
548 p = locToChars(); | |
549 | |
550 if (*p) | |
551 fprintf(stdmsg, "%s: ", p); | |
552 mem.free(p); | |
553 | |
427
f1d37dc5d354
Give errors originating from Dsymbol::error the proper 'Error:' heading.
Christian Kamm <kamm incasoftware de>
parents:
336
diff
changeset
|
554 fprintf(stdmsg, "Error: "); |
159 | 555 fprintf(stdmsg, "%s %s ", kind(), toPrettyChars()); |
556 | |
557 va_list ap; | |
558 va_start(ap, format); | |
559 vfprintf(stdmsg, format, ap); | |
560 va_end(ap); | |
561 | |
562 fprintf(stdmsg, "\n"); | |
563 fflush(stdmsg); | |
564 } | |
565 | |
566 global.errors++; | |
567 | |
568 //fatal(); | |
569 } | |
570 | |
571 void Dsymbol::checkDeprecated(Loc loc, Scope *sc) | |
572 { | |
573 if (!global.params.useDeprecated && isDeprecated()) | |
574 { | |
575 // Don't complain if we're inside a deprecated symbol's scope | |
576 for (Dsymbol *sp = sc->parent; sp; sp = sp->parent) | |
577 { if (sp->isDeprecated()) | |
578 return; | |
579 } | |
580 | |
581 for (; sc; sc = sc->enclosing) | |
582 { | |
583 if (sc->scopesym && sc->scopesym->isDeprecated()) | |
584 return; | |
336 | 585 |
586 // If inside a StorageClassDeclaration that is deprecated | |
587 if (sc->stc & STCdeprecated) | |
588 return; | |
159 | 589 } |
590 | |
591 error(loc, "is deprecated"); | |
592 } | |
593 } | |
594 | |
595 /********************************** | |
596 * Determine which Module a Dsymbol is in. | |
597 */ | |
598 | |
599 Module *Dsymbol::getModule() | |
600 { | |
601 Module *m; | |
602 Dsymbol *s; | |
603 | |
604 //printf("Dsymbol::getModule()\n"); | |
605 s = this; | |
606 while (s) | |
607 { | |
608 //printf("\ts = '%s'\n", s->toChars()); | |
609 m = s->isModule(); | |
610 if (m) | |
611 return m; | |
612 s = s->parent; | |
613 } | |
614 return NULL; | |
615 } | |
616 | |
946
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
626
diff
changeset
|
617 |
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
626
diff
changeset
|
618 /********************************** |
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
626
diff
changeset
|
619 * Determine which Module a Dsymbol will be compiled in. |
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
626
diff
changeset
|
620 * This may be different from getModule for templates. |
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
626
diff
changeset
|
621 */ |
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
626
diff
changeset
|
622 |
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
626
diff
changeset
|
623 Module *Dsymbol::getCompilationModule() |
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
626
diff
changeset
|
624 { |
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
626
diff
changeset
|
625 Module *m; |
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
626
diff
changeset
|
626 TemplateInstance *ti; |
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
626
diff
changeset
|
627 Dsymbol *s; |
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
626
diff
changeset
|
628 |
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
626
diff
changeset
|
629 //printf("Dsymbol::getModule()\n"); |
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
626
diff
changeset
|
630 s = this; |
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
626
diff
changeset
|
631 while (s) |
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
626
diff
changeset
|
632 { |
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
626
diff
changeset
|
633 //printf("\ts = '%s'\n", s->toChars()); |
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
626
diff
changeset
|
634 m = s->isModule(); |
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
626
diff
changeset
|
635 if (m) |
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
626
diff
changeset
|
636 return m; |
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
626
diff
changeset
|
637 ti = s->isTemplateInstance(); |
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
626
diff
changeset
|
638 if (ti && ti->tmodule) |
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
626
diff
changeset
|
639 return ti->tmodule; |
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
626
diff
changeset
|
640 s = s->parent; |
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
626
diff
changeset
|
641 } |
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
626
diff
changeset
|
642 return NULL; |
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
626
diff
changeset
|
643 } |
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
626
diff
changeset
|
644 |
159 | 645 /************************************* |
646 */ | |
647 | |
648 enum PROT Dsymbol::prot() | |
649 { | |
650 return PROTpublic; | |
651 } | |
652 | |
653 /************************************* | |
654 * Do syntax copy of an array of Dsymbol's. | |
655 */ | |
656 | |
657 | |
658 Array *Dsymbol::arraySyntaxCopy(Array *a) | |
659 { | |
660 | |
661 Array *b = NULL; | |
662 if (a) | |
663 { | |
664 b = a->copy(); | |
665 for (int i = 0; i < b->dim; i++) | |
666 { | |
667 Dsymbol *s = (Dsymbol *)b->data[i]; | |
668 | |
669 s = s->syntaxCopy(NULL); | |
670 b->data[i] = (void *)s; | |
671 } | |
672 } | |
673 return b; | |
674 } | |
675 | |
676 | |
677 /**************************************** | |
678 * Add documentation comment to Dsymbol. | |
679 * Ignore NULL comments. | |
680 */ | |
681 | |
682 void Dsymbol::addComment(unsigned char *comment) | |
683 { | |
1587 | 684 //if (comment) |
685 //printf("adding comment '%s' to symbol %p '%s'\n", comment, this, toChars()); | |
159 | 686 |
687 if (!this->comment) | |
688 this->comment = comment; | |
689 #if 1 | |
690 else if (comment && strcmp((char *)comment, (char *)this->comment)) | |
691 { // Concatenate the two | |
692 this->comment = Lexer::combineComments(this->comment, comment); | |
693 } | |
694 #endif | |
695 } | |
696 | |
1587 | 697 /********************************* OverloadSet ****************************/ |
698 | |
699 #if DMDV2 | |
700 OverloadSet::OverloadSet() | |
701 : Dsymbol() | |
702 { | |
703 } | |
704 | |
705 void OverloadSet::push(Dsymbol *s) | |
706 { | |
707 a.push(s); | |
708 } | |
709 | |
710 const char *OverloadSet::kind() | |
711 { | |
712 return "overloadset"; | |
713 } | |
714 #endif | |
715 | |
159 | 716 |
717 /********************************* ScopeDsymbol ****************************/ | |
718 | |
719 ScopeDsymbol::ScopeDsymbol() | |
720 : Dsymbol() | |
721 { | |
722 members = NULL; | |
723 symtab = NULL; | |
724 imports = NULL; | |
725 prots = NULL; | |
726 } | |
727 | |
728 ScopeDsymbol::ScopeDsymbol(Identifier *id) | |
729 : Dsymbol(id) | |
730 { | |
731 members = NULL; | |
732 symtab = NULL; | |
733 imports = NULL; | |
734 prots = NULL; | |
735 } | |
736 | |
737 Dsymbol *ScopeDsymbol::syntaxCopy(Dsymbol *s) | |
738 { | |
739 //printf("ScopeDsymbol::syntaxCopy('%s')\n", toChars()); | |
740 | |
741 ScopeDsymbol *sd; | |
742 if (s) | |
743 sd = (ScopeDsymbol *)s; | |
744 else | |
745 sd = new ScopeDsymbol(ident); | |
746 sd->members = arraySyntaxCopy(members); | |
747 return sd; | |
748 } | |
749 | |
750 Dsymbol *ScopeDsymbol::search(Loc loc, Identifier *ident, int flags) | |
336 | 751 { |
752 //printf("%s->ScopeDsymbol::search(ident='%s', flags=x%x)\n", toChars(), ident->toChars(), flags); | |
1587 | 753 //if (strcmp(ident->toChars(),"c") == 0) *(char*)0=0; |
159 | 754 |
755 // Look in symbols declared in this module | |
336 | 756 Dsymbol *s = symtab ? symtab->lookup(ident) : NULL; |
626
e83ba4ae4878
Fix import visibility bugs 313 and 314.
Christian Kamm <kamm incasoftware de>
parents:
443
diff
changeset
|
757 |
1358
78038e540342
Fix overload resolution issue in dmd bug 313/314 fix.
Christian Kamm <kamm incasoftware de>
parents:
1147
diff
changeset
|
758 // hide the aliases generated by selective or renamed private imports |
78038e540342
Fix overload resolution issue in dmd bug 313/314 fix.
Christian Kamm <kamm incasoftware de>
parents:
1147
diff
changeset
|
759 if (s && flags & 1) |
78038e540342
Fix overload resolution issue in dmd bug 313/314 fix.
Christian Kamm <kamm incasoftware de>
parents:
1147
diff
changeset
|
760 if (AliasDeclaration* ad = s->isAliasDeclaration()) |
78038e540342
Fix overload resolution issue in dmd bug 313/314 fix.
Christian Kamm <kamm incasoftware de>
parents:
1147
diff
changeset
|
761 // may be a private alias to a function that is overloaded. these |
78038e540342
Fix overload resolution issue in dmd bug 313/314 fix.
Christian Kamm <kamm incasoftware de>
parents:
1147
diff
changeset
|
762 // are sorted out during overload resolution, accept them here |
78038e540342
Fix overload resolution issue in dmd bug 313/314 fix.
Christian Kamm <kamm incasoftware de>
parents:
1147
diff
changeset
|
763 if (ad->importprot == PROTprivate && !ad->aliassym->isFuncAliasDeclaration()) |
78038e540342
Fix overload resolution issue in dmd bug 313/314 fix.
Christian Kamm <kamm incasoftware de>
parents:
1147
diff
changeset
|
764 s = NULL; |
626
e83ba4ae4878
Fix import visibility bugs 313 and 314.
Christian Kamm <kamm incasoftware de>
parents:
443
diff
changeset
|
765 |
159 | 766 if (s) |
767 { | |
768 //printf("\ts = '%s.%s'\n",toChars(),s->toChars()); | |
769 } | |
770 else if (imports) | |
771 { | |
772 // Look in imported modules | |
336 | 773 for (int i = 0; i < imports->dim; i++) |
159 | 774 { ScopeDsymbol *ss = (ScopeDsymbol *)imports->data[i]; |
775 Dsymbol *s2; | |
776 | |
777 // If private import, don't search it | |
778 if (flags & 1 && prots[i] == PROTprivate) | |
779 continue; | |
780 | |
781 //printf("\tscanning import '%s', prots = %d, isModule = %p, isImport = %p\n", ss->toChars(), prots[i], ss->isModule(), ss->isImport()); | |
336 | 782 /* Don't find private members if ss is a module |
783 */ | |
159 | 784 s2 = ss->search(loc, ident, ss->isModule() ? 1 : 0); |
785 if (!s) | |
786 s = s2; | |
787 else if (s2 && s != s2) | |
788 { | |
789 if (s->toAlias() == s2->toAlias()) | |
790 { | |
336 | 791 /* After following aliases, we found the same symbol, |
792 * so it's not an ambiguity. | |
793 * But if one alias is deprecated, prefer the other. | |
794 */ | |
159 | 795 if (s->isDeprecated()) |
796 s = s2; | |
797 } | |
798 else | |
799 { | |
800 /* Two imports of the same module should be regarded as | |
801 * the same. | |
802 */ | |
803 Import *i1 = s->isImport(); | |
804 Import *i2 = s2->isImport(); | |
805 if (!(i1 && i2 && | |
806 (i1->mod == i2->mod || | |
807 (!i1->parent->isImport() && !i2->parent->isImport() && | |
808 i1->ident->equals(i2->ident)) | |
809 ) | |
810 ) | |
811 ) | |
812 { | |
813 ss->multiplyDefined(loc, s, s2); | |
814 break; | |
815 } | |
816 } | |
817 } | |
818 } | |
819 if (s) | |
820 { | |
821 Declaration *d = s->isDeclaration(); | |
822 if (d && d->protection == PROTprivate && !d->parent->isTemplateMixin()) | |
823 error("%s is private", d->toPrettyChars()); | |
824 } | |
825 } | |
826 return s; | |
827 } | |
828 | |
829 void ScopeDsymbol::importScope(ScopeDsymbol *s, enum PROT protection) | |
830 { | |
831 //printf("%s->ScopeDsymbol::importScope(%s, %d)\n", toChars(), s->toChars(), protection); | |
832 | |
833 // No circular or redundant import's | |
834 if (s != this) | |
835 { | |
836 if (!imports) | |
837 imports = new Array(); | |
838 else | |
839 { | |
840 for (int i = 0; i < imports->dim; i++) | |
841 { ScopeDsymbol *ss; | |
842 | |
843 ss = (ScopeDsymbol *) imports->data[i]; | |
1587 | 844 if (ss == s) // if already imported |
159 | 845 { |
846 if (protection > prots[i]) | |
847 prots[i] = protection; // upgrade access | |
848 return; | |
849 } | |
850 } | |
851 } | |
852 imports->push(s); | |
853 prots = (unsigned char *)mem.realloc(prots, imports->dim * sizeof(prots[0])); | |
854 prots[imports->dim - 1] = protection; | |
855 } | |
856 } | |
857 | |
858 int ScopeDsymbol::isforwardRef() | |
859 { | |
860 return (members == NULL); | |
861 } | |
862 | |
863 void ScopeDsymbol::defineRef(Dsymbol *s) | |
864 { | |
865 ScopeDsymbol *ss; | |
866 | |
867 ss = s->isScopeDsymbol(); | |
868 members = ss->members; | |
869 ss->members = NULL; | |
870 } | |
871 | |
872 void ScopeDsymbol::multiplyDefined(Loc loc, Dsymbol *s1, Dsymbol *s2) | |
873 { | |
874 #if 0 | |
875 printf("ScopeDsymbol::multiplyDefined()\n"); | |
876 printf("s1 = %p, '%s' kind = '%s', parent = %s\n", s1, s1->toChars(), s1->kind(), s1->parent ? s1->parent->toChars() : ""); | |
877 printf("s2 = %p, '%s' kind = '%s', parent = %s\n", s2, s2->toChars(), s2->kind(), s2->parent ? s2->parent->toChars() : ""); | |
878 #endif | |
879 if (loc.filename) | |
880 { ::error(loc, "%s at %s conflicts with %s at %s", | |
881 s1->toPrettyChars(), | |
882 s1->locToChars(), | |
883 s2->toPrettyChars(), | |
884 s2->locToChars()); | |
885 } | |
886 else | |
887 { | |
888 s1->error(loc, "conflicts with %s %s at %s", | |
889 s2->kind(), | |
890 s2->toPrettyChars(), | |
891 s2->locToChars()); | |
892 } | |
893 } | |
894 | |
895 Dsymbol *ScopeDsymbol::nameCollision(Dsymbol *s) | |
896 { | |
897 Dsymbol *sprev; | |
898 | |
899 // Look to see if we are defining a forward referenced symbol | |
900 | |
901 sprev = symtab->lookup(s->ident); | |
902 assert(sprev); | |
903 if (s->equals(sprev)) // if the same symbol | |
904 { | |
905 if (s->isforwardRef()) // if second declaration is a forward reference | |
906 return sprev; | |
907 if (sprev->isforwardRef()) | |
908 { | |
909 sprev->defineRef(s); // copy data from s into sprev | |
910 return sprev; | |
911 } | |
912 } | |
913 multiplyDefined(0, s, sprev); | |
914 return sprev; | |
915 } | |
916 | |
336 | 917 const char *ScopeDsymbol::kind() |
159 | 918 { |
919 return "ScopeDsymbol"; | |
920 } | |
921 | |
1587 | 922 Dsymbol *ScopeDsymbol::symtabInsert(Dsymbol *s) |
923 { | |
924 return symtab->insert(s); | |
925 } | |
926 | |
927 /*************************************** | |
928 * Determine number of Dsymbols, folding in AttribDeclaration members. | |
929 */ | |
930 | |
931 #if DMDV2 | |
932 size_t ScopeDsymbol::dim(Array *members) | |
933 { | |
934 size_t n = 0; | |
935 if (members) | |
936 { | |
937 for (size_t i = 0; i < members->dim; i++) | |
938 { Dsymbol *s = (Dsymbol *)members->data[i]; | |
939 AttribDeclaration *a = s->isAttribDeclaration(); | |
940 | |
941 if (a) | |
942 { | |
943 n += dim(a->decl); | |
944 } | |
945 else | |
946 n++; | |
947 } | |
948 } | |
949 return n; | |
950 } | |
951 #endif | |
952 | |
953 /*************************************** | |
954 * Get nth Dsymbol, folding in AttribDeclaration members. | |
955 * Returns: | |
956 * Dsymbol* nth Dsymbol | |
957 * NULL not found, *pn gets incremented by the number | |
958 * of Dsymbols | |
959 */ | |
960 | |
961 #if DMDV2 | |
962 Dsymbol *ScopeDsymbol::getNth(Array *members, size_t nth, size_t *pn) | |
963 { | |
964 if (!members) | |
965 return NULL; | |
966 | |
967 size_t n = 0; | |
968 for (size_t i = 0; i < members->dim; i++) | |
969 { Dsymbol *s = (Dsymbol *)members->data[i]; | |
970 AttribDeclaration *a = s->isAttribDeclaration(); | |
971 | |
972 if (a) | |
973 { | |
974 s = getNth(a->decl, nth - n, &n); | |
975 if (s) | |
976 return s; | |
977 } | |
978 else if (n == nth) | |
979 return s; | |
980 else | |
981 n++; | |
982 } | |
983 | |
984 if (pn) | |
985 *pn += n; | |
986 return NULL; | |
987 } | |
988 #endif | |
159 | 989 |
990 /******************************************* | |
991 * Look for member of the form: | |
992 * const(MemberInfo)[] getMembers(string); | |
993 * Returns NULL if not found | |
994 */ | |
995 | |
336 | 996 #if DMDV2 |
159 | 997 FuncDeclaration *ScopeDsymbol::findGetMembers() |
998 { | |
999 Dsymbol *s = search_function(this, Id::getmembers); | |
1000 FuncDeclaration *fdx = s ? s->isFuncDeclaration() : NULL; | |
1001 | |
1002 #if 0 // Finish | |
1003 static TypeFunction *tfgetmembers; | |
1004 | |
1005 if (!tfgetmembers) | |
1006 { | |
1007 Scope sc; | |
1008 Arguments *arguments = new Arguments; | |
1009 Arguments *arg = new Argument(STCin, Type::tchar->constOf()->arrayOf(), NULL, NULL); | |
1010 arguments->push(arg); | |
1011 | |
1012 Type *tret = NULL; | |
1013 tfgetmembers = new TypeFunction(arguments, tret, 0, LINKd); | |
1014 tfgetmembers = (TypeFunction *)tfgetmembers->semantic(0, &sc); | |
1015 } | |
1016 if (fdx) | |
1017 fdx = fdx->overloadExactMatch(tfgetmembers); | |
1018 #endif | |
1019 if (fdx && fdx->isVirtual()) | |
1020 fdx = NULL; | |
1021 | |
1022 return fdx; | |
1023 } | |
1024 #endif | |
1025 | |
1026 | |
1027 /****************************** WithScopeSymbol ******************************/ | |
1028 | |
1029 WithScopeSymbol::WithScopeSymbol(WithStatement *withstate) | |
1030 : ScopeDsymbol() | |
1031 { | |
1032 this->withstate = withstate; | |
1033 } | |
1034 | |
1035 Dsymbol *WithScopeSymbol::search(Loc loc, Identifier *ident, int flags) | |
1036 { | |
1037 // Acts as proxy to the with class declaration | |
1038 return withstate->exp->type->toDsymbol(NULL)->search(loc, ident, 0); | |
1039 } | |
1040 | |
1041 /****************************** ArrayScopeSymbol ******************************/ | |
1042 | |
1043 ArrayScopeSymbol::ArrayScopeSymbol(Expression *e) | |
1044 : ScopeDsymbol() | |
1045 { | |
1046 assert(e->op == TOKindex || e->op == TOKslice); | |
1047 exp = e; | |
1048 type = NULL; | |
1049 td = NULL; | |
1050 } | |
1051 | |
1052 ArrayScopeSymbol::ArrayScopeSymbol(TypeTuple *t) | |
1053 : ScopeDsymbol() | |
1054 { | |
1055 exp = NULL; | |
1056 type = t; | |
1057 td = NULL; | |
1058 } | |
1059 | |
1060 ArrayScopeSymbol::ArrayScopeSymbol(TupleDeclaration *s) | |
1061 : ScopeDsymbol() | |
1062 { | |
1063 exp = NULL; | |
1064 type = NULL; | |
1065 td = s; | |
1066 } | |
1067 | |
1068 Dsymbol *ArrayScopeSymbol::search(Loc loc, Identifier *ident, int flags) | |
1069 { | |
1070 //printf("ArrayScopeSymbol::search('%s', flags = %d)\n", ident->toChars(), flags); | |
1071 if (ident == Id::length || ident == Id::dollar) | |
1072 { VarDeclaration **pvar; | |
1073 Expression *ce; | |
1074 | |
1075 L1: | |
1076 | |
1077 if (td) | |
1587 | 1078 { /* $ gives the number of elements in the tuple |
1079 */ | |
159 | 1080 VarDeclaration *v = new VarDeclaration(loc, Type::tsize_t, Id::dollar, NULL); |
1081 Expression *e = new IntegerExp(0, td->objects->dim, Type::tsize_t); | |
1082 v->init = new ExpInitializer(0, e); | |
1083 v->storage_class |= STCconst; | |
1084 return v; | |
1085 } | |
1086 | |
1087 if (type) | |
1587 | 1088 { /* $ gives the number of type entries in the type tuple |
1089 */ | |
159 | 1090 VarDeclaration *v = new VarDeclaration(loc, Type::tsize_t, Id::dollar, NULL); |
1091 Expression *e = new IntegerExp(0, type->arguments->dim, Type::tsize_t); | |
1092 v->init = new ExpInitializer(0, e); | |
1093 v->storage_class |= STCconst; | |
1094 return v; | |
1095 } | |
1096 | |
1097 if (exp->op == TOKindex) | |
1587 | 1098 { /* array[index] where index is some function of $ |
1099 */ | |
159 | 1100 IndexExp *ie = (IndexExp *)exp; |
1101 | |
1102 pvar = &ie->lengthVar; | |
1103 ce = ie->e1; | |
1104 } | |
1105 else if (exp->op == TOKslice) | |
1587 | 1106 { /* array[lwr .. upr] where lwr or upr is some function of $ |
1107 */ | |
159 | 1108 SliceExp *se = (SliceExp *)exp; |
1109 | |
1110 pvar = &se->lengthVar; | |
1111 ce = se->e1; | |
1112 } | |
1113 else | |
1587 | 1114 /* Didn't find $, look in enclosing scope(s). |
1115 */ | |
159 | 1116 return NULL; |
1117 | |
1587 | 1118 /* If we are indexing into an array that is really a type |
1119 * tuple, rewrite this as an index into a type tuple and | |
1120 * try again. | |
1121 */ | |
159 | 1122 if (ce->op == TOKtype) |
1123 { | |
1124 Type *t = ((TypeExp *)ce)->type; | |
1125 if (t->ty == Ttuple) | |
1126 { type = (TypeTuple *)t; | |
1127 goto L1; | |
1128 } | |
1129 } | |
1130 | |
1587 | 1131 /* *pvar is lazily initialized, so if we refer to $ |
1132 * multiple times, it gets set only once. | |
1133 */ | |
1134 if (!*pvar) // if not already initialized | |
1135 { /* Create variable v and set it to the value of $, | |
1136 * which will be a constant. | |
1137 */ | |
159 | 1138 VarDeclaration *v = new VarDeclaration(loc, Type::tsize_t, Id::dollar, NULL); |
1139 | |
1140 if (ce->op == TOKstring) | |
1141 { /* It is for a string literal, so the | |
1142 * length will be a const. | |
1143 */ | |
1144 Expression *e = new IntegerExp(0, ((StringExp *)ce)->len, Type::tsize_t); | |
1145 v->init = new ExpInitializer(0, e); | |
1146 v->storage_class |= STCconst; | |
1147 } | |
1148 else if (ce->op == TOKarrayliteral) | |
1149 { /* It is for an array literal, so the | |
1150 * length will be a const. | |
1151 */ | |
1152 Expression *e = new IntegerExp(0, ((ArrayLiteralExp *)ce)->elements->dim, Type::tsize_t); | |
1153 v->init = new ExpInitializer(0, e); | |
1154 v->storage_class |= STCconst; | |
1155 } | |
1156 else if (ce->op == TOKtuple) | |
1157 { /* It is for an expression tuple, so the | |
1158 * length will be a const. | |
1159 */ | |
1160 Expression *e = new IntegerExp(0, ((TupleExp *)ce)->exps->dim, Type::tsize_t); | |
1161 v->init = new ExpInitializer(0, e); | |
1162 v->storage_class |= STCconst; | |
1163 } | |
1164 *pvar = v; | |
1165 } | |
1166 return (*pvar); | |
1167 } | |
1168 return NULL; | |
1169 } | |
1170 | |
1171 | |
1172 /****************************** DsymbolTable ******************************/ | |
1173 | |
1174 DsymbolTable::DsymbolTable() | |
1175 { | |
1176 tab = new StringTable; | |
1177 } | |
1178 | |
1179 DsymbolTable::~DsymbolTable() | |
1180 { | |
1181 delete tab; | |
1182 } | |
1183 | |
1184 Dsymbol *DsymbolTable::lookup(Identifier *ident) | |
1587 | 1185 { |
159 | 1186 #ifdef DEBUG |
1187 assert(ident); | |
1188 assert(tab); | |
1189 #endif | |
1587 | 1190 StringValue *sv = tab->lookup((char*)ident->string, ident->len); |
159 | 1191 return (Dsymbol *)(sv ? sv->ptrvalue : NULL); |
1192 } | |
1193 | |
1194 Dsymbol *DsymbolTable::insert(Dsymbol *s) | |
1195 { StringValue *sv; | |
1196 Identifier *ident; | |
1197 | |
1198 //printf("DsymbolTable::insert(this = %p, '%s')\n", this, s->ident->toChars()); | |
1199 ident = s->ident; | |
1200 #ifdef DEBUG | |
1201 assert(ident); | |
1202 assert(tab); | |
1203 #endif | |
1204 sv = tab->insert(ident->toChars(), ident->len); | |
1205 if (!sv) | |
1206 return NULL; // already in table | |
1207 sv->ptrvalue = s; | |
1208 return s; | |
1209 } | |
1210 | |
1211 Dsymbol *DsymbolTable::insert(Identifier *ident, Dsymbol *s) | |
1212 { StringValue *sv; | |
1213 | |
1214 //printf("DsymbolTable::insert()\n"); | |
1215 sv = tab->insert(ident->toChars(), ident->len); | |
1216 if (!sv) | |
1217 return NULL; // already in table | |
1218 sv->ptrvalue = s; | |
1219 return s; | |
1220 } | |
1221 | |
1222 Dsymbol *DsymbolTable::update(Dsymbol *s) | |
1223 { StringValue *sv; | |
1224 Identifier *ident; | |
1225 | |
1226 ident = s->ident; | |
1227 sv = tab->update(ident->toChars(), ident->len); | |
1228 sv->ptrvalue = s; | |
1229 return s; | |
1230 } | |
1231 | |
1232 | |
1233 | |
1234 |