зеркало из https://github.com/microsoft/clang-1.git
Switch AddLineNumbers to hack on a rewritebuffer instead of on a
rewriter, getting sourcelocations out of the picture. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49775 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
735271479a
Коммит
8570f0b0fd
|
@ -75,35 +75,35 @@ std::string html::EscapeText(const std::string& s, bool EscapeSpaces,
|
||||||
for (unsigned i = 0 ; i < len; ++i) {
|
for (unsigned i = 0 ; i < len; ++i) {
|
||||||
|
|
||||||
char c = s[i];
|
char c = s[i];
|
||||||
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
default:
|
default:
|
||||||
os << c; break;
|
os << c; break;
|
||||||
|
|
||||||
case ' ':
|
case ' ':
|
||||||
if (EscapeSpaces) os << " ";
|
if (EscapeSpaces) os << " ";
|
||||||
else os << ' ';
|
else os << ' ';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '\t':
|
||||||
|
if (ReplaceTabs)
|
||||||
|
for (unsigned i = 0; i < 4; ++i)
|
||||||
|
os << " ";
|
||||||
|
else
|
||||||
|
os << c;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '\t':
|
case '<': os << "<"; break;
|
||||||
if (ReplaceTabs)
|
case '>': os << ">"; break;
|
||||||
for (unsigned i = 0; i < 4; ++i)
|
case '&': os << "&"; break;
|
||||||
os << " ";
|
|
||||||
else os << c;
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case '<': os << "<"; break;
|
|
||||||
case '>': os << ">"; break;
|
|
||||||
case '&': os << "&"; break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return os.str();
|
return os.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AddLineNumber(Rewriter& R, unsigned LineNo,
|
static void AddLineNumber(RewriteBuffer &RB, unsigned LineNo,
|
||||||
SourceLocation B, SourceLocation E) {
|
unsigned B, unsigned E) {
|
||||||
llvm::SmallString<100> Str;
|
llvm::SmallString<100> Str;
|
||||||
Str += "<tr><td class=\"num\" id=\"LN";
|
Str += "<tr><td class=\"num\" id=\"LN";
|
||||||
Str.append_uint(LineNo);
|
Str.append_uint(LineNo);
|
||||||
|
@ -113,10 +113,10 @@ static void AddLineNumber(Rewriter& R, unsigned LineNo,
|
||||||
|
|
||||||
if (B == E) { // Handle empty lines.
|
if (B == E) { // Handle empty lines.
|
||||||
Str += " </td></tr>";
|
Str += " </td></tr>";
|
||||||
R.InsertTextBefore(B, &Str[0], Str.size());
|
RB.InsertTextBefore(B, &Str[0], Str.size());
|
||||||
} else {
|
} else {
|
||||||
R.InsertTextBefore(B, &Str[0], Str.size());
|
RB.InsertTextBefore(B, &Str[0], Str.size());
|
||||||
R.InsertCStrBefore(E, "</td></tr>");
|
RB.InsertTextBefore(E, "</td></tr>", strlen("</td></tr>"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,6 +126,7 @@ void html::AddLineNumbers(Rewriter& R, unsigned FileID) {
|
||||||
const char* FileBeg = Buf->getBufferStart();
|
const char* FileBeg = Buf->getBufferStart();
|
||||||
const char* FileEnd = Buf->getBufferEnd();
|
const char* FileEnd = Buf->getBufferEnd();
|
||||||
const char* C = FileBeg;
|
const char* C = FileBeg;
|
||||||
|
RewriteBuffer &RB = R.getEditBuffer(FileID);
|
||||||
|
|
||||||
assert (C <= FileEnd);
|
assert (C <= FileEnd);
|
||||||
|
|
||||||
|
@ -155,18 +156,14 @@ void html::AddLineNumbers(Rewriter& R, unsigned FileID) {
|
||||||
++FilePos;
|
++FilePos;
|
||||||
}
|
}
|
||||||
|
|
||||||
AddLineNumber(R, LineNo,
|
AddLineNumber(RB, LineNo, LineStartPos, LineEndPos);
|
||||||
SourceLocation::getFileLoc(FileID, LineStartPos),
|
|
||||||
SourceLocation::getFileLoc(FileID, LineEndPos));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add one big div tag that surrounds all of the code.
|
// Add one big table tag that surrounds all of the code.
|
||||||
|
RB.InsertTextBefore(0, "<table class=\"code\">\n",
|
||||||
|
strlen("<table class=\"code\">\n"));
|
||||||
|
|
||||||
R.InsertCStrBefore(SourceLocation::getFileLoc(FileID, 0),
|
RB.InsertTextAfter(FileEnd - FileBeg, "</table>", strlen("</table>"));
|
||||||
"<table class=\"code\">\n");
|
|
||||||
|
|
||||||
R.InsertCStrAfter(SourceLocation::getFileLoc(FileID, FileEnd - FileBeg),
|
|
||||||
"</table>");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void html::AddHeaderFooterInternalBuiltinCSS(Rewriter& R, unsigned FileID) {
|
void html::AddHeaderFooterInternalBuiltinCSS(Rewriter& R, unsigned FileID) {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче