diff options
author | Chris Lattner <sabre@nondot.org> | 2009-02-17 00:51:07 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-02-17 00:51:07 +0000 |
commit | 8cad67b8a4d344866934ca6afdc4fb483453ddfb (patch) | |
tree | 0b783efe2ae9dd98e3a7f7680b73b8e9eebeaebb /clang/lib/Rewrite | |
parent | 46414874a51c05cf92b75fddfcc147a1263ab80b (diff) | |
download | bcm5719-llvm-8cad67b8a4d344866934ca6afdc4fb483453ddfb.tar.gz bcm5719-llvm-8cad67b8a4d344866934ca6afdc4fb483453ddfb.zip |
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.
llvm-svn: 64710
Diffstat (limited to 'clang/lib/Rewrite')
-rw-r--r-- | clang/lib/Rewrite/HTMLRewrite.cpp | 27 |
1 files changed, 8 insertions, 19 deletions
diff --git a/clang/lib/Rewrite/HTMLRewrite.cpp b/clang/lib/Rewrite/HTMLRewrite.cpp index 8942cec8f5d..cf49701a1d7 100644 --- a/clang/lib/Rewrite/HTMLRewrite.cpp +++ b/clang/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<Token> 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, "<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 @@ void html::HighlightMacros(Rewriter &R, FileID FID, Preprocessor& PP) { 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()); } } |