[PCH/Modules] Revert r172843, it caused a module to fail building.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172884 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Argyrios Kyrtzidis 2013-01-19 03:14:56 +00:00
Родитель 1dfebd9f99
Коммит dc1088f620
6 изменённых файлов: 62 добавлений и 61 удалений

Просмотреть файл

@ -169,14 +169,6 @@ public:
/// \brief Get previous definition of the macro with the same name.
MacroInfo *getPreviousDefinition() { return PreviousDefinition; }
/// \brief Get the first definition in the chain.
MacroInfo *getFirstDefinition() {
MacroInfo *MI = this;
while (MI->PreviousDefinition)
MI = MI->PreviousDefinition;
return MI;
}
/// \brief Find macro definition active in the specified source location. If
/// this macro was not defined there, return NULL.
const MacroInfo *findDefinitionAtLoc(SourceLocation L,

Просмотреть файл

@ -533,7 +533,8 @@ public:
/// \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);

Просмотреть файл

@ -1535,7 +1535,7 @@ public:
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.
@ -1693,19 +1693,20 @@ public:
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.
serialization::PreprocessedEntityID
getGlobalPreprocessedEntityID(ModuleFile &M, unsigned LocalID) const;
/// \brief Add the macro ID assosiated with \c II for deserialization.
/// \brief Note that the identifier has a macro history.
///
/// \param II The name of the macro.
/// \param ID The global macro ID that is associated with this identifier.
void addMacroIDForDeserialization(IdentifierInfo *II,
serialization::MacroID ID);
///
/// \param IDs The global macro IDs that are associated with this identifier.
void setIdentifierIsMacro(IdentifierInfo *II,
ArrayRef<serialization::MacroID> IDs);
/// \brief Read the set of macros defined by this external macro source.
virtual void ReadDefinedMacros();

Просмотреть файл

@ -55,9 +55,11 @@ void Preprocessor::setMacroInfo(IdentifierInfo *II, MacroInfo *MI) {
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?");
MacroInfo *&StoredMI = Macros[II];
@ -77,7 +79,7 @@ void Preprocessor::addLoadedMacroInfo(IdentifierInfo *II, MacroInfo *MI) {
// Simple case: if this is the first actual definition, just put it at
// th beginning.
if (!StoredMI->isDefined()) {
MI->getFirstDefinition()->setPreviousDefinition(StoredMI);
MI->setPreviousDefinition(StoredMI);
StoredMI = MI;
II->setHasMacroDefinition(true);
@ -110,14 +112,16 @@ void Preprocessor::addLoadedMacroInfo(IdentifierInfo *II, MacroInfo *MI) {
MI->setAmbiguous(true);
// Wire this macro information into the chain.
MI->getFirstDefinition()->setPreviousDefinition(
Prev->getPreviousDefinition());
MI->setPreviousDefinition(Prev->getPreviousDefinition());
Prev->setPreviousDefinition(MI);
return;
}
// The macro is not a definition; put it at the end of the list.
StoredMI->getFirstDefinition()->setPreviousDefinition(MI);
MacroInfo *Prev = Hint? Hint : StoredMI;
while (Prev->getPreviousDefinition())
Prev = Prev->getPreviousDefinition();
Prev->setPreviousDefinition(MI);
}
void Preprocessor::makeLoadedMacroInfoVisible(IdentifierInfo *II,

Просмотреть файл

@ -525,9 +525,13 @@ IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k,
// If this identifier is a macro, deserialize the macro
// definition.
if (hadMacroDefinition) {
SmallVector<MacroID, 4> MacroIDs;
while (uint32_t LocalID = ReadUnalignedLE32(d)) {
MacroIDs.push_back(Reader.getGlobalMacroID(F, LocalID));
DataLen -= 4;
}
DataLen -= 4;
uint32_t LocalID = ReadUnalignedLE32(d);
Reader.addMacroIDForDeserialization(II, Reader.getGlobalMacroID(F,LocalID));
Reader.setIdentifierIsMacro(II, MacroIDs);
}
Reader.SetIdentifierInfo(ID, II);
@ -1057,7 +1061,8 @@ bool ASTReader::ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor,
}
}
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
@ -1073,18 +1078,19 @@ void ASTReader::ReadMacroRecord(ModuleFile &F, uint64_t Offset) {
// adding tokens.
struct AddLoadedMacroInfoRAII {
Preprocessor &PP;
MacroInfo *Hint;
MacroInfo *MI;
IdentifierInfo *II;
explicit AddLoadedMacroInfoRAII(Preprocessor &PP)
: PP(PP), MI(), II() { }
AddLoadedMacroInfoRAII(Preprocessor &PP, MacroInfo *Hint)
: PP(PP), Hint(Hint), MI(), II() { }
~AddLoadedMacroInfoRAII( ) {
if (MI) {
// Finally, install the macro.
PP.addLoadedMacroInfo(II, MI);
PP.addLoadedMacroInfo(II, MI, Hint);
}
}
} AddLoadedMacroInfo(PP);
} AddLoadedMacroInfo(PP, Hint);
while (true) {
unsigned Code = Stream.ReadCode();
@ -1140,9 +1146,6 @@ void ASTReader::ReadMacroRecord(ModuleFile &F, uint64_t Offset) {
SourceLocation Loc = ReadSourceLocation(F, Record, NextIndex);
MacroInfo *MI = PP.AllocateMacroInfo(Loc);
MI->setDefinitionEndLoc(ReadSourceLocation(F, Record, NextIndex));
bool isHeadMI = Record[NextIndex++];
MacroInfo *PrevMI = getMacro(getGlobalMacroID(F, Record[NextIndex++]));
MI->setPreviousDefinition(PrevMI);
// Record this macro.
MacrosLoaded[GlobalID - NUM_PREDEF_MACRO_IDS] = MI;
@ -1227,11 +1230,9 @@ void ASTReader::ReadMacroRecord(ModuleFile &F, uint64_t Offset) {
}
MI->setHidden(Hidden);
if (isHeadMI) {
// Make sure we install the macro once we're done.
AddLoadedMacroInfo.MI = MI;
AddLoadedMacroInfo.II = II;
}
// Make sure we install the macro once we're done.
AddLoadedMacroInfo.MI = MI;
AddLoadedMacroInfo.II = II;
// Remember that we saw this macro last so that we add the tokens that
// form its body to it.
@ -1340,13 +1341,10 @@ HeaderFileInfoTrait::ReadData(const internal_key_type, const unsigned char *d,
return HFI;
}
void ASTReader::addMacroIDForDeserialization(IdentifierInfo *II, MacroID ID){
void ASTReader::setIdentifierIsMacro(IdentifierInfo *II, ArrayRef<MacroID> IDs){
II->setHadMacroDefinition(true);
assert(NumCurrentElementsDeserializing > 0 &&"Missing deserialization guard");
SmallVector<serialization::MacroID, 2> &MacroIDs = PendingMacroIDs[II];
assert(std::find(MacroIDs.begin(), MacroIDs.end(), ID) == MacroIDs.end() &&
"Already added the macro ID for deserialization");
MacroIDs.push_back(ID);
PendingMacroIDs[II].append(IDs.begin(), IDs.end());
}
void ASTReader::ReadDefinedMacros() {
@ -6162,7 +6160,7 @@ IdentifierID ASTReader::getGlobalIdentifierID(ModuleFile &M, unsigned LocalID) {
return LocalID + I->second;
}
MacroInfo *ASTReader::getMacro(MacroID ID) {
MacroInfo *ASTReader::getMacro(MacroID ID, MacroInfo *Hint) {
if (ID == 0)
return 0;
@ -6178,7 +6176,7 @@ MacroInfo *ASTReader::getMacro(MacroID ID) {
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];
@ -6877,14 +6875,13 @@ void ASTReader::finishPendingActions() {
PendingDeclChains.clear();
// Load any pending macro definitions.
// Note that new macros may be added while deserializing a macro.
for (unsigned I = 0; I != PendingMacroIDs.size(); ++I) {
PendingMacroIDsMap::iterator PMIt = PendingMacroIDs.begin() + I;
SmallVector<serialization::MacroID, 2> MacroIDs;
MacroIDs.swap(PMIt->second);
for (SmallVectorImpl<serialization::MacroID>::iterator
MIt = MacroIDs.begin(), ME = MacroIDs.end(); MIt != ME; ++MIt) {
getMacro(*MIt);
// 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) {
Hint = getMacro(GlobalIDs[IDIdx], Hint);
}
}
PendingMacroIDs.clear();

Просмотреть файл

@ -1798,10 +1798,12 @@ void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) {
// Construct the list of macro definitions that need to be serialized.
SmallVector<std::pair<const IdentifierInfo *, MacroInfo *>, 2>
MacrosToEmit;
llvm::SmallPtrSet<const IdentifierInfo*, 4> MacroDefinitionsSeen;
for (Preprocessor::macro_iterator I = PP.macro_begin(Chain == 0),
E = PP.macro_end(Chain == 0);
I != E; ++I) {
if (!IsModule || I->second->isPublic()) {
MacroDefinitionsSeen.insert(I->first);
MacrosToEmit.push_back(std::make_pair(I->first, I->second));
}
}
@ -1821,9 +1823,9 @@ void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) {
for (unsigned I = 0, N = MacrosToEmit.size(); I != N; ++I) {
const IdentifierInfo *Name = MacrosToEmit[I].first;
MacroInfo *HeadMI = MacrosToEmit[I].second;
for (MacroInfo *MI = HeadMI; MI; MI = MI->getPreviousDefinition()) {
for (MacroInfo *MI = MacrosToEmit[I].second; MI;
MI = MI->getPreviousDefinition()) {
MacroID ID = getMacroRef(MI);
if (!ID)
continue;
@ -1854,13 +1856,6 @@ void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) {
Record.push_back(inferSubmoduleIDFromLocation(MI->getDefinitionLoc()));
AddSourceLocation(MI->getDefinitionLoc(), Record);
AddSourceLocation(MI->getDefinitionEndLoc(), Record);
Record.push_back(MI == HeadMI);
MacroInfo *PrevMI = MI->getPreviousDefinition();
// Serialize only the part of the definition chain that is local.
// The chain will be synthesized across modules by the ASTReader.
if (Chain && PrevMI && PrevMI->isFromAST())
PrevMI = 0;
addMacroRef(PrevMI, Record);
AddSourceLocation(MI->getUndefLoc(), Record);
Record.push_back(MI->isUsed());
Record.push_back(MI->isPublic());
@ -2742,8 +2737,14 @@ public:
if (isInterestingIdentifier(II, Macro)) {
DataLen += 2; // 2 bytes for builtin ID
DataLen += 2; // 2 bytes for flags
if (hadMacroDefinition(II, Macro))
if (hadMacroDefinition(II, Macro)) {
for (MacroInfo *M = Macro; M; M = M->getPreviousDefinition()) {
if (Writer.getMacroRef(M) != 0)
DataLen += 4;
}
DataLen += 4;
}
for (IdentifierResolver::iterator D = IdResolver.begin(II),
DEnd = IdResolver.end();
@ -2788,8 +2789,13 @@ public:
clang::io::Emit16(Out, Bits);
if (HadMacroDefinition) {
// Write the macro ID associated with this identifier.
clang::io::Emit32(Out, Writer.getMacroRef(Macro));
// Write all of the macro IDs associated with this identifier.
for (MacroInfo *M = Macro; M; M = M->getPreviousDefinition()) {
if (MacroID ID = Writer.getMacroRef(M))
clang::io::Emit32(Out, ID);
}
clang::io::Emit32(Out, 0);
}
// Emit the declaration IDs in reverse order, because the