2015-10-02 21:41:04 +08:00
|
|
|
//===--- StmtCXX.cpp - Classes for representing C++ statements ------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the subclesses of Stmt class declared in StmtCXX.h
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/AST/StmtCXX.h"
|
|
|
|
|
|
|
|
#include "clang/AST/ASTContext.h"
|
|
|
|
|
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
QualType CXXCatchStmt::getCaughtType() const {
|
|
|
|
if (ExceptionDecl)
|
|
|
|
return ExceptionDecl->getType();
|
|
|
|
return QualType();
|
|
|
|
}
|
|
|
|
|
|
|
|
CXXTryStmt *CXXTryStmt::Create(const ASTContext &C, SourceLocation tryLoc,
|
|
|
|
Stmt *tryBlock, ArrayRef<Stmt *> handlers) {
|
2018-07-23 20:45:24 +08:00
|
|
|
const size_t Size = totalSizeToAlloc<Stmt *>(handlers.size() + 1);
|
2016-10-20 22:27:22 +08:00
|
|
|
void *Mem = C.Allocate(Size, alignof(CXXTryStmt));
|
2015-10-02 21:41:04 +08:00
|
|
|
return new (Mem) CXXTryStmt(tryLoc, tryBlock, handlers);
|
|
|
|
}
|
|
|
|
|
|
|
|
CXXTryStmt *CXXTryStmt::Create(const ASTContext &C, EmptyShell Empty,
|
|
|
|
unsigned numHandlers) {
|
2018-07-23 20:45:24 +08:00
|
|
|
const size_t Size = totalSizeToAlloc<Stmt *>(numHandlers + 1);
|
2016-10-20 22:27:22 +08:00
|
|
|
void *Mem = C.Allocate(Size, alignof(CXXTryStmt));
|
2015-10-02 21:41:04 +08:00
|
|
|
return new (Mem) CXXTryStmt(Empty, numHandlers);
|
|
|
|
}
|
|
|
|
|
|
|
|
CXXTryStmt::CXXTryStmt(SourceLocation tryLoc, Stmt *tryBlock,
|
|
|
|
ArrayRef<Stmt *> handlers)
|
|
|
|
: Stmt(CXXTryStmtClass), TryLoc(tryLoc), NumHandlers(handlers.size()) {
|
2018-07-23 20:45:24 +08:00
|
|
|
Stmt **Stmts = getStmts();
|
2015-10-02 21:41:04 +08:00
|
|
|
Stmts[0] = tryBlock;
|
|
|
|
std::copy(handlers.begin(), handlers.end(), Stmts + 1);
|
|
|
|
}
|
|
|
|
|
2016-03-20 18:33:40 +08:00
|
|
|
CXXForRangeStmt::CXXForRangeStmt(DeclStmt *Range,
|
|
|
|
DeclStmt *BeginStmt, DeclStmt *EndStmt,
|
2015-10-02 21:41:04 +08:00
|
|
|
Expr *Cond, Expr *Inc, DeclStmt *LoopVar,
|
|
|
|
Stmt *Body, SourceLocation FL,
|
2015-10-27 14:02:45 +08:00
|
|
|
SourceLocation CAL, SourceLocation CL,
|
|
|
|
SourceLocation RPL)
|
|
|
|
: Stmt(CXXForRangeStmtClass), ForLoc(FL), CoawaitLoc(CAL), ColonLoc(CL),
|
|
|
|
RParenLoc(RPL) {
|
2015-10-02 21:41:04 +08:00
|
|
|
SubExprs[RANGE] = Range;
|
2016-03-20 18:33:40 +08:00
|
|
|
SubExprs[BEGINSTMT] = BeginStmt;
|
|
|
|
SubExprs[ENDSTMT] = EndStmt;
|
2015-10-02 21:41:04 +08:00
|
|
|
SubExprs[COND] = Cond;
|
|
|
|
SubExprs[INC] = Inc;
|
|
|
|
SubExprs[LOOPVAR] = LoopVar;
|
|
|
|
SubExprs[BODY] = Body;
|
|
|
|
}
|
|
|
|
|
|
|
|
Expr *CXXForRangeStmt::getRangeInit() {
|
|
|
|
DeclStmt *RangeStmt = getRangeStmt();
|
|
|
|
VarDecl *RangeDecl = dyn_cast_or_null<VarDecl>(RangeStmt->getSingleDecl());
|
|
|
|
assert(RangeDecl && "for-range should have a single var decl");
|
|
|
|
return RangeDecl->getInit();
|
|
|
|
}
|
|
|
|
|
|
|
|
const Expr *CXXForRangeStmt::getRangeInit() const {
|
|
|
|
return const_cast<CXXForRangeStmt *>(this)->getRangeInit();
|
|
|
|
}
|
|
|
|
|
|
|
|
VarDecl *CXXForRangeStmt::getLoopVariable() {
|
|
|
|
Decl *LV = cast<DeclStmt>(getLoopVarStmt())->getSingleDecl();
|
|
|
|
assert(LV && "No loop variable in CXXForRangeStmt");
|
|
|
|
return cast<VarDecl>(LV);
|
|
|
|
}
|
|
|
|
|
|
|
|
const VarDecl *CXXForRangeStmt::getLoopVariable() const {
|
|
|
|
return const_cast<CXXForRangeStmt *>(this)->getLoopVariable();
|
|
|
|
}
|
2017-02-13 13:05:02 +08:00
|
|
|
|
|
|
|
CoroutineBodyStmt *CoroutineBodyStmt::Create(
|
2017-05-23 04:22:23 +08:00
|
|
|
const ASTContext &C, CoroutineBodyStmt::CtorArgs const &Args) {
|
2017-02-13 13:05:02 +08:00
|
|
|
std::size_t Size = totalSizeToAlloc<Stmt *>(
|
|
|
|
CoroutineBodyStmt::FirstParamMove + Args.ParamMoves.size());
|
|
|
|
|
|
|
|
void *Mem = C.Allocate(Size, alignof(CoroutineBodyStmt));
|
|
|
|
return new (Mem) CoroutineBodyStmt(Args);
|
|
|
|
}
|
|
|
|
|
2017-07-26 02:01:49 +08:00
|
|
|
CoroutineBodyStmt *CoroutineBodyStmt::Create(const ASTContext &C, EmptyShell,
|
|
|
|
unsigned NumParams) {
|
|
|
|
std::size_t Size = totalSizeToAlloc<Stmt *>(
|
|
|
|
CoroutineBodyStmt::FirstParamMove + NumParams);
|
|
|
|
|
|
|
|
void *Mem = C.Allocate(Size, alignof(CoroutineBodyStmt));
|
|
|
|
auto *Result = new (Mem) CoroutineBodyStmt(CtorArgs());
|
|
|
|
Result->NumParams = NumParams;
|
|
|
|
auto *ParamBegin = Result->getStoredStmts() + SubStmt::FirstParamMove;
|
|
|
|
std::uninitialized_fill(ParamBegin, ParamBegin + NumParams,
|
|
|
|
static_cast<Stmt *>(nullptr));
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2017-02-13 13:05:02 +08:00
|
|
|
CoroutineBodyStmt::CoroutineBodyStmt(CoroutineBodyStmt::CtorArgs const &Args)
|
|
|
|
: Stmt(CoroutineBodyStmtClass), NumParams(Args.ParamMoves.size()) {
|
|
|
|
Stmt **SubStmts = getStoredStmts();
|
|
|
|
SubStmts[CoroutineBodyStmt::Body] = Args.Body;
|
|
|
|
SubStmts[CoroutineBodyStmt::Promise] = Args.Promise;
|
|
|
|
SubStmts[CoroutineBodyStmt::InitSuspend] = Args.InitialSuspend;
|
|
|
|
SubStmts[CoroutineBodyStmt::FinalSuspend] = Args.FinalSuspend;
|
|
|
|
SubStmts[CoroutineBodyStmt::OnException] = Args.OnException;
|
|
|
|
SubStmts[CoroutineBodyStmt::OnFallthrough] = Args.OnFallthrough;
|
|
|
|
SubStmts[CoroutineBodyStmt::Allocate] = Args.Allocate;
|
|
|
|
SubStmts[CoroutineBodyStmt::Deallocate] = Args.Deallocate;
|
|
|
|
SubStmts[CoroutineBodyStmt::ReturnValue] = Args.ReturnValue;
|
2017-05-23 04:22:23 +08:00
|
|
|
SubStmts[CoroutineBodyStmt::ResultDecl] = Args.ResultDecl;
|
|
|
|
SubStmts[CoroutineBodyStmt::ReturnStmt] = Args.ReturnStmt;
|
2017-03-28 07:36:59 +08:00
|
|
|
SubStmts[CoroutineBodyStmt::ReturnStmtOnAllocFailure] =
|
|
|
|
Args.ReturnStmtOnAllocFailure;
|
2017-02-13 13:05:02 +08:00
|
|
|
std::copy(Args.ParamMoves.begin(), Args.ParamMoves.end(),
|
|
|
|
const_cast<Stmt **>(getParamMoves().data()));
|
2017-04-04 03:21:00 +08:00
|
|
|
}
|