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; |
| 31 | QualType RetType; |
| 32 | SmallVector<Stmt *, 4> ParamMovesVector; |
| 33 | const bool IsPromiseDependentType; |
| 34 | CXXRecordDecl *PromiseRecordDecl = nullptr; |
| 35 | |
| 36 | public: |
| 37 | /// \brief Construct a CoroutineStmtBuilder and initialize the promise |
| 38 | /// statement and initial/final suspends from the FunctionScopeInfo. |
| 39 | CoroutineStmtBuilder(Sema &S, FunctionDecl &FD, sema::FunctionScopeInfo &Fn, |
| 40 | Stmt *Body); |
| 41 | |
| 42 | /// \brief Build the coroutine body statements, including the |
| 43 | /// "promise dependent" statements when the promise type is not dependent. |
| 44 | bool buildStatements(); |
| 45 | |
| 46 | /// \brief Build the coroutine body statements that require a non-dependent |
| 47 | /// promise type in order to construct. |
| 48 | /// |
| 49 | /// For example different new/delete overloads are selected depending on |
| 50 | /// if the promise type provides `unhandled_exception()`, and therefore they |
| 51 | /// cannot be built until the promise type is complete so that we can perform |
| 52 | /// name lookup. |
| 53 | bool buildDependentStatements(); |
| 54 | |
| 55 | bool isInvalid() const { return !this->IsValid; } |
| 56 | |
| 57 | private: |
| 58 | bool makePromiseStmt(); |
| 59 | bool makeInitialAndFinalSuspend(); |
| 60 | bool makeNewAndDeleteExpr(); |
| 61 | bool makeOnFallthrough(); |
| 62 | bool makeOnException(); |
| 63 | bool makeReturnObject(); |
| 64 | bool makeReturnOnAllocFailure(); |
| 65 | bool makeParamMoves(); |
| 66 | }; |
| 67 | |
| 68 | } // end namespace clang |
| 69 | |
| 70 | #endif // LLVM_CLANG_LIB_SEMA_COROUTINESTMTBUILDER_H |