From: Chris Lattner Date: Tue, 17 Feb 2009 00:51:07 +0000 (+0000) Subject: simplify this code and make it use highlight range. This X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e9e6cb93afa51eee1f83abc7e2cb7d8a0453d810;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64710 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Rewrite/HTMLRewrite.cpp b/lib/Rewrite/HTMLRewrite.cpp index 8942cec8f5..cf49701a1d 100644 --- a/lib/Rewrite/HTMLRewrite.cpp +++ b/lib/Rewrite/HTMLRewrite.cpp @@ -420,9 +420,6 @@ void html::SyntaxHighlight(Rewriter &R, FileID FID, Preprocessor &PP) { /// 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 TokenStream; @@ -486,21 +483,9 @@ void html::HighlightMacros(Rewriter &R, FileID FID, Preprocessor& PP) { continue; } - unsigned StartOffs = SM.getFileOffset(LLoc.first); - - // Highlight the macro invocation itself. - RB.InsertTextAfter(StartOffs, "", - strlen("")); - 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, "", strlen("")); - - + std::string Expansion = PP.getSpelling(Tok); unsigned LineLen = Expansion.size(); @@ -535,9 +520,13 @@ void html::HighlightMacros(Rewriter &R, FileID FID, Preprocessor& PP) { PP.Lex(Tok); } - // Insert the information about the expansion inside the macro span. - Expansion = "" + Expansion + ""; - 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 = "" + Expansion + ""; + + HighlightRange(R, LLoc.first, LLoc.second, + "", Expansion.c_str()); } }