Coverage Report

Created: 2018-07-21 08:31

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/AST/Stmt.h
Line
Count
Source (jump to first uncovered line)
1
//===- Stmt.h - Classes for representing 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
//  This file defines the Stmt interface and subclasses.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_CLANG_AST_STMT_H
15
#define LLVM_CLANG_AST_STMT_H
16
17
#include "clang/AST/DeclGroup.h"
18
#include "clang/AST/StmtIterator.h"
19
#include "clang/Basic/CapturedStmt.h"
20
#include "clang/Basic/IdentifierTable.h"
21
#include "clang/Basic/LLVM.h"
22
#include "clang/Basic/SourceLocation.h"
23
#include "llvm/ADT/ArrayRef.h"
24
#include "llvm/ADT/PointerIntPair.h"
25
#include "llvm/ADT/StringRef.h"
26
#include "llvm/ADT/iterator.h"
27
#include "llvm/ADT/iterator_range.h"
28
#include "llvm/Support/Casting.h"
29
#include "llvm/Support/Compiler.h"
30
#include "llvm/Support/ErrorHandling.h"
31
#include <algorithm>
32
#include <cassert>
33
#include <cstddef>
34
#include <iterator>
35
#include <string>
36
37
namespace llvm {
38
39
class FoldingSetNodeID;
40
41
} // namespace llvm
42
43
namespace clang {
44
45
class ASTContext;
46
class Attr;
47
class CapturedDecl;
48
class Decl;
49
class Expr;
50
class LabelDecl;
51
class ODRHash;
52
class PrinterHelper;
53
struct PrintingPolicy;
54
class RecordDecl;
55
class SourceManager;
56
class StringLiteral;
57
class Token;
58
class VarDecl;
59
60
//===----------------------------------------------------------------------===//
61
// AST classes for statements.
62
//===----------------------------------------------------------------------===//
63
64
/// Stmt - This represents one statement.
65
///
66
class alignas(void *) Stmt {
67
public:
68
  enum StmtClass {
69
    NoStmtClass = 0,
70
#define STMT(CLASS, PARENT) CLASS##Class,
71
#define STMT_RANGE(BASE, FIRST, LAST) \
72
        first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class,
73
#define LAST_STMT_RANGE(BASE, FIRST, LAST) \
74
        first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class
75
#define ABSTRACT_STMT(STMT)
76
#include "clang/AST/StmtNodes.inc"
77
  };
78
79
  // Make vanilla 'new' and 'delete' illegal for Stmts.
80
protected:
81
  friend class ASTStmtReader;
82
  friend class ASTStmtWriter;
83
84
0
  void *operator new(size_t bytes) noexcept {
85
0
    llvm_unreachable("Stmts cannot be allocated with regular 'new'.");
86
0
  }
87
88
0
  void operator delete(void *data) noexcept {
89
0
    llvm_unreachable("Stmts cannot be released with regular 'delete'.");
90
0
  }
91
92
  class StmtBitfields {
93
    friend class Stmt;
94
95
    /// The statement class.
96
    unsigned sClass : 8;
97
  };
98
  enum { NumStmtBits = 8 };
99
100
  class CompoundStmtBitfields {
101
    friend class CompoundStmt;
102
103
    unsigned : NumStmtBits;
104
105
    unsigned NumStmts : 32 - NumStmtBits;
106
  };
107
108
  class IfStmtBitfields {
109
    friend class IfStmt;
110
111
    unsigned : NumStmtBits;
112
113
    unsigned IsConstexpr : 1;
114
  };
115
116
  class ExprBitfields {
117
    friend class ASTStmtReader; // deserialization
118
    friend class AtomicExpr; // ctor
119
    friend class BlockDeclRefExpr; // ctor
120
    friend class CallExpr; // ctor
121
    friend class CXXConstructExpr; // ctor
122
    friend class CXXDependentScopeMemberExpr; // ctor
123
    friend class CXXNewExpr; // ctor
124
    friend class CXXUnresolvedConstructExpr; // ctor
125
    friend class DeclRefExpr; // computeDependence
126
    friend class DependentScopeDeclRefExpr; // ctor
127
    friend class DesignatedInitExpr; // ctor
128
    friend class Expr;
129
    friend class InitListExpr; // ctor
130
    friend class ObjCArrayLiteral; // ctor
131
    friend class ObjCDictionaryLiteral; // ctor
132
    friend class ObjCMessageExpr; // ctor
133
    friend class OffsetOfExpr; // ctor
134
    friend class OpaqueValueExpr; // ctor
135
    friend class OverloadExpr; // ctor
136
    friend class ParenListExpr; // ctor
137
    friend class PseudoObjectExpr; // ctor
138
    friend class ShuffleVectorExpr; // ctor
139
140
    unsigned : NumStmtBits;
141
142
    unsigned ValueKind : 2;
143
    unsigned ObjectKind : 3;
144
    unsigned TypeDependent : 1;
145
    unsigned ValueDependent : 1;
146
    unsigned InstantiationDependent : 1;
147
    unsigned ContainsUnexpandedParameterPack : 1;
148
  };
149
  enum { NumExprBits = 17 };
150
151
  class CharacterLiteralBitfields {
152
    friend class CharacterLiteral;
153
154
    unsigned : NumExprBits;
155
156
    unsigned Kind : 3;
157
  };
158
159
  enum APFloatSemantics {
160
    IEEEhalf,
161
    IEEEsingle,
162
    IEEEdouble,
163
    x87DoubleExtended,
164
    IEEEquad,
165
    PPCDoubleDouble
166
  };
167
168
  class FloatingLiteralBitfields {
169
    friend class FloatingLiteral;
170
171
    unsigned : NumExprBits;
172
173
    unsigned Semantics : 3; // Provides semantics for APFloat construction
174
    unsigned IsExact : 1;
175
  };
176
177
  class UnaryExprOrTypeTraitExprBitfields {
178
    friend class UnaryExprOrTypeTraitExpr;
179
180
    unsigned : NumExprBits;
181
182
    unsigned Kind : 2;
183
    unsigned IsType : 1; // true if operand is a type, false if an expression.
184
  };
185
186
  class DeclRefExprBitfields {
187
    friend class ASTStmtReader; // deserialization
188
    friend class DeclRefExpr;
189
190
    unsigned : NumExprBits;
191
192
    unsigned HasQualifier : 1;
193
    unsigned HasTemplateKWAndArgsInfo : 1;
194
    unsigned HasFoundDecl : 1;
195
    unsigned HadMultipleCandidates : 1;
196
    unsigned RefersToEnclosingVariableOrCapture : 1;
197
  };
198
199
  class CastExprBitfields {
200
    friend class CastExpr;
201
202
    unsigned : NumExprBits;
203
204
    unsigned Kind : 6;
205
    unsigned BasePathSize : 32 - 6 - NumExprBits;
206
  };
207
208
  class CallExprBitfields {
209
    friend class CallExpr;
210
211
    unsigned : NumExprBits;
212
213
    unsigned NumPreArgs : 1;
214
  };
215
216
  class ExprWithCleanupsBitfields {
217
    friend class ASTStmtReader; // deserialization
218
    friend class ExprWithCleanups;
219
220
    unsigned : NumExprBits;
221
222
    // When false, it must not have side effects.
223
    unsigned CleanupsHaveSideEffects : 1;
224
225
    unsigned NumObjects : 32 - 1 - NumExprBits;
226
  };
227
228
  class PseudoObjectExprBitfields {
229
    friend class ASTStmtReader; // deserialization
230
    friend class PseudoObjectExpr;
231
232
    unsigned : NumExprBits;
233
234
    // These don't need to be particularly wide, because they're
235
    // strictly limited by the forms of expressions we permit.
236
    unsigned NumSubExprs : 8;
237
    unsigned ResultIndex : 32 - 8 - NumExprBits;
238
  };
239
240
  class OpaqueValueExprBitfields {
241
    friend class OpaqueValueExpr;
242
243
    unsigned : NumExprBits;
244
245
    /// The OVE is a unique semantic reference to its source expressio if this
246
    /// bit is set to true.
247
    unsigned IsUnique : 1;
248
  };
249
250
  class ObjCIndirectCopyRestoreExprBitfields {
251
    friend class ObjCIndirectCopyRestoreExpr;
252
253
    unsigned : NumExprBits;
254
255
    unsigned ShouldCopy : 1;
256
  };
257
258
  class InitListExprBitfields {
259
    friend class InitListExpr;
260
261
    unsigned : NumExprBits;
262
263
    /// Whether this initializer list originally had a GNU array-range
264
    /// designator in it. This is a temporary marker used by CodeGen.
265
    unsigned HadArrayRangeDesignator : 1;
266
  };
267
268
  class TypeTraitExprBitfields {
269
    friend class ASTStmtReader;
270
    friend class ASTStmtWriter;
271
    friend class TypeTraitExpr;
272
    
273
    unsigned : NumExprBits;
274
    
275
    /// The kind of type trait, which is a value of a TypeTrait enumerator.
276
    unsigned Kind : 8;
277
    
278
    /// If this expression is not value-dependent, this indicates whether
279
    /// the trait evaluated true or false.
280
    unsigned Value : 1;
281
282
    /// The number of arguments to this type trait.
283
    unsigned NumArgs : 32 - 8 - 1 - NumExprBits;
284
  };
285
286
  class CoawaitExprBitfields {
287
    friend class CoawaitExpr;
288
289
    unsigned : NumExprBits;
290
291
    unsigned IsImplicit : 1;
292
  };
293
294
  union {
295
    StmtBitfields StmtBits;
296
    CompoundStmtBitfields CompoundStmtBits;
297
    IfStmtBitfields IfStmtBits;
298
    ExprBitfields ExprBits;
299
    CharacterLiteralBitfields CharacterLiteralBits;
300
    FloatingLiteralBitfields FloatingLiteralBits;
301
    UnaryExprOrTypeTraitExprBitfields UnaryExprOrTypeTraitExprBits;
302
    DeclRefExprBitfields DeclRefExprBits;
303
    CastExprBitfields CastExprBits;
304
    CallExprBitfields CallExprBits;
305
    ExprWithCleanupsBitfields ExprWithCleanupsBits;
306
    PseudoObjectExprBitfields PseudoObjectExprBits;
307
    OpaqueValueExprBitfields OpaqueValueExprBits;
308
    ObjCIndirectCopyRestoreExprBitfields ObjCIndirectCopyRestoreExprBits;
309
    InitListExprBitfields InitListExprBits;
310
    TypeTraitExprBitfields TypeTraitExprBits;
311
    CoawaitExprBitfields CoawaitBits;
312
  };
313
314
public:
315
  // Only allow allocation of Stmts using the allocator in ASTContext
316
  // or by doing a placement new.
317
  void* operator new(size_t bytes, const ASTContext& C,
318
                     unsigned alignment = 8);
319
320
  void* operator new(size_t bytes, const ASTContext* C,
321
3.76k
                     unsigned alignment = 8) {
322
3.76k
    return operator new(bytes, *C, alignment);
323
3.76k
  }
324
325
51.0M
  void *operator new(size_t bytes, void *mem) noexcept { return mem; }
326
327
0
  void operator delete(void *, const ASTContext &, unsigned) noexcept {}
328
0
  void operator delete(void *, const ASTContext *, unsigned) noexcept {}
329
0
  void operator delete(void *, size_t) noexcept {}
330
0
  void operator delete(void *, void *) noexcept {}
331
332
public:
333
  /// A placeholder type used to construct an empty shell of a
334
  /// type, that will be filled in later (e.g., by some
335
  /// de-serialization).
336
  struct EmptyShell {};
337
338
protected:
339
  /// Iterator for iterating over Stmt * arrays that contain only Expr *
340
  ///
341
  /// This is needed because AST nodes use Stmt* arrays to store
342
  /// references to children (to be compatible with StmtIterator).
343
  struct ExprIterator
344
      : llvm::iterator_adaptor_base<ExprIterator, Stmt **,
345
                                    std::random_access_iterator_tag, Expr *> {
346
    ExprIterator() : iterator_adaptor_base(nullptr) {}
347
6.97M
    ExprIterator(Stmt **I) : iterator_adaptor_base(I) {}
348
349
7.56M
    reference operator*() const {
350
7.56M
      assert((*I)->getStmtClass() >= firstExprConstant &&
351
7.56M
             (*I)->getStmtClass() <= lastExprConstant);
352
7.56M
      return *reinterpret_cast<Expr **>(I);
353
7.56M
    }
354
  };
355
356
  /// Const iterator for iterating over Stmt * arrays that contain only Expr *
357
  struct ConstExprIterator
358
      : llvm::iterator_adaptor_base<ConstExprIterator, const Stmt *const *,
359
                                    std::random_access_iterator_tag,
360
                                    const Expr *const> {
361
    ConstExprIterator() : iterator_adaptor_base(nullptr) {}
362
1.71M
    ConstExprIterator(const Stmt *const *I) : iterator_adaptor_base(I) {}
363
364
3.75M
    reference operator*() const {
365
3.75M
      assert((*I)->getStmtClass() >= firstExprConstant &&
366
3.75M
             (*I)->getStmtClass() <= lastExprConstant);
367
3.75M
      return *reinterpret_cast<const Expr *const *>(I);
368
3.75M
    }
369
  };
370
371
private:
372
  /// Whether statistic collection is enabled.
373
  static bool StatisticsEnabled;
374
375
protected:
376
  /// Construct an empty statement.
377
56.0k
  explicit Stmt(StmtClass SC, EmptyShell) : Stmt(SC) {}
378
379
public:
380
93.5M
  Stmt(StmtClass SC) {
381
93.5M
    static_assert(sizeof(*this) == sizeof(void *),
382
93.5M
                  "changing bitfields changed sizeof(Stmt)");
383
93.5M
    static_assert(sizeof(*this) % alignof(void *) == 0,
384
93.5M
                  "Insufficient alignment!");
385
93.5M
    StmtBits.sClass = SC;
386
93.5M
    if (StatisticsEnabled) 
Stmt::addStmtClass(SC)13
;
387
93.5M
  }
388
389
3.28G
  StmtClass getStmtClass() const {
390
3.28G
    return static_cast<StmtClass>(StmtBits.sClass);
391
3.28G
  }
392
393
  const char *getStmtClassName() const;
394
395
  /// SourceLocation tokens are not useful in isolation - they are low level
396
  /// value objects created/interpreted by SourceManager. We assume AST
397
  /// clients will have a pointer to the respective SourceManager.
398
  SourceRange getSourceRange() const LLVM_READONLY;
399
  SourceLocation getLocStart() const LLVM_READONLY;
400
  SourceLocation getLocEnd() const LLVM_READONLY;
401
402
  // global temp stats (until we have a per-module visitor)
403
  static void addStmtClass(const StmtClass s);
404
  static void EnableStatistics();
405
  static void PrintStats();
406
407
  /// Dumps the specified AST fragment and all subtrees to
408
  /// \c llvm::errs().
409
  void dump() const;
410
  void dump(SourceManager &SM) const;
411
  void dump(raw_ostream &OS, SourceManager &SM) const;
412
  void dump(raw_ostream &OS) const;
413
414
  /// dumpColor - same as dump(), but forces color highlighting.
415
  void dumpColor() const;
416
417
  /// dumpPretty/printPretty - These two methods do a "pretty print" of the AST
418
  /// back to its original source language syntax.
419
  void dumpPretty(const ASTContext &Context) const;
420
  void printPretty(raw_ostream &OS, PrinterHelper *Helper,
421
                   const PrintingPolicy &Policy, unsigned Indentation = 0,
422
                   const ASTContext *Context = nullptr) const;
423
424
  /// viewAST - Visualize an AST rooted at this Stmt* using GraphViz.  Only
425
  ///   works on systems with GraphViz (Mac OS X) or dot+gv installed.
426
  void viewAST() const;
427
428
  /// Skip past any implicit AST nodes which might surround this
429
  /// statement, such as ExprWithCleanups or ImplicitCastExpr nodes.
430
  Stmt *IgnoreImplicit();
431
441
  const Stmt *IgnoreImplicit() const {
432
441
    return const_cast<Stmt *>(this)->IgnoreImplicit();
433
441
  }
434
435
  /// Skip no-op (attributed, compound) container stmts and skip captured
436
  /// stmt at the top, if \a IgnoreCaptured is true.
437
  Stmt *IgnoreContainers(bool IgnoreCaptured = false);
438
6.85k
  const Stmt *IgnoreContainers(bool IgnoreCaptured = false) const {
439
6.85k
    return const_cast<Stmt *>(this)->IgnoreContainers(IgnoreCaptured);
440
6.85k
  }
441
442
  const Stmt *stripLabelLikeStatements() const;
443
1.69M
  Stmt *stripLabelLikeStatements() {
444
1.69M
    return const_cast<Stmt*>(
445
1.69M
      const_cast<const Stmt*>(this)->stripLabelLikeStatements());
446
1.69M
  }
447
448
  /// Child Iterators: All subclasses must implement 'children'
449
  /// to permit easy iteration over the substatements/subexpessions of an
450
  /// AST node.  This permits easy iteration over all nodes in the AST.
451
  using child_iterator = StmtIterator;
452
  using const_child_iterator = ConstStmtIterator;
453
454
  using child_range = llvm::iterator_range<child_iterator>;
455
  using const_child_range = llvm::iterator_range<const_child_iterator>;
456
457
  child_range children();
458
459
24.8M
  const_child_range children() const {
460
24.8M
    auto Children = const_cast<Stmt *>(this)->children();
461
24.8M
    return const_child_range(Children.begin(), Children.end());
462
24.8M
  }
463
464
2.18M
  child_iterator child_begin() { return children().begin(); }
465
18
  child_iterator child_end() { return children().end(); }
466
467
246k
  const_child_iterator child_begin() const { return children().begin(); }
468
4.38k
  const_child_iterator child_end() const { return children().end(); }
469
470
  /// Produce a unique representation of the given statement.
471
  ///
472
  /// \param ID once the profiling operation is complete, will contain
473
  /// the unique representation of the given statement.
474
  ///
475
  /// \param Context the AST context in which the statement resides
476
  ///
477
  /// \param Canonical whether the profile should be based on the canonical
478
  /// representation of this statement (e.g., where non-type template
479
  /// parameters are identified by index/level rather than their
480
  /// declaration pointers) or the exact representation of the statement as
481
  /// written in the source.
482
  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
483
               bool Canonical) const;
484
485
  /// Calculate a unique representation for a statement that is
486
  /// stable across compiler invocations.
487
  ///
488
  /// \param ID profile information will be stored in ID.
489
  ///
490
  /// \param Hash an ODRHash object which will be called where pointers would
491
  /// have been used in the Profile function.
492
  void ProcessODRHash(llvm::FoldingSetNodeID &ID, ODRHash& Hash) const;
493
};
494
495
/// DeclStmt - Adaptor class for mixing declarations with statements and
496
/// expressions. For example, CompoundStmt mixes statements, expressions
497
/// and declarations (variables, types). Another example is ForStmt, where
498
/// the first statement can be an expression or a declaration.
499
class DeclStmt : public Stmt {
500
  DeclGroupRef DG;
501
  SourceLocation StartLoc, EndLoc;
502
503
public:
504
  DeclStmt(DeclGroupRef dg, SourceLocation startLoc, SourceLocation endLoc)
505
1.88M
      : Stmt(DeclStmtClass), DG(dg), StartLoc(startLoc), EndLoc(endLoc) {}
506
507
  /// Build an empty declaration statement.
508
15.5k
  explicit DeclStmt(EmptyShell Empty) : Stmt(DeclStmtClass, Empty) {}
509
510
  /// isSingleDecl - This method returns true if this DeclStmt refers
511
  /// to a single Decl.
512
514k
  bool isSingleDecl() const {
513
514k
    return DG.isSingleDecl();
514
514k
  }
515
516
44.3k
  const Decl *getSingleDecl() const { return DG.getSingleDecl(); }
517
507k
  Decl *getSingleDecl() { return DG.getSingleDecl(); }
518
519
0
  const DeclGroupRef getDeclGroup() const { return DG; }
520
23.7k
  DeclGroupRef getDeclGroup() { return DG; }
521
15.5k
  void setDeclGroup(DeclGroupRef DGR) { DG = DGR; }
522
523
173k
  SourceLocation getStartLoc() const { return StartLoc; }
524
15.5k
  void setStartLoc(SourceLocation L) { StartLoc = L; }
525
173k
  SourceLocation getEndLoc() const { return EndLoc; }
526
15.5k
  void setEndLoc(SourceLocation L) { EndLoc = L; }
527
528
400k
  SourceLocation getLocStart() const LLVM_READONLY { return StartLoc; }
529
177k
  SourceLocation getLocEnd() const LLVM_READONLY { return EndLoc; }
530
531
1.99M
  static bool classof(const Stmt *T) {
532
1.99M
    return T->getStmtClass() == DeclStmtClass;
533
1.99M
  }
534
535
  // Iterators over subexpressions.
536
109k
  child_range children() {
537
109k
    return child_range(child_iterator(DG.begin(), DG.end()),
538
109k
                       child_iterator(DG.end(), DG.end()));
539
109k
  }
540
541
  using decl_iterator = DeclGroupRef::iterator;
542
  using const_decl_iterator = DeclGroupRef::const_iterator;
543
  using decl_range = llvm::iterator_range<decl_iterator>;
544
  using decl_const_range = llvm::iterator_range<const_decl_iterator>;
545
546
1.20M
  decl_range decls() { return decl_range(decl_begin(), decl_end()); }
547
548
718k
  decl_const_range decls() const {
549
718k
    return decl_const_range(decl_begin(), decl_end());
550
718k
  }
551
552
1.56M
  decl_iterator decl_begin() { return DG.begin(); }
553
1.21M
  decl_iterator decl_end() { return DG.end(); }
554
741k
  const_decl_iterator decl_begin() const { return DG.begin(); }
555
718k
  const_decl_iterator decl_end() const { return DG.end(); }
556
557
  using reverse_decl_iterator = std::reverse_iterator<decl_iterator>;
558
559
5.55k
  reverse_decl_iterator decl_rbegin() {
560
5.55k
    return reverse_decl_iterator(decl_end());
561
5.55k
  }
562
563
5.55k
  reverse_decl_iterator decl_rend() {
564
5.55k
    return reverse_decl_iterator(decl_begin());
565
5.55k
  }
566
};
567
568
/// NullStmt - This is the null statement ";": C99 6.8.3p3.
569
///
570
class NullStmt : public Stmt {
571
  SourceLocation SemiLoc;
572
573
  /// True if the null statement was preceded by an empty macro, e.g:
574
  /// @code
575
  ///   #define CALL(x)
576
  ///   CALL(0);
577
  /// @endcode
578
  bool HasLeadingEmptyMacro = false;
579
580
public:
581
  friend class ASTStmtReader;
582
  friend class ASTStmtWriter;
583
584
  NullStmt(SourceLocation L, bool hasLeadingEmptyMacro = false)
585
      : Stmt(NullStmtClass), SemiLoc(L),
586
112k
        HasLeadingEmptyMacro(hasLeadingEmptyMacro) {}
587
588
  /// Build an empty null statement.
589
269
  explicit NullStmt(EmptyShell Empty) : Stmt(NullStmtClass, Empty) {}
590
591
5.08k
  SourceLocation getSemiLoc() const { return SemiLoc; }
592
269
  void setSemiLoc(SourceLocation L) { SemiLoc = L; }
593
594
835
  bool hasLeadingEmptyMacro() const { return HasLeadingEmptyMacro; }
595
596
661
  SourceLocation getLocStart() const LLVM_READONLY { return SemiLoc; }
597
3.93k
  SourceLocation getLocEnd() const LLVM_READONLY { return SemiLoc; }
598
599
1.03M
  static bool classof(const Stmt *T) {
600
1.03M
    return T->getStmtClass() == NullStmtClass;
601
1.03M
  }
602
603
65.4k
  child_range children() {
604
65.4k
    return child_range(child_iterator(), child_iterator());
605
65.4k
  }
606
};
607
608
/// CompoundStmt - This represents a group of statements like { stmt stmt }.
609
class CompoundStmt final : public Stmt,
610
                           private llvm::TrailingObjects<CompoundStmt, Stmt *> {
611
  friend class ASTStmtReader;
612
  friend TrailingObjects;
613
614
  SourceLocation LBraceLoc, RBraceLoc;
615
616
  CompoundStmt(ArrayRef<Stmt *> Stmts, SourceLocation LB, SourceLocation RB);
617
13.5k
  explicit CompoundStmt(EmptyShell Empty) : Stmt(CompoundStmtClass, Empty) {}
618
619
  void setStmts(ArrayRef<Stmt *> Stmts);
620
621
public:
622
  static CompoundStmt *Create(const ASTContext &C, ArrayRef<Stmt *> Stmts,
623
                              SourceLocation LB, SourceLocation RB);
624
625
  // Build an empty compound statement with a location.
626
  explicit CompoundStmt(SourceLocation Loc)
627
39.0k
      : Stmt(CompoundStmtClass), LBraceLoc(Loc), RBraceLoc(Loc) {
628
39.0k
    CompoundStmtBits.NumStmts = 0;
629
39.0k
  }
630
631
  // Build an empty compound statement.
632
  static CompoundStmt *CreateEmpty(const ASTContext &C, unsigned NumStmts);
633
634
746k
  bool body_empty() const { return CompoundStmtBits.NumStmts == 0; }
635
4.00M
  unsigned size() const { return CompoundStmtBits.NumStmts; }
636
637
  using body_iterator = Stmt **;
638
  using body_range = llvm::iterator_range<body_iterator>;
639
640
1.15M
  body_range body() { return body_range(body_begin(), body_end()); }
641
9.47M
  body_iterator body_begin() { return getTrailingObjects<Stmt *>(); }
642
3.08M
  body_iterator body_end() { return body_begin() + size(); }
643
388
  Stmt *body_front() { return !body_empty() ? body_begin()[0] : 
nullptr0
; }
644
645
56.8k
  Stmt *body_back() {
646
56.8k
    return !body_empty() ? body_begin()[size() - 1] : 
nullptr0
;
647
56.8k
  }
648
649
10.5k
  void setLastStmt(Stmt *S) {
650
10.5k
    assert(!body_empty() && "setLastStmt");
651
10.5k
    body_begin()[size() - 1] = S;
652
10.5k
  }
653
654
  using const_body_iterator = Stmt* const *;
655
  using body_const_range = llvm::iterator_range<const_body_iterator>;
656
657
125k
  body_const_range body() const {
658
125k
    return body_const_range(body_begin(), body_end());
659
125k
  }
660
661
1.57M
  const_body_iterator body_begin() const {
662
1.57M
    return getTrailingObjects<Stmt *>();
663
1.57M
  }
664
665
782k
  const_body_iterator body_end() const { return body_begin() + size(); }
666
667
1.65k
  const Stmt *body_front() const {
668
1.65k
    return !body_empty() ? 
body_begin()[0]1.59k
:
nullptr60
;
669
1.65k
  }
670
671
10.2k
  const Stmt *body_back() const {
672
10.2k
    return !body_empty() ? body_begin()[size() - 1] : 
nullptr0
;
673
10.2k
  }
674
675
  using reverse_body_iterator = std::reverse_iterator<body_iterator>;
676
677
1.20M
  reverse_body_iterator body_rbegin() {
678
1.20M
    return reverse_body_iterator(body_end());
679
1.20M
  }
680
681
622k
  reverse_body_iterator body_rend() {
682
622k
    return reverse_body_iterator(body_begin());
683
622k
  }
684
685
  using const_reverse_body_iterator =
686
      std::reverse_iterator<const_body_iterator>;
687
688
114k
  const_reverse_body_iterator body_rbegin() const {
689
114k
    return const_reverse_body_iterator(body_end());
690
114k
  }
691
692
114k
  const_reverse_body_iterator body_rend() const {
693
114k
    return const_reverse_body_iterator(body_begin());
694
114k
  }
695
696
928k
  SourceLocation getLocStart() const LLVM_READONLY { return LBraceLoc; }
697
4.00M
  SourceLocation getLocEnd() const LLVM_READONLY { return RBraceLoc; }
698
699
658k
  SourceLocation getLBracLoc() const { return LBraceLoc; }
700
365k
  SourceLocation getRBracLoc() const { return RBraceLoc; }
701
702
1.87M
  static bool classof(const Stmt *T) {
703
1.87M
    return T->getStmtClass() == CompoundStmtClass;
704
1.87M
  }
705
706
  // Iterators
707
725k
  child_range children() { return child_range(body_begin(), body_end()); }
708
709
63
  const_child_range children() const {
710
63
    return const_child_range(body_begin(), body_end());
711
63
  }
712
};
713
714
// SwitchCase is the base class for CaseStmt and DefaultStmt,
715
class SwitchCase : public Stmt {
716
protected:
717
  // A pointer to the following CaseStmt or DefaultStmt class,
718
  // used by SwitchStmt.
719
  SwitchCase *NextSwitchCase = nullptr;
720
  SourceLocation KeywordLoc;
721
  SourceLocation ColonLoc;
722
723
  SwitchCase(StmtClass SC, SourceLocation KWLoc, SourceLocation ColonLoc)
724
115k
      : Stmt(SC), KeywordLoc(KWLoc), ColonLoc(ColonLoc) {}
725
726
27
  SwitchCase(StmtClass SC, EmptyShell) : Stmt(SC) {}
727
728
public:
729
28.8k
  const SwitchCase *getNextSwitchCase() const { return NextSwitchCase; }
730
731
147k
  SwitchCase *getNextSwitchCase() { return NextSwitchCase; }
732
733
115k
  void setNextSwitchCase(SwitchCase *SC) { NextSwitchCase = SC; }
734
735
31
  SourceLocation getKeywordLoc() const { return KeywordLoc; }
736
27
  void setKeywordLoc(SourceLocation L) { KeywordLoc = L; }
737
38
  SourceLocation getColonLoc() const { return ColonLoc; }
738
27
  void setColonLoc(SourceLocation L) { ColonLoc = L; }
739
740
  Stmt *getSubStmt();
741
103k
  const Stmt *getSubStmt() const {
742
103k
    return const_cast<SwitchCase*>(this)->getSubStmt();
743
103k
  }
744
745
38
  SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; }
