Mercurial > hg > CbC > CbC_llvm
changeset 188:dd01b8f82867
use scope instead of funcion call
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 05 Jun 2020 20:19:07 +0900 |
parents | 4680e0f68448 |
children | 390e42bfd95a |
files | clang/lib/Parse/ParseCbC.cpp |
diffstat | 1 files changed, 12 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- a/clang/lib/Parse/ParseCbC.cpp Fri Jun 05 18:34:26 2020 +0900 +++ b/clang/lib/Parse/ParseCbC.cpp Fri Jun 05 20:19:07 2020 +0900 @@ -1,4 +1,4 @@ -#ifndef noCbC +#ifndef noCbC #include "clang/Parse/Parser.h" #include "clang/Parse/RAIIObjectsForParser.h" @@ -161,10 +161,8 @@ PrettyStackTraceLoc CrashInfo(PP.getSourceManager(),Loc,"in compound statement ('{}')"); StmtVector CompoundStmts; - size_t cs = Actions.getCurFunction()->CompoundScopes.size(); // create code segment for return to C's function CreateRetCS(retcsII); - printf("cs = %zu, %zu\n", cs ,Actions.getCurFunction()->CompoundScopes.size()); // __code (*__CbC_return)(); innerRes = CreateDeclStmt(__CbC_retII, true, false, DeclSpec::TST___code); @@ -180,12 +178,8 @@ innerRes = CreateComplexStmtRet(__CbC_retII, false); if (innerRes.isUsable()) CompoundStmts.push_back(innerRes.get()); - cs = Actions.getCurFunction()->CompoundScopes.size(); Sema::CompoundScopeRAII CompoundScope(Actions); CompoundStmtRes = Actions.ActOnCompoundStmt(Loc,Loc,CompoundStmts,true); - // assert( cs == Actions.getCurFunction()->CompoundScopes.size()); - printf("cs = %zu, %zu\n", cs ,Actions.getCurFunction()->CompoundScopes.size()); - // ConsumeToken(); ConsumeAnyToken(); // eat the '__return'. return Actions.ActOnStmtExpr(getCurScope(),Loc, CompoundStmtRes.get(), Loc); @@ -219,7 +213,6 @@ return ExprError(); } - size_t cs = Actions.getCurFunction()->CompoundScopes.size(); Sema::CompoundScopeRAII CompoundScope(Actions); StmtResult innerRes; SourceLocation Loc = Tok.getLocation(); @@ -272,8 +265,6 @@ CompoundStmts.push_back(innerRes.get()); StmtResult CompoundStmtRes = Actions.ActOnCompoundStmt(Loc,Loc,CompoundStmts,true); - // assert( cs == Actions.getCurFunction()->CompoundScopes.size()); - printf("cs = %zu, %zu\n", cs ,Actions.getCurFunction()->CompoundScopes.size()); ConsumeAnyToken(); // eat the '__environment'. Result = Actions.ActOnStmtExpr(getCurScope() ,Loc, CompoundStmtRes.get(), Loc); @@ -522,7 +513,6 @@ ParseScope InnerScope(this, Scope::DeclScope,false); StmtResult StmtRes; - size_t cs = Actions.getCurFunction()->CompoundScopes.size(); Sema::CompoundScopeRAII CompoundScope(Actions); PrettyStackTraceLoc CrashInfo(PP.getSourceManager(),Loc,"in create setjmp statement for CbC"); StmtVector innerStmts; @@ -533,8 +523,6 @@ if (innerStmtRes.isUsable()) innerStmts.push_back(innerStmtRes.get()); StmtRes = Actions.ActOnCompoundStmt(Loc, Loc,innerStmts, false); - // assert( cs == Actions.getCurFunction()->CompoundScopes.size()); - printf("cs = %zu, %zu\n", cs ,Actions.getCurFunction()->CompoundScopes.size()); StmtResult ThenStmt(StmtRes); InnerScope.Exit(); IfScope.Exit(); @@ -696,25 +684,14 @@ DeclContext *SavedContext = Actions.CurContext; TypeSourceInfo *CurFuncTI = Actions.Context.CreateTypeSourceInfo(CurFuncResQT); sema::FunctionScopeInfo *SavedFSI = Actions.FunctionScopes.pop_back_val(); - Decl *BodyRes = 0; - StmtResult FnBody; - CreateRetCS1(csName, Policy, CurFuncResQT, CurFuncTI,&BodyRes, FnBody); - Decl *TheDecl = Actions.ActOnFinishFunctionBody(BodyRes, FnBody.get()); - DeclGroupPtrTy returnDecl = DeclGroupPtrTy(); - returnDecl = Actions.ConvertDeclToDeclGroup(TheDecl); - (&Actions.getASTConsumer())->HandleTopLevelDecl(returnDecl.get()); - Actions.CurScope = SavedScope; - Actions.CurContext = SavedContext; - Actions.FunctionScopes.push_back(SavedFSI); -} -void Parser::CreateRetCS1(IdentifierInfo *csName, const PrintingPolicy &Policy, QualType CurFuncResQT , TypeSourceInfo *CurFuncTI , Decl ** BodyResP, StmtResult &FnBody){ Actions.CurContext = static_cast<DeclContext *>(Actions.Context.getTranslationUnitDecl()); Scope *TopScope = getCurScope(); while(TopScope->getParent() != NULL) TopScope = TopScope->getParent(); Actions.CurScope = TopScope; + DeclGroupPtrTy returnDecl = DeclGroupPtrTy(); SourceLocation Loc = Tok.getLocation(); ParsingDeclSpec PDS(*this); setTST(&PDS, DeclSpec::TST___code); @@ -756,6 +733,7 @@ Loc, Loc, D, TrailingReturnType, &FDS), std::move(FnAttrs), Loc); PrototypeScope.Exit(); + Decl *TheDecl; ParseScope BodyScope(this, Scope::FnScope|Scope::DeclScope); Sema::SkipBodyInfo SkipBody; const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(); @@ -766,7 +744,7 @@ D.complete(BodyRes); D.getMutableDeclSpec().abort(); Actions.ActOnDefaultCtorInitializers(BodyRes); - *BodyResP = BodyRes; + StmtResult FnBody; StmtVector FnStmts; StmtResult innerR; ExprResult retvalAssginmentExpr,LHS; @@ -789,7 +767,7 @@ starDS.getUnalignedSpecLoc()), std::move(starDS.getAttributes()), SourceLocation()); - size_t cs = Actions.getCurFunction()->CompoundScopes.size(); + { // scope for RAII Sema::CompoundScopeRAII CompoundScope(Actions); ExprVector ArgExprs2; LHS = LookupNameAndBuildExpr(envII); @@ -853,9 +831,14 @@ if(innerR.isUsable()) FnStmts.push_back(innerR.get()); FnBody = Actions.ActOnCompoundStmt(Loc, Loc, FnStmts, false); - // assert( cs == Actions.getCurFunction()->CompoundScopes.size()); - printf("cs = %zu, %zu\n", cs ,Actions.getCurFunction()->CompoundScopes.size()); + } // RAII clear BodyScope.Exit(); + TheDecl = Actions.ActOnFinishFunctionBody(BodyRes, FnBody.get()); + returnDecl = Actions.ConvertDeclToDeclGroup(TheDecl); + (&Actions.getASTConsumer())->HandleTopLevelDecl(returnDecl.get()); + Actions.CurScope = SavedScope; + Actions.CurContext = SavedContext; + Actions.FunctionScopes.push_back(SavedFSI); } /// IIToExpr - Create ExprResult from IdentifierInfo. @@ -1052,11 +1035,8 @@ if (retRes.isUsable()) CompoundedStmts.push_back(retRes.get()); } - size_t cs = Actions.getCurFunction()->CompoundScopes.size(); Sema::CompoundScopeRAII CompoundScope(Actions); StmtResult R = Actions.ActOnCompoundStmt(gotoLoc, Tok.getLocation(), CompoundedStmts, false); - // assert( cs == Actions.getCurFunction()->CompoundScopes.size()); - printf("cs = %zu, %zu\n", cs ,Actions.getCurFunction()->CompoundScopes.size()); return R; }