Coverage Report

Created: 2019-03-22 08:08

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/AST/StmtObjC.h
Line
Count
Source (jump to first uncovered line)
1
//===--- StmtObjC.h - Classes for representing ObjC statements --*- 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
9
/// \file
10
/// Defines the Objective-C statement AST node classes.
11
12
#ifndef LLVM_CLANG_AST_STMTOBJC_H
13
#define LLVM_CLANG_AST_STMTOBJC_H
14
15
#include "clang/AST/Stmt.h"
16
#include "llvm/Support/Compiler.h"
17
18
namespace clang {
19
20
/// Represents Objective-C's collection statement.
21
///
22
/// This is represented as 'for (element 'in' collection-expression)' stmt.
23
class ObjCForCollectionStmt : public Stmt {
24
  enum { ELEM, COLLECTION, BODY, END_EXPR };
25
  Stmt* SubExprs[END_EXPR]; // SubExprs[ELEM] is an expression or declstmt.
26
  SourceLocation ForLoc;
27
  SourceLocation RParenLoc;
28
public:
29
  ObjCForCollectionStmt(Stmt *Elem, Expr *Collect, Stmt *Body,
30
                        SourceLocation FCL, SourceLocation RPL);
31
  explicit ObjCForCollectionStmt(EmptyShell Empty) :
32
0
    Stmt(ObjCForCollectionStmtClass, Empty) { }
33
34
439
  Stmt *getElement() { return SubExprs[ELEM]; }
35
289
  Expr *getCollection() {
36
289
    return reinterpret_cast<Expr*>(SubExprs[COLLECTION]);
37
289
  }
38
200
  Stmt *getBody() { return SubExprs[BODY]; }
39
40
555
  const Stmt *getElement() const { return SubExprs[ELEM]; }
41
1.06k
  const Expr *getCollection() const {
42
1.06k
    return reinterpret_cast<Expr*>(SubExprs[COLLECTION]);
43
1.06k
  }
44
171
  const Stmt *getBody() const { return SubExprs[BODY]; }
45
46
0
  void setElement(Stmt *S) { SubExprs[ELEM] = S; }
47
0
  void setCollection(Expr *E) {
48
0
    SubExprs[COLLECTION] = reinterpret_cast<Stmt*>(E);
49
0
  }
50
246
  void setBody(Stmt *S) { SubExprs[BODY] = S; }
51
52
19
  SourceLocation getForLoc() const { return ForLoc; }
53
0
  void setForLoc(SourceLocation Loc) { ForLoc = Loc; }
54
38
  SourceLocation getRParenLoc() const { return RParenLoc; }
55
0
  void setRParenLoc(SourceLocation Loc) { RParenLoc = Loc; }
56
57
1.46k
  SourceLocation getBeginLoc() const LLVM_READONLY { return ForLoc; }
58
285
  SourceLocation getEndLoc() const LLVM_READONLY {
59
285
    return SubExprs[BODY]->getEndLoc();
60
285
  }
61
62
65.6k
  static bool classof(const Stmt *T) {
63
65.6k
    return T->getStmtClass() == ObjCForCollectionStmtClass;
64
65.6k
  }
65
66
  // Iterators
67
684
  child_range children() {
68
684
    return child_range(&SubExprs[0], &SubExprs[END_EXPR]);
69
684
  }
70
};
71
72
/// Represents Objective-C's \@catch statement.
73
class ObjCAtCatchStmt : public Stmt {
74
private:
75
  VarDecl *ExceptionDecl;
76
  Stmt *Body;
77
  SourceLocation AtCatchLoc, RParenLoc;
78
79
public:
80
  ObjCAtCatchStmt(SourceLocation atCatchLoc, SourceLocation rparenloc,
81
                  VarDecl *catchVarDecl,
82
                  Stmt *atCatchStmt)
83
    : Stmt(ObjCAtCatchStmtClass), ExceptionDecl(catchVarDecl),
84
281
    Body(atCatchStmt), AtCatchLoc(atCatchLoc), RParenLoc(rparenloc) { }
85
86
  explicit ObjCAtCatchStmt(EmptyShell Empty) :
87
6
    Stmt(ObjCAtCatchStmtClass, Empty) { }
88
89
208
  const Stmt *getCatchBody() const { return Body; }
90
42
  Stmt *getCatchBody() { return Body; }
91
6
  void setCatchBody(Stmt *S) { Body = S; }
92
93
228
  const VarDecl *getCatchParamDecl() const {
94
228
    return ExceptionDecl;
95
228
  }
96
42
  VarDecl *getCatchParamDecl() {
97
42
    return ExceptionDecl;
98
42
  }
99
6
  void setCatchParamDecl(VarDecl *D) { ExceptionDecl = D; }
100
101
22
  SourceLocation getAtCatchLoc() const { return AtCatchLoc; }
102
6
  void setAtCatchLoc(SourceLocation Loc) { AtCatchLoc = Loc; }
103
21
  SourceLocation getRParenLoc() const { return RParenLoc; }
104
6
  void setRParenLoc(SourceLocation Loc) { RParenLoc = Loc; }
105
106
47
  SourceLocation getBeginLoc() const LLVM_READONLY { return AtCatchLoc; }
107
35
  SourceLocation getEndLoc() const LLVM_READONLY { return Body->getEndLoc(); }
108
109
6
  bool hasEllipsis() const { return getCatchParamDecl() == nullptr; }
110
111
  static bool classof(const Stmt *T) {
112
    return T->getStmtClass() == ObjCAtCatchStmtClass;
113
  }
114
115
49
  child_range children() { return child_range(&Body, &Body + 1); }
116
};
117
118
/// Represents Objective-C's \@finally statement
119
class ObjCAtFinallyStmt : public Stmt {
120
  SourceLocation AtFinallyLoc;
121
  Stmt *AtFinallyStmt;
122
123
public:
124
  ObjCAtFinallyStmt(SourceLocation atFinallyLoc, Stmt *atFinallyStmt)
125
      : Stmt(ObjCAtFinallyStmtClass), AtFinallyLoc(atFinallyLoc),
126
70
        AtFinallyStmt(atFinallyStmt) {}
127
128
  explicit ObjCAtFinallyStmt(EmptyShell Empty) :
129
2
    Stmt(ObjCAtFinallyStmtClass, Empty) { }
130
131
22
  const Stmt *getFinallyBody() const { return AtFinallyStmt; }
132
22
  Stmt *getFinallyBody() { return AtFinallyStmt; }
133
2
  void setFinallyBody(Stmt *S) { AtFinallyStmt = S; }
134
135
39
  SourceLocation getBeginLoc() const LLVM_READONLY { return AtFinallyLoc; }
136
39
  SourceLocation getEndLoc() const LLVM_READONLY {
137
39
    return AtFinallyStmt->getEndLoc();
138
39
  }
139
140
10
  SourceLocation getAtFinallyLoc() const { return AtFinallyLoc; }
141
2
  void setAtFinallyLoc(SourceLocation Loc) { AtFinallyLoc = Loc; }
142
143
272
  static bool classof(const Stmt *T) {
144
272
    return T->getStmtClass() == ObjCAtFinallyStmtClass;
145
272
  }
146
147
68
  child_range children() {
148
68
    return child_range(&AtFinallyStmt, &AtFinallyStmt+1);
149
68
  }
150
};
151
152
/// Represents Objective-C's \@try ... \@catch ... \@finally statement.
153
class ObjCAtTryStmt : public Stmt {
154
private:
155
  // The location of the @ in the \@try.
156
  SourceLocation AtTryLoc;
157
158
  // The number of catch blocks in this statement.
159
  unsigned NumCatchStmts : 16;
160
161
  // Whether this statement has a \@finally statement.
162
  bool HasFinally : 1;
163
164
  /// Retrieve the statements that are stored after this \@try statement.
165
  ///
166
  /// The order of the statements in memory follows the order in the source,
167
  /// with the \@try body first, followed by the \@catch statements (if any)
168
  /// and, finally, the \@finally (if it exists).
169
558
  Stmt **getStmts() { return reinterpret_cast<Stmt **> (this + 1); }
170
449
  const Stmt* const *getStmts() const {
171
449
    return reinterpret_cast<const Stmt * const*> (this + 1);
172
449
  }
173
174
  ObjCAtTryStmt(SourceLocation atTryLoc, Stmt *atTryStmt,
175
                Stmt **CatchStmts, unsigned NumCatchStmts,
176
                Stmt *atFinallyStmt);
177
178
  explicit ObjCAtTryStmt(EmptyShell Empty, unsigned NumCatchStmts,
179
                         bool HasFinally)
180
    : Stmt(ObjCAtTryStmtClass, Empty), NumCatchStmts(NumCatchStmts),
181
2
      HasFinally(HasFinally) { }
182
183
public:
184
  static ObjCAtTryStmt *Create(const ASTContext &Context,
185
                               SourceLocation atTryLoc, Stmt *atTryStmt,
186
                               Stmt **CatchStmts, unsigned NumCatchStmts,
187
                               Stmt *atFinallyStmt);
188
  static ObjCAtTryStmt *CreateEmpty(const ASTContext &Context,
189
                                    unsigned NumCatchStmts, bool HasFinally);
190
191
  /// Retrieve the location of the @ in the \@try.
192
29
  SourceLocation getAtTryLoc() const { return AtTryLoc; }
193
2
  void setAtTryLoc(SourceLocation Loc) { AtTryLoc = Loc; }
194
195
  /// Retrieve the \@try body.
196
170
  const Stmt *getTryBody() const { return getStmts()[0]; }
197
46
  Stmt *getTryBody() { return getStmts()[0]; }
198
2
  void setTryBody(Stmt *S) { getStmts()[0] = S; }
199
200
  /// Retrieve the number of \@catch statements in this try-catch-finally
201
  /// block.
202
681
  unsigned getNumCatchStmts() const { return NumCatchStmts; }
203
204
  /// Retrieve a \@catch statement.
205
219
  const ObjCAtCatchStmt *getCatchStmt(unsigned I) const {
206
219
    assert(I < NumCatchStmts && "Out-of-bounds @catch index");
207
219
    return cast_or_null<ObjCAtCatchStmt>(getStmts()[I + 1]);
208
219
  }
209
210
  /// Retrieve a \@catch statement.
211
48
  ObjCAtCatchStmt *getCatchStmt(unsigned I) {
212
48
    assert(I < NumCatchStmts && "Out-of-bounds @catch index");
213
48
    return cast_or_null<ObjCAtCatchStmt>(getStmts()[I + 1]);
214
48
  }
215
216
  /// Set a particular catch statement.
217
6
  void setCatchStmt(unsigned I, ObjCAtCatchStmt *S) {
218
6
    assert(I < NumCatchStmts && "Out-of-bounds @catch index");
219
6
    getStmts()[I + 1] = S;
220
6
  }
221
222
  /// Retrieve the \@finally statement, if any.
223
358
  const ObjCAtFinallyStmt *getFinallyStmt() const {
224
358
    if (!HasFinally)
225
298
      return nullptr;
226
60
227
60
    return cast_or_null<ObjCAtFinallyStmt>(getStmts()[1 + NumCatchStmts]);
228
60
  }
229
47
  ObjCAtFinallyStmt *getFinallyStmt() {
230
47
    if (!HasFinally)
231
19
      return nullptr;
232
28
233
28
    return cast_or_null<ObjCAtFinallyStmt>(getStmts()[1 + NumCatchStmts]);
234
28
  }
235
2
  void setFinallyStmt(Stmt *S) {
236
2
    assert(HasFinally && "@try does not have a @finally slot!");
237
2
    getStmts()[1 + NumCatchStmts] = S;
238
2
  }
239
240
58
  SourceLocation getBeginLoc() const LLVM_READONLY { return AtTryLoc; }
241
  SourceLocation getEndLoc() const LLVM_READONLY;
242
243
36.1k
  static bool classof(const Stmt *T) {
244
36.1k
    return T->getStmtClass() == ObjCAtTryStmtClass;
245
36.1k
  }
246
247
89
  child_range children() {
248
89
    return child_range(getStmts(),
249
89
                       getStmts() + 1 + NumCatchStmts + HasFinally);
250
89
  }
251
};
252
253
/// Represents Objective-C's \@synchronized statement.
254
///
255
/// Example:
256
/// \code
257
///   @synchronized (sem) {
258
///     do-something;
259
///   }
260
/// \endcode
261
class ObjCAtSynchronizedStmt : public Stmt {
262
private:
263
  SourceLocation AtSynchronizedLoc;
264
  enum { SYNC_EXPR, SYNC_BODY, END_EXPR };
265
  Stmt* SubStmts[END_EXPR];
266
267
public:
268
  ObjCAtSynchronizedStmt(SourceLocation atSynchronizedLoc, Stmt *synchExpr,
269
                         Stmt *synchBody)
270
49
  : Stmt(ObjCAtSynchronizedStmtClass) {
271
49
    SubStmts[SYNC_EXPR] = synchExpr;
272
49
    SubStmts[SYNC_BODY] = synchBody;
273
49
    AtSynchronizedLoc = atSynchronizedLoc;
274
49
  }
275
  explicit ObjCAtSynchronizedStmt(EmptyShell Empty) :
276
0
    Stmt(ObjCAtSynchronizedStmtClass, Empty) { }
277
278
8
  SourceLocation getAtSynchronizedLoc() const { return AtSynchronizedLoc; }
279
0
  void setAtSynchronizedLoc(SourceLocation Loc) { AtSynchronizedLoc = Loc; }
280
281
66
  const CompoundStmt *getSynchBody() const {
282
66
    return reinterpret_cast<CompoundStmt*>(SubStmts[SYNC_BODY]);
283
66
  }
284
66
  CompoundStmt *getSynchBody() {
285
66
    return reinterpret_cast<CompoundStmt*>(SubStmts[SYNC_BODY]);
286
66
  }
287
0
  void setSynchBody(Stmt *S) { SubStmts[SYNC_BODY] = S; }
288
289
28
  const Expr *getSynchExpr() const {
290
28
    return reinterpret_cast<Expr*>(SubStmts[SYNC_EXPR]);
291
28
  }
292
47
  Expr *getSynchExpr() {
293
47
    return reinterpret_cast<Expr*>(SubStmts[SYNC_EXPR]);
294
47
  }
295
0
  void setSynchExpr(Stmt *S) { SubStmts[SYNC_EXPR] = S; }
296
297
151
  SourceLocation getBeginLoc() const LLVM_READONLY { return AtSynchronizedLoc; }
298
52
  SourceLocation getEndLoc() const LLVM_READONLY {
299
52
    return getSynchBody()->getEndLoc();
300
52
  }
301
302
4.31k
  static bool classof(const Stmt *T) {
303
4.31k
    return T->getStmtClass() == ObjCAtSynchronizedStmtClass;
304
4.31k
  }
305
306
152
  child_range children() {
307
152
    return child_range(&SubStmts[0], &SubStmts[0]+END_EXPR);
308
152
  }
309
};
310
311
/// Represents Objective-C's \@throw statement.
312
class ObjCAtThrowStmt : public Stmt {
313
  SourceLocation AtThrowLoc;
314
  Stmt *Throw;
315
316
public:
317
  ObjCAtThrowStmt(SourceLocation atThrowLoc, Stmt *throwExpr)
318
68
  : Stmt(ObjCAtThrowStmtClass), Throw(throwExpr) {
319
68
    AtThrowLoc = atThrowLoc;
320
68
  }
321
  explicit ObjCAtThrowStmt(EmptyShell Empty) :
322
0
    Stmt(ObjCAtThrowStmtClass, Empty) { }
323
324
32
  const Expr *getThrowExpr() const { return reinterpret_cast<Expr*>(Throw); }
325
25
  Expr *getThrowExpr() { return reinterpret_cast<Expr*>(Throw); }
326
0
  void setThrowExpr(Stmt *S) { Throw = S; }
327
328
6
  SourceLocation getThrowLoc() const LLVM_READONLY { return AtThrowLoc; }
329
0
  void setThrowLoc(SourceLocation Loc) { AtThrowLoc = Loc; }
330
331
25
  SourceLocation getBeginLoc() const LLVM_READONLY { return AtThrowLoc; }
332
16
  SourceLocation getEndLoc() const LLVM_READONLY {
333
16
    return Throw ? 
Throw->getEndLoc()10
:
AtThrowLoc6
;
334
16
  }
335
336
4.50k
  static bool classof(const Stmt *T) {
337
4.50k
    return T->getStmtClass() == ObjCAtThrowStmtClass;
338
4.50k
  }
339
340
36
  child_range children() { return child_range(&Throw, &Throw+1); }
341
};
342
343
/// Represents Objective-C's \@autoreleasepool Statement
344
class ObjCAutoreleasePoolStmt : public Stmt {
345
  SourceLocation AtLoc;
346
  Stmt *SubStmt;
347
348
public:
349
  ObjCAutoreleasePoolStmt(SourceLocation atLoc, Stmt *subStmt)
350
90
      : Stmt(ObjCAutoreleasePoolStmtClass), AtLoc(atLoc), SubStmt(subStmt) {}
351
352
  explicit ObjCAutoreleasePoolStmt(EmptyShell Empty) :
353
0
    Stmt(ObjCAutoreleasePoolStmtClass, Empty) { }
354
355
23
  const Stmt *getSubStmt() const { return SubStmt; }
356
115
  Stmt *getSubStmt() { return SubStmt; }
357
0
  void setSubStmt(Stmt *S) { SubStmt = S; }
358
359
14
  SourceLocation getBeginLoc() const LLVM_READONLY { return AtLoc; }
360
11
  SourceLocation getEndLoc() const LLVM_READONLY {
361
11
    return SubStmt->getEndLoc();
362
11
  }
363
364
5
  SourceLocation getAtLoc() const { return AtLoc; }
365
0
  void setAtLoc(SourceLocation Loc) { AtLoc = Loc; }
366
367
2.38k
  static bool classof(const Stmt *T) {
368
2.38k
    return T->getStmtClass() == ObjCAutoreleasePoolStmtClass;
369
2.38k
  }
370
371
138
  child_range children() { return child_range(&SubStmt, &SubStmt + 1); }
372
};
373
374
}  // end namespace clang
375
376
#endif