[cfe-commits] r43503 - /cfe/trunk/Driver/RewriteTest.cpp

Steve Naroff snaroff at apple.com
Tue Oct 30 09:42:30 PDT 2007


Author: snaroff
Date: Tue Oct 30 11:42:30 2007
New Revision: 43503

URL: http://llvm.org/viewvc/llvm-project?rev=43503&view=rev
Log:

Rewrite protocols.


Modified:
    cfe/trunk/Driver/RewriteTest.cpp

Modified: cfe/trunk/Driver/RewriteTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteTest.cpp?rev=43503&r1=43502&r2=43503&view=diff

==============================================================================
--- cfe/trunk/Driver/RewriteTest.cpp (original)
+++ cfe/trunk/Driver/RewriteTest.cpp Tue Oct 30 11:42:30 2007
@@ -61,6 +61,7 @@
     void RewriteForwardClassDecl(ObjcClassDecl *Dcl);
     void RewriteInterfaceDecl(ObjcInterfaceDecl *Dcl);
     void RewriteCategoryDecl(ObjcCategoryDecl *Dcl);
+    void RewriteProtocolDecl(ObjcProtocolDecl *Dcl);
     void RewriteMethods(int nMethods, ObjcMethodDecl **Methods);
     
     // Expression Rewriting.
@@ -126,6 +127,8 @@
     RewriteInterfaceDecl(MD);
   } else if (ObjcCategoryDecl *CD = dyn_cast<ObjcCategoryDecl>(D)) {
     RewriteCategoryDecl(CD);
+  } else if (ObjcProtocolDecl *PD = dyn_cast<ObjcProtocolDecl>(D)) {
+    RewriteProtocolDecl(PD);
   }
   // If we have a decl in the main file, see if we should rewrite it.
   if (SM->getDecomposedFileLoc(Loc).first == MainFileID)
@@ -293,6 +296,20 @@
   Rewrite.ReplaceText(CatDecl->getAtEndLoc(), 0, "// ", 3);
 }
 
+void RewriteTest::RewriteProtocolDecl(ObjcProtocolDecl *PDecl) {
+  SourceLocation LocStart = PDecl->getLocStart();
+  
+  // FIXME: handle protocol headers that are declared across multiple lines.
+  Rewrite.ReplaceText(LocStart, 0, "// ", 3);
+  
+  RewriteMethods(PDecl->getNumInstanceMethods(),
+                 PDecl->getInstanceMethods());
+  RewriteMethods(PDecl->getNumClassMethods(),
+                 PDecl->getClassMethods());
+  // Lastly, comment out the @end.
+  Rewrite.ReplaceText(PDecl->getAtEndLoc(), 0, "// ", 3);
+}
+
 void RewriteTest::RewriteInterfaceDecl(ObjcInterfaceDecl *ClassDecl) {
 
   SourceLocation LocStart = ClassDecl->getLocStart();
@@ -349,7 +366,7 @@
     // FIXME: Missing definition of Rewrite.InsertText(clang::SourceLocation, char const*, unsigned int).
     // Rewrite.InsertText(startLoc, messString.c_str(), messString.size());
     // Tried this, but it didn't work either...
-    Rewrite.ReplaceText(startLoc, 0, messString.c_str(), messString.size());
+    // Rewrite.ReplaceText(startLoc, 0, messString.c_str(), messString.size());
     return RewriteMessageExpr(MessExpr);
   }
   // Return this stmt unmodified.





More information about the cfe-commits mailing list