[cfe-commits] r38628 - in /cfe/cfe/trunk: Lex/IdentifierTable.cpp include/clang/Lex/IdentifierTable.h

sabre at cs.uiuc.edu sabre at cs.uiuc.edu
Wed Jul 11 09:23:20 PDT 2007


Author: sabre
Date: Wed Jul 11 11:23:20 2007
New Revision: 38628

URL: http://llvm.org/viewvc/llvm-project?rev=38628&view=rev
Log:
Add a new IdentifierVisitor class and a new IdentifierTable::VisitIdentifiers
method to support iteration over all identifiers.

Modified:
    cfe/cfe/trunk/Lex/IdentifierTable.cpp
    cfe/cfe/trunk/include/clang/Lex/IdentifierTable.h

Modified: cfe/cfe/trunk/Lex/IdentifierTable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/IdentifierTable.cpp?rev=38628&r1=38627&r2=38628&view=diff

==============================================================================
--- cfe/cfe/trunk/Lex/IdentifierTable.cpp (original)
+++ cfe/cfe/trunk/Lex/IdentifierTable.cpp Wed Jul 11 11:23:20 2007
@@ -7,7 +7,8 @@
 //
 //===----------------------------------------------------------------------===//
 //
-// This file implements the IdentifierTokenInfo and IdentifierTable interfaces.
+// This file implements the IdentifierTokenInfo, IdentifierVisitor, and
+// IdentifierTable interfaces.
 //
 //===----------------------------------------------------------------------===//
 
@@ -25,6 +26,12 @@
   delete Macro;
 }
 
+//===----------------------------------------------------------------------===//
+// IdentifierVisitor Implementation
+//===----------------------------------------------------------------------===//
+
+IdentifierVisitor::~IdentifierVisitor() {
+}
 
 //===----------------------------------------------------------------------===//
 // Memory Allocation Support
@@ -212,7 +219,15 @@
   return get(NameBytes, NameBytes+Size);
 }
 
-
+/// VisitIdentifiers - This method walks through all of the identifiers,
+/// invoking IV->VisitIdentifier for each of them.
+void IdentifierTable::VisitIdentifiers(const IdentifierVisitor &IV) {
+  IdentifierBucket **TableArray = (IdentifierBucket**)TheTable;
+  for (unsigned i = 0, e = HASH_TABLE_SIZE; i != e; ++i) {
+    for (IdentifierBucket *Id = TableArray[i]; Id; Id = Id->Next)
+      IV.VisitIdentifier(Id->TokInfo);
+  }
+}
 
 /// PrintStats - Print statistics about how well the identifier table is doing
 /// at hashing identifiers.

Modified: cfe/cfe/trunk/include/clang/Lex/IdentifierTable.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Lex/IdentifierTable.h?rev=38628&r1=38627&r2=38628&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/Lex/IdentifierTable.h (original)
+++ cfe/cfe/trunk/include/clang/Lex/IdentifierTable.h Wed Jul 11 11:23:20 2007
@@ -7,7 +7,8 @@
 //
 //===----------------------------------------------------------------------===//
 //
-// This file defines the IdentifierTokenInfo and IdentifierTable interfaces.
+// This file defines the IdentifierTokenInfo, IdentifierVisitor, and
+// IdentifierTable interfaces.
 //
 //===----------------------------------------------------------------------===//
 
@@ -84,6 +85,14 @@
   void Destroy();
 };
 
+/// IdentifierVisitor - Subclasses of this class may be implemented to walk all
+/// of the defined identifiers.
+class IdentifierVisitor {
+public:
+  virtual ~IdentifierVisitor();
+  virtual void VisitIdentifier(IdentifierTokenInfo &ITI) const = 0;
+};
+
 /// IdentifierTable - This table implements an efficient mapping from strings to
 /// IdentifierTokenInfo nodes.  It has no other purpose, but this is an
 /// extremely performance-critical piece of the code, as each occurrance of
@@ -95,11 +104,16 @@
 public:
   IdentifierTable();
   ~IdentifierTable();
+  
   /// get - Return the identifier token info for the specified named identifier.
   ///
   IdentifierTokenInfo &get(const char *NameStart, const char *NameEnd);
   IdentifierTokenInfo &get(const std::string &Name);
   
+  /// VisitIdentifiers - This method walks through all of the identifiers,
+  /// invoking IV->VisitIdentifier for each of them.
+  void VisitIdentifiers(const IdentifierVisitor &IV);
+  
   /// PrintStats - Print some statistics to stderr that indicate how well the
   /// hashing is doing.
   void PrintStats() const;





More information about the cfe-commits mailing list