/// \brief Specify a macro for this identifier.
void setMacroInfo(IdentifierInfo *II, MacroInfo *MI);
/// \brief Add a MacroInfo that was loaded from an AST file.
- void addLoadedMacroInfo(IdentifierInfo *II, MacroInfo *MI);
+ void addLoadedMacroInfo(IdentifierInfo *II, MacroInfo *MI,
+ MacroInfo *Hint = 0);
/// \brief Make the given MacroInfo, that was loaded from an AST file and
/// previously hidden, visible.
void makeLoadedMacroInfoVisible(IdentifierInfo *II, MacroInfo *MI);
unsigned LocalID);
/// \brief Retrieve the macro with the given ID.
- MacroInfo *getMacro(serialization::MacroID ID);
+ MacroInfo *getMacro(serialization::MacroID ID, MacroInfo *Hint = 0);
/// \brief Retrieve the global macro ID corresponding to the given local
/// ID within the given module file.
Expr *ReadSubExpr();
/// \brief Reads the macro record located at the given offset.
- void ReadMacroRecord(ModuleFile &F, uint64_t Offset);
+ void ReadMacroRecord(ModuleFile &F, uint64_t Offset, MacroInfo *Hint = 0);
/// \brief Determine the global preprocessed entity ID that corresponds to
/// the given local ID within the given module.
II->setChangedSinceDeserialization();
}
-void Preprocessor::addLoadedMacroInfo(IdentifierInfo *II, MacroInfo *MI) {
+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?");
}
// The macro is not a definition; put it at the end of the list.
- // FIXME: Adding macro history is quadratic, but a hint could fix this.
- MacroInfo *Prev = StoredMI;
+ MacroInfo *Prev = Hint? Hint : StoredMI;
while (Prev->getPreviousDefinition())
Prev = Prev->getPreviousDefinition();
Prev->setPreviousDefinition(MI);
}
}
-void ASTReader::ReadMacroRecord(ModuleFile &F, uint64_t Offset) {
+void ASTReader::ReadMacroRecord(ModuleFile &F, uint64_t Offset,
+ MacroInfo *Hint) {
llvm::BitstreamCursor &Stream = F.MacroCursor;
// Keep track of where we are in the stream, then jump back there
MI->setHidden(Hidden);
// Finally, install the macro.
- PP.addLoadedMacroInfo(II, MI);
+ PP.addLoadedMacroInfo(II, MI, Hint);
// Remember that we saw this macro last so that we add the tokens that
// form its body to it.
return LocalID + I->second;
}
-MacroInfo *ASTReader::getMacro(MacroID ID) {
+MacroInfo *ASTReader::getMacro(MacroID ID, MacroInfo *Hint) {
if (ID == 0)
return 0;
assert(I != GlobalMacroMap.end() && "Corrupted global macro map");
ModuleFile *M = I->second;
unsigned Index = ID - M->BaseMacroID;
- ReadMacroRecord(*M, M->MacroOffsets[Index]);
+ ReadMacroRecord(*M, M->MacroOffsets[Index], Hint);
}
return MacrosLoaded[ID];
for (unsigned I = 0; I != PendingMacroIDs.size(); ++I) {
// FIXME: std::move here
SmallVector<MacroID, 2> GlobalIDs = PendingMacroIDs.begin()[I].second;
+ MacroInfo *Hint = 0;
for (unsigned IDIdx = 0, NumIDs = GlobalIDs.size(); IDIdx != NumIDs;
++IDIdx) {
- getMacro(GlobalIDs[IDIdx]);
+ Hint = getMacro(GlobalIDs[IDIdx], Hint);
}
}
PendingMacroIDs.clear();