Coverage Report

Created: 2019-05-19 14:56

/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
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
//  This file defines the Stmt interface and subclasses.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#ifndef LLVM_CLANG_AST_STMT_H
14
#define LLVM_CLANG_AST_STMT_H
15
16
#include "clang/AST/DeclGroup.h"
17
#include "clang/AST/StmtIterator.h"
18
#include "clang/Basic/CapturedStmt.h"
19
#include "clang/Basic/IdentifierTable.h"
20
#include "clang/Basic/LLVM.h"
21
#include "clang/Basic/SourceLocation.h"
22
#include "llvm/ADT/ArrayRef.h"
23
#include "llvm/ADT/PointerIntPair.h"
24
#include "llvm/ADT/StringRef.h"
25
#include "llvm/ADT/iterator.h"
26
#include "llvm/ADT/iterator_range.h"
27
#include "llvm/Support/Casting.h"
28
#include "llvm/Support/Compiler.h"
29
#include "llvm/Support/ErrorHandling.h"
30
#include <algorithm>
31
#include <cassert>
32
#include <cstddef>
33
#include <iterator>
34
#include <string>
35
36
namespace llvm {
37
38
class FoldingSetNodeID;
39
40
} // namespace llvm
41
42
namespace clang {
43
44
class ASTContext;
45
class Attr;
46
class CapturedDecl;
47
class Decl;
48
class Expr;
49
class LabelDecl;
50
class ODRHash;
51
class PrinterHelper;
52
struct PrintingPolicy;
53
class RecordDecl;
54
class SourceManager;
55
class StringLiteral;
56
class Token;
57
class VarDecl;
58
59
//===----------------------------------------------------------------------===//
60
// AST classes for statements.
61
//===----------------------------------------------------------------------===//
62
63
/// Stmt - This represents one statement.
64
///
65
class alignas(void *) Stmt {
66
public:
67
  enum StmtClass {
68
    NoStmtClass = 0,
69
#define STMT(CLASS, PARENT) CLASS##Class,
70
#define STMT_RANGE(BASE, FIRST, LAST) \
71
        first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class,
72
#define LAST_STMT_RANGE(BASE, FIRST, LAST) \
73
        first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class
74
#define ABSTRACT_STMT(STMT)
75
#include "clang/AST/StmtNodes.inc"
76
  };
77
78
  // Make vanilla 'new' and 'delete' illegal for Stmts.
79
protected:
80
  friend class ASTStmtReader;
81
  friend class ASTStmtWriter;
82
83
0
  void *operator new(size_t bytes) noexcept {
84
0
    llvm_unreachable("Stmts cannot be allocated with regular 'new'.");
85
0
  }
86
87
  void operator delete(void *data) noexcept {
88
    llvm_unreachable("Stmts cannot be released with regular 'delete'.");
89
  }
90
91
  //===--- Statement bitfields classes ---===//
92
93
  class StmtBitfields {
94
    friend class ASTStmtReader;
95
    friend class ASTStmtWriter;
96
    friend class Stmt;
97
98
    /// The statement class.
99
    unsigned sClass : 8;
100
101
    /// This bit is set only for the Stmts that are the structured-block of
102
    /// OpenMP executable directives. Directives that have a structured block
103
    /// are called "non-standalone" directives.
104
    /// I.e. those returned by OMPExecutableDirective::getStructuredBlock().
105
    unsigned IsOMPStructuredBlock : 1;
106
  };
107
  enum { NumStmtBits = 9 };
108
109
  class NullStmtBitfields {
110
    friend class ASTStmtReader;
111
    friend class ASTStmtWriter;
112
    friend class NullStmt;
113
114
    unsigned : NumStmtBits;
115
116
    /// True if the null statement was preceded by an empty macro, e.g:
117
    /// @code
118
    ///   #define CALL(x)
119
    ///   CALL(0);
120
    /// @endcode
121
    unsigned HasLeadingEmptyMacro : 1;
122
123
    /// The location of the semi-colon.
124
    SourceLocation SemiLoc;
125
  };
126
127
  class CompoundStmtBitfields {
128
    friend class ASTStmtReader;
129
    friend class CompoundStmt;
130
131
    unsigned : NumStmtBits;
132
133
    unsigned NumStmts : 32 - NumStmtBits;
134
135
    /// The location of the opening "{".
136
    SourceLocation LBraceLoc;
137
  };
138
139
  class LabelStmtBitfields {
140
    friend class LabelStmt;
141
142
    unsigned : NumStmtBits;
143
144
    SourceLocation IdentLoc;
145
  };
146
147
  class AttributedStmtBitfields {
148
    friend class ASTStmtReader;
149
    friend class AttributedStmt;
150
151
    unsigned : NumStmtBits;
152
153
    /// Number of attributes.
154
    unsigned NumAttrs : 32 - NumStmtBits;
155
156
    /// The location of the attribute.
157
    SourceLocation AttrLoc;
158
  };
159
160
  class IfStmtBitfields {
161
    friend class ASTStmtReader;
162
    friend class IfStmt;
163
164
    unsigned : NumStmtBits;
165
166
    /// True if this if statement is a constexpr if.
167
    unsigned IsConstexpr : 1;
168
169
    /// True if this if statement has storage for an else statement.
170
    unsigned HasElse : 1;
171
172
    /// True if this if statement has storage for a variable declaration.
173
    unsigned HasVar : 1;
174
175
    /// True if this if statement has storage for an init statement.
176
    unsigned HasInit : 1;
177
178
    /// The location of the "if".
179
    SourceLocation IfLoc;
180
  };
181
182
  class SwitchStmtBitfields {
183
    friend class SwitchStmt;
184
185
    unsigned : NumStmtBits;
186
187
    /// True if the SwitchStmt has storage for an init statement.
188
    unsigned HasInit : 1;
189
190
    /// True if the SwitchStmt has storage for a condition variable.
191
    unsigned HasVar : 1;
192
193
    /// If the SwitchStmt is a switch on an enum value, records whether all
194
    /// the enum values were covered by CaseStmts.  The coverage information
195
    /// value is meant to be a hint for possible clients.
196
    unsigned AllEnumCasesCovered : 1;
197
198
    /// The location of the "switch".
199
    SourceLocation SwitchLoc;
200
  };
201
202
  class WhileStmtBitfields {
203
    friend class ASTStmtReader;
204
    friend class WhileStmt;
205
206
    unsigned : NumStmtBits;
207
208
    /// True if the WhileStmt has storage for a condition variable.
209
    unsigned HasVar : 1;
210
211
    /// The location of the "while".
212
    SourceLocation WhileLoc;
213
  };
214
215
  class DoStmtBitfields {
216
    friend class DoStmt;
217
218
    unsigned : NumStmtBits;
219
220
    /// The location of the "do".
221
    SourceLocation DoLoc;
222
  };
223
224
  class ForStmtBitfields {
225
    friend class ForStmt;
226
227
    unsigned : NumStmtBits;
228
229
    /// The location of the "for".
230
    SourceLocation ForLoc;
231
  };
232
233
  class GotoStmtBitfields {
234
    friend class GotoStmt;
235
    friend class IndirectGotoStmt;
236
237
    unsigned : NumStmtBits;
238
239
    /// The location of the "goto".
240
    SourceLocation GotoLoc;
241
  };
242
243
  class ContinueStmtBitfields {
244
    friend class ContinueStmt;
245
246
    unsigned : NumStmtBits;
247
248
    /// The location of the "continue".
249
    SourceLocation ContinueLoc;
250
  };
251
252
  class BreakStmtBitfields {
253
    friend class BreakStmt;
254
255
    unsigned : NumStmtBits;
256
257
    /// The location of the "break".
258
    SourceLocation BreakLoc;
259
  };
260
261
  class ReturnStmtBitfields {
262
    friend class ReturnStmt;
263
264
    unsigned : NumStmtBits;
265
266
    /// True if this ReturnStmt has storage for an NRVO candidate.
267
    unsigned HasNRVOCandidate : 1;
268
269
    /// The location of the "return".
270
    SourceLocation RetLoc;
271
  };
272
273
  class SwitchCaseBitfields {
274
    friend class SwitchCase;
275
    friend class CaseStmt;
276
277
    unsigned : NumStmtBits;
278
279
    /// Used by CaseStmt to store whether it is a case statement
280
    /// of the form case LHS ... RHS (a GNU extension).
281
    unsigned CaseStmtIsGNURange : 1;
282
283
    /// The location of the "case" or "default" keyword.
284
    SourceLocation KeywordLoc;
285
  };
286
287
  //===--- Expression bitfields classes ---===//
288
289
  class ExprBitfields {
290
    friend class ASTStmtReader; // deserialization
291
    friend class AtomicExpr; // ctor
292
    friend class BlockDeclRefExpr; // ctor
293
    friend class CallExpr; // ctor
294
    friend class CXXConstructExpr; // ctor
295
    friend class CXXDependentScopeMemberExpr; // ctor
296
    friend class CXXNewExpr; // ctor
297
    friend class CXXUnresolvedConstructExpr; // ctor
298
    friend class DeclRefExpr; // computeDependence
299
    friend class DependentScopeDeclRefExpr; // ctor
300
    friend class DesignatedInitExpr; // ctor
301
    friend class Expr;
302
    friend class InitListExpr; // ctor
303
    friend class ObjCArrayLiteral; // ctor
304
    friend class ObjCDictionaryLiteral; // ctor
305
    friend class ObjCMessageExpr; // ctor
306
    friend class OffsetOfExpr; // ctor
307
    friend class OpaqueValueExpr; // ctor
308
    friend class OverloadExpr; // ctor
309
    friend class ParenListExpr; // ctor
310
    friend class PseudoObjectExpr; // ctor
311
    friend class ShuffleVectorExpr; // ctor
312
313
    unsigned : NumStmtBits;
314
315
    unsigned ValueKind : 2;
316
    unsigned ObjectKind : 3;
317
    unsigned TypeDependent : 1;
318
    unsigned ValueDependent : 1;
319
    unsigned InstantiationDependent : 1;
320
    unsigned ContainsUnexpandedParameterPack : 1;
321
  };
322
  enum { NumExprBits = NumStmtBits + 9 };
323
324
  class PredefinedExprBitfields {
325
    friend class ASTStmtReader;
326
    friend class PredefinedExpr;
327
328
    unsigned : NumExprBits;
329
330
    /// The kind of this PredefinedExpr. One of the enumeration values
331
    /// in PredefinedExpr::IdentKind.
332
    unsigned Kind : 4;
333
334
    /// True if this PredefinedExpr has a trailing "StringLiteral *"
335
    /// for the predefined identifier.
336
    unsigned HasFunctionName : 1;
337
338
    /// The location of this PredefinedExpr.
339
    SourceLocation Loc;
340
  };
341
342
  class DeclRefExprBitfields {
343
    friend class ASTStmtReader; // deserialization
344
    friend class DeclRefExpr;
345
346
    unsigned : NumExprBits;
347
348
    unsigned HasQualifier : 1;
349
    unsigned HasTemplateKWAndArgsInfo : 1;
350
    unsigned HasFoundDecl : 1;
351
    unsigned HadMultipleCandidates : 1;
352
    unsigned RefersToEnclosingVariableOrCapture : 1;
353
354
    /// The location of the declaration name itself.
355
    SourceLocation Loc;
356
  };
357
358
  enum APFloatSemantics {
359
    IEEEhalf,
360
    IEEEsingle,
361
    IEEEdouble,
362
    x87DoubleExtended,
363
    IEEEquad,
364
    PPCDoubleDouble
365
  };
366
367
  class FloatingLiteralBitfields {
368
    friend class FloatingLiteral;
369
370
    unsigned : NumExprBits;
371
372
    unsigned Semantics : 3; // Provides semantics for APFloat construction
373
    unsigned IsExact : 1;
374
  };
375
376
  class StringLiteralBitfields {
377
    friend class ASTStmtReader;
378
    friend class StringLiteral;
379
380
    unsigned : NumExprBits;
381
382
    /// The kind of this string literal.
383
    /// One of the enumeration values of StringLiteral::StringKind.
384
    unsigned Kind : 3;
385
386
    /// The width of a single character in bytes. Only values of 1, 2,
387
    /// and 4 bytes are supported. StringLiteral::mapCharByteWidth maps
388
    /// the target + string kind to the appropriate CharByteWidth.
389
    unsigned CharByteWidth : 3;
390
391
    unsigned IsPascal : 1;
392
393
    /// The number of concatenated token this string is made of.
394
    /// This is the number of trailing SourceLocation.
395
    unsigned NumConcatenated;
396
  };
397
398
  class CharacterLiteralBitfields {
399
    friend class CharacterLiteral;
400
401
    unsigned : NumExprBits;
402
403
    unsigned Kind : 3;
404
  };
405
406
  class UnaryOperatorBitfields {
407
    friend class UnaryOperator;
408
409
    unsigned : NumExprBits;
410
411
    unsigned Opc : 5;
412
    unsigned CanOverflow : 1;
413
414
    SourceLocation Loc;
415
  };
416
417
  class UnaryExprOrTypeTraitExprBitfields {
418
    friend class UnaryExprOrTypeTraitExpr;
419
420
    unsigned : NumExprBits;
421
422
    unsigned Kind : 3;
423
    unsigned IsType : 1; // true if operand is a type, false if an expression.
424
  };
425
426
  class ArraySubscriptExprBitfields {
427
    friend class ArraySubscriptExpr;
428
429
    unsigned : NumExprBits;
430
431
    SourceLocation RBracketLoc;
432
  };
433
434
  class CallExprBitfields {
435
    friend class CallExpr;
436
437
    unsigned : NumExprBits;
438
439
    unsigned NumPreArgs : 1;
440
441
    /// True if the callee of the call expression was found using ADL.
442
    unsigned UsesADL : 1;
443
444
    /// Padding used to align OffsetToTrailingObjects to a byte multiple.
445
    unsigned : 24 - 2 - NumExprBits;
446
447
    /// The offset in bytes from the this pointer to the start of the
448
    /// trailing objects belonging to CallExpr. Intentionally byte sized
449
    /// for faster access.
450
    unsigned OffsetToTrailingObjects : 8;
451
  };
452
  enum { NumCallExprBits = 32 };
453
454
  class MemberExprBitfields {
455
    friend class MemberExpr;
456
457
    unsigned : NumExprBits;
458
459
    /// IsArrow - True if this is "X->F", false if this is "X.F".
460
    unsigned IsArrow : 1;
461
462
    /// True if this member expression used a nested-name-specifier to
463
    /// refer to the member, e.g., "x->Base::f", or found its member via
464
    /// a using declaration.  When true, a MemberExprNameQualifier
465
    /// structure is allocated immediately after the MemberExpr.
466
    unsigned HasQualifierOrFoundDecl : 1;
467
468
    /// True if this member expression specified a template keyword
469
    /// and/or a template argument list explicitly, e.g., x->f<int>,
470
    /// x->template f, x->template f<int>.
471
    /// When true, an ASTTemplateKWAndArgsInfo structure and its
472
    /// TemplateArguments (if any) are present.
473
    unsigned HasTemplateKWAndArgsInfo : 1;
474
475
    /// True if this member expression refers to a method that
476
    /// was resolved from an overloaded set having size greater than 1.
477
    unsigned HadMultipleCandidates : 1;
478
479
    /// This is the location of the -> or . in the expression.
480
    SourceLocation OperatorLoc;
481
  };
482
483
  class CastExprBitfields {
484
    friend class CastExpr;
485
    friend class ImplicitCastExpr;
486
487
    unsigned : NumExprBits;
488
489
    unsigned Kind : 6;
490
    unsigned PartOfExplicitCast : 1; // Only set for ImplicitCastExpr.
491
492
    /// The number of CXXBaseSpecifiers in the cast. 14 bits would be enough
493
    /// here. ([implimits] Direct and indirect base classes [16384]).
494
    unsigned BasePathSize;
495
  };
496
497
  class BinaryOperatorBitfields {
498
    friend class BinaryOperator;
499
500
    unsigned : NumExprBits;
501
502
    unsigned Opc : 6;
503
504
    /// This is only meaningful for operations on floating point
505
    /// types and 0 otherwise.
506
    unsigned FPFeatures : 3;
507
508
    SourceLocation OpLoc;
509
  };
510
511
  class InitListExprBitfields {
512
    friend class InitListExpr;
513
514
    unsigned : NumExprBits;
515
516
    /// Whether this initializer list originally had a GNU array-range
517
    /// designator in it. This is a temporary marker used by CodeGen.
518
    unsigned HadArrayRangeDesignator : 1;
519
  };
520
521
  class ParenListExprBitfields {
522
    friend class ASTStmtReader;
523
    friend class ParenListExpr;
524
525
    unsigned : NumExprBits;
526
527
    /// The number of expressions in the paren list.
528
    unsigned NumExprs;
529
  };
530
531
  class GenericSelectionExprBitfields {
532
    friend class ASTStmtReader;
533
    friend class GenericSelectionExpr;
534
535
    unsigned : NumExprBits;
536
537
    /// The location of the "_Generic".
538
    SourceLocation GenericLoc;
539
  };
540
541
  class PseudoObjectExprBitfields {
542
    friend class ASTStmtReader; // deserialization
543
    friend class PseudoObjectExpr;
544
545
    unsigned : NumExprBits;
546
547
    // These don't need to be particularly wide, because they're
548
    // strictly limited by the forms of expressions we permit.
549
    unsigned NumSubExprs : 8;
550
    unsigned ResultIndex : 32 - 8 - NumExprBits;
551
  };
552
553
  class SourceLocExprBitfields {
554
    friend class ASTStmtReader;
555
    friend class SourceLocExpr;
556
557
    unsigned : NumExprBits;
558
559
    /// The kind of source location builtin represented by the SourceLocExpr.
560
    /// Ex. __builtin_LINE, __builtin_FUNCTION, ect.
561
    unsigned Kind : 2;
562
  };
563
564
  //===--- C++ Expression bitfields classes ---===//
565
566
  class CXXOperatorCallExprBitfields {
567
    friend class ASTStmtReader;
568
    friend class CXXOperatorCallExpr;
569
570
    unsigned : NumCallExprBits;
571
572
    /// The kind of this overloaded operator. One of the enumerator
573
    /// value of OverloadedOperatorKind.
574
    unsigned OperatorKind : 6;
575
576
    // Only meaningful for floating point types.
577
    unsigned FPFeatures : 3;
578
  };
579
580
  class CXXBoolLiteralExprBitfields {
581
    friend class CXXBoolLiteralExpr;
582
583
    unsigned : NumExprBits;
584
585
    /// The value of the boolean literal.
586
    unsigned Value : 1;
587
588
    /// The location of the boolean literal.
589
    SourceLocation Loc;
590
  };
591
592
  class CXXNullPtrLiteralExprBitfields {
593
    friend class CXXNullPtrLiteralExpr;
594
595
    unsigned : NumExprBits;
596
597
    /// The location of the null pointer literal.
598
    SourceLocation Loc;
599
  };
600
601
  class CXXThisExprBitfields {
602
    friend class CXXThisExpr;
603
604
    unsigned : NumExprBits;
605
606
    /// Whether this is an implicit "this".
607
    unsigned IsImplicit : 1;
608
609
    /// The location of the "this".
610
    SourceLocation Loc;
611
  };
612
613
  class CXXThrowExprBitfields {
614
    friend class ASTStmtReader;
615
    friend class CXXThrowExpr;
616
617
    unsigned : NumExprBits;
618
619
    /// Whether the thrown variable (if any) is in scope.
620
    unsigned IsThrownVariableInScope : 1;
621
622
    /// The location of the "throw".
623
    SourceLocation ThrowLoc;
624
  };
625
626
  class CXXDefaultArgExprBitfields {
627
    friend class ASTStmtReader;
628
    friend class CXXDefaultArgExpr;
629
630
    unsigned : NumExprBits;
631
632
    /// The location where the default argument expression was used.
633
    SourceLocation Loc;
634
  };
635
636
  class CXXDefaultInitExprBitfields {
637
    friend class ASTStmtReader;
638
    friend class CXXDefaultInitExpr;
639
640
    unsigned : NumExprBits;
641
642
    /// The location where the default initializer expression was used.
643
    SourceLocation Loc;
644
  };
645
646
  class CXXScalarValueInitExprBitfields {
647
    friend class ASTStmtReader;
648
    friend class CXXScalarValueInitExpr;
649
650
    unsigned : NumExprBits;
651
652
    SourceLocation RParenLoc;
653
  };
654
655
  class CXXNewExprBitfields {
656
    friend class ASTStmtReader;
657
    friend class ASTStmtWriter;
658
    friend class CXXNewExpr;
659
660
    unsigned : NumExprBits;
661
662
    /// Was the usage ::new, i.e. is the global new to be used?
663
    unsigned IsGlobalNew : 1;
664
665
    /// Do we allocate an array? If so, the first trailing "Stmt *" is the
666
    /// size expression.
667
    unsigned IsArray : 1;
668
669
    /// Should the alignment be passed to the allocation function?
670
    unsigned ShouldPassAlignment : 1;
671
672
    /// If this is an array allocation, does the usual deallocation
673
    /// function for the allocated type want to know the allocated size?
674
    unsigned UsualArrayDeleteWantsSize : 1;
675
676
    /// What kind of initializer do we have? Could be none, parens, or braces.
677
    /// In storage, we distinguish between "none, and no initializer expr", and
678
    /// "none, but an implicit initializer expr".
679
    unsigned StoredInitializationStyle : 2;
680
681
    /// True if the allocated type was expressed as a parenthesized type-id.
682
    unsigned IsParenTypeId : 1;
683
684
    /// The number of placement new arguments.
685
    unsigned NumPlacementArgs;
686
  };
687
688
  class CXXDeleteExprBitfields {
689
    friend class ASTStmtReader;
690
    friend class CXXDeleteExpr;
691
692
    unsigned : NumExprBits;
693
694
    /// Is this a forced global delete, i.e. "::delete"?
695
    unsigned GlobalDelete : 1;
696
697
    /// Is this the array form of delete, i.e. "delete[]"?
698
    unsigned ArrayForm : 1;
699
700
    /// ArrayFormAsWritten can be different from ArrayForm if 'delete' is
701
    /// applied to pointer-to-array type (ArrayFormAsWritten will be false
702
    /// while ArrayForm will be true).
703
    unsigned ArrayFormAsWritten : 1;
704
705
    /// Does the usual deallocation function for the element type require
706
    /// a size_t argument?
707
    unsigned UsualArrayDeleteWantsSize : 1;
708
709
    /// Location of the expression.
710
    SourceLocation Loc;
711
  };
712
713
  class TypeTraitExprBitfields {
714
    friend class ASTStmtReader;
715
    friend class ASTStmtWriter;
716
    friend class TypeTraitExpr;
717
718
    unsigned : NumExprBits;
719
720
    /// The kind of type trait, which is a value of a TypeTrait enumerator.
721
    unsigned Kind : 8;
722
723
    /// If this expression is not value-dependent, this indicates whether
724
    /// the trait evaluated true or false.
725
    unsigned Value : 1;
726
727
    /// The number of arguments to this type trait.
728
    unsigned NumArgs : 32 - 8 - 1 - NumExprBits;
729
  };
730
731
  class DependentScopeDeclRefExprBitfields {
732
    friend class ASTStmtReader;
733
    friend class ASTStmtWriter;
734
    friend class DependentScopeDeclRefExpr;
735
736
    unsigned : NumExprBits;
737
738
    /// Whether the name includes info for explicit template
739
    /// keyword and arguments.
740
    unsigned HasTemplateKWAndArgsInfo : 1;
741
  };
742
743
  class CXXConstructExprBitfields {
744
    friend class ASTStmtReader;
745
    friend class CXXConstructExpr;
746
747
    unsigned : NumExprBits;
748
749
    unsigned Elidable : 1;
750
    unsigned HadMultipleCandidates : 1;
751
    unsigned ListInitialization : 1;
752
    unsigned StdInitListInitialization : 1;
753
    unsigned ZeroInitialization : 1;
754
    unsigned ConstructionKind : 3;
755
756
    SourceLocation Loc;
757
  };
758
759
  class ExprWithCleanupsBitfields {
760
    friend class ASTStmtReader; // deserialization
761
    friend class ExprWithCleanups;
762
763
    unsigned : NumExprBits;
764
765
    // When false, it must not have side effects.
766
    unsigned CleanupsHaveSideEffects : 1;
767
768
    unsigned NumObjects : 32 - 1 - NumExprBits;
769
  };
770
771
  class CXXUnresolvedConstructExprBitfields {
772
    friend class ASTStmtReader;
773
    friend class CXXUnresolvedConstructExpr;
774
775
    unsigned : NumExprBits;
776
777
    /// The number of arguments used to construct the type.
778
    unsigned NumArgs;
779
  };
780
781
  class CXXDependentScopeMemberExprBitfields {
782
    friend class ASTStmtReader;
783
    friend class CXXDependentScopeMemberExpr;
784
785
    unsigned : NumExprBits;
786
787
    /// Whether this member expression used the '->' operator or
788
    /// the '.' operator.
789
    unsigned IsArrow : 1;
790
791
    /// Whether this member expression has info for explicit template
792
    /// keyword and arguments.
793
    unsigned HasTemplateKWAndArgsInfo : 1;
794
795
    /// See getFirstQualifierFoundInScope() and the comment listing
796
    /// the trailing objects.
797
    unsigned HasFirstQualifierFoundInScope : 1;
798
799
    /// The location of the '->' or '.' operator.
800
    SourceLocation OperatorLoc;
801
  };
802
803
  class OverloadExprBitfields {
804
    friend class ASTStmtReader;
805
    friend class OverloadExpr;
806
807
    unsigned : NumExprBits;
808
809
    /// Whether the name includes info for explicit template
810
    /// keyword and arguments.
811
    unsigned HasTemplateKWAndArgsInfo : 1;
812
813
    /// Padding used by the derived classes to store various bits. If you
814
    /// need to add some data here, shrink this padding and add your data
815
    /// above. NumOverloadExprBits also needs to be updated.
816
    unsigned : 32 - NumExprBits - 1;
817
818
    /// The number of results.
819
    unsigned NumResults;
820
  };
821
  enum { NumOverloadExprBits = NumExprBits + 1 };
822
823
  class UnresolvedLookupExprBitfields {
824
    friend class ASTStmtReader;
825
    friend class UnresolvedLookupExpr;
826
827
    unsigned : NumOverloadExprBits;
828
829
    /// True if these lookup results should be extended by
830
    /// argument-dependent lookup if this is the operand of a function call.
831
    unsigned RequiresADL : 1;
832
833
    /// True if these lookup results are overloaded.  This is pretty trivially
834
    /// rederivable if we urgently need to kill this field.
835
    unsigned Overloaded : 1;
836
  };
837
  static_assert(sizeof(UnresolvedLookupExprBitfields) <= 4,
838
                "UnresolvedLookupExprBitfields must be <= than 4 bytes to"
839
                "avoid trashing OverloadExprBitfields::NumResults!");
840
841
  class UnresolvedMemberExprBitfields {
842
    friend class ASTStmtReader;
843
    friend class UnresolvedMemberExpr;
844
845
    unsigned : NumOverloadExprBits;
846
847
    /// Whether this member expression used the '->' operator or
848
    /// the '.' operator.
849
    unsigned IsArrow : 1;
850
851
    /// Whether the lookup results contain an unresolved using declaration.
852
    unsigned HasUnresolvedUsing : 1;
853
  };
854
  static_assert(sizeof(UnresolvedMemberExprBitfields) <= 4,
855
                "UnresolvedMemberExprBitfields must be <= than 4 bytes to"
856
                "avoid trashing OverloadExprBitfields::NumResults!");
857
858
  class CXXNoexceptExprBitfields {
859
    friend class ASTStmtReader;
860
    friend class CXXNoexceptExpr;
861
862
    unsigned : NumExprBits;
863
864
    unsigned Value : 1;
865
  };
866
867
  class SubstNonTypeTemplateParmExprBitfields {
868
    friend class ASTStmtReader;
869
    friend class SubstNonTypeTemplateParmExpr;
870
871
    unsigned : NumExprBits;
872
873
    /// The location of the non-type template parameter reference.
874
    SourceLocation NameLoc;
875
  };
876
877
  //===--- C++ Coroutines TS bitfields classes ---===//
878
879
  class CoawaitExprBitfields {
880
    friend class CoawaitExpr;
881
882
    unsigned : NumExprBits;
883
884
    unsigned IsImplicit : 1;
885
  };
886
887
  //===--- Obj-C Expression bitfields classes ---===//
888
889
  class ObjCIndirectCopyRestoreExprBitfields {
890
    friend class ObjCIndirectCopyRestoreExpr;
891
892
    unsigned : NumExprBits;
893
894
    unsigned ShouldCopy : 1;
895
  };
896
897
  //===--- Clang Extensions bitfields classes ---===//
898
899
  class OpaqueValueExprBitfields {
900
    friend class ASTStmtReader;
901
    friend class OpaqueValueExpr;
902
903
    unsigned : NumExprBits;
904
905
    /// The OVE is a unique semantic reference to its source expression if this
906
    /// bit is set to true.
907
    unsigned IsUnique : 1;
908
909
    SourceLocation Loc;
910
  };
911
912
  union {
913
    // Same order as in StmtNodes.td.
914
    // Statements
915
    StmtBitfields StmtBits;
916
    NullStmtBitfields NullStmtBits;
917
    CompoundStmtBitfields CompoundStmtBits;
918
    LabelStmtBitfields LabelStmtBits;
919
    AttributedStmtBitfields AttributedStmtBits;
920
    IfStmtBitfields IfStmtBits;
921
    SwitchStmtBitfields SwitchStmtBits;
922
    WhileStmtBitfields WhileStmtBits;
923
    DoStmtBitfields DoStmtBits;
924
    ForStmtBitfields ForStmtBits;
925
    GotoStmtBitfields GotoStmtBits;
926
    ContinueStmtBitfields ContinueStmtBits;
927
    BreakStmtBitfields BreakStmtBits;
928
    ReturnStmtBitfields ReturnStmtBits;
929
    SwitchCaseBitfields SwitchCaseBits;
930
931
    // Expressions
932
    ExprBitfields ExprBits;
933
    PredefinedExprBitfields PredefinedExprBits;
934
    DeclRefExprBitfields DeclRefExprBits;
935
    FloatingLiteralBitfields FloatingLiteralBits;
936
    StringLiteralBitfields StringLiteralBits;
937
    CharacterLiteralBitfields CharacterLiteralBits;
938
    UnaryOperatorBitfields UnaryOperatorBits;
939
    UnaryExprOrTypeTraitExprBitfields UnaryExprOrTypeTraitExprBits;
940
    ArraySubscriptExprBitfields ArraySubscriptExprBits;
941
    CallExprBitfields CallExprBits;
942
    MemberExprBitfields MemberExprBits;
943
    CastExprBitfields CastExprBits;
944
    BinaryOperatorBitfields BinaryOperatorBits;
945
    InitListExprBitfields InitListExprBits;
946
    ParenListExprBitfields ParenListExprBits;
947
    GenericSelectionExprBitfields GenericSelectionExprBits;
948
    PseudoObjectExprBitfields PseudoObjectExprBits;
949
    SourceLocExprBitfields SourceLocExprBits;
950
951
    // C++ Expressions
952
    CXXOperatorCallExprBitfields CXXOperatorCallExprBits;
953
    CXXBoolLiteralExprBitfields CXXBoolLiteralExprBits;
954
    CXXNullPtrLiteralExprBitfields CXXNullPtrLiteralExprBits;
955
    CXXThisExprBitfields CXXThisExprBits;
956
    CXXThrowExprBitfields CXXThrowExprBits;
957
    CXXDefaultArgExprBitfields CXXDefaultArgExprBits;
958
    CXXDefaultInitExprBitfields CXXDefaultInitExprBits;
959
    CXXScalarValueInitExprBitfields CXXScalarValueInitExprBits;
960
    CXXNewExprBitfields CXXNewExprBits;
961
    CXXDeleteExprBitfields CXXDeleteExprBits;
962
    TypeTraitExprBitfields TypeTraitExprBits;
963
    DependentScopeDeclRefExprBitfields DependentScopeDeclRefExprBits;
964
    CXXConstructExprBitfields CXXConstructExprBits;
965
    ExprWithCleanupsBitfields ExprWithCleanupsBits;
966
    CXXUnresolvedConstructExprBitfields CXXUnresolvedConstructExprBits;
967
    CXXDependentScopeMemberExprBitfields CXXDependentScopeMemberExprBits;
968
    OverloadExprBitfields OverloadExprBits;
969
    UnresolvedLookupExprBitfields UnresolvedLookupExprBits;
970
    UnresolvedMemberExprBitfields UnresolvedMemberExprBits;
971
    CXXNoexceptExprBitfields CXXNoexceptExprBits;
972
    SubstNonTypeTemplateParmExprBitfields SubstNonTypeTemplateParmExprBits;
973
974
    // C++ Coroutines TS expressions
975
    CoawaitExprBitfields CoawaitBits;
976
977
    // Obj-C Expressions
978
    ObjCIndirectCopyRestoreExprBitfields ObjCIndirectCopyRestoreExprBits;
979
980
    // Clang Extensions
981
    OpaqueValueExprBitfields OpaqueValueExprBits;
982
  };
983
984
public:
985
  // Only allow allocation of Stmts using the allocator in ASTContext
986
  // or by doing a placement new.
987
  void* operator new(size_t bytes, const ASTContext& C,
988
                     unsigned alignment = 8);
989
990
  void* operator new(size_t bytes, const ASTContext* C,
991
14.4k
                     unsigned alignment = 8) {
992
14.4k
    return operator new(bytes, *C, alignment);
993
14.4k
  }
994
995
73.7M
  void *operator new(size_t bytes, void *mem) noexcept { return mem; }
996
997
  void operator delete(void *, const ASTContext &, unsigned) noexcept {}
998
  void operator delete(void *, const ASTContext *, unsigned) noexcept {}
999
  void operator delete(void *, size_t) noexcept {}
1000
  void operator delete(void *, void *) noexcept {}
1001
1002
public:
1003
  /// A placeholder type used to construct an empty shell of a
1004
  /// type, that will be filled in later (e.g., by some
1005
  /// de-serialization).
1006
  struct EmptyShell {};
1007
1008
protected:
1009
  /// Iterator for iterating over Stmt * arrays that contain only T *.
1010
  ///
1011
  /// This is needed because AST nodes use Stmt* arrays to store
1012
  /// references to children (to be compatible with StmtIterator).
1013
  template<typename T, typename TPtr = T *, typename StmtPtr = Stmt *>
1014
  struct CastIterator
1015
      : llvm::iterator_adaptor_base<CastIterator<T, TPtr, StmtPtr>, StmtPtr *,
1016
                                    std::random_access_iterator_tag, TPtr> {
1017
    using Base = typename CastIterator::iterator_adaptor_base;
1018
1019
    CastIterator() : Base(nullptr) {}
1020
8.32M
    CastIterator(StmtPtr *I) : Base(I) {}
clang::Stmt::CastIterator<clang::Expr, clang::Expr const* const, clang::Stmt const* const>::CastIterator(clang::Stmt const* const*)
Line
Count
Source
1020
1.94M
    CastIterator(StmtPtr *I) : Base(I) {}
clang::Stmt::CastIterator<clang::Expr, clang::Expr*, clang::Stmt*>::CastIterator(clang::Stmt**)
Line
Count
Source
1020
6.37M
    CastIterator(StmtPtr *I) : Base(I) {}
1021
1022
11.0M
    typename Base::value_type operator*() const {
1023
11.0M
      return cast_or_null<T>(*this->I);
1024
11.0M
    }
clang::Stmt::CastIterator<clang::Expr, clang::Expr const* const, clang::Stmt const* const>::operator*() const
Line
Count
Source
1022
3.99M
    typename Base::value_type operator*() const {
1023
3.99M
      return cast_or_null<T>(*this->I);
1024
3.99M
    }
clang::Stmt::CastIterator<clang::Expr, clang::Expr*, clang::Stmt*>::operator*() const
Line
Count
Source
1022
7.04M
    typename Base::value_type operator*() const {
1023
7.04M
      return cast_or_null<T>(*this->I);
1024
7.04M
    }
1025
  };
1026
1027
  /// Const iterator for iterating over Stmt * arrays that contain only T *.
1028
  template <typename T>
1029
  using ConstCastIterator = CastIterator<T, const T *const, const Stmt *const>;
1030
1031
  using ExprIterator = CastIterator<Expr>;
1032
  using ConstExprIterator = ConstCastIterator<Expr>;
1033
1034
private:
1035
  /// Whether statistic collection is enabled.
1036
  static bool StatisticsEnabled;
1037
1038
protected:
1039
  /// Construct an empty statement.
1040
57.1k
  explicit Stmt(StmtClass SC, EmptyShell) : Stmt(SC) {}
1041
1042
public:
1043
107M
  Stmt(StmtClass SC) {
1044
107M
    static_assert(sizeof(*this) <= 8,
1045
107M
                  "changing bitfields changed sizeof(Stmt)");
1046
107M
    static_assert(sizeof(*this) % alignof(void *) == 0,
1047
107M
                  "Insufficient alignment!");
1048
107M
    StmtBits.sClass = SC;
1049
107M
    StmtBits.IsOMPStructuredBlock = false;
1050
107M
    if (StatisticsEnabled) 
Stmt::addStmtClass(SC)13
;
1051
107M
  }
1052
1053
5.13G
  StmtClass getStmtClass() const {
1054
5.13G
    return static_cast<StmtClass>(StmtBits.sClass);
1055
5.13G
  }
1056
1057
  Stmt(const Stmt &) = delete;
1058
  Stmt(Stmt &&) = delete;
1059
  Stmt &operator=(const Stmt &) = delete;
1060
  Stmt &operator=(Stmt &&) = delete;
1061
1062
  const char *getStmtClassName() const;
1063
1064
22.1k
  bool isOMPStructuredBlock() const { return StmtBits.IsOMPStructuredBlock; }
1065
698k
  void setIsOMPStructuredBlock(bool IsOMPStructuredBlock) {
1066
698k
    StmtBits.IsOMPStructuredBlock = IsOMPStructuredBlock;
1067
698k
  }
1068
1069
  /// SourceLocation tokens are not useful in isolation - they are low level
1070
  /// value objects created/interpreted by SourceManager. We assume AST
1071
  /// clients will have a pointer to the respective SourceManager.
1072
  SourceRange getSourceRange() const LLVM_READONLY;
1073
  SourceLocation getBeginLoc() const LLVM_READONLY;
1074
  SourceLocation getEndLoc() const LLVM_READONLY;
1075
1076
  // global temp stats (until we have a per-module visitor)
1077
  static void addStmtClass(const StmtClass s);
1078
  static void EnableStatistics();
1079
  static void PrintStats();
1080
1081
  /// Dumps the specified AST fragment and all subtrees to
1082
  /// \c llvm::errs().
1083
  void dump() const;
1084
  void dump(SourceManager &SM) const;
1085
  void dump(raw_ostream &OS, SourceManager &SM) const;
1086
  void dump(raw_ostream &OS) const;
1087
1088
  /// \return Unique reproducible object identifier
1089
  int64_t getID(const ASTContext &Context) const;
1090
1091
  /// dumpColor - same as dump(), but forces color highlighting.
1092
  void dumpColor() const;
1093
1094
  /// dumpPretty/printPretty - These two methods do a "pretty print" of the AST
1095
  /// back to its original source language syntax.
1096
  void dumpPretty(const ASTContext &Context) const;
1097
  void printPretty(raw_ostream &OS, PrinterHelper *Helper,
1098
                   const PrintingPolicy &Policy, unsigned Indentation = 0,
1099
                   StringRef NewlineSymbol = "\n",
1100
                   const ASTContext *Context = nullptr) const;
1101
1102
  /// viewAST - Visualize an AST rooted at this Stmt* using GraphViz.  Only
1103
  ///   works on systems with GraphViz (Mac OS X) or dot+gv installed.
1104
  void viewAST() const;
1105
1106
  /// Skip no-op (attributed, compound) container stmts and skip captured
1107
  /// stmt at the top, if \a IgnoreCaptured is true.
1108
  Stmt *IgnoreContainers(bool IgnoreCaptured = false);
1109
98.9k
  const Stmt *IgnoreContainers(bool IgnoreCaptured = false) const {
1110
98.9k
    return const_cast<Stmt *>(this)->IgnoreContainers(IgnoreCaptured);
1111
98.9k
  }
1112
1113
  const Stmt *stripLabelLikeStatements() const;
1114
1.67M
  Stmt *stripLabelLikeStatements() {
1115
1.67M
    return const_cast<Stmt*>(
1116
1.67M
      const_cast<const Stmt*>(this)->stripLabelLikeStatements());
1117
1.67M
  }
1118
1119
  /// Child Iterators: All subclasses must implement 'children'
1120
  /// to permit easy iteration over the substatements/subexpessions of an
1121
  /// AST node.  This permits easy iteration over all nodes in the AST.
1122
  using child_iterator = StmtIterator;
1123
  using const_child_iterator = ConstStmtIterator;
1124
1125
  using child_range = llvm::iterator_range<child_iterator>;
1126
  using const_child_range = llvm::iterator_range<const_child_iterator>;
1127
1128
  child_range children();
1129
1130
27.8M
  const_child_range children() const {
1131
27.8M
    auto Children = const_cast<Stmt *>(this)->children();
1132
27.8M
    return const_child_range(Children.begin(), Children.end());
1133
27.8M
  }
1134
1135
2.48M
  child_iterator child_begin() { return children().begin(); }
1136
18
  child_iterator child_end() { return children().end(); }
1137
1138
418k
  const_child_iterator child_begin() const { return children().begin(); }
1139
4.39k
  const_child_iterator child_end() const { return children().end(); }
1140
1141
  /// Produce a unique representation of the given statement.
1142
  ///
1143
  /// \param ID once the profiling operation is complete, will contain
1144
  /// the unique representation of the given statement.
1145
  ///
1146
  /// \param Context the AST context in which the statement resides
1147
  ///
1148
  /// \param Canonical whether the profile should be based on the canonical
1149
  /// representation of this statement (e.g., where non-type template
1150
  /// parameters are identified by index/level rather than their
1151
  /// declaration pointers) or the exact representation of the statement as
1152
  /// written in the source.
1153
  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
1154
               bool Canonical) const;
1155
1156
  /// Calculate a unique representation for a statement that is
1157
  /// stable across compiler invocations.
1158
  ///
1159
  /// \param ID profile information will be stored in ID.
1160
  ///
1161
  /// \param Hash an ODRHash object which will be called where pointers would
1162
  /// have been used in the Profile function.
1163
  void ProcessODRHash(llvm::FoldingSetNodeID &ID, ODRHash& Hash) const;
1164
};
1165
1166
/// DeclStmt - Adaptor class for mixing declarations with statements and
1167
/// expressions. For example, CompoundStmt mixes statements, expressions
1168
/// and declarations (variables, types). Another example is ForStmt, where
1169
/// the first statement can be an expression or a declaration.
1170
class DeclStmt : public Stmt {
1171
  DeclGroupRef DG;
1172
  SourceLocation StartLoc, EndLoc;
1173
1174
public:
1175
  DeclStmt(DeclGroupRef dg, SourceLocation startLoc, SourceLocation endLoc)
1176
2.05M
      : Stmt(DeclStmtClass), DG(dg), StartLoc(startLoc), EndLoc(endLoc) {}
1177
1178
  /// Build an empty declaration statement.
1179
15.7k
  explicit DeclStmt(EmptyShell Empty) : Stmt(DeclStmtClass, Empty) {}
1180
1181
  /// isSingleDecl - This method returns true if this DeclStmt refers
1182
  /// to a single Decl.
1183
517k
  bool isSingleDecl() const { return DG.isSingleDecl(); }
1184
1185
53.2k
  const Decl *getSingleDecl() const { return DG.getSingleDecl(); }
1186
505k
  Decl *getSingleDecl() { return DG.getSingleDecl(); }
1187
1188
1.78k
  const DeclGroupRef getDeclGroup() const { return DG; }
1189
23.7k
  DeclGroupRef getDeclGroup() { return DG; }
1190
15.7k
  void setDeclGroup(DeclGroupRef DGR) { DG = DGR; }
1191
1192
15.7k
  void setStartLoc(SourceLocation L) { StartLoc = L; }
1193
376k
  SourceLocation getEndLoc() const { return EndLoc; }
1194
15.7k
  void setEndLoc(SourceLocation L) { EndLoc = L; }
1195
1196
739k
  SourceLocation getBeginLoc() const LLVM_READONLY { return StartLoc; }
1197
1198
2.00M
  static bool classof(const Stmt *T) {
1199
2.00M
    return T->getStmtClass() == DeclStmtClass;
1200
2.00M
  }
1201
1202
  // Iterators over subexpressions.
1203
119k
  child_range children() {
1204
119k
    return child_range(child_iterator(DG.begin(), DG.end()),
1205
119k
                       child_iterator(DG.end(), DG.end()));
1206
119k
  }
1207
1208
0
  const_child_range children() const {
1209
0
    auto Children = const_cast<DeclStmt *>(this)->children();
1210
0
    return const_child_range(Children);
1211
0
  }
1212
1213
  using decl_iterator = DeclGroupRef::iterator;
1214
  using const_decl_iterator = DeclGroupRef::const_iterator;
1215
  using decl_range = llvm::iterator_range<decl_iterator>;
1216
  using decl_const_range = llvm::iterator_range<const_decl_iterator>;
1217
1218
1.22M
  decl_range decls() { return decl_range(decl_begin(), decl_end()); }
1219
1220
745k
  decl_const_range decls() const {
1221
745k
    return decl_const_range(decl_begin(), decl_end());
1222
745k
  }
1223
1224
1.58M
  decl_iterator decl_begin() { return DG.begin(); }
1225
1.22M
  decl_iterator decl_end() { return DG.end(); }
1226
771k
  const_decl_iterator decl_begin() const { return DG.begin(); }
1227
745k
  const_decl_iterator decl_end() const { return DG.end(); }
1228
1229
  using reverse_decl_iterator = std::reverse_iterator<decl_iterator>;
1230
1231
5.01k
  reverse_decl_iterator decl_rbegin() {
1232
5.01k
    return reverse_decl_iterator(decl_end());
1233
5.01k
  }
1234
1235
5.01k
  reverse_decl_iterator decl_rend() {
1236
5.01k
    return reverse_decl_iterator(decl_begin());
1237
5.01k
  }
1238
};
1239
1240
/// NullStmt - This is the null statement ";": C99 6.8.3p3.
1241
///
1242
class NullStmt : public Stmt {
1243
public:
1244
  NullStmt(SourceLocation L, bool hasLeadingEmptyMacro = false)
1245
107k
      : Stmt(NullStmtClass) {
1246
107k
    NullStmtBits.HasLeadingEmptyMacro = hasLeadingEmptyMacro;
1247
107k
    setSemiLoc(L);
1248
107k
  }
1249
1250
  /// Build an empty null statement.
1251
281
  explicit NullStmt(EmptyShell Empty) : Stmt(NullStmtClass, Empty) {}
1252
1253
12.8k
  SourceLocation getSemiLoc() const { return NullStmtBits.SemiLoc; }
1254
107k
  void setSemiLoc(SourceLocation L) { NullStmtBits.SemiLoc = L; }
1255
1256
943
  bool hasLeadingEmptyMacro() const {
1257
943
    return NullStmtBits.HasLeadingEmptyMacro;
1258
943
  }
1259
1260
1.13k
  SourceLocation getBeginLoc() const { return getSemiLoc(); }
1261
6.42k
  SourceLocation getEndLoc() const { return getSemiLoc(); }
1262
1263
1.07M
  static bool classof(const Stmt *T) {
1264
1.07M
    return T->getStmtClass() == NullStmtClass;
1265
1.07M
  }
1266
1267
70.4k
  child_range children() {
1268
70.4k
    return child_range(child_iterator(), child_iterator());
1269
70.4k
  }
1270
1271
0
  const_child_range children() const {
1272
0
    return const_child_range(const_child_iterator(), const_child_iterator());
1273
0
  }
1274
};
1275
1276
/// CompoundStmt - This represents a group of statements like { stmt stmt }.
1277
class CompoundStmt final : public Stmt,
1278
                           private llvm::TrailingObjects<CompoundStmt, Stmt *> {
1279
  friend class ASTStmtReader;
1280
  friend TrailingObjects;
1281
1282
  /// The location of the closing "}". LBraceLoc is stored in CompoundStmtBits.
1283
  SourceLocation RBraceLoc;
1284
1285
  CompoundStmt(ArrayRef<Stmt *> Stmts, SourceLocation LB, SourceLocation RB);
1286
13.8k
  explicit CompoundStmt(EmptyShell Empty) : Stmt(CompoundStmtClass, Empty) {}
1287
1288
  void setStmts(ArrayRef<Stmt *> Stmts);
1289
1290
public:
1291
  static CompoundStmt *Create(const ASTContext &C, ArrayRef<Stmt *> Stmts,
1292
                              SourceLocation LB, SourceLocation RB);
1293
1294
  // Build an empty compound statement with a location.
1295
  explicit CompoundStmt(SourceLocation Loc)
1296
40.9k
      : Stmt(CompoundStmtClass), RBraceLoc(Loc) {
1297
40.9k
    CompoundStmtBits.NumStmts = 0;
1298
40.9k
    CompoundStmtBits.LBraceLoc = Loc;
1299
40.9k
  }
1300
1301
  // Build an empty compound statement.
1302
  static CompoundStmt *CreateEmpty(const ASTContext &C, unsigned NumStmts);
1303
1304
731k
  bool body_empty() const { return CompoundStmtBits.NumStmts == 0; }
1305
4.21M
  unsigned size() const { return CompoundStmtBits.NumStmts; }
1306
1307
  using body_iterator = Stmt **;
1308
  using body_range = llvm::iterator_range<body_iterator>;
1309
1310
1.08M
  body_range body() { return body_range(body_begin(), body_end()); }
1311
10.2M
  body_iterator body_begin() { return getTrailingObjects<Stmt *>(); }
1312
3.21M
  body_iterator body_end() { return body_begin() + size(); }
1313
400
  Stmt *body_front() { return !body_empty() ? body_begin()[0] : 
nullptr0
; }
1314
1315
57.3k
  Stmt *body_back() {
1316
57.3k
    return !body_empty() ? body_begin()[size() - 1] : 
nullptr0
;
1317
57.3k
  }
1318
1319
0
  void setLastStmt(Stmt *S) {
1320
0
    assert(!body_empty() && "setLastStmt");
1321
0
    body_begin()[size() - 1] = S;
1322
0
  }
1323
1324
  using const_body_iterator = Stmt *const *;
1325
  using body_const_range = llvm::iterator_range<const_body_iterator>;
1326
1327
148k
  body_const_range body() const {
1328
148k
    return body_const_range(body_begin(), body_end());
1329
148k
  }
1330
1331
1.72M
  const_body_iterator body_begin() const {
1332
1.72M
    return getTrailingObjects<Stmt *>();
1333
1.72M
  }
1334
1335
856k
  const_body_iterator body_end() const { return body_begin() + size(); }
1336
1337
12
  const Stmt *body_front() const {
1338
12
    return !body_empty() ? body_begin()[0] : 
nullptr0
;
1339
12
  }
1340
1341
10.7k
  const Stmt *body_back() const {
1342
10.7k
    return !body_empty() ? body_begin()[size() - 1] : 
nullptr0
;
1343
10.7k
  }
1344
1345
  using reverse_body_iterator = std::reverse_iterator<body_iterator>;
1346
1347
1.17M
  reverse_body_iterator body_rbegin() {
1348
1.17M
    return reverse_body_iterator(body_end());
1349
1.17M
  }
1350
1351
609k
  reverse_body_iterator body_rend() {
1352
609k
    return reverse_body_iterator(body_begin());
1353
609k
  }
1354
1355
  using const_reverse_body_iterator =
1356
      std::reverse_iterator<const_body_iterator>;
1357
1358
125k
  const_reverse_body_iterator body_rbegin() const {
1359
125k
    return const_reverse_body_iterator(body_end());
1360
125k
  }
1361
1362
125k
  const_reverse_body_iterator body_rend() const {
1363
125k
    return const_reverse_body_iterator(body_begin());
1364
125k
  }
1365
1366
992k
  SourceLocation getBeginLoc() const { return CompoundStmtBits.LBraceLoc; }
1367
4.59M
  SourceLocation getEndLoc() const { return RBraceLoc; }
1368
1369
724k
  SourceLocation getLBracLoc() const { return CompoundStmtBits.LBraceLoc; }
1370
422k
  SourceLocation getRBracLoc() const { return RBraceLoc; }
1371
1372
1.98M
  static bool classof(const Stmt *T) {
1373
1.98M
    return T->getStmtClass() == CompoundStmtClass;
1374
1.98M
  }
1375
1376
  // Iterators
1377
956k
  child_range children() { return child_range(body_begin(), body_end()); }
1378
1379
63
  const_child_range children() const {
1380
63
    return const_child_range(body_begin(), body_end());
1381
63
  }
1382
};
1383
1384
// SwitchCase is the base class for CaseStmt and DefaultStmt,
1385
class SwitchCase : public Stmt {
1386
protected:
1387
  /// The location of the ":".
1388
  SourceLocation ColonLoc;
1389
1390
  // The location of the "case" or "default" keyword. Stored in SwitchCaseBits.
1391
  // SourceLocation KeywordLoc;
1392
1393
  /// A pointer to the following CaseStmt or DefaultStmt class,
1394
  /// used by SwitchStmt.
1395
  SwitchCase *NextSwitchCase = nullptr;
1396
1397
  SwitchCase(StmtClass SC, SourceLocation KWLoc, SourceLocation ColonLoc)
1398
120k
      : Stmt(SC), ColonLoc(ColonLoc) {
1399
120k
    setKeywordLoc(KWLoc);
1400
120k
  }
1401
1402
27
  SwitchCase(StmtClass SC, EmptyShell) : Stmt(SC) {}
1403
1404
public:
1405
29.3k
  const SwitchCase *getNextSwitchCase() const { return NextSwitchCase; }
1406
154k
  SwitchCase *getNextSwitchCase() { return NextSwitchCase; }
1407
120k
  void setNextSwitchCase(SwitchCase *SC) { NextSwitchCase = SC; }
1408
1409
206k
  SourceLocation getKeywordLoc() const { return SwitchCaseBits.KeywordLoc; }
1410
120k
  void setKeywordLoc(SourceLocation L) { SwitchCaseBits.KeywordLoc = L; }
1411
53.4k
  SourceLocation getColonLoc() const { return ColonLoc; }
1412
27
  void setColonLoc(SourceLocation L) { ColonLoc = L; }
1413
1414
  inline Stmt *getSubStmt();
1415
103k
  const Stmt *getSubStmt() const {
1416
103k
    return const_cast<SwitchCase *>(this)->getSubStmt();
1417
103k
  }
1418
1419
38
  SourceLocation getBeginLoc() const { return getKeywordLoc(); }
1420
  inline SourceLocation getEndLoc() const LLVM_READONLY;
1421
1422
18.6M
  static bool classof(const Stmt *T) {
1423
18.6M
    return T->getStmtClass() == CaseStmtClass ||
1424
18.6M
           
T->getStmtClass() == DefaultStmtClass18.5M
;
1425
18.6M
  }
1426
};
1427
1428
/// CaseStmt - Represent a case statement. It can optionally be a GNU case
1429
/// statement of the form LHS ... RHS representing a range of cases.
1430
class CaseStmt final
1431
    : public SwitchCase,
