]> granicus.if.org Git - clang/commitdiff
Rewrite method definition bodies. Also renamed a method to distinguish between method...
authorSteve Naroff <snaroff@apple.com>
Tue, 13 Nov 2007 23:01:27 +0000 (23:01 +0000)
committerSteve Naroff <snaroff@apple.com>
Tue, 13 Nov 2007 23:01:27 +0000 (23:01 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44080 91177308-0d34-0410-b5e6-96231b3b80d8

Driver/RewriteTest.cpp
Parse/ParseObjc.cpp
Parse/Parser.cpp
include/clang/Parse/Parser.h

index ff9bf2f9243d0bbb44b5f0b8b47a981646184da6..9e17a6ef8cd64e0fd8b5392ef7412d9aa6fb05b4 100644 (file)
@@ -91,7 +91,7 @@ namespace {
     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 @@ void RewriteTest::HandleDeclInMainFile(Decl *D) {
   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 @@ void RewriteTest::RewriteForwardClassDecl(ObjcClassDecl *ClassDecl) {
                       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 @@ void RewriteTest::RewriteCategoryDecl(ObjcCategoryDecl *CatDecl) {
   // 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 @@ void RewriteTest::RewriteProtocolDecl(ObjcProtocolDecl *PDecl) {
   // 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 @@ void RewriteTest::RewriteInterfaceDecl(ObjcInterfaceDecl *ClassDecl) {
                       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);
index 19d32bd486e2316cac70689a479d33b1639ccd16..2152601094b2283ddf1f604e999a868113a51d8b 100644 (file)
@@ -1139,7 +1139,7 @@ Parser::StmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) {
 
 ///   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 @@ void Parser::ParseObjCMethodDefinition() {
     
     // 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 @@ void Parser::ParseObjCMethodDefinition() {
   
   // TODO: Pass argument information.
   Actions.ActOnFinishFunctionBody(MDecl, FnBody.Val);
+  return MDecl;
 }
 
 Parser::ExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) {
index bc8d0d0c3048620eb2066e3127faee7c2cf51916..b571703a3a5cbe3852c7ec8f2d59875095f2fe8a 100644 (file)
@@ -331,7 +331,7 @@ Parser::DeclTy *Parser::ParseExternalDeclaration() {
   case tok::minus:
   case tok::plus:
     if (getLang().ObjC1)
-      ParseObjCMethodDefinition();
+      return ParseObjCMethodDefinition();
     else {
       Diag(Tok, diag::err_expected_external_declaration);
       ConsumeToken();
index 3660e643bb01e27e157702a243f7a5e8e54b16d1..57fd4e1e790f8800c1a6821773625ce3dc364d7e 100644 (file)
@@ -300,7 +300,7 @@ private:
   void ParseObjCPropertyAttribute(ObjcDeclSpec &DS);
   DeclTy *ParseObjCPropertyDecl(DeclTy *interfaceDecl, SourceLocation AtLoc);
   
-  void ParseObjCMethodDefinition();
+  DeclTy *ParseObjCMethodDefinition();
   
   //===--------------------------------------------------------------------===//
   // C99 6.5: Expressions.