/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/AST/StmtCXX.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===--- StmtCXX.cpp - Classes for representing C++ statements ------------===// |
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 | | // |
9 | | // This file implements the subclesses of Stmt class declared in StmtCXX.h |
10 | | // |
11 | | //===----------------------------------------------------------------------===// |
12 | | |
13 | | #include "clang/AST/StmtCXX.h" |
14 | | |
15 | | #include "clang/AST/ASTContext.h" |
16 | | |
17 | | using namespace clang; |
18 | | |
19 | 2.47k | QualType CXXCatchStmt::getCaughtType() const { |
20 | 2.47k | if (ExceptionDecl) |
21 | 1.64k | return ExceptionDecl->getType(); |
22 | 833 | return QualType(); |
23 | 2.47k | } |
24 | | |
25 | | CXXTryStmt *CXXTryStmt::Create(const ASTContext &C, SourceLocation tryLoc, |
26 | 15.2k | Stmt *tryBlock, ArrayRef<Stmt *> handlers) { |
27 | 15.2k | const size_t Size = totalSizeToAlloc<Stmt *>(handlers.size() + 1); |
28 | 15.2k | void *Mem = C.Allocate(Size, alignof(CXXTryStmt)); |
29 | 15.2k | return new (Mem) CXXTryStmt(tryLoc, tryBlock, handlers); |
30 | 15.2k | } |
31 | | |
32 | | CXXTryStmt *CXXTryStmt::Create(const ASTContext &C, EmptyShell Empty, |
33 | 22 | unsigned numHandlers) { |
34 | 22 | const size_t Size = totalSizeToAlloc<Stmt *>(numHandlers + 1); |
35 | 22 | void *Mem = C.Allocate(Size, alignof(CXXTryStmt)); |
36 | 22 | return new (Mem) CXXTryStmt(Empty, numHandlers); |
37 | 22 | } |
38 | | |
39 | | CXXTryStmt::CXXTryStmt(SourceLocation tryLoc, Stmt *tryBlock, |
40 | | ArrayRef<Stmt *> handlers) |
41 | 15.2k | : Stmt(CXXTryStmtClass), TryLoc(tryLoc), NumHandlers(handlers.size()) { |
42 | 15.2k | Stmt **Stmts = getStmts(); |
43 | 15.2k | Stmts[0] = tryBlock; |
44 | 15.2k | std::copy(handlers.begin(), handlers.end(), Stmts + 1); |
45 | 15.2k | } |
46 | | |
47 | | CXXForRangeStmt::CXXForRangeStmt(Stmt *Init, DeclStmt *Range, |
48 | | DeclStmt *BeginStmt, DeclStmt *EndStmt, |
49 | | Expr *Cond, Expr *Inc, DeclStmt *LoopVar, |
50 | | Stmt *Body, SourceLocation FL, |
51 | | SourceLocation CAL, SourceLocation CL, |
52 | | SourceLocation RPL) |
53 | | : Stmt(CXXForRangeStmtClass), ForLoc(FL), CoawaitLoc(CAL), ColonLoc(CL), |
54 | 1.78k | RParenLoc(RPL) { |
55 | 1.78k | SubExprs[INIT] = Init; |
56 | 1.78k | SubExprs[RANGE] = Range; |
57 | 1.78k | SubExprs[BEGINSTMT] = BeginStmt; |
58 | 1.78k | SubExprs[ENDSTMT] = EndStmt; |
59 | 1.78k | SubExprs[COND] = Cond; |
60 | 1.78k | SubExprs[INC] = Inc; |
61 | 1.78k | SubExprs[LOOPVAR] = LoopVar; |
62 | 1.78k | SubExprs[BODY] = Body; |
63 | 1.78k | } |
64 | | |
65 | 636 | Expr *CXXForRangeStmt::getRangeInit() { |
66 | 636 | DeclStmt *RangeStmt = getRangeStmt(); |
67 | 636 | VarDecl *RangeDecl = dyn_cast_or_null<VarDecl>(RangeStmt->getSingleDecl()); |
68 | 636 | assert(RangeDecl && "for-range should have a single var decl"); |
69 | 0 | return RangeDecl->getInit(); |
70 | 636 | } |
71 | | |
72 | 334 | const Expr *CXXForRangeStmt::getRangeInit() const { |
73 | 334 | return const_cast<CXXForRangeStmt *>(this)->getRangeInit(); |
74 | 334 | } |
75 | | |
76 | 690 | VarDecl *CXXForRangeStmt::getLoopVariable() { |
77 | 690 | Decl *LV = cast<DeclStmt>(getLoopVarStmt())->getSingleDecl(); |
78 | 690 | assert(LV && "No loop variable in CXXForRangeStmt"); |
79 | 0 | return cast<VarDecl>(LV); |
80 | 690 | } |
81 | | |
82 | 498 | const VarDecl *CXXForRangeStmt::getLoopVariable() const { |
83 | 498 | return const_cast<CXXForRangeStmt *>(this)->getLoopVariable(); |
84 | 498 | } |
85 | | |
86 | | CoroutineBodyStmt *CoroutineBodyStmt::Create( |
87 | 945 | const ASTContext &C, CoroutineBodyStmt::CtorArgs const &Args) { |
88 | 945 | std::size_t Size = totalSizeToAlloc<Stmt *>( |
89 | 945 | CoroutineBodyStmt::FirstParamMove + Args.ParamMoves.size()); |
90 | | |
91 | 945 | void *Mem = C.Allocate(Size, alignof(CoroutineBodyStmt)); |
92 | 945 | return new (Mem) CoroutineBodyStmt(Args); |
93 | 945 | } |
94 | | |
95 | | CoroutineBodyStmt *CoroutineBodyStmt::Create(const ASTContext &C, EmptyShell, |
96 | 4 | unsigned NumParams) { |
97 | 4 | std::size_t Size = totalSizeToAlloc<Stmt *>( |
98 | 4 | CoroutineBodyStmt::FirstParamMove + NumParams); |
99 | | |
100 | 4 | void *Mem = C.Allocate(Size, alignof(CoroutineBodyStmt)); |
101 | 4 | auto *Result = new (Mem) CoroutineBodyStmt(CtorArgs()); |
102 | 4 | Result->NumParams = NumParams; |
103 | 4 | auto *ParamBegin = Result->getStoredStmts() + SubStmt::FirstParamMove; |
104 | 4 | std::uninitialized_fill(ParamBegin, ParamBegin + NumParams, |
105 | 4 | static_cast<Stmt *>(nullptr)); |
106 | 4 | return Result; |
107 | 4 | } |
108 | | |
109 | | CoroutineBodyStmt::CoroutineBodyStmt(CoroutineBodyStmt::CtorArgs const &Args) |
110 | 949 | : Stmt(CoroutineBodyStmtClass), NumParams(Args.ParamMoves.size()) { |
111 | 949 | Stmt **SubStmts = getStoredStmts(); |
112 | 949 | SubStmts[CoroutineBodyStmt::Body] = Args.Body; |
113 | 949 | SubStmts[CoroutineBodyStmt::Promise] = Args.Promise; |
114 | 949 | SubStmts[CoroutineBodyStmt::InitSuspend] = Args.InitialSuspend; |
115 | 949 | SubStmts[CoroutineBodyStmt::FinalSuspend] = Args.FinalSuspend; |
116 | 949 | SubStmts[CoroutineBodyStmt::OnException] = Args.OnException; |
117 | 949 | SubStmts[CoroutineBodyStmt::OnFallthrough] = Args.OnFallthrough; |
118 | 949 | SubStmts[CoroutineBodyStmt::Allocate] = Args.Allocate; |
119 | 949 | SubStmts[CoroutineBodyStmt::Deallocate] = Args.Deallocate; |
120 | 949 | SubStmts[CoroutineBodyStmt::ReturnValue] = Args.ReturnValue; |
121 | 949 | SubStmts[CoroutineBodyStmt::ReturnStmt] = Args.ReturnStmt; |
122 | 949 | SubStmts[CoroutineBodyStmt::ReturnStmtOnAllocFailure] = |
123 | 949 | Args.ReturnStmtOnAllocFailure; |
124 | 949 | std::copy(Args.ParamMoves.begin(), Args.ParamMoves.end(), |
125 | 949 | const_cast<Stmt **>(getParamMoves().data())); |
126 | 949 | } |