diff options
| author | Douglas Gregor <dgregor@apple.com> | 2008-12-23 21:05:05 +0000 |
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2008-12-23 21:05:05 +0000 |
| commit | 8b9ccca5e5f18910c83b7f12754e8bf446e06b27 (patch) | |
| tree | 436d1fb99b0b8f3a1b83985a1e425917cc5cbbab /clang/lib/AST | |
| parent | 8a35adf3a59e469dee9f63d72ac63261d3ae5289 (diff) | |
| download | bcm5719-llvm-8b9ccca5e5f18910c83b7f12754e8bf446e06b27.tar.gz bcm5719-llvm-8b9ccca5e5f18910c83b7f12754e8bf446e06b27.zip | |
Don't push OverloadedFunctionDecls onto the chain of declarations
attached to an identifier. Instead, all overloaded functions will be
pushed into scope, and we'll synthesize an OverloadedFunctionDecl on
the fly when we need it.
llvm-svn: 61386
Diffstat (limited to 'clang/lib/AST')
| -rw-r--r-- | clang/lib/AST/Decl.cpp | 13 | ||||
| -rw-r--r-- | clang/lib/AST/DeclBase.cpp | 33 |
2 files changed, 23 insertions, 23 deletions
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 3edf8a02efb..bfe0272038f 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -174,6 +174,19 @@ ScopedDecl::~ScopedDecl() { delete getMultipleDC(); } +bool ScopedDecl::declarationReplaces(NamedDecl *OldD) const { + assert(getDeclName() == OldD->getDeclName() && "Declaration name mismatch"); + + if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(this)) + // For function declarations, we keep track of redeclarations. + return FD->getPreviousDeclaration() == OldD; + + // For non-function declarations, if the declarations are of the + // same kind then this must be a redeclaration, or semantic analysis + // would not have given us the new declaration. + return this->getKind() == OldD->getKind(); +} + //===----------------------------------------------------------------------===// // VarDecl Implementation //===----------------------------------------------------------------------===// diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp index 87ebf85b41d..c6b3c53cc42 100644 --- a/clang/lib/AST/DeclBase.cpp +++ b/clang/lib/AST/DeclBase.cpp @@ -17,6 +17,8 @@ #include "clang/AST/ASTContext.h" #include "clang/AST/Type.h" #include "llvm/ADT/DenseMap.h" +#include <algorithm> +#include <functional> #include <vector> using namespace clang; @@ -543,19 +545,6 @@ void DeclContext::insert(ASTContext &Context, ScopedDecl *D) { insertImpl(D); } -static bool isRedeclarationOf(ScopedDecl *D, ScopedDecl *OldD) { - assert(D->getDeclName() == OldD->getDeclName() && "Declaration name mismatch"); - - if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) - // For function declarations, we keep track of redeclarations. - return FD->getPreviousDeclaration() == OldD; - - // For non-function declarations, if the declarations are of the - // same kind then this must be a redeclaration, or semantic analysis - // would not have given us the new declaration. - return D->getKind() == OldD->getKind(); -} - void DeclContext::insertImpl(ScopedDecl *D) { bool MayBeRedeclaration = true; @@ -591,7 +580,7 @@ void DeclContext::insertImpl(ScopedDecl *D) { if (Array[LastMatch]->getDeclName() != D->getDeclName()) break; - if (isRedeclarationOf(D, Array[LastMatch])) { + if (D->declarationReplaces(Array[LastMatch])) { // D is a redeclaration of an existing element in the // array. Replace that element with D. Array[LastMatch] = D; @@ -640,15 +629,13 @@ void DeclContext::insertImpl(ScopedDecl *D) { if (Pos != Map->end()) { if (MayBeRedeclaration) { // Determine if this declaration is actually a redeclaration. - for (std::vector<ScopedDecl *>::iterator I = Pos->second.begin(), - IEnd = Pos->second.end(); - I != IEnd; ++I) { - if (isRedeclarationOf(D, *I)) { - // D is a redeclaration of *I. Replace *I with D and we're - // done. - *I = D; - return; - } + std::vector<ScopedDecl *>::iterator Redecl + = std::find_if(Pos->second.begin(), Pos->second.end(), + std::bind1st(std::mem_fun(&ScopedDecl::declarationReplaces), + D)); + if (Redecl != Pos->second.end()) { + *Redecl = D; + return; } } |

