HTMLDiagnostics now uses the new "getCanonicalID()", "isFromMainFileID()" methods from
SourceManager when doing HTML pretty-printing. This resolves an insidious bug when presenting error reports that only occurred in large source files. llvm-svn: 49683
This commit is contained in:
parent
17acadebb4
commit
bb2b224159
|
@ -47,7 +47,7 @@ public:
|
||||||
void HandlePiece(Rewriter& R, const PathDiagnosticPiece& P,
|
void HandlePiece(Rewriter& R, const PathDiagnosticPiece& P,
|
||||||
unsigned num, unsigned max);
|
unsigned num, unsigned max);
|
||||||
|
|
||||||
void HighlightRange(Rewriter& R, SourceRange Range, unsigned MainFileID);
|
void HighlightRange(Rewriter& R, SourceRange Range);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end anonymous namespace
|
} // end anonymous namespace
|
||||||
|
@ -222,13 +222,11 @@ void HTMLDiagnostics::HandlePiece(Rewriter& R,
|
||||||
|
|
||||||
SourceManager& SM = R.getSourceMgr();
|
SourceManager& SM = R.getSourceMgr();
|
||||||
FullSourceLoc LPos = Pos.getLogicalLoc();
|
FullSourceLoc LPos = Pos.getLogicalLoc();
|
||||||
unsigned FileID = LPos.getLocation().getFileID();
|
unsigned FileID = SM.getCanonicalFileID(LPos.getLocation());
|
||||||
|
|
||||||
assert (&LPos.getManager() == &SM && "SourceManagers are different!");
|
assert (&LPos.getManager() == &SM && "SourceManagers are different!");
|
||||||
|
|
||||||
unsigned MainFileID = SM.getMainFileID();
|
if (!SM.isFromMainFile(LPos.getLocation()))
|
||||||
|
|
||||||
if (FileID != MainFileID)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Compute the column number. Rewind from the current position to the start
|
// Compute the column number. Rewind from the current position to the start
|
||||||
|
@ -277,34 +275,33 @@ void HTMLDiagnostics::HandlePiece(Rewriter& R,
|
||||||
|
|
||||||
for (const SourceRange *I = P.ranges_begin(), *E = P.ranges_end();
|
for (const SourceRange *I = P.ranges_begin(), *E = P.ranges_end();
|
||||||
I != E; ++I)
|
I != E; ++I)
|
||||||
HighlightRange(R, *I, MainFileID);
|
HighlightRange(R, *I);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HTMLDiagnostics::HighlightRange(Rewriter& R, SourceRange Range,
|
void HTMLDiagnostics::HighlightRange(Rewriter& R, SourceRange Range) {
|
||||||
unsigned MainFileID) {
|
|
||||||
|
|
||||||
SourceManager& SourceMgr = R.getSourceMgr();
|
SourceManager& SM = R.getSourceMgr();
|
||||||
|
|
||||||
SourceLocation LogicalStart = SourceMgr.getLogicalLoc(Range.getBegin());
|
SourceLocation LogicalStart = SM.getLogicalLoc(Range.getBegin());
|
||||||
unsigned StartLineNo = SourceMgr.getLineNumber(LogicalStart);
|
unsigned StartLineNo = SM.getLineNumber(LogicalStart);
|
||||||
|
|
||||||
SourceLocation LogicalEnd = SourceMgr.getLogicalLoc(Range.getEnd());
|
SourceLocation LogicalEnd = SM.getLogicalLoc(Range.getEnd());
|
||||||
unsigned EndLineNo = SourceMgr.getLineNumber(LogicalEnd);
|
unsigned EndLineNo = SM.getLineNumber(LogicalEnd);
|
||||||
|
|
||||||
if (EndLineNo < StartLineNo)
|
if (EndLineNo < StartLineNo)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (LogicalStart.getFileID() != MainFileID ||
|
if (!SM.isFromMainFile(LogicalStart) ||
|
||||||
LogicalEnd.getFileID() != MainFileID)
|
!SM.isFromMainFile(LogicalEnd))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Compute the column number of the end.
|
// Compute the column number of the end.
|
||||||
unsigned EndColNo = SourceMgr.getColumnNumber(LogicalEnd);
|
unsigned EndColNo = SM.getColumnNumber(LogicalEnd);
|
||||||
unsigned OldEndColNo = EndColNo;
|
unsigned OldEndColNo = EndColNo;
|
||||||
|
|
||||||
if (EndColNo) {
|
if (EndColNo) {
|
||||||
// Add in the length of the token, so that we cover multi-char tokens.
|
// Add in the length of the token, so that we cover multi-char tokens.
|
||||||
EndColNo += Lexer::MeasureTokenLength(Range.getEnd(), SourceMgr);
|
EndColNo += Lexer::MeasureTokenLength(Range.getEnd(), SM);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Highlight the range. Make the span tag the outermost tag for the
|
// Highlight the range. Make the span tag the outermost tag for the
|
||||||
|
@ -323,16 +320,17 @@ void HTMLDiagnostics::HighlightRange(Rewriter& R, SourceRange Range,
|
||||||
|
|
||||||
// Add in </span><span> tags for intermediate lines.
|
// Add in </span><span> tags for intermediate lines.
|
||||||
|
|
||||||
const llvm::MemoryBuffer *Buf = R.getSourceMgr().getBuffer(MainFileID);
|
unsigned FileID = SM.getCanonicalFileID(LogicalStart);
|
||||||
|
const llvm::MemoryBuffer *Buf = R.getSourceMgr().getBuffer(FileID);
|
||||||
|
|
||||||
unsigned Pos = SourceMgr.getFullFilePos(LogicalStart);
|
unsigned Pos = SM.getFullFilePos(LogicalStart);
|
||||||
unsigned EndPos = SourceMgr.getFullFilePos(E);
|
unsigned EndPos = SM.getFullFilePos(E);
|
||||||
const char* buf = Buf->getBufferStart();
|
const char* buf = Buf->getBufferStart();
|
||||||
|
|
||||||
for (; Pos != EndPos; ++Pos) {
|
for (; Pos != EndPos; ++Pos) {
|
||||||
|
|
||||||
SourceLocation L = SourceLocation::getFileLoc(MainFileID, Pos);
|
SourceLocation L = SourceLocation::getFileLoc(FileID, Pos);
|
||||||
unsigned Col = SourceMgr.getColumnNumber(L);
|
unsigned Col = SM.getColumnNumber(L);
|
||||||
|
|
||||||
if (Col == 1) {
|
if (Col == 1) {
|
||||||
|
|
||||||
|
@ -367,7 +365,7 @@ void HTMLDiagnostics::HighlightRange(Rewriter& R, SourceRange Range,
|
||||||
|
|
||||||
// This line contains text that we should highlight.
|
// This line contains text that we should highlight.
|
||||||
// Ignore leading whitespace.
|
// Ignore leading whitespace.
|
||||||
L = SourceLocation::getFileLoc(MainFileID, Pos);
|
L = SourceLocation::getFileLoc(FileID, Pos);
|
||||||
R.InsertCStrAfter(L, "<span class=\"mrange\">");
|
R.InsertCStrAfter(L, "<span class=\"mrange\">");
|
||||||
}
|
}
|
||||||
else if (buf[Pos] == '\n')
|
else if (buf[Pos] == '\n')
|
||||||
|
|
Loading…
Reference in New Issue