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

Ted Kremenek kremenek at apple.com
Tue Mar 18 14:26:34 PDT 2008


Author: kremenek
Date: Tue Mar 18 16:26:34 2008
New Revision: 48506

URL: http://llvm.org/viewvc/llvm-project?rev=48506&view=rev
Log:
Modified "InsertTag" (HTML rewriter) to have an optional "OutermostTag" flag to
indicate whether or not the new tag should be the outermost tag at the specified
location (in the case that other tags have been inserted at the same spot).

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

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

==============================================================================
--- cfe/trunk/include/clang/Rewrite/HTMLRewrite.h (original)
+++ cfe/trunk/include/clang/Rewrite/HTMLRewrite.h Tue Mar 18 16:26:34 2008
@@ -29,7 +29,8 @@
 
   void InsertTag(Rewriter& R, Tags tag,
                  SourceLocation OpenLoc, SourceLocation CloseLoc,
-                 bool NewlineOpen = false, bool NewlineClose = true);
+                 bool NewlineOpen = false, bool NewlineClose = true,
+                 bool OutermostTag = false);
 
 } // end html namespace
 } // end clang namespace

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

==============================================================================
--- cfe/trunk/lib/Rewrite/HTMLRewrite.cpp (original)
+++ cfe/trunk/lib/Rewrite/HTMLRewrite.cpp Tue Mar 18 16:26:34 2008
@@ -48,7 +48,7 @@
 
 void html::InsertTag(Rewriter& R, html::Tags tag,
                      SourceLocation B, SourceLocation E,
-                     bool NewlineOpen, bool NewlineClose) {
+                     bool NewlineOpen, bool NewlineClose, bool OutermostTag) {
   
   const char* TagStr = 0;
   
@@ -65,13 +65,27 @@
     std::ostringstream os;  
     os << '<' << TagStr << '>';
     if (NewlineOpen) os << '\n';
-    R.InsertTextAfter(B, os.str().c_str(), os.str().size());
+    
+    const char* s = os.str().c_str();
+    unsigned n = os.str().size();
+    
+    if (OutermostTag)
+      R.InsertTextBefore(B, s, n);
+    else
+      R.InsertTextAfter(B, s, n);
   }
   
   { // Generate the closing tag.
     std::ostringstream os;  
     os << "</" << TagStr << '>';
     if (NewlineClose) os << '\n';
-    R.InsertTextBefore(E, os.str().c_str(), os.str().size());
+    
+    const char* s = os.str().c_str();
+    unsigned n = os.str().size();
+    
+    if (OutermostTag)
+      R.InsertTextAfter(E, s, n);
+    else
+      R.InsertTextBefore(E, s, n);
   }
 }





More information about the cfe-commits mailing list