[cfe-commits] r49781 - /cfe/trunk/lib/Rewrite/HTMLRewrite.cpp
Chris Lattner
sabre at nondot.org
Tue Apr 15 23:53:09 PDT 2008
Author: lattner
Date: Wed Apr 16 01:53:09 2008
New Revision: 49781
URL: http://llvm.org/viewvc/llvm-project?rev=49781&view=rev
Log:
Take a stab at highlighting #defines and #includes. This doesn't work yet.
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=49781&r1=49780&r2=49781&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/HTMLRewrite.cpp (original)
+++ cfe/trunk/lib/Rewrite/HTMLRewrite.cpp Wed Apr 16 01:53:09 2008
@@ -187,6 +187,7 @@
" .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 @@
// 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 @@
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);
}
More information about the cfe-commits
mailing list