1*0b57cec5SDimitry Andric //===- CoroutineStmtBuilder.h - Implicit coroutine stmt builder -*- C++ -*-===// 2*0b57cec5SDimitry Andric // 3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 7*0b57cec5SDimitry Andric // 8*0b57cec5SDimitry Andric // This file defines CoroutineStmtBuilder, a class for building the implicit 9*0b57cec5SDimitry Andric // statements required for building a coroutine body. 10*0b57cec5SDimitry Andric // 11*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 12*0b57cec5SDimitry Andric 13*0b57cec5SDimitry Andric #ifndef LLVM_CLANG_LIB_SEMA_COROUTINESTMTBUILDER_H 14*0b57cec5SDimitry Andric #define LLVM_CLANG_LIB_SEMA_COROUTINESTMTBUILDER_H 15*0b57cec5SDimitry Andric 16*0b57cec5SDimitry Andric #include "clang/AST/Decl.h" 17*0b57cec5SDimitry Andric #include "clang/AST/ExprCXX.h" 18*0b57cec5SDimitry Andric #include "clang/AST/StmtCXX.h" 19*0b57cec5SDimitry Andric #include "clang/Lex/Preprocessor.h" 20*0b57cec5SDimitry Andric #include "clang/Sema/SemaInternal.h" 21*0b57cec5SDimitry Andric 22*0b57cec5SDimitry Andric namespace clang { 23*0b57cec5SDimitry Andric 24*0b57cec5SDimitry Andric class CoroutineStmtBuilder : public CoroutineBodyStmt::CtorArgs { 25*0b57cec5SDimitry Andric Sema &S; 26*0b57cec5SDimitry Andric FunctionDecl &FD; 27*0b57cec5SDimitry Andric sema::FunctionScopeInfo &Fn; 28*0b57cec5SDimitry Andric bool IsValid = true; 29*0b57cec5SDimitry Andric SourceLocation Loc; 30*0b57cec5SDimitry Andric SmallVector<Stmt *, 4> ParamMovesVector; 31*0b57cec5SDimitry Andric const bool IsPromiseDependentType; 32*0b57cec5SDimitry Andric CXXRecordDecl *PromiseRecordDecl = nullptr; 33*0b57cec5SDimitry Andric 34*0b57cec5SDimitry Andric public: 35*0b57cec5SDimitry Andric /// Construct a CoroutineStmtBuilder and initialize the promise 36*0b57cec5SDimitry Andric /// statement and initial/final suspends from the FunctionScopeInfo. 37*0b57cec5SDimitry Andric CoroutineStmtBuilder(Sema &S, FunctionDecl &FD, sema::FunctionScopeInfo &Fn, 38*0b57cec5SDimitry Andric Stmt *Body); 39*0b57cec5SDimitry Andric 40*0b57cec5SDimitry Andric /// Build the coroutine body statements, including the 41*0b57cec5SDimitry Andric /// "promise dependent" statements when the promise type is not dependent. 42*0b57cec5SDimitry Andric bool buildStatements(); 43*0b57cec5SDimitry Andric 44*0b57cec5SDimitry Andric /// Build the coroutine body statements that require a non-dependent 45*0b57cec5SDimitry Andric /// promise type in order to construct. 46*0b57cec5SDimitry Andric /// 47*0b57cec5SDimitry Andric /// For example different new/delete overloads are selected depending on 48*0b57cec5SDimitry Andric /// if the promise type provides `unhandled_exception()`, and therefore they 49*0b57cec5SDimitry Andric /// cannot be built until the promise type is complete so that we can perform 50*0b57cec5SDimitry Andric /// name lookup. 51*0b57cec5SDimitry Andric bool buildDependentStatements(); 52*0b57cec5SDimitry Andric isInvalid()53*0b57cec5SDimitry Andric bool isInvalid() const { return !this->IsValid; } 54*0b57cec5SDimitry Andric 55*0b57cec5SDimitry Andric private: 56*0b57cec5SDimitry Andric bool makePromiseStmt(); 57*0b57cec5SDimitry Andric bool makeInitialAndFinalSuspend(); 58*0b57cec5SDimitry Andric bool makeNewAndDeleteExpr(); 59*0b57cec5SDimitry Andric bool makeOnFallthrough(); 60*0b57cec5SDimitry Andric bool makeOnException(); 61*0b57cec5SDimitry Andric bool makeReturnObject(); 62*0b57cec5SDimitry Andric bool makeGroDeclAndReturnStmt(); 63*0b57cec5SDimitry Andric bool makeReturnOnAllocFailure(); 64*0b57cec5SDimitry Andric }; 65*0b57cec5SDimitry Andric 66*0b57cec5SDimitry Andric } // end namespace clang 67*0b57cec5SDimitry Andric 68*0b57cec5SDimitry Andric #endif // LLVM_CLANG_LIB_SEMA_COROUTINESTMTBUILDER_H 69