746
  SourceLocation getLocEnd() const LLVM_READONLY;
747
748
18.0M
  static bool classof(const Stmt *T) {
749
18.0M
    return T->getStmtClass() == CaseStmtClass ||
750
18.0M
           
T->getStmtClass() == DefaultStmtClass17.8M
;
751
18.0M
  }
752
};
753
754
class CaseStmt : public SwitchCase {
755
  SourceLocation EllipsisLoc;
756
  enum { LHS, RHS, SUBSTMT, END_EXPR };
757
  Stmt* SubExprs[END_EXPR];  // The expression for the RHS is Non-null for
758
                             // GNU "case 1 ... 4" extension
759
760
public:
761
  CaseStmt(Expr *lhs, Expr *rhs, SourceLocation caseLoc,
762
           SourceLocation ellipsisLoc, SourceLocation colonLoc)
763
111k
    : SwitchCase(CaseStmtClass, caseLoc, colonLoc) {
764
111k
    SubExprs[SUBSTMT] = nullptr;
765
111k
    SubExprs[LHS] = reinterpret_cast<Stmt*>(lhs);
766
111k
    SubExprs[RHS] = reinterpret_cast<Stmt*>(rhs);
767
111k
    EllipsisLoc = ellipsisLoc;
768
111k
  }
769
770
  /// Build an empty switch case statement.
771
21
  explicit CaseStmt(EmptyShell Empty) : SwitchCase(CaseStmtClass, Empty) {}
772
773
52.7k
  SourceLocation getCaseLoc() const { return KeywordLoc; }
774
  void setCaseLoc(SourceLocation L) { KeywordLoc = L; }
775
52.7k
  SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
776
21
  void setEllipsisLoc(SourceLocation L) { EllipsisLoc = L; }
777
52.6k
  SourceLocation getColonLoc() const { return ColonLoc; }
778
  void setColonLoc(SourceLocation L) { ColonLoc = L; }
779
780
171k
  Expr *getLHS() { return reinterpret_cast<Expr*>(SubExprs[LHS]); }
781
152k
  Expr *getRHS() { return reinterpret_cast<Expr*>(SubExprs[RHS]); }
782
266k
  Stmt *getSubStmt() { return SubExprs[SUBSTMT]; }
783
784
50.4k
  const Expr *getLHS() const {
785
50.4k
    return reinterpret_cast<const Expr*>(SubExprs[LHS]);
786
50.4k
  }
787
788
25.3k
  const Expr *getRHS() const {
789
25.3k
    return reinterpret_cast<const Expr*>(SubExprs[RHS]);
790
25.3k
  }
791
792
53.8k
  const Stmt *getSubStmt() const { return SubExprs[SUBSTMT]; }
793
794
111k
  void setSubStmt(Stmt *S) { SubExprs[SUBSTMT] = S; }
795
99.5k
  void setLHS(Expr *Val) { SubExprs[LHS] = reinterpret_cast<Stmt*>(Val); }
796
109
  void setRHS(Expr *Val) { SubExprs[RHS] = reinterpret_cast<Stmt*>(Val); }
797
798
41.9k
  SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; }
