aboutsummaryrefslogtreecommitdiff
path: root/lib/AST/DeclBase.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-04-07 17:20:56 +0000
committerDouglas Gregor <dgregor@apple.com>2009-04-07 17:20:56 +0000
commitc2ee10d79f70036af652a395ac1f8273f3d04e12 (patch)
treed6db3c7d97d104967ff017f0687d14bb0e658bb5 /lib/AST/DeclBase.cpp
parent82fc0cb7883747942326d6d6ca1333b27bd647f0 (diff)
Move the internal DeclContext data structures into a separate header.
Simplify the addition of a case statement to a switch. Fix -print-stats for attribute-qualified types. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68522 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/DeclBase.cpp')
-rw-r--r--lib/AST/DeclBase.cpp110
1 files changed, 1 insertions, 109 deletions
diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp
index 0abe047a80..615bf00087 100644
--- a/lib/AST/DeclBase.cpp
+++ b/lib/AST/DeclBase.cpp
@@ -13,6 +13,7 @@
#include "clang/AST/DeclBase.h"
#include "clang/AST/Decl.h"
+#include "clang/AST/DeclContextInternals.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/DeclTemplate.h"
@@ -363,115 +364,6 @@ bool DeclContext::classof(const Decl *D) {
}
}
-/// StoredDeclsList - This is an array of decls optimized a common case of only
-/// containing one entry.
-struct StoredDeclsList {
- /// VectorTy - When in vector form, this is what the Data pointer points to.
- typedef llvm::SmallVector<NamedDecl*, 4> VectorTy;
-
- /// Data - Union of NamedDecl*/VectorTy*.
- llvm::PointerUnion<NamedDecl*, VectorTy*> Data;
-public:
- StoredDeclsList() {}
- StoredDeclsList(const StoredDeclsList &RHS) : Data(RHS.Data) {
- if (isVector())
- Data = new VectorTy(*Data.get<VectorTy*>());
- }
-
- ~StoredDeclsList() {
- // If this is a vector-form, free the vector.
- if (isVector())
- delete Data.get<VectorTy*>();
- }
-
- StoredDeclsList &operator=(const StoredDeclsList &RHS) {
- if (isVector())
- delete Data.get<VectorTy*>();
- Data = RHS.Data;
- if (isVector())
- Data = new VectorTy(*Data.get<VectorTy*>());
- return *this;
- }
-
- bool isVector() const { return Data.is<VectorTy*>(); }
- bool isInline() const { return Data.is<NamedDecl*>(); }
- bool isNull() const { return Data.isNull(); }
-
- void setOnlyValue(NamedDecl *ND) {
- assert(isInline() && "Not inline");
- Data = ND;
- }
-
- /// getLookupResult - Return an array of all the decls that this list
- /// represents.
- DeclContext::lookup_result getLookupResult() {
- // If we have a single inline unit, return it.
- if (isInline()) {
- assert(!isNull() && "Empty list isn't allowed");
-
- // Data is a raw pointer to a NamedDecl*, return it.
- void *Ptr = &Data;
- return DeclContext::lookup_result((NamedDecl**)Ptr, (NamedDecl**)Ptr+1);
- }
-
- // Otherwise, we have a range result.
- VectorTy &V = *Data.get<VectorTy*>();
- return DeclContext::lookup_result(&V[0], &V[0]+V.size());
- }
-
- /// HandleRedeclaration - If this is a redeclaration of an existing decl,
- /// replace the old one with D and return true. Otherwise return false.
- bool HandleRedeclaration(NamedDecl *D) {
- // Most decls only have one entry in their list, special case it.
- if (isInline()) {
- if (!D->declarationReplaces(Data.get<NamedDecl*>()))
- return false;
- setOnlyValue(D);
- return true;
- }
-
- // Determine if this declaration is actually a redeclaration.
- VectorTy &Vec = *Data.get<VectorTy*>();
- VectorTy::iterator RDI
- = std::find_if(Vec.begin(), Vec.end(),
- std::bind1st(std::mem_fun(&NamedDecl::declarationReplaces),
- D));
- if (RDI == Vec.end())
- return false;
- *RDI = D;
- return true;
- }
-
- /// AddSubsequentDecl - This is called on the second and later decl when it is
- /// not a redeclaration to merge it into the appropriate place in our list.
- ///
- void AddSubsequentDecl(NamedDecl *D) {
- // If this is the second decl added to the list, convert this to vector
- // form.
- if (isInline()) {
- NamedDecl *OldD = Data.get<NamedDecl*>();
- VectorTy *VT = new VectorTy();
- VT->push_back(OldD);
- Data = VT;
- }
-
- VectorTy &Vec = *Data.get<VectorTy*>();
- if (isa<UsingDirectiveDecl>(D) ||
- D->getIdentifierNamespace() == Decl::IDNS_Tag)
- Vec.push_back(D);
- else if (Vec.back()->getIdentifierNamespace() == Decl::IDNS_Tag) {
- NamedDecl *TagD = Vec.back();
- Vec.back() = D;
- Vec.push_back(TagD);
- } else
- Vec.push_back(D);
- }
-};
-
-
-
-typedef llvm::DenseMap<DeclarationName, StoredDeclsList> StoredDeclsMap;
-
DeclContext::~DeclContext() {
if (isLookupMap())
delete static_cast<StoredDeclsMap*>(LookupPtr.getPointer());