[cfe-commits] r49836 - /cfe/trunk/lib/Rewrite/HTMLRewrite.cpp

Chris Lattner sabre at nondot.org
Wed Apr 16 17:40:45 PDT 2008


Author: lattner
Date: Wed Apr 16 19:40:45 2008
New Revision: 49836

URL: http://llvm.org/viewvc/llvm-project?rev=49836&view=rev
Log:
insert macro expansions into floating divs.  For now, they are always displayed,
but we want some javascript or something toggle their display.

Modified:
    cfe/trunk/lib/Rewrite/HTMLRewrite.cpp

Modified: cfe/trunk/lib/Rewrite/HTMLRewrite.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/HTMLRewrite.cpp?rev=49836&r1=49835&r2=49836&view=diff

==============================================================================
--- cfe/trunk/lib/Rewrite/HTMLRewrite.cpp (original)
+++ cfe/trunk/lib/Rewrite/HTMLRewrite.cpp Wed Apr 16 19:40:45 2008
@@ -120,9 +120,9 @@
       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 @@
       " .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 @@
     unsigned TokLen = Lexer::MeasureTokenLength(LLoc, SourceMgr);
     
     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();
+    
     // Okay, eat this token, getting the next one.
     PP.Lex(Tok);
     
@@ -421,8 +432,22 @@
     // 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 += "<br>";
+        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 = "<span class='expansion'>" + Expansion + "</span>";
+    RB.InsertTextBefore(TokOffs+TokLen, Expansion.c_str(), Expansion.size());
   }
 }
 





More information about the cfe-commits mailing list