[cfe-commits] r44080 - in /cfe/trunk: Driver/RewriteTest.cpp Parse/ParseObjc.cpp Parse/Parser.cpp include/clang/Parse/Parser.h

Steve Naroff snaroff at apple.com
Tue Nov 13 15:01:27 PST 2007


Author: snaroff
Date: Tue Nov 13 17:01:27 2007
New Revision: 44080

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

Rewrite method definition bodies. Also renamed a method to distinguish between method declarations and definitions.

Modified:
    cfe/trunk/Driver/RewriteTest.cpp
    cfe/trunk/Parse/ParseObjc.cpp
    cfe/trunk/Parse/Parser.cpp
    cfe/trunk/include/clang/Parse/Parser.h

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

==============================================================================
--- cfe/trunk/Driver/RewriteTest.cpp (original)
+++ cfe/trunk/Driver/RewriteTest.cpp Tue Nov 13 17:01:27 2007
@@ -91,7 +91,7 @@
     void RewriteObjcMethodDecl(ObjcMethodDecl *MDecl, std::string &ResultStr);
     void RewriteCategoryDecl(ObjcCategoryDecl *Dcl);
     void RewriteProtocolDecl(ObjcProtocolDecl *Dcl);
-    void RewriteMethods(int nMethods, ObjcMethodDecl **Methods);
+    void RewriteMethodDeclarations(int nMethods, ObjcMethodDecl **Methods);
     void RewriteProperties(int nProperties, ObjcPropertyDecl **Properties);
     void RewriteFunctionDecl(FunctionDecl *FD);
     void RewriteObjcQualifiedInterfaceTypes(
@@ -189,7 +189,11 @@
   if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
     if (Stmt *Body = FD->getBody())
       FD->setBody(RewriteFunctionBodyOrGlobalInitializer(Body));
-  
+	  
+  if (ObjcMethodDecl *MD = dyn_cast<ObjcMethodDecl>(D)) {
+    if (Stmt *Body = MD->getBody())
+      MD->setBody(RewriteFunctionBodyOrGlobalInitializer(Body));
+  }
   if (ObjcImplementationDecl *CI = dyn_cast<ObjcImplementationDecl>(D))
     ClassImplementation.push_back(CI);
   else if (ObjcCategoryImplDecl *CI = dyn_cast<ObjcCategoryImplDecl>(D))
@@ -325,7 +329,7 @@
                       typedefString.c_str(), typedefString.size());
 }
 
-void RewriteTest::RewriteMethods(int nMethods, ObjcMethodDecl **Methods) {
+void RewriteTest::RewriteMethodDeclarations(int nMethods, ObjcMethodDecl **Methods) {
   for (int i = 0; i < nMethods; i++) {
     ObjcMethodDecl *Method = Methods[i];
     SourceLocation Loc = Method->getLocStart();
@@ -354,10 +358,10 @@
   // FIXME: handle category headers that are declared across multiple lines.
   Rewrite.ReplaceText(LocStart, 0, "// ", 3);
   
-  RewriteMethods(CatDecl->getNumInstanceMethods(),
-                 CatDecl->getInstanceMethods());
-  RewriteMethods(CatDecl->getNumClassMethods(),
-                 CatDecl->getClassMethods());
+  RewriteMethodDeclarations(CatDecl->getNumInstanceMethods(),
+                            CatDecl->getInstanceMethods());
+  RewriteMethodDeclarations(CatDecl->getNumClassMethods(),
+                            CatDecl->getClassMethods());
   // Lastly, comment out the @end.
   Rewrite.ReplaceText(CatDecl->getAtEndLoc(), 0, "// ", 3);
 }
@@ -368,10 +372,10 @@
   // 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());
+  RewriteMethodDeclarations(PDecl->getNumInstanceMethods(),
+                            PDecl->getInstanceMethods());
+  RewriteMethodDeclarations(PDecl->getNumClassMethods(),
+                            PDecl->getClassMethods());
   // Lastly, comment out the @end.
   Rewrite.ReplaceText(PDecl->getAtEndLoc(), 0, "// ", 3);
 }
@@ -533,10 +537,10 @@
                       ResultStr.c_str(), ResultStr.size());
   RewriteProperties(ClassDecl->getNumPropertyDecl(),
                     ClassDecl->getPropertyDecl());
-  RewriteMethods(ClassDecl->getNumInstanceMethods(),
-                 ClassDecl->getInstanceMethods());
-  RewriteMethods(ClassDecl->getNumClassMethods(),
-                 ClassDecl->getClassMethods());
+  RewriteMethodDeclarations(ClassDecl->getNumInstanceMethods(),
+                            ClassDecl->getInstanceMethods());
+  RewriteMethodDeclarations(ClassDecl->getNumClassMethods(),
+                            ClassDecl->getClassMethods());
   
   // Lastly, comment out the @end.
   Rewrite.ReplaceText(ClassDecl->getAtEndLoc(), 0, "// ", 3);

Modified: cfe/trunk/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/ParseObjc.cpp?rev=44080&r1=44079&r2=44080&view=diff

==============================================================================
--- cfe/trunk/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/Parse/ParseObjc.cpp Tue Nov 13 17:01:27 2007
@@ -1139,7 +1139,7 @@
 
 ///   objc-method-def: objc-method-proto ';'[opt] '{' body '}'
 ///
-void Parser::ParseObjCMethodDefinition() {
+Parser::DeclTy *Parser::ParseObjCMethodDefinition() {
   DeclTy *MDecl = ParseObjCMethodPrototype(ObjcImpDecl);
   // parse optional ';'
   if (Tok.is(tok::semi))
@@ -1154,7 +1154,7 @@
     
     // If we didn't find the '{', bail out.
     if (Tok.isNot(tok::l_brace))
-      return;
+      return 0;
   }
   SourceLocation BraceLoc = Tok.getLocation();
   
@@ -1176,6 +1176,7 @@
   
   // TODO: Pass argument information.
   Actions.ActOnFinishFunctionBody(MDecl, FnBody.Val);
+  return MDecl;
 }
 
 Parser::ExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) {

Modified: cfe/trunk/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/Parser.cpp?rev=44080&r1=44079&r2=44080&view=diff

==============================================================================
--- cfe/trunk/Parse/Parser.cpp (original)
+++ cfe/trunk/Parse/Parser.cpp Tue Nov 13 17:01:27 2007
@@ -331,7 +331,7 @@
   case tok::minus:
   case tok::plus:
     if (getLang().ObjC1)
-      ParseObjCMethodDefinition();
+      return ParseObjCMethodDefinition();
     else {
       Diag(Tok, diag::err_expected_external_declaration);
       ConsumeToken();

Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=44080&r1=44079&r2=44080&view=diff

==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Tue Nov 13 17:01:27 2007
@@ -300,7 +300,7 @@
   void ParseObjCPropertyAttribute(ObjcDeclSpec &DS);
   DeclTy *ParseObjCPropertyDecl(DeclTy *interfaceDecl, SourceLocation AtLoc);
   
-  void ParseObjCMethodDefinition();
+  DeclTy *ParseObjCMethodDefinition();
   
   //===--------------------------------------------------------------------===//
   // C99 6.5: Expressions.





More information about the cfe-commits mailing list