1432
      private llvm::TrailingObjects<CaseStmt, Stmt *, SourceLocation> {
1433
  friend TrailingObjects;
1434
1435
  // CaseStmt is followed by several trailing objects, some of which optional.
1436
  // Note that it would be more convenient to put the optional trailing objects
1437
  // at the end but this would impact children().
1438
  // The trailing objects are in order:
1439
  //
1440
  // * A "Stmt *" for the LHS of the case statement. Always present.
1441
  //
1442
  // * A "Stmt *" for the RHS of the case statement. This is a GNU extension
1443
  //   which allow ranges in cases statement of the form LHS ... RHS.
1444
  //   Present if and only if caseStmtIsGNURange() is true.
1445
  //
1446
  // * A "Stmt *" for the substatement of the case statement. Always present.
1447
  //
1448
  // * A SourceLocation for the location of the ... if this is a case statement
1449
  //   with a range. Present if and only if caseStmtIsGNURange() is true.
1450
  enum { LhsOffset = 0, SubStmtOffsetFromRhs = 1 };
1451
  enum { NumMandatoryStmtPtr = 2 };
1452
1453
6.65k
  unsigned numTrailingObjects(OverloadToken<Stmt *>) const {
1454
6.65k
    return NumMandatoryStmtPtr + caseStmtIsGNURange();
1455
6.65k
  }
1456
1457
0
  unsigned numTrailingObjects(OverloadToken<SourceLocation>) const {
1458
0
    return caseStmtIsGNURange();
1459
0
  }
1460
1461
345k
  unsigned lhsOffset() const { return LhsOffset; }
1462
554k
  unsigned rhsOffset() const { return LhsOffset + caseStmtIsGNURange(); }
1463
554k
  unsigned subStmtOffset() const { return rhsOffset() + SubStmtOffsetFromRhs; }
1464
1465
  /// Build a case statement assuming that the storage for the
1466
  /// trailing objects has been properly allocated.
1467
  CaseStmt(Expr *lhs, Expr *rhs, SourceLocation caseLoc,
1468
           SourceLocation ellipsisLoc, SourceLocation colonLoc)
1469
115k
      : SwitchCase(CaseStmtClass, caseLoc, colonLoc) {
1470
115k
    // Handle GNU case statements of the form LHS ... RHS.
1471
115k
    bool IsGNURange = rhs != nullptr;
1472
115k
    SwitchCaseBits.CaseStmtIsGNURange = IsGNURange;
1473
115k
    setLHS(lhs);
1474
115k
    setSubStmt(nullptr);
1475
115k
    if (IsGNURange) {
1476
98
      setRHS(rhs);
1477
98
      setEllipsisLoc(ellipsisLoc);
1478
98
    }
1479
115k
  }
1480
1481
  /// Build an empty switch case statement.
1482
  explicit CaseStmt(EmptyShell Empty, bool CaseStmtIsGNURange)
1483
21
      : SwitchCase(CaseStmtClass, Empty) {
1484
21
    SwitchCaseBits.CaseStmtIsGNURange = CaseStmtIsGNURange;
1485
21
  }
1486
1487
public:
1488
  /// Build a case statement.
1489
  static CaseStmt *Create(const ASTContext &Ctx, Expr *lhs, Expr *rhs,
1490
                          SourceLocation caseLoc, SourceLocation ellipsisLoc,
1491
                          SourceLocation colonLoc);
1492
1493
  /// Build an empty case statement.
1494
  static CaseStmt *CreateEmpty(const ASTContext &Ctx, bool CaseStmtIsGNURange);
1495
1496
  /// True if this case statement is of the form case LHS ... RHS, which
1497
  /// is a GNU extension. In this case the RHS can be obtained with getRHS()
1498
  /// and the location of the ellipsis can be obtained with getEllipsisLoc().
1499
798k
  bool caseStmtIsGNURange() const { return SwitchCaseBits.CaseStmtIsGNURange; }
1500
1501
159k
  SourceLocation getCaseLoc() const { return getKeywordLoc(); }
1502
  void setCaseLoc(SourceLocation L) { setKeywordLoc(L); }
1503
1504
  /// Get the location of the ... in a case statement of the form LHS ... RHS.
1505
53.1k
  SourceLocation getEllipsisLoc() const {
1506
53.1k
    return caseStmtIsGNURange() ? 
*getTrailingObjects<SourceLocation>()6
1507
53.1k
                                : 
SourceLocation()53.1k
;
1508
53.1k
  }
1509
1510
  /// Set the location of the ... in a case statement of the form LHS ... RHS.
1511
  /// Assert that this case statement is of this form.
1512
98
  void setEllipsisLoc(SourceLocation L) {
1513
98
    assert(
1514
98
        caseStmtIsGNURange() &&
1515
98
        "setEllipsisLoc but this is not a case stmt of the form LHS ... RHS!");
1516
98
    *getTrailingObjects<SourceLocation>() = L;
1517
98
  }
1518
1519
178k
  Expr *getLHS() {
1520
178k
    return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[lhsOffset()]);
1521
178k
  }
