CoroutineStmtBuilder.h 2.3 KB

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