diff options
author | Chris Lattner <sabre@nondot.org> | 2011-07-18 01:54:02 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2011-07-18 01:54:02 +0000 |
commit | b5f65475d25b67f87e368daa1583b762af7e2e45 (patch) | |
tree | 5561df2d9e07879c274537845f7b64c5c268b074 /lib/Sema/SemaLookup.cpp | |
parent | 8435069798b5621615f9f65c471c7e7808316b20 (diff) |
Use the new llvm::TinyPtrVector class, which implements exactly what
ShadowMapEntry was.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135368 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaLookup.cpp')
-rw-r--r-- | lib/Sema/SemaLookup.cpp | 78 |
1 files changed, 5 insertions, 73 deletions
diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index 0e448e3120..f18b6ecdfe 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/lib/Sema/SemaLookup.cpp @@ -35,6 +35,7 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/StringMap.h" +#include "llvm/ADT/TinyPtrVector.h" #include "llvm/Support/ErrorHandling.h" #include <limits> #include <list> @@ -2530,24 +2531,7 @@ public: /// \brief An entry in the shadow map, which is optimized to store a /// single declaration (the common case) but can also store a list /// of declarations. - class ShadowMapEntry { - typedef llvm::SmallVector<NamedDecl *, 4> DeclVector; - - /// \brief Contains either the solitary NamedDecl * or a vector - /// of declarations. - llvm::PointerUnion<NamedDecl *, DeclVector*> DeclOrVector; - - public: - ShadowMapEntry() : DeclOrVector() { } - - void Add(NamedDecl *ND); - void Destroy(); - - // Iteration. - typedef NamedDecl * const *iterator; - iterator begin(); - iterator end(); - }; + typedef llvm::TinyPtrVector<NamedDecl*> ShadowMapEntry; private: /// \brief A mapping from declaration names to the declarations that have @@ -2581,7 +2565,9 @@ public: NamedDecl *checkHidden(NamedDecl *ND); /// \brief Add a declaration to the current shadow map. - void add(NamedDecl *ND) { ShadowMaps.back()[ND->getDeclName()].Add(ND); } + void add(NamedDecl *ND) { + ShadowMaps.back()[ND->getDeclName()].push_back(ND); + } }; /// \brief RAII object that records when we've entered a shadow context. @@ -2596,66 +2582,12 @@ public: } ~ShadowContextRAII() { - for (ShadowMap::iterator E = Visible.ShadowMaps.back().begin(), - EEnd = Visible.ShadowMaps.back().end(); - E != EEnd; - ++E) - E->second.Destroy(); - Visible.ShadowMaps.pop_back(); } }; } // end anonymous namespace -void VisibleDeclsRecord::ShadowMapEntry::Add(NamedDecl *ND) { - if (DeclOrVector.isNull()) { - // 0 - > 1 elements: just set the single element information. - DeclOrVector = ND; - return; - } - - if (NamedDecl *PrevND = DeclOrVector.dyn_cast<NamedDecl *>()) { - // 1 -> 2 elements: create the vector of results and push in the - // existing declaration. - DeclVector *Vec = new DeclVector; - Vec->push_back(PrevND); - DeclOrVector = Vec; - } - - // Add the new element to the end of the vector. - DeclOrVector.get<DeclVector*>()->push_back(ND); -} - -void VisibleDeclsRecord::ShadowMapEntry::Destroy() { - if (DeclVector *Vec = DeclOrVector.dyn_cast<DeclVector *>()) { - delete Vec; - DeclOrVector = ((NamedDecl *)0); - } -} - -VisibleDeclsRecord::ShadowMapEntry::iterator -VisibleDeclsRecord::ShadowMapEntry::begin() { - if (DeclOrVector.isNull()) - return 0; - - if (DeclOrVector.is<NamedDecl *>()) - return DeclOrVector.getAddrOf<NamedDecl *>(); - - return DeclOrVector.get<DeclVector *>()->begin(); -} - -VisibleDeclsRecord::ShadowMapEntry::iterator -VisibleDeclsRecord::ShadowMapEntry::end() { - if (DeclOrVector.isNull()) - return 0; - - if (DeclOrVector.is<NamedDecl *>()) - return DeclOrVector.getAddrOf<NamedDecl *>() + 1; - - return DeclOrVector.get<DeclVector *>()->end(); -} - NamedDecl *VisibleDeclsRecord::checkHidden(NamedDecl *ND) { // Look through using declarations. ND = ND->getUnderlyingDecl(); |