1522
1523
51.2k
  const Expr *getLHS() const {
1524
51.2k
    return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[lhsOffset()]);
1525
51.2k
  }
1526
1527
115k
  void setLHS(Expr *Val) {
1528
115k
    getTrailingObjects<Stmt *>()[lhsOffset()] = reinterpret_cast<Stmt *>(Val);
1529
115k
  }
1530
1531
157k
  Expr *getRHS() {
1532
157k
    return caseStmtIsGNURange() ? reinterpret_cast<Expr *>(
1533
333
                                      getTrailingObjects<Stmt *>()[rhsOffset()])
1534
157k
                                : 
nullptr156k
;
1535
157k
  }
1536
1537
26.0k
  const Expr *getRHS() const {
1538
26.0k
    return caseStmtIsGNURange() ? reinterpret_cast<Expr *>(
1539
115
                                      getTrailingObjects<Stmt *>()[rhsOffset()])
1540
26.0k
                                : 
nullptr25.9k
;
1541
26.0k
  }
1542
1543
98
  void setRHS(Expr *Val) {
1544
98
    assert(caseStmtIsGNURange() &&
1545
98
           "setRHS but this is not a case stmt of the form LHS ... RHS!");
1546
98
    getTrailingObjects<Stmt *>()[rhsOffset()] = reinterpret_cast<Stmt *>(Val);
1547
98
  }
