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;
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.
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));
}
IsCPPOperatorKeyword = false;
NeedsHandleIdentifier = false;
IsFromPCH = false;
+ RevertedTokenID = false;
FETokenInfo = 0;
Entry = 0;
}
// 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);
}
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();
}
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;
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");
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);
// 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);
}
// 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);
}
--- /dev/null
+// 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;
--- /dev/null
+// Header for PCH test cxx-traits.cpp
+
+template<typename _Tp>
+struct __is_pod {
+ enum { __value };
+};
+
+template<typename _Tp>
+struct __is_empty {
+ enum { __value };
+};