summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/StmtCXX.cpp
diff options
context:
space:
mode:
authorGor Nishanov <GorNishanov@gmail.com>2017-02-13 05:05:02 +0000
committerGor Nishanov <GorNishanov@gmail.com>2017-02-13 05:05:02 +0000
commitbbe1c073873e7934809be14494c1988450c962b3 (patch)
tree0bd3b816a11e15ed0d6c3e8a7c06e49f9d52349f /clang/lib/AST/StmtCXX.cpp
parent3668bde3717b0ffd67e683be45607f0892036312 (diff)
[coroutines] NFC: Refactor Sema::CoroutineBodyStmt construction.
Summary: Sema::CheckCompletedCoroutineBody was growing unwieldy with building all of the substatements. Also, constructors for CoroutineBodyStmt had way too many parameters. Instead, CoroutineBodyStmt now defines CtorArgs structure with all of the required construction parameters. CheckCompleteCoroutineBody delegates construction of individual substatements to short functions one per each substatement. Also, added a drive-by fix of initializing CoroutinePromise to nullptr in ScopeInfo.h. And addressed the FIXME that wanted to tail allocate extra room at the end of the CoroutineBodyStmt to hold parameter move expressions. (The comment was longer that the code that implemented tail allocation). Reviewers: rsmith, EricWF Subscribers: mehdi_amini, cfe-commits Differential Revision: https://reviews.llvm.org/D28835 llvm-svn: 294933
Diffstat (limited to 'clang/lib/AST/StmtCXX.cpp')
-rw-r--r--clang/lib/AST/StmtCXX.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/clang/lib/AST/StmtCXX.cpp b/clang/lib/AST/StmtCXX.cpp
index 4a04fc211262..5c7686c8cb8f 100644
--- a/clang/lib/AST/StmtCXX.cpp
+++ b/clang/lib/AST/StmtCXX.cpp
@@ -86,3 +86,28 @@ VarDecl *CXXForRangeStmt::getLoopVariable() {
const VarDecl *CXXForRangeStmt::getLoopVariable() const {
return const_cast<CXXForRangeStmt *>(this)->getLoopVariable();
}
+
+CoroutineBodyStmt *CoroutineBodyStmt::Create(
+ const ASTContext &C, CoroutineBodyStmt::CtorArgs const& Args) {
+ std::size_t Size = totalSizeToAlloc<Stmt *>(
+ CoroutineBodyStmt::FirstParamMove + Args.ParamMoves.size());
+
+ void *Mem = C.Allocate(Size, alignof(CoroutineBodyStmt));
+ return new (Mem) CoroutineBodyStmt(Args);
+}
+
+CoroutineBodyStmt::CoroutineBodyStmt(CoroutineBodyStmt::CtorArgs const &Args)
+ : Stmt(CoroutineBodyStmtClass), NumParams(Args.ParamMoves.size()) {
+ Stmt **SubStmts = getStoredStmts();
+ SubStmts[CoroutineBodyStmt::Body] = Args.Body;
+ SubStmts[CoroutineBodyStmt::Promise] = Args.Promise;
+ SubStmts[CoroutineBodyStmt::InitSuspend] = Args.InitialSuspend;
+ SubStmts[CoroutineBodyStmt::FinalSuspend] = Args.FinalSuspend;
+ SubStmts[CoroutineBodyStmt::OnException] = Args.OnException;
+ SubStmts[CoroutineBodyStmt::OnFallthrough] = Args.OnFallthrough;
+ SubStmts[CoroutineBodyStmt::Allocate] = Args.Allocate;
+ SubStmts[CoroutineBodyStmt::Deallocate] = Args.Deallocate;
+ SubStmts[CoroutineBodyStmt::ReturnValue] = Args.ReturnValue;
+ std::copy(Args.ParamMoves.begin(), Args.ParamMoves.end(),
+ const_cast<Stmt **>(getParamMoves().data()));
+} \ No newline at end of file