aboutsummaryrefslogtreecommitdiff
path: root/lib/Rewrite/HTMLRewrite.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-02-15 21:32:34 +0000
committerChris Lattner <sabre@nondot.org>2009-02-15 21:32:34 +0000
commitb7949a9a91ad8e49124cd6a82ff98972d7efaadc (patch)
tree2ecba51b6008be246af7cbed2db596b68f568406 /lib/Rewrite/HTMLRewrite.cpp
parent6678133b8ce642f93e5141f056fa643112041ad0 (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64607 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Rewrite/HTMLRewrite.cpp')
-rw-r--r--lib/Rewrite/HTMLRewrite.cpp38
1 files changed, 21 insertions, 17 deletions
diff --git a/lib/Rewrite/HTMLRewrite.cpp b/lib/Rewrite/HTMLRewrite.cpp
index a0f289b2b4..8942cec8f5 100644
--- a/lib/Rewrite/HTMLRewrite.cpp
+++ b/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());
}
}