[cfe-commits] r49828 - /cfe/trunk/lib/Rewrite/HTMLRewrite.cpp
Chris Lattner
sabre at nondot.org
Wed Apr 16 16:21:17 PDT 2008
Author: lattner
Date: Wed Apr 16 18:21:17 2008
New Revision: 49828
URL: http://llvm.org/viewvc/llvm-project?rev=49828&view=rev
Log:
correctly hilight multi-line macro definitions and other
preprocessor directives.
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=49828&r1=49827&r2=49828&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/HTMLRewrite.cpp (original)
+++ cfe/trunk/lib/Rewrite/HTMLRewrite.cpp Wed Apr 16 18:21:17 2008
@@ -261,7 +261,7 @@
" .code { line-height: 1.2em }\n"
" .comment { color: #A0A0A0; font-style: oblique }\n"
" .keyword { color: #FF00FF }\n"
- " .directive { color: #FFFF00 }\n"
+ " .directive { color: #00A000 }\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"
@@ -340,19 +340,27 @@
HighlightRange(RB, TokOffs, TokOffs+TokLen, BufferStart,
"<span class='comment'>", "</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?
-
+ case tok::hash: {
// If this is a preprocessor directive, all tokens to end of line are too.
- if (Tok.isAtStartOfLine()) {
- // Find end of line. This is a hack.
- const char *LineEnd = SourceMgr.getCharacterData(Tok.getLocation());
- unsigned TokEnd = TokOffs+strcspn(LineEnd, "\n\r");
- HighlightRange(RB, TokOffs, TokEnd, BufferStart,
- "<span class='directive'>", "</span>");
+ if (!Tok.isAtStartOfLine())
+ break;
+
+ // Eat all of the tokens until we get to the next one at the start of
+ // line.
+ unsigned TokEnd = TokOffs+TokLen;
+ L.LexRawToken(Tok);
+ while (!Tok.isAtStartOfLine() && Tok.isNot(tok::eof)) {
+ TokEnd = SourceMgr.getFullFilePos(Tok.getLocation())+Tok.getLength();
+ L.LexRawToken(Tok);
}
- break;
+
+ // Find end of line. This is a hack.
+ HighlightRange(RB, TokOffs, TokEnd, BufferStart,
+ "<span class='directive'>", "</span>");
+
+ // Don't skip the next token.
+ continue;
+ }
}
L.LexRawToken(Tok);
More information about the cfe-commits
mailing list