mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-25 14:46:07 +00:00
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. llvm-svn: 42793
This commit is contained in:
parent
eac5948348
commit
a55a2cc25c
@ -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
|
||||
|
@ -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
|
||||
|
@ -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<FunctionDecl*>(D);
|
||||
FD->setBody((Stmt*)Body);
|
||||
|
||||
|
@ -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 = "";
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user