From 6f46be279f4bc8fc24611f060258bcfbe1c175c4 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 17 Apr 2008 00:40:45 +0000 Subject: [PATCH] insert macro expansions into floating divs. For now, they are always displayed, but we want some javascript or something toggle their display. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49836 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Rewrite/HTMLRewrite.cpp | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/lib/Rewrite/HTMLRewrite.cpp b/lib/Rewrite/HTMLRewrite.cpp index e6a72e9777..43f13d2ab6 100644 --- a/lib/Rewrite/HTMLRewrite.cpp +++ b/lib/Rewrite/HTMLRewrite.cpp @@ -120,9 +120,9 @@ void html::EscapeText(Rewriter& R, unsigned FileID, if (!ReplaceTabs) break; if (EscapeSpaces) - RB.ReplaceText(FilePos, 1, "    ", 6*4); + RB.ReplaceText(FilePos, 1, "        ", 6*8); else - RB.ReplaceText(FilePos, 1, " ", 4); + RB.ReplaceText(FilePos, 1, " ", 8); break; case '<': @@ -262,7 +262,14 @@ void html::AddHeaderFooterInternalBuiltinCSS(Rewriter& R, unsigned FileID) { " .comment { color: #A0A0A0; font-style: oblique }\n" " .keyword { color: #FF00FF }\n" " .directive { color: #00A000 }\n" - " .macro { color: #FF0000; background-color:#FFC0C0 }\n" + // Macro expansions. + " .expansion { display: block; border: 2px solid #FF0000; padding: 2px;" + "background-color:#FFF0F0;" + " -webkit-border-radius:5px; -webkit-box-shadow:1px 1px 7px #000; " + "position: absolute; top: -1em; left:10em } \n" + " .macro { color: #FF0000; background-color:#FFC0C0;" + // Macros are position: relative to provide base for expansions. + " position: relative }\n" " .num { width:2.5em; padding-right:2ex; background-color:#eeeeee }\n" " .num { text-align:right; font-size: smaller }\n" " .num { color:#444444 }\n" @@ -410,10 +417,14 @@ void html::HighlightMacros(Rewriter &R, unsigned FileID, Preprocessor &PP) { unsigned TokLen = Lexer::MeasureTokenLength(LLoc, SourceMgr); unsigned TokOffs = LLocInfo.second; + // Highlight the macro invocation itself. RB.InsertTextAfter(TokOffs, "", strlen("")); RB.InsertTextBefore(TokOffs+TokLen, "", strlen("")); + std::string Expansion = PP.getSpelling(Tok); + unsigned LineLen = Expansion.size(); + // Okay, eat this token, getting the next one. PP.Lex(Tok); @@ -421,8 +432,22 @@ void html::HighlightMacros(Rewriter &R, unsigned FileID, 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) && - SourceMgr.getLogicalLoc(Tok.getLocation()) == LLoc) + SourceMgr.getLogicalLoc(Tok.getLocation()) == LLoc) { + // Insert a newline if the macro expansion is getting large. + if (LineLen > 60) { + Expansion += "
"; + LineLen = 0; + } + + LineLen -= Expansion.size(); + Expansion += ' ' + PP.getSpelling(Tok); + LineLen += Expansion.size(); PP.Lex(Tok); + } + + // Insert the information about the expansion inside the macro span. + Expansion = "" + Expansion + ""; + RB.InsertTextBefore(TokOffs+TokLen, Expansion.c_str(), Expansion.size()); } } -- 2.40.0