799
800
372
  SourceLocation getLocEnd() const LLVM_READONLY {
801
372
    // Handle deeply nested case statements with iteration instead of recursion.
802
372
    const CaseStmt *CS = this;
803
378
    while (const auto *CS2 = dyn_cast<CaseStmt>(CS->getSubStmt()))
804
6
      CS = CS2;
805
372
806
372
    return CS->getSubStmt()->getLocEnd();
807
372
  }
808
809
283k
  static bool classof(const Stmt *T) {
810
283k
    return T->getStmtClass() == CaseStmtClass;
811
283k
  }
812
813
  // Iterators
814
6.15k
  child_range children() {
815
6.15k
    return child_range(&SubExprs[0], &SubExprs[END_EXPR]);
816
6.15k
  }
817
};
818
819
class DefaultStmt : public SwitchCase {
820
  Stmt* SubStmt;
821
822
public:
823
  DefaultStmt(SourceLocation DL, SourceLocation CL, Stmt *substmt) :
824
4.37k
    SwitchCase(DefaultStmtClass, DL, CL), SubStmt(substmt) {}
825
826
  /// Build an empty default statement.
827
  explicit DefaultStmt(EmptyShell Empty)
828
6
      : SwitchCase(DefaultStmtClass, Empty) {}
829
830
8.30k
  Stmt *getSubStmt() { return SubStmt; }
831
2.01k
  const Stmt *getSubStmt() const { return SubStmt; }
832
6
  void setSubStmt(Stmt *S) { SubStmt = S; }
833
834
616
  SourceLocation getDefaultLoc() const { return KeywordLoc; }
835
  void setDefaultLoc(SourceLocation L) { KeywordLoc = L; }
836
238
  SourceLocation getColonLoc() const { return ColonLoc; }
837
  void setColonLoc(SourceLocation L) { ColonLoc = L; }
838
839
2.60k
  SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; }
840
82
  SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();}
841
842
109k
  static bool classof(const Stmt *T) {
843
109k
    return T->getStmtClass() == DefaultStmtClass;
844
109k
  }
845
846
  // Iterators
847
553
  child_range children() { return child_range(&SubStmt, &SubStmt+1); }
848
};
849
850
inline SourceLocation SwitchCase::getLocEnd() const {
851
  if (const auto *CS = dyn_cast<CaseStmt>(this))
852
    return CS->getLocEnd();
853
  return cast<DefaultStmt>(this)->getLocEnd();
854
}
855
856
/// LabelStmt - Represents a label, which has a substatement.  For example:
857
///    foo: return;
858
class LabelStmt : public Stmt {
859
  SourceLocation IdentLoc;
860
  LabelDecl *TheDecl;
861
  Stmt *SubStmt;
862
863
public:
864
  LabelStmt(SourceLocation IL, LabelDecl *D, Stmt *substmt)
865
3.90k
      : Stmt(LabelStmtClass), IdentLoc(IL), TheDecl(D), SubStmt(substmt) {
866
3.90k
    static_assert(sizeof(LabelStmt) ==
867
3.90k
                      2 * sizeof(SourceLocation) + 2 * sizeof(void *),
868
3.90k
                  "LabelStmt too big");
869
3.90k
  }
870
871
  // Build an empty label statement.
872
4
  explicit LabelStmt(EmptyShell Empty) : Stmt(LabelStmtClass, Empty) {}
873
874
322
  SourceLocation getIdentLoc() const { return IdentLoc; }
875
2.09k
  LabelDecl *getDecl() const { return TheDecl; }
876
4
  void setDecl(LabelDecl *D) { TheDecl = D; }
877
  const char *getName() const;
878
3.70k
  Stmt *getSubStmt() { return SubStmt; }
879
6.13k
  const Stmt *getSubStmt() const { return SubStmt; }
880
4
  void setIdentLoc(SourceLocation L) { IdentLoc = L; }
881
13
  void setSubStmt(Stmt *SS) { SubStmt = SS; }
882
883
180
  SourceLocation getLocStart() const LLVM_READONLY { return IdentLoc; }
884
165
  SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();}
885
886
500
  child_range children() { return child_range(&SubStmt, &SubStmt+1); }
