From 47d9de678162202786aa5f8aa153a7c58a4cebd4 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Fri, 8 Jun 2012 16:40:28 +0000 Subject: [PATCH] Switch LineTableInfo to use FileID instead of int for file references, from Tom Honermann! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158211 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/SourceManagerInternals.h | 13 +++++++------ lib/Basic/SourceManager.cpp | 16 ++++++++-------- lib/Serialization/ASTReader.cpp | 2 +- lib/Serialization/ASTWriter.cpp | 4 ++-- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/include/clang/Basic/SourceManagerInternals.h b/include/clang/Basic/SourceManagerInternals.h index 1cb16b458f..827de30aeb 100644 --- a/include/clang/Basic/SourceManagerInternals.h +++ b/include/clang/Basic/SourceManagerInternals.h @@ -15,6 +15,7 @@ #ifndef LLVM_CLANG_SOURCEMANAGER_INTERNALS_H #define LLVM_CLANG_SOURCEMANAGER_INTERNALS_H +#include "clang/Basic/SourceLocation.h" #include "clang/Basic/SourceManager.h" #include "llvm/ADT/StringMap.h" #include @@ -84,7 +85,7 @@ class LineTableInfo { /// LineEntries - This is a map from FileIDs to a list of line entries (sorted /// by the offset they occur in the file. - std::map > LineEntries; + std::map > LineEntries; public: LineTableInfo() { } @@ -104,25 +105,25 @@ public: } unsigned getNumFilenames() const { return FilenamesByID.size(); } - void AddLineNote(int FID, unsigned Offset, + void AddLineNote(FileID FID, unsigned Offset, unsigned LineNo, int FilenameID); - void AddLineNote(int FID, unsigned Offset, + void AddLineNote(FileID FID, unsigned Offset, unsigned LineNo, int FilenameID, unsigned EntryExit, SrcMgr::CharacteristicKind FileKind); /// FindNearestLineEntry - Find the line entry nearest to FID that is before /// it. If there is no line entry before Offset in FID, return null. - const LineEntry *FindNearestLineEntry(int FID, unsigned Offset); + const LineEntry *FindNearestLineEntry(FileID FID, unsigned Offset); // Low-level access - typedef std::map >::iterator iterator; + typedef std::map >::iterator iterator; iterator begin() { return LineEntries.begin(); } iterator end() { return LineEntries.end(); } /// \brief Add a new line entry that has already been encoded into /// the internal representation of the line table. - void AddEntry(int FID, const std::vector &Entries); + void AddEntry(FileID FID, const std::vector &Entries); }; } // end namespace clang diff --git a/lib/Basic/SourceManager.cpp b/lib/Basic/SourceManager.cpp index 783e073e66..bf233fa1cc 100644 --- a/lib/Basic/SourceManager.cpp +++ b/lib/Basic/SourceManager.cpp @@ -191,7 +191,7 @@ unsigned LineTableInfo::getLineTableFilenameID(StringRef Name) { /// AddLineNote - Add a line note to the line table that indicates that there /// is a #line at the specified FID/Offset location which changes the presumed /// location to LineNo/FilenameID. -void LineTableInfo::AddLineNote(int FID, unsigned Offset, +void LineTableInfo::AddLineNote(FileID FID, unsigned Offset, unsigned LineNo, int FilenameID) { std::vector &Entries = LineEntries[FID]; @@ -222,7 +222,7 @@ void LineTableInfo::AddLineNote(int FID, unsigned Offset, /// presumed #include stack. If it is 1, this is a file entry, if it is 2 then /// this is a file exit. FileKind specifies whether this is a system header or /// extern C system header. -void LineTableInfo::AddLineNote(int FID, unsigned Offset, +void LineTableInfo::AddLineNote(FileID FID, unsigned Offset, unsigned LineNo, int FilenameID, unsigned EntryExit, SrcMgr::CharacteristicKind FileKind) { @@ -256,7 +256,7 @@ void LineTableInfo::AddLineNote(int FID, unsigned Offset, /// FindNearestLineEntry - Find the line entry nearest to FID that is before /// it. If there is no line entry before Offset in FID, return null. -const LineEntry *LineTableInfo::FindNearestLineEntry(int FID, +const LineEntry *LineTableInfo::FindNearestLineEntry(FileID FID, unsigned Offset) { const std::vector &Entries = LineEntries[FID]; assert(!Entries.empty() && "No #line entries for this FID after all!"); @@ -275,7 +275,7 @@ const LineEntry *LineTableInfo::FindNearestLineEntry(int FID, /// \brief Add a new line entry that has already been encoded into /// the internal representation of the line table. -void LineTableInfo::AddEntry(int FID, +void LineTableInfo::AddEntry(FileID FID, const std::vector &Entries) { LineEntries[FID] = Entries; } @@ -308,7 +308,7 @@ void SourceManager::AddLineNote(SourceLocation Loc, unsigned LineNo, if (LineTable == 0) LineTable = new LineTableInfo(); - LineTable->AddLineNote(LocInfo.first.ID, LocInfo.second, LineNo, FilenameID); + LineTable->AddLineNote(LocInfo.first, LocInfo.second, LineNo, FilenameID); } /// AddLineNote - Add a GNU line marker to the line table. @@ -353,7 +353,7 @@ void SourceManager::AddLineNote(SourceLocation Loc, unsigned LineNo, else if (IsFileExit) EntryExit = 2; - LineTable->AddLineNote(LocInfo.first.ID, LocInfo.second, LineNo, FilenameID, + LineTable->AddLineNote(LocInfo.first, LocInfo.second, LineNo, FilenameID, EntryExit, FileKind); } @@ -1315,7 +1315,7 @@ SourceManager::getFileCharacteristic(SourceLocation Loc) const { assert(LineTable && "Can't have linetable entries without a LineTable!"); // See if there is a #line directive before the location. const LineEntry *Entry = - LineTable->FindNearestLineEntry(LocInfo.first.ID, LocInfo.second); + LineTable->FindNearestLineEntry(LocInfo.first, LocInfo.second); // If this is before the first line marker, use the file characteristic. if (!Entry) @@ -1380,7 +1380,7 @@ PresumedLoc SourceManager::getPresumedLoc(SourceLocation Loc) const { assert(LineTable && "Can't have linetable entries without a LineTable!"); // See if there is a #line directive before this. If so, get it. if (const LineEntry *Entry = - LineTable->FindNearestLineEntry(LocInfo.first.ID, LocInfo.second)) { + LineTable->FindNearestLineEntry(LocInfo.first, LocInfo.second)) { // If the LineEntry indicates a filename, use it. if (Entry->FilenameID != -1) Filename = LineTable->getFilename(Entry->FilenameID); diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 3b59163d24..b762d1c65f 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -829,7 +829,7 @@ bool ASTReader::ParseLineTable(ModuleFile &F, Entries.push_back(LineEntry::get(FileOffset, LineNo, FilenameID, FileKind, IncludeOffset)); } - LineTable.AddEntry(FID, Entries); + LineTable.AddEntry(FileID::get(FID), Entries); } return false; diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index 0eb2f1675b..bda665698f 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -1604,11 +1604,11 @@ void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr, for (LineTableInfo::iterator L = LineTable.begin(), LEnd = LineTable.end(); L != LEnd; ++L) { // Only emit entries for local files. - if (L->first < 0) + if (L->first.ID < 0) continue; // Emit the file ID - Record.push_back(L->first); + Record.push_back(L->first.ID); // Emit the line entries Record.push_back(L->second.size()); -- 2.40.0