Add a new IdentifierVisitor class and a new IdentifierTable::VisitIdentifiers

method to support iteration over all identifiers.

llvm-svn: 38628
This commit is contained in:
Chris Lattner 2006-07-03 04:28:52 +00:00
parent 44f8a66bcc
commit 91cbf11c10
2 changed files with 32 additions and 3 deletions

View File

@ -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.

View File

@ -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;