1548
1549
267k
  Stmt *getSubStmt() { return getTrailingObjects<Stmt *>()[subStmtOffset()]; }
1550
55.4k
  const Stmt *getSubStmt() const {
1551
55.4k
    return getTrailingObjects<Stmt *>()[subStmtOffset()];
1552
55.4k
  }
1553
1554
231k
  void setSubStmt(Stmt *S) {
1555
231k
    getTrailingObjects<Stmt *>()[subStmtOffset()] = S;
1556
231k
  }
1557
1558
43.9k
  SourceLocation getBeginLoc() const { return getKeywordLoc(); }
1559
467
  SourceLocation getEndLoc() const LLVM_READONLY {
1560
467
    // Handle deeply nested case statements with iteration instead of recursion.
1561
467
    const CaseStmt *CS = this;
1562
477
    while (const auto *CS2 = dyn_cast<CaseStmt>(CS->getSubStmt()))
1563
10
      CS = CS2;
1564
467
1565
467
    return CS->getSubStmt()->getEndLoc();
1566
467
  }
1567
1568
286k
  static bool classof(const Stmt *T) {
1569
286k
    return T->getStmtClass() == CaseStmtClass;
1570
286k
  }
1571
1572
  // Iterators
1573
6.55k
  child_range children() {
1574
6.55k
    return child_range(getTrailingObjects<Stmt *>(),
1575
6.55k
                       getTrailingObjects<Stmt *>() +
1576
6.55k
                           numTrailingObjects(OverloadToken<Stmt *>()));
1577
6.55k
  }
1578
1579
0
  const_child_range children() const {
1580
0
    return const_child_range(getTrailingObjects<Stmt *>(),
1581
0
                             getTrailingObjects<Stmt *>() +
1582
0
                                 numTrailingObjects(OverloadToken<Stmt *>()));
1583
0
  }
1584
};
1585
1586
class DefaultStmt : public SwitchCase {
1587
  Stmt *SubStmt;
1588
1589
public:
1590
  DefaultStmt(SourceLocation DL, SourceLocation CL, Stmt *substmt)
1591
4.69k
      : SwitchCase(DefaultStmtClass, DL, CL), SubStmt(substmt) {}
1592
1593
  /// Build an empty default statement.
1594
  explicit DefaultStmt(EmptyShell Empty)
1595
6
      : SwitchCase(DefaultStmtClass, Empty) {}
1596
1597
8.29k
  Stmt *getSubStmt() { return SubStmt; }
1598
1.99k
  const Stmt *getSubStmt() const { return SubStmt; }
1599
6
  void setSubStmt(Stmt *S) { SubStmt = S; }
1600
1601
753
  SourceLocation getDefaultLoc() const { return getKeywordLoc(); }
1602
  void setDefaultLoc(SourceLocation L) { setKeywordLoc(L); }
1603
1604
2.68k
  SourceLocation getBeginLoc() const { return getKeywordLoc(); }
1605
86
  SourceLocation getEndLoc() const LLVM_READONLY {
1606
86
    return SubStmt->getEndLoc();
1607
86
  }
1608
1609
119k
  static bool classof(const Stmt *T) {
1610
119k
    return T->getStmtClass() == DefaultStmtClass;
1611
119k
  }
1612
1613
  // Iterators
1614
584
  child_range children() { return child_range(&SubStmt, &SubStmt + 1); }
1615
1616
0
  const_child_range children() const {
1617
0
    return const_child_range(&SubStmt, &SubStmt + 1);
1618
0
  }
1619
};
1620
1621
SourceLocation SwitchCase::getEndLoc() const {
1622
  if (const auto *CS = dyn_cast<CaseStmt>(this))
1623
    return CS->getEndLoc();
1624
  else if (const auto *DS = dyn_cast<DefaultStmt>(this))
1625
    return DS->getEndLoc();
1626
  llvm_unreachable("SwitchCase is neither a CaseStmt nor a DefaultStmt!");
1627
}
1628
1629
149k
Stmt *SwitchCase::getSubStmt() {
1630
149k
  if (auto *CS = dyn_cast<CaseStmt>(this))
1631
143k
    return CS->getSubStmt();
1632
5.82k
  else if (auto *DS = dyn_cast<DefaultStmt>(this))
1633
5.82k
    return DS->getSubStmt();
1634
0
  llvm_unreachable("SwitchCase is neither a CaseStmt nor a DefaultStmt!");
1635
0
}
1636
1637
/// Represents a statement that could possibly have a value and type. This
1638
/// covers expression-statements, as well as labels and attributed statements.
1639
///
1640
/// Value statements have a special meaning when they are the last non-null
1641
/// statement in a GNU statement expression, where they determine the value
1642
/// of the statement expression.
1643
class ValueStmt : public Stmt {
1644
protected:
1645
  using Stmt::Stmt;
1646
1647
public:
1648
  const Expr *getExprStmt() const;
1649
0
  Expr *getExprStmt() {
1650
0
    const ValueStmt *ConstThis = this;
1651
0
    return const_cast<Expr*>(ConstThis->getExprStmt());
1652
0
  }
1653
1654
11.1k
  static bool classof(const Stmt *T) {
1655
11.1k
    return T->getStmtClass() >= firstValueStmtConstant &&
1656
11.1k
           
T->getStmtClass() <= lastValueStmtConstant10.9k
;
1657
11.1k
  }
1658
};
1659
1660
/// LabelStmt - Represents a label, which has a substatement.  For example:
1661
///    foo: return;
1662
class LabelStmt : public ValueStmt {
1663
  LabelDecl *TheDecl;
1664
  Stmt *SubStmt;
1665
1666
public:
1667
  /// Build a label statement.
1668
  LabelStmt(SourceLocation IL, LabelDecl *D, Stmt *substmt)
1669
4.04k
      : ValueStmt(LabelStmtClass), TheDecl(D), SubStmt(substmt) {
1670
4.04k
    setIdentLoc(IL);
1671
4.04k
  }
1672
1673
  /// Build an empty label statement.
1674
4
  explicit LabelStmt(EmptyShell Empty) : ValueStmt(LabelStmtClass, Empty) {}
1675
1676
536
  SourceLocation getIdentLoc() const { return LabelStmtBits.IdentLoc; }
1677
4.04k
  void setIdentLoc(SourceLocation L) { LabelStmtBits.IdentLoc = L; }
1678
1679
2.52k
  LabelDecl *getDecl() const { return TheDecl; }
1680
4
  void setDecl(LabelDecl *D) { TheDecl = D; }
1681
1682
  const char *getName() const;
1683
3.85k
  Stmt *getSubStmt() { return SubStmt; }
1684
1685
2.37k
  const Stmt *getSubStmt() const { return SubStmt; }
1686
4
  void setSubStmt(Stmt *SS) { SubStmt = SS; }
1687
1688
184
  SourceLocation getBeginLoc() const { return getIdentLoc(); }
1689
165
  SourceLocation getEndLoc() const LLVM_READONLY { return SubStmt->getEndLoc();}
1690
1691
508
  child_range children() { return child_range(&SubStmt, &SubStmt + 1); }
1692
1693
0
  const_child_range children() const {
1694
0
    return const_child_range(&SubStmt, &SubStmt + 1);
1695
0
  }
1696
1697
22.0M
  static bool classof(const Stmt *T) {
1698
22.0M
    return T->getStmtClass() == LabelStmtClass;
1699
22.0M
  }
1700
};
1701
1702
/// Represents an attribute applied to a statement.
1703
///
1704
/// Represents an attribute applied to a statement. For example:
1705
///   [[omp::for(...)]] for (...) { ... }
1706
class AttributedStmt final
1707
    : public ValueStmt,
1708
      private llvm::TrailingObjects<AttributedStmt, const Attr *> {
1709
  friend class ASTStmtReader;
1710
  friend TrailingObjects;
1711
1712
  Stmt *SubStmt;
1713
1714
  AttributedStmt(SourceLocation Loc, ArrayRef<const Attr *> Attrs,
1715
                 Stmt *SubStmt)
1716
1.04k
      : ValueStmt(AttributedStmtClass), SubStmt(SubStmt) {
1717
1.04k
    AttributedStmtBits.NumAttrs = Attrs.size();
1718
1.04k
    AttributedStmtBits.AttrLoc = Loc;
1719
1.04k
    std::copy(Attrs.begin(), Attrs.end(), getAttrArrayPtr());
1720
1.04k
  }
1721
1722
  explicit AttributedStmt(EmptyShell Empty, unsigned NumAttrs)
1723
10
      : ValueStmt(AttributedStmtClass, Empty) {
1724
10
    AttributedStmtBits.NumAttrs = NumAttrs;
1725
10
    AttributedStmtBits.AttrLoc = SourceLocation{};
1726
10
    std::fill_n(getAttrArrayPtr(), NumAttrs, nullptr);
1727
10
  }
1728
1729
237
  const Attr *const *getAttrArrayPtr() const {
1730
237
    return getTrailingObjects<const Attr *>();
1731
237
  }
1732
1.06k
  const Attr **getAttrArrayPtr() { return getTrailingObjects<const Attr *>(); }
1733
1734
public:
1735
  static AttributedStmt *Create(const ASTContext &C, SourceLocation Loc,
1736
                                ArrayRef<const Attr *> Attrs, Stmt *SubStmt);
1737
1738
  // Build an empty attributed statement.
1739
  static AttributedStmt *CreateEmpty(const ASTContext &C, unsigned NumAttrs);
1740
1741
62
  SourceLocation getAttrLoc() const { return AttributedStmtBits.AttrLoc; }
1742
237
  ArrayRef<const Attr *> getAttrs() const {
1743
237
    return llvm::makeArrayRef(getAttrArrayPtr(), AttributedStmtBits.NumAttrs);
1744
237
  }
1745
1746
92
  Stmt *getSubStmt() { return SubStmt; }
1747
132
  const Stmt *getSubStmt() const { return SubStmt; }
1748
1749
25
  SourceLocation getBeginLoc() const { return getAttrLoc(); }
1750
7
  SourceLocation getEndLoc() const LLVM_READONLY { return SubStmt->getEndLoc();}
1751
1752
972
  child_range children() { return child_range(&SubStmt, &SubStmt + 1); }
1753
1754
0
  const_child_range children() const {
1755
0
    return const_child_range(&SubStmt, &SubStmt + 1);
1756
0
  }
1757
1758
1.95M
  static bool classof(const Stmt *T) {
1759
1.95M
    return T->getStmtClass() == AttributedStmtClass;
1760
1.95M
  }
1761
};
1762
1763
/// IfStmt - This represents an if/then/else.
1764
class IfStmt final
1765
    : public Stmt,
1766
      private llvm::TrailingObjects<IfStmt, Stmt *, SourceLocation> {
1767
  friend TrailingObjects;
1768
1769
  // IfStmt is followed by several trailing objects, some of which optional.
1770
  // Note that it would be more convenient to put the optional trailing
1771
  // objects at then end but this would change the order of the children.
1772
  // The trailing objects are in order:
1773
  //
1774
  // * A "Stmt *" for the init statement.
1775
  //    Present if and only if hasInitStorage().
1776
  //
1777
  // * A "Stmt *" for the condition variable.
1778
  //    Present if and only if hasVarStorage(). This is in fact a "DeclStmt *".
1779
  //
1780
  // * A "Stmt *" for the condition.
1781
  //    Always present. This is in fact a "Expr *".
1782
  //
1783
  // * A "Stmt *" for the then statement.
1784
  //    Always present.
1785
  //
1786
  // * A "Stmt *" for the else statement.
1787
  //    Present if and only if hasElseStorage().
1788
  //
1789
  // * A "SourceLocation" for the location of the "else".
1790
  //    Present if and only if hasElseStorage().
1791
  enum { InitOffset = 0, ThenOffsetFromCond = 1, ElseOffsetFromCond = 2 };
1792
  enum { NumMandatoryStmtPtr = 2 };
1793
1794
572k
  unsigned numTrailingObjects(OverloadToken<Stmt *>) const {
1795
572k
    return NumMandatoryStmtPtr + hasElseStorage() + hasVarStorage() +
1796
572k
           hasInitStorage();
1797
572k
  }
1798
1799
0
  unsigned numTrailingObjects(OverloadToken<SourceLocation>) const {
1800
0
    return hasElseStorage();
1801
0
  }
1802
1803
140
  unsigned initOffset() const { return InitOffset; }
1804
9.15k
  unsigned varOffset() const { return InitOffset + hasInitStorage(); }
1805
4.92M
  unsigned condOffset() const {
1806
4.92M
    return InitOffset + hasInitStorage() + hasVarStorage();
1807
4.92M
  }
1808
1.85M
  unsigned thenOffset() const { return condOffset() + ThenOffsetFromCond; }
1809
382k
  unsigned elseOffset() const { return condOffset() + ElseOffsetFromCond; }
1810
1811
  /// Build an if/then/else statement.
1812
  IfStmt(const ASTContext &Ctx, SourceLocation IL, bool IsConstexpr, Stmt *Init,
1813
         VarDecl *Var, Expr *Cond, Stmt *Then, SourceLocation EL, Stmt *Else);
1814
1815
  /// Build an empty if/then/else statement.
1816
  explicit IfStmt(EmptyShell Empty, bool HasElse, bool HasVar, bool HasInit);
1817
1818
public:
1819
  /// Create an IfStmt.
1820
  static IfStmt *Create(const ASTContext &Ctx, SourceLocation IL,
1821
                        bool IsConstexpr, Stmt *Init, VarDecl *Var, Expr *Cond,
1822
                        Stmt *Then, SourceLocation EL = SourceLocation(),
1823
                        Stmt *Else = nullptr);
1824
1825
  /// Create an empty IfStmt optionally with storage for an else statement,
1826
  /// condition variable and init expression.
1827
  static IfStmt *CreateEmpty(const ASTContext &Ctx, bool HasElse, bool HasVar,
1828
                             bool HasInit);
1829
1830
  /// True if this IfStmt has the storage for an init statement.
1831
6.43M
  bool hasInitStorage() const { return IfStmtBits.HasInit; }
1832
1833
  /// True if this IfStmt has storage for a variable declaration.
1834
6.62M
  bool hasVarStorage() const { return IfStmtBits.HasVar; }
1835
1836
  /// True if this IfStmt has storage for an else statement.
1837
1.51M
  bool hasElseStorage() const { return IfStmtBits.HasElse; }
1838
1839
883k
  Expr *getCond() {
1840
883k
    return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[condOffset()]);
1841
883k
  }