887
888
28.0M
  static bool classof(const Stmt *T) {
889
28.0M
    return T->getStmtClass() == LabelStmtClass;
890
28.0M
  }
891
};
892
893
/// Represents an attribute applied to a statement.
894
///
895
/// Represents an attribute applied to a statement. For example:
896
///   [[omp::for(...)]] for (...) { ... }
897
class AttributedStmt final
898
    : public Stmt,
899
      private llvm::TrailingObjects<AttributedStmt, const Attr *> {
900
  friend class ASTStmtReader;
901
  friend TrailingObjects;
902
903
  Stmt *SubStmt;
904
  SourceLocation AttrLoc;
905
  unsigned NumAttrs;
906
907
  AttributedStmt(SourceLocation Loc, ArrayRef<const Attr*> Attrs, Stmt *SubStmt)
908
    : Stmt(AttributedStmtClass), SubStmt(SubStmt), AttrLoc(Loc),
909
195
      NumAttrs(Attrs.size()) {
910
195
    std::copy(Attrs.begin(), Attrs.end(), getAttrArrayPtr());
911
195
  }
912
913
  explicit AttributedStmt(EmptyShell Empty, unsigned NumAttrs)
914
10
      : Stmt(AttributedStmtClass, Empty), NumAttrs(NumAttrs) {
915
10
    std::fill_n(getAttrArrayPtr(), NumAttrs, nullptr);
916
10
  }
917
918
217
  const Attr *const *getAttrArrayPtr() const {
919
217
    return getTrailingObjects<const Attr *>();
920
217
  }
921
215
  const Attr **getAttrArrayPtr() { return getTrailingObjects<const Attr *>(); }
922
923
public:
924
  static AttributedStmt *Create(const ASTContext &C, SourceLocation Loc,
925
                                ArrayRef<const Attr*> Attrs, Stmt *SubStmt);
926
927
  // Build an empty attributed statement.
928
  static AttributedStmt *CreateEmpty(const ASTContext &C, unsigned NumAttrs);
929
930
36
  SourceLocation getAttrLoc() const { return AttrLoc; }
931
217
  ArrayRef<const Attr*> getAttrs() const {
932
217
    return llvm::makeArrayRef(getAttrArrayPtr(), NumAttrs);
933
217
  }
934
935
90
  Stmt *getSubStmt() { return SubStmt; }
936
107
  const Stmt *getSubStmt() const { return SubStmt; }
937
938
25
  SourceLocation getLocStart() const LLVM_READONLY { return AttrLoc; }
939
7
  SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();}
940
941
151
  child_range children() { return child_range(&SubStmt, &SubStmt + 1); }
942
943
1.88M
  static bool classof(const Stmt *T) {
944
1.88M
    return T->getStmtClass() == AttributedStmtClass;
945
1.88M
  }
946
};
947
948
/// IfStmt - This represents an if/then/else.
949
class IfStmt : public Stmt {
950
  enum { INIT, VAR, COND, THEN, ELSE, END_EXPR };
951
  Stmt* SubExprs[END_EXPR];
952
953
  SourceLocation IfLoc;
954
  SourceLocation ElseLoc;
955
956
public:
957
  IfStmt(const ASTContext &C, SourceLocation IL,
958
         bool IsConstexpr, Stmt *init, VarDecl *var, Expr *cond,
959
         Stmt *then, SourceLocation EL = SourceLocation(),
960
         Stmt *elsev = nullptr);
961
962
  /// Build an empty if/then/else statement
963
18
  explicit IfStmt(EmptyShell Empty) : Stmt(IfStmtClass, Empty) {}
964
965
  /// Retrieve the variable declared in this "if" statement, if any.
966
  ///
967
  /// In the following example, "x" is the condition variable.
968
  /// \code
969
  /// if (int x = foo()) {
970
  ///   printf("x is %d", x);
971
  /// }
972
  /// \endcode
973
  VarDecl *getConditionVariable() const;
974
  void setConditionVariable(const ASTContext &C, VarDecl *V);
975
976
  /// If this IfStmt has a condition variable, return the faux DeclStmt
977
  /// associated with the creation of that condition variable.
978
207k
  const DeclStmt *getConditionVariableDeclStmt() const {
979
207k
    return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
980
207k
  }
981
982
679k
  Stmt *getInit() { return SubExprs[INIT]; }
983
242k
  const Stmt *getInit() const { return SubExprs[INIT]; }
984
18
  void setInit(Stmt *S) { SubExprs[INIT] = S; }
985
728k
  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
986
18
  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); }
987
471k
  const Stmt *getThen() const { return SubExprs[THEN]; }
988
18
  void setThen(Stmt *S) { SubExprs[THEN] = S; }
989
472k
  const Stmt *getElse() const { return SubExprs[ELSE]; }
990
18
  void setElse(Stmt *S) { SubExprs[ELSE] = S; }
991
992
884k
  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
993
348k
  Stmt *getThen() { return SubExprs[THEN]; }
994
348k
  Stmt *getElse() { return SubExprs[ELSE]; }
995
996
192k
  SourceLocation getIfLoc() const { return IfLoc; }
997
18
  void setIfLoc(SourceLocation L) { IfLoc = L; }
998
96.4k
  SourceLocation getElseLoc() const { return ElseLoc; }
999
18
  void setElseLoc(SourceLocation L) { ElseLoc = L; }
1000
1001
588k
  bool isConstexpr() const { return IfStmtBits.IsConstexpr; }
1002
985k
  void setConstexpr(bool C) { IfStmtBits.IsConstexpr = C; }
1003
1004
  bool isObjCAvailabilityCheck() const;
1005
1006
128k
  SourceLocation getLocStart() const LLVM_READONLY { return IfLoc; }
1007
1008
8.33k
  SourceLocation getLocEnd() const LLVM_READONLY {
1009
8.33k
    if (SubExprs[ELSE])
1010
1.17k
      return SubExprs[ELSE]->getLocEnd();
1011
7.16k
    else
1012
7.16k
      return SubExprs[THEN]->getLocEnd();
1013
8.33k
  }
1014
1015
  // Iterators over subexpressions.  The iterators will include iterating
1016
  // over the initialization expression referenced by the condition variable.
1017
332k
  child_range children() {
1018
332k
    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
1019
332k
  }
1020
1021
27.5k
  static bool classof(const Stmt *T) {
1022
27.5k
    return T->getStmtClass() == IfStmtClass;
1023
27.5k
  }
1024
};
1025
1026
/// SwitchStmt - This represents a 'switch' stmt.
1027
class SwitchStmt : public Stmt {
1028
  SourceLocation SwitchLoc;
1029
  enum { INIT, VAR, COND, BODY, END_EXPR };
1030
  Stmt* SubExprs[END_EXPR];
1031
1032
  // This points to a linked list of case and default statements and, if the
1033
  // SwitchStmt is a switch on an enum value, records whether all the enum
1034
  // values were covered by CaseStmts.  The coverage information value is meant
1035
  // to be a hint for possible clients.
1036
  llvm::PointerIntPair<SwitchCase *, 1, bool> FirstCase;
1037
1038
public:
1039
  SwitchStmt(const ASTContext &C, Stmt *Init, VarDecl *Var, Expr *cond);
1040
1041
  /// Build a empty switch statement.
1042
12
  explicit SwitchStmt(EmptyShell Empty) : Stmt(SwitchStmtClass, Empty) {}
1043
1044
  /// Retrieve the variable declared in this "switch" statement, if any.
1045
  ///
1046
  /// In the following example, "x" is the condition variable.
1047
  /// \code
1048
  /// switch (int x = foo()) {
1049
  ///   case 0: break;
1050
  ///   // ...
1051
  /// }
1052
  /// \endcode
1053
  VarDecl *getConditionVariable() const;
1054
  void setConditionVariable(const ASTContext &C, VarDecl *V);
1055
1056
  /// If this SwitchStmt has a condition variable, return the faux DeclStmt
1057
  /// associated with the creation of that condition variable.
1058
57
  const DeclStmt *getConditionVariableDeclStmt() const {
1059
57
    return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
1060
57
  }
1061
1062
24.3k
  Stmt *getInit() { return SubExprs[INIT]; }
1063
7.53k
  const Stmt *getInit() const { return SubExprs[INIT]; }
1064
12
  void setInit(Stmt *S) { SubExprs[INIT] = S; }
1065
10.8k
  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
1066
3.86k
  const Stmt *getBody() const { return SubExprs[BODY]; }
1067
4.17k
  const SwitchCase *getSwitchCaseList() const { return FirstCase.getPointer(); }
1068
1069
31.4k
  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]);}
1070
12
  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); }
1071
17.3k
  Stmt *getBody() { return SubExprs[BODY]; }
1072
16
  void setBody(Stmt *S) { SubExprs[BODY] = S; }
1073
22.7k
  SwitchCase *getSwitchCaseList() { return FirstCase.getPointer(); }
1074
1075
  /// Set the case list for this switch statement.
1076
16
  void setSwitchCaseList(SwitchCase *SC) { FirstCase.setPointer(SC); }
1077
1078
11.6k
  SourceLocation getSwitchLoc() const { return SwitchLoc; }
1079
16
  void setSwitchLoc(SourceLocation L) { SwitchLoc = L; }
1080
1081
13.9k
  void setBody(Stmt *S, SourceLocation SL) {
1082
13.9k
    SubExprs[BODY] = S;
1083
13.9k
    SwitchLoc = SL;
1084
13.9k
  }
1085
1086
115k
  void addSwitchCase(SwitchCase *SC) {
1087
115k
    assert(!SC->getNextSwitchCase()
1088
115k
           && "case/default already added to a switch");
1089
115k
    SC->setNextSwitchCase(FirstCase.getPointer());
1090
115k
    FirstCase.setPointer(SC);
1091
115k
  }
1092
1093
  /// Set a flag in the SwitchStmt indicating that if the 'switch (X)' is a
1094
  /// switch over an enum value then all cases have been explicitly covered.
1095
2.10k
  void setAllEnumCasesCovered() { FirstCase.setInt(true); }
1096
1097
  /// Returns true if the SwitchStmt is a switch of an enum value and all cases
1098
  /// have been explicitly covered.
1099
6.69k
  bool isAllEnumCasesCovered() const { return FirstCase.getInt(); }
1100
1101
1.56k
  SourceLocation getLocStart() const LLVM_READONLY { return SwitchLoc; }
1102
1103
345
  SourceLocation getLocEnd() const LLVM_READONLY {
1104
345
    return SubExprs[BODY] ? SubExprs[BODY]->getLocEnd() : 
SubExprs[COND]->getLocEnd()0
;
1105
345
  }
1106
1107
  // Iterators
1108
11.8k
  child_range children() {
1109
11.8k
    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
1110
11.8k
  }
1111
1112
806k
  static bool classof(const Stmt *T) {
1113
806k
    return T->getStmtClass() == SwitchStmtClass;
1114
806k
  }
