clang 8.0.0

StmtCXX.cpp
Go to the documentation of this file.
1 //===--- StmtCXX.cpp - Classes for representing C++ statements ------------===//
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 //
10 // This file implements the subclesses of Stmt class declared in StmtCXX.h
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "clang/AST/StmtCXX.h"
15
16 #include "clang/AST/ASTContext.h"
17
18 using namespace clang;
19
20 QualType CXXCatchStmt::getCaughtType() const {
21 if (ExceptionDecl)
22 return ExceptionDecl->getType();
23 return QualType();
24 }
25
26 CXXTryStmt *CXXTryStmt::Create(const ASTContext &C, SourceLocation tryLoc,
27 Stmt *tryBlock, ArrayRef<Stmt *> handlers) {
28 const size_t Size = totalSizeToAlloc<Stmt *>(handlers.size() + 1);
29 void *Mem = C.Allocate(Size, alignof(CXXTryStmt));
30 return new (Mem) CXXTryStmt(tryLoc, tryBlock, handlers);
31 }
32
33 CXXTryStmt *CXXTryStmt::Create(const ASTContext &C, EmptyShell Empty,
34 unsigned numHandlers) {
35 const size_t Size = totalSizeToAlloc<Stmt *>(numHandlers + 1);
36 void *Mem = C.Allocate(Size, alignof(CXXTryStmt));
37 return new (Mem) CXXTryStmt(Empty, numHandlers);
38 }
39
40 CXXTryStmt::CXXTryStmt(SourceLocation tryLoc, Stmt *tryBlock,
41 ArrayRef<Stmt *> handlers)
42 : Stmt(CXXTryStmtClass), TryLoc(tryLoc), NumHandlers(handlers.size()) {
43 Stmt **Stmts = getStmts();
44 Stmts[0] = tryBlock;
45 std::copy(handlers.begin(), handlers.end(), Stmts + 1);
46 }
47
48 CXXForRangeStmt::CXXForRangeStmt(Stmt *Init, DeclStmt *Range,
49 DeclStmt *BeginStmt, DeclStmt *EndStmt,
50 Expr *Cond, Expr *Inc, DeclStmt *LoopVar,
51 Stmt *Body, SourceLocation FL,
52 SourceLocation CAL, SourceLocation CL,
53 SourceLocation RPL)
54 : Stmt(CXXForRangeStmtClass), ForLoc(FL), CoawaitLoc(CAL), ColonLoc(CL),
55 RParenLoc(RPL) {
56 SubExprs[INIT] = Init;
57 SubExprs[RANGE] = Range;
58 SubExprs[BEGINSTMT] = BeginStmt;
59 SubExprs[ENDSTMT] = EndStmt;
60 SubExprs[COND] = Cond;
61 SubExprs[INC] = Inc;
62 SubExprs[LOOPVAR] = LoopVar;
63 SubExprs[BODY] = Body;
64 }
65
66 Expr *CXXForRangeStmt::getRangeInit() {
67 DeclStmt *RangeStmt = getRangeStmt();
68 VarDecl *RangeDecl = dyn_cast_or_null<VarDecl>(RangeStmt->getSingleDecl());
69 assert(RangeDecl && "for-range should have a single var decl");
70 return RangeDecl->getInit();
71 }
72
73 const Expr *CXXForRangeStmt::getRangeInit() const {
74 return const_cast<CXXForRangeStmt *>(this)->getRangeInit();
75 }
76
77 VarDecl *CXXForRangeStmt::getLoopVariable() {
78 Decl *LV = cast<DeclStmt>(getLoopVarStmt())->getSingleDecl();
79 assert(LV && "No loop variable in CXXForRangeStmt");
80 return cast<VarDecl>(LV);
81 }
82
83 const VarDecl *CXXForRangeStmt::getLoopVariable() const {
84 return const_cast<CXXForRangeStmt *>(this)->getLoopVariable();
85 }
86
87 CoroutineBodyStmt *CoroutineBodyStmt::Create(
88 const ASTContext &C, CoroutineBodyStmt::CtorArgs const &Args) {
89 std::size_t Size = totalSizeToAlloc<Stmt *>(
90 CoroutineBodyStmt::FirstParamMove + Args.ParamMoves.size());
91
92 void *Mem = C.Allocate(Size, alignof(CoroutineBodyStmt));
93 return new (Mem) CoroutineBodyStmt(Args);
94 }
95
96 CoroutineBodyStmt *CoroutineBodyStmt::Create(const ASTContext &C, EmptyShell,
97 unsigned NumParams) {
98 std::size_t Size = totalSizeToAlloc<Stmt *>(
99 CoroutineBodyStmt::FirstParamMove + NumParams);
100
101 void *Mem = C.Allocate(Size, alignof(CoroutineBodyStmt));
102 auto *Result = new (Mem) CoroutineBodyStmt(CtorArgs());
103 Result->NumParams = NumParams;
104 auto *ParamBegin = Result->getStoredStmts() + SubStmt::FirstParamMove;
105 std::uninitialized_fill(ParamBegin, ParamBegin + NumParams,
106 static_cast<Stmt *>(nullptr));
107 return Result;
108 }
109
110 CoroutineBodyStmt::CoroutineBodyStmt(CoroutineBodyStmt::CtorArgs const &Args)
111 : Stmt(CoroutineBodyStmtClass), NumParams(Args.ParamMoves.size()) {
112 Stmt **SubStmts = getStoredStmts();
113 SubStmts[CoroutineBodyStmt::Body] = Args.Body;
114 SubStmts[CoroutineBodyStmt::Promise] = Args.Promise;
115 SubStmts[CoroutineBodyStmt::InitSuspend] = Args.InitialSuspend;
116 SubStmts[CoroutineBodyStmt::FinalSuspend] = Args.FinalSuspend;
117 SubStmts[CoroutineBodyStmt::OnException] = Args.OnException;
118 SubStmts[CoroutineBodyStmt::OnFallthrough] = Args.OnFallthrough;
119 SubStmts[CoroutineBodyStmt::Allocate] = Args.Allocate;
120 SubStmts[CoroutineBodyStmt::Deallocate] = Args.Deallocate;
121 SubStmts[CoroutineBodyStmt::ReturnValue] = Args.ReturnValue;
122 SubStmts[CoroutineBodyStmt::ResultDecl] = Args.ResultDecl;
123 SubStmts[CoroutineBodyStmt::ReturnStmt] = Args.ReturnStmt;
124 SubStmts[CoroutineBodyStmt::ReturnStmtOnAllocFailure] =
125 Args.ReturnStmtOnAllocFailure;
126 std::copy(Args.ParamMoves.begin(), Args.ParamMoves.end(),
127 const_cast<Stmt **>(getParamMoves().data()));
128 }
ASTContext.h
Defines the clang::ASTContext interface.
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:638
size_t
__SIZE_TYPE__ size_t
The unsigned integer type of the result of the sizeof operator.
Definition: opencl-c.h:68
clang::Stmt
Stmt - This represents one statement.
Definition: Stmt.h:66
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:87
clang::CoroutineBodyStmt::CtorArgs::Allocate
Expr * Allocate
Definition: StmtCXX.h:339
clang::VarDecl
Represents a variable declaration or definition.
Definition: Decl.h:813
clang::CoroutineBodyStmt::CtorArgs::ReturnStmt
Stmt * ReturnStmt
Definition: StmtCXX.h:343
clang::Stmt::Stmt
Stmt(StmtClass SC, EmptyShell)
Construct an empty statement.
Definition: Stmt.h:1017
clang::CoroutineBodyStmt::CtorArgs::Body
Stmt * Body
Definition: StmtCXX.h:333
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:155
clang::CXXCatchStmt::getCaughtType
QualType getCaughtType() const
Definition: StmtCXX.cpp:20
StmtCXX.h
clang::CoroutineBodyStmt::CtorArgs::ReturnStmtOnAllocFailure
Stmt * ReturnStmtOnAllocFailure
Definition: StmtCXX.h:344
clang::CXXForRangeStmt
CXXForRangeStmt - This represents C++0x [stmt.ranged]&#39;s ranged for statement, represented as &#39;for (ra...
Definition: StmtCXX.h:127
llvm::ArrayRef
Definition: LLVM.h:32
clang::CoroutineBodyStmt::CtorArgs::InitialSuspend
Expr * InitialSuspend
Definition: StmtCXX.h:335
clang::Expr
This represents one expression.
Definition: Expr.h:106
clang::CXXTryStmt
CXXTryStmt - A C++ try block, including all handlers.
Definition: StmtCXX.h:65
clang::ObjCSubstitutionContext::Result
The result type of a method or function.
clang::CoroutineBodyStmt::Create
static CoroutineBodyStmt * Create(const ASTContext &C, CtorArgs const &Args)
Definition: StmtCXX.cpp:87
clang::CoroutineBodyStmt::CtorArgs::Promise
Stmt * Promise
Definition: StmtCXX.h:334
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:88
clang::DeclStmt
DeclStmt - Adaptor class for mixing declarations with statements and expressions. ...
Definition: Stmt.h:1143
clang::CoroutineBodyStmt::CtorArgs
Definition: StmtCXX.h:332
clang::CoroutineBodyStmt::CtorArgs::ParamMoves
ArrayRef< Stmt * > ParamMoves
Definition: StmtCXX.h:345
clang::CoroutineBodyStmt::CtorArgs::ReturnValue
Expr * ReturnValue
Definition: StmtCXX.h:341
clang::CoroutineBodyStmt::CtorArgs::FinalSuspend
Expr * FinalSuspend
Definition: StmtCXX.h:336
clang::CXXForRangeStmt::getRangeInit
Expr * getRangeInit()
Definition: StmtCXX.cpp:66
clang::Stmt::EmptyShell
A placeholder type used to construct an empty shell of a type, that will be filled in later (e...
Definition: Stmt.h:976
clang::ASTContext::Allocate
void * Allocate(size_t Size, unsigned Align=8) const
Definition: ASTContext.h:669
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:22
clang::VarDecl::getInit
const Expr * getInit() const
Definition: Decl.h:1220
clang::DeclStmt::getSingleDecl
const Decl * getSingleDecl() const
Definition: Stmt.h:1158
clang::CXXForRangeStmt::CXXForRangeStmt
CXXForRangeStmt(Stmt *InitStmt, DeclStmt *Range, DeclStmt *Begin, DeclStmt *End, Expr *Cond, Expr *Inc, DeclStmt *LoopVar, Stmt *Body, SourceLocation FL, SourceLocation CAL, SourceLocation CL, SourceLocation RPL)
Definition: StmtCXX.cpp:48
clang::CoroutineBodyStmt
Represents the body of a coroutine.
Definition: StmtCXX.h:302
clang::CXXForRangeStmt::getRangeStmt
DeclStmt * getRangeStmt()
Definition: StmtCXX.h:154
clang::CXXTryStmt::Create
static CXXTryStmt * Create(const ASTContext &C, SourceLocation tryLoc, Stmt *tryBlock, ArrayRef< Stmt *> handlers)
Definition: StmtCXX.cpp:26
clang::CXXForRangeStmt::getLoopVariable
VarDecl * getLoopVariable()
Definition: StmtCXX.cpp:77
clang::AttrSyntax::C
clang::CoroutineBodyStmt::CtorArgs::OnFallthrough
Stmt * OnFallthrough
Definition: StmtCXX.h:338
clang::CoroutineBodyStmt::CtorArgs::ResultDecl
Stmt * ResultDecl
Definition: StmtCXX.h:342
clang::CXXForRangeStmt::getLoopVarStmt
DeclStmt * getLoopVarStmt()
Definition: StmtCXX.h:161
clang::ValueDecl::getType
QualType getType() const
Definition: Decl.h:648
clang::CoroutineBodyStmt::CtorArgs::OnException
Stmt * OnException
Definition: StmtCXX.h:337
ColonLoc
SourceLocation ColonLoc
Location of &#39;:&#39;.
Definition: OpenMPClause.h:108
clang::CoroutineBodyStmt::CtorArgs::Deallocate
Expr * Deallocate
Definition: StmtCXX.h:340