[cfe-commits] r49406 - in /cfe/trunk: Driver/HTMLDiagnostics.cpp include/clang/Rewrite/HTMLRewrite.h lib/Rewrite/HTMLRewrite.cpp

Ted Kremenek kremenek at apple.com
Tue Apr 8 15:37:58 PDT 2008


Author: kremenek
Date: Tue Apr  8 17:37:58 2008
New Revision: 49406

URL: http://llvm.org/viewvc/llvm-project?rev=49406&view=rev
Log:
Don't expand tabs in EscapeText, but rather expand them when writing out
the HTML file.  This should reduce the amount of memory pressure on the
rewriter for files that have a lot of tabs.

Modified:
    cfe/trunk/Driver/HTMLDiagnostics.cpp
    cfe/trunk/include/clang/Rewrite/HTMLRewrite.h
    cfe/trunk/lib/Rewrite/HTMLRewrite.cpp

Modified: cfe/trunk/Driver/HTMLDiagnostics.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/HTMLDiagnostics.cpp?rev=49406&r1=49405&r2=49406&view=diff

==============================================================================
--- cfe/trunk/Driver/HTMLDiagnostics.cpp (original)
+++ cfe/trunk/Driver/HTMLDiagnostics.cpp Tue Apr  8 17:37:58 2008
@@ -199,8 +199,13 @@
   
   // Emit the HTML to disk.
 
-  for (RewriteBuffer::iterator I = Buf->begin(), E = Buf->end(); I!=E; ++I)
-    os << *I;  
+  for (RewriteBuffer::iterator I = Buf->begin(), E = Buf->end(); I!=E; ++I) {
+    // Expand tabs.
+    if (*I == '\t')
+      os << "   ";
+    else  
+      os << *I;
+  }
 }
 
 void HTMLDiagnostics::HandlePiece(Rewriter& R,

Modified: cfe/trunk/include/clang/Rewrite/HTMLRewrite.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Rewrite/HTMLRewrite.h?rev=49406&r1=49405&r2=49406&view=diff

==============================================================================
--- cfe/trunk/include/clang/Rewrite/HTMLRewrite.h (original)
+++ cfe/trunk/include/clang/Rewrite/HTMLRewrite.h Tue Apr  8 17:37:58 2008
@@ -24,8 +24,20 @@
   
 namespace html {
 
-  void EscapeText(Rewriter& R, unsigned FileID, bool EscapeSpaces = false);
-  std::string EscapeText(const std::string& s, bool EscapeSpaces = false);
+  /// EscapeText - HTMLize a specified file so that special characters are
+  /// are translated so that they are not interpreted as HTML tags.  In this
+  /// version tabs are not replaced with spaces by default, as this can
+  /// introduce a serious performance overhead as the amount of replaced
+  /// text can be very large.
+  void EscapeText(Rewriter& R, unsigned FileID,
+                  bool EscapeSpaces = false, bool ReplacesTabs = false);
+
+  /// EscapeText - HTMLized the provided string so that special characters
+  ///  in 's' are not interpreted as HTML tags.  Unlike the version of
+  ///  EscapeText that rewrites a file, this version by default replaces tabs
+  ///  with spaces.
+  std::string EscapeText(const std::string& s,
+                         bool EscapeSpaces = false, bool ReplaceTabs = true);
 
   void AddLineNumbers(Rewriter& R, unsigned FileID);  
   

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

==============================================================================
--- cfe/trunk/lib/Rewrite/HTMLRewrite.cpp (original)
+++ cfe/trunk/lib/Rewrite/HTMLRewrite.cpp Tue Apr  8 17:37:58 2008
@@ -20,7 +20,8 @@
 
 using namespace clang;
 
-void html::EscapeText(Rewriter& R, unsigned FileID, bool EscapeSpaces) {
+void html::EscapeText(Rewriter& R, unsigned FileID,
+                      bool EscapeSpaces, bool ReplaceTabs) {
   
   const llvm::MemoryBuffer *Buf = R.getSourceMgr().getBuffer(FileID);
   const char* C = Buf->getBufferStart();
@@ -41,6 +42,9 @@
         break;
 
       case '\t': {
+        if (!ReplaceTabs)
+          break;
+        
         SourceLocation Loc = SourceLocation::getFileLoc(FileID, FilePos);
         
         if (EscapeSpaces)
@@ -72,7 +76,8 @@
   }
 }
 
-std::string html::EscapeText(const std::string& s, bool EscapeSpaces) {
+std::string html::EscapeText(const std::string& s, bool EscapeSpaces,
+                             bool ReplaceTabs) {
   
   unsigned len = s.size();
   std::ostringstream os;
@@ -90,7 +95,13 @@
         else os << ' ';
         break;
         
-        case '\t': for (unsigned i = 0; i < 4; ++i) os << " "; break;
+        case '\t':
+          if (ReplaceTabs)
+            for (unsigned i = 0; i < 4; ++i) os << " ";
+          else os << c;
+        
+          break;
+        
         case '<': os << "<"; break;
         case '>': os << ">"; break;
         case '&': os << "&"; break;





More information about the cfe-commits mailing list