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