[preprocessor] Split the MacroInfo class into two separate concepts, MacroInfo class
for the data specific to a macro definition (e.g. what the tokens are), and
MacroDirective class which encapsulates the changes to the "macro namespace"
(e.g. the location where the macro name became active, the location where it was undefined, etc.)
(A MacroDirective always points to a MacroInfo object.)
Usually a macro definition (MacroInfo) is where a macro name becomes active (MacroDirective) but
splitting the concepts allows us to better model the effect of modules to the macro namespace
(also as a bonus it allows better modeling of push_macro/pop_macro #pragmas).
Modules can have their own macro history, separate from the local (current translation unit)
macro history; MacroDirectives will be used to model the macro history (changes to macro namespace).
For example, if "@import A;" imports macro FOO, there will be a new local MacroDirective created
to indicate that "FOO" became active at the import location. Module "A" itself will contain another
MacroDirective in its macro history (at the point of the definition of FOO) and both MacroDirectives
will point to the same MacroInfo object.
Introducing the separation of macro concepts is the first part towards better modeling of module macros.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175585 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Frontend/PrintPreprocessedOutput.cpp b/lib/Frontend/PrintPreprocessedOutput.cpp
index 4024093..c85945b 100644
--- a/lib/Frontend/PrintPreprocessedOutput.cpp
+++ b/lib/Frontend/PrintPreprocessedOutput.cpp
@@ -592,7 +592,7 @@
for (Preprocessor::macro_iterator I = PP.macro_begin(), E = PP.macro_end();
I != E; ++I) {
if (I->first->hasMacroDefinition())
- MacrosByID.push_back(id_macro_pair(I->first, I->second));
+ MacrosByID.push_back(id_macro_pair(I->first, I->second->getInfo()));
}
llvm::array_pod_sort(MacrosByID.begin(), MacrosByID.end(), MacroIDCompare);
diff --git a/lib/Lex/MacroInfo.cpp b/lib/Lex/MacroInfo.cpp
index d1875c7..ed6cc6e 100644
--- a/lib/Lex/MacroInfo.cpp
+++ b/lib/Lex/MacroInfo.cpp
@@ -17,7 +17,6 @@
MacroInfo::MacroInfo(SourceLocation DefLoc)
: Location(DefLoc),
- PreviousDefinition(0),
ArgumentList(0),
NumArguments(0),
IsDefinitionLengthCached(false),
@@ -26,54 +25,10 @@
IsGNUVarargs(false),
IsBuiltinMacro(false),
HasCommaPasting(false),
- IsFromAST(false),
- ChangedAfterLoad(false),
IsDisabled(false),
IsUsed(false),
IsAllowRedefinitionsWithoutWarning(false),
- IsWarnIfUnused(false),
- IsPublic(true),
- IsHidden(false),
- IsAmbiguous(false) {
-}
-
-MacroInfo::MacroInfo(const MacroInfo &MI, llvm::BumpPtrAllocator &PPAllocator)
- : Location(MI.Location),
- EndLocation(MI.EndLocation),
- UndefLocation(MI.UndefLocation),
- PreviousDefinition(0),
- ArgumentList(0),
- NumArguments(0),
- ReplacementTokens(MI.ReplacementTokens),
- DefinitionLength(MI.DefinitionLength),
- IsDefinitionLengthCached(MI.IsDefinitionLengthCached),
- IsFunctionLike(MI.IsFunctionLike),
- IsC99Varargs(MI.IsC99Varargs),
- IsGNUVarargs(MI.IsGNUVarargs),
- IsBuiltinMacro(MI.IsBuiltinMacro),
- HasCommaPasting(MI.HasCommaPasting),
- IsFromAST(MI.IsFromAST),
- ChangedAfterLoad(MI.ChangedAfterLoad),
- IsDisabled(MI.IsDisabled),
- IsUsed(MI.IsUsed),
- IsAllowRedefinitionsWithoutWarning(MI.IsAllowRedefinitionsWithoutWarning),
- IsWarnIfUnused(MI.IsWarnIfUnused),
- IsPublic(MI.IsPublic),
- IsHidden(MI.IsHidden),
- IsAmbiguous(MI.IsAmbiguous) {
- setArgumentList(MI.ArgumentList, MI.NumArguments, PPAllocator);
-}
-
-const MacroInfo *MacroInfo::findDefinitionAtLoc(SourceLocation L,
- SourceManager &SM) const {
- assert(L.isValid() && "SourceLocation is invalid.");
- for (const MacroInfo *MI = this; MI; MI = MI->PreviousDefinition) {
- if (MI->Location.isInvalid() || // For macros defined on the command line.
- SM.isBeforeInTranslationUnit(MI->Location, L))
- return (MI->UndefLocation.isInvalid() ||
- SM.isBeforeInTranslationUnit(L, MI->UndefLocation)) ? MI : NULL;
- }
- return NULL;
+ IsWarnIfUnused(false) {
}
unsigned MacroInfo::getDefinitionLengthSlow(SourceManager &SM) const {
@@ -151,3 +106,15 @@
return true;
}
+
+const MacroDirective *
+MacroDirective::findDirectiveAtLoc(SourceLocation L, SourceManager &SM) const {
+ assert(L.isValid() && "SourceLocation is invalid.");
+ for (const MacroDirective *MD = this; MD; MD = MD->Previous) {
+ if (MD->getLocation().isInvalid() || // For macros defined on the command line.
+ SM.isBeforeInTranslationUnit(MD->getLocation(), L))
+ return (MD->UndefLocation.isInvalid() ||
+ SM.isBeforeInTranslationUnit(L, MD->UndefLocation)) ? MD : NULL;
+ }
+ return NULL;
+}
diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp
index c8e1f4f..1825028 100644
--- a/lib/Lex/PPDirectives.cpp
+++ b/lib/Lex/PPDirectives.cpp
@@ -57,10 +57,12 @@
return MI;
}
-MacroInfo *Preprocessor::CloneMacroInfo(const MacroInfo &MacroToClone) {
- MacroInfo *MI = AllocateMacroInfo();
- new (MI) MacroInfo(MacroToClone, BP);
- return MI;
+MacroDirective *Preprocessor::AllocateMacroDirective(MacroInfo *MI,
+ SourceLocation Loc,
+ bool isImported) {
+ MacroDirective *MD = BP.Allocate<MacroDirective>();
+ new (MD) MacroDirective(MI, Loc, isImported);
+ return MD;
}
/// \brief Release the specified MacroInfo to be reused for allocating
@@ -1110,22 +1112,22 @@
CheckEndOfDirective("__public_macro");
// Okay, we finally have a valid identifier to undef.
- MacroInfo *MI = getMacroInfo(MacroNameTok.getIdentifierInfo());
+ MacroDirective *MD = getMacroDirective(MacroNameTok.getIdentifierInfo());
// If the macro is not defined, this is an error.
- if (MI == 0) {
+ if (MD == 0) {
Diag(MacroNameTok, diag::err_pp_visibility_non_macro)
<< MacroNameTok.getIdentifierInfo();
return;
}
// Note that this macro has now been exported.
- MI->setVisibility(/*IsPublic=*/true, MacroNameTok.getLocation());
-
+ MD->setVisibility(/*IsPublic=*/true, MacroNameTok.getLocation());
+
// If this macro definition came from a PCH file, mark it
// as having changed since serialization.
- if (MI->isFromAST())
- MI->setChangedAfterLoad();
+ if (MD->isImported())
+ MD->setChangedAfterLoad();
}
/// \brief Handle a #private directive.
@@ -1141,22 +1143,22 @@
CheckEndOfDirective("__private_macro");
// Okay, we finally have a valid identifier to undef.
- MacroInfo *MI = getMacroInfo(MacroNameTok.getIdentifierInfo());
+ MacroDirective *MD = getMacroDirective(MacroNameTok.getIdentifierInfo());
// If the macro is not defined, this is an error.
- if (MI == 0) {
+ if (MD == 0) {
Diag(MacroNameTok, diag::err_pp_visibility_non_macro)
<< MacroNameTok.getIdentifierInfo();
return;
}
// Note that this macro has now been marked private.
- MI->setVisibility(/*IsPublic=*/false, MacroNameTok.getLocation());
-
+ MD->setVisibility(/*IsPublic=*/false, MacroNameTok.getLocation());
+
// If this macro definition came from a PCH file, mark it
// as having changed since serialization.
- if (MI->isFromAST())
- MI->setChangedAfterLoad();
+ if (MD->isImported())
+ MD->setChangedAfterLoad();
}
//===----------------------------------------------------------------------===//
@@ -1918,7 +1920,7 @@
// Finally, if this identifier already had a macro defined for it, verify that
// the macro bodies are identical, and issue diagnostics if they are not.
- if (MacroInfo *OtherMI = getMacroInfo(MacroNameTok.getIdentifierInfo())) {
+ if (const MacroInfo *OtherMI=getMacroInfo(MacroNameTok.getIdentifierInfo())) {
// It is very common for system headers to have tons of macro redefinitions
// and for warnings to be disabled in system headers. If this is the case,
// then don't bother calling MacroInfo::isIdenticalTo.
@@ -1940,7 +1942,7 @@
WarnUnusedMacroLocs.erase(OtherMI->getDefinitionLoc());
}
- setMacroInfo(MacroNameTok.getIdentifierInfo(), MI);
+ setMacroDirective(MacroNameTok.getIdentifierInfo(), MI);
assert(!MI->isUsed());
// If we need warning for not using the macro, add its location in the
@@ -1973,7 +1975,8 @@
CheckEndOfDirective("undef");
// Okay, we finally have a valid identifier to undef.
- MacroInfo *MI = getMacroInfo(MacroNameTok.getIdentifierInfo());
+ MacroDirective *MD = getMacroDirective(MacroNameTok.getIdentifierInfo());
+ const MacroInfo *MI = MD ? MD->getInfo() : 0;
// If the callbacks want to know, tell them about the macro #undef.
// Note: no matter if the macro was defined or not.
@@ -1989,17 +1992,17 @@
if (MI->isWarnIfUnused())
WarnUnusedMacroLocs.erase(MI->getDefinitionLoc());
- UndefineMacro(MacroNameTok.getIdentifierInfo(), MI,
+ UndefineMacro(MacroNameTok.getIdentifierInfo(), MD,
MacroNameTok.getLocation());
}
-void Preprocessor::UndefineMacro(IdentifierInfo *II, MacroInfo *MI,
+void Preprocessor::UndefineMacro(IdentifierInfo *II, MacroDirective *MD,
SourceLocation UndefLoc) {
- MI->setUndefLoc(UndefLoc);
- if (MI->isFromAST()) {
- MI->setChangedAfterLoad();
+ MD->setUndefLoc(UndefLoc);
+ if (MD->isImported()) {
+ MD->setChangedAfterLoad();
if (Listener)
- Listener->UndefinedMacro(MI);
+ Listener->UndefinedMacro(MD);
}
clearMacroInfo(II);
diff --git a/lib/Lex/PPMacroExpansion.cpp b/lib/Lex/PPMacroExpansion.cpp
index bda31ed..3e68fbd 100644
--- a/lib/Lex/PPMacroExpansion.cpp
+++ b/lib/Lex/PPMacroExpansion.cpp
@@ -32,7 +32,8 @@
#include <ctime>
using namespace clang;
-MacroInfo *Preprocessor::getMacroInfoHistory(const IdentifierInfo *II) const {
+MacroDirective *
+Preprocessor::getMacroDirectiveHistory(const IdentifierInfo *II) const {
assert(II->hadMacroDefinition() && "Identifier has not been not a macro!");
macro_iterator Pos = Macros.find(II);
@@ -42,32 +43,32 @@
/// setMacroInfo - Specify a macro for this identifier.
///
-void Preprocessor::setMacroInfo(IdentifierInfo *II, MacroInfo *MI) {
+void Preprocessor::setMacroDirective(IdentifierInfo *II, MacroInfo *MI,
+ SourceLocation Loc, bool isImported) {
assert(MI && "MacroInfo should be non-zero!");
- assert(MI->getUndefLoc().isInvalid() &&
- "Undefined macros cannot be registered");
- MacroInfo *&StoredMI = Macros[II];
- MI->setPreviousDefinition(StoredMI);
- StoredMI = MI;
- II->setHasMacroDefinition(MI->getUndefLoc().isInvalid());
+ MacroDirective *MD = AllocateMacroDirective(MI, Loc, isImported);
+ MacroDirective *&StoredMD = Macros[II];
+ MD->setPrevious(StoredMD);
+ StoredMD = MD;
+ II->setHasMacroDefinition(true);
if (II->isFromAST())
II->setChangedSinceDeserialization();
}
-void Preprocessor::addLoadedMacroInfo(IdentifierInfo *II, MacroInfo *MI,
- MacroInfo *Hint) {
- assert(MI && "Missing macro?");
- assert(MI->isFromAST() && "Macro is not from an AST?");
- assert(!MI->getPreviousDefinition() && "Macro already in chain?");
+void Preprocessor::addLoadedMacroInfo(IdentifierInfo *II, MacroDirective *MD,
+ MacroDirective *Hint) {
+ assert(MD && "Missing macro?");
+ assert(MD->isImported() && "Macro is not from an AST?");
+ assert(!MD->getPrevious() && "Macro already in chain?");
- MacroInfo *&StoredMI = Macros[II];
+ MacroDirective *&StoredMD = Macros[II];
// Easy case: this is the first macro definition for this macro.
- if (!StoredMI) {
- StoredMI = MI;
+ if (!StoredMD) {
+ StoredMD = MD;
- if (MI->isDefined())
+ if (MD->isDefined())
II->setHasMacroDefinition(true);
return;
}
@@ -75,79 +76,79 @@
// If this macro is a definition and this identifier has been neither
// defined nor undef'd in the current translation unit, add this macro
// to the end of the chain of definitions.
- if (MI->isDefined() && StoredMI->isFromAST()) {
+ if (MD->isDefined() && StoredMD->isImported()) {
// Simple case: if this is the first actual definition, just put it at
// th beginning.
- if (!StoredMI->isDefined()) {
- MI->setPreviousDefinition(StoredMI);
- StoredMI = MI;
+ if (!StoredMD->isDefined()) {
+ MD->setPrevious(StoredMD);
+ StoredMD = MD;
II->setHasMacroDefinition(true);
return;
}
// Find the end of the definition chain.
- MacroInfo *Prev;
- MacroInfo *PrevPrev = StoredMI;
- bool Ambiguous = StoredMI->isAmbiguous();
+ MacroDirective *Prev;
+ MacroDirective *PrevPrev = StoredMD;
+ bool Ambiguous = StoredMD->isAmbiguous();
bool MatchedOther = false;
do {
Prev = PrevPrev;
// If the macros are not identical, we have an ambiguity.
- if (!Prev->isIdenticalTo(*MI, *this)) {
+ if (!Prev->getInfo()->isIdenticalTo(*MD->getInfo(), *this)) {
if (!Ambiguous) {
Ambiguous = true;
- StoredMI->setAmbiguous(true);
+ StoredMD->setAmbiguous(true);
}
} else {
MatchedOther = true;
}
- } while ((PrevPrev = Prev->getPreviousDefinition()) &&
+ } while ((PrevPrev = Prev->getPrevious()) &&
PrevPrev->isDefined());
// If there are ambiguous definitions, and we didn't match any other
// definition, then mark us as ambiguous.
if (Ambiguous && !MatchedOther)
- MI->setAmbiguous(true);
+ MD->setAmbiguous(true);
// Wire this macro information into the chain.
- MI->setPreviousDefinition(Prev->getPreviousDefinition());
- Prev->setPreviousDefinition(MI);
+ MD->setPrevious(Prev->getPrevious());
+ Prev->setPrevious(MD);
return;
}
// The macro is not a definition; put it at the end of the list.
- MacroInfo *Prev = Hint? Hint : StoredMI;
- while (Prev->getPreviousDefinition())
- Prev = Prev->getPreviousDefinition();
- Prev->setPreviousDefinition(MI);
+ MacroDirective *Prev = Hint? Hint : StoredMD;
+ while (Prev->getPrevious())
+ Prev = Prev->getPrevious();
+ Prev->setPrevious(MD);
}
void Preprocessor::makeLoadedMacroInfoVisible(IdentifierInfo *II,
- MacroInfo *MI) {
- assert(MI->isFromAST() && "Macro must be from the AST");
+ MacroDirective *MD) {
+ assert(MD->isImported() && "Macro must be from the AST");
- MacroInfo *&StoredMI = Macros[II];
- if (StoredMI == MI) {
+ MacroDirective *&StoredMD = Macros[II];
+ if (StoredMD == MD) {
// Easy case: this is the first macro anyway.
- II->setHasMacroDefinition(MI->isDefined());
+ II->setHasMacroDefinition(MD->isDefined());
return;
}
// Go find the macro and pull it out of the list.
// FIXME: Yes, this is O(N), and making a pile of macros visible or hidden
// would be quadratic, but it's extremely rare.
- MacroInfo *Prev = StoredMI;
- while (Prev->getPreviousDefinition() != MI)
- Prev = Prev->getPreviousDefinition();
- Prev->setPreviousDefinition(MI->getPreviousDefinition());
- MI->setPreviousDefinition(0);
+ MacroDirective *Prev = StoredMD;
+ while (Prev->getPrevious() != MD)
+ Prev = Prev->getPrevious();
+ Prev->setPrevious(MD->getPrevious());
+ MD->setPrevious(0);
// Add the macro back to the list.
- addLoadedMacroInfo(II, MI);
+ addLoadedMacroInfo(II, MD);
- II->setHasMacroDefinition(StoredMI->isDefined());
+ II->setHasMacroDefinition(StoredMD->isDefined());
if (II->isFromAST())
II->setChangedSinceDeserialization();
}
@@ -170,7 +171,7 @@
// Mark it as being a macro that is builtin.
MacroInfo *MI = PP.AllocateMacroInfo(SourceLocation());
MI->setIsBuiltinMacro();
- PP.setMacroInfo(Id, MI);
+ PP.setMacroDirective(Id, MI);
return Id;
}
diff --git a/lib/Lex/Pragma.cpp b/lib/Lex/Pragma.cpp
index 092216a..23d088a 100644
--- a/lib/Lex/Pragma.cpp
+++ b/lib/Lex/Pragma.cpp
@@ -650,17 +650,13 @@
// Get the MacroInfo associated with IdentInfo.
MacroInfo *MI = getMacroInfo(IdentInfo);
- MacroInfo *MacroCopyToPush = 0;
if (MI) {
- // Make a clone of MI.
- MacroCopyToPush = CloneMacroInfo(*MI);
-
// Allow the original MacroInfo to be redefined later.
MI->setIsAllowRedefinitionsWithoutWarning(true);
}
// Push the cloned MacroInfo so we can retrieve it later.
- PragmaPushMacroInfo[IdentInfo].push_back(MacroCopyToPush);
+ PragmaPushMacroInfo[IdentInfo].push_back(MI);
}
/// \brief Handle \#pragma pop_macro.
@@ -681,10 +677,10 @@
PragmaPushMacroInfo.find(IdentInfo);
if (iter != PragmaPushMacroInfo.end()) {
// Forget the MacroInfo currently associated with IdentInfo.
- if (MacroInfo *CurrentMI = getMacroInfo(IdentInfo)) {
- if (CurrentMI->isWarnIfUnused())
- WarnUnusedMacroLocs.erase(CurrentMI->getDefinitionLoc());
- UndefineMacro(IdentInfo, CurrentMI, MessageLoc);
+ if (MacroDirective *CurrentMD = getMacroDirective(IdentInfo)) {
+ if (CurrentMD->getInfo()->isWarnIfUnused())
+ WarnUnusedMacroLocs.erase(CurrentMD->getInfo()->getDefinitionLoc());
+ UndefineMacro(IdentInfo, CurrentMD, MessageLoc);
}
// Get the MacroInfo we want to reinstall.
@@ -692,7 +688,8 @@
if (MacroToReInstall) {
// Reinstall the previously pushed macro.
- setMacroInfo(IdentInfo, MacroToReInstall);
+ setMacroDirective(IdentInfo, MacroToReInstall, MessageLoc,
+ /*isImported=*/false);
} else if (IdentInfo->hasMacroDefinition()) {
clearMacroInfo(IdentInfo);
}
diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp
index 155074c..8209c3c 100644
--- a/lib/Lex/Preprocessor.cpp
+++ b/lib/Lex/Preprocessor.cpp
@@ -306,14 +306,15 @@
StringRef BestSpelling;
for (Preprocessor::macro_iterator I = macro_begin(), E = macro_end();
I != E; ++I) {
- if (!I->second->isObjectLike())
+ if (!I->second->getInfo()->isObjectLike())
continue;
- const MacroInfo *MI = I->second->findDefinitionAtLoc(Loc, SourceMgr);
- if (!MI)
+ const MacroDirective *
+ MD = I->second->findDirectiveAtLoc(Loc, SourceMgr);
+ if (!MD)
continue;
- if (!MacroDefinitionEquals(MI, Tokens))
+ if (!MacroDefinitionEquals(MD->getInfo(), Tokens))
continue;
- SourceLocation Location = I->second->getDefinitionLoc();
+ SourceLocation Location = I->second->getInfo()->getDefinitionLoc();
// Choose the macro defined latest.
if (BestLocation.isInvalid() ||
(Location.isValid() &&
diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp
index 5e5011b..a52d1f2 100644
--- a/lib/Sema/Sema.cpp
+++ b/lib/Sema/Sema.cpp
@@ -49,7 +49,8 @@
PrintingPolicy Policy = Context.getPrintingPolicy();
Policy.Bool = Context.getLangOpts().Bool;
if (!Policy.Bool) {
- if (MacroInfo *BoolMacro = PP.getMacroInfo(&Context.Idents.get("bool"))) {
+ if (const MacroInfo *
+ BoolMacro = PP.getMacroInfo(&Context.Idents.get("bool"))) {
Policy.Bool = BoolMacro->isObjectLike() &&
BoolMacro->getNumTokens() == 1 &&
BoolMacro->getReplacementToken(0).is(tok::kw__Bool);
diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp
index f894a0b..2cc7b85 100644
--- a/lib/Sema/SemaCodeComplete.cpp
+++ b/lib/Sema/SemaCodeComplete.cpp
@@ -2552,8 +2552,9 @@
}
if (Kind == RK_Macro) {
- MacroInfo *MI = PP.getMacroInfoHistory(Macro);
- assert(MI && "Not a macro?");
+ const MacroDirective *MD = PP.getMacroDirectiveHistory(Macro);
+ assert(MD && "Not a macro?");
+ const MacroInfo *MI = MD->getInfo();
Result.AddTypedTextChunk(
Result.getAllocator().CopyString(Macro->getName()));
diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp
index 7c394ab..f8e1c3e 100644
--- a/lib/Serialization/ASTReader.cpp
+++ b/lib/Serialization/ASTReader.cpp
@@ -1062,7 +1062,7 @@
}
void ASTReader::ReadMacroRecord(ModuleFile &F, uint64_t Offset,
- MacroInfo *Hint) {
+ MacroDirective *Hint) {
BitstreamCursor &Stream = F.MacroCursor;
// Keep track of where we are in the stream, then jump back there
@@ -1078,16 +1078,16 @@
// adding tokens.
struct AddLoadedMacroInfoRAII {
Preprocessor &PP;
- MacroInfo *Hint;
- MacroInfo *MI;
+ MacroDirective *Hint;
+ MacroDirective *MD;
IdentifierInfo *II;
- AddLoadedMacroInfoRAII(Preprocessor &PP, MacroInfo *Hint)
- : PP(PP), Hint(Hint), MI(), II() { }
+ AddLoadedMacroInfoRAII(Preprocessor &PP, MacroDirective *Hint)
+ : PP(PP), Hint(Hint), MD(), II() { }
~AddLoadedMacroInfoRAII( ) {
- if (MI) {
+ if (MD) {
// Finally, install the macro.
- PP.addLoadedMacroInfo(II, MI, Hint);
+ PP.addLoadedMacroInfo(II, MD, Hint);
}
}
} AddLoadedMacroInfo(PP, Hint);
@@ -1140,20 +1140,22 @@
unsigned NextIndex = 3;
SourceLocation Loc = ReadSourceLocation(F, Record, NextIndex);
MacroInfo *MI = PP.AllocateMacroInfo(Loc);
+ // FIXME: Location should be import location in case of module.
+ MacroDirective *MD = PP.AllocateMacroDirective(MI, Loc,
+ /*isImported=*/true);
MI->setDefinitionEndLoc(ReadSourceLocation(F, Record, NextIndex));
// Record this macro.
- MacrosLoaded[GlobalID - NUM_PREDEF_MACRO_IDS] = MI;
+ MacrosLoaded[GlobalID - NUM_PREDEF_MACRO_IDS] = MD;
SourceLocation UndefLoc = ReadSourceLocation(F, Record, NextIndex);
if (UndefLoc.isValid())
- MI->setUndefLoc(UndefLoc);
+ MD->setUndefLoc(UndefLoc);
MI->setIsUsed(Record[NextIndex++]);
- MI->setIsFromAST();
bool IsPublic = Record[NextIndex++];
- MI->setVisibility(IsPublic, ReadSourceLocation(F, Record, NextIndex));
+ MD->setVisibility(IsPublic, ReadSourceLocation(F, Record, NextIndex));
if (RecType == PP_MACRO_FUNCTION_LIKE) {
// Decode function-like macro info.
@@ -1175,13 +1177,13 @@
}
if (DeserializationListener)
- DeserializationListener->MacroRead(GlobalID, MI);
+ DeserializationListener->MacroRead(GlobalID, MD);
// If an update record marked this as undefined, do so now.
// FIXME: Only if the submodule this update came from is visible?
MacroUpdatesMap::iterator Update = MacroUpdates.find(GlobalID);
if (Update != MacroUpdates.end()) {
- if (MI->getUndefLoc().isInvalid()) {
+ if (MD->getUndefLoc().isInvalid()) {
for (unsigned I = 0, N = Update->second.size(); I != N; ++I) {
bool Hidden = false;
if (unsigned SubmoduleID = Update->second[I].first) {
@@ -1192,15 +1194,15 @@
// Record this hiding for later.
HiddenNamesMap[Owner].push_back(
- HiddenName(II, MI, Update->second[I].second.UndefLoc));
+ HiddenName(II, MD, Update->second[I].second.UndefLoc));
}
}
}
if (!Hidden) {
- MI->setUndefLoc(Update->second[I].second.UndefLoc);
+ MD->setUndefLoc(Update->second[I].second.UndefLoc);
if (PPMutationListener *Listener = PP.getPPMutationListener())
- Listener->UndefinedMacro(MI);
+ Listener->UndefinedMacro(MD);
break;
}
}
@@ -1209,7 +1211,7 @@
}
// Determine whether this macro definition is visible.
- bool Hidden = !MI->isPublic();
+ bool Hidden = !MD->isPublic();
if (!Hidden && GlobalSubmoduleID) {
if (Module *Owner = getSubmodule(GlobalSubmoduleID)) {
if (Owner->NameVisibility == Module::Hidden) {
@@ -1219,14 +1221,14 @@
// Note that this macro definition was hidden because its owning
// module is not yet visible.
- HiddenNamesMap[Owner].push_back(HiddenName(II, MI));
+ HiddenNamesMap[Owner].push_back(HiddenName(II, MD));
}
}
}
- MI->setHidden(Hidden);
+ MD->setHidden(Hidden);
// Make sure we install the macro once we're done.
- AddLoadedMacroInfo.MI = MI;
+ AddLoadedMacroInfo.MD = MD;
AddLoadedMacroInfo.II = II;
// Remember that we saw this macro last so that we add the tokens that
@@ -2639,7 +2641,7 @@
break;
}
case HiddenName::MacroVisibility: {
- std::pair<IdentifierInfo *, MacroInfo *> Macro = Names[I].getMacro();
+ std::pair<IdentifierInfo *, MacroDirective *> Macro = Names[I].getMacro();
Macro.second->setHidden(!Macro.second->isPublic());
if (Macro.second->isDefined()) {
PP.makeLoadedMacroInfoVisible(Macro.first, Macro.second);
@@ -2648,7 +2650,7 @@
}
case HiddenName::MacroUndef: {
- std::pair<IdentifierInfo *, MacroInfo *> Macro = Names[I].getMacro();
+ std::pair<IdentifierInfo *, MacroDirective *> Macro = Names[I].getMacro();
if (Macro.second->isDefined()) {
Macro.second->setUndefLoc(Names[I].getMacroUndefLoc());
if (PPMutationListener *Listener = PP.getPPMutationListener())
@@ -5638,7 +5640,7 @@
unsigned NumMacrosLoaded
= MacrosLoaded.size() - std::count(MacrosLoaded.begin(),
MacrosLoaded.end(),
- (MacroInfo *)0);
+ (MacroDirective *)0);
unsigned NumSelectorsLoaded
= SelectorsLoaded.size() - std::count(SelectorsLoaded.begin(),
SelectorsLoaded.end(),
@@ -6247,7 +6249,7 @@
return LocalID + I->second;
}
-MacroInfo *ASTReader::getMacro(MacroID ID, MacroInfo *Hint) {
+MacroDirective *ASTReader::getMacro(MacroID ID, MacroDirective *Hint) {
if (ID == 0)
return 0;
@@ -6979,7 +6981,7 @@
for (unsigned I = 0; I != PendingMacroIDs.size(); ++I) {
// FIXME: std::move here
SmallVector<MacroID, 2> GlobalIDs = PendingMacroIDs.begin()[I].second;
- MacroInfo *Hint = 0;
+ MacroDirective *Hint = 0;
for (unsigned IDIdx = 0, NumIDs = GlobalIDs.size(); IDIdx != NumIDs;
++IDIdx) {
Hint = getMacro(GlobalIDs[IDIdx], Hint);
diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp
index 8747bc8..f33fbc2 100644
--- a/lib/Serialization/ASTWriter.cpp
+++ b/lib/Serialization/ASTWriter.cpp
@@ -1746,7 +1746,7 @@
// emitting each to the PP section.
// Construct the list of macro definitions that need to be serialized.
- SmallVector<std::pair<const IdentifierInfo *, MacroInfo *>, 2>
+ SmallVector<std::pair<const IdentifierInfo *, MacroDirective *>, 2>
MacrosToEmit;
llvm::SmallPtrSet<const IdentifierInfo*, 4> MacroDefinitionsSeen;
for (Preprocessor::macro_iterator I = PP.macro_begin(Chain == 0),
@@ -1774,19 +1774,19 @@
for (unsigned I = 0, N = MacrosToEmit.size(); I != N; ++I) {
const IdentifierInfo *Name = MacrosToEmit[I].first;
- for (MacroInfo *MI = MacrosToEmit[I].second; MI;
- MI = MI->getPreviousDefinition()) {
- MacroID ID = getMacroRef(MI);
+ for (MacroDirective *MD = MacrosToEmit[I].second; MD;
+ MD = MD->getPrevious()) {
+ MacroID ID = getMacroRef(MD);
if (!ID)
continue;
// Skip macros from a AST file if we're chaining.
- if (Chain && MI->isFromAST() && !MI->hasChangedAfterLoad())
+ if (Chain && MD->isImported() && !MD->hasChangedAfterLoad())
continue;
if (ID < FirstMacroID) {
// This will have been dealt with via an update record.
- assert(MacroUpdates.count(MI) > 0 && "Missing macro update");
+ assert(MacroUpdates.count(MD) > 0 && "Missing macro update");
continue;
}
@@ -1802,14 +1802,15 @@
}
AddIdentifierRef(Name, Record);
- addMacroRef(MI, Record);
+ addMacroRef(MD, Record);
+ const MacroInfo *MI = MD->getInfo();
Record.push_back(inferSubmoduleIDFromLocation(MI->getDefinitionLoc()));
AddSourceLocation(MI->getDefinitionLoc(), Record);
AddSourceLocation(MI->getDefinitionEndLoc(), Record);
- AddSourceLocation(MI->getUndefLoc(), Record);
+ AddSourceLocation(MD->getUndefLoc(), Record);
Record.push_back(MI->isUsed());
- Record.push_back(MI->isPublic());
- AddSourceLocation(MI->getVisibilityLocation(), Record);
+ Record.push_back(MD->isPublic());
+ AddSourceLocation(MD->getVisibilityLocation(), Record);
unsigned Code;
if (MI->isObjectLike()) {
Code = PP_MACRO_OBJECT_LIKE;
@@ -2643,7 +2644,7 @@
/// \brief Determines whether this is an "interesting" identifier
/// that needs a full IdentifierInfo structure written into the hash
/// table.
- bool isInterestingIdentifier(IdentifierInfo *II, MacroInfo *&Macro) {
+ bool isInterestingIdentifier(IdentifierInfo *II, MacroDirective *&Macro) {
if (II->isPoisoned() ||
II->isExtensionToken() ||
II->getObjCOrBuiltinID() ||
@@ -2654,12 +2655,13 @@
return hadMacroDefinition(II, Macro);
}
- bool hadMacroDefinition(IdentifierInfo *II, MacroInfo *&Macro) {
+ bool hadMacroDefinition(IdentifierInfo *II, MacroDirective *&Macro) {
if (!II->hadMacroDefinition())
return false;
- if (Macro || (Macro = PP.getMacroInfoHistory(II)))
- return !Macro->isBuiltinMacro() && (!IsModule || Macro->isPublic());
+ if (Macro || (Macro = PP.getMacroDirectiveHistory(II)))
+ return !Macro->getInfo()->isBuiltinMacro() &&
+ (!IsModule || Macro->isPublic());
return false;
}
@@ -2683,12 +2685,12 @@
EmitKeyDataLength(raw_ostream& Out, IdentifierInfo* II, IdentID ID) {
unsigned KeyLen = II->getLength() + 1;
unsigned DataLen = 4; // 4 bytes for the persistent ID << 1
- MacroInfo *Macro = 0;
+ MacroDirective *Macro = 0;
if (isInterestingIdentifier(II, Macro)) {
DataLen += 2; // 2 bytes for builtin ID
DataLen += 2; // 2 bytes for flags
if (hadMacroDefinition(II, Macro)) {
- for (MacroInfo *M = Macro; M; M = M->getPreviousDefinition()) {
+ for (MacroDirective *M = Macro; M; M = M->getPrevious()) {
if (Writer.getMacroRef(M) != 0)
DataLen += 4;
}
@@ -2719,7 +2721,7 @@
void EmitData(raw_ostream& Out, IdentifierInfo* II,
IdentID ID, unsigned) {
- MacroInfo *Macro = 0;
+ MacroDirective *Macro = 0;
if (!isInterestingIdentifier(II, Macro)) {
clang::io::Emit32(Out, ID << 1);
return;
@@ -2740,7 +2742,7 @@
if (HadMacroDefinition) {
// Write all of the macro IDs associated with this identifier.
- for (MacroInfo *M = Macro; M; M = M->getPreviousDefinition()) {
+ for (MacroDirective *M = Macro; M; M = M->getPrevious()) {
if (MacroID ID = Writer.getMacroRef(M))
clang::io::Emit32(Out, ID);
}
@@ -3943,8 +3945,8 @@
Record.push_back(getIdentifierRef(II));
}
-void ASTWriter::addMacroRef(MacroInfo *MI, RecordDataImpl &Record) {
- Record.push_back(getMacroRef(MI));
+void ASTWriter::addMacroRef(MacroDirective *MD, RecordDataImpl &Record) {
+ Record.push_back(getMacroRef(MD));
}
IdentID ASTWriter::getIdentifierRef(const IdentifierInfo *II) {
@@ -3957,14 +3959,14 @@
return ID;
}
-MacroID ASTWriter::getMacroRef(MacroInfo *MI) {
+MacroID ASTWriter::getMacroRef(MacroDirective *MD) {
// Don't emit builtin macros like __LINE__ to the AST file unless they
// have been redefined by the header (in which case they are not
// isBuiltinMacro).
- if (MI == 0 || MI->isBuiltinMacro())
+ if (MD == 0 || MD->getInfo()->isBuiltinMacro())
return 0;
- MacroID &ID = MacroIDs[MI];
+ MacroID &ID = MacroIDs[MD];
if (ID == 0)
ID = NextMacroID++;
return ID;
@@ -4709,9 +4711,9 @@
StoredID = ID;
}
-void ASTWriter::MacroRead(serialization::MacroID ID, MacroInfo *MI) {
+void ASTWriter::MacroRead(serialization::MacroID ID, MacroDirective *MD) {
// Always keep the highest ID. See \p TypeRead() for more information.
- MacroID &StoredID = MacroIDs[MI];
+ MacroID &StoredID = MacroIDs[MD];
if (ID > StoredID)
StoredID = ID;
}
@@ -4745,8 +4747,8 @@
SubmoduleIDs[Mod] = ID;
}
-void ASTWriter::UndefinedMacro(MacroInfo *MI) {
- MacroUpdates[MI].UndefLoc = MI->getUndefLoc();
+void ASTWriter::UndefinedMacro(MacroDirective *MD) {
+ MacroUpdates[MD].UndefLoc = MD->getUndefLoc();
}
void ASTWriter::CompletedTagDefinition(const TagDecl *D) {