From 409be835b68344e0de56f99ef9a1e12760bc69ee Mon Sep 17 00:00:00 2001 From: Steve Naroff Date: Sun, 11 Nov 2007 19:54:21 +0000 Subject: [PATCH] Replace 3 method definition functions (ObjcParseMethodDefinition, ParseObjCInstanceMethodDefinition, ParseObjCClassMethodDefinition) with 1 method definition function (ParseObjCMethodDefinition). Less code/confusion. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43999 91177308-0d34-0410-b5e6-96231b3b80d8 --- Parse/ParseObjc.cpp | 50 +++++++++++++++++++++--------------- Parse/Parser.cpp | 46 +-------------------------------- include/clang/Parse/Parser.h | 4 +-- 3 files changed, 32 insertions(+), 68 deletions(-) diff --git a/Parse/ParseObjc.cpp b/Parse/ParseObjc.cpp index 7bf1483682..76a9a969b2 100644 --- a/Parse/ParseObjc.cpp +++ b/Parse/ParseObjc.cpp @@ -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) { diff --git a/Parse/Parser.cpp b/Parse/Parser.cpp index bfe342d26a..bc8d0d0c30 100644 --- a/Parse/Parser.cpp +++ b/Parse/Parser.cpp @@ -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) { diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h index d8bde405e5..3660e643bb 100644 --- a/include/clang/Parse/Parser.h +++ b/include/clang/Parse/Parser.h @@ -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. -- 2.40.0