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

Steve Naroff snaroff at apple.com
Sun Nov 11 11:54:21 PST 2007


Author: snaroff
Date: Sun Nov 11 13:54:21 2007
New Revision: 43999

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

Replace 3 method definition functions (ObjcParseMethodDefinition, ParseObjCInstanceMethodDefinition, ParseObjCClassMethodDefinition) with 1 method definition function (ParseObjCMethodDefinition).

Less code/confusion.


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

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

==============================================================================
--- cfe/trunk/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/Parse/ParseObjc.cpp Sun Nov 11 13:54:21 2007
@@ -1139,33 +1139,43 @@
 
 ///   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) {

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

==============================================================================
--- cfe/trunk/Parse/Parser.cpp (original)
+++ cfe/trunk/Parse/Parser.cpp Sun Nov 11 13:54:21 2007
@@ -329,16 +329,9 @@
     // @ 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 @@
   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) {

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

==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Sun Nov 11 13:54:21 2007
@@ -250,7 +250,6 @@
   DeclTy *ParseExternalDeclaration();
   DeclTy *ParseDeclarationOrFunctionDefinition();
   DeclTy *ParseFunctionDefinition(Declarator &D);
-  void ObjcParseMethodDefinition(DeclTy *D);
   void ParseKNRParamDeclarations(Declarator &D);
   void ParseSimpleAsm();
   void ParseAsmStringLiteral();
@@ -301,8 +300,7 @@
   void ParseObjCPropertyAttribute(ObjcDeclSpec &DS);
   DeclTy *ParseObjCPropertyDecl(DeclTy *interfaceDecl, SourceLocation AtLoc);
   
-  void ParseObjCInstanceMethodDefinition();
-  void ParseObjCClassMethodDefinition();
+  void ParseObjCMethodDefinition();
   
   //===--------------------------------------------------------------------===//
   // C99 6.5: Expressions.





More information about the cfe-commits mailing list