1115
};
1116
1117
/// WhileStmt - This represents a 'while' stmt.
1118
class WhileStmt : public Stmt {
1119
  SourceLocation WhileLoc;
1120
  enum { VAR, COND, BODY, END_EXPR };
1121
  Stmt* SubExprs[END_EXPR];
1122
1123
public:
1124
  WhileStmt(const ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body,
1125
            SourceLocation WL);
1126
1127
  /// Build an empty while statement.
1128
12
  explicit WhileStmt(EmptyShell Empty) : Stmt(WhileStmtClass, Empty) {}
1129
1130
  /// Retrieve the variable declared in this "while" statement, if any.
1131
  ///
1132
  /// In the following example, "x" is the condition variable.
1133
  /// \code
1134
  /// while (int x = random()) {
1135
  ///   // ...
1136
  /// }
1137
  /// \endcode
1138
  VarDecl *getConditionVariable() const;
1139
  void setConditionVariable(const ASTContext &C, VarDecl *V);
1140
1141
  /// If this WhileStmt has a condition variable, return the faux DeclStmt
1142
  /// associated with the creation of that condition variable.
1143
70
  const DeclStmt *getConditionVariableDeclStmt() const {
1144
70
    return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
1145
70
  }
1146
1147
27.4k
  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
1148
29.5k
  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
1149
12
  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
1150
9.75k
  Stmt *getBody() { return SubExprs[BODY]; }
1151
19.9k
  const Stmt *getBody() const { return SubExprs[BODY]; }
1152
12
  void setBody(Stmt *S) { SubExprs[BODY] = S; }
1153
1154
6.15k
  SourceLocation getWhileLoc() const { return WhileLoc; }
1155
12
  void setWhileLoc(SourceLocation L) { WhileLoc = L; }
1156
1157
14.5k
  SourceLocation getLocStart() const LLVM_READONLY { return WhileLoc; }
1158
1159
8.56k
  SourceLocation getLocEnd() const LLVM_READONLY {
1160
8.56k
    return SubExprs[BODY]->getLocEnd();
1161
8.56k
  }
1162
1163
60.6k
  static bool classof(const Stmt *T) {
1164
60.6k
    return T->getStmtClass() == WhileStmtClass;
1165
60.6k
  }
1166
1167
  // Iterators
1168
19.6k
  child_range children() {
1169
19.6k
    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
1170
19.6k
  }
1171
};
1172
1173
/// DoStmt - This represents a 'do/while' stmt.
1174
class DoStmt : public Stmt {
1175
  SourceLocation DoLoc;
1176
  enum { BODY, COND, END_EXPR };
1177
  Stmt* SubExprs[END_EXPR];
1178
  SourceLocation WhileLoc;
1179
  SourceLocation RParenLoc;  // Location of final ')' in do stmt condition.
1180
1181
public:
1182
  DoStmt(Stmt *body, Expr *cond, SourceLocation DL, SourceLocation WL,
1183
         SourceLocation RP)
1184
148k
    : Stmt(DoStmtClass), DoLoc(DL), WhileLoc(WL), RParenLoc(RP) {
1185
148k
    SubExprs[COND] = reinterpret_cast<Stmt*>(cond);
1186
148k
    SubExprs[BODY] = body;
1187
148k
  }
1188
1189
  /// Build an empty do-while statement.
1190
1
  explicit DoStmt(EmptyShell Empty) : Stmt(DoStmtClass, Empty) {}
1191
1192
144k
  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
1193
31.2k
  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
1194
1
  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
1195
143k
  Stmt *getBody() { return SubExprs[BODY]; }
1196
31.0k
  const Stmt *getBody() const { return SubExprs[BODY]; }
1197
1
  void setBody(Stmt *S) { SubExprs[BODY] = S; }
1198
1199
15.3k
  SourceLocation getDoLoc() const { return DoLoc; }
1200
1
  void setDoLoc(SourceLocation L) { DoLoc = L; }
1201
30.5k
  SourceLocation getWhileLoc() const { return WhileLoc; }
1202
1
  void setWhileLoc(SourceLocation L) { WhileLoc = L; }
1203
1204
15.3k
  SourceLocation getRParenLoc() const { return RParenLoc; }
1205
1
  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1206
1207
56.5k
  SourceLocation getLocStart() const LLVM_READONLY { return DoLoc; }
1208
29.4k
  SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
1209
1210
43.0k
  static bool classof(const Stmt *T) {
1211
43.0k
    return T->getStmtClass() == DoStmtClass;
1212
43.0k
  }
1213
1214
  // Iterators
1215
33.5k
  child_range children() {
1216
33.5k
    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
1217
33.5k
  }
1218
};
1219
1220
/// ForStmt - This represents a 'for (init;cond;inc)' stmt.  Note that any of
1221
/// the init/cond/inc parts of the ForStmt will be null if they were not
1222
/// specified in the source.
1223
class ForStmt : public Stmt {
1224
  SourceLocation ForLoc;
1225
  enum { INIT, CONDVAR, COND, INC, BODY, END_EXPR };
1226
  Stmt* SubExprs[END_EXPR]; // SubExprs[INIT] is an expression or declstmt.
1227
  SourceLocation LParenLoc, RParenLoc;
1228
1229
public:
1230
  ForStmt(const ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar,
1231
          Expr *Inc, Stmt *Body, SourceLocation FL, SourceLocation LP,
1232
          SourceLocation RP);
1233
1234
  /// Build an empty for statement.
1235
4.56k
  explicit ForStmt(EmptyShell Empty) : Stmt(ForStmtClass, Empty) {}
1236
1237
203k
  Stmt *getInit() { return SubExprs[INIT]; }
1238
1239
  /// Retrieve the variable declared in this "for" statement, if any.
1240
  ///
1241
  /// In the following example, "y" is the condition variable.
1242
  /// \code
1243
  /// for (int x = random(); int y = mangle(x); ++x) {
1244
  ///   // ...
1245
  /// }
1246
  /// \endcode
1247
  VarDecl *getConditionVariable() const;
1248
  void setConditionVariable(const ASTContext &C, VarDecl *V);
1249
1250
  /// If this ForStmt has a condition variable, return the faux DeclStmt
1251
  /// associated with the creation of that condition variable.
1252
38
  const DeclStmt *getConditionVariableDeclStmt() const {
1253
38
    return reinterpret_cast<DeclStmt*>(SubExprs[CONDVAR]);
1254
38
  }
1255
1256
213k
  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
1257
186k
  Expr *getInc()  { return reinterpret_cast<Expr*>(SubExprs[INC]); }
1258
168k
  Stmt *getBody() { return SubExprs[BODY]; }
1259
1260
66.9k
  const Stmt *getInit() const { return SubExprs[INIT]; }
1261
160k
  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
1262
157k
  const Expr *getInc()  const { return reinterpret_cast<Expr*>(SubExprs[INC]); }
1263
103k
  const Stmt *getBody() const { return SubExprs[BODY]; }
1264
1265
4.56k
  void setInit(Stmt *S) { SubExprs[INIT] = S; }
1266
4.56k
  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
1267
4.56k
  void setInc(Expr *E) { SubExprs[INC] = reinterpret_cast<Stmt*>(E); }
1268
4.56k
  void setBody(Stmt *S) { SubExprs[BODY] = S; }
1269
1270
189k
  SourceLocation getForLoc() const { return ForLoc; }
1271
4.56k
  void setForLoc(SourceLocation L) { ForLoc = L; }
1272
43.9k
  SourceLocation getLParenLoc() const { return LParenLoc; }
1273
4.56k
  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
1274
45.6k
  SourceLocation getRParenLoc() const { return RParenLoc; }
1275
4.56k
  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1276
1277
310k
  SourceLocation getLocStart() const LLVM_READONLY { return ForLoc; }
1278
1279
114k
  SourceLocation getLocEnd() const LLVM_READONLY {
1280
114k
    return SubExprs[BODY]->getLocEnd();
1281
114k
  }
1282
1283
152k
  static bool classof(const Stmt *T) {
1284
152k
    return T->getStmtClass() == ForStmtClass;
1285
152k
  }
1286
1287
  // Iterators
1288
97.6k
  child_range children() {
1289
97.6k
    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
1290
97.6k
  }
1291
};
1292
1293
/// GotoStmt - This represents a direct goto.
1294
class GotoStmt : public Stmt {
1295
  LabelDecl *Label;
1296
  SourceLocation GotoLoc;
1297
  SourceLocation LabelLoc;
1298
1299
public:
1300
  GotoStmt(LabelDecl *label, SourceLocation GL, SourceLocation LL)
1301
8.32k
      : Stmt(GotoStmtClass), Label(label), GotoLoc(GL), LabelLoc(LL) {}
1302
1303
  /// Build an empty goto statement.
1304
2
  explicit GotoStmt(EmptyShell Empty) : Stmt(GotoStmtClass, Empty) {}
1305
1306
21.5k
  LabelDecl *getLabel() const { return Label; }
1307
2
  void setLabel(LabelDecl *D) { Label = D; }
1308
1309
3.66k
  SourceLocation getGotoLoc() const { return GotoLoc; }
1310
2
  void setGotoLoc(SourceLocation L) { GotoLoc = L; }
1311
356
  SourceLocation getLabelLoc() const { return LabelLoc; }
1312
2
  void setLabelLoc(SourceLocation L) { LabelLoc = L; }
1313
1314
316
  SourceLocation getLocStart() const LLVM_READONLY { return GotoLoc; }
1315
117
  SourceLocation getLocEnd() const LLVM_READONLY { return LabelLoc; }
1316
1317
22.0k
  static bool classof(const Stmt *T) {
1318
22.0k
    return T->getStmtClass() == GotoStmtClass;
1319
22.0k
  }
1320
1321
  // Iterators
1322
8.84k
  child_range children() {
1323
8.84k
    return child_range(child_iterator(), child_iterator());
1324
8.84k
  }
1325
};
1326
1327
/// IndirectGotoStmt - This represents an indirect goto.
1328
class IndirectGotoStmt : public Stmt {
1329
  SourceLocation GotoLoc;
1330
  SourceLocation StarLoc;
1331
  Stmt *Target;
1332
1333
public:
1334
  IndirectGotoStmt(SourceLocation gotoLoc, SourceLocation starLoc,
1335
                   Expr *target)
1336
    : Stmt(IndirectGotoStmtClass), GotoLoc(gotoLoc), StarLoc(starLoc),
1337
135
      Target((Stmt*)target) {}
1338
1339
  /// Build an empty indirect goto statement.
1340
  explicit IndirectGotoStmt(EmptyShell Empty)
1341
1
      : Stmt(IndirectGotoStmtClass, Empty) {}
1342
1343
1
  void setGotoLoc(SourceLocation L) { GotoLoc = L; }
1344
40
  SourceLocation getGotoLoc() const { return GotoLoc; }
1345
1
  void setStarLoc(SourceLocation L) { StarLoc = L; }
1346
3
  SourceLocation getStarLoc() const { return StarLoc; }
1347
1348
234
  Expr *getTarget() { return reinterpret_cast<Expr*>(Target); }
1349
61
  const Expr *getTarget() const {return reinterpret_cast<const Expr*>(Target);}
1350
1
  void setTarget(Expr *E) { Target = reinterpret_cast<Stmt*>(E); }
1351
1352
  /// getConstantTarget - Returns the fixed target of this indirect
1353
  /// goto, if one exists.
1354
  LabelDecl *getConstantTarget();
1355
53
  const LabelDecl *getConstantTarget() const {
1356
53
    return const_cast<IndirectGotoStmt*>(this)->getConstantTarget();
1357
53
  }
1358
1359
12
  SourceLocation getLocStart() const LLVM_READONLY { return GotoLoc; }
1360
6
  SourceLocation getLocEnd() const LLVM_READONLY { return Target->getLocEnd(); }
1361
1362
7.20k
  static bool classof(const Stmt *T) {
1363
7.20k
    return T->getStmtClass() == IndirectGotoStmtClass;
1364
7.20k
  }
1365
1366
  // Iterators
1367
155
  child_range children() { return child_range(&Target, &Target+1); }
1368
};
1369
1370
/// ContinueStmt - This represents a continue.
1371
class ContinueStmt : public Stmt {
1372
  SourceLocation ContinueLoc;
1373
1374
public:
1375
7.17k
  ContinueStmt(SourceLocation CL) : Stmt(ContinueStmtClass), ContinueLoc(CL) {}
1376
1377
  /// Build an empty continue statement.
1378
1
  explicit ContinueStmt(EmptyShell Empty) : Stmt(ContinueStmtClass, Empty) {}
1379
1380
18
  SourceLocation getContinueLoc() const { return ContinueLoc; }
1381
1
  void setContinueLoc(SourceLocation L) { ContinueLoc = L; }
1382
1383
1.35k
  SourceLocation getLocStart() const LLVM_READONLY { return ContinueLoc; }
1384
37
  SourceLocation getLocEnd() const LLVM_READONLY { return ContinueLoc; }
1385
1386
5.79k
  static bool classof(const Stmt *T) {
1387
5.79k
    return T->getStmtClass() == ContinueStmtClass;
1388
5.79k
  }
1389
1390
  // Iterators
1391
4.07k
  child_range children() {
1392
4.07k
    return child_range(child_iterator(), child_iterator());
1393
4.07k
  }
1394
};
1395
1396
/// BreakStmt - This represents a break.
1397
class BreakStmt : public Stmt {
1398
  SourceLocation BreakLoc;
1399
1400
public:
1401
58.4k
  BreakStmt(SourceLocation BL) : Stmt(BreakStmtClass), BreakLoc(BL) {
1402
58.4k
    static_assert(sizeof(BreakStmt) == 2 * sizeof(SourceLocation),
1403
58.4k
                  "BreakStmt too large");
1404
58.4k
  }
1405
1406
  /// Build an empty break statement.
1407
17
  explicit BreakStmt(EmptyShell Empty) : Stmt(BreakStmtClass, Empty) {}
1408
1409
51
  SourceLocation getBreakLoc() const { return BreakLoc; }
1410
17
  void setBreakLoc(SourceLocation L) { BreakLoc = L; }
1411
1412
4.14k
  SourceLocation getLocStart() const LLVM_READONLY { return BreakLoc; }
1413
691
  SourceLocation getLocEnd() const LLVM_READONLY { return BreakLoc; }
1414
1415
32.2k
  static bool classof(const Stmt *T) {
1416
32.2k
    return T->getStmtClass() == BreakStmtClass;
1417
32.2k
  }
1418
1419
  // Iterators
1420
41.4k
  child_range children() {
1421
41.4k
    return child_range(child_iterator(), child_iterator());
1422
41.4k
  }
1423
};
1424
1425
/// ReturnStmt - This represents a return, optionally of an expression:
1426
///   return;
1427
///   return 4;
1428
///
1429
/// Note that GCC allows return with no argument in a function declared to
1430
/// return a value, and it allows returning a value in functions declared to
1431
/// return void.  We explicitly model this in the AST, which means you can't
1432
/// depend on the return type of the function and the presence of an argument.
1433
class ReturnStmt : public Stmt {
1434
  SourceLocation RetLoc;
1435
  Stmt *RetExpr;
1436
  const VarDecl *NRVOCandidate;
1437
1438
public:
1439
8
  explicit ReturnStmt(SourceLocation RL) : ReturnStmt(RL, nullptr, nullptr) {}
1440
1441
  ReturnStmt(SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
1442
      : Stmt(ReturnStmtClass), RetLoc(RL), RetExpr((Stmt *)E),
1443
2.45M
        NRVOCandidate(NRVOCandidate) {}
1444
1445
  /// Build an empty return expression.
1446
3.25k
  explicit ReturnStmt(EmptyShell Empty) : Stmt(ReturnStmtClass, Empty) {}
1447
1448
  const Expr *getRetValue() const;
1449
  Expr *getRetValue();
1450
3.27k
  void setRetValue(Expr *E) { RetExpr = reinterpret_cast<Stmt*>(E); }
1451
1452
234k
  SourceLocation getReturnLoc() const { return RetLoc; }
1453
3.25k
  void setReturnLoc(SourceLocation L) { RetLoc = L; }
1454
1455
  /// Retrieve the variable that might be used for the named return
1456
  /// value optimization.
1457
  ///
1458
  /// The optimization itself can only be performed if the variable is
1459
  /// also marked as an NRVO object.
1460
4.92M
  const VarDecl *getNRVOCandidate() const { return NRVOCandidate; }
1461
3.47k
  void setNRVOCandidate(const VarDecl *Var) { NRVOCandidate = Var; }
1462
1463
266k
  SourceLocation getLocStart() const LLVM_READONLY { return RetLoc; }
1464
1465
40.6k
  SourceLocation getLocEnd() const LLVM_READONLY {
1466
40.6k
    return RetExpr ? 
RetExpr->getLocEnd()38.5k
:
RetLoc2.09k
;
1467
40.6k
  }
1468
1469
1.73M
  static bool classof(const Stmt *T) {
1470
1.73M
    return T->getStmtClass() == ReturnStmtClass;
1471
1.73M
  }
1472
1473
  // Iterators
1474
637k
  child_range children() {
1475
637k
    if (RetExpr) 
return child_range(&RetExpr, &RetExpr+1)597k
;
1476
39.5k
    return child_range(child_iterator(), child_iterator());
1477
39.5k
  }
1478
};
1479
1480
/// AsmStmt is the base class for GCCAsmStmt and MSAsmStmt.
1481
class AsmStmt : public Stmt {
1482
protected:
1483
  friend class ASTStmtReader;
1484
1485
  SourceLocation AsmLoc;
1486
1487
  /// True if the assembly statement does not have any input or output
1488
  /// operands.
1489
  bool IsSimple;
1490
1491
  /// If true, treat this inline assembly as having side effects.
1492
  /// This assembly statement should not be optimized, deleted or moved.
1493
  bool IsVolatile;
1494
1495
  unsigned NumOutputs;
1496
  unsigned NumInputs;
1497
  unsigned NumClobbers;
1498
1499
  Stmt **Exprs = nullptr;
1500
1501
  AsmStmt(StmtClass SC, SourceLocation asmloc, bool issimple, bool isvolatile,
1502
          unsigned numoutputs, unsigned numinputs, unsigned numclobbers)
1503
      : Stmt (SC), AsmLoc(asmloc), IsSimple(issimple), IsVolatile(isvolatile),
1504
        NumOutputs(numoutputs), NumInputs(numinputs),
1505
25.5k
        NumClobbers(numclobbers) {}
1506
1507
public:
1508
  /// Build an empty inline-assembly statement.
1509
2
  explicit AsmStmt(StmtClass SC, EmptyShell Empty) : Stmt(SC, Empty) {}
1510
1511
4.93k
  SourceLocation getAsmLoc() const { return AsmLoc; }
1512
2
  void setAsmLoc(SourceLocation L) { AsmLoc = L; }
1513
1514
38.3k
  bool isSimple() const { return IsSimple; }
1515
2
  void setSimple(bool V) { IsSimple = V; }
1516
1517
13.1k
  bool isVolatile() const { return IsVolatile; }
1518
2
  void setVolatile(bool V) { IsVolatile = V; }
1519
1520
  SourceLocation getLocStart() const LLVM_READONLY { return {}; }
1521
  SourceLocation getLocEnd() const LLVM_READONLY { return {}; }
1522
1523
  //===--- Asm String Analysis ---===//
1524
1525
  /// Assemble final IR asm string.
1526
  std::string generateAsmString(const ASTContext &C) const;
1527
1528
  //===--- Output operands ---===//
1529
1530
102k
  unsigned getNumOutputs() const { return NumOutputs; }
1531
1532
  /// getOutputConstraint - Return the constraint string for the specified
1533
  /// output operand.  All output constraints are known to be non-empty (either
1534
  /// '=' or '+').
1535
  StringRef getOutputConstraint(unsigned i) const;
1536
1537
  /// isOutputPlusConstraint - Return true if the specified output constraint
1538
  /// is a "+" constraint (which is both an input and an output) or false if it
1539
  /// is an "=" constraint (just an output).
1540
16.3k
  bool isOutputPlusConstraint(unsigned i) const {
1541
16.3k
    return getOutputConstraint(i)[0] == '+';
1542
16.3k
  }
1543
1544
  const Expr *getOutputExpr(unsigned i) const;
1545
1546
  /// getNumPlusOperands - Return the number of output operands that have a "+"
1547
  /// constraint.
1548
  unsigned getNumPlusOperands() const;
1549
1550
  //===--- Input operands ---===//
1551
1552
85.0k
  unsigned getNumInputs() const { return NumInputs; }
1553
1554
  /// getInputConstraint - Return the specified input constraint.  Unlike output
1555
  /// constraints, these can be empty.
1556
  StringRef getInputConstraint(unsigned i) const;
1557
  
1558
  const Expr *getInputExpr(unsigned i) const;
1559
1560
  //===--- Other ---===//
1561
1562
13.3k
  unsigned getNumClobbers() const { return NumClobbers; }
1563
  StringRef getClobber(unsigned i) const;
1564
1565
21
  static bool classof(const Stmt *T) {
1566
21
    return T->getStmtClass() == GCCAsmStmtClass ||
1567
21
      
T->getStmtClass() == MSAsmStmtClass11
;
1568
21
  }
1569
1570
  // Input expr iterators.
1571
1572
  using inputs_iterator = ExprIterator;
1573
  using const_inputs_iterator = ConstExprIterator;
1574
  using inputs_range = llvm::iterator_range<inputs_iterator>;
1575
  using inputs_const_range = llvm::iterator_range<const_inputs_iterator>;
1576
1577
2
  inputs_iterator begin_inputs() {
1578
2
    return &Exprs[0] + NumOutputs;
1579
2
  }
1580
1581
2
  inputs_iterator end_inputs() {
1582
2
    return &Exprs[0] + NumOutputs + NumInputs;
1583
2
  }
1584
1585
2
  inputs_range inputs() { return inputs_range(begin_inputs(), end_inputs()); }
1586
1587
0
  const_inputs_iterator begin_inputs() const {
1588
0
    return &Exprs[0] + NumOutputs;
1589
0
  }
1590
1591
0
  const_inputs_iterator end_inputs() const {
1592
0
    return &Exprs[0] + NumOutputs + NumInputs;
1593
0
  }
1594
1595
0
  inputs_const_range inputs() const {
1596
0
    return inputs_const_range(begin_inputs(), end_inputs());
1597
0
  }
1598
1599
  // Output expr iterators.
1600
1601
  using outputs_iterator = ExprIterator;
1602
  using const_outputs_iterator = ConstExprIterator;
1603
  using outputs_range = llvm::iterator_range<outputs_iterator>;
1604
  using outputs_const_range = llvm::iterator_range<const_outputs_iterator>;
1605
1606
2
  outputs_iterator begin_outputs() {
1607
2
    return &Exprs[0];
1608
2
  }
1609
1610
2
  outputs_iterator end_outputs() {
1611
2
    return &Exprs[0] + NumOutputs;
1612
2
  }
1613
1614
2
  outputs_range outputs() {
1615
2
    return outputs_range(begin_outputs(), end_outputs());
1616
2
  }
1617
1618
0
  const_outputs_iterator begin_outputs() const {
1619
0
    return &Exprs[0];
1620
0
  }
1621
1622
0
  const_outputs_iterator end_outputs() const {
1623
0
    return &Exprs[0] + NumOutputs;
1624
0
  }
1625
1626
0
  outputs_const_range outputs() const {
1627
0
    return outputs_const_range(begin_outputs(), end_outputs());
1628
0
  }
1629
1630
47.3k
  child_range children() {
1631
47.3k
    return child_range(&Exprs[0], &Exprs[0] + NumOutputs + NumInputs);
1632
47.3k
  }
1633
};
1634
1635
/// This represents a GCC inline-assembly statement extension.
1636
class GCCAsmStmt : public AsmStmt {
1637
  friend class ASTStmtReader;
1638
1639
  SourceLocation RParenLoc;
1640
  StringLiteral *AsmStr;
1641
1642
  // FIXME: If we wanted to, we could allocate all of these in one big array.
1643
  StringLiteral **Constraints = nullptr;
1644
  StringLiteral **Clobbers = nullptr;
1645
  IdentifierInfo **Names = nullptr;
1646
1647
public:
1648
  GCCAsmStmt(const ASTContext &C, SourceLocation asmloc, bool issimple,
1649
             bool isvolatile, unsigned numoutputs, unsigned numinputs,
1650
             IdentifierInfo **names, StringLiteral **constraints, Expr **exprs,
1651
             StringLiteral *asmstr, unsigned numclobbers,
1652
             StringLiteral **clobbers, SourceLocation rparenloc);
1653
1654
  /// Build an empty inline-assembly statement.
1655
2
  explicit GCCAsmStmt(EmptyShell Empty) : AsmStmt(GCCAsmStmtClass, Empty) {}
1656
1657
4.78k
  SourceLocation getRParenLoc() const { return RParenLoc; }
1658
2
  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1659
1660
  //===--- Asm String Analysis ---===//
1661
1662
75.0k
  const StringLiteral *getAsmString() const { return AsmStr; }
1663
4.80k
  StringLiteral *getAsmString() { return AsmStr; }
1664
2
  void setAsmString(StringLiteral *E) { AsmStr = E; }
1665
1666
  /// AsmStringPiece - this is part of a decomposed asm string specification
1667
  /// (for use with the AnalyzeAsmString function below).  An asm string is
1668
  /// considered to be a concatenation of these parts.
1669
  class AsmStringPiece {
1670
  public:
1671
    enum Kind {
1672
      String,  // String in .ll asm string form, "$" -> "$$" and "%%" -> "%".
1673
      Operand  // Operand reference, with optional modifier %c4.
1674
    };
1675
1676
  private:
1677
    Kind MyKind;
1678
    std::string Str;
1679
    unsigned OperandNo;
1680
1681
    // Source range for operand references.
1682
    CharSourceRange Range;
1683
1684
  public:
1685
26.2k
    AsmStringPiece(const std::string &S) : MyKind(String), Str(S) {}
1686
    AsmStringPiece(unsigned OpNo, const std::string &S, SourceLocation Begin,
1687
                   SourceLocation End)
1688
        : MyKind(Operand), Str(S), OperandNo(OpNo),
1689
16.6k
          Range(CharSourceRange::getCharRange(Begin, End)) {}
1690
1691
3.65k
    bool isString() const { return MyKind == String; }
1692
39.2k
    bool isOperand() const { return MyKind == Operand; }
1693
1694
2.15k
    const std::string &getString() const { return Str; }
1695
1696
16.6k
    unsigned getOperandNo() const {
1697
16.6k
      assert(isOperand());
1698
16.6k
      return OperandNo;
1699
16.6k
    }
1700
1701
22
    CharSourceRange getRange() const {
1702
22
      assert(isOperand() && "Range is currently used only for Operands.");
1703
22
      return Range;
1704
22
    }
1705
1706
    /// getModifier - Get the modifier for this operand, if present.  This
1707
    /// returns '\0' if there was no modifier.
1708
    char getModifier() const;
1709
  };
1710
1711
  /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing
1712
  /// it into pieces.  If the asm string is erroneous, emit errors and return
1713
  /// true, otherwise return false.  This handles canonicalization and
1714
  /// translation of strings from GCC syntax to LLVM IR syntax, and handles
1715
  //// flattening of named references like %[foo] to Operand AsmStringPiece's.
1716
  unsigned AnalyzeAsmString(SmallVectorImpl<AsmStringPiece> &Pieces,
1717
                            const ASTContext &C, unsigned &DiagOffs) const;
1718
1719
  /// Assemble final IR asm string.
1720
  std::string generateAsmString(const ASTContext &C) const;
1721
1722
  //===--- Output operands ---===//
1723
1724
6.03k
  IdentifierInfo *getOutputIdentifier(unsigned i) const { return Names[i]; }
1725
1726
1.22k
  StringRef getOutputName(unsigned i) const {
1727
1.22k
    if (IdentifierInfo *II = getOutputIdentifier(i))
1728
104
      return II->getName();
1729
1.12k
1730
1.12k
    return {};
1731
1.12k
  }
1732
1733
  StringRef getOutputConstraint(unsigned i) const;
1734
1735
18.5k
  const StringLiteral *getOutputConstraintLiteral(unsigned i) const {
1736
18.5k
    return Constraints[i];
1737
18.5k
  }
1738
4.81k
  StringLiteral *getOutputConstraintLiteral(unsigned i) {
1739
4.81k
    return Constraints[i];
1740
4.81k
  }
1741
1742
  Expr *getOutputExpr(unsigned i);
1743
1744
1.16k
  const Expr *getOutputExpr(unsigned i) const {
1745
1.16k
    return const_cast<GCCAsmStmt*>(this)->getOutputExpr(i);
1746
1.16k
  }
1747
1748
  //===--- Input operands ---===//
1749
1750
5.95k
  IdentifierInfo *getInputIdentifier(unsigned i) const {
1751
5.95k
    return Names[i + NumOutputs];
1752
5.95k
  }
1753
1754
1.12k
  StringRef getInputName(unsigned i) const {
1755
1.12k
    if (IdentifierInfo *II = getInputIdentifier(i))
1756
48
      return II->getName();
1757
1.07k
1758
1.07k
    return {};
1759
1.07k
  }
1760
1761
  StringRef getInputConstraint(unsigned i) const;
1762
1763
2.09k
  const StringLiteral *getInputConstraintLiteral(unsigned i) const {
1764
2.09k
    return Constraints[i + NumOutputs];
1765
2.09k
  }
1766
4.83k
  StringLiteral *getInputConstraintLiteral(unsigned i) {
1767
4.83k
    return Constraints[i + NumOutputs];
1768
4.83k
  }
1769
1770
  Expr *getInputExpr(unsigned i);
1771
  void setInputExpr(unsigned i, Expr *E);
1772
1773
1.03k
  const Expr *getInputExpr(unsigned i) const {
1774
1.03k
    return const_cast<GCCAsmStmt*>(this)->getInputExpr(i);
1775
1.03k
  }
1776
1777
private:
1778
  void setOutputsAndInputsAndClobbers(const ASTContext &C,
1779
                                      IdentifierInfo **Names,
1780
                                      StringLiteral **Constraints,
1781
                                      Stmt **Exprs,
1782
                                      unsigned NumOutputs,
1783
                                      unsigned NumInputs,
1784
                                      StringLiteral **Clobbers,
1785
                                      unsigned NumClobbers);
1786
1787
public:
1788
  //===--- Other ---===//
1789
1790
  /// getNamedOperand - Given a symbolic operand reference like %[foo],
1791
  /// translate this into a numeric value needed to reference the same operand.
1792
  /// This returns -1 if the operand name is invalid.
1793
  int getNamedOperand(StringRef SymbolicName) const;
1794
1795
  StringRef getClobber(unsigned i) const;
1796
1797
79.6k
  StringLiteral *getClobberStringLiteral(unsigned i) { return Clobbers[i]; }
1798
7.43k
  const StringLiteral *getClobberStringLiteral(unsigned i) const {
1799
7.43k
    return Clobbers[i];
1800
7.43k
  }
1801
1802
7.14k
  SourceLocation getLocStart() const LLVM_READONLY { return AsmLoc; }
1803
575
  SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
1804
1805
49.4k
  static bool classof(const Stmt *T) {
1806
49.4k
    return T->getStmtClass() == GCCAsmStmtClass;
1807
49.4k
  }
1808
};
1809
1810
/// This represents a Microsoft inline-assembly statement extension.
1811
class MSAsmStmt : public AsmStmt {
1812
  friend class ASTStmtReader;
1813
1814
  SourceLocation LBraceLoc, EndLoc;
1815
  StringRef AsmStr;
1816
1817
  unsigned NumAsmToks = 0;
1818
1819
  Token *AsmToks = nullptr;
1820
  StringRef *Constraints = nullptr;
1821
  StringRef *Clobbers = nullptr;
1822
1823
public:
1824
  MSAsmStmt(const ASTContext &C, SourceLocation asmloc,
1825
            SourceLocation lbraceloc, bool issimple, bool isvolatile,
1826
            ArrayRef<Token> asmtoks, unsigned numoutputs, unsigned numinputs,
1827
            ArrayRef<StringRef> constraints,
1828
            ArrayRef<Expr*> exprs, StringRef asmstr,
1829
            ArrayRef<StringRef> clobbers, SourceLocation endloc);
1830
1831
  /// Build an empty MS-style inline-assembly statement.
1832
0
  explicit MSAsmStmt(EmptyShell Empty) : AsmStmt(MSAsmStmtClass, Empty) {}
1833
1834
1
  SourceLocation getLBraceLoc() const { return LBraceLoc; }
1835
0
  void setLBraceLoc(SourceLocation L) { LBraceLoc = L; }
1836
1
  SourceLocation getEndLoc() const { return EndLoc; }
1837
0
  void setEndLoc(SourceLocation L) { EndLoc = L; }
1838
1839
0
  bool hasBraces() const { return LBraceLoc.isValid(); }
1840
1841
1
  unsigned getNumAsmToks() { return NumAsmToks; }
1842
1
  Token *getAsmToks() { return AsmToks; }
1843
1844
  //===--- Asm String Analysis ---===//
1845
1
  StringRef getAsmString() const { return AsmStr; }
1846
1847
  /// Assemble final IR asm string.
1848
  std::string generateAsmString(const ASTContext &C) const;
1849
1850
  //===--- Output operands ---===//
1851
1852
40
  StringRef getOutputConstraint(unsigned i) const {
1853
40
    assert(i < NumOutputs);
1854
40
    return Constraints[i];
1855
40
  }
1856
1857
  Expr *getOutputExpr(unsigned i);
1858
1859
20
  const Expr *getOutputExpr(unsigned i) const {
1860
20
    return const_cast<MSAsmStmt*>(this)->getOutputExpr(i);
1861
20
  }
1862
1863
  //===--- Input operands ---===//
1864
1865
206
  StringRef getInputConstraint(unsigned i) const {
1866
206
    assert(i < NumInputs);
1867
206
    return Constraints[i + NumOutputs];
1868
206
  }
1869
1870
  Expr *getInputExpr(unsigned i);
1871
  void setInputExpr(unsigned i, Expr *E);
1872
1873
103
  const Expr *getInputExpr(unsigned i) const {
1874
103
    return const_cast<MSAsmStmt*>(this)->getInputExpr(i);
1875
103
  }
1876
1877
  //===--- Other ---===//
1878
1879
1
  ArrayRef<StringRef> getAllConstraints() const {
1880
1
    return llvm::makeArrayRef(Constraints, NumInputs + NumOutputs);
1881
1
  }
1882
1883
187
  ArrayRef<StringRef> getClobbers() const {
1884
187
    return llvm::makeArrayRef(Clobbers, NumClobbers);
1885
187
  }
1886
1887
1
  ArrayRef<Expr*> getAllExprs() const {
1888
1
    return llvm::makeArrayRef(reinterpret_cast<Expr**>(Exprs),
1889
1
                              NumInputs + NumOutputs);
1890
1
  }
1891
1892
186
  StringRef getClobber(unsigned i) const { return getClobbers()[i]; }
1893
1894
private:
1895
  void initialize(const ASTContext &C, StringRef AsmString,
1896
                  ArrayRef<Token> AsmToks, ArrayRef<StringRef> Constraints,
1897
                  ArrayRef<Expr*> Exprs, ArrayRef<StringRef> Clobbers);
1898
1899
public:
1900
0
  SourceLocation getLocStart() const LLVM_READONLY { return AsmLoc; }
1901
0
  SourceLocation getLocEnd() const LLVM_READONLY { return EndLoc; }
1902
1903
17.6k
  static bool classof(const Stmt *T) {
1904
17.6k
    return T->getStmtClass() == MSAsmStmtClass;
1905
17.6k
  }
1906
1907
35
  child_range children() {
1908
35
    return child_range(&Exprs[0], &Exprs[NumInputs + NumOutputs]);
1909
35
  }
1910
};
1911
1912
class SEHExceptStmt : public Stmt {
1913
  friend class ASTReader;
1914
  friend class ASTStmtReader;
1915
1916
  SourceLocation  Loc;
1917
  Stmt *Children[2];
1918
1919
  enum { FILTER_EXPR, BLOCK };
1920
1921
  SEHExceptStmt(SourceLocation Loc, Expr *FilterExpr, Stmt *Block);
1922
1
  explicit SEHExceptStmt(EmptyShell E) : Stmt(SEHExceptStmtClass, E) {}
1923
1924
public:
1925
  static SEHExceptStmt* Create(const ASTContext &C,
1926
                               SourceLocation ExceptLoc,
1927
                               Expr *FilterExpr,
1928
                               Stmt *Block);
1929
1930
24
  SourceLocation getLocStart() const LLVM_READONLY { return getExceptLoc(); }
1931
48
  SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); }
