Mercurial > projects > ldc
comparison dmd/dsymbol.c @ 336:aaade6ded589 trunk
[svn r357] Merged DMD 1.033
author | lindquist |
---|---|
date | Sat, 12 Jul 2008 19:38:31 +0200 |
parents | 5acec6b2eef8 |
children | f1d37dc5d354 |
comparison
equal
deleted
inserted
replaced
335:17b844102023 | 336:aaade6ded589 |
---|---|
1 | 1 |
2 // Compiler implementation of the D programming language | 2 // Compiler implementation of the D programming language |
3 // Copyright (c) 1999-2007 by Digital Mars | 3 // Copyright (c) 1999-2008 by Digital Mars |
4 // All Rights Reserved | 4 // All Rights Reserved |
5 // written by Walter Bright | 5 // written by Walter Bright |
6 // http://www.digitalmars.com | 6 // http://www.digitalmars.com |
7 // License for redistribution is by either the Artistic License | 7 // License for redistribution is by either the Artistic License |
8 // in artistic.txt, or the GNU General Public License in gnu.txt. | 8 // in artistic.txt, or the GNU General Public License in gnu.txt. |
199 if (m && m->srcfile) | 199 if (m && m->srcfile) |
200 loc.filename = m->srcfile->toChars(); | 200 loc.filename = m->srcfile->toChars(); |
201 return loc.toChars(); | 201 return loc.toChars(); |
202 } | 202 } |
203 | 203 |
204 char *Dsymbol::kind() | 204 const char *Dsymbol::kind() |
205 { | 205 { |
206 return "symbol"; | 206 return "symbol"; |
207 } | 207 } |
208 | 208 |
209 /********************************* | 209 /********************************* |
242 while (s && s->isTemplateInstance()) | 242 while (s && s->isTemplateInstance()) |
243 s = s->parent; | 243 s = s->parent; |
244 return s; | 244 return s; |
245 } | 245 } |
246 | 246 |
247 TemplateInstance *Dsymbol::inTemplateInstance() | |
248 { | |
249 for (Dsymbol *parent = this->parent; parent; parent = parent->parent) | |
250 { | |
251 TemplateInstance *ti = parent->isTemplateInstance(); | |
252 if (ti) | |
253 return ti; | |
254 } | |
255 return NULL; | |
256 } | |
247 | 257 |
248 int Dsymbol::isAnonymous() | 258 int Dsymbol::isAnonymous() |
249 { | 259 { |
250 return ident ? 0 : 1; | 260 return ident ? 0 : 1; |
251 } | 261 } |
267 | 277 |
268 void Dsymbol::inlineScan() | 278 void Dsymbol::inlineScan() |
269 { | 279 { |
270 // Most Dsymbols have no further semantic analysis needed | 280 // Most Dsymbols have no further semantic analysis needed |
271 } | 281 } |
282 | |
283 /********************************************* | |
284 * Search for ident as member of s. | |
285 * Input: | |
286 * flags: 1 don't find private members | |
287 * 2 don't give error messages | |
288 * 4 return NULL if ambiguous | |
289 * Returns: | |
290 * NULL if not found | |
291 */ | |
272 | 292 |
273 Dsymbol *Dsymbol::search(Loc loc, Identifier *ident, int flags) | 293 Dsymbol *Dsymbol::search(Loc loc, Identifier *ident, int flags) |
274 { | 294 { |
275 //printf("Dsymbol::search(this=%p,%s, ident='%s')\n", this, toChars(), ident->toChars()); | 295 //printf("Dsymbol::search(this=%p,%s, ident='%s')\n", this, toChars(), ident->toChars()); |
276 return NULL; | 296 return NULL; |
387 return NULL; | 407 return NULL; |
388 } | 408 } |
389 | 409 |
390 AggregateDeclaration *Dsymbol::isMember() // is this a member of an AggregateDeclaration? | 410 AggregateDeclaration *Dsymbol::isMember() // is this a member of an AggregateDeclaration? |
391 { | 411 { |
412 //printf("Dsymbol::isMember() %s\n", toChars()); | |
392 Dsymbol *parent = toParent(); | 413 Dsymbol *parent = toParent(); |
414 //printf("parent is %s %s\n", parent->kind(), parent->toChars()); | |
393 return parent ? parent->isAggregateDeclaration() : NULL; | 415 return parent ? parent->isAggregateDeclaration() : NULL; |
394 } | 416 } |
395 | 417 |
396 Type *Dsymbol::getType() | 418 Type *Dsymbol::getType() |
397 { | 419 { |
499 } | 521 } |
500 | 522 |
501 for (; sc; sc = sc->enclosing) | 523 for (; sc; sc = sc->enclosing) |
502 { | 524 { |
503 if (sc->scopesym && sc->scopesym->isDeprecated()) | 525 if (sc->scopesym && sc->scopesym->isDeprecated()) |
526 return; | |
527 | |
528 // If inside a StorageClassDeclaration that is deprecated | |
529 if (sc->stc & STCdeprecated) | |
504 return; | 530 return; |
505 } | 531 } |
506 | 532 |
507 error(loc, "is deprecated"); | 533 error(loc, "is deprecated"); |
508 } | 534 } |
615 sd->members = arraySyntaxCopy(members); | 641 sd->members = arraySyntaxCopy(members); |
616 return sd; | 642 return sd; |
617 } | 643 } |
618 | 644 |
619 Dsymbol *ScopeDsymbol::search(Loc loc, Identifier *ident, int flags) | 645 Dsymbol *ScopeDsymbol::search(Loc loc, Identifier *ident, int flags) |
620 { Dsymbol *s; | 646 { |
621 int i; | |
622 | |
623 //printf("%s->ScopeDsymbol::search(ident='%s', flags=x%x)\n", toChars(), ident->toChars(), flags); | 647 //printf("%s->ScopeDsymbol::search(ident='%s', flags=x%x)\n", toChars(), ident->toChars(), flags); |
648 | |
624 // Look in symbols declared in this module | 649 // Look in symbols declared in this module |
625 s = symtab ? symtab->lookup(ident) : NULL; | 650 Dsymbol *s = symtab ? symtab->lookup(ident) : NULL; |
626 if (s) | 651 if (s) |
627 { | 652 { |
628 //printf("\ts = '%s.%s'\n",toChars(),s->toChars()); | 653 //printf("\ts = '%s.%s'\n",toChars(),s->toChars()); |
629 } | 654 } |
630 else if (imports) | 655 else if (imports) |
631 { | 656 { |
632 // Look in imported modules | 657 // Look in imported modules |
633 for (i = 0; i < imports->dim; i++) | 658 for (int i = 0; i < imports->dim; i++) |
634 { ScopeDsymbol *ss = (ScopeDsymbol *)imports->data[i]; | 659 { ScopeDsymbol *ss = (ScopeDsymbol *)imports->data[i]; |
635 Dsymbol *s2; | 660 Dsymbol *s2; |
636 | 661 |
637 // If private import, don't search it | 662 // If private import, don't search it |
638 if (flags & 1 && prots[i] == PROTprivate) | 663 if (flags & 1 && prots[i] == PROTprivate) |
639 continue; | 664 continue; |
640 | 665 |
641 //printf("\tscanning import '%s', prots = %d, isModule = %p, isImport = %p\n", ss->toChars(), prots[i], ss->isModule(), ss->isImport()); | 666 //printf("\tscanning import '%s', prots = %d, isModule = %p, isImport = %p\n", ss->toChars(), prots[i], ss->isModule(), ss->isImport()); |
667 /* Don't find private members if ss is a module | |
668 */ | |
642 s2 = ss->search(loc, ident, ss->isModule() ? 1 : 0); | 669 s2 = ss->search(loc, ident, ss->isModule() ? 1 : 0); |
643 if (!s) | 670 if (!s) |
644 s = s2; | 671 s = s2; |
645 else if (s2 && s != s2) | 672 else if (s2 && s != s2) |
646 { | 673 { |
647 if (s->toAlias() == s2->toAlias()) | 674 if (s->toAlias() == s2->toAlias()) |
648 { | 675 { |
676 /* After following aliases, we found the same symbol, | |
677 * so it's not an ambiguity. | |
678 * But if one alias is deprecated, prefer the other. | |
679 */ | |
649 if (s->isDeprecated()) | 680 if (s->isDeprecated()) |
650 s = s2; | 681 s = s2; |
651 } | 682 } |
652 else | 683 else |
653 { | 684 { |
766 } | 797 } |
767 multiplyDefined(0, s, sprev); | 798 multiplyDefined(0, s, sprev); |
768 return sprev; | 799 return sprev; |
769 } | 800 } |
770 | 801 |
771 char *ScopeDsymbol::kind() | 802 const char *ScopeDsymbol::kind() |
772 { | 803 { |
773 return "ScopeDsymbol"; | 804 return "ScopeDsymbol"; |
774 } | 805 } |
775 | 806 |
776 | 807 |
778 * Look for member of the form: | 809 * Look for member of the form: |
779 * const(MemberInfo)[] getMembers(string); | 810 * const(MemberInfo)[] getMembers(string); |
780 * Returns NULL if not found | 811 * Returns NULL if not found |
781 */ | 812 */ |
782 | 813 |
783 #if V2 | 814 #if DMDV2 |
784 FuncDeclaration *ScopeDsymbol::findGetMembers() | 815 FuncDeclaration *ScopeDsymbol::findGetMembers() |
785 { | 816 { |
786 Dsymbol *s = search_function(this, Id::getmembers); | 817 Dsymbol *s = search_function(this, Id::getmembers); |
787 FuncDeclaration *fdx = s ? s->isFuncDeclaration() : NULL; | 818 FuncDeclaration *fdx = s ? s->isFuncDeclaration() : NULL; |
788 | 819 |