aboutsummaryrefslogtreecommitdiff
path: root/lib/Rewrite/HTMLRewrite.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-04-16 06:53:09 +0000
committerChris Lattner <sabre@nondot.org>2008-04-16 06:53:09 +0000
commit74ea3e5c57c087c046223096a97ea4e365f85eb6 (patch)
tree43ffac7a1e1c7b38d96c72507fd2c3a7fad1f428 /lib/Rewrite/HTMLRewrite.cpp
parentc4586c234edd8df0477a895aebcbc3eb220aed6b (diff)
Take a stab at highlighting #defines and #includes. This doesn't work yet.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49781 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Rewrite/HTMLRewrite.cpp')
-rw-r--r--lib/Rewrite/HTMLRewrite.cpp41
1 files changed, 30 insertions, 11 deletions
diff --git a/lib/Rewrite/HTMLRewrite.cpp b/lib/Rewrite/HTMLRewrite.cpp
index ca99c624a7..8a4059cf85 100644
--- a/lib/Rewrite/HTMLRewrite.cpp
+++ b/lib/Rewrite/HTMLRewrite.cpp
@@ -187,6 +187,7 @@ void html::AddHeaderFooterInternalBuiltinCSS(Rewriter& R, unsigned FileID) {
" .code { line-height: 1.2em }\n"
" .comment { color: #A0A0A0 }\n"
" .keyword { color: #FF00FF }\n"
+ " .directive { color: #FFFF00 }\n"
" .macro { color: #FF0000; background-color:#FFC0C0 }\n"
" .num { width:2.5em; padding-right:2ex; background-color:#eeeeee }\n"
" .num { text-align:right; font-size: smaller }\n"
@@ -238,17 +239,20 @@ void html::SyntaxHighlight(Rewriter &R, unsigned FileID, Preprocessor &PP) {
// macros.
const SourceManager &SourceMgr = PP.getSourceManager();
Token Tok;
- do {
+ PP.LexUnexpandedToken(Tok);
+
+ // Skip tokens from the predefine buffer or whatever else.
+ // Consume all of the tokens that come from the predefines buffer. Those
+ // should not be emitted into the output and are guaranteed to be at the
+ // start.
+ while (Tok.isNot(tok::eof) && Tok.getLocation().isFileID() &&
+ SourceMgr.getCanonicalFileID(Tok.getLocation()) != FileID)
PP.LexUnexpandedToken(Tok);
- // Ignore tokens whose logical location was not the main file.
- SourceLocation LLoc = SourceMgr.getLogicalLoc(Tok.getLocation());
- std::pair<unsigned, unsigned> LLocInfo =
- SourceMgr.getDecomposedFileLoc(LLoc);
-
- if (LLocInfo.first != FileID)
- continue;
-
- unsigned TokOffs = LLocInfo.second;
+
+ while (Tok.isNot(tok::eof)) {
+ // Since we are lexing unexpanded tokens, all tokens are from the main
+ // FileID.
+ unsigned TokOffs = SourceMgr.getFullFilePos(Tok.getLocation());
unsigned TokLen = Tok.getLength();
switch (Tok.getKind()) {
default:
@@ -265,9 +269,24 @@ void html::SyntaxHighlight(Rewriter &R, unsigned FileID, Preprocessor &PP) {
strlen("<span class='comment'>"));
RB.InsertTextBefore(TokOffs+TokLen, "</span>", strlen("</span>"));
break;
+ case tok::hash:
+ // FIXME: This isn't working because we're not in raw mode in the lexer.
+ // Just cons up our own lexer here?
+
+ // If this is a preprocessor directive, all tokens to end of line are too.
+ if (Tok.isAtStartOfLine()) {
+ RB.InsertTextAfter(TokOffs, "<span class='directive'>",
+ strlen("<span class='directive'>"));
+ // Find end of line. This is a hack.
+ const char *LineEnd = SourceMgr.getCharacterData(Tok.getLocation());
+ unsigned TokEnd = TokOffs+strcspn(LineEnd, "\n\r");
+ RB.InsertTextBefore(TokEnd, "</span>", strlen("</span>"));
+ }
+ break;
}
- } while (Tok.isNot(tok::eof));
+ PP.LexUnexpandedToken(Tok);
+ }
PP.SetCommentRetentionState(false, false);
}