1932
1933
28
  SourceLocation getExceptLoc() const { return Loc; }
1934
48
  SourceLocation getEndLoc() const { return getBlock()->getLocEnd(); }
1935
1936
72
  Expr *getFilterExpr() const {
1937
72
    return reinterpret_cast<Expr*>(Children[FILTER_EXPR]);
1938
72
  }
1939
1940
156
  CompoundStmt *getBlock() const {
1941
156
    return cast<CompoundStmt>(Children[BLOCK]);
1942
156
  }
1943
1944
5
  child_range children() {
1945
5
    return child_range(Children, Children+2);
1946
5
  }
1947
1948
202
  static bool classof(const Stmt *T) {
1949
202
    return T->getStmtClass() == SEHExceptStmtClass;
1950
202
  }
1951
};
1952
1953
class SEHFinallyStmt : public Stmt {
1954
  friend class ASTReader;
1955
  friend class ASTStmtReader;
1956
1957
  SourceLocation  Loc;
1958
  Stmt *Block;
1959
1960
  SEHFinallyStmt(SourceLocation Loc, Stmt *Block);
1961
0
  explicit SEHFinallyStmt(EmptyShell E) : Stmt(SEHFinallyStmtClass, E) {}
1962
1963
public:
1964
  static SEHFinallyStmt* Create(const ASTContext &C,
1965
                                SourceLocation FinallyLoc,
1966
                                Stmt *Block);
1967
1968
52
  SourceLocation getLocStart() const LLVM_READONLY { return getFinallyLoc(); }
1969
104
  SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); }
