[cfe-commits] r49775 - /cfe/trunk/lib/Rewrite/HTMLRewrite.cpp
Chris Lattner
sabre at nondot.org
Tue Apr 15 21:37:29 PDT 2008
Author: lattner
Date: Tue Apr 15 23:37:29 2008
New Revision: 49775
URL: http://llvm.org/viewvc/llvm-project?rev=49775&view=rev
Log:
Switch AddLineNumbers to hack on a rewritebuffer instead of on a
rewriter, getting sourcelocations out of the picture.
Modified:
cfe/trunk/lib/Rewrite/HTMLRewrite.cpp
Modified: cfe/trunk/lib/Rewrite/HTMLRewrite.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/HTMLRewrite.cpp?rev=49775&r1=49774&r2=49775&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/HTMLRewrite.cpp (original)
+++ cfe/trunk/lib/Rewrite/HTMLRewrite.cpp Tue Apr 15 23:37:29 2008
@@ -75,35 +75,35 @@
for (unsigned i = 0 ; i < len; ++i) {
char c = s[i];
-
switch (c) {
- default:
- os << c; break;
-
- case ' ':
- if (EscapeSpaces) os << " ";
- else os << ' ';
+ default:
+ os << c; break;
+
+ case ' ':
+ if (EscapeSpaces) os << " ";
+ else os << ' ';
+ break;
+
+ case '\t':
+ if (ReplaceTabs)
+ for (unsigned i = 0; i < 4; ++i)
+ os << " ";
+ else
+ os << c;
+
break;
-
- case '\t':
- if (ReplaceTabs)
- for (unsigned i = 0; i < 4; ++i)
- os << " ";
- else os << c;
-
- break;
-
- case '<': os << "<"; break;
- case '>': os << ">"; break;
- case '&': os << "&"; break;
+
+ case '<': os << "<"; break;
+ case '>': os << ">"; break;
+ case '&': os << "&"; break;
}
}
return os.str();
}
-static void AddLineNumber(Rewriter& R, unsigned LineNo,
- SourceLocation B, SourceLocation E) {
+static void AddLineNumber(RewriteBuffer &RB, unsigned LineNo,
+ unsigned B, unsigned E) {
llvm::SmallString<100> Str;
Str += "<tr><td class=\"num\" id=\"LN";
Str.append_uint(LineNo);
@@ -113,10 +113,10 @@
if (B == E) { // Handle empty lines.
Str += " </td></tr>";
- R.InsertTextBefore(B, &Str[0], Str.size());
+ RB.InsertTextBefore(B, &Str[0], Str.size());
} else {
- R.InsertTextBefore(B, &Str[0], Str.size());
- R.InsertCStrBefore(E, "</td></tr>");
+ RB.InsertTextBefore(B, &Str[0], Str.size());
+ RB.InsertTextBefore(E, "</td></tr>", strlen("</td></tr>"));
}
}
@@ -126,6 +126,7 @@
const char* FileBeg = Buf->getBufferStart();
const char* FileEnd = Buf->getBufferEnd();
const char* C = FileBeg;
+ RewriteBuffer &RB = R.getEditBuffer(FileID);
assert (C <= FileEnd);
@@ -155,18 +156,14 @@
++FilePos;
}
- AddLineNumber(R, LineNo,
- SourceLocation::getFileLoc(FileID, LineStartPos),
- SourceLocation::getFileLoc(FileID, LineEndPos));
+ AddLineNumber(RB, LineNo, LineStartPos, LineEndPos);
}
- // Add one big div tag that surrounds all of the code.
-
- R.InsertCStrBefore(SourceLocation::getFileLoc(FileID, 0),
- "<table class=\"code\">\n");
+ // Add one big table tag that surrounds all of the code.
+ RB.InsertTextBefore(0, "<table class=\"code\">\n",
+ strlen("<table class=\"code\">\n"));
- R.InsertCStrAfter(SourceLocation::getFileLoc(FileID, FileEnd - FileBeg),
- "</table>");
+ RB.InsertTextAfter(FileEnd - FileBeg, "</table>", strlen("</table>"));
}
void html::AddHeaderFooterInternalBuiltinCSS(Rewriter& R, unsigned FileID) {
More information about the cfe-commits
mailing list