mirror of
https://github.com/intel/llvm.git
synced 2026-01-31 16:29:50 +08:00
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:
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user