aboutsummaryrefslogtreecommitdiff
path: root/Driver/HTMLDiagnostics.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2008-07-23 23:18:15 +0000
committerTed Kremenek <kremenek@apple.com>2008-07-23 23:18:15 +0000
commitfd8fc4ee5c1a9a02c1a131f4478a5cf9c687057e (patch)
tree69b5875b001dc42c313670f1240163bf384905ef /Driver/HTMLDiagnostics.cpp
parent1c61b472b24e7a61b91d535c030c92cd1fd8c7ee (diff)
Modified HTMLDiagnostics to also perform syntax highlighting for errors in header files.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@53965 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'Driver/HTMLDiagnostics.cpp')
-rw-r--r--Driver/HTMLDiagnostics.cpp70
1 files changed, 57 insertions, 13 deletions
diff --git a/Driver/HTMLDiagnostics.cpp b/Driver/HTMLDiagnostics.cpp
index 541e49b429..5fab267956 100644
--- a/Driver/HTMLDiagnostics.cpp
+++ b/Driver/HTMLDiagnostics.cpp
@@ -48,10 +48,10 @@ public:
virtual void HandlePathDiagnostic(const PathDiagnostic* D);
- void HandlePiece(Rewriter& R, const PathDiagnosticPiece& P,
- unsigned num, unsigned max);
+ void HandlePiece(Rewriter& R, unsigned BugFileID,
+ const PathDiagnosticPiece& P, unsigned num, unsigned max);
- void HighlightRange(Rewriter& R, SourceRange Range);
+ void HighlightRange(Rewriter& R, unsigned BugFileID, SourceRange Range);
void ReportDiag(const PathDiagnostic& D);
};
@@ -123,8 +123,52 @@ void HTMLDiagnostics::ReportDiag(const PathDiagnostic& D) {
if (noDir)
return;
- // Create a new rewriter to generate HTML.
SourceManager& SMgr = D.begin()->getLocation().getManager();
+
+ unsigned FileID = 0;
+ bool FileIDInitialized = false;
+
+ // 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();
+
+ if (!L.isFileID())
+ return; // FIXME: Emit a warning?
+
+ if (!FileIDInitialized) {
+ FileID = L.getCanonicalFileID();
+ FileIDInitialized = true;
+ }
+ else if (L.getCanonicalFileID() != FileID)
+ return; // FIXME: Emit a warning?
+
+ // Check the source ranges.
+ for (PathDiagnosticPiece::range_iterator RI=I->ranges_begin(),
+ RE=I->ranges_end(); RI!=RE; ++RI) {
+
+ SourceLocation L = RI->getBegin();
+
+ if (!L.isFileID())
+ return; // FIXME: Emit a warning?
+
+ if (SMgr.getCanonicalFileID(L) != FileID)
+ return; // FIXME: Emit a warning?
+
+ L = RI->getEnd();
+
+ if (!L.isFileID())
+ return; // FIXME: Emit a warning?
+
+ if (SMgr.getCanonicalFileID(L) != FileID)
+ return; // FIXME: Emit a warning?
+ }
+ }
+
+ if (!FileIDInitialized)
+ return; // FIXME: Emit a warning?
+
+ // Create a new rewriter to generate HTML.
Rewriter R(SMgr);
// Process the path.
@@ -135,12 +179,12 @@ void HTMLDiagnostics::ReportDiag(const PathDiagnostic& D) {
for (PathDiagnostic::const_reverse_iterator I=D.rbegin(), E=D.rend();
I!=E; ++I, --n) {
- HandlePiece(R, *I, n, max);
+ HandlePiece(R, FileID, *I, n, max);
}
// Add line numbers, header, footer, etc.
- unsigned FileID = R.getSourceMgr().getMainFileID();
+ // unsigned FileID = R.getSourceMgr().getMainFileID();
html::EscapeText(R, FileID);
html::AddLineNumbers(R, FileID);
@@ -270,7 +314,7 @@ void HTMLDiagnostics::ReportDiag(const PathDiagnostic& D) {
os << *I;
}
-void HTMLDiagnostics::HandlePiece(Rewriter& R,
+void HTMLDiagnostics::HandlePiece(Rewriter& R, unsigned BugFileID,
const PathDiagnosticPiece& P,
unsigned num, unsigned max) {
@@ -288,12 +332,11 @@ void HTMLDiagnostics::HandlePiece(Rewriter& R,
assert (&LPos.getManager() == &SM && "SourceManagers are different!");
- if (!SM.isFromMainFile(LPos.getLocation()))
+ if (LPos.getCanonicalFileID() != BugFileID)
return;
const llvm::MemoryBuffer *Buf = SM.getBuffer(FileID);
const char* FileStart = Buf->getBufferStart();
-
// Compute the column number. Rewind from the current position to the start
// of the line.
@@ -360,10 +403,11 @@ void HTMLDiagnostics::HandlePiece(Rewriter& R,
for (const SourceRange *I = P.ranges_begin(), *E = P.ranges_end();
I != E; ++I)
- HighlightRange(R, *I);
+ HighlightRange(R, FileID, *I);
}
-void HTMLDiagnostics::HighlightRange(Rewriter& R, SourceRange Range) {
+void HTMLDiagnostics::HighlightRange(Rewriter& R, unsigned BugFileID,
+ SourceRange Range) {
SourceManager& SM = R.getSourceMgr();
@@ -376,8 +420,8 @@ void HTMLDiagnostics::HighlightRange(Rewriter& R, SourceRange Range) {
if (EndLineNo < StartLineNo)
return;
- if (!SM.isFromMainFile(LogicalStart) ||
- !SM.isFromMainFile(LogicalEnd))
+ if (!SM.getCanonicalFileID(LogicalStart) != BugFileID ||
+ !SM.getCanonicalFileID(LogicalEnd) != BugFileID)
return;
// Compute the column number of the end.