Macro history (de-)serialization. Deserialization currently reads only the latest macro definition. Needs more work.
Summary: Passes all tests (+ the new one with code completion), but needs a thorough review in part related to modules.
Reviewers: doug.gregor
Reviewed By: alexfh
CC: cfe-commits, rsmith
Differential Revision: http://llvm-reviews.chandlerc.com/D41
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@164610 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Lex/PPMacroExpansion.cpp b/lib/Lex/PPMacroExpansion.cpp
index b2d5977..dcaa5a6 100644
--- a/lib/Lex/PPMacroExpansion.cpp
+++ b/lib/Lex/PPMacroExpansion.cpp
@@ -32,8 +32,8 @@
#include <ctime>
using namespace clang;
-MacroInfo *Preprocessor::getInfoForMacro(IdentifierInfo *II) const {
- assert(II->hasMacroDefinition() && "Identifier is not a macro!");
+MacroInfo *Preprocessor::getMacroInfoHistory(IdentifierInfo *II) const {
+ assert(II->hadMacroDefinition() && "Identifier has not been not a macro!");
macro_iterator Pos = Macros.find(II);
if (Pos == Macros.end()) {
@@ -42,7 +42,6 @@
Pos = Macros.find(II);
}
assert(Pos != Macros.end() && "Identifier macro info is missing!");
- assert(Pos->second->getUndefLoc().isInvalid() && "Macro is undefined!");
return Pos->second;
}
@@ -51,9 +50,11 @@
void Preprocessor::setMacroInfo(IdentifierInfo *II, MacroInfo *MI,
bool LoadedFromAST) {
assert(MI && "MacroInfo should be non-zero!");
+ assert((LoadedFromAST || MI->getUndefLoc().isInvalid()) &&
+ "Undefined macros can only be registered when just LoadedFromAST");
MI->setPreviousDefinition(Macros[II]);
Macros[II] = MI;
- II->setHasMacroDefinition(true);
+ II->setHasMacroDefinition(MI->getUndefLoc().isInvalid());
if (II->isFromAST() && !LoadedFromAST)
II->setChangedSinceDeserialization();
}