1842
1843
792k
  const Expr *getCond() const {
1844
792k
    return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[condOffset()]);
1845
792k
  }
1846
1847
1.01M
  void setCond(Expr *Cond) {
1848
1.01M
    getTrailingObjects<Stmt *>()[condOffset()] = reinterpret_cast<Stmt *>(Cond);
1849
1.01M
  }
1850
1851
349k
  Stmt *getThen() { return getTrailingObjects<Stmt *>()[thenOffset()]; }
1852
485k
  const Stmt *getThen() const {
1853
485k
    return getTrailingObjects<Stmt *>()[thenOffset()];
1854
485k
  }
1855
1856
1.01M
  void setThen(Stmt *Then) {
1857
1.01M
    getTrailingObjects<Stmt *>()[thenOffset()] = Then;
1858
1.01M
  }
1859
1860
350k
  Stmt *getElse() {
1861
350k
    return hasElseStorage() ? 
getTrailingObjects<Stmt *>()[elseOffset()]86.4k
1862
350k
                            : 
nullptr263k
;
1863
350k
  }
1864
1865
489k
  const Stmt *getElse() const {
1866
489k
    return hasElseStorage() ? 
getTrailingObjects<Stmt *>()[elseOffset()]95.2k
1867
489k
                            : 
nullptr394k
;
1868
489k
  }
1869
1870
200k
  void setElse(Stmt *Else) {
1871
200k
    assert(hasElseStorage() &&
1872
200k
           "This if statement has no storage for an else statement!");
1873
200k
    getTrailingObjects<Stmt *>()[elseOffset()] = Else;
1874
200k
  }
1875
1876
  /// Retrieve the variable declared in this "if" statement, if any.
1877
  ///
1878
  /// In the following example, "x" is the condition variable.
1879
  /// \code
1880
  /// if (int x = foo()) {
1881
  ///   printf("x is %d", x);
1882
  /// }
1883
  /// \endcode
1884
  VarDecl *getConditionVariable();
1885
248k
  const VarDecl *getConditionVariable() const {
1886
248k
    return const_cast<IfStmt *>(this)->getConditionVariable();
1887
248k
  }
1888
1889
  /// Set the condition variable for this if statement.
1890
  /// The if statement must have storage for the condition variable.
1891
  void setConditionVariable(const ASTContext &Ctx, VarDecl *V);
1892
1893
  /// If this IfStmt has a condition variable, return the faux DeclStmt
1894
  /// associated with the creation of that condition variable.
1895
1.12M
  DeclStmt *getConditionVariableDeclStmt() {
1896
1.12M
    return hasVarStorage() ? static_cast<DeclStmt *>(
1897
5.98k
                                 getTrailingObjects<Stmt *>()[varOffset()])
1898
1.12M
                           : 
nullptr1.12M
;
1899
1.12M
  }
1900
1901
17
  const DeclStmt *getConditionVariableDeclStmt() const {
1902
17
    return hasVarStorage() ? static_cast<DeclStmt *>(
1903
3
                                 getTrailingObjects<Stmt *>()[varOffset()])
1904
17
                           : 
nullptr14
;
1905
17
  }
1906
1907
677k
  Stmt *getInit() {
1908
677k
    return hasInitStorage() ? 
getTrailingObjects<Stmt *>()[initOffset()]26
1909
677k
                            : 
nullptr677k
;
1910
677k
  }
1911
1912
247k
  const Stmt *getInit() const {
1913
247k
    return hasInitStorage() ? 
getTrailingObjects<Stmt *>()[initOffset()]34
1914
247k
                            : 
nullptr247k
;
1915
247k
  }
1916
1917
80
  void setInit(Stmt *Init) {
1918
80
    assert(hasInitStorage() &&
1919
80
           "This if statement has no storage for an init statement!");
1920
80
    getTrailingObjects<Stmt *>()[initOffset()] = Init;
1921
80
  }
1922
1923
331k
  SourceLocation getIfLoc() const { return IfStmtBits.IfLoc; }
1924
1.01M
  void setIfLoc(SourceLocation IfLoc) { IfStmtBits.IfLoc = IfLoc; }
1925
1926
101k
  SourceLocation getElseLoc() const {
1927
101k
    return hasElseStorage() ? 
*getTrailingObjects<SourceLocation>()34.3k
1928
101k
                            : 
SourceLocation()67.3k
;
1929
101k
  }
1930
1931
200k
  void setElseLoc(SourceLocation ElseLoc) {
1932
200k
    assert(hasElseStorage() &&
1933
200k
           "This if statement has no storage for an else statement!");
1934
200k
    *getTrailingObjects<SourceLocation>() = ElseLoc;
1935
200k
  }
1936
1937
612k
  bool isConstexpr() const { return IfStmtBits.IsConstexpr; }
1938
1.01M
  void setConstexpr(bool C) { IfStmtBits.IsConstexpr = C; }
1939
1940
  bool isObjCAvailabilityCheck() const;
1941
1942
127k
  SourceLocation getBeginLoc() const { return getIfLoc(); }
1943
8.84k
  SourceLocation getEndLoc() const LLVM_READONLY {
1944
8.84k
    if (getElse())
1945
1.19k
      return getElse()->getEndLoc();
1946
7.64k
    return getThen()->getEndLoc();
1947
7.64k
  }
1948
1949
  // Iterators over subexpressions.  The iterators will include iterating
1950
  // over the initialization expression referenced by the condition variable.
1951
337k
  child_range children() {
1952
337k
    return child_range(getTrailingObjects<Stmt *>(),
1953
337k
                       getTrailingObjects<Stmt *>() +
1954
337k
                           numTrailingObjects(OverloadToken<Stmt *>()));
1955
337k
  }
1956
1957
0
  const_child_range children() const {
1958
0
    return const_child_range(getTrailingObjects<Stmt *>(),
1959
0
                             getTrailingObjects<Stmt *>() +
1960
0
                                 numTrailingObjects(OverloadToken<Stmt *>()));
1961
0
  }
1962
1963
32.7k
  static bool classof(const Stmt *T) {
1964
32.7k
    return T->getStmtClass() == IfStmtClass;
1965
32.7k
  }
1966
};
1967
1968
/// SwitchStmt - This represents a 'switch' stmt.
1969
class SwitchStmt final : public Stmt,
1970
                         private llvm::TrailingObjects<SwitchStmt, Stmt *> {
1971
  friend TrailingObjects;
1972
1973
  /// Points to a linked list of case and default statements.
1974
  SwitchCase *FirstCase;
1975
1976
  // SwitchStmt is followed by several trailing objects,
1977
  // some of which optional. Note that it would be more convenient to
1978
  // put the optional trailing objects at the end but this would change
1979
  // the order in children().
1980
  // The trailing objects are in order:
1981
  //
1982
  // * A "Stmt *" for the init statement.
1983
  //    Present if and only if hasInitStorage().
1984
  //
1985
  // * A "Stmt *" for the condition variable.
1986
  //    Present if and only if hasVarStorage(). This is in fact a "DeclStmt *".
1987
  //
1988
  // * A "Stmt *" for the condition.
1989
  //    Always present. This is in fact an "Expr *".
1990
  //
1991
  // * A "Stmt *" for the body.
1992
  //    Always present.
1993
  enum { InitOffset = 0, BodyOffsetFromCond = 1 };
1994
  enum { NumMandatoryStmtPtr = 2 };
1995
1996
12.5k
  unsigned numTrailingObjects(OverloadToken<Stmt *>) const {
1997
12.5k
    return NumMandatoryStmtPtr + hasInitStorage() + hasVarStorage();
1998
12.5k
  }
1999
2000
196
  unsigned initOffset() const { return InitOffset; }
2001
218
  unsigned varOffset() const { return InitOffset + hasInitStorage(); }
2002
226k
  unsigned condOffset() const {
2003
226k
    return InitOffset + hasInitStorage() + hasVarStorage();
2004
226k
  }
2005
51.8k
  unsigned bodyOffset() const { return condOffset() + BodyOffsetFromCond; }
2006
2007
  /// Build a switch statement.
2008
  SwitchStmt(const ASTContext &Ctx, Stmt *Init, VarDecl *Var, Expr *Cond);
2009
2010
  /// Build a empty switch statement.
2011
  explicit SwitchStmt(EmptyShell Empty, bool HasInit, bool HasVar);
2012
2013
public:
2014
  /// Create a switch statement.
2015
  static SwitchStmt *Create(const ASTContext &Ctx, Stmt *Init, VarDecl *Var,
2016
                            Expr *Cond);
2017
2018
  /// Create an empty switch statement optionally with storage for
2019
  /// an init expression and a condition variable.
2020
  static SwitchStmt *CreateEmpty(const ASTContext &Ctx, bool HasInit,
2021
                                 bool HasVar);
2022
2023
  /// True if this SwitchStmt has storage for an init statement.
2024
271k
  bool hasInitStorage() const { return SwitchStmtBits.HasInit; }
2025
2026
  /// True if this SwitchStmt has storage for a condition variable.
2027
271k
  bool hasVarStorage() const { return SwitchStmtBits.HasVar; }
2028
2029
148k
  Expr *getCond() {
2030
148k
    return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[condOffset()]);
2031
148k
  }
2032
2033
11.1k
  const Expr *getCond() const {
2034
11.1k
    return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[condOffset()]);
2035
11.1k
  }
2036
2037
14.9k
  void setCond(Expr *Cond) {
2038
14.9k
    getTrailingObjects<Stmt *>()[condOffset()] = reinterpret_cast<Stmt *>(Cond);
2039
14.9k
  }
2040
2041
17.2k
  Stmt *getBody() { return getTrailingObjects<Stmt *>()[bodyOffset()]; }
2042
4.72k
  const Stmt *getBody() const {
2043
4.72k
    return getTrailingObjects<Stmt *>()[bodyOffset()];
2044
4.72k
  }
2045
2046
29.9k
  void setBody(Stmt *Body) {
2047
29.9k
    getTrailingObjects<Stmt *>()[bodyOffset()] = Body;
2048
29.9k
  }
2049
2050
24.8k
  Stmt *getInit() {
2051
24.8k
    return hasInitStorage() ? 
getTrailingObjects<Stmt *>()[initOffset()]79
2052
24.8k
                            : 
nullptr24.8k
;
2053
24.8k
  }
2054
2055
7.65k
  const Stmt *getInit() const {
2056
7.65k
    return hasInitStorage() ? 
getTrailingObjects<Stmt *>()[initOffset()]49
2057
7.65k
                            : 
nullptr7.60k
;
2058
7.65k
  }
2059
2060
68
  void setInit(Stmt *Init) {
2061
68
    assert(hasInitStorage() &&
2062
68
           "This switch statement has no storage for an init statement!");
2063
68
    getTrailingObjects<Stmt *>()[initOffset()] = Init;
2064
68
  }
2065
2066
  /// Retrieve the variable declared in this "switch" statement, if any.
2067
  ///
2068
  /// In the following example, "x" is the condition variable.
2069
  /// \code
2070
  /// switch (int x = foo()) {
2071
  ///   case 0: break;
2072
  ///   // ...
2073
  /// }
2074
  /// \endcode
2075
  VarDecl *getConditionVariable();
2076
7.64k
  const VarDecl *getConditionVariable() const {
2077
7.64k
    return const_cast<SwitchStmt *>(this)->getConditionVariable();
2078
7.64k
  }
2079
2080
  /// Set the condition variable in this switch statement.
2081
  /// The switch statement must have storage for it.
2082
  void setConditionVariable(const ASTContext &Ctx, VarDecl *VD);
2083
2084
  /// If this SwitchStmt has a condition variable, return the faux DeclStmt
2085
  /// associated with the creation of that condition variable.
2086
32.5k
  DeclStmt *getConditionVariableDeclStmt() {
2087
32.5k
    return hasVarStorage() ? static_cast<DeclStmt *>(
2088
163
                                 getTrailingObjects<Stmt *>()[varOffset()])
2089
32.5k
                           : 
nullptr32.3k
;
2090
32.5k
  }
2091
2092
2
  const DeclStmt *getConditionVariableDeclStmt() const {
2093
2
    return hasVarStorage() ? static_cast<DeclStmt *>(
2094
0
                                 getTrailingObjects<Stmt *>()[varOffset()])
2095
2
                           : nullptr;
2096
2
  }
2097
2098
24.2k
  SwitchCase *getSwitchCaseList() { return FirstCase; }
2099
4.24k
  const SwitchCase *getSwitchCaseList() const { return FirstCase; }
2100
22
  void setSwitchCaseList(SwitchCase *SC) { FirstCase = SC; }
2101
2102
13.5k
  SourceLocation getSwitchLoc() const { return SwitchStmtBits.SwitchLoc; }
2103
29.9k
  void setSwitchLoc(SourceLocation L) { SwitchStmtBits.SwitchLoc = L; }
2104
2105
14.9k
  void setBody(Stmt *S, SourceLocation SL) {
2106
14.9k
    setBody(S);
2107
14.9k
    setSwitchLoc(SL);
2108
14.9k
  }
2109
2110
120k
  void addSwitchCase(SwitchCase *SC) {
2111
120k
    assert(!SC->getNextSwitchCase() &&
2112
120k
           "case/default already added to a switch");
2113
120k
    SC->setNextSwitchCase(FirstCase);
2114
120k
    FirstCase = SC;
2115
120k
  }
2116
2117
  /// Set a flag in the SwitchStmt indicating that if the 'switch (X)' is a
2118
  /// switch over an enum value then all cases have been explicitly covered.
2119
2.56k
  void setAllEnumCasesCovered() { SwitchStmtBits.AllEnumCasesCovered = true; }
2120
2121
  /// Returns true if the SwitchStmt is a switch of an enum value and all cases
2122
  /// have been explicitly covered.
2123
6.60k
  bool isAllEnumCasesCovered() const {
2124
6.60k
    return SwitchStmtBits.AllEnumCasesCovered;
2125
6.60k
  }
2126
2127
1.62k
  SourceLocation getBeginLoc() const { return getSwitchLoc(); }
2128
398
  SourceLocation getEndLoc() const LLVM_READONLY {
2129
398
    return getBody() ? getBody()->getEndLoc()
2130
398
                     : 
reinterpret_cast<const Stmt *>(getCond())->getEndLoc()0
;
2131
398
  }
2132
2133
  // Iterators
2134
12.5k
  child_range children() {
2135
12.5k
    return child_range(getTrailingObjects<Stmt *>(),
2136
12.5k
                       getTrailingObjects<Stmt *>() +
2137
12.5k
                           numTrailingObjects(OverloadToken<Stmt *>()));
2138
12.5k
  }
2139
2140
0
  const_child_range children() const {
2141
0
    return const_child_range(getTrailingObjects<Stmt *>(),
2142
0
                             getTrailingObjects<Stmt *>() +
2143
0
                                 numTrailingObjects(OverloadToken<Stmt *>()));
2144
0
  }
2145
2146
816k
  static bool classof(const Stmt *T) {
2147
816k
    return T->getStmtClass() == SwitchStmtClass;
2148
816k
  }
2149
};
2150
2151
/// WhileStmt - This represents a 'while' stmt.
2152
class WhileStmt final : public Stmt,
2153
                        private llvm::TrailingObjects<WhileStmt, Stmt *> {
2154
  friend TrailingObjects;
2155
2156
  // WhileStmt is followed by several trailing objects,
2157
  // some of which optional. Note that it would be more
2158
  // convenient to put the optional trailing object at the end
2159
  // but this would affect children().
2160
  // The trailing objects are in order:
2161
  //
2162
  // * A "Stmt *" for the condition variable.
2163
  //    Present if and only if hasVarStorage(). This is in fact a "DeclStmt *".
2164
  //
2165
  // * A "Stmt *" for the condition.
2166
  //    Always present. This is in fact an "Expr *".
2167
  //
2168
  // * A "Stmt *" for the body.
2169
  //    Always present.
2170
  //
2171
  enum { VarOffset = 0, BodyOffsetFromCond = 1 };
2172
  enum { NumMandatoryStmtPtr = 2 };
2173
2174
573
  unsigned varOffset() const { return VarOffset; }
2175
219k
  unsigned condOffset() const { return VarOffset + hasVarStorage(); }
2176
100k
  unsigned bodyOffset() const { return condOffset() + BodyOffsetFromCond; }
2177
2178
20.9k
  unsigned numTrailingObjects(OverloadToken<Stmt *>) const {
2179
20.9k
    return NumMandatoryStmtPtr + hasVarStorage();
2180
20.9k
  }
2181
2182
  /// Build a while statement.
2183
  WhileStmt(const ASTContext &Ctx, VarDecl *Var, Expr *Cond, Stmt *Body,
2184
            SourceLocation WL);
2185
2186
  /// Build an empty while statement.
2187
  explicit WhileStmt(EmptyShell Empty, bool HasVar);
2188
2189
public:
2190
  /// Create a while statement.
2191
  static WhileStmt *Create(const ASTContext &Ctx, VarDecl *Var, Expr *Cond,
2192
                           Stmt *Body, SourceLocation WL);
2193
2194
  /// Create an empty while statement optionally with storage for
2195
  /// a condition variable.
2196
  static WhileStmt *CreateEmpty(const ASTContext &Ctx, bool HasVar);
2197
2198
  /// True if this WhileStmt has storage for a condition variable.
2199
264k
  bool hasVarStorage() const { return WhileStmtBits.HasVar; }
2200
2201
29.5k
  Expr *getCond() {
2202
29.5k
    return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[condOffset()]);
2203
29.5k
  }
