"
<< LineNo << " | ";
if (B == E) { // Handle empty lines.
os << " |
";
R.InsertStrBefore(B, os.str());
}
else {
R.InsertStrBefore(B, os.str());
R.InsertCStrBefore(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).
while (C != FileEnd) {
char c = *C;
++C;
if (c == '\n') {
LineEndPos = FilePos++;
break;
}
++FilePos;
}
AddLineNumber(R, LineNo,
SourceLocation::getFileLoc(FileID, LineStartPos),
SourceLocation::getFileLoc(FileID, LineEndPos));
}
// Add one big div tag that surrounds all of the code.
R.InsertCStrBefore(SourceLocation::getFileLoc(FileID, 0),
"