]> granicus.if.org Git - clang/commitdiff
Replace 3 method definition functions (ObjcParseMethodDefinition, ParseObjCInstanceMe...
authorSteve Naroff <snaroff@apple.com>
Sun, 11 Nov 2007 19:54:21 +0000 (19:54 +0000)
committerSteve Naroff <snaroff@apple.com>
Sun, 11 Nov 2007 19:54:21 +0000 (19:54 +0000)
Less code/confusion.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43999 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 7bf1483682b6dd72516d671d80cf0d0a556fbc79..76a9a969b26159e05577919b16f7bb5abd4102ae 100644 (file)
@@ -1139,33 +1139,43 @@ Parser::StmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) {
 
 ///   objc-method-def: objc-method-proto ';'[opt] '{' body '}'
 ///
-void Parser::ParseObjCInstanceMethodDefinition() {
-  assert(Tok.is(tok::minus) && "Method definitions should start with '-'");
+void Parser::ParseObjCMethodDefinition() {
   DeclTy *MDecl = ParseObjCMethodPrototype(ObjcImpDecl);
   // parse optional ';'
   if (Tok.is(tok::semi))
     ConsumeToken();
 
+  // We should have an opening brace now.
   if (Tok.isNot(tok::l_brace)) {
-    Diag (Tok, diag::err_expected_lbrace);
-    return;
-  }
-  ObjcParseMethodDefinition(MDecl);
-}
-
-///   objc-method-def: objc-method-proto ';'[opt] '{' body '}'
-///
-void Parser::ParseObjCClassMethodDefinition() {
-  assert(Tok.is(tok::plus) && "Class method definitions should start with '+'");
-  DeclTy *MDecl = ParseObjCMethodPrototype(ObjcImpDecl);
-  // parse optional ';'
-  if (Tok.is(tok::semi))
-    ConsumeToken();
-  if (Tok.isNot(tok::l_brace)) {
-    Diag (Tok, diag::err_expected_lbrace);
-    return;
+    Diag(Tok, diag::err_expected_fn_body);
+    
+    // Skip over garbage, until we get to '{'.  Don't eat the '{'.
+    SkipUntil(tok::l_brace, true, true);
+    
+    // If we didn't find the '{', bail out.
+    if (Tok.isNot(tok::l_brace))
+      return;
   }
-  ObjcParseMethodDefinition(MDecl);
+  SourceLocation BraceLoc = Tok.getLocation();
+  
+  // Enter a scope for the method body.
+  EnterScope(Scope::FnScope|Scope::DeclScope);
+  
+  // Tell the actions module that we have entered a method definition with the
+  // specified Declarator for the method.
+  Actions.ObjcActOnStartOfMethodDef(CurScope, MDecl);
+  
+  StmtResult FnBody = ParseCompoundStatementBody();
+  
+  // If the function body could not be parsed, make a bogus compoundstmt.
+  if (FnBody.isInvalid)
+    FnBody = Actions.ActOnCompoundStmt(BraceLoc, BraceLoc, 0, 0, false);
+  
+  // Leave the function body scope.
+  ExitScope();
+  
+  // TODO: Pass argument information.
+  Actions.ActOnMethodDefBody(MDecl, FnBody.Val);
 }
 
 Parser::ExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) {
index bfe342d26a67e240a546fe2efe063819a5cb313b..bc8d0d0c3048620eb2066e3127faee7c2cf51916 100644 (file)
@@ -329,16 +329,9 @@ Parser::DeclTy *Parser::ParseExternalDeclaration() {
     // @ is not a legal token unless objc is enabled, no need to check.
     return ParseObjCAtDirectives();
   case tok::minus:
-    if (getLang().ObjC1)
-      ParseObjCInstanceMethodDefinition();
-    else {
-      Diag(Tok, diag::err_expected_external_declaration);
-      ConsumeToken();
-    }
-    return 0;
   case tok::plus:
     if (getLang().ObjC1)
-      ParseObjCClassMethodDefinition();
+      ParseObjCMethodDefinition();
     else {
       Diag(Tok, diag::err_expected_external_declaration);
       ConsumeToken();
@@ -464,43 +457,6 @@ Parser::DeclTy *Parser::ParseFunctionDefinition(Declarator &D) {
   return ParseFunctionStatementBody(Res, BraceLoc, BraceLoc);  
 }
 
-/// ObjcParseMethodDefinition - This routine parses a method definition and
-/// returns its AST.
-void Parser::ObjcParseMethodDefinition(DeclTy *D) {
-  // We should have an opening brace now.
-  if (Tok.isNot(tok::l_brace)) {
-    Diag(Tok, diag::err_expected_fn_body);
-    
-    // Skip over garbage, until we get to '{'.  Don't eat the '{'.
-    SkipUntil(tok::l_brace, true, true);
-    
-    // If we didn't find the '{', bail out.
-    if (Tok.isNot(tok::l_brace))
-      return;
-  }
-  
-  SourceLocation BraceLoc = Tok.getLocation();
-  
-  // Enter a scope for the method body.
-  EnterScope(Scope::FnScope|Scope::DeclScope);
-  
-  // Tell the actions module that we have entered a method definition with the
-  // specified Declarator for the method.
-  Actions.ObjcActOnStartOfMethodDef(CurScope, D);
-  
-  StmtResult FnBody = ParseCompoundStatementBody();
-  
-  // If the function body could not be parsed, make a bogus compoundstmt.
-  if (FnBody.isInvalid)
-    FnBody = Actions.ActOnCompoundStmt(BraceLoc, BraceLoc, 0, 0, false);
-  
-  // Leave the function body scope.
-  ExitScope();
-  
-  // TODO: Pass argument information.
-  Actions.ActOnMethodDefBody(D, FnBody.Val);
-}
-
 /// ParseKNRParamDeclarations - Parse 'declaration-list[opt]' which provides
 /// types for a function with a K&R-style identifier list for arguments.
 void Parser::ParseKNRParamDeclarations(Declarator &D) {
index d8bde405e576fc2dd2388b7db05697afff13a2c0..3660e643bb01e27e157702a243f7a5e8e54b16d1 100644 (file)
@@ -250,7 +250,6 @@ private:
   DeclTy *ParseExternalDeclaration();
   DeclTy *ParseDeclarationOrFunctionDefinition();
   DeclTy *ParseFunctionDefinition(Declarator &D);
-  void ObjcParseMethodDefinition(DeclTy *D);
   void ParseKNRParamDeclarations(Declarator &D);
   void ParseSimpleAsm();
   void ParseAsmStringLiteral();
@@ -301,8 +300,7 @@ private:
   void ParseObjCPropertyAttribute(ObjcDeclSpec &DS);
   DeclTy *ParseObjCPropertyDecl(DeclTy *interfaceDecl, SourceLocation AtLoc);
   
-  void ParseObjCInstanceMethodDefinition();
-  void ParseObjCClassMethodDefinition();
+  void ParseObjCMethodDefinition();
   
   //===--------------------------------------------------------------------===//
   // C99 6.5: Expressions.