]> granicus.if.org Git - clang/commitdiff
Replace 2 method definition actions (ActOnFunctionDefBody, ActOnMethodDefBody) with...
authorSteve Naroff <snaroff@apple.com>
Sun, 11 Nov 2007 23:20:51 +0000 (23:20 +0000)
committerSteve Naroff <snaroff@apple.com>
Sun, 11 Nov 2007 23:20:51 +0000 (23:20 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44000 91177308-0d34-0410-b5e6-96231b3b80d8

Parse/ParseObjc.cpp
Parse/ParseStmt.cpp
Sema/Sema.h
Sema/SemaDecl.cpp
include/clang/Parse/Action.h

index 76a9a969b26159e05577919b16f7bb5abd4102ae..7cf551d0ae184b03df39a7b496a4415558ab43ef 100644 (file)
@@ -1175,7 +1175,7 @@ void Parser::ParseObjCMethodDefinition() {
   ExitScope();
   
   // TODO: Pass argument information.
-  Actions.ActOnMethodDefBody(MDecl, FnBody.Val);
+  Actions.ActOnFinishFunctionBody(MDecl, FnBody.Val);
 }
 
 Parser::ExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) {
index 6836f10c58473dbf75a6324bfc0fa81ae98b2729..cb2a6917190540850ab241639a2f8a535553a497 100644 (file)
@@ -1046,5 +1046,5 @@ Parser::DeclTy *Parser::ParseFunctionStatementBody(DeclTy *Decl,
   ExitScope();
   
   // TODO: Pass argument information.
-  return Actions.ActOnFunctionDefBody(Decl, FnBody.Val);
+  return Actions.ActOnFinishFunctionBody(Decl, FnBody.Val);
 }
\ No newline at end of file
index 190302df99cb10d82f2048492c49fd3b5ad23a19..0aea99e2d507c655336985ff7766880e80cc8610 100644 (file)
@@ -191,8 +191,8 @@ private:
 
   virtual DeclTy *ActOnStartOfFunctionDef(Scope *S, Declarator &D);
   virtual void ObjcActOnStartOfMethodDef(Scope *S, DeclTy *D);
-  virtual DeclTy *ActOnFunctionDefBody(DeclTy *Decl, StmtTy *Body);
-  virtual void ActOnMethodDefBody(DeclTy *Decl, StmtTy *Body);
+  
+  virtual DeclTy *ActOnFinishFunctionBody(DeclTy *Decl, StmtTy *Body);
   
   /// Scope actions.
   virtual void ActOnPopScope(SourceLocation Loc, Scope *S);
index e043fa19f62d06e58825511bc5178dfefe65f67f..c0fb92c4207f9d5196c317bcb58b8c6a2bea42fd 100644 (file)
@@ -996,47 +996,18 @@ Sema::DeclTy *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Declarator &D) {
   return FD;
 }
 
-Sema::DeclTy *Sema::ActOnFunctionDefBody(DeclTy *D, StmtTy *Body) {
-  FunctionDecl *FD = static_cast<FunctionDecl*>(D);
-  FD->setBody((Stmt*)Body);
-  
-  assert(FD == CurFunctionDecl && "Function parsing confused");
-  CurFunctionDecl = 0;
-  
-  // Verify and clean out per-function state.
-  
-  // Check goto/label use.
-  for (llvm::DenseMap<IdentifierInfo*, LabelStmt*>::iterator
-       I = LabelMap.begin(), E = LabelMap.end(); I != E; ++I) {
-    // Verify that we have no forward references left.  If so, there was a goto
-    // or address of a label taken, but no definition of it.  Label fwd
-    // definitions are indicated with a null substmt.
-    if (I->second->getSubStmt() == 0) {
-      LabelStmt *L = I->second;
-      // Emit error.
-      Diag(L->getIdentLoc(), diag::err_undeclared_label_use, L->getName());
-      
-      // At this point, we have gotos that use the bogus label.  Stitch it into
-      // the function body so that they aren't leaked and that the AST is well
-      // formed.
-      L->setSubStmt(new NullStmt(L->getIdentLoc()));
-      cast<CompoundStmt>((Stmt*)Body)->push_back(L);
-    }
+Sema::DeclTy *Sema::ActOnFinishFunctionBody(DeclTy *D, StmtTy *Body) {
+  Decl *dcl = static_cast<Decl *>(D);
+  if (FunctionDecl *FD = dyn_cast<FunctionDecl>(dcl)) {
+    FD->setBody((Stmt*)Body);
+    assert(FD == CurFunctionDecl && "Function parsing confused");
+  } else if (ObjcMethodDecl *MD = dyn_cast<ObjcMethodDecl>(dcl)) {
+    MD->setBody((Stmt*)Body);
   }
-  LabelMap.clear();
-  
-  return FD;
-}
-
-void Sema::ActOnMethodDefBody(DeclTy *D, StmtTy *Body) {
-  ObjcMethodDecl *FD = static_cast<ObjcMethodDecl*>(D);
-  FD->setBody((Stmt*)Body);
   CurFunctionDecl = 0;
   
   // Verify and clean out per-function state.
   
-  // TODO: This code block is common with ActOnFunctionDefBody and need be 
-  // refactored.
   // Check goto/label use.
   for (llvm::DenseMap<IdentifierInfo*, LabelStmt*>::iterator
        I = LabelMap.begin(), E = LabelMap.end(); I != E; ++I) {
@@ -1056,6 +1027,8 @@ void Sema::ActOnMethodDefBody(DeclTy *D, StmtTy *Body) {
     }
   }
   LabelMap.clear();
+  
+  return D;
 }
 
 /// ObjcActOnStartOfMethodDef - This routine sets up parameters; invisible
index 7a725d1aca7accf8aca89701de8c2e7dc1937bd0..24b3af70412b693ae2adfe5de2c4c741eabed127 100644 (file)
@@ -141,14 +141,10 @@ public:
   
   /// ActOnFunctionDefBody - This is called when a function body has completed
   /// parsing.  Decl is the DeclTy returned by ParseStartOfFunctionDef.
-  virtual DeclTy *ActOnFunctionDefBody(DeclTy *Decl, StmtTy *Body) {
+  virtual DeclTy *ActOnFinishFunctionBody(DeclTy *Decl, StmtTy *Body) {
     return Decl;
   }
 
-  virtual void ActOnMethodDefBody(DeclTy *Decl, StmtTy *Body) {
-    return;
-  }
-  
   /// ActOnPopScope - This callback is called immediately before the specified
   /// scope is popped and deleted.
   virtual void ActOnPopScope(SourceLocation Loc, Scope *S) {}