diff options
author | Chris Lattner <sabre@nondot.org> | 2009-02-15 21:32:34 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-02-15 21:32:34 +0000 |
commit | 20cf43010a77508d7b06d3fee163dcfe2804d404 (patch) | |
tree | 1e52fa6e707c20e2716b1ab7f9a57a345a3bdbd2 /clang/lib/Rewrite | |
parent | f52c0b261cb09bda8d39821f264578b7c5f181bf (diff) | |
download | bcm5719-llvm-20cf43010a77508d7b06d3fee163dcfe2804d404.tar.gz bcm5719-llvm-20cf43010a77508d7b06d3fee163dcfe2804d404.zip |
fix a fixme in -emit-html output: highlight the entire range of a macro
instantiation, which highlights the arguments of a function like macro
as well as its identifier.
llvm-svn: 64607
Diffstat (limited to 'clang/lib/Rewrite')
-rw-r--r-- | clang/lib/Rewrite/HTMLRewrite.cpp | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/clang/lib/Rewrite/HTMLRewrite.cpp b/clang/lib/Rewrite/HTMLRewrite.cpp index a0f289b2b4f..8942cec8f5d 100644 --- a/clang/lib/Rewrite/HTMLRewrite.cpp +++ b/clang/lib/Rewrite/HTMLRewrite.cpp @@ -474,28 +474,32 @@ void html::HighlightMacros(Rewriter &R, FileID FID, Preprocessor& PP) { continue; } - // Ignore tokens whose instantiation location was not the main file. - SourceLocation LLoc = SM.getInstantiationLoc(Tok.getLocation()); - std::pair<FileID, unsigned> LLocInfo = SM.getDecomposedLoc(LLoc); + // Okay, we have the first token of a macro expansion: highlight the + // instantiation by inserting a start tag before the macro instantiation and + // end tag after it. + std::pair<SourceLocation, SourceLocation> LLoc = + SM.getInstantiationRange(Tok.getLocation()); - if (LLocInfo.first != FID) { + // Ignore tokens whose instantiation location was not the main file. + if (SM.getFileID(LLoc.first) != FID) { PP.Lex(Tok); 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); - // Okay, we have the first token of a macro expansion: highlight the - // instantiation. - // Get the size of current macro call itself. - // FIXME: This should highlight the args of a function-like - // macro, using a heuristic. - unsigned TokLen = Lexer::MeasureTokenLength(LLoc, SM); + unsigned TokLen = Lexer::MeasureTokenLength(LLoc.second, SM); + RB.InsertTextBefore(EndOffs+TokLen, "</span>", strlen("</span>")); - unsigned TokOffs = LLocInfo.second; - // Highlight the macro invocation itself. - RB.InsertTextAfter(TokOffs, "<span class='macro'>", - strlen("<span class='macro'>")); - RB.InsertTextBefore(TokOffs+TokLen, "</span>", strlen("</span>")); std::string Expansion = PP.getSpelling(Tok); unsigned LineLen = Expansion.size(); @@ -508,7 +512,7 @@ void html::HighlightMacros(Rewriter &R, FileID FID, Preprocessor& PP) { // instantiation. It would be really nice to pop up a window with all the // spelling of the tokens or something. while (!Tok.is(tok::eof) && - SM.getInstantiationLoc(Tok.getLocation()) == LLoc) { + SM.getInstantiationLoc(Tok.getLocation()) == LLoc.first) { // Insert a newline if the macro expansion is getting large. if (LineLen > 60) { Expansion += "<br>"; @@ -533,7 +537,7 @@ void html::HighlightMacros(Rewriter &R, FileID FID, Preprocessor& PP) { // Insert the information about the expansion inside the macro span. Expansion = "<span class='expansion'>" + Expansion + "</span>"; - RB.InsertTextBefore(TokOffs+TokLen, Expansion.c_str(), Expansion.size()); + RB.InsertTextBefore(EndOffs+TokLen, Expansion.c_str(), Expansion.size()); } } |