From: Chris Lattner Date: Tue, 9 Oct 2007 17:14:05 +0000 (+0000) Subject: rename some "Parse" actions to "ActOn". Move code around in X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b652cea7d7b70ebe3744fb6d72c9ad9cf3c95429;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42793 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Parse/Parser.cpp b/Parse/Parser.cpp index 362ca35512..abca8a1257 100644 --- a/Parse/Parser.cpp +++ b/Parse/Parser.cpp @@ -457,14 +457,6 @@ Parser::DeclTy *Parser::ParseFunctionDefinition(Declarator &D) { 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 @@ Parser::DeclTy *Parser::ParseFunctionDefinition(Declarator &D) { 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 diff --git a/Sema/Sema.h b/Sema/Sema.h index 70997b0ae4..9baad3af7d 100644 --- a/Sema/Sema.h +++ b/Sema/Sema.h @@ -154,8 +154,8 @@ private: 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 diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp index 2a006d87e6..c3b36526f8 100644 --- a/Sema/SemaDecl.cpp +++ b/Sema/SemaDecl.cpp @@ -768,7 +768,7 @@ Sema::ParseParamDeclarator(DeclaratorChunk &FTI, unsigned ArgNo, } -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 @@ Sema::DeclTy *Sema::ParseStartOfFunctionDef(Scope *FnBodyScope, Declarator &D) { return FD; } -Sema::DeclTy *Sema::ParseFunctionDefBody(DeclTy *D, StmtTy *Body) { +Sema::DeclTy *Sema::ActOnFunctionDefBody(DeclTy *D, StmtTy *Body) { FunctionDecl *FD = static_cast(D); FD->setBody((Stmt*)Body); diff --git a/clang.xcodeproj/project.pbxproj b/clang.xcodeproj/project.pbxproj index 12ddcaae8c..951688f92a 100644 --- a/clang.xcodeproj/project.pbxproj +++ b/clang.xcodeproj/project.pbxproj @@ -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 = ""; diff --git a/include/clang/Parse/Action.h b/include/clang/Parse/Action.h index dad24a6947..31045f3cf4 100644 --- a/include/clang/Parse/Action.h +++ b/include/clang/Parse/Action.h @@ -120,17 +120,17 @@ public: 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; }