diff options
author | Douglas Gregor <dgregor@apple.com> | 2008-11-17 20:34:05 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2008-11-17 20:34:05 +0000 |
commit | 2def48394f6d48bde0dec2b514193c2b533265b5 (patch) | |
tree | cdcb2c59ee38761e2b9be2fb3f649f4a7c6118ed /lib/Sema/IdentifierResolver.cpp | |
parent | ca354faa7e9b99af17070c82b9662a5fca76422c (diff) |
Updated IdentifierResolver to deal with DeclarationNames. The names of
C++ constructors, destructors, and conversion functions now have a
FETokenInfo field that IdentifierResolver can access, so that these
special names are handled just like ordinary identifiers. A few other
Sema routines now use DeclarationNames instead of IdentifierInfo*'s.
To validate this design, this code also implements parsing and
semantic analysis for id-expressions that name conversion functions,
e.g.,
return operator bool();
The new parser action ActOnConversionFunctionExpr takes the result of
parsing "operator type-id" and turning it into an expression, using
the IdentifierResolver with the DeclarationName of the conversion
function. ActOnDeclarator pushes those conversion function names into
scope so that the IdentifierResolver can find them, of course.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59462 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/IdentifierResolver.cpp')
-rw-r--r-- | lib/Sema/IdentifierResolver.cpp | 51 |
1 files changed, 25 insertions, 26 deletions
diff --git a/lib/Sema/IdentifierResolver.cpp b/lib/Sema/IdentifierResolver.cpp index 82f95bf108..cf0342fe1b 100644 --- a/lib/Sema/IdentifierResolver.cpp +++ b/lib/Sema/IdentifierResolver.cpp @@ -8,7 +8,7 @@ //===----------------------------------------------------------------------===// // // This file implements the IdentifierResolver class, which is used for lexical -// scoped lookup, based on identifier. +// scoped lookup, based on declaration names. // //===----------------------------------------------------------------------===// @@ -23,7 +23,7 @@ using namespace clang; // IdDeclInfoMap class //===----------------------------------------------------------------------===// -/// IdDeclInfoMap - Associates IdDeclInfos with Identifiers. +/// IdDeclInfoMap - Associates IdDeclInfos with declaration names. /// Allocates 'pools' (vectors of IdDeclInfos) to avoid allocating each /// individual IdDeclInfo to heap. class IdentifierResolver::IdDeclInfoMap { @@ -36,9 +36,9 @@ class IdentifierResolver::IdDeclInfoMap { public: IdDeclInfoMap() : CurIndex(VECTOR_SIZE) {} - /// Returns the IdDeclInfo associated to the IdentifierInfo. + /// Returns the IdDeclInfo associated to the DeclarationName. /// It creates a new IdDeclInfo if one was not created before for this id. - IdDeclInfo &operator[](IdentifierInfo *II); + IdDeclInfo &operator[](DeclarationName Name); }; @@ -173,19 +173,19 @@ bool IdentifierResolver::isDeclInScope(Decl *D, DeclContext *Ctx, /// AddDecl - Link the decl to its shadowed decl chain. void IdentifierResolver::AddDecl(NamedDecl *D) { - IdentifierInfo *II = D->getIdentifier(); - void *Ptr = II->getFETokenInfo<void>(); + DeclarationName Name = D->getDeclName(); + void *Ptr = Name.getFETokenInfo<void>(); if (!Ptr) { - II->setFETokenInfo(D); + Name.setFETokenInfo(D); return; } IdDeclInfo *IDI; if (isDeclPtr(Ptr)) { - II->setFETokenInfo(NULL); - IDI = &(*IdDeclInfos)[II]; + Name.setFETokenInfo(NULL); + IDI = &(*IdDeclInfos)[Name]; NamedDecl *PrevD = static_cast<NamedDecl*>(Ptr); IDI->AddDecl(PrevD); } else @@ -198,18 +198,18 @@ void IdentifierResolver::AddDecl(NamedDecl *D) { /// after the decl that the iterator points to, thus the 'Shadow' decl will be /// encountered before the 'D' decl. void IdentifierResolver::AddShadowedDecl(NamedDecl *D, NamedDecl *Shadow) { - assert(D->getIdentifier() == Shadow->getIdentifier() && "Different ids!"); + assert(D->getDeclName() == Shadow->getDeclName() && "Different ids!"); assert(LookupContext(D) == LookupContext(Shadow) && "Different context!"); - IdentifierInfo *II = D->getIdentifier(); - void *Ptr = II->getFETokenInfo<void>(); + DeclarationName Name = D->getDeclName(); + void *Ptr = Name.getFETokenInfo<void>(); assert(Ptr && "No decl from Ptr ?"); IdDeclInfo *IDI; if (isDeclPtr(Ptr)) { - II->setFETokenInfo(NULL); - IDI = &(*IdDeclInfos)[II]; + Name.setFETokenInfo(NULL); + IDI = &(*IdDeclInfos)[Name]; NamedDecl *PrevD = static_cast<NamedDecl*>(Ptr); assert(PrevD == Shadow && "Invalid shadow decl ?"); IDI->AddDecl(D); @@ -225,29 +225,29 @@ void IdentifierResolver::AddShadowedDecl(NamedDecl *D, NamedDecl *Shadow) { /// The decl must already be part of the decl chain. void IdentifierResolver::RemoveDecl(NamedDecl *D) { assert(D && "null param passed"); - IdentifierInfo *II = D->getIdentifier(); - void *Ptr = II->getFETokenInfo<void>(); + DeclarationName Name = D->getDeclName(); + void *Ptr = Name.getFETokenInfo<void>(); assert(Ptr && "Didn't find this decl on its identifier's chain!"); if (isDeclPtr(Ptr)) { assert(D == Ptr && "Didn't find this decl on its identifier's chain!"); - II->setFETokenInfo(NULL); + Name.setFETokenInfo(NULL); return; } return toIdDeclInfo(Ptr)->RemoveDecl(D); } -/// begin - Returns an iterator for decls of identifier 'II', starting at +/// begin - Returns an iterator for decls with name 'Name', starting at /// declaration context 'Ctx'. If 'LookInParentCtx' is true, it will walk the /// decls of parent declaration contexts too. IdentifierResolver::iterator -IdentifierResolver::begin(const IdentifierInfo *II, const DeclContext *Ctx, +IdentifierResolver::begin(DeclarationName Name, const DeclContext *Ctx, bool LookInParentCtx) { assert(Ctx && "null param passed"); - void *Ptr = II->getFETokenInfo<void>(); + void *Ptr = Name.getFETokenInfo<void>(); if (!Ptr) return end(); LookupContext LC(Ctx); @@ -284,7 +284,7 @@ IdentifierResolver::begin(const IdentifierInfo *II, const DeclContext *Ctx, void IdentifierResolver::iterator::PreIncIter() { NamedDecl *D = **this; LookupContext Ctx(D); - void *InfoPtr = D->getIdentifier()->getFETokenInfo<void>(); + void *InfoPtr = D->getDeclName().getFETokenInfo<void>(); assert(!isDeclPtr(InfoPtr) && "Decl with wrong id ?"); IdDeclInfo *Info = toIdDeclInfo(InfoPtr); @@ -310,12 +310,11 @@ void IdentifierResolver::iterator::PreIncIter() { // IdDeclInfoMap Implementation //===----------------------------------------------------------------------===// -/// Returns the IdDeclInfo associated to the IdentifierInfo. +/// Returns the IdDeclInfo associated to the DeclarationName. /// It creates a new IdDeclInfo if one was not created before for this id. IdentifierResolver::IdDeclInfo & -IdentifierResolver::IdDeclInfoMap::operator[](IdentifierInfo *II) { - assert (II && "null IdentifierInfo passed"); - void *Ptr = II->getFETokenInfo<void>(); +IdentifierResolver::IdDeclInfoMap::operator[](DeclarationName Name) { + void *Ptr = Name.getFETokenInfo<void>(); if (Ptr) return *toIdDeclInfo(Ptr); @@ -327,7 +326,7 @@ IdentifierResolver::IdDeclInfoMap::operator[](IdentifierInfo *II) { CurIndex = 0; } IdDeclInfo *IDI = &IDIVecs.back()[CurIndex]; - II->setFETokenInfo(reinterpret_cast<void*>( + Name.setFETokenInfo(reinterpret_cast<void*>( reinterpret_cast<uintptr_t>(IDI) | 0x1) ); ++CurIndex; |