From: Argyrios Kyrtzidis Date: Sat, 12 Apr 2008 01:50:47 +0000 (+0000) Subject: Fixed comments. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=321f278db3405268e8644eb75f4fcf8900e0d09c;p=clang 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 --- 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 +#include 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(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( reinterpret_cast(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 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 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 > IDIVecs; unsigned int CurIndex; public: - IdDeclInfoMap() : CurIndex(ARRAY_SIZE) {} - ~IdDeclInfoMap() { - for (std::list::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( reinterpret_cast(IDI) | 0x1) ); diff --git a/lib/Sema/IdentifierResolver.h b/lib/Sema/IdentifierResolver.h index 8db4615df2..bdaab694fe 100644 --- a/lib/Sema/IdentifierResolver.h +++ b/lib/Sema/IdentifierResolver.h @@ -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);