1970
1971
53
  SourceLocation getFinallyLoc() const { return Loc; }
1972
104
  SourceLocation getEndLoc() const { return Block->getLocEnd(); }
1973
1974
106
  CompoundStmt *getBlock() const { return cast<CompoundStmt>(Block); }
1975
1976
7
  child_range children() {
1977
7
    return child_range(&Block,&Block+1);
1978
7
  }
1979
1980
304
  static bool classof(const Stmt *T) {
1981
304
    return T->getStmtClass() == SEHFinallyStmtClass;
1982
304
  }
1983
};
1984
1985
class SEHTryStmt : public Stmt {
1986
  friend class ASTReader;
1987
  friend class ASTStmtReader;
1988
1989
  bool IsCXXTry;
1990
  SourceLocation  TryLoc;
1991
  Stmt *Children[2];
1992
1993
  enum { TRY = 0, HANDLER = 1 };
1994
1995
  SEHTryStmt(bool isCXXTry, // true if 'try' otherwise '__try'
1996
             SourceLocation TryLoc,
1997
             Stmt *TryBlock,
1998
             Stmt *Handler);
1999
2000
1
  explicit SEHTryStmt(EmptyShell E) : Stmt(SEHTryStmtClass, E) {}
2001
2002
public:
2003
  static SEHTryStmt* Create(const ASTContext &C, bool isCXXTry,
2004
                            SourceLocation TryLoc, Stmt *TryBlock,
2005
                            Stmt *Handler);
2006
2007
76
  SourceLocation getLocStart() const LLVM_READONLY { return getTryLoc(); }
2008
76
  SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); }
