Coverage Report

Created: 2018-09-25 23:22

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