2204
2205
32.6k
  const Expr *getCond() const {
2206
32.6k
    return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[condOffset()]);
2207
32.6k
  }
2208
2209
57.5k
  void setCond(Expr *Cond) {
2210
57.5k
    getTrailingObjects<Stmt *>()[condOffset()] = reinterpret_cast<Stmt *>(Cond);
2211
57.5k
  }
2212
2213
10.7k
  Stmt *getBody() { return getTrailingObjects<Stmt *>()[bodyOffset()]; }
2214
31.7k
  const Stmt *getBody() const {
2215
31.7k
    return getTrailingObjects<Stmt *>()[bodyOffset()];
2216
31.7k
  }
2217
2218
57.5k
  void setBody(Stmt *Body) {
2219
57.5k
    getTrailingObjects<Stmt *>()[bodyOffset()] = Body;
2220
57.5k
  }
2221
2222
  /// Retrieve the variable declared in this "while" statement, if any.
2223
  ///
2224
  /// In the following example, "x" is the condition variable.
2225
  /// \code
2226
  /// while (int x = random()) {
2227
  ///   // ...
2228
  /// }
2229
  /// \endcode
2230
  VarDecl *getConditionVariable();
2231
11.0k
  const VarDecl *getConditionVariable() const {
2232
11.0k
    return const_cast<WhileStmt *>(this)->getConditionVariable();
2233
11.0k
  }
2234
2235
  /// Set the condition variable of this while statement.
2236
  /// The while statement must have storage for it.
2237
  void setConditionVariable(const ASTContext &Ctx, VarDecl *V);
2238
2239
  /// If this WhileStmt has a condition variable, return the faux DeclStmt
2240
  /// associated with the creation of that condition variable.
2241
23.9k
  DeclStmt *getConditionVariableDeclStmt() {
2242
23.9k
    return hasVarStorage() ? static_cast<DeclStmt *>(
2243
266
                                 getTrailingObjects<Stmt *>()[varOffset()])
2244
23.9k
                           : 
nullptr23.7k
;
2245
23.9k
  }
2246
2247
0
  const DeclStmt *getConditionVariableDeclStmt() const {
2248
0
    return hasVarStorage() ? static_cast<DeclStmt *>(
2249
0
                                 getTrailingObjects<Stmt *>()[varOffset()])
2250
0
                           : nullptr;
2251
0
  }
2252
2253
23.2k
  SourceLocation getWhileLoc() const { return WhileStmtBits.WhileLoc; }
2254
57.5k
  void setWhileLoc(SourceLocation L) { WhileStmtBits.WhileLoc = L; }
2255
2256
15.3k
  SourceLocation getBeginLoc() const { return getWhileLoc(); }
2257
9.09k
  SourceLocation getEndLoc() const LLVM_READONLY {
2258
9.09k
    return getBody()->getEndLoc();
2259
9.09k
  }
2260
2261
67.2k
  static bool classof(const Stmt *T) {
2262
67.2k
    return T->getStmtClass() == WhileStmtClass;
2263
67.2k
  }
2264
2265
  // Iterators
2266
20.9k
  child_range children() {
2267
20.9k
    return child_range(getTrailingObjects<Stmt *>(),
2268
20.9k
                       getTrailingObjects<Stmt *>() +
2269
20.9k
                           numTrailingObjects(OverloadToken<Stmt *>()));
2270
20.9k
  }
2271
2272
0
  const_child_range children() const {
2273
0
    return const_child_range(getTrailingObjects<Stmt *>(),
2274
0
                             getTrailingObjects<Stmt *>() +
2275
0
                                 numTrailingObjects(OverloadToken<Stmt *>()));
2276
0
  }
2277
};
2278
2279
/// DoStmt - This represents a 'do/while' stmt.
2280
class DoStmt : public Stmt {
2281
  enum { BODY, COND, END_EXPR };
2282
  Stmt *SubExprs[END_EXPR];
2283
  SourceLocation WhileLoc;
2284
  SourceLocation RParenLoc; // Location of final ')' in do stmt condition.
2285
2286
public:
2287
  DoStmt(Stmt *Body, Expr *Cond, SourceLocation DL, SourceLocation WL,
2288
         SourceLocation RP)
2289
138k
      : Stmt(DoStmtClass), WhileLoc(WL), RParenLoc(RP) {
2290
138k
    setCond(Cond);
2291
138k
    setBody(Body);
2292
138k
    setDoLoc(DL);
2293
138k
  }
2294
2295
  /// Build an empty do-while statement.
2296
1
  explicit DoStmt(EmptyShell Empty) : Stmt(DoStmtClass, Empty) {}
2297
2298
134k
  Expr *getCond() { return reinterpret_cast<Expr *>(SubExprs[COND]); }
2299
29.9k
  const Expr *getCond() const {
2300
29.9k
    return reinterpret_cast<Expr *>(SubExprs[COND]);
2301
29.9k
  }
2302
2303
138k
  void setCond(Expr *Cond) { SubExprs[COND] = reinterpret_cast<Stmt *>(Cond); }
2304
2305
133k
  Stmt *getBody() { return SubExprs[BODY]; }
2306
29.7k
  const Stmt *getBody() const { return SubExprs[BODY]; }
2307
138k
  void setBody(Stmt *Body) { SubExprs[BODY] = Body; }
2308
2309
67.7k
  SourceLocation getDoLoc() const { return DoStmtBits.DoLoc; }
2310
138k
  void setDoLoc(SourceLocation L) { DoStmtBits.DoLoc = L; }
2311
28.3k
  SourceLocation getWhileLoc() const { return WhileLoc; }
2312
1
  void setWhileLoc(SourceLocation L) { WhileLoc = L; }
2313
42.2k
  SourceLocation getRParenLoc() const { return RParenLoc; }
2314
1
  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2315
2316
53.5k
  SourceLocation getBeginLoc() const { return getDoLoc(); }
2317
28.0k
  SourceLocation getEndLoc() const { return getRParenLoc(); }
2318
2319
48.6k
  static bool classof(const Stmt *T) {
2320
48.6k
    return T->getStmtClass() == DoStmtClass;
2321
48.6k
  }
2322
2323
  // Iterators
2324
31.9k
  child_range children() {
2325
31.9k
    return child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
2326
31.9k
  }
2327
2328
0
  const_child_range children() const {
2329
0
    return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
2330
0
  }
2331
};
2332
2333
/// ForStmt - This represents a 'for (init;cond;inc)' stmt.  Note that any of
2334
/// the init/cond/inc parts of the ForStmt will be null if they were not
2335
/// specified in the source.
2336
class ForStmt : public Stmt {
2337
  enum { INIT, CONDVAR, COND, INC, BODY, END_EXPR };
2338
  Stmt* SubExprs[END_EXPR]; // SubExprs[INIT] is an expression or declstmt.
2339
  SourceLocation LParenLoc, RParenLoc;
2340
2341
public:
2342
  ForStmt(const ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar,
2343
          Expr *Inc, Stmt *Body, SourceLocation FL, SourceLocation LP,
2344
          SourceLocation RP);
2345
2346
  /// Build an empty for statement.
2347
4.57k
  explicit ForStmt(EmptyShell Empty) : Stmt(ForStmtClass, Empty) {}
2348
2349
205k
  Stmt *getInit() { return SubExprs[INIT]; }
2350
2351
  /// Retrieve the variable declared in this "for" statement, if any.
2352
  ///
2353
  /// In the following example, "y" is the condition variable.
2354
  /// \code
2355
  /// for (int x = random(); int y = mangle(x); ++x) {
2356
  ///   // ...
2357
  /// }
2358
  /// \endcode
2359
  VarDecl *getConditionVariable() const;
2360
  void setConditionVariable(const ASTContext &C, VarDecl *V);
2361
2362
  /// If this ForStmt has a condition variable, return the faux DeclStmt
2363
  /// associated with the creation of that condition variable.
2364
38
  const DeclStmt *getConditionVariableDeclStmt() const {
2365
38
    return reinterpret_cast<DeclStmt*>(SubExprs[CONDVAR]);
2366
38
  }
2367
2368
218k
  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
2369
189k
  Expr *getInc()  { return reinterpret_cast<Expr*>(SubExprs[INC]); }
2370
164k
  Stmt *getBody() { return SubExprs[BODY]; }
2371
2372
69.6k
  const Stmt *getInit() const { return SubExprs[INIT]; }
2373
165k
  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
2374
162k
  const Expr *getInc()  const { return reinterpret_cast<Expr*>(SubExprs[INC]); }
2375
302k
  const Stmt *getBody() const { return SubExprs[BODY]; }
2376
2377
4.57k
  void setInit(Stmt *S) { SubExprs[INIT] = S; }
2378
4.57k
  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
2379
4.57k
  void setInc(Expr *E) { SubExprs[INC] = reinterpret_cast<Stmt*>(E); }
2380
4.57k
  void setBody(Stmt *S) { SubExprs[BODY] = S; }
2381
2382
515k
  SourceLocation getForLoc() const { return ForStmtBits.ForLoc; }
2383
4.57k
  void setForLoc(SourceLocation L) { ForStmtBits.ForLoc = L; }
2384
45.7k
  SourceLocation getLParenLoc() const { return LParenLoc; }
2385
4.57k
  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2386
47.5k
  SourceLocation getRParenLoc() const { return RParenLoc; }
2387
4.57k
  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2388
2389
322k
  SourceLocation getBeginLoc() const { return getForLoc(); }
2390
122k
  SourceLocation getEndLoc() const { return getBody()->getEndLoc(); }
2391
2392
159k
  static bool classof(const Stmt *T) {
2393
159k
    return T->getStmtClass() == ForStmtClass;
2394
159k
  }
2395
2396
  // Iterators
2397
101k
  child_range children() {
2398
101k
    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
2399
101k
  }
2400
2401
0
  const_child_range children() const {
2402
0
    return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
2403
0
  }
2404
};
2405
2406
/// GotoStmt - This represents a direct goto.
2407
class GotoStmt : public Stmt {
2408
  LabelDecl *Label;
2409
  SourceLocation LabelLoc;
2410
2411
public:
2412
  GotoStmt(LabelDecl *label, SourceLocation GL, SourceLocation LL)
2413
8.49k
      : Stmt(GotoStmtClass), Label(label), LabelLoc(LL) {
2414
8.49k
    setGotoLoc(GL);
2415
8.49k
  }
2416
2417
  /// Build an empty goto statement.
2418
2
  explicit GotoStmt(EmptyShell Empty) : Stmt(GotoStmtClass, Empty) {}
2419
2420
22.3k
  LabelDecl *getLabel() const { return Label; }
2421
2
  void setLabel(LabelDecl *D) { Label = D; }
2422
2423
4.30k
  SourceLocation getGotoLoc() const { return GotoStmtBits.GotoLoc; }
2424
8.50k
  void setGotoLoc(SourceLocation L) { GotoStmtBits.GotoLoc = L; }
2425
512
  SourceLocation getLabelLoc() const { return LabelLoc; }
2426
2
  void setLabelLoc(SourceLocation L) { LabelLoc = L; }
2427
2428
415
  SourceLocation getBeginLoc() const { return getGotoLoc(); }
2429
121
  SourceLocation getEndLoc() const { return getLabelLoc(); }
2430
2431
23.0k
  static bool classof(const Stmt *T) {
2432
23.0k
    return T->getStmtClass() == GotoStmtClass;
2433
23.0k
  }
2434
2435
  // Iterators
2436
9.09k
  child_range children() {
2437
9.09k
    return child_range(child_iterator(), child_iterator());
2438
9.09k
  }
2439
2440
0
  const_child_range children() const {
2441
0
    return const_child_range(const_child_iterator(), const_child_iterator());
2442
0
  }
2443
};
2444
2445
/// IndirectGotoStmt - This represents an indirect goto.
2446
class IndirectGotoStmt : public Stmt {
2447
  SourceLocation StarLoc;
2448
  Stmt *Target;
2449
2450
public:
2451
  IndirectGotoStmt(SourceLocation gotoLoc, SourceLocation starLoc, Expr *target)
2452
141
      : Stmt(IndirectGotoStmtClass), StarLoc(starLoc) {
2453
141
    setTarget(target);
2454
141
    setGotoLoc(gotoLoc);
2455
141
  }
2456
2457
  /// Build an empty indirect goto statement.
2458
  explicit IndirectGotoStmt(EmptyShell Empty)
2459
1
      : Stmt(IndirectGotoStmtClass, Empty) {}
2460
2461
142
  void setGotoLoc(SourceLocation L) { GotoStmtBits.GotoLoc = L; }
2462
58
  SourceLocation getGotoLoc() const { return GotoStmtBits.GotoLoc; }
2463
1
  void setStarLoc(SourceLocation L) { StarLoc = L; }
2464
5
  SourceLocation getStarLoc() const { return StarLoc; }
2465
2466
243
  Expr *getTarget() { return reinterpret_cast<Expr *>(Target); }
2467
62
  const Expr *getTarget() const {
2468
62
    return reinterpret_cast<const Expr *>(Target);
2469
62
  }
2470
142
  void setTarget(Expr *E) { Target = reinterpret_cast<Stmt *>(E); }
2471
2472
  /// getConstantTarget - Returns the fixed target of this indirect
2473
  /// goto, if one exists.
2474
  LabelDecl *getConstantTarget();
2475
54
  const LabelDecl *getConstantTarget() const {
2476
54
    return const_cast<IndirectGotoStmt *>(this)->getConstantTarget();
2477
54
  }
2478
2479
16
  SourceLocation getBeginLoc() const { return getGotoLoc(); }
2480
9
  SourceLocation getEndLoc() const LLVM_READONLY { return Target->getEndLoc(); }
2481
2482
7.78k
  static bool classof(const Stmt *T) {
2483
7.78k
    return T->getStmtClass() == IndirectGotoStmtClass;
2484
7.78k
  }
2485
2486
  // Iterators
2487
160
  child_range children() { return child_range(&Target, &Target + 1); }
2488
2489
0
  const_child_range children() const {
2490
0
    return const_child_range(&Target, &Target + 1);
2491
0
  }
2492
};
2493
2494
/// ContinueStmt - This represents a continue.
2495
class ContinueStmt : public Stmt {
2496
public:
2497
7.00k
  ContinueStmt(SourceLocation CL) : Stmt(ContinueStmtClass) {
2498
7.00k
    setContinueLoc(CL);
2499
7.00k
  }
2500
2501
  /// Build an empty continue statement.
2502
1
  explicit ContinueStmt(EmptyShell Empty) : Stmt(ContinueStmtClass, Empty) {}
2503
2504
1.38k
  SourceLocation getContinueLoc() const { return ContinueStmtBits.ContinueLoc; }
2505
7.00k
  void setContinueLoc(SourceLocation L) { ContinueStmtBits.ContinueLoc = L; }
2506
2507
1.31k
  SourceLocation getBeginLoc() const { return getContinueLoc(); }
2508
43
  SourceLocation getEndLoc() const { return getContinueLoc(); }
2509
2510
5.89k
  static bool classof(const Stmt *T) {
2511
5.89k
    return T->getStmtClass() == ContinueStmtClass;
2512
5.89k
  }
2513
2514
  // Iterators
2515
4.10k
  child_range children() {
2516
4.10k
    return child_range(child_iterator(), child_iterator());
2517
4.10k
  }
2518
2519
0
  const_child_range children() const {
2520
0
    return const_child_range(const_child_iterator(), const_child_iterator());
2521
0
  }
2522
};
2523
2524
/// BreakStmt - This represents a break.
2525
class BreakStmt : public Stmt {
2526
public:
2527
61.0k
  BreakStmt(SourceLocation BL) : Stmt(BreakStmtClass) {
2528
61.0k
    setBreakLoc(BL);
2529
61.0k
  }
2530
2531
  /// Build an empty break statement.
2532
17
  explicit BreakStmt(EmptyShell Empty) : Stmt(BreakStmtClass, Empty) {}
2533
2534
4.90k
  SourceLocation getBreakLoc() const { return BreakStmtBits.BreakLoc; }
2535
61.0k
  void setBreakLoc(SourceLocation L) { BreakStmtBits.BreakLoc = L; }
2536
2537
4.07k
  SourceLocation getBeginLoc() const { return getBreakLoc(); }
2538
760
  SourceLocation getEndLoc() const { return getBreakLoc(); }
2539
2540
33.1k
  static bool classof(const Stmt *T) {
2541
33.1k
    return T->getStmtClass() == BreakStmtClass;
2542
33.1k
  }
2543
2544
  // Iterators
2545
42.7k
  child_range children() {
2546
42.7k
    return child_range(child_iterator(), child_iterator());
2547
42.7k
  }
2548
2549
0
  const_child_range children() const {
2550
0
    return const_child_range(const_child_iterator(), const_child_iterator());
2551
0
  }
2552
};
2553
2554
/// ReturnStmt - This represents a return, optionally of an expression:
2555
///   return;
2556
///   return 4;
2557
///
2558
/// Note that GCC allows return with no argument in a function declared to
2559
/// return a value, and it allows returning a value in functions declared to
2560
/// return void.  We explicitly model this in the AST, which means you can't
2561
/// depend on the return type of the function and the presence of an argument.
2562
class ReturnStmt final
2563
    : public Stmt,
