[cfe-commits] r49570 - in /cfe/trunk/lib/Sema: IdentifierResolver.cpp IdentifierResolver.h

Argiris Kirtzidis akyrtzi at gmail.com
Fri Apr 11 18:50:47 PDT 2008


Author: akirtzidis
Date: Fri Apr 11 20:50:47 2008
New Revision: 49570

URL: http://llvm.org/viewvc/llvm-project?rev=49570&view=rev
Log:
Fixed comments.
Moved IdDeclInfo class to anonymous namespace.
Replaced array with a std::vector.

Modified:
    cfe/trunk/lib/Sema/IdentifierResolver.cpp
    cfe/trunk/lib/Sema/IdentifierResolver.h

Modified: cfe/trunk/lib/Sema/IdentifierResolver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/IdentifierResolver.cpp?rev=49570&r1=49569&r2=49570&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/IdentifierResolver.cpp (original)
+++ cfe/trunk/lib/Sema/IdentifierResolver.cpp Fri Apr 11 20:50:47 2008
@@ -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 @@
 }
 
 
-/// 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 @@
   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 @@
   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 @@
 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 @@
   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 @@
   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 @@
     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)
                                                                      );

Modified: cfe/trunk/lib/Sema/IdentifierResolver.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/IdentifierResolver.h?rev=49570&r1=49569&r2=49570&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/IdentifierResolver.h (original)
+++ cfe/trunk/lib/Sema/IdentifierResolver.h Fri Apr 11 20:50:47 2008
@@ -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 @@
   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);
 





More information about the cfe-commits mailing list