[cfe-commits] r42722 - in /cfe/trunk: Lex/IdentifierTable.cpp include/clang/Lex/IdentifierTable.h
Chris Lattner
sabre at nondot.org
Sun Oct 7 00:09:52 PDT 2007
Author: lattner
Date: Sun Oct 7 02:09:52 2007
New Revision: 42722
URL: http://llvm.org/viewvc/llvm-project?rev=42722&view=rev
Log:
First step to fixing a long lived layering violation: this
moves the MacroInfo pointer to a side hash table (which currently
lives in IdentifierTable.cpp). This removes a pointer from
Identifier info, but doesn't shrink it, as it requires a new bit
be added. This strange approach with the 'hasmacro' bit is needed
to not lose preprocessor performance.
Modified:
cfe/trunk/Lex/IdentifierTable.cpp
cfe/trunk/include/clang/Lex/IdentifierTable.h
Modified: cfe/trunk/Lex/IdentifierTable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Lex/IdentifierTable.cpp?rev=42722&r1=42721&r2=42722&view=diff
==============================================================================
--- cfe/trunk/Lex/IdentifierTable.cpp (original)
+++ cfe/trunk/Lex/IdentifierTable.cpp Sun Oct 7 02:09:52 2007
@@ -19,6 +19,24 @@
#include "llvm/ADT/DenseMap.h"
using namespace clang;
+static llvm::DenseMap<const IdentifierInfo*, MacroInfo*> Macros;
+
+MacroInfo *IdentifierInfo::getMacroInfoInternal() const {
+ return Macros[this];
+}
+void IdentifierInfo::setMacroInfo(MacroInfo *I) {
+ if (I == 0) {
+ if (HasMacro) {
+ Macros.erase(this);
+ HasMacro = false;
+ }
+ } else {
+ Macros[this] = I;
+ HasMacro = true;
+ }
+}
+
+
//===----------------------------------------------------------------------===//
// Token Implementation
//===----------------------------------------------------------------------===//
@@ -40,11 +58,11 @@
//===----------------------------------------------------------------------===//
IdentifierInfo::IdentifierInfo() {
- Macro = 0;
TokenID = tok::identifier;
PPID = tok::pp_not_keyword;
ObjCID = tok::objc_not_keyword;
BuiltinID = 0;
+ HasMacro = false;
IsExtension = false;
IsPoisoned = false;
IsOtherTargetMacro = false;
@@ -54,7 +72,8 @@
}
IdentifierInfo::~IdentifierInfo() {
- delete Macro;
+ if (MacroInfo *Macro = getMacroInfo())
+ delete Macro;
}
//===----------------------------------------------------------------------===//
Modified: cfe/trunk/include/clang/Lex/IdentifierTable.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/IdentifierTable.h?rev=42722&r1=42721&r2=42722&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/IdentifierTable.h (original)
+++ cfe/trunk/include/clang/Lex/IdentifierTable.h Sun Oct 7 02:09:52 2007
@@ -37,11 +37,11 @@
/// variable or function name). The preprocessor keeps this information in a
/// set, and all tok::identifier tokens have a pointer to one of these.
class IdentifierInfo {
- MacroInfo *Macro; // Set if this identifier is #define'd.
tok::TokenKind TokenID : 8; // Front-end token ID or tok::identifier.
+ unsigned BuiltinID : 9; // ID if this is a builtin (__builtin_inf).
tok::PPKeywordKind PPID : 5; // ID for preprocessor command like #'ifdef'.
tok::ObjCKeywordKind ObjCID : 5; // ID for objc @ keyword like @'protocol'.
- unsigned BuiltinID : 9; // ID if this is a builtin (__builtin_inf).
+ bool HasMacro : 1; // True if there is a #define for this.
bool IsExtension : 1; // True if identifier is a lang extension.
bool IsPoisoned : 1; // True if identifier is poisoned.
bool IsOtherTargetMacro : 1; // True if ident is macro on another target.
@@ -49,6 +49,7 @@
bool IsNonPortableBuiltin : 1; // True if builtin varies across targets.
void *FETokenInfo; // Managed by the language front-end.
IdentifierInfo(const IdentifierInfo&); // NONCOPYABLE.
+ void operator=(const IdentifierInfo&); // NONASSIGNABLE.
public:
IdentifierInfo();
~IdentifierInfo();
@@ -72,8 +73,10 @@
/// getMacroInfo - Return macro information about this identifier, or null if
/// it is not a macro.
- MacroInfo *getMacroInfo() const { return Macro; }
- void setMacroInfo(MacroInfo *I) { Macro = I; }
+ MacroInfo *getMacroInfo() const {
+ return HasMacro ? getMacroInfoInternal() : 0;
+ }
+ void setMacroInfo(MacroInfo *I);
/// get/setTokenID - If this is a source-language token (e.g. 'for'), this API
/// can be used to cause the lexer to map identifiers to source-language
@@ -137,6 +140,8 @@
template<typename T>
T *getFETokenInfo() const { return static_cast<T*>(FETokenInfo); }
void setFETokenInfo(void *T) { FETokenInfo = T; }
+private:
+ MacroInfo *getMacroInfoInternal() const;
};
/// IdentifierTable - This table implements an efficient mapping from strings to
@@ -274,6 +279,9 @@
} // end namespace clang
+
+/// Define DenseMapInfo so that Selectors can be used as keys in DenseMap and
+/// DenseSets.
namespace llvm {
template <>
struct DenseMapInfo<clang::Selector> {
More information about the cfe-commits
mailing list