Coverage Report

Created: 2018-09-25 23:22

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