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