mirror of
https://github.com/intel/llvm.git
synced 2026-01-31 16:29:50 +08:00
Fixed comments.
Moved IdDeclInfo class to anonymous namespace. Replaced array with a std::vector. llvm-svn: 49570
This commit is contained in:
@@ -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)
|
||||
);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines the IdentifierResolver class,which is used for lexical
|
||||
// This file defines the IdentifierResolver class, which is used for lexical
|
||||
// scoped lookup, based on identifier.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
@@ -21,20 +21,20 @@ namespace clang {
|
||||
class Scope;
|
||||
|
||||
/// IdentifierResolver - Keeps track of shadowed decls on enclosing scopes.
|
||||
/// it manages the shadowing chains of identifiers and implements efficent decl
|
||||
/// It manages the shadowing chains of identifiers and implements efficent decl
|
||||
/// lookup based on an identifier.
|
||||
class IdentifierResolver {
|
||||
public:
|
||||
IdentifierResolver();
|
||||
~IdentifierResolver();
|
||||
|
||||
/// AddDecl - Link the decl to its shadowed decl chain
|
||||
/// AddDecl - Link the decl to its shadowed decl chain.
|
||||
void AddDecl(NamedDecl *D, Scope *S);
|
||||
|
||||
/// 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 AddGlobalDecl(NamedDecl *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 RemoveDecl(NamedDecl *D);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user