summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/IdentifierResolver.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2008-04-13 21:07:44 +0000
committerDouglas Gregor <dgregor@apple.com>2008-04-13 21:07:44 +0000
commit83a586ec19dd0db7fe4bc3b8e881173ae07f74f4 (patch)
treeeb1f1dc07b92bcc6b7b1b2ac434ee743a0dee18b /clang/lib/Sema/IdentifierResolver.cpp
parentf8f945499c169b5bb24cfa55d3d22f5bb23cda79 (diff)
downloadbcm5719-llvm-83a586ec19dd0db7fe4bc3b8e881173ae07f74f4.tar.gz
bcm5719-llvm-83a586ec19dd0db7fe4bc3b8e881173ae07f74f4.zip
Introduce support for finding class and enum names via ordinary name lookup in C++
llvm-svn: 49621
Diffstat (limited to 'clang/lib/Sema/IdentifierResolver.cpp')
-rw-r--r--clang/lib/Sema/IdentifierResolver.cpp27
1 files changed, 23 insertions, 4 deletions
diff --git a/clang/lib/Sema/IdentifierResolver.cpp b/clang/lib/Sema/IdentifierResolver.cpp
index 79898e43806..037802c6404 100644
--- a/clang/lib/Sema/IdentifierResolver.cpp
+++ b/clang/lib/Sema/IdentifierResolver.cpp
@@ -15,6 +15,7 @@
#include "IdentifierResolver.h"
#include "clang/Basic/IdentifierTable.h"
#include "clang/AST/Decl.h"
+#include "clang/Parse/Scope.h"
#include <list>
#include <vector>
@@ -113,6 +114,25 @@ void IdentifierResolver::AddDecl(NamedDecl *D, Scope *S) {
} else
IDI = toIdDeclInfo(Ptr);
+ // C++ [basic.scope]p4:
+ // -- exactly one declaration shall declare a class name or
+ // enumeration name that is not a typedef name and the other
+ // declarations shall all refer to the same object or
+ // enumerator, or all refer to functions and function templates;
+ // in this case the class name or enumeration name is hidden.
+ if (isa<TagDecl>(D)) {
+ // We are pushing the name of a tag (enum or class).
+ IdDeclInfo::ShadowedIter TopIter = IDI->shadowed_end() - 1;
+ if (S->isDeclScope(*TopIter)) {
+ // There is already a declaration with the same name in the same
+ // scope. It must be found before we find the new declaration,
+ // so swap the order on the shadowed declaration stack.
+ NamedDecl *Temp = *TopIter;
+ *TopIter = D;
+ D = Temp;
+ }
+ }
+
IDI->PushShadowed(D);
}
@@ -159,16 +179,15 @@ void IdentifierResolver::RemoveDecl(NamedDecl *D) {
/// Lookup - Find the non-shadowed decl that belongs to a particular
/// Decl::IdentifierNamespace.
-NamedDecl *IdentifierResolver::Lookup(const IdentifierInfo *II, unsigned NSI) {
+NamedDecl *IdentifierResolver::Lookup(const IdentifierInfo *II, unsigned NS) {
assert(II && "null param passed");
- Decl::IdentifierNamespace NS = (Decl::IdentifierNamespace)NSI;
void *Ptr = II->getFETokenInfo<void>();
if (!Ptr) return NULL;
if (isDeclPtr(Ptr)) {
NamedDecl *D = static_cast<NamedDecl*>(Ptr);
- return (D->getIdentifierNamespace() == NS) ? D : NULL;
+ return (D->getIdentifierNamespace() & NS) ? D : NULL;
}
IdDeclInfo *IDI = toIdDeclInfo(Ptr);
@@ -178,7 +197,7 @@ NamedDecl *IdentifierResolver::Lookup(const IdentifierInfo *II, unsigned NSI) {
for (IdDeclInfo::ShadowedIter SI = IDI->shadowed_end();
SI != IDI->shadowed_begin(); --SI) {
NamedDecl *D = *(SI-1);
- if (D->getIdentifierNamespace() == NS)
+ if (D->getIdentifierNamespace() & NS)
return D;
}
OpenPOWER on IntegriCloud