summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
Diffstat (limited to 'clang')
-rw-r--r--clang/Lex/IdentifierTable.cpp19
-rw-r--r--clang/include/clang/Lex/IdentifierTable.h16
2 files changed, 32 insertions, 3 deletions
diff --git a/clang/Lex/IdentifierTable.cpp b/clang/Lex/IdentifierTable.cpp
index c28d4830f8e..a7da508906f 100644
--- a/clang/Lex/IdentifierTable.cpp
+++ b/clang/Lex/IdentifierTable.cpp
@@ -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 @@ void IdentifierTokenInfo::Destroy() {
delete Macro;
}
+//===----------------------------------------------------------------------===//
+// IdentifierVisitor Implementation
+//===----------------------------------------------------------------------===//
+
+IdentifierVisitor::~IdentifierVisitor() {
+}
//===----------------------------------------------------------------------===//
// Memory Allocation Support
@@ -212,7 +219,15 @@ IdentifierTokenInfo &IdentifierTable::get(const std::string &Name) {
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.
diff --git a/clang/include/clang/Lex/IdentifierTable.h b/clang/include/clang/Lex/IdentifierTable.h
index fbc5c583fe2..3c02e1788ef 100644
--- a/clang/include/clang/Lex/IdentifierTable.h
+++ b/clang/include/clang/Lex/IdentifierTable.h
@@ -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 @@ private:
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 @@ class IdentifierTable {
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;
OpenPOWER on IntegriCloud