diff options
| author | Chris Lattner <sabre@nondot.org> | 2006-07-03 04:28:52 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2006-07-03 04:28:52 +0000 |
| commit | 91cbf11c101ac7464d77e3da390e8cc65d1d8157 (patch) | |
| tree | 362664704f3313f7e0e620fdee7ddaaa1a2357e2 /clang | |
| parent | 44f8a66bcc86d06380324e83335eeac235c6bfc7 (diff) | |
| download | bcm5719-llvm-91cbf11c101ac7464d77e3da390e8cc65d1d8157.tar.gz bcm5719-llvm-91cbf11c101ac7464d77e3da390e8cc65d1d8157.zip | |
Add a new IdentifierVisitor class and a new IdentifierTable::VisitIdentifiers
method to support iteration over all identifiers.
llvm-svn: 38628
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/Lex/IdentifierTable.cpp | 19 | ||||
| -rw-r--r-- | clang/include/clang/Lex/IdentifierTable.h | 16 |
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; |

