[cfe-commits] r64710 - /cfe/trunk/lib/Rewrite/HTMLRewrite.cpp

Chris Lattner sabre at nondot.org
Mon Feb 16 16:51:07 PST 2009


Author: lattner
Date: Mon Feb 16 18:51:07 2009
New Revision: 64710

URL: http://llvm.org/viewvc/llvm-project?rev=64710&view=rev
Log:
simplify this code and make it use highlight range.  This
makes -emit-html do nice things for code like:

#define FOO(X) y

int FOO(4
);

highlighting the FOO instance as well as the ) on the next line properly.


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=64710&r1=64709&r2=64710&view=diff

==============================================================================
--- cfe/trunk/lib/Rewrite/HTMLRewrite.cpp (original)
+++ cfe/trunk/lib/Rewrite/HTMLRewrite.cpp Mon Feb 16 18:51:07 2009
@@ -420,9 +420,6 @@
 /// macro expansions.  This won't be perfectly perfect, but it will be
 /// reasonably close.
 void html::HighlightMacros(Rewriter &R, FileID FID, Preprocessor& PP) {
-  
-  RewriteBuffer &RB = R.getEditBuffer(FID);
-  
   // Re-lex the raw token stream into a token buffer.
   const SourceManager &SM = PP.getSourceManager();
   std::vector<Token> TokenStream;
@@ -486,21 +483,9 @@
       continue;
     }
 
-    unsigned StartOffs = SM.getFileOffset(LLoc.first);
-
-    // Highlight the macro invocation itself.
-    RB.InsertTextAfter(StartOffs, "<span class='macro'>",
-                       strlen("<span class='macro'>"));
-
     assert(SM.getFileID(LLoc.second) == FID &&
            "Start and end of expansion must be in the same ultimate file!");
-    unsigned EndOffs = SM.getFileOffset(LLoc.second);
-    
-    // Get the size of current macro call itself.
-    unsigned TokLen = Lexer::MeasureTokenLength(LLoc.second, SM);
-    RB.InsertTextBefore(EndOffs+TokLen, "</span>", strlen("</span>"));
-    
-    
+
     std::string Expansion = PP.getSpelling(Tok);
     unsigned LineLen = Expansion.size();
     
@@ -535,9 +520,13 @@
       PP.Lex(Tok);
     }
     
-    // Insert the information about the expansion inside the macro span.
-    Expansion = "<span class='expansion'>" + Expansion + "</span>";
-    RB.InsertTextBefore(EndOffs+TokLen, Expansion.c_str(), Expansion.size());
+
+    // Insert the expansion as the end tag, so that multi-line macros all get
+    // highlighted.
+    Expansion = "<span class='expansion'>" + Expansion + "</span></span>";
+
+    HighlightRange(R, LLoc.first, LLoc.second,
+                   "<span class='macro'>", Expansion.c_str());
   }
 }
 





More information about the cfe-commits mailing list