[cfe-commits] r48533 - in /cfe/trunk: Driver/HTMLPrint.cpp lib/Rewrite/HTMLRewrite.cpp

Ted Kremenek kremenek at apple.com
Tue Mar 18 22:07:26 PDT 2008


Author: kremenek
Date: Wed Mar 19 00:07:26 2008
New Revision: 48533

URL: http://llvm.org/viewvc/llvm-project?rev=48533&view=rev
Log:
More cleanups to the HTML rewriter (with line formatting), with better
pretty-printing of line numbers.

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

Modified: cfe/trunk/Driver/HTMLPrint.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/HTMLPrint.cpp?rev=48533&r1=48532&r2=48533&view=diff

==============================================================================
--- cfe/trunk/Driver/HTMLPrint.cpp (original)
+++ cfe/trunk/Driver/HTMLPrint.cpp Wed Mar 19 00:07:26 2008
@@ -57,14 +57,21 @@
     std::ostringstream os;
   
     os << "<html>\n<head>\n"
-       << " <style type=\"text/css\">\n"
-       << "  .nums, .lines { vertical-align:top }\n"
-       << "  .nums { padding-right:.5em; width:2.5em }\n"
+       << " <style type=\"text/css\">\n"    
+       << "  .codeblock { width:100% }\n"
+       << "  .codeline { font-family: \"Monaco\", fixed; font-size:11pt }\n"
+       << "  .codeline { height:1.5em; line-height:1.5em }\n"
+       << "  .nums, .lines { float:left; height:100% }\n"
+       << "  .nums { background-color: #eeeeee }\n"
+       << "  .nums { font-family: \"Andale Mono\", fixed; font-size:smaller }\n"
+       << "  .nums { width:2.5em; padding-right:2ex; text-align:right }\n"
+       << "  .lines { padding-left: 1ex; border-left: 3px solid #ccc }\n"
+       << "  .lines { white-space: pre }\n"
        << " </style>\n"
        << "</head>\n"
-       << "<body>\n<pre>";
+       << "<body>";
 
-    R.InsertTextBefore(StartLoc, os.str().c_str(), os.str().size());
+    R.InsertStrBefore(StartLoc, os.str());
   }
   
   // Generate footer
@@ -72,8 +79,8 @@
   {
     std::ostringstream os;
     
-    os << "</pre>\n</body></html>\n";
-    R.InsertTextAfter(EndLoc, os.str().c_str(), os.str().size());
+    os << "</body></html>\n";
+    R.InsertStrAfter(EndLoc, os.str());
   }
     
   

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

==============================================================================
--- cfe/trunk/lib/Rewrite/HTMLRewrite.cpp (original)
+++ cfe/trunk/lib/Rewrite/HTMLRewrite.cpp Wed Mar 19 00:07:26 2008
@@ -49,16 +49,26 @@
 static void AddLineNumber(Rewriter& R, unsigned LineNo,
                           SourceLocation B, SourceLocation E) {
     
-  // Surround the line with a span tag.
+  // Surround the line text with a div tag.
   
-  R.InsertTextBefore(E, "</span>", 7);
-  R.InsertTextBefore(B, "<span class=lines>", 18);
+  if (B == E) // Handle empty lines.
+    R.InsertCStrBefore(B, "<div class=\"lines\"> </div>");
+  else {                         
+    R.InsertCStrBefore(E, "</div>");
+    R.InsertCStrBefore(B, "<div class=\"lines\">");
+  }
+  
+  // Insert a div tag for the line number.
   
-  // Insert a span tag for the line number.
-
   std::ostringstream os;
-  os << "<span class=nums>" << LineNo << "</span>";
-  R.InsertTextBefore(B, os.str().c_str(), os.str().size());
+  os << "<div class=\"nums\">" << LineNo << "</div>";
+  
+  R.InsertStrBefore(B, os.str());
+  
+  // Now surround the whole line with another div tag.
+  
+  R.InsertCStrBefore(B, "<div class=\"codeline\">");
+  R.InsertCStrAfter(E, "</div>");
 }
 
 void html::AddLineNumbers(Rewriter& R, unsigned FileID) {
@@ -98,5 +108,13 @@
       ++C;
       ++FilePos;
     }      
-  }    
+  }
+  
+  // Add one big div tag that surrounds all of the code.
+  
+  R.InsertCStrBefore(SourceLocation::getFileLoc(FileID, 0),
+                     "<div id=\"codeblock\">");
+  
+  R.InsertCStrAfter(SourceLocation::getFileLoc(FileID, FileEnd - FileBeg),
+                    "</div>");
 }





More information about the cfe-commits mailing list