]> granicus.if.org Git - clang/commitdiff
correctly hilight multi-line macro definitions and other
authorChris Lattner <sabre@nondot.org>
Wed, 16 Apr 2008 23:21:17 +0000 (23:21 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 16 Apr 2008 23:21:17 +0000 (23:21 +0000)
preprocessor directives.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49828 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Rewrite/HTMLRewrite.cpp

index 5aa77370a8fda22962ceda91f81c5fd75152f8a7..e6a72e977724bdbd0bcbd2f6c7115dfea772284c 100644 (file)
@@ -261,7 +261,7 @@ void html::AddHeaderFooterInternalBuiltinCSS(Rewriter& R, unsigned FileID) {
       " .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 @@ void html::SyntaxHighlight(Rewriter &R, unsigned FileID, Preprocessor &PP) {
       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);