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