From f9ed3157c93495474003a5ec360039030fd42e9c Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Thu, 8 Nov 2007 19:01:26 +0000 Subject: [PATCH] Refactored parsing of main function body for reuse by objective-c methods. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43898 91177308-0d34-0410-b5e6-96231b3b80d8 --- Parse/ParseStmt.cpp | 18 ++++++++++++++++++ Parse/Parser.cpp | 16 +--------------- include/clang/Parse/Parser.h | 2 ++ 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/Parse/ParseStmt.cpp b/Parse/ParseStmt.cpp index 5e05f9a27d..6836f10c58 100644 --- a/Parse/ParseStmt.cpp +++ b/Parse/ParseStmt.cpp @@ -1030,3 +1030,21 @@ void Parser::ParseAsmOperandsOpt() { ConsumeToken(); } } + +Parser::DeclTy *Parser::ParseFunctionStatementBody(DeclTy *Decl, + SourceLocation L, SourceLocation R) { + // 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 the function body could not be parsed, make a bogus compoundstmt. + if (FnBody.isInvalid) + FnBody = Actions.ActOnCompoundStmt(L, R, 0, 0, false); + + // Leave the function body scope. + ExitScope(); + + // TODO: Pass argument information. + return Actions.ActOnFunctionDefBody(Decl, FnBody.Val); +} \ No newline at end of file diff --git a/Parse/Parser.cpp b/Parse/Parser.cpp index 8040eb8ebc..a2ba86e903 100644 --- a/Parse/Parser.cpp +++ b/Parse/Parser.cpp @@ -462,21 +462,7 @@ Parser::DeclTy *Parser::ParseFunctionDefinition(Declarator &D) { // 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 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.ActOnFunctionDefBody(Res, FnBody.Val); + return ParseFunctionStatementBody(Res, BraceLoc, BraceLoc); } /// ParseKNRParamDeclarations - Parse 'declaration-list[opt]' which provides diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h index b7476a77b6..7339d6ca50 100644 --- a/include/clang/Parse/Parser.h +++ b/include/clang/Parse/Parser.h @@ -397,6 +397,8 @@ private: DeclTy *ParseDeclaration(unsigned Context); DeclTy *ParseSimpleDeclaration(unsigned Context); DeclTy *ParseInitDeclaratorListAfterFirstDeclarator(Declarator &D); + DeclTy *ParseFunctionStatementBody(DeclTy *Decl, + SourceLocation L, SourceLocation R); void ParseDeclarationSpecifiers(DeclSpec &DS); void ParseSpecifierQualifierList(DeclSpec &DS); -- 2.50.1