2564
      private llvm::TrailingObjects<ReturnStmt, const VarDecl *> {
2565
  friend TrailingObjects;
2566
2567
  /// The return expression.
2568
  Stmt *RetExpr;
2569
2570
  // ReturnStmt is followed optionally by a trailing "const VarDecl *"
2571
  // for the NRVO candidate. Present if and only if hasNRVOCandidate().
2572
2573
  /// True if this ReturnStmt has storage for an NRVO candidate.
2574
5.83M
  bool hasNRVOCandidate() const { return ReturnStmtBits.HasNRVOCandidate; }
2575
2576
0
  unsigned numTrailingObjects(OverloadToken<const VarDecl *>) const {
2577
0
    return hasNRVOCandidate();
2578
0
  }
2579
2580
  /// Build a return statement.
2581
  ReturnStmt(SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate);
2582
2583
  /// Build an empty return statement.
2584
  explicit ReturnStmt(EmptyShell Empty, bool HasNRVOCandidate);
2585
2586
public:
2587
  /// Create a return statement.
2588
  static ReturnStmt *Create(const ASTContext &Ctx, SourceLocation RL, Expr *E,
2589
                            const VarDecl *NRVOCandidate);
2590
2591
  /// Create an empty return statement, optionally with
2592
  /// storage for an NRVO candidate.
2593
  static ReturnStmt *CreateEmpty(const ASTContext &Ctx, bool HasNRVOCandidate);
2594
2595
631k
  Expr *getRetValue() { return reinterpret_cast<Expr *>(RetExpr); }
2596
434k
  const Expr *getRetValue() const { return reinterpret_cast<Expr *>(RetExpr); }
2597
3.43k
  void setRetValue(Expr *E) { RetExpr = reinterpret_cast<Stmt *>(E); }
2598
2599
  /// Retrieve the variable that might be used for the named return
2600
  /// value optimization.
2601
  ///
2602
  /// The optimization itself can only be performed if the variable is
2603
  /// also marked as an NRVO object.
2604
5.83M
  const VarDecl *getNRVOCandidate() const {
2605
5.83M
    return hasNRVOCandidate() ? 
*getTrailingObjects<const VarDecl *>()106k
2606
5.83M
                              : 
nullptr5.72M
;
2607
5.83M
  }
2608
2609
  /// Set the variable that might be used for the named return value
2610
  /// optimization. The return statement must have storage for it,
2611
  /// which is the case if and only if hasNRVOCandidate() is true.
2612
46.4k
  void setNRVOCandidate(const VarDecl *Var) {
2613
46.4k
    assert(hasNRVOCandidate() &&
2614
46.4k
           "This return statement has no storage for an NRVO candidate!");
2615
46.4k
    *getTrailingObjects<const VarDecl *>() = Var;
2616
46.4k
  }
2617
2618
608k
  SourceLocation getReturnLoc() const { return ReturnStmtBits.RetLoc; }
2619
2.90M
  void setReturnLoc(SourceLocation L) { ReturnStmtBits.RetLoc = L; }
2620
2621
326k
  SourceLocation getBeginLoc() const { return getReturnLoc(); }
2622
54.5k
  SourceLocation getEndLoc() const LLVM_READONLY {
2623
54.5k
    return RetExpr ? 
RetExpr->getEndLoc()51.1k
:
getReturnLoc()3.41k
;
2624
54.5k
  }
2625
2626
2.20M
  static bool classof(const Stmt *T) {
2627
2.20M
    return T->getStmtClass() == ReturnStmtClass;
2628
2.20M
  }
2629
2630
  // Iterators
2631
674k
  child_range children() {
2632
674k
    if (RetExpr)
2633
633k
      return child_range(&RetExpr, &RetExpr + 1);
2634
40.8k
    return child_range(child_iterator(), child_iterator());
2635
40.8k
  }
2636
2637
0
  const_child_range children() const {
2638
0
    if (RetExpr)
2639
0
      return const_child_range(&RetExpr, &RetExpr + 1);
2640
0
    return const_child_range(const_child_iterator(), const_child_iterator());
2641
0
  }
2642
};
2643
2644
/// AsmStmt is the base class for GCCAsmStmt and MSAsmStmt.
2645
class AsmStmt : public Stmt {
2646
protected:
2647
  friend class ASTStmtReader;
2648
2649
  SourceLocation AsmLoc;
2650
2651
  /// True if the assembly statement does not have any input or output
2652
  /// operands.
2653
  bool IsSimple;
2654
2655
  /// If true, treat this inline assembly as having side effects.
2656
  /// This assembly statement should not be optimized, deleted or moved.
2657
  bool IsVolatile;
2658
2659
  unsigned NumOutputs;
2660
  unsigned NumInputs;
2661
  unsigned NumClobbers;
2662
2663
  Stmt **Exprs = nullptr;
2664
2665
  AsmStmt(StmtClass SC, SourceLocation asmloc, bool issimple, bool isvolatile,
2666
          unsigned numoutputs, unsigned numinputs, unsigned numclobbers)
2667
      : Stmt (SC), AsmLoc(asmloc), IsSimple(issimple), IsVolatile(isvolatile),
2668
        NumOutputs(numoutputs), NumInputs(numinputs),
2669
23.5k
        NumClobbers(numclobbers) {}
2670
2671
public:
2672
  /// Build an empty inline-assembly statement.
2673
3
  explicit AsmStmt(StmtClass SC, EmptyShell Empty) : Stmt(SC, Empty) {}
2674
2675
4.29k
  SourceLocation getAsmLoc() const { return AsmLoc; }
2676
3
  void setAsmLoc(SourceLocation L) { AsmLoc = L; }
2677
2678
35.2k
  bool isSimple() const { return IsSimple; }
2679
3
  void setSimple(bool V) { IsSimple = V; }
2680
2681
12.2k
  bool isVolatile() const { return IsVolatile; }
2682
3
  void setVolatile(bool V) { IsVolatile = V; }
2683
2684
  SourceLocation getBeginLoc() const LLVM_READONLY { return {}; }
2685
  SourceLocation getEndLoc() const LLVM_READONLY { return {}; }
2686
2687
  //===--- Asm String Analysis ---===//
2688
2689
  /// Assemble final IR asm string.
2690
  std::string generateAsmString(const ASTContext &C) const;
2691
2692
  //===--- Output operands ---===//
2693
2694
96.9k
  unsigned getNumOutputs() const { return NumOutputs; }
2695
2696
  /// getOutputConstraint - Return the constraint string for the specified
2697
  /// output operand.  All output constraints are known to be non-empty (either
2698
  /// '=' or '+').
2699
  StringRef getOutputConstraint(unsigned i) const;
2700
2701
  /// isOutputPlusConstraint - Return true if the specified output constraint
2702
  /// is a "+" constraint (which is both an input and an output) or false if it
2703
  /// is an "=" constraint (just an output).
2704
16.3k
  bool isOutputPlusConstraint(unsigned i) const {
2705
16.3k
    return getOutputConstraint(i)[0] == '+';
2706
16.3k
  }
2707
2708
  const Expr *getOutputExpr(unsigned i) const;
2709
2710
  /// getNumPlusOperands - Return the number of output operands that have a "+"
2711
  /// constraint.
2712
  unsigned getNumPlusOperands() const;
2713
2714
  //===--- Input operands ---===//
2715
2716
79.7k
  unsigned getNumInputs() const { return NumInputs; }
2717
2718
  /// getInputConstraint - Return the specified input constraint.  Unlike output
2719
  /// constraints, these can be empty.
2720
  StringRef getInputConstraint(unsigned i) const;
2721
2722
  const Expr *getInputExpr(unsigned i) const;
2723
2724
  //===--- Other ---===//
2725
2726
12.3k
  unsigned getNumClobbers() const { return NumClobbers; }
2727
  StringRef getClobber(unsigned i) const;
2728
2729
1.83k
  static bool classof(const Stmt *T) {
2730
1.83k
    return T->getStmtClass() == GCCAsmStmtClass ||
2731
1.83k
      
T->getStmtClass() == MSAsmStmtClass1.82k
;
2732
1.83k
  }
2733
2734
  // Input expr iterators.
2735
2736
  using inputs_iterator = ExprIterator;
2737
  using const_inputs_iterator = ConstExprIterator;
2738
  using inputs_range = llvm::iterator_range<inputs_iterator>;
2739
  using inputs_const_range = llvm::iterator_range<const_inputs_iterator>;
2740
2741
3
  inputs_iterator begin_inputs() {
2742
3
    return &Exprs[0] + NumOutputs;
2743
3
  }
2744
2745
3
  inputs_iterator end_inputs() {
2746
3
    return &Exprs[0] + NumOutputs + NumInputs;
2747
3
  }
2748
2749
3
  inputs_range inputs() { return inputs_range(begin_inputs(), end_inputs()); }
2750
2751
0
  const_inputs_iterator begin_inputs() const {
2752
0
    return &Exprs[0] + NumOutputs;
2753
0
  }
2754
2755
0
  const_inputs_iterator end_inputs() const {
2756
0
    return &Exprs[0] + NumOutputs + NumInputs;
2757
0
  }
2758
2759
0
  inputs_const_range inputs() const {
2760
0
    return inputs_const_range(begin_inputs(), end_inputs());
2761
0
  }
2762
2763
  // Output expr iterators.
2764
2765
  using outputs_iterator = ExprIterator;
2766
  using const_outputs_iterator = ConstExprIterator;
2767
  using outputs_range = llvm::iterator_range<outputs_iterator>;
2768
  using outputs_const_range = llvm::iterator_range<const_outputs_iterator>;
2769
2770
3
  outputs_iterator begin_outputs() {
2771
3
    return &Exprs[0];
2772
3
  }
2773
2774
3
  outputs_iterator end_outputs() {
2775
3
    return &Exprs[0] + NumOutputs;
2776
3
  }
2777
2778
3
  outputs_range outputs() {
2779
3
    return outputs_range(begin_outputs(), end_outputs());
2780
3
  }
2781
2782
2
  const_outputs_iterator begin_outputs() const {
2783
2
    return &Exprs[0];
2784
2
  }
2785
2786
2
  const_outputs_iterator end_outputs() const {
2787
2
    return &Exprs[0] + NumOutputs;
2788
2
  }
2789
2790
2
  outputs_const_range outputs() const {
2791
2
    return outputs_const_range(begin_outputs(), end_outputs());
2792
2
  }
2793
2794
43.1k
  child_range children() {
2795
43.1k
    return child_range(&Exprs[0], &Exprs[0] + NumOutputs + NumInputs);
2796
43.1k
  }
2797
2798
0
  const_child_range children() const {
2799
0
    return const_child_range(&Exprs[0], &Exprs[0] + NumOutputs + NumInputs);
2800
0
  }
2801
};
2802
2803
/// This represents a GCC inline-assembly statement extension.
2804
class GCCAsmStmt : public AsmStmt {
2805
  friend class ASTStmtReader;
2806
2807
  SourceLocation RParenLoc;
2808
  StringLiteral *AsmStr;
2809
2810
  // FIXME: If we wanted to, we could allocate all of these in one big array.
2811
  StringLiteral **Constraints = nullptr;
2812
  StringLiteral **Clobbers = nullptr;
2813
  IdentifierInfo **Names = nullptr;
2814
2815
public:
2816
  GCCAsmStmt(const ASTContext &C, SourceLocation asmloc, bool issimple,
2817
             bool isvolatile, unsigned numoutputs, unsigned numinputs,
2818
             IdentifierInfo **names, StringLiteral **constraints, Expr **exprs,
2819
             StringLiteral *asmstr, unsigned numclobbers,
2820
             StringLiteral **clobbers, SourceLocation rparenloc);
2821
2822
  /// Build an empty inline-assembly statement.
2823
3
  explicit GCCAsmStmt(EmptyShell Empty) : AsmStmt(GCCAsmStmtClass, Empty) {}
2824
2825
4.14k
  SourceLocation getRParenLoc() const { return RParenLoc; }
2826
3
  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2827
2828
  //===--- Asm String Analysis ---===//
2829
2830
71.7k
  const StringLiteral *getAsmString() const { return AsmStr; }
2831
4.17k
  StringLiteral *getAsmString() { return AsmStr; }
2832
3
  void setAsmString(StringLiteral *E) { AsmStr = E; }
2833
2834
  /// AsmStringPiece - this is part of a decomposed asm string specification
2835
  /// (for use with the AnalyzeAsmString function below).  An asm string is
2836
  /// considered to be a concatenation of these parts.
2837
  class AsmStringPiece {
2838
  public:
2839
    enum Kind {
2840
      String,  // String in .ll asm string form, "$" -> "$$" and "%%" -> "%".
2841
      Operand  // Operand reference, with optional modifier %c4.
2842
    };
2843
2844
  private:
2845
    Kind MyKind;
2846
    std::string Str;
2847
    unsigned OperandNo;
2848
2849
    // Source range for operand references.
2850
    CharSourceRange Range;
2851
2852
  public:
2853
25.4k
    AsmStringPiece(const std::string &S) : MyKind(String), Str(S) {}
2854
    AsmStringPiece(unsigned OpNo, const std::string &S, SourceLocation Begin,
2855
                   SourceLocation End)
2856
        : MyKind(Operand), Str(S), OperandNo(OpNo),
2857
16.4k
          Range(CharSourceRange::getCharRange(Begin, End)) {}
2858
2859
3.83k
    bool isString() const { return MyKind == String; }
2860
38.0k
    bool isOperand() const { return MyKind == Operand; }
2861
2862
2.23k
    const std::string &getString() const { return Str; }
2863
2864
16.4k
    unsigned getOperandNo() const {
2865
16.4k
      assert(isOperand());
2866
16.4k
      return OperandNo;
2867
16.4k
    }
2868
2869
22
    CharSourceRange getRange() const {
2870
22
      assert(isOperand() && "Range is currently used only for Operands.");
2871
22
      return Range;
2872
22
    }
2873
2874
    /// getModifier - Get the modifier for this operand, if present.  This
2875
    /// returns '\0' if there was no modifier.
2876
    char getModifier() const;
2877
  };
2878
2879
  /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing
2880
  /// it into pieces.  If the asm string is erroneous, emit errors and return
2881
  /// true, otherwise return false.  This handles canonicalization and
2882
  /// translation of strings from GCC syntax to LLVM IR syntax, and handles
2883
  //// flattening of named references like %[foo] to Operand AsmStringPiece's.
2884
  unsigned AnalyzeAsmString(SmallVectorImpl<AsmStringPiece> &Pieces,
2885
                            const ASTContext &C, unsigned &DiagOffs) const;
2886
2887
  /// Assemble final IR asm string.
2888
  std::string generateAsmString(const ASTContext &C) const;
2889
2890
  //===--- Output operands ---===//
2891
2892
5.45k
  IdentifierInfo *getOutputIdentifier(unsigned i) const { return Names[i]; }
2893
2894
1.27k
  StringRef getOutputName(unsigned i) const {
2895
1.27k
    if (IdentifierInfo *II = getOutputIdentifier(i))
2896
122
      return II->getName();
2897
1.15k
2898
1.15k
    return {};
2899
1.15k
  }
2900
2901
  StringRef getOutputConstraint(unsigned i) const;
2902
2903
18.5k
  const StringLiteral *getOutputConstraintLiteral(unsigned i) const {
2904
18.5k
    return Constraints[i];
2905
18.5k
  }
2906
4.18k
  StringLiteral *getOutputConstraintLiteral(unsigned i) {
2907
4.18k
    return Constraints[i];
2908
4.18k
  }
2909
2910
  Expr *getOutputExpr(unsigned i);
2911
2912
1.19k
  const Expr *getOutputExpr(unsigned i) const {
2913
1.19k
    return const_cast<GCCAsmStmt*>(this)->getOutputExpr(i);
2914
1.19k
  }
2915
2916
  //===--- Input operands ---===//
2917
2918
5.40k
  IdentifierInfo *getInputIdentifier(unsigned i) const {
2919
5.40k
    return Names[i + NumOutputs];
2920
5.40k
  }
2921
2922
1.20k
  StringRef getInputName(unsigned i) const {
2923
1.20k
    if (IdentifierInfo *II = getInputIdentifier(i))
2924
77
      return II->getName();
2925
1.13k
2926
1.13k
    return {};
2927
1.13k
  }
2928
2929
  StringRef getInputConstraint(unsigned i) const;
2930
2931
2.21k
  const StringLiteral *getInputConstraintLiteral(unsigned i) const {
2932
2.21k
    return Constraints[i + NumOutputs];
2933
2.21k
  }
2934
4.19k
  StringLiteral *getInputConstraintLiteral(unsigned i) {
2935
4.19k
    return Constraints[i + NumOutputs];
2936
4.19k
  }
2937
2938
  Expr *getInputExpr(unsigned i);
2939
  void setInputExpr(unsigned i, Expr *E);
2940
2941
1.09k
  const Expr *getInputExpr(unsigned i) const {
2942
1.09k
    return const_cast<GCCAsmStmt*>(this)->getInputExpr(i);
2943
1.09k
  }
2944
2945
private:
2946
  void setOutputsAndInputsAndClobbers(const ASTContext &C,
2947
                                      IdentifierInfo **Names,
2948
                                      StringLiteral **Constraints,
2949
                                      Stmt **Exprs,
2950
                                      unsigned NumOutputs,
2951
                                      unsigned NumInputs,
2952
                                      StringLiteral **Clobbers,
2953
                                      unsigned NumClobbers);
2954
2955
public:
2956
  //===--- Other ---===//
2957
2958
  /// getNamedOperand - Given a symbolic operand reference like %[foo],
2959
  /// translate this into a numeric value needed to reference the same operand.
2960
  /// This returns -1 if the operand name is invalid.
2961
  int getNamedOperand(StringRef SymbolicName) const;
2962
2963
  StringRef getClobber(unsigned i) const;
2964
2965
36.4k
  StringLiteral *getClobberStringLiteral(unsigned i) { return Clobbers[i]; }
2966
7.15k
  const StringLiteral *getClobberStringLiteral(unsigned i) const {
2967
7.15k
    return Clobbers[i];
2968
7.15k
  }
2969
2970
6.75k
  SourceLocation getBeginLoc() const LLVM_READONLY { return AsmLoc; }
2971
543
  SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
2972
2973
48.8k
  static bool classof(const Stmt *T) {
2974
48.8k
    return T->getStmtClass() == GCCAsmStmtClass;
2975
48.8k
  }
2976
};
2977
2978
/// This represents a Microsoft inline-assembly statement extension.
2979
class MSAsmStmt : public AsmStmt {
2980
  friend class ASTStmtReader;
2981
2982
  SourceLocation LBraceLoc, EndLoc;
2983
  StringRef AsmStr;
2984
2985
  unsigned NumAsmToks = 0;
2986
2987
  Token *AsmToks = nullptr;
2988
  StringRef *Constraints = nullptr;
2989
  StringRef *Clobbers = nullptr;
2990
2991
public:
2992
  MSAsmStmt(const ASTContext &C, SourceLocation asmloc,
2993
            SourceLocation lbraceloc, bool issimple, bool isvolatile,
2994
            ArrayRef<Token> asmtoks, unsigned numoutputs, unsigned numinputs,
2995
            ArrayRef<StringRef> constraints,
2996
            ArrayRef<Expr*> exprs, StringRef asmstr,
2997
            ArrayRef<StringRef> clobbers, SourceLocation endloc);
2998
2999
  /// Build an empty MS-style inline-assembly statement.
3000
0
  explicit MSAsmStmt(EmptyShell Empty) : AsmStmt(MSAsmStmtClass, Empty) {}
3001
3002
1
  SourceLocation getLBraceLoc() const { return LBraceLoc; }
3003
0
  void setLBraceLoc(SourceLocation L) { LBraceLoc = L; }
3004
1
  SourceLocation getEndLoc() const { return EndLoc; }
3005
0
  void setEndLoc(SourceLocation L) { EndLoc = L; }
3006
3007
0
  bool hasBraces() const { return LBraceLoc.isValid(); }
3008
3009
1
  unsigned getNumAsmToks() { return NumAsmToks; }
3010
1
  Token *getAsmToks() { return AsmToks; }
3011
3012
  //===--- Asm String Analysis ---===//
3013
1
  StringRef getAsmString() const { return AsmStr; }
3014
3015
  /// Assemble final IR asm string.
3016
  std::string generateAsmString(const ASTContext &C) const;
3017
3018
  //===--- Output operands ---===//
3019
3020
40
  StringRef getOutputConstraint(unsigned i) const {
3021
40
    assert(i < NumOutputs);
3022
40
    return Constraints[i];
3023
40
  }
3024
3025
  Expr *getOutputExpr(unsigned i);
3026
3027
20
  const Expr *getOutputExpr(unsigned i) const {
3028
20
    return const_cast<MSAsmStmt*>(this)->getOutputExpr(i);
3029
20
  }
3030
3031
  //===--- Input operands ---===//
3032
3033
206
  StringRef getInputConstraint(unsigned i) const {
3034
206
    assert(i < NumInputs);
3035
206
    return Constraints[i + NumOutputs];
3036
206
  }
3037
3038
  Expr *getInputExpr(unsigned i);
3039
  void setInputExpr(unsigned i, Expr *E);
3040
3041
103
  const Expr *getInputExpr(unsigned i) const {
3042
103
    return const_cast<MSAsmStmt*>(this)->getInputExpr(i);
3043
103
  }
3044
3045
  //===--- Other ---===//
3046
3047
1
  ArrayRef<StringRef> getAllConstraints() const {
3048
1
    return llvm::makeArrayRef(Constraints, NumInputs + NumOutputs);
3049
1
  }
3050
3051
187
  ArrayRef<StringRef> getClobbers() const {
3052
187
    return llvm::makeArrayRef(Clobbers, NumClobbers);
3053
187
  }
3054
3055
1
  ArrayRef<Expr*> getAllExprs() const {
3056
1
    return llvm::makeArrayRef(reinterpret_cast<Expr**>(Exprs),
3057
1
                              NumInputs + NumOutputs);
3058
1
  }
3059
3060
186
  StringRef getClobber(unsigned i) const { return getClobbers()[i]; }
3061
3062
private:
3063
  void initialize(const ASTContext &C, StringRef AsmString,
3064
                  ArrayRef<Token> AsmToks, ArrayRef<StringRef> Constraints,
3065
                  ArrayRef<Expr*> Exprs, ArrayRef<StringRef> Clobbers);
3066
3067
public:
3068
0
  SourceLocation getBeginLoc() const LLVM_READONLY { return AsmLoc; }
3069
3070
16.9k
  static bool classof(const Stmt *T) {
3071
16.9k
    return T->getStmtClass() == MSAsmStmtClass;
3072
16.9k
  }
3073
3074
35
  child_range children() {
3075
35
    return child_range(&Exprs[0], &Exprs[NumInputs + NumOutputs]);
3076
35
  }
3077
3078
0
  const_child_range children() const {
3079
0
    return const_child_range(&Exprs[0], &Exprs[NumInputs + NumOutputs]);
3080
0
  }
3081
};
3082
3083
class SEHExceptStmt : public Stmt {
3084
  friend class ASTReader;
3085
  friend class ASTStmtReader;
3086
3087
  SourceLocation  Loc;
3088
  Stmt *Children[2];
3089
3090
  enum { FILTER_EXPR, BLOCK };
3091
3092
  SEHExceptStmt(SourceLocation Loc, Expr *FilterExpr, Stmt *Block);
3093
1
  explicit SEHExceptStmt(EmptyShell E) : Stmt(SEHExceptStmtClass, E) {}
3094
3095
public:
3096
  static SEHExceptStmt* Create(const ASTContext &C,
3097
                               SourceLocation ExceptLoc,
3098
                               Expr *FilterExpr,
3099
                               Stmt *Block);
3100
3101
24
  SourceLocation getBeginLoc() const LLVM_READONLY { return getExceptLoc(); }
3102
3103
28
  SourceLocation getExceptLoc() const { return Loc; }
3104
48
  SourceLocation getEndLoc() const { return getBlock()->getEndLoc(); }
3105
3106
81
  Expr *getFilterExpr() const {
3107
81
    return reinterpret_cast<Expr*>(Children[FILTER_EXPR]);
3108
81
  }
3109
3110
168
  CompoundStmt *getBlock() const {
3111
168
    return cast<CompoundStmt>(Children[BLOCK]);
3112
168
  }
3113
3114
5
  child_range children() {
3115
5
    return child_range(Children, Children+2);
3116
5
  }
3117
3118
0
  const_child_range children() const {
3119
0
    return const_child_range(Children, Children + 2);
3120
0
  }
3121
3122
221
  static bool classof(const Stmt *T) {
3123
221
    return T->getStmtClass() == SEHExceptStmtClass;
3124
221
  }
3125
};
3126
3127
class SEHFinallyStmt : public Stmt {
3128
  friend class ASTReader;
3129
  friend class ASTStmtReader;
3130
3131
  SourceLocation  Loc;
3132
  Stmt *Block;
3133
3134
  SEHFinallyStmt(SourceLocation Loc, Stmt *Block);
3135
0
  explicit SEHFinallyStmt(EmptyShell E) : Stmt(SEHFinallyStmtClass, E) {}
3136
3137
public:
3138
  static SEHFinallyStmt* Create(const ASTContext &C,
3139
                                SourceLocation FinallyLoc,
3140
                                Stmt *Block);
3141
3142
53
  SourceLocation getBeginLoc() const LLVM_READONLY { return getFinallyLoc(); }
3143
3144
54
  SourceLocation getFinallyLoc() const { return Loc; }
3145
106
  SourceLocation getEndLoc() const { return Block->getEndLoc(); }
3146
3147
129
  CompoundStmt *getBlock() const { return cast<CompoundStmt>(Block); }
3148
3149
11
  child_range children() {
3150
11
    return child_range(&Block,&Block+1);
3151
11
  }
3152
3153
0
  const_child_range children() const {
3154
0
    return const_child_range(&Block, &Block + 1);
3155
0
  }
3156
3157
371
  static bool classof(const Stmt *T) {
3158
371
    return T->getStmtClass() == SEHFinallyStmtClass;
3159
371
  }
3160
};
3161
3162
class SEHTryStmt : public Stmt {
3163
  friend class ASTReader;
3164
  friend class ASTStmtReader;
3165
3166
  bool IsCXXTry;
3167
  SourceLocation  TryLoc;
3168
  Stmt *Children[2];
3169
3170
  enum { TRY = 0, HANDLER = 1 };
3171
3172
  SEHTryStmt(bool isCXXTry, // true if 'try' otherwise '__try'
3173
             SourceLocation TryLoc,
3174
             Stmt *TryBlock,
3175
             Stmt *Handler);
3176
3177
1
  explicit SEHTryStmt(EmptyShell E) : Stmt(SEHTryStmtClass, E) {}
3178
3179
public:
3180
  static SEHTryStmt* Create(const ASTContext &C, bool isCXXTry,
3181
                            SourceLocation TryLoc, Stmt *TryBlock,
3182
                            Stmt *Handler);
3183
3184
77
  SourceLocation getBeginLoc() const LLVM_READONLY { return getTryLoc(); }
3185
3186
82
  SourceLocation getTryLoc() const { return TryLoc; }
3187
77
  SourceLocation getEndLoc() const { return Children[HANDLER]->getEndLoc(); }
3188
3189
5
  bool getIsCXXTry() const { return IsCXXTry; }
3190
3191
256
  CompoundStmt* getTryBlock() const {
3192
256
    return cast<CompoundStmt>(Children[TRY]);
3193
256
  }
3194
3195
595
  Stmt *getHandler() const { return Children[HANDLER]; }
3196
3197
  /// Returns 0 if not defined
3198
  SEHExceptStmt  *getExceptHandler() const;
3199
  SEHFinallyStmt *getFinallyHandler() const;
3200
3201
16
  child_range children() {
3202
16
    return child_range(Children, Children+2);
3203
16
  }
3204
3205
0
  const_child_range children() const {
3206
0
    return const_child_range(Children, Children + 2);
3207
0
  }
3208
3209
0
  static bool classof(const Stmt *T) {
3210
0
    return T->getStmtClass() == SEHTryStmtClass;
3211
0
  }
3212
};
3213
3214
/// Represents a __leave statement.
3215
class SEHLeaveStmt : public Stmt {
3216
  SourceLocation LeaveLoc;
3217
3218
public:
3219
  explicit SEHLeaveStmt(SourceLocation LL)
3220
24
      : Stmt(SEHLeaveStmtClass), LeaveLoc(LL) {}
3221
3222
  /// Build an empty __leave statement.
3223
0
  explicit SEHLeaveStmt(EmptyShell Empty) : Stmt(SEHLeaveStmtClass, Empty) {}
3224
3225
0
  SourceLocation getLeaveLoc() const { return LeaveLoc; }
3226
0
  void setLeaveLoc(SourceLocation L) { LeaveLoc = L; }
3227
3228
0
  SourceLocation getBeginLoc() const LLVM_READONLY { return LeaveLoc; }
3229
0
  SourceLocation getEndLoc() const LLVM_READONLY { return LeaveLoc; }
3230
3231
  static bool classof(const Stmt *T) {
3232
    return T->getStmtClass() == SEHLeaveStmtClass;
3233
  }
3234
3235
  // Iterators
3236
6
  child_range children() {
3237
6
    return child_range(child_iterator(), child_iterator());
3238
6
  }
3239
3240
0
  const_child_range children() const {
3241
0
    return const_child_range(const_child_iterator(), const_child_iterator());
3242
0
  }
3243
};
3244
3245
/// This captures a statement into a function. For example, the following
3246
/// pragma annotated compound statement can be represented as a CapturedStmt,
3247
/// and this compound statement is the body of an anonymous outlined function.
3248
/// @code
3249
/// #pragma omp parallel
3250
/// {
3251
///   compute();
3252
/// }
3253
/// @endcode
3254
class CapturedStmt : public Stmt {
3255
public:
3256
  /// The different capture forms: by 'this', by reference, capture for
3257
  /// variable-length array type etc.
3258
  enum VariableCaptureKind {
3259
    VCK_This,
3260
    VCK_ByRef,
3261
    VCK_ByCopy,
3262
    VCK_VLAType,
3263
  };
3264
3265
  /// Describes the capture of either a variable, or 'this', or
3266
  /// variable-length array type.
3267
  class Capture {
3268
    llvm::PointerIntPair<VarDecl *, 2, VariableCaptureKind> VarAndKind;
3269
    SourceLocation Loc;
3270
3271
  public:
3272
    friend class ASTStmtReader;
3273
3274
    /// Create a new capture.
3275
    ///
3276
    /// \param Loc The source location associated with this capture.
3277
    ///
3278
    /// \param Kind The kind of capture (this, ByRef, ...).
3279
    ///
3280
    /// \param Var The variable being captured, or null if capturing this.
3281
    Capture(SourceLocation Loc, VariableCaptureKind Kind,
3282
            VarDecl *Var = nullptr);
3283
3284
    /// Determine the kind of capture.
3285
    VariableCaptureKind getCaptureKind() const;
3286
3287
    /// Retrieve the source location at which the variable or 'this' was
3288
    /// first used.
3289
137k
    SourceLocation getLocation() const { return Loc; }
3290
3291
    /// Determine whether this capture handles the C++ 'this' pointer.
3292
84.1k
    bool capturesThis() const { return getCaptureKind() == VCK_This; }
3293
3294
    /// Determine whether this capture handles a variable (by reference).
3295
552k
    bool capturesVariable() const { return getCaptureKind() == VCK_ByRef; }
3296
3297
    /// Determine whether this capture handles a variable by copy.
3298
267k
    bool capturesVariableByCopy() const {
3299
267k
      return getCaptureKind() == VCK_ByCopy;
3300
267k
    }
3301
3302
    /// Determine whether this capture handles a variable-length array
3303
    /// type.
3304
45.3k
    bool capturesVariableArrayType() const {
3305
45.3k
      return getCaptureKind() == VCK_VLAType;
3306
45.3k
    }
3307
3308
    /// Retrieve the declaration of the variable being captured.
3309
    ///
3310
    /// This operation is only valid if this capture captures a variable.
3311
    VarDecl *getCapturedVar() const;
3312
  };
3313
3314
private:
3315
  /// The number of variable captured, including 'this'.
3316
  unsigned NumCaptures;
3317
3318
  /// The pointer part is the implicit the outlined function and the
3319
  /// int part is the captured region kind, 'CR_Default' etc.
3320
  llvm::PointerIntPair<CapturedDecl *, 2, CapturedRegionKind> CapDeclAndKind;
3321
3322
  /// The record for captured variables, a RecordDecl or CXXRecordDecl.
3323
  RecordDecl *TheRecordDecl = nullptr;
3324
3325
  /// Construct a captured statement.
3326
  CapturedStmt(Stmt *S, CapturedRegionKind Kind, ArrayRef<Capture> Captures,
3327
               ArrayRef<Expr *> CaptureInits, CapturedDecl *CD, RecordDecl *RD);
3328
3329
  /// Construct an empty captured statement.
3330
  CapturedStmt(EmptyShell Empty, unsigned NumCaptures);
3331
3332
1.43M
  Stmt **getStoredStmts() { return reinterpret_cast<Stmt **>(this + 1); }
3333
3334
457k
  Stmt *const *getStoredStmts() const {
3335
457k
    return reinterpret_cast<Stmt *const *>(this + 1);
3336
457k
  }
3337
3338
  Capture *getStoredCaptures() const;
3339
3340
19.1k
  void setCapturedStmt(Stmt *S) { getStoredStmts()[NumCaptures] = S; }
3341
3342
public:
3343
  friend class ASTStmtReader;
3344
3345
  static CapturedStmt *Create(const ASTContext &Context, Stmt *S,
3346
                              CapturedRegionKind Kind,
3347
                              ArrayRef<Capture> Captures,
3348
                              ArrayRef<Expr *> CaptureInits,
3349
                              CapturedDecl *CD, RecordDecl *RD);
3350
3351
  static CapturedStmt *CreateDeserialized(const ASTContext &Context,
3352
                                          unsigned NumCaptures);
3353
3354
  /// Retrieve the statement being captured.
3355
994k
  Stmt *getCapturedStmt() { return getStoredStmts()[NumCaptures]; }
3356
432k
  const Stmt *getCapturedStmt() const { return getStoredStmts()[NumCaptures]; }
3357
3358
  /// Retrieve the outlined function declaration.
3359
  CapturedDecl *getCapturedDecl();
3360
  const CapturedDecl *getCapturedDecl() const;
3361
3362
  /// Set the outlined function declaration.
3363
  void setCapturedDecl(CapturedDecl *D);
3364
3365
  /// Retrieve the captured region kind.
3366
  CapturedRegionKind getCapturedRegionKind() const;
3367
3368
  /// Set the captured region kind.
3369
  void setCapturedRegionKind(CapturedRegionKind Kind);
3370
3371
  /// Retrieve the record declaration for captured variables.
3372
65.7k
  const RecordDecl *getCapturedRecordDecl() const { return TheRecordDecl; }
3373
3374
  /// Set the record declaration for captured variables.
3375
19.1k
  void setCapturedRecordDecl(RecordDecl *D) {
3376
19.1k
    assert(D && "null RecordDecl");
3377
19.1k
    TheRecordDecl = D;
3378
19.1k
  }
3379
3380
  /// True if this variable has been captured.
3381
  bool capturesVariable(const VarDecl *Var) const;
3382
3383
  /// An iterator that walks over the captures.
3384
  using capture_iterator = Capture *;
3385
  using const_capture_iterator = const Capture *;
3386
  using capture_range = llvm::iterator_range<capture_iterator>;
3387
  using capture_const_range = llvm::iterator_range<const_capture_iterator>;
3388
3389
72.7k
  capture_range captures() {
3390
72.7k
    return capture_range(capture_begin(), capture_end());
3391
72.7k
  }
3392
358k
  capture_const_range captures() const {
3393
358k
    return capture_const_range(capture_begin(), capture_end());
3394
358k
  }
3395
3396
  /// Retrieve an iterator pointing to the first capture.
3397
92.6k
  capture_iterator capture_begin() { return getStoredCaptures(); }
3398
376k
  const_capture_iterator capture_begin() const { return getStoredCaptures(); }
3399
3400
  /// Retrieve an iterator pointing past the end of the sequence of
3401
  /// captures.
3402
469k
  capture_iterator capture_end() const {
3403
469k
    return getStoredCaptures() + NumCaptures;
3404
469k
  }
3405
3406
  /// Retrieve the number of captures, including 'this'.
3407
62
  unsigned capture_size() const { return NumCaptures; }
3408
3409
  /// Iterator that walks over the capture initialization arguments.
3410
  using capture_init_iterator = Expr **;
3411
  using capture_init_range = llvm::iterator_range<capture_init_iterator>;
3412
3413
  /// Const iterator that walks over the capture initialization
3414
  /// arguments.
3415
  using const_capture_init_iterator = Expr *const *;
3416
  using const_capture_init_range =
3417
      llvm::iterator_range<const_capture_init_iterator>;
3418
3419
19.8k
  capture_init_range capture_inits() {
3420
19.8k
    return capture_init_range(capture_init_begin(), capture_init_end());
3421
19.8k
  }
3422
3423
0
  const_capture_init_range capture_inits() const {
3424
0
    return const_capture_init_range(capture_init_begin(), capture_init_end());
3425
0
  }
3426
3427
  /// Retrieve the first initialization argument.
3428
78.0k
  capture_init_iterator capture_init_begin() {
3429
78.0k
    return reinterpret_cast<Expr **>(getStoredStmts());
3430
78.0k
  }
3431
3432
25.2k
  const_capture_init_iterator capture_init_begin() const {
3433
25.2k
    return reinterpret_cast<Expr *const *>(getStoredStmts());
3434
25.2k
  }
3435
3436
  /// Retrieve the iterator pointing one past the last initialization
3437
  /// argument.
3438
39.0k
  capture_init_iterator capture_init_end() {
3439
39.0k
    return capture_init_begin() + NumCaptures;
3440
39.0k
  }
3441
3442
12.6k
  const_capture_init_iterator capture_init_end() const {
3443
12.6k
    return capture_init_begin() + NumCaptures;
3444
12.6k
  }
3445
3446
200k
  SourceLocation getBeginLoc() const LLVM_READONLY {
3447
200k
    return getCapturedStmt()->getBeginLoc();
3448
200k
  }
3449
3450
5
  SourceLocation getEndLoc() const LLVM_READONLY {
3451
5
    return getCapturedStmt()->getEndLoc();
3452
5
  }
3453
3454
6.45k
  SourceRange getSourceRange() const LLVM_READONLY {
3455
6.45k
    return getCapturedStmt()->getSourceRange();
3456
6.45k
  }
3457
3458
130k
  static bool classof(const Stmt *T) {
3459
130k
    return T->getStmtClass() == CapturedStmtClass;
3460
130k
  }
3461
3462
  child_range children();
3463
3464
  const_child_range children() const;
3465
};
3466
3467
} // namespace clang
3468
3469
#endif // LLVM_CLANG_AST_STMT_H