");
}
// Insert a div tag for the line number.
std::ostringstream os;
os << "
" << LineNo << "
";
R.InsertStrBefore(B, os.str());
// Now surround the whole line with another div tag.
R.InsertCStrBefore(B, "
");
R.InsertCStrAfter(E, "
");
}
void html::AddLineNumbers(Rewriter& R, unsigned FileID) {
const llvm::MemoryBuffer *Buf = R.getSourceMgr().getBuffer(FileID);
const char* FileBeg = Buf->getBufferStart();
const char* FileEnd = Buf->getBufferEnd();
const char* C = FileBeg;
assert (C <= FileEnd);
unsigned LineNo = 0;
unsigned FilePos = 0;
while (C != FileEnd) {
++LineNo;
unsigned LineStartPos = FilePos;
unsigned LineEndPos = FileEnd - FileBeg;
assert (FilePos <= LineEndPos);
assert (C < FileEnd);
// Scan until the newline (or end-of-file).
for ( ; C != FileEnd ; ++C, ++FilePos)
if (*C == '\n') {
LineEndPos = FilePos;
break;
}
AddLineNumber(R, LineNo,
SourceLocation::getFileLoc(FileID, LineStartPos),
SourceLocation::getFileLoc(FileID, LineEndPos));
if (C != FileEnd) {
++C;
++FilePos;
}
}
// Add one big div tag that surrounds all of the code.
R.InsertCStrBefore(SourceLocation::getFileLoc(FileID, 0),
"
");
R.InsertCStrAfter(SourceLocation::getFileLoc(FileID, FileEnd - FileBeg),
"
");
}