2009
2010
81
  SourceLocation getTryLoc() const { return TryLoc; }
2011
76
  SourceLocation getEndLoc() const { return Children[HANDLER]->getLocEnd(); }
2012
2013
5
  bool getIsCXXTry() const { return IsCXXTry; }
2014
2015
221
  CompoundStmt* getTryBlock() const {
2016
221
    return cast<CompoundStmt>(Children[TRY]);
2017
221
  }
2018
2019
509
  Stmt *getHandler() const { return Children[HANDLER]; }
2020
2021
  /// Returns 0 if not defined
2022
  SEHExceptStmt  *getExceptHandler() const;
2023
  SEHFinallyStmt *getFinallyHandler() const;
2024
2025
12
  child_range children() {
2026
12
    return child_range(Children, Children+2);
2027
12
  }
2028
2029
0
  static bool classof(const Stmt *T) {
2030
0
    return T->getStmtClass() == SEHTryStmtClass;
2031
0
  }
2032
};
2033
2034
/// Represents a __leave statement.
2035
class SEHLeaveStmt : public Stmt {
2036
  SourceLocation LeaveLoc;
2037
2038
public:
2039
  explicit SEHLeaveStmt(SourceLocation LL)
2040
24
      : Stmt(SEHLeaveStmtClass), LeaveLoc(LL) {}
2041
2042
  /// Build an empty __leave statement.
2043
0
  explicit SEHLeaveStmt(EmptyShell Empty) : Stmt(SEHLeaveStmtClass, Empty) {}
2044
2045
0
  SourceLocation getLeaveLoc() const { return LeaveLoc; }
2046
0
  void setLeaveLoc(SourceLocation L) { LeaveLoc = L; }
2047
2048
0
  SourceLocation getLocStart() const LLVM_READONLY { return LeaveLoc; }
2049
0
  SourceLocation getLocEnd() const LLVM_READONLY { return LeaveLoc; }
2050
2051
  static bool classof(const Stmt *T) {
2052
    return T->getStmtClass() == SEHLeaveStmtClass;
2053
  }
2054
2055
  // Iterators
2056
6
  child_range children() {
2057
6
    return child_range(child_iterator(), child_iterator());
2058
6
  }
2059
};
2060
2061
/// This captures a statement into a function. For example, the following
2062
/// pragma annotated compound statement can be represented as a CapturedStmt,
2063
/// and this compound statement is the body of an anonymous outlined function.
2064
/// @code
2065
/// #pragma omp parallel
2066
/// {
2067
///   compute();
2068
/// }
2069
/// @endcode
2070
class CapturedStmt : public Stmt {
2071
public:
2072
  /// The different capture forms: by 'this', by reference, capture for
2073
  /// variable-length array type etc.
2074
  enum VariableCaptureKind {
2075
    VCK_This,
2076
    VCK_ByRef,
2077
    VCK_ByCopy,
2078
    VCK_VLAType,
2079
  };
2080
2081
  /// Describes the capture of either a variable, or 'this', or
2082
  /// variable-length array type.
2083
  class Capture {
2084
    llvm::PointerIntPair<VarDecl *, 2, VariableCaptureKind> VarAndKind;
2085
    SourceLocation Loc;
2086
2087
  public:
2088
    friend class ASTStmtReader;
2089
2090
    /// Create a new capture.
2091
    ///
2092
    /// \param Loc The source location associated with this capture.
2093
    ///
2094
    /// \param Kind The kind of capture (this, ByRef, ...).
2095
    ///
2096
    /// \param Var The variable being captured, or null if capturing this.
2097
    Capture(SourceLocation Loc, VariableCaptureKind Kind,
2098
            VarDecl *Var = nullptr);
2099
2100
    /// Determine the kind of capture.
2101
    VariableCaptureKind getCaptureKind() const;
2102
2103
    /// Retrieve the source location at which the variable or 'this' was
2104
    /// first used.
2105
103k
    SourceLocation getLocation() const { return Loc; }
2106
2107
    /// Determine whether this capture handles the C++ 'this' pointer.
2108
83.3k
    bool capturesThis() const { return getCaptureKind() == VCK_This; }
2109
2110
    /// Determine whether this capture handles a variable (by reference).
2111
442k
    bool capturesVariable() const { return getCaptureKind() == VCK_ByRef; }
2112
2113
    /// Determine whether this capture handles a variable by copy.
2114
241k
    bool capturesVariableByCopy() const {
2115
241k
      return getCaptureKind() == VCK_ByCopy;
2116
241k
    }
2117
2118
    /// Determine whether this capture handles a variable-length array
2119
    /// type.
2120
44.6k
    bool capturesVariableArrayType() const {
2121
44.6k
      return getCaptureKind() == VCK_VLAType;
2122
44.6k
    }
2123
2124
    /// Retrieve the declaration of the variable being captured.
2125
    ///
2126
    /// This operation is only valid if this capture captures a variable.
2127
    VarDecl *getCapturedVar() const;
2128
  };
2129
2130
private:
2131
  /// The number of variable captured, including 'this'.
2132
  unsigned NumCaptures;
2133
2134
  /// The pointer part is the implicit the outlined function and the 
2135
  /// int part is the captured region kind, 'CR_Default' etc.
2136
  llvm::PointerIntPair<CapturedDecl *, 2, CapturedRegionKind> CapDeclAndKind;
2137
2138
  /// The record for captured variables, a RecordDecl or CXXRecordDecl.
2139
  RecordDecl *TheRecordDecl = nullptr;
2140
2141
  /// Construct a captured statement.
2142
  CapturedStmt(Stmt *S, CapturedRegionKind Kind, ArrayRef<Capture> Captures,
2143
               ArrayRef<Expr *> CaptureInits, CapturedDecl *CD, RecordDecl *RD);
2144
2145
  /// Construct an empty captured statement.
2146
  CapturedStmt(EmptyShell Empty, unsigned NumCaptures);
2147
2148
1.27M
  Stmt **getStoredStmts() { return reinterpret_cast<Stmt **>(this + 1); }
2149
2150
296k
  Stmt *const *getStoredStmts() const {
2151
296k
    return reinterpret_cast<Stmt *const *>(this + 1);
2152
296k
  }
2153
2154
  Capture *getStoredCaptures() const;
2155
2156
18.8k
  void setCapturedStmt(Stmt *S) { getStoredStmts()[NumCaptures] = S; }
2157
2158
public:
2159
  friend class ASTStmtReader;
2160
2161
  static CapturedStmt *Create(const ASTContext &Context, Stmt *S,
2162
                              CapturedRegionKind Kind,
2163
                              ArrayRef<Capture> Captures,
2164
                              ArrayRef<Expr *> CaptureInits,
2165
                              CapturedDecl *CD, RecordDecl *RD);
2166
2167
  static CapturedStmt *CreateDeserialized(const ASTContext &Context,
2168
                                          unsigned NumCaptures);
2169
2170
  /// Retrieve the statement being captured.
2171
850k
  Stmt *getCapturedStmt() { return getStoredStmts()[NumCaptures]; }
2172
274k
  const Stmt *getCapturedStmt() const { return getStoredStmts()[NumCaptures]; }
2173
2174
  /// Retrieve the outlined function declaration.
2175
  CapturedDecl *getCapturedDecl();
2176
  const CapturedDecl *getCapturedDecl() const;
2177
2178
  /// Set the outlined function declaration.
2179
  void setCapturedDecl(CapturedDecl *D);
2180
2181
  /// Retrieve the captured region kind.
2182
  CapturedRegionKind getCapturedRegionKind() const;
2183
2184
  /// Set the captured region kind.
2185
  void setCapturedRegionKind(CapturedRegionKind Kind);
2186
2187
  /// Retrieve the record declaration for captured variables.
2188
60.0k
  const RecordDecl *getCapturedRecordDecl() const { return TheRecordDecl; }
2189
2190
  /// Set the record declaration for captured variables.
2191
18.8k
  void setCapturedRecordDecl(RecordDecl *D) {
2192
18.8k
    assert(D && "null RecordDecl");
2193
18.8k
    TheRecordDecl = D;
2194
18.8k
  }
2195
2196
  /// True if this variable has been captured.
2197
  bool capturesVariable(const VarDecl *Var) const;
2198
2199
  /// An iterator that walks over the captures.
2200
  using capture_iterator = Capture *;
2201
  using const_capture_iterator = const Capture *;
2202
  using capture_range = llvm::iterator_range<capture_iterator>;
2203
  using capture_const_range = llvm::iterator_range<const_capture_iterator>;
2204
2205
38.4k
  capture_range captures() {
2206
38.4k
    return capture_range(capture_begin(), capture_end());
2207
38.4k
  }
2208
314k
  capture_const_range captures() const {
2209
314k
    return capture_const_range(capture_begin(), capture_end());
2210
314k
  }
2211
2212
  /// Retrieve an iterator pointing to the first capture.
2213
58.0k
  capture_iterator capture_begin() { return getStoredCaptures(); }
2214
331k
  const_capture_iterator capture_begin() const { return getStoredCaptures(); }
2215
2216
  /// Retrieve an iterator pointing past the end of the sequence of
2217
  /// captures.
2218
389k
  capture_iterator capture_end() const {
2219
389k
    return getStoredCaptures() + NumCaptures;
2220
389k
  }
2221
2222
  /// Retrieve the number of captures, including 'this'.
2223
78
  unsigned capture_size() const { return NumCaptures; }
2224
2225
  /// Iterator that walks over the capture initialization arguments.
2226
  using capture_init_iterator = Expr **;
2227
  using capture_init_range = llvm::iterator_range<capture_init_iterator>;
2228
2229
  /// Const iterator that walks over the capture initialization
2230
  /// arguments.
2231
  using const_capture_init_iterator = Expr *const *;
2232
  using const_capture_init_range =
2233
      llvm::iterator_range<const_capture_init_iterator>;
2234
2235
19.6k
  capture_init_range capture_inits() {
2236
19.6k
    return capture_init_range(capture_init_begin(), capture_init_end());
2237
19.6k
  }
2238
2239
0
  const_capture_init_range capture_inits() const {
2240
0
    return const_capture_init_range(capture_init_begin(), capture_init_end());
2241
0
  }
2242
2243
  /// Retrieve the first initialization argument.
2244
76.8k
  capture_init_iterator capture_init_begin() {
2245
76.8k
    return reinterpret_cast<Expr **>(getStoredStmts());
2246
76.8k
  }
2247
2248
22.3k
  const_capture_init_iterator capture_init_begin() const {
2249
22.3k
    return reinterpret_cast<Expr *const *>(getStoredStmts());
2250
22.3k
  }
2251
2252
  /// Retrieve the iterator pointing one past the last initialization
2253
  /// argument.
2254
38.4k
  capture_init_iterator capture_init_end() {
2255
38.4k
    return capture_init_begin() + NumCaptures;
2256
38.4k
  }
2257
2258
11.1k
  const_capture_init_iterator capture_init_end() const {
2259
11.1k
    return capture_init_begin() + NumCaptures;
2260
11.1k
  }
2261
2262
193k
  SourceLocation getLocStart() const LLVM_READONLY {
2263
193k
    return getCapturedStmt()->getLocStart();
2264
193k
  }
2265
2266
4
  SourceLocation getLocEnd() const LLVM_READONLY {
2267
4
    return getCapturedStmt()->getLocEnd();
2268
4
  }
2269
2270
5.11k
  SourceRange getSourceRange() const LLVM_READONLY {
2271
5.11k
    return getCapturedStmt()->getSourceRange();
2272
5.11k
  }
2273
2274
122k
  static bool classof(const Stmt *T) {
2275
122k
    return T->getStmtClass() == CapturedStmtClass;
2276
122k
  }
2277
2278
  child_range children();
2279
};
2280
2281
} // namespace clang
2282
2283
#endif // LLVM_CLANG_AST_STMT_H