[PATCH] D33004: getIdentifierInfo now updates the returned information by default
Raphael Isemann via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue May 9 08:22:54 PDT 2017
teemperor created this revision.
Calling `Preprocessor::getIdentifierInfo` is not automatically updating the returned identifier at the moment. This patch adds a flag that is ensuring by default that the returned IdentifierInfo is updated. The flag is true by default because that seems like the most logical behavior for this method. Can be turned off for performance reasons
https://reviews.llvm.org/D33004
Files:
include/clang/Lex/Preprocessor.h
lib/Lex/Preprocessor.cpp
Index: lib/Lex/Preprocessor.cpp
===================================================================
--- lib/Lex/Preprocessor.cpp
+++ lib/Lex/Preprocessor.cpp
@@ -245,6 +245,27 @@
llvm::errs() << ">";
}
+IdentifierInfo *Preprocessor::getIdentifierInfo(StringRef Name,
+ bool CheckOutOfDate) const {
+ IdentifierInfo &II = Identifiers.get(Name);
+ // If the information about this identifier is out of date, update it from
+ // the external source.
+ // We have to treat __VA_ARGS__ in a special way, since it gets
+ // serialized with isPoisoned = true, but our preprocessor may have
+ // unpoisoned it if we're defining a C99 macro.
+ if (CheckOutOfDate && II.isOutOfDate()) {
+ bool CurrentIsPoisoned = false;
+ if (&II == Ident__VA_ARGS__)
+ CurrentIsPoisoned = Ident__VA_ARGS__->isPoisoned();
+
+ updateOutOfDateIdentifier(II);
+
+ if (&II == Ident__VA_ARGS__)
+ II.setIsPoisoned(CurrentIsPoisoned);
+ }
+ return &II;
+}
+
void Preprocessor::DumpLocation(SourceLocation Loc) const {
Loc.dump(SourceMgr);
}
@@ -646,23 +667,8 @@
IdentifierInfo &II = *Identifier.getIdentifierInfo();
- // If the information about this identifier is out of date, update it from
- // the external source.
- // We have to treat __VA_ARGS__ in a special way, since it gets
- // serialized with isPoisoned = true, but our preprocessor may have
- // unpoisoned it if we're defining a C99 macro.
- if (II.isOutOfDate()) {
- bool CurrentIsPoisoned = false;
- if (&II == Ident__VA_ARGS__)
- CurrentIsPoisoned = Ident__VA_ARGS__->isPoisoned();
-
- updateOutOfDateIdentifier(II);
- Identifier.setKind(II.getTokenID());
+ Identifier.setKind(II.getTokenID());
- if (&II == Ident__VA_ARGS__)
- II.setIsPoisoned(CurrentIsPoisoned);
- }
-
// If this identifier was poisoned, and if it was not produced from a macro
// expansion, emit an error.
if (II.isPoisoned() && CurPPLexer) {
Index: include/clang/Lex/Preprocessor.h
===================================================================
--- include/clang/Lex/Preprocessor.h
+++ include/clang/Lex/Preprocessor.h
@@ -939,11 +939,11 @@
void setPredefines(const char *P) { Predefines = P; }
void setPredefines(StringRef P) { Predefines = P; }
- /// Return information about the specified preprocessor
- /// identifier token.
- IdentifierInfo *getIdentifierInfo(StringRef Name) const {
- return &Identifiers.get(Name);
- }
+ /// Return information about the specified preprocessor identifier token.
+ /// If \p CheckOutOfDate is true, then the returned information is ensured
+ /// to be not out of date.
+ IdentifierInfo *getIdentifierInfo(StringRef Name,
+ bool CheckOutOfDate = true) const;
/// \brief Add the specified pragma handler to this preprocessor.
///
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33004.98291.patch
Type: text/x-patch
Size: 2883 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170509/61d55e2c/attachment.bin>
More information about the cfe-commits
mailing list