[cfe-commits] r110868 - in /cfe/trunk: include/clang/Basic/IdentifierTable.h lib/Basic/IdentifierTable.cpp lib/Frontend/PCHReader.cpp lib/Frontend/PCHWriter.cpp lib/Parse/ParseDeclCXX.cpp test/PCH/cxx-traits.cpp test/PCH/cxx-traits.h
Argyrios Kyrtzidis
akyrtzi at gmail.com
Wed Aug 11 15:55:13 PDT 2010
Author: akirtzidis
Date: Wed Aug 11 17:55:12 2010
New Revision: 110868
URL: http://llvm.org/viewvc/llvm-project?rev=110868&view=rev
Log:
-Make TokenID of IdentifierInfo read-only, remove setTokenID().
-There are 2 instances that change the TokenID for GNU libstdc++ 4.2 compatibility.
To handler those cases introduce a RevertedTokenID bitfield, RevertTokenIDToIdentifier() and hasRevertedTokenIDToIdentifier() methods.
Store the bitfield in PCH.
Added:
cfe/trunk/test/PCH/cxx-traits.cpp
cfe/trunk/test/PCH/cxx-traits.h
Modified:
cfe/trunk/include/clang/Basic/IdentifierTable.h
cfe/trunk/lib/Basic/IdentifierTable.cpp
cfe/trunk/lib/Frontend/PCHReader.cpp
cfe/trunk/lib/Frontend/PCHWriter.cpp
cfe/trunk/lib/Parse/ParseDeclCXX.cpp
Modified: cfe/trunk/include/clang/Basic/IdentifierTable.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/IdentifierTable.h?rev=110868&r1=110867&r2=110868&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/IdentifierTable.h (original)
+++ cfe/trunk/include/clang/Basic/IdentifierTable.h Wed Aug 11 17:55:12 2010
@@ -61,7 +61,9 @@
bool NeedsHandleIdentifier : 1; // See "RecomputeNeedsHandleIdentifier".
bool IsFromPCH : 1; // True if identfier first appeared in a PCH
// and wasn't modified since.
- // 8 bits left in 32-bit word.
+ bool RevertedTokenID : 1; // True if RevertTokenIDToIdentifier was
+ // called.
+ // 7 bits left in 32-bit word.
void *FETokenInfo; // Managed by the language front-end.
llvm::StringMapEntry<IdentifierInfo*> *Entry;
@@ -130,11 +132,21 @@
IsFromPCH = false;
}
- /// get/setTokenID - If this is a source-language token (e.g. 'for'), this API
+ /// getTokenID - 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
/// tokens.
tok::TokenKind getTokenID() const { return (tok::TokenKind)TokenID; }
- void setTokenID(tok::TokenKind ID) { TokenID = ID; }
+
+ /// \brief True if RevertTokenIDToIdentifier() was called.
+ bool hasRevertedTokenIDToIdentifier() const { return RevertedTokenID; }
+
+ /// \brief Revert TokenID to tok::identifier; used for GNU libstdc++ 4.2
+ /// compatibility.
+ void RevertTokenIDToIdentifier() {
+ assert(TokenID != tok::identifier && "Already at tok::identifier");
+ TokenID = tok::identifier;
+ RevertedTokenID = true;
+ }
/// getPPKeywordID - Return the preprocessor keyword ID for this identifier.
/// For example, "define" will return tok::pp_define.
@@ -323,6 +335,12 @@
return *II;
}
+ IdentifierInfo &get(llvm::StringRef Name, tok::TokenKind TokenCode) {
+ IdentifierInfo &II = get(Name);
+ II.TokenID = TokenCode;
+ return II;
+ }
+
IdentifierInfo &get(const char *NameStart, const char *NameEnd) {
return get(llvm::StringRef(NameStart, NameEnd-NameStart));
}
Modified: cfe/trunk/lib/Basic/IdentifierTable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/IdentifierTable.cpp?rev=110868&r1=110867&r2=110868&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/IdentifierTable.cpp (original)
+++ cfe/trunk/lib/Basic/IdentifierTable.cpp Wed Aug 11 17:55:12 2010
@@ -35,6 +35,7 @@
IsCPPOperatorKeyword = false;
NeedsHandleIdentifier = false;
IsFromPCH = false;
+ RevertedTokenID = false;
FETokenInfo = 0;
Entry = 0;
}
@@ -101,8 +102,7 @@
// Don't add this keyword if disabled in this language.
if (AddResult == 0) return;
- IdentifierInfo &Info = Table.get(Keyword);
- Info.setTokenID(TokenCode);
+ IdentifierInfo &Info = Table.get(Keyword, TokenCode);
Info.setIsExtensionToken(AddResult == 1);
}
@@ -111,8 +111,7 @@
static void AddCXXOperatorKeyword(llvm::StringRef Keyword,
tok::TokenKind TokenCode,
IdentifierTable &Table) {
- IdentifierInfo &Info = Table.get(Keyword);
- Info.setTokenID(TokenCode);
+ IdentifierInfo &Info = Table.get(Keyword, TokenCode);
Info.setIsCPlusPlusOperatorKeyword();
}
Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=110868&r1=110867&r2=110868&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Wed Aug 11 17:55:12 2010
@@ -657,6 +657,8 @@
unsigned Bits = ReadUnalignedLE16(d);
bool CPlusPlusOperatorKeyword = Bits & 0x01;
Bits >>= 1;
+ bool HasRevertedTokenIDToIdentifier = Bits & 0x01;
+ Bits >>= 1;
bool Poisoned = Bits & 0x01;
Bits >>= 1;
bool ExtensionToken = Bits & 0x01;
@@ -677,7 +679,9 @@
Reader.SetIdentifierInfo(ID, II);
// Set or check the various bits in the IdentifierInfo structure.
- // FIXME: Load token IDs lazily, too?
+ // Token IDs are read-only.
+ if (HasRevertedTokenIDToIdentifier)
+ II->RevertTokenIDToIdentifier();
II->setObjCOrBuiltinID(ObjCOrBuiltinID);
assert(II->isExtensionToken() == ExtensionToken &&
"Incorrect extension token flag");
Modified: cfe/trunk/lib/Frontend/PCHWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriter.cpp?rev=110868&r1=110867&r2=110868&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Wed Aug 11 17:55:12 2010
@@ -1847,6 +1847,7 @@
Bits = (Bits << 1) | unsigned(hasMacroDefinition);
Bits = (Bits << 1) | unsigned(II->isExtensionToken());
Bits = (Bits << 1) | unsigned(II->isPoisoned());
+ Bits = (Bits << 1) | unsigned(II->hasRevertedTokenIDToIdentifier());
Bits = (Bits << 1) | unsigned(II->isCPlusPlusOperatorKeyword());
clang::io::Emit16(Out, Bits);
Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=110868&r1=110867&r2=110868&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Wed Aug 11 17:55:12 2010
@@ -661,7 +661,7 @@
// token sequence "struct __is_pod", make __is_pod into a normal
// identifier rather than a keyword, to allow libstdc++ 4.2 to work
// properly.
- Tok.getIdentifierInfo()->setTokenID(tok::identifier);
+ Tok.getIdentifierInfo()->RevertTokenIDToIdentifier();
Tok.setKind(tok::identifier);
}
@@ -671,7 +671,7 @@
// token sequence "struct __is_empty", make __is_empty into a normal
// identifier rather than a keyword, to allow libstdc++ 4.2 to work
// properly.
- Tok.getIdentifierInfo()->setTokenID(tok::identifier);
+ Tok.getIdentifierInfo()->RevertTokenIDToIdentifier();
Tok.setKind(tok::identifier);
}
Added: cfe/trunk/test/PCH/cxx-traits.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/cxx-traits.cpp?rev=110868&view=auto
==============================================================================
--- cfe/trunk/test/PCH/cxx-traits.cpp (added)
+++ cfe/trunk/test/PCH/cxx-traits.cpp Wed Aug 11 17:55:12 2010
@@ -0,0 +1,8 @@
+// Test this without pch.
+// RUN: %clang_cc1 -include %S/cxx-traits.h -fsyntax-only -verify %s
+
+// RUN: %clang_cc1 -x c++-header -emit-pch -o %t %S/cxx-traits.h
+// RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s
+
+bool _Is_pod_comparator = __is_pod<int>::__value;
+bool _Is_empty_check = __is_empty<int>::__value;
Added: cfe/trunk/test/PCH/cxx-traits.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/cxx-traits.h?rev=110868&view=auto
==============================================================================
--- cfe/trunk/test/PCH/cxx-traits.h (added)
+++ cfe/trunk/test/PCH/cxx-traits.h Wed Aug 11 17:55:12 2010
@@ -0,0 +1,11 @@
+// Header for PCH test cxx-traits.cpp
+
+template<typename _Tp>
+struct __is_pod {
+ enum { __value };
+};
+
+template<typename _Tp>
+struct __is_empty {
+ enum { __value };
+};
More information about the cfe-commits
mailing list