diff options
Diffstat (limited to 'lib/Driver')
-rw-r--r-- | lib/Driver/HTMLDiagnostics.cpp | 92 | ||||
-rw-r--r-- | lib/Driver/PlistDiagnostics.cpp | 29 |
2 files changed, 59 insertions, 62 deletions
diff --git a/lib/Driver/HTMLDiagnostics.cpp b/lib/Driver/HTMLDiagnostics.cpp index f335396ec4..81cedba557 100644 --- a/lib/Driver/HTMLDiagnostics.cpp +++ b/lib/Driver/HTMLDiagnostics.cpp @@ -49,10 +49,10 @@ public: virtual void HandlePathDiagnostic(const PathDiagnostic* D); - void HandlePiece(Rewriter& R, unsigned BugFileID, + void HandlePiece(Rewriter& R, FileID BugFileID, const PathDiagnosticPiece& P, unsigned num, unsigned max); - void HighlightRange(Rewriter& R, unsigned BugFileID, SourceRange Range); + void HighlightRange(Rewriter& R, FileID BugFileID, SourceRange Range); void ReportDiag(const PathDiagnostic& D); }; @@ -125,17 +125,15 @@ void HTMLDiagnostics::ReportDiag(const PathDiagnostic& D) { return; SourceManager &SMgr = D.begin()->getLocation().getManager(); - unsigned FileID = 0; - bool FileIDInitialized = false; + FileID FID; // Verify that the entire path is from the same FileID. for (PathDiagnostic::const_iterator I = D.begin(), E = D.end(); I != E; ++I) { FullSourceLoc L = I->getLocation().getInstantiationLoc(); - if (!FileIDInitialized) { - FileID = SMgr.getCanonicalFileID(L); - FileIDInitialized = true; - } else if (SMgr.getCanonicalFileID(L) != FileID) + if (FID.isInvalid()) { + FID = SMgr.getCanonicalFileID(L); + } else if (SMgr.getCanonicalFileID(L) != FID) return; // FIXME: Emit a warning? // Check the source ranges. @@ -147,7 +145,7 @@ void HTMLDiagnostics::ReportDiag(const PathDiagnostic& D) { if (!L.isFileID()) return; // FIXME: Emit a warning? - if (SMgr.getCanonicalFileID(L) != FileID) + if (SMgr.getCanonicalFileID(L) != FID) return; // FIXME: Emit a warning? L = SMgr.getInstantiationLoc(RI->getEnd()); @@ -155,12 +153,12 @@ void HTMLDiagnostics::ReportDiag(const PathDiagnostic& D) { if (!L.isFileID()) return; // FIXME: Emit a warning? - if (SMgr.getCanonicalFileID(L) != FileID) + if (SMgr.getCanonicalFileID(L) != FID) return; // FIXME: Emit a warning? } } - if (!FileIDInitialized) + if (FID.isInvalid()) return; // FIXME: Emit a warning? // Create a new rewriter to generate HTML. @@ -174,31 +172,31 @@ void HTMLDiagnostics::ReportDiag(const PathDiagnostic& D) { for (PathDiagnostic::const_reverse_iterator I=D.rbegin(), E=D.rend(); I!=E; ++I, --n) { - HandlePiece(R, FileID, *I, n, max); + HandlePiece(R, FID, *I, n, max); } // Add line numbers, header, footer, etc. - // unsigned FileID = R.getSourceMgr().getMainFileID(); - html::EscapeText(R, FileID); - html::AddLineNumbers(R, FileID); + // unsigned FID = R.getSourceMgr().getMainFileID(); + html::EscapeText(R, FID); + html::AddLineNumbers(R, FID); // If we have a preprocessor, relex the file and syntax highlight. // We might not have a preprocessor if we come from a deserialized AST file, // for example. - if (PP) html::SyntaxHighlight(R, FileID, *PP); + if (PP) html::SyntaxHighlight(R, FID, *PP); // FIXME: We eventually want to use PPF to create a fresh Preprocessor, // once we have worked out the bugs. // - // if (PPF) html::HighlightMacros(R, FileID, *PPF); + // if (PPF) html::HighlightMacros(R, FID, *PPF); // - if (PP) html::HighlightMacros(R, FileID, *PP); + if (PP) html::HighlightMacros(R, FID, *PP); // Get the full directory name of the analyzed file. - const FileEntry* Entry = SMgr.getFileEntryForID(FileID); + const FileEntry* Entry = SMgr.getFileEntryForID(FID); // This is a cludge; basically we want to append either the full // working directory if we have no directory information. This is @@ -241,7 +239,7 @@ void HTMLDiagnostics::ReportDiag(const PathDiagnostic& D) { os << "</table>\n<!-- REPORTSUMMARYEXTRA -->\n" "<h3>Annotated Source Code</h3>\n"; - R.InsertStrBefore(SourceLocation::getFileLoc(FileID, 0), os.str()); + R.InsertStrBefore(SMgr.getLocForStartOfFile(FID), os.str()); } // Embed meta-data tags. @@ -252,7 +250,7 @@ void HTMLDiagnostics::ReportDiag(const PathDiagnostic& D) { std::string s; llvm::raw_string_ostream os(s); os << "\n<!-- BUGDESC " << BugDesc << " -->\n"; - R.InsertStrBefore(SourceLocation::getFileLoc(FileID, 0), os.str()); + R.InsertStrBefore(SMgr.getLocForStartOfFile(FID), os.str()); } const std::string& BugCategory = D.getCategory(); @@ -261,14 +259,14 @@ void HTMLDiagnostics::ReportDiag(const PathDiagnostic& D) { std::string s; llvm::raw_string_ostream os(s); os << "\n<!-- BUGCATEGORY " << BugCategory << " -->\n"; - R.InsertStrBefore(SourceLocation::getFileLoc(FileID, 0), os.str()); + R.InsertStrBefore(SMgr.getLocForStartOfFile(FID), os.str()); } { std::string s; llvm::raw_string_ostream os(s); os << "\n<!-- BUGFILE " << DirName << Entry->getName() << " -->\n"; - R.InsertStrBefore(SourceLocation::getFileLoc(FileID, 0), os.str()); + R.InsertStrBefore(SMgr.getLocForStartOfFile(FID), os.str()); } { @@ -276,22 +274,22 @@ void HTMLDiagnostics::ReportDiag(const PathDiagnostic& D) { llvm::raw_string_ostream os(s); os << "\n<!-- BUGLINE " << D.back()->getLocation().getInstantiationLineNumber() << " -->\n"; - R.InsertStrBefore(SourceLocation::getFileLoc(FileID, 0), os.str()); + R.InsertStrBefore(SMgr.getLocForStartOfFile(FID), os.str()); } { std::string s; llvm::raw_string_ostream os(s); os << "\n<!-- BUGPATHLENGTH " << D.size() << " -->\n"; - R.InsertStrBefore(SourceLocation::getFileLoc(FileID, 0), os.str()); + R.InsertStrBefore(SMgr.getLocForStartOfFile(FID), os.str()); } // Add CSS, header, and footer. - html::AddHeaderFooterInternalBuiltinCSS(R, FileID, Entry->getName()); + html::AddHeaderFooterInternalBuiltinCSS(R, FID, Entry->getName()); // Get the rewrite buffer. - const RewriteBuffer *Buf = R.getRewriteBufferFor(FileID); + const RewriteBuffer *Buf = R.getRewriteBufferFor(FID); if (!Buf) { llvm::cerr << "warning: no diagnostics generated for main file.\n"; @@ -325,28 +323,26 @@ void HTMLDiagnostics::ReportDiag(const PathDiagnostic& D) { os << *I; } -void HTMLDiagnostics::HandlePiece(Rewriter& R, unsigned BugFileID, +void HTMLDiagnostics::HandlePiece(Rewriter& R, FileID BugFileID, const PathDiagnosticPiece& P, unsigned num, unsigned max) { // For now, just draw a box above the line in question, and emit the // warning. - FullSourceLoc Pos = P.getLocation(); if (!Pos.isValid()) return; - SourceManager& SM = R.getSourceMgr(); + SourceManager &SM = R.getSourceMgr(); FullSourceLoc LPos = Pos.getInstantiationLoc(); - unsigned FileID = SM.getCanonicalFileID(LPos); - - assert (&LPos.getManager() == &SM && "SourceManagers are different!"); + FileID FID = SM.getCanonicalFileID(LPos); + assert(&LPos.getManager() == &SM && "SourceManagers are different!"); if (SM.getCanonicalFileID(LPos) != BugFileID) return; - const llvm::MemoryBuffer *Buf = SM.getBuffer(FileID); + const llvm::MemoryBuffer *Buf = SM.getBuffer(FID); const char* FileStart = Buf->getBufferStart(); // Compute the column number. Rewind from the current position to the start @@ -436,30 +432,30 @@ void HTMLDiagnostics::HandlePiece(Rewriter& R, unsigned BugFileID, os << html::EscapeText(Msg) << "</div></td></tr>"; // Insert the new html. - unsigned DisplayPos = 0; - + unsigned DisplayPos; switch (P.getDisplayHint()) { - case PathDiagnosticPiece::Above: - DisplayPos = LineStart - FileStart; - break; - case PathDiagnosticPiece::Below: - DisplayPos = LineEnd - FileStart; - break; - default: - assert (false && "Unhandled hint."); + default: assert(0 && "Unhandled hint."); + case PathDiagnosticPiece::Above: + DisplayPos = LineStart - FileStart; + break; + case PathDiagnosticPiece::Below: + DisplayPos = LineEnd - FileStart; + break; } - - R.InsertStrBefore(SourceLocation::getFileLoc(FileID, DisplayPos), os.str()); + + SourceLocation Loc = + SM.getLocForStartOfFile(FID).getFileLocWithOffset(DisplayPos); + R.InsertStrBefore(Loc, os.str()); } // Now highlight the ranges. for (const SourceRange *I = P.ranges_begin(), *E = P.ranges_end(); I != E; ++I) - HighlightRange(R, FileID, *I); + HighlightRange(R, FID, *I); } -void HTMLDiagnostics::HighlightRange(Rewriter& R, unsigned BugFileID, +void HTMLDiagnostics::HighlightRange(Rewriter& R, FileID BugFileID, SourceRange Range) { SourceManager& SM = R.getSourceMgr(); diff --git a/lib/Driver/PlistDiagnostics.cpp b/lib/Driver/PlistDiagnostics.cpp index 14280288cd..0b2ca52f11 100644 --- a/lib/Driver/PlistDiagnostics.cpp +++ b/lib/Driver/PlistDiagnostics.cpp @@ -20,9 +20,9 @@ #include "llvm/System/Path.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallVector.h" - using namespace clang; -typedef llvm::DenseMap<unsigned,unsigned> FIDMap; + +typedef llvm::DenseMap<FileID, unsigned> FIDMap; namespace clang { class Preprocessor; @@ -51,27 +51,28 @@ clang::CreatePlistDiagnosticClient(const std::string& s, return new PlistDiagnostics(s); } -static void AddFID(FIDMap& FIDs, - llvm::SmallVectorImpl<unsigned>& V, +static void AddFID(FIDMap &FIDs, + llvm::SmallVectorImpl<FileID> &V, SourceManager& SM, SourceLocation L) { - unsigned fid = SM.getCanonicalFileID(SM.getInstantiationLoc(L)); - FIDMap::iterator I = FIDs.find(fid); + FileID FID = SM.getCanonicalFileID(SM.getInstantiationLoc(L)); + FIDMap::iterator I = FIDs.find(FID); if (I != FIDs.end()) return; - FIDs[fid] = V.size(); - V.push_back(fid); + FIDs[FID] = V.size(); + V.push_back(FID); } static unsigned GetFID(const FIDMap& FIDs, SourceManager& SM, SourceLocation L) { - unsigned fid = SM.getCanonicalFileID(SM.getInstantiationLoc(L)); - FIDMap::const_iterator I = FIDs.find(fid); - assert (I != FIDs.end()); + FileID FID = SM.getCanonicalFileID(SM.getInstantiationLoc(L)); + FIDMap::const_iterator I = FIDs.find(FID); + assert(I != FIDs.end()); return I->second; } static llvm::raw_ostream& Indent(llvm::raw_ostream& o, const unsigned indent) { - for (unsigned i = 0; i < indent; ++i) o << ' '; + for (unsigned i = 0; i < indent; ++i) + o << ' '; return o; } @@ -171,7 +172,7 @@ void PlistDiagnostics::HandlePathDiagnostic(const PathDiagnostic* D) { // Build up a set of FIDs that we use by scanning the locations and // ranges of the diagnostics. FIDMap FM; - llvm::SmallVector<unsigned, 10> Fids; + llvm::SmallVector<FileID, 10> Fids; for (PathDiagnostic::const_iterator I=D->begin(), E=D->end(); I != E; ++I) { AddFID(FM, Fids, SM, I->getLocation()); @@ -214,7 +215,7 @@ void PlistDiagnostics::HandlePathDiagnostic(const PathDiagnostic* D) { " <key>files</key>\n" " <array>\n"; - for (llvm::SmallVectorImpl<unsigned>::iterator I=Fids.begin(), E=Fids.end(); + for (llvm::SmallVectorImpl<FileID>::iterator I=Fids.begin(), E=Fids.end(); I!=E; ++I) o << " <string>" << SM.getFileEntryForID(*I)->getName() << "</string>\n"; |