[cfe-commits] r42793 - in /cfe/trunk: Parse/Parser.cpp Sema/Sema.h Sema/SemaDecl.cpp clang.xcodeproj/project.pbxproj include/clang/Parse/Action.h

Chris Lattner sabre at nondot.org
Tue Oct 9 10:14:06 PDT 2007


Author: lattner
Date: Tue Oct  9 12:14:05 2007
New Revision: 42793

URL: http://llvm.org/viewvc/llvm-project?rev=42793&view=rev
Log:
rename some "Parse" actions to "ActOn".  Move code around in
ParseFunctionDefinition so that ActOnFunctionDefBody is always
called if ActOnStartOfFunctionDef is called.  This fixes a crash
reported by Nuno Lopes.



Modified:
    cfe/trunk/Parse/Parser.cpp
    cfe/trunk/Sema/Sema.h
    cfe/trunk/Sema/SemaDecl.cpp
    cfe/trunk/clang.xcodeproj/project.pbxproj
    cfe/trunk/include/clang/Parse/Action.h

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

==============================================================================
--- cfe/trunk/Parse/Parser.cpp (original)
+++ cfe/trunk/Parse/Parser.cpp Tue Oct  9 12:14:05 2007
@@ -457,14 +457,6 @@
   if (!FTI.hasPrototype && FTI.NumArgs != 0)
     ParseKNRParamDeclarations(D);
 
-  // Enter a scope for the function body.
-  EnterScope(Scope::FnScope|Scope::DeclScope);
-  
-  // Tell the actions module that we have entered a function definition with the
-  // specified Declarator for the function.
-  DeclTy *Res = Actions.ParseStartOfFunctionDef(CurScope, D);
-  
-  
   // We should have an opening brace now.
   if (Tok.getKind() != tok::l_brace) {
     Diag(Tok, diag::err_expected_fn_body);
@@ -473,26 +465,34 @@
     SkipUntil(tok::l_brace, true, true);
     
     // If we didn't find the '{', bail out.
-    if (Tok.getKind() != tok::l_brace) {
-      ExitScope();
+    if (Tok.getKind() != tok::l_brace)
       return 0;
-    }
   }
   
+  SourceLocation BraceLoc = Tok.getLocation();
+  
+  // Enter a scope for the function body.
+  EnterScope(Scope::FnScope|Scope::DeclScope);
+  
+  // Tell the actions module that we have entered a function definition with the
+  // specified Declarator for the function.
+  DeclTy *Res = Actions.ActOnStartOfFunctionDef(CurScope, D);
+  
+  
   // Do not enter a scope for the brace, as the arguments are in the same scope
   // (the function body) as the body itself.  Instead, just read the statement
   // list and put it into a CompoundStmt for safe keeping.
   StmtResult FnBody = ParseCompoundStatementBody();
-  if (FnBody.isInvalid) {
-    ExitScope();
-    return 0;
-  }
+
+  // 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.
-  return Actions.ParseFunctionDefBody(Res, FnBody.Val);
+  return Actions.ActOnFunctionDefBody(Res, FnBody.Val);
 }
 
 /// ParseKNRParamDeclarations - Parse 'declaration-list[opt]' which provides

Modified: cfe/trunk/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/Sema.h?rev=42793&r1=42792&r2=42793&view=diff

==============================================================================
--- cfe/trunk/Sema/Sema.h (original)
+++ cfe/trunk/Sema/Sema.h Tue Oct  9 12:14:05 2007
@@ -154,8 +154,8 @@
   void AddInitializerToDecl(DeclTy *dcl, ExprTy *init);
   virtual DeclTy *FinalizeDeclaratorGroup(Scope *S, DeclTy *Group);
 
-  virtual DeclTy *ParseStartOfFunctionDef(Scope *S, Declarator &D);
-  virtual DeclTy *ParseFunctionDefBody(DeclTy *Decl, StmtTy *Body);
+  virtual DeclTy *ActOnStartOfFunctionDef(Scope *S, Declarator &D);
+  virtual DeclTy *ActOnFunctionDefBody(DeclTy *Decl, StmtTy *Body);
   virtual void PopScope(SourceLocation Loc, Scope *S);
 
   /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with

Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=42793&r1=42792&r2=42793&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Tue Oct  9 12:14:05 2007
@@ -768,7 +768,7 @@
 }
   
 
-Sema::DeclTy *Sema::ParseStartOfFunctionDef(Scope *FnBodyScope, Declarator &D) {
+Sema::DeclTy *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Declarator &D) {
   assert(CurFunctionDecl == 0 && "Function parsing confused");
   assert(D.getTypeObject(0).Kind == DeclaratorChunk::Function &&
          "Not a function declarator!");
@@ -819,7 +819,7 @@
   return FD;
 }
 
-Sema::DeclTy *Sema::ParseFunctionDefBody(DeclTy *D, StmtTy *Body) {
+Sema::DeclTy *Sema::ActOnFunctionDefBody(DeclTy *D, StmtTy *Body) {
   FunctionDecl *FD = static_cast<FunctionDecl*>(D);
   FD->setBody((Stmt*)Body);
   

Modified: cfe/trunk/clang.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/clang.xcodeproj/project.pbxproj?rev=42793&r1=42792&r2=42793&view=diff

==============================================================================
--- cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/trunk/clang.xcodeproj/project.pbxproj Tue Oct  9 12:14:05 2007
@@ -739,7 +739,6 @@
 		08FB7793FE84155DC02AAC07 /* Project object */ = {
 			isa = PBXProject;
 			buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
-			compatibilityVersion = "Xcode 2.4";
 			hasScannedForEncodings = 1;
 			mainGroup = 08FB7794FE84155DC02AAC07 /* clang */;
 			projectDirPath = "";

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

==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Tue Oct  9 12:14:05 2007
@@ -120,17 +120,17 @@
     return Group;
   }
 
-  /// ParseStartOfFunctionDef - This is called at the start of a function
+  /// ActOnStartOfFunctionDef - This is called at the start of a function
   /// definition, instead of calling ActOnDeclarator.  The Declarator includes
   /// information about formal arguments that are part of this function.
-  virtual DeclTy *ParseStartOfFunctionDef(Scope *FnBodyScope, Declarator &D) {
+  virtual DeclTy *ActOnStartOfFunctionDef(Scope *FnBodyScope, Declarator &D) {
     // Default to ActOnDeclarator.
     return ActOnDeclarator(FnBodyScope, D, 0);
   }
 
-  /// ParseFunctionDefBody - This is called when a function body has completed
+  /// ActOnFunctionDefBody - This is called when a function body has completed
   /// parsing.  Decl is the DeclTy returned by ParseStartOfFunctionDef.
-  virtual DeclTy *ParseFunctionDefBody(DeclTy *Decl, StmtTy *Body) {
+  virtual DeclTy *ActOnFunctionDefBody(DeclTy *Decl, StmtTy *Body) {
     return Decl;
   }
 





More information about the cfe-commits mailing list