Coverage Report

Created: 2018-12-11 17:59

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