aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/IdentifierResolver.cpp
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2008-04-12 01:50:47 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2008-04-12 01:50:47 +0000
commit321f278db3405268e8644eb75f4fcf8900e0d09c (patch)
tree97e5e6aee9641417e69c34002f9edfd8ce12d5db /lib/Sema/IdentifierResolver.cpp
parent87f3ff0c27be71cfd0eaf4628eb64538e84ee6ce (diff)
Fixed comments.
Moved IdDeclInfo class to anonymous namespace. Replaced array with a std::vector. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49570 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/IdentifierResolver.cpp')
-rw-r--r--lib/Sema/IdentifierResolver.cpp56
1 files changed, 29 insertions, 27 deletions
diff --git a/lib/Sema/IdentifierResolver.cpp b/lib/Sema/IdentifierResolver.cpp
index eae64384cd..541bc7ddb0 100644
--- a/lib/Sema/IdentifierResolver.cpp
+++ b/lib/Sema/IdentifierResolver.cpp
@@ -7,7 +7,7 @@
//
//===----------------------------------------------------------------------===//
//
-// This file implements the IdentifierResolver class,which is used for lexical
+// This file implements the IdentifierResolver class, which is used for lexical
// scoped lookup, based on identifier.
//
//===----------------------------------------------------------------------===//
@@ -16,17 +16,20 @@
#include "clang/Basic/IdentifierTable.h"
#include "clang/AST/Decl.h"
#include <list>
+#include <vector>
using namespace clang;
+namespace {
+
class IdDeclInfo;
-/// FETokenInfo of an identifier contains a Decl pointer if lower bit == 0
+/// Identifier's FETokenInfo contains a Decl pointer if lower bit == 0.
static inline bool isDeclPtr(void *Ptr) {
return (reinterpret_cast<uintptr_t>(Ptr) & 0x1) == 0;
}
-/// FETokenInfo of an identifier contains a IdDeclInfo pointer if lower bit == 1
+/// Identifier's FETokenInfo contains a IdDeclInfo pointer if lower bit == 1.
static inline IdDeclInfo *toIdDeclInfo(void *Ptr) {
return reinterpret_cast<IdDeclInfo*>(
reinterpret_cast<uintptr_t>(Ptr) & ~0x1
@@ -34,9 +37,10 @@ static inline IdDeclInfo *toIdDeclInfo(void *Ptr) {
}
-/// IdDeclInfo - Keeps track of information about decls associated to a particular
-/// identifier. IdDeclInfos are lazily constructed and assigned to an identifier
-/// the first time a decl with that identifier is shadowed in some scope.
+/// IdDeclInfo - Keeps track of information about decls associated to a
+/// particular identifier. IdDeclInfos are lazily constructed and assigned
+/// to an identifier the first time a decl with that identifier is shadowed
+/// in some scope.
class IdDeclInfo {
typedef llvm::SmallVector<NamedDecl *, 2> ShadowedTy;
ShadowedTy ShadowedDecls;
@@ -47,13 +51,13 @@ public:
inline ShadowedIter shadowed_begin() { return ShadowedDecls.begin(); }
inline ShadowedIter shadowed_end() { return ShadowedDecls.end(); }
- /// Add a decl in the scope chain
+ /// Add a decl in the scope chain.
void PushShadowed(NamedDecl *D) {
assert(D && "Decl null");
ShadowedDecls.push_back(D);
}
- /// Add the decl at the top of scope chain
+ /// Add the decl at the top of scope chain.
void PushGlobalShadowed(NamedDecl *D) {
assert(D && "Decl null");
ShadowedDecls.insert(ShadowedDecls.begin(), D);
@@ -64,25 +68,21 @@ public:
void RemoveShadowed(NamedDecl *D);
};
+} // end anonymous namespace
+
/// IdDeclInfoMap - Associates IdDeclInfos with Identifiers.
-/// Allocates 'pools' (arrays of IdDeclInfos) to avoid allocating each
+/// Allocates 'pools' (vectors of IdDeclInfos) to avoid allocating each
/// individual IdDeclInfo to heap.
class IdentifierResolver::IdDeclInfoMap {
- static const unsigned int ARRAY_SIZE = 512;
- // Holds pointers to arrays of IdDeclInfos that serve as 'pools'.
- // Used only to iterate and destroy them at destructor.
- std::list<IdDeclInfo*> IDIArrPtrs;
- IdDeclInfo *CurArr;
+ static const unsigned int VECTOR_SIZE = 512;
+ // Holds vectors of IdDeclInfos that serve as 'pools'.
+ // New vectors are added when the current one is full.
+ std::list< std::vector<IdDeclInfo> > IDIVecs;
unsigned int CurIndex;
public:
- IdDeclInfoMap() : CurIndex(ARRAY_SIZE) {}
- ~IdDeclInfoMap() {
- for (std::list<IdDeclInfo*>::iterator it = IDIArrPtrs.begin();
- it != IDIArrPtrs.end(); ++it)
- delete[] *it;
- }
+ IdDeclInfoMap() : CurIndex(VECTOR_SIZE) {}
/// Returns the IdDeclInfo associated to the IdentifierInfo.
/// It creates a new IdDeclInfo if one was not created before for this id.
@@ -93,7 +93,7 @@ public:
IdentifierResolver::IdentifierResolver() : IdDeclInfos(*new IdDeclInfoMap) {}
IdentifierResolver::~IdentifierResolver() { delete &IdDeclInfos; }
-/// AddDecl - Link the decl to its shadowed decl chain
+/// AddDecl - Link the decl to its shadowed decl chain.
void IdentifierResolver::AddDecl(NamedDecl *D, Scope *S) {
assert(D && S && "null param passed");
IdentifierInfo *II = D->getIdentifier();
@@ -116,7 +116,7 @@ void IdentifierResolver::AddDecl(NamedDecl *D, Scope *S) {
IDI->PushShadowed(D);
}
-/// AddGlobalDecl - Link the decl at the top of the shadowed decl chain
+/// AddGlobalDecl - Link the decl at the top of the shadowed decl chain.
void IdentifierResolver::AddGlobalDecl(NamedDecl *D) {
assert(D && "null param passed");
IdentifierInfo *II = D->getIdentifier();
@@ -139,7 +139,7 @@ void IdentifierResolver::AddGlobalDecl(NamedDecl *D) {
IDI->PushGlobalShadowed(D);
}
-/// RemoveDecl - Unlink the decl from its shadowed decl chain
+/// RemoveDecl - Unlink the decl from its shadowed decl chain.
/// The decl must already be part of the decl chain.
void IdentifierResolver::RemoveDecl(NamedDecl *D) {
assert(D && "null param passed");
@@ -221,12 +221,14 @@ IdDeclInfo &IdentifierResolver::IdDeclInfoMap::operator[](IdentifierInfo *II) {
return *toIdDeclInfo(Ptr);
}
- if (CurIndex == ARRAY_SIZE) {
- CurArr = new IdDeclInfo[ARRAY_SIZE];
- IDIArrPtrs.push_back(CurArr);
+ if (CurIndex == VECTOR_SIZE) {
+ // Add a IdDeclInfo vector 'pool'
+ IDIVecs.resize(IDIVecs.size() + 1);
+ // Fill the vector
+ IDIVecs.back().resize(VECTOR_SIZE);
CurIndex = 0;
}
- IdDeclInfo *IDI = CurArr + CurIndex;
+ IdDeclInfo *IDI = &IDIVecs.back()[CurIndex];
II->setFETokenInfo(reinterpret_cast<void*>(
reinterpret_cast<uintptr_t>(IDI) | 0x1)
);