Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/lib/AST/StmtCXX.cpp
Line
Count
Source
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
1.95k
QualType CXXCatchStmt::getCaughtType() const {
20
1.95k
  if (ExceptionDecl)
21
1.94k
    return ExceptionDecl->getType();
22
9
  return QualType();
23
9
}
24
25
CXXTryStmt *CXXTryStmt::Create(const ASTContext &C, SourceLocation tryLoc,
26
11.6k
                               Stmt *tryBlock, ArrayRef<Stmt *> handlers) {
27
11.6k
  const size_t Size = totalSizeToAlloc<Stmt *>(handlers.size() + 1);
28
11.6k
  void *Mem = C.Allocate(Size, alignof(CXXTryStmt));
29
11.6k
  return new (Mem) CXXTryStmt(tryLoc, tryBlock, handlers);
30
11.6k
}
31
32
CXXTryStmt *CXXTryStmt::Create(const ASTContext &C, EmptyShell Empty,
33
4
                               unsigned numHandlers) {
34
4
  const size_t Size = totalSizeToAlloc<Stmt *>(numHandlers + 1);
35
4
  void *Mem = C.Allocate(Size, alignof(CXXTryStmt));
36
4
  return new (Mem) CXXTryStmt(Empty, numHandlers);
37
4
}
38
39
CXXTryStmt::CXXTryStmt(SourceLocation tryLoc, Stmt *tryBlock,
40
                       ArrayRef<Stmt *> handlers)
41
11.6k
    : Stmt(CXXTryStmtClass), TryLoc(tryLoc), NumHandlers(handlers.size()) {
42
11.6k
  Stmt **Stmts = getStmts();
43
11.6k
  Stmts[0] = tryBlock;
44
11.6k
  std::copy(handlers.begin(), handlers.end(), Stmts + 1);
45
11.6k
}
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
2.84k
      RParenLoc(RPL) {
55
2.84k
  SubExprs[INIT] = Init;
56
2.84k
  SubExprs[RANGE] = Range;
57
2.84k
  SubExprs[BEGINSTMT] = BeginStmt;
58
2.84k
  SubExprs[ENDSTMT] = EndStmt;
59
2.84k
  SubExprs[COND] = Cond;
60
2.84k
  SubExprs[INC] = Inc;
61
2.84k
  SubExprs[LOOPVAR] = LoopVar;
62
2.84k
  SubExprs[BODY] = Body;
63
2.84k
}
64
65
143
Expr *CXXForRangeStmt::getRangeInit() {
66
143
  DeclStmt *RangeStmt = getRangeStmt();
67
143
  VarDecl *RangeDecl = dyn_cast_or_null<VarDecl>(RangeStmt->getSingleDecl());
68
143
  assert(RangeDecl && "for-range should have a single var decl");
69
143
  return RangeDecl->getInit();
70
143
}
71
72
98
const Expr *CXXForRangeStmt::getRangeInit() const {
73
98
  return const_cast<CXXForRangeStmt *>(this)->getRangeInit();
74
98
}
75
76
156
VarDecl *CXXForRangeStmt::getLoopVariable() {
77
156
  Decl *LV = cast<DeclStmt>(getLoopVarStmt())->getSingleDecl();
78
156
  assert(LV && "No loop variable in CXXForRangeStmt");
79
156
  return cast<VarDecl>(LV);
80
156
}
81
82
154
const VarDecl *CXXForRangeStmt::getLoopVariable() const {
83
154
  return const_cast<CXXForRangeStmt *>(this)->getLoopVariable();
84
154
}
85
86
CoroutineBodyStmt *CoroutineBodyStmt::Create(
87
217
    const ASTContext &C, CoroutineBodyStmt::CtorArgs const &Args) {
88
217
  std::size_t Size = totalSizeToAlloc<Stmt *>(
89
217
      CoroutineBodyStmt::FirstParamMove + Args.ParamMoves.size());
90
217
91
217
  void *Mem = C.Allocate(Size, alignof(CoroutineBodyStmt));
92
217
  return new (Mem) CoroutineBodyStmt(Args);
93
217
}
94
95
CoroutineBodyStmt *CoroutineBodyStmt::Create(const ASTContext &C, EmptyShell,
96
2
                                             unsigned NumParams) {
97
2
  std::size_t Size = totalSizeToAlloc<Stmt *>(
98
2
      CoroutineBodyStmt::FirstParamMove + NumParams);
99
2
100
2
  void *Mem = C.Allocate(Size, alignof(CoroutineBodyStmt));
101
2
  auto *Result = new (Mem) CoroutineBodyStmt(CtorArgs());
102
2
  Result->NumParams = NumParams;
103
2
  auto *ParamBegin = Result->getStoredStmts() + SubStmt::FirstParamMove;
104
2
  std::uninitialized_fill(ParamBegin, ParamBegin + NumParams,
105
2
                          static_cast<Stmt *>(nullptr));
106
2
  return Result;
107
2
}
108
109
CoroutineBodyStmt::CoroutineBodyStmt(CoroutineBodyStmt::CtorArgs const &Args)
110
219
    : Stmt(CoroutineBodyStmtClass), NumParams(Args.ParamMoves.size()) {
111
219
  Stmt **SubStmts = getStoredStmts();
112
219
  SubStmts[CoroutineBodyStmt::Body] = Args.Body;
113
219
  SubStmts[CoroutineBodyStmt::Promise] = Args.Promise;
114
219
  SubStmts[CoroutineBodyStmt::InitSuspend] = Args.InitialSuspend;
115
219
  SubStmts[CoroutineBodyStmt::FinalSuspend] = Args.FinalSuspend;
116
219
  SubStmts[CoroutineBodyStmt::OnException] = Args.OnException;
117
219
  SubStmts[CoroutineBodyStmt::OnFallthrough] = Args.OnFallthrough;
118
219
  SubStmts[CoroutineBodyStmt::Allocate] = Args.Allocate;
119
219
  SubStmts[CoroutineBodyStmt::Deallocate] = Args.Deallocate;
120
219
  SubStmts[CoroutineBodyStmt::ReturnValue] = Args.ReturnValue;
121
219
  SubStmts[CoroutineBodyStmt::ResultDecl] = Args.ResultDecl;
122
219
  SubStmts[CoroutineBodyStmt::ReturnStmt] = Args.ReturnStmt;
123
219
  SubStmts[CoroutineBodyStmt::ReturnStmtOnAllocFailure] =
124
219
      Args.ReturnStmtOnAllocFailure;
125
219
  std::copy(Args.ParamMoves.begin(), Args.ParamMoves.end(),
126
219
            const_cast<Stmt **>(getParamMoves().data()));
127
219
}