File indexing completed on 2026-05-10 08:36:42
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef LLVM_CLANG_AST_STMT_H
0014 #define LLVM_CLANG_AST_STMT_H
0015
0016 #include "clang/AST/APValue.h"
0017 #include "clang/AST/DeclGroup.h"
0018 #include "clang/AST/DependenceFlags.h"
0019 #include "clang/AST/OperationKinds.h"
0020 #include "clang/AST/StmtIterator.h"
0021 #include "clang/Basic/CapturedStmt.h"
0022 #include "clang/Basic/IdentifierTable.h"
0023 #include "clang/Basic/LLVM.h"
0024 #include "clang/Basic/Lambda.h"
0025 #include "clang/Basic/LangOptions.h"
0026 #include "clang/Basic/OperatorKinds.h"
0027 #include "clang/Basic/SourceLocation.h"
0028 #include "clang/Basic/Specifiers.h"
0029 #include "clang/Basic/TypeTraits.h"
0030 #include "llvm/ADT/APFloat.h"
0031 #include "llvm/ADT/ArrayRef.h"
0032 #include "llvm/ADT/BitmaskEnum.h"
0033 #include "llvm/ADT/PointerIntPair.h"
0034 #include "llvm/ADT/StringRef.h"
0035 #include "llvm/ADT/iterator.h"
0036 #include "llvm/ADT/iterator_range.h"
0037 #include "llvm/Support/Casting.h"
0038 #include "llvm/Support/Compiler.h"
0039 #include "llvm/Support/ErrorHandling.h"
0040 #include <algorithm>
0041 #include <cassert>
0042 #include <cstddef>
0043 #include <iterator>
0044 #include <optional>
0045 #include <string>
0046
0047 namespace llvm {
0048
0049 class FoldingSetNodeID;
0050
0051 }
0052
0053 namespace clang {
0054
0055 class ASTContext;
0056 class Attr;
0057 class CapturedDecl;
0058 class Decl;
0059 class Expr;
0060 class AddrLabelExpr;
0061 class LabelDecl;
0062 class ODRHash;
0063 class PrinterHelper;
0064 struct PrintingPolicy;
0065 class RecordDecl;
0066 class SourceManager;
0067 class StringLiteral;
0068 class Token;
0069 class VarDecl;
0070 enum class CharacterLiteralKind;
0071 enum class ConstantResultStorageKind;
0072 enum class CXXConstructionKind;
0073 enum class CXXNewInitializationStyle;
0074 enum class PredefinedIdentKind;
0075 enum class SourceLocIdentKind;
0076 enum class StringLiteralKind;
0077
0078
0079
0080
0081
0082
0083
0084 class alignas(void *) Stmt {
0085 public:
0086 enum StmtClass {
0087 NoStmtClass = 0,
0088 #define STMT(CLASS, PARENT) CLASS##Class,
0089 #define STMT_RANGE(BASE, FIRST, LAST) \
0090 first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class,
0091 #define LAST_STMT_RANGE(BASE, FIRST, LAST) \
0092 first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class
0093 #define ABSTRACT_STMT(STMT)
0094 #include "clang/AST/StmtNodes.inc"
0095 };
0096
0097
0098 protected:
0099 friend class ASTStmtReader;
0100 friend class ASTStmtWriter;
0101
0102 void *operator new(size_t bytes) noexcept {
0103 llvm_unreachable("Stmts cannot be allocated with regular 'new'.");
0104 }
0105
0106 void operator delete(void *data) noexcept {
0107 llvm_unreachable("Stmts cannot be released with regular 'delete'.");
0108 }
0109
0110
0111
0112 #define NumStmtBits 9
0113
0114 class StmtBitfields {
0115 friend class ASTStmtReader;
0116 friend class ASTStmtWriter;
0117 friend class Stmt;
0118
0119
0120 LLVM_PREFERRED_TYPE(StmtClass)
0121 unsigned sClass : NumStmtBits;
0122 };
0123
0124 class NullStmtBitfields {
0125 friend class ASTStmtReader;
0126 friend class ASTStmtWriter;
0127 friend class NullStmt;
0128
0129 LLVM_PREFERRED_TYPE(StmtBitfields)
0130 unsigned : NumStmtBits;
0131
0132
0133
0134
0135
0136
0137 LLVM_PREFERRED_TYPE(bool)
0138 unsigned HasLeadingEmptyMacro : 1;
0139
0140
0141 SourceLocation SemiLoc;
0142 };
0143
0144 class CompoundStmtBitfields {
0145 friend class ASTStmtReader;
0146 friend class CompoundStmt;
0147
0148 LLVM_PREFERRED_TYPE(StmtBitfields)
0149 unsigned : NumStmtBits;
0150
0151
0152
0153 LLVM_PREFERRED_TYPE(bool)
0154 unsigned HasFPFeatures : 1;
0155
0156 unsigned NumStmts;
0157 };
0158
0159 class LabelStmtBitfields {
0160 friend class LabelStmt;
0161
0162 LLVM_PREFERRED_TYPE(StmtBitfields)
0163 unsigned : NumStmtBits;
0164
0165 SourceLocation IdentLoc;
0166 };
0167
0168 class AttributedStmtBitfields {
0169 friend class ASTStmtReader;
0170 friend class AttributedStmt;
0171
0172 LLVM_PREFERRED_TYPE(StmtBitfields)
0173 unsigned : NumStmtBits;
0174
0175
0176 unsigned NumAttrs : 32 - NumStmtBits;
0177
0178
0179 SourceLocation AttrLoc;
0180 };
0181
0182 class IfStmtBitfields {
0183 friend class ASTStmtReader;
0184 friend class IfStmt;
0185
0186 LLVM_PREFERRED_TYPE(StmtBitfields)
0187 unsigned : NumStmtBits;
0188
0189
0190 LLVM_PREFERRED_TYPE(IfStatementKind)
0191 unsigned Kind : 3;
0192
0193
0194 LLVM_PREFERRED_TYPE(bool)
0195 unsigned HasElse : 1;
0196
0197
0198 LLVM_PREFERRED_TYPE(bool)
0199 unsigned HasVar : 1;
0200
0201
0202 LLVM_PREFERRED_TYPE(bool)
0203 unsigned HasInit : 1;
0204
0205
0206 SourceLocation IfLoc;
0207 };
0208
0209 class SwitchStmtBitfields {
0210 friend class SwitchStmt;
0211
0212 LLVM_PREFERRED_TYPE(StmtBitfields)
0213 unsigned : NumStmtBits;
0214
0215
0216 LLVM_PREFERRED_TYPE(bool)
0217 unsigned HasInit : 1;
0218
0219
0220 LLVM_PREFERRED_TYPE(bool)
0221 unsigned HasVar : 1;
0222
0223
0224
0225
0226 LLVM_PREFERRED_TYPE(bool)
0227 unsigned AllEnumCasesCovered : 1;
0228
0229
0230 SourceLocation SwitchLoc;
0231 };
0232
0233 class WhileStmtBitfields {
0234 friend class ASTStmtReader;
0235 friend class WhileStmt;
0236
0237 LLVM_PREFERRED_TYPE(StmtBitfields)
0238 unsigned : NumStmtBits;
0239
0240
0241 LLVM_PREFERRED_TYPE(bool)
0242 unsigned HasVar : 1;
0243
0244
0245 SourceLocation WhileLoc;
0246 };
0247
0248 class DoStmtBitfields {
0249 friend class DoStmt;
0250
0251 LLVM_PREFERRED_TYPE(StmtBitfields)
0252 unsigned : NumStmtBits;
0253
0254
0255 SourceLocation DoLoc;
0256 };
0257
0258 class ForStmtBitfields {
0259 friend class ForStmt;
0260
0261 LLVM_PREFERRED_TYPE(StmtBitfields)
0262 unsigned : NumStmtBits;
0263
0264
0265 SourceLocation ForLoc;
0266 };
0267
0268 class GotoStmtBitfields {
0269 friend class GotoStmt;
0270 friend class IndirectGotoStmt;
0271
0272 LLVM_PREFERRED_TYPE(StmtBitfields)
0273 unsigned : NumStmtBits;
0274
0275
0276 SourceLocation GotoLoc;
0277 };
0278
0279 class ContinueStmtBitfields {
0280 friend class ContinueStmt;
0281
0282 LLVM_PREFERRED_TYPE(StmtBitfields)
0283 unsigned : NumStmtBits;
0284
0285
0286 SourceLocation ContinueLoc;
0287 };
0288
0289 class BreakStmtBitfields {
0290 friend class BreakStmt;
0291
0292 LLVM_PREFERRED_TYPE(StmtBitfields)
0293 unsigned : NumStmtBits;
0294
0295
0296 SourceLocation BreakLoc;
0297 };
0298
0299 class ReturnStmtBitfields {
0300 friend class ReturnStmt;
0301
0302 LLVM_PREFERRED_TYPE(StmtBitfields)
0303 unsigned : NumStmtBits;
0304
0305
0306 LLVM_PREFERRED_TYPE(bool)
0307 unsigned HasNRVOCandidate : 1;
0308
0309
0310 SourceLocation RetLoc;
0311 };
0312
0313 class SwitchCaseBitfields {
0314 friend class SwitchCase;
0315 friend class CaseStmt;
0316
0317 LLVM_PREFERRED_TYPE(StmtBitfields)
0318 unsigned : NumStmtBits;
0319
0320
0321
0322 LLVM_PREFERRED_TYPE(bool)
0323 unsigned CaseStmtIsGNURange : 1;
0324
0325
0326 SourceLocation KeywordLoc;
0327 };
0328
0329
0330
0331 class ExprBitfields {
0332 friend class ASTStmtReader;
0333 friend class AtomicExpr;
0334 friend class BlockDeclRefExpr;
0335 friend class CallExpr;
0336 friend class CXXConstructExpr;
0337 friend class CXXDependentScopeMemberExpr;
0338 friend class CXXNewExpr;
0339 friend class CXXUnresolvedConstructExpr;
0340 friend class DeclRefExpr;
0341 friend class DependentScopeDeclRefExpr;
0342 friend class DesignatedInitExpr;
0343 friend class Expr;
0344 friend class InitListExpr;
0345 friend class ObjCArrayLiteral;
0346 friend class ObjCDictionaryLiteral;
0347 friend class ObjCMessageExpr;
0348 friend class OffsetOfExpr;
0349 friend class OpaqueValueExpr;
0350 friend class OverloadExpr;
0351 friend class ParenListExpr;
0352 friend class PseudoObjectExpr;
0353 friend class ShuffleVectorExpr;
0354
0355 LLVM_PREFERRED_TYPE(StmtBitfields)
0356 unsigned : NumStmtBits;
0357
0358 LLVM_PREFERRED_TYPE(ExprValueKind)
0359 unsigned ValueKind : 2;
0360 LLVM_PREFERRED_TYPE(ExprObjectKind)
0361 unsigned ObjectKind : 3;
0362 LLVM_PREFERRED_TYPE(ExprDependence)
0363 unsigned Dependent : llvm::BitWidth<ExprDependence>;
0364 };
0365 enum { NumExprBits = NumStmtBits + 5 + llvm::BitWidth<ExprDependence> };
0366
0367 class ConstantExprBitfields {
0368 friend class ASTStmtReader;
0369 friend class ASTStmtWriter;
0370 friend class ConstantExpr;
0371
0372 LLVM_PREFERRED_TYPE(ExprBitfields)
0373 unsigned : NumExprBits;
0374
0375
0376 LLVM_PREFERRED_TYPE(ConstantResultStorageKind)
0377 unsigned ResultKind : 2;
0378
0379
0380 LLVM_PREFERRED_TYPE(APValue::ValueKind)
0381 unsigned APValueKind : 4;
0382
0383
0384
0385 LLVM_PREFERRED_TYPE(bool)
0386 unsigned IsUnsigned : 1;
0387
0388
0389
0390
0391
0392 unsigned BitWidth : 7;
0393
0394
0395
0396 LLVM_PREFERRED_TYPE(bool)
0397 unsigned HasCleanup : 1;
0398
0399
0400 LLVM_PREFERRED_TYPE(bool)
0401 unsigned IsImmediateInvocation : 1;
0402 };
0403
0404 class PredefinedExprBitfields {
0405 friend class ASTStmtReader;
0406 friend class PredefinedExpr;
0407
0408 LLVM_PREFERRED_TYPE(ExprBitfields)
0409 unsigned : NumExprBits;
0410
0411 LLVM_PREFERRED_TYPE(PredefinedIdentKind)
0412 unsigned Kind : 4;
0413
0414
0415
0416 LLVM_PREFERRED_TYPE(bool)
0417 unsigned HasFunctionName : 1;
0418
0419
0420
0421 LLVM_PREFERRED_TYPE(bool)
0422 unsigned IsTransparent : 1;
0423
0424
0425 SourceLocation Loc;
0426 };
0427
0428 class DeclRefExprBitfields {
0429 friend class ASTStmtReader;
0430 friend class DeclRefExpr;
0431
0432 LLVM_PREFERRED_TYPE(ExprBitfields)
0433 unsigned : NumExprBits;
0434
0435 LLVM_PREFERRED_TYPE(bool)
0436 unsigned HasQualifier : 1;
0437 LLVM_PREFERRED_TYPE(bool)
0438 unsigned HasTemplateKWAndArgsInfo : 1;
0439 LLVM_PREFERRED_TYPE(bool)
0440 unsigned HasFoundDecl : 1;
0441 LLVM_PREFERRED_TYPE(bool)
0442 unsigned HadMultipleCandidates : 1;
0443 LLVM_PREFERRED_TYPE(bool)
0444 unsigned RefersToEnclosingVariableOrCapture : 1;
0445 LLVM_PREFERRED_TYPE(bool)
0446 unsigned CapturedByCopyInLambdaWithExplicitObjectParameter : 1;
0447 LLVM_PREFERRED_TYPE(NonOdrUseReason)
0448 unsigned NonOdrUseReason : 2;
0449 LLVM_PREFERRED_TYPE(bool)
0450 unsigned IsImmediateEscalating : 1;
0451
0452
0453 SourceLocation Loc;
0454 };
0455
0456
0457 class FloatingLiteralBitfields {
0458 friend class FloatingLiteral;
0459
0460 LLVM_PREFERRED_TYPE(ExprBitfields)
0461 unsigned : NumExprBits;
0462
0463 static_assert(
0464 llvm::APFloat::S_MaxSemantics < 32,
0465 "Too many Semantics enum values to fit in bitfield of size 5");
0466 LLVM_PREFERRED_TYPE(llvm::APFloat::Semantics)
0467 unsigned Semantics : 5;
0468 LLVM_PREFERRED_TYPE(bool)
0469 unsigned IsExact : 1;
0470 };
0471
0472 class StringLiteralBitfields {
0473 friend class ASTStmtReader;
0474 friend class StringLiteral;
0475
0476 LLVM_PREFERRED_TYPE(ExprBitfields)
0477 unsigned : NumExprBits;
0478
0479
0480
0481 LLVM_PREFERRED_TYPE(StringLiteralKind)
0482 unsigned Kind : 3;
0483
0484
0485
0486
0487 unsigned CharByteWidth : 3;
0488
0489 LLVM_PREFERRED_TYPE(bool)
0490 unsigned IsPascal : 1;
0491
0492
0493
0494 unsigned NumConcatenated;
0495 };
0496
0497 class CharacterLiteralBitfields {
0498 friend class CharacterLiteral;
0499
0500 LLVM_PREFERRED_TYPE(ExprBitfields)
0501 unsigned : NumExprBits;
0502
0503 LLVM_PREFERRED_TYPE(CharacterLiteralKind)
0504 unsigned Kind : 3;
0505 };
0506
0507 class UnaryOperatorBitfields {
0508 friend class UnaryOperator;
0509
0510 LLVM_PREFERRED_TYPE(ExprBitfields)
0511 unsigned : NumExprBits;
0512
0513 LLVM_PREFERRED_TYPE(UnaryOperatorKind)
0514 unsigned Opc : 5;
0515 LLVM_PREFERRED_TYPE(bool)
0516 unsigned CanOverflow : 1;
0517
0518
0519
0520
0521 LLVM_PREFERRED_TYPE(bool)
0522 unsigned HasFPFeatures : 1;
0523
0524 SourceLocation Loc;
0525 };
0526
0527 class UnaryExprOrTypeTraitExprBitfields {
0528 friend class UnaryExprOrTypeTraitExpr;
0529
0530 LLVM_PREFERRED_TYPE(ExprBitfields)
0531 unsigned : NumExprBits;
0532
0533 LLVM_PREFERRED_TYPE(UnaryExprOrTypeTrait)
0534 unsigned Kind : 3;
0535 LLVM_PREFERRED_TYPE(bool)
0536 unsigned IsType : 1;
0537 };
0538
0539 class ArrayOrMatrixSubscriptExprBitfields {
0540 friend class ArraySubscriptExpr;
0541 friend class MatrixSubscriptExpr;
0542
0543 LLVM_PREFERRED_TYPE(ExprBitfields)
0544 unsigned : NumExprBits;
0545
0546 SourceLocation RBracketLoc;
0547 };
0548
0549 class CallExprBitfields {
0550 friend class CallExpr;
0551
0552 LLVM_PREFERRED_TYPE(ExprBitfields)
0553 unsigned : NumExprBits;
0554
0555 unsigned NumPreArgs : 1;
0556
0557
0558 LLVM_PREFERRED_TYPE(bool)
0559 unsigned UsesADL : 1;
0560
0561
0562 LLVM_PREFERRED_TYPE(bool)
0563 unsigned HasFPFeatures : 1;
0564
0565
0566 unsigned IsCoroElideSafe : 1;
0567
0568
0569 unsigned : 24 - 4 - NumExprBits;
0570
0571
0572
0573
0574 unsigned OffsetToTrailingObjects : 8;
0575 };
0576 enum { NumCallExprBits = 32 };
0577
0578 class MemberExprBitfields {
0579 friend class ASTStmtReader;
0580 friend class MemberExpr;
0581
0582 LLVM_PREFERRED_TYPE(ExprBitfields)
0583 unsigned : NumExprBits;
0584
0585
0586 LLVM_PREFERRED_TYPE(bool)
0587 unsigned IsArrow : 1;
0588
0589
0590
0591 LLVM_PREFERRED_TYPE(bool)
0592 unsigned HasQualifier : 1;
0593
0594
0595 LLVM_PREFERRED_TYPE(bool)
0596 unsigned HasFoundDecl : 1;
0597
0598
0599
0600
0601
0602
0603 LLVM_PREFERRED_TYPE(bool)
0604 unsigned HasTemplateKWAndArgsInfo : 1;
0605
0606
0607
0608 LLVM_PREFERRED_TYPE(bool)
0609 unsigned HadMultipleCandidates : 1;
0610
0611
0612
0613
0614 LLVM_PREFERRED_TYPE(NonOdrUseReason)
0615 unsigned NonOdrUseReason : 2;
0616
0617
0618 SourceLocation OperatorLoc;
0619 };
0620
0621 class CastExprBitfields {
0622 friend class CastExpr;
0623 friend class ImplicitCastExpr;
0624
0625 LLVM_PREFERRED_TYPE(ExprBitfields)
0626 unsigned : NumExprBits;
0627
0628 LLVM_PREFERRED_TYPE(CastKind)
0629 unsigned Kind : 7;
0630 LLVM_PREFERRED_TYPE(bool)
0631 unsigned PartOfExplicitCast : 1;
0632
0633
0634 LLVM_PREFERRED_TYPE(bool)
0635 unsigned HasFPFeatures : 1;
0636
0637
0638
0639 unsigned BasePathSize;
0640 };
0641
0642 class BinaryOperatorBitfields {
0643 friend class BinaryOperator;
0644
0645 LLVM_PREFERRED_TYPE(ExprBitfields)
0646 unsigned : NumExprBits;
0647
0648 LLVM_PREFERRED_TYPE(BinaryOperatorKind)
0649 unsigned Opc : 6;
0650
0651
0652
0653
0654 LLVM_PREFERRED_TYPE(bool)
0655 unsigned HasFPFeatures : 1;
0656
0657
0658
0659 LLVM_PREFERRED_TYPE(bool)
0660 unsigned ExcludedOverflowPattern : 1;
0661
0662 SourceLocation OpLoc;
0663 };
0664
0665 class InitListExprBitfields {
0666 friend class InitListExpr;
0667
0668 LLVM_PREFERRED_TYPE(ExprBitfields)
0669 unsigned : NumExprBits;
0670
0671
0672
0673 LLVM_PREFERRED_TYPE(bool)
0674 unsigned HadArrayRangeDesignator : 1;
0675 };
0676
0677 class ParenListExprBitfields {
0678 friend class ASTStmtReader;
0679 friend class ParenListExpr;
0680
0681 LLVM_PREFERRED_TYPE(ExprBitfields)
0682 unsigned : NumExprBits;
0683
0684
0685 unsigned NumExprs;
0686 };
0687
0688 class GenericSelectionExprBitfields {
0689 friend class ASTStmtReader;
0690 friend class GenericSelectionExpr;
0691
0692 LLVM_PREFERRED_TYPE(ExprBitfields)
0693 unsigned : NumExprBits;
0694
0695
0696 SourceLocation GenericLoc;
0697 };
0698
0699 class PseudoObjectExprBitfields {
0700 friend class ASTStmtReader;
0701 friend class PseudoObjectExpr;
0702
0703 LLVM_PREFERRED_TYPE(ExprBitfields)
0704 unsigned : NumExprBits;
0705
0706 unsigned NumSubExprs : 16;
0707 unsigned ResultIndex : 16;
0708 };
0709
0710 class SourceLocExprBitfields {
0711 friend class ASTStmtReader;
0712 friend class SourceLocExpr;
0713
0714 LLVM_PREFERRED_TYPE(ExprBitfields)
0715 unsigned : NumExprBits;
0716
0717
0718
0719 LLVM_PREFERRED_TYPE(SourceLocIdentKind)
0720 unsigned Kind : 3;
0721 };
0722
0723 class ParenExprBitfields {
0724 friend class ASTStmtReader;
0725 friend class ASTStmtWriter;
0726 friend class ParenExpr;
0727
0728 LLVM_PREFERRED_TYPE(ExprBitfields)
0729 unsigned : NumExprBits;
0730
0731 LLVM_PREFERRED_TYPE(bool)
0732 unsigned ProducedByFoldExpansion : 1;
0733 };
0734
0735 class StmtExprBitfields {
0736 friend class ASTStmtReader;
0737 friend class StmtExpr;
0738
0739 LLVM_PREFERRED_TYPE(ExprBitfields)
0740 unsigned : NumExprBits;
0741
0742
0743
0744
0745 unsigned TemplateDepth;
0746 };
0747
0748
0749
0750 class CXXOperatorCallExprBitfields {
0751 friend class ASTStmtReader;
0752 friend class CXXOperatorCallExpr;
0753
0754 LLVM_PREFERRED_TYPE(CallExprBitfields)
0755 unsigned : NumCallExprBits;
0756
0757
0758
0759 LLVM_PREFERRED_TYPE(OverloadedOperatorKind)
0760 unsigned OperatorKind : 6;
0761 };
0762
0763 class CXXRewrittenBinaryOperatorBitfields {
0764 friend class ASTStmtReader;
0765 friend class CXXRewrittenBinaryOperator;
0766
0767 LLVM_PREFERRED_TYPE(CallExprBitfields)
0768 unsigned : NumCallExprBits;
0769
0770 LLVM_PREFERRED_TYPE(bool)
0771 unsigned IsReversed : 1;
0772 };
0773
0774 class CXXBoolLiteralExprBitfields {
0775 friend class CXXBoolLiteralExpr;
0776
0777 LLVM_PREFERRED_TYPE(ExprBitfields)
0778 unsigned : NumExprBits;
0779
0780
0781 LLVM_PREFERRED_TYPE(bool)
0782 unsigned Value : 1;
0783
0784
0785 SourceLocation Loc;
0786 };
0787
0788 class CXXNullPtrLiteralExprBitfields {
0789 friend class CXXNullPtrLiteralExpr;
0790
0791 LLVM_PREFERRED_TYPE(ExprBitfields)
0792 unsigned : NumExprBits;
0793
0794
0795 SourceLocation Loc;
0796 };
0797
0798 class CXXThisExprBitfields {
0799 friend class CXXThisExpr;
0800
0801 LLVM_PREFERRED_TYPE(ExprBitfields)
0802 unsigned : NumExprBits;
0803
0804
0805 LLVM_PREFERRED_TYPE(bool)
0806 unsigned IsImplicit : 1;
0807
0808
0809
0810 LLVM_PREFERRED_TYPE(bool)
0811 unsigned CapturedByCopyInLambdaWithExplicitObjectParameter : 1;
0812
0813
0814 SourceLocation Loc;
0815 };
0816
0817 class CXXThrowExprBitfields {
0818 friend class ASTStmtReader;
0819 friend class CXXThrowExpr;
0820
0821 LLVM_PREFERRED_TYPE(ExprBitfields)
0822 unsigned : NumExprBits;
0823
0824
0825 LLVM_PREFERRED_TYPE(bool)
0826 unsigned IsThrownVariableInScope : 1;
0827
0828
0829 SourceLocation ThrowLoc;
0830 };
0831
0832 class CXXDefaultArgExprBitfields {
0833 friend class ASTStmtReader;
0834 friend class CXXDefaultArgExpr;
0835
0836 LLVM_PREFERRED_TYPE(ExprBitfields)
0837 unsigned : NumExprBits;
0838
0839
0840 LLVM_PREFERRED_TYPE(bool)
0841 unsigned HasRewrittenInit : 1;
0842
0843
0844 SourceLocation Loc;
0845 };
0846
0847 class CXXDefaultInitExprBitfields {
0848 friend class ASTStmtReader;
0849 friend class CXXDefaultInitExpr;
0850
0851 LLVM_PREFERRED_TYPE(ExprBitfields)
0852 unsigned : NumExprBits;
0853
0854
0855
0856 LLVM_PREFERRED_TYPE(bool)
0857 unsigned HasRewrittenInit : 1;
0858
0859
0860 SourceLocation Loc;
0861 };
0862
0863 class CXXScalarValueInitExprBitfields {
0864 friend class ASTStmtReader;
0865 friend class CXXScalarValueInitExpr;
0866
0867 LLVM_PREFERRED_TYPE(ExprBitfields)
0868 unsigned : NumExprBits;
0869
0870 SourceLocation RParenLoc;
0871 };
0872
0873 class CXXNewExprBitfields {
0874 friend class ASTStmtReader;
0875 friend class ASTStmtWriter;
0876 friend class CXXNewExpr;
0877
0878 LLVM_PREFERRED_TYPE(ExprBitfields)
0879 unsigned : NumExprBits;
0880
0881
0882 LLVM_PREFERRED_TYPE(bool)
0883 unsigned IsGlobalNew : 1;
0884
0885
0886
0887 LLVM_PREFERRED_TYPE(bool)
0888 unsigned IsArray : 1;
0889
0890
0891 LLVM_PREFERRED_TYPE(bool)
0892 unsigned ShouldPassAlignment : 1;
0893
0894
0895
0896 LLVM_PREFERRED_TYPE(bool)
0897 unsigned UsualArrayDeleteWantsSize : 1;
0898
0899
0900 LLVM_PREFERRED_TYPE(bool)
0901 unsigned HasInitializer : 1;
0902
0903
0904 LLVM_PREFERRED_TYPE(CXXNewInitializationStyle)
0905 unsigned StoredInitializationStyle : 2;
0906
0907
0908 LLVM_PREFERRED_TYPE(bool)
0909 unsigned IsParenTypeId : 1;
0910
0911
0912 unsigned NumPlacementArgs;
0913 };
0914
0915 class CXXDeleteExprBitfields {
0916 friend class ASTStmtReader;
0917 friend class CXXDeleteExpr;
0918
0919 LLVM_PREFERRED_TYPE(ExprBitfields)
0920 unsigned : NumExprBits;
0921
0922
0923 LLVM_PREFERRED_TYPE(bool)
0924 unsigned GlobalDelete : 1;
0925
0926
0927 LLVM_PREFERRED_TYPE(bool)
0928 unsigned ArrayForm : 1;
0929
0930
0931
0932
0933 LLVM_PREFERRED_TYPE(bool)
0934 unsigned ArrayFormAsWritten : 1;
0935
0936
0937
0938 LLVM_PREFERRED_TYPE(bool)
0939 unsigned UsualArrayDeleteWantsSize : 1;
0940
0941
0942 SourceLocation Loc;
0943 };
0944
0945 class TypeTraitExprBitfields {
0946 friend class ASTStmtReader;
0947 friend class ASTStmtWriter;
0948 friend class TypeTraitExpr;
0949
0950 LLVM_PREFERRED_TYPE(ExprBitfields)
0951 unsigned : NumExprBits;
0952
0953
0954 LLVM_PREFERRED_TYPE(TypeTrait)
0955 unsigned Kind : 8;
0956
0957
0958
0959 LLVM_PREFERRED_TYPE(bool)
0960 unsigned Value : 1;
0961
0962
0963
0964
0965 unsigned NumArgs;
0966 };
0967
0968 class DependentScopeDeclRefExprBitfields {
0969 friend class ASTStmtReader;
0970 friend class ASTStmtWriter;
0971 friend class DependentScopeDeclRefExpr;
0972
0973 LLVM_PREFERRED_TYPE(ExprBitfields)
0974 unsigned : NumExprBits;
0975
0976
0977
0978 LLVM_PREFERRED_TYPE(bool)
0979 unsigned HasTemplateKWAndArgsInfo : 1;
0980 };
0981
0982 class CXXConstructExprBitfields {
0983 friend class ASTStmtReader;
0984 friend class CXXConstructExpr;
0985
0986 LLVM_PREFERRED_TYPE(ExprBitfields)
0987 unsigned : NumExprBits;
0988
0989 LLVM_PREFERRED_TYPE(bool)
0990 unsigned Elidable : 1;
0991 LLVM_PREFERRED_TYPE(bool)
0992 unsigned HadMultipleCandidates : 1;
0993 LLVM_PREFERRED_TYPE(bool)
0994 unsigned ListInitialization : 1;
0995 LLVM_PREFERRED_TYPE(bool)
0996 unsigned StdInitListInitialization : 1;
0997 LLVM_PREFERRED_TYPE(bool)
0998 unsigned ZeroInitialization : 1;
0999 LLVM_PREFERRED_TYPE(CXXConstructionKind)
1000 unsigned ConstructionKind : 3;
1001 LLVM_PREFERRED_TYPE(bool)
1002 unsigned IsImmediateEscalating : 1;
1003
1004 SourceLocation Loc;
1005 };
1006
1007 class ExprWithCleanupsBitfields {
1008 friend class ASTStmtReader;
1009 friend class ExprWithCleanups;
1010
1011 LLVM_PREFERRED_TYPE(ExprBitfields)
1012 unsigned : NumExprBits;
1013
1014
1015 LLVM_PREFERRED_TYPE(bool)
1016 unsigned CleanupsHaveSideEffects : 1;
1017
1018 unsigned NumObjects : 32 - 1 - NumExprBits;
1019 };
1020
1021 class CXXUnresolvedConstructExprBitfields {
1022 friend class ASTStmtReader;
1023 friend class CXXUnresolvedConstructExpr;
1024
1025 LLVM_PREFERRED_TYPE(ExprBitfields)
1026 unsigned : NumExprBits;
1027
1028
1029 unsigned NumArgs;
1030 };
1031
1032 class CXXDependentScopeMemberExprBitfields {
1033 friend class ASTStmtReader;
1034 friend class CXXDependentScopeMemberExpr;
1035
1036 LLVM_PREFERRED_TYPE(ExprBitfields)
1037 unsigned : NumExprBits;
1038
1039
1040
1041 LLVM_PREFERRED_TYPE(bool)
1042 unsigned IsArrow : 1;
1043
1044
1045
1046 LLVM_PREFERRED_TYPE(bool)
1047 unsigned HasTemplateKWAndArgsInfo : 1;
1048
1049
1050
1051 LLVM_PREFERRED_TYPE(bool)
1052 unsigned HasFirstQualifierFoundInScope : 1;
1053
1054
1055 SourceLocation OperatorLoc;
1056 };
1057
1058 class OverloadExprBitfields {
1059 friend class ASTStmtReader;
1060 friend class OverloadExpr;
1061
1062 LLVM_PREFERRED_TYPE(ExprBitfields)
1063 unsigned : NumExprBits;
1064
1065
1066
1067 LLVM_PREFERRED_TYPE(bool)
1068 unsigned HasTemplateKWAndArgsInfo : 1;
1069
1070
1071
1072
1073 unsigned : 32 - NumExprBits - 1;
1074
1075
1076 unsigned NumResults;
1077 };
1078 enum { NumOverloadExprBits = NumExprBits + 1 };
1079
1080 class UnresolvedLookupExprBitfields {
1081 friend class ASTStmtReader;
1082 friend class UnresolvedLookupExpr;
1083
1084 LLVM_PREFERRED_TYPE(OverloadExprBitfields)
1085 unsigned : NumOverloadExprBits;
1086
1087
1088
1089 LLVM_PREFERRED_TYPE(bool)
1090 unsigned RequiresADL : 1;
1091 };
1092 static_assert(sizeof(UnresolvedLookupExprBitfields) <= 4,
1093 "UnresolvedLookupExprBitfields must be <= than 4 bytes to"
1094 "avoid trashing OverloadExprBitfields::NumResults!");
1095
1096 class UnresolvedMemberExprBitfields {
1097 friend class ASTStmtReader;
1098 friend class UnresolvedMemberExpr;
1099
1100 LLVM_PREFERRED_TYPE(OverloadExprBitfields)
1101 unsigned : NumOverloadExprBits;
1102
1103
1104
1105 LLVM_PREFERRED_TYPE(bool)
1106 unsigned IsArrow : 1;
1107
1108
1109 LLVM_PREFERRED_TYPE(bool)
1110 unsigned HasUnresolvedUsing : 1;
1111 };
1112 static_assert(sizeof(UnresolvedMemberExprBitfields) <= 4,
1113 "UnresolvedMemberExprBitfields must be <= than 4 bytes to"
1114 "avoid trashing OverloadExprBitfields::NumResults!");
1115
1116 class CXXNoexceptExprBitfields {
1117 friend class ASTStmtReader;
1118 friend class CXXNoexceptExpr;
1119
1120 LLVM_PREFERRED_TYPE(ExprBitfields)
1121 unsigned : NumExprBits;
1122
1123 LLVM_PREFERRED_TYPE(bool)
1124 unsigned Value : 1;
1125 };
1126
1127 class SubstNonTypeTemplateParmExprBitfields {
1128 friend class ASTStmtReader;
1129 friend class SubstNonTypeTemplateParmExpr;
1130
1131 LLVM_PREFERRED_TYPE(ExprBitfields)
1132 unsigned : NumExprBits;
1133
1134
1135 SourceLocation NameLoc;
1136 };
1137
1138 class LambdaExprBitfields {
1139 friend class ASTStmtReader;
1140 friend class ASTStmtWriter;
1141 friend class LambdaExpr;
1142
1143 LLVM_PREFERRED_TYPE(ExprBitfields)
1144 unsigned : NumExprBits;
1145
1146
1147
1148 LLVM_PREFERRED_TYPE(LambdaCaptureDefault)
1149 unsigned CaptureDefault : 2;
1150
1151
1152
1153 LLVM_PREFERRED_TYPE(bool)
1154 unsigned ExplicitParams : 1;
1155
1156
1157 LLVM_PREFERRED_TYPE(bool)
1158 unsigned ExplicitResultType : 1;
1159
1160
1161 unsigned NumCaptures : 16;
1162 };
1163
1164 class RequiresExprBitfields {
1165 friend class ASTStmtReader;
1166 friend class ASTStmtWriter;
1167 friend class RequiresExpr;
1168
1169 LLVM_PREFERRED_TYPE(ExprBitfields)
1170 unsigned : NumExprBits;
1171
1172 LLVM_PREFERRED_TYPE(bool)
1173 unsigned IsSatisfied : 1;
1174 SourceLocation RequiresKWLoc;
1175 };
1176
1177
1178
1179 class CoawaitExprBitfields {
1180 friend class CoawaitExpr;
1181
1182 LLVM_PREFERRED_TYPE(ExprBitfields)
1183 unsigned : NumExprBits;
1184
1185 LLVM_PREFERRED_TYPE(bool)
1186 unsigned IsImplicit : 1;
1187 };
1188
1189
1190
1191 class ObjCIndirectCopyRestoreExprBitfields {
1192 friend class ObjCIndirectCopyRestoreExpr;
1193
1194 LLVM_PREFERRED_TYPE(ExprBitfields)
1195 unsigned : NumExprBits;
1196
1197 LLVM_PREFERRED_TYPE(bool)
1198 unsigned ShouldCopy : 1;
1199 };
1200
1201
1202
1203 class OpaqueValueExprBitfields {
1204 friend class ASTStmtReader;
1205 friend class OpaqueValueExpr;
1206
1207 LLVM_PREFERRED_TYPE(ExprBitfields)
1208 unsigned : NumExprBits;
1209
1210
1211
1212 LLVM_PREFERRED_TYPE(bool)
1213 unsigned IsUnique : 1;
1214
1215 SourceLocation Loc;
1216 };
1217
1218 union {
1219
1220
1221 StmtBitfields StmtBits;
1222 NullStmtBitfields NullStmtBits;
1223 CompoundStmtBitfields CompoundStmtBits;
1224 LabelStmtBitfields LabelStmtBits;
1225 AttributedStmtBitfields AttributedStmtBits;
1226 IfStmtBitfields IfStmtBits;
1227 SwitchStmtBitfields SwitchStmtBits;
1228 WhileStmtBitfields WhileStmtBits;
1229 DoStmtBitfields DoStmtBits;
1230 ForStmtBitfields ForStmtBits;
1231 GotoStmtBitfields GotoStmtBits;
1232 ContinueStmtBitfields ContinueStmtBits;
1233 BreakStmtBitfields BreakStmtBits;
1234 ReturnStmtBitfields ReturnStmtBits;
1235 SwitchCaseBitfields SwitchCaseBits;
1236
1237
1238 ExprBitfields ExprBits;
1239 ConstantExprBitfields ConstantExprBits;
1240 PredefinedExprBitfields PredefinedExprBits;
1241 DeclRefExprBitfields DeclRefExprBits;
1242 FloatingLiteralBitfields FloatingLiteralBits;
1243 StringLiteralBitfields StringLiteralBits;
1244 CharacterLiteralBitfields CharacterLiteralBits;
1245 UnaryOperatorBitfields UnaryOperatorBits;
1246 UnaryExprOrTypeTraitExprBitfields UnaryExprOrTypeTraitExprBits;
1247 ArrayOrMatrixSubscriptExprBitfields ArrayOrMatrixSubscriptExprBits;
1248 CallExprBitfields CallExprBits;
1249 MemberExprBitfields MemberExprBits;
1250 CastExprBitfields CastExprBits;
1251 BinaryOperatorBitfields BinaryOperatorBits;
1252 InitListExprBitfields InitListExprBits;
1253 ParenListExprBitfields ParenListExprBits;
1254 GenericSelectionExprBitfields GenericSelectionExprBits;
1255 PseudoObjectExprBitfields PseudoObjectExprBits;
1256 SourceLocExprBitfields SourceLocExprBits;
1257 ParenExprBitfields ParenExprBits;
1258
1259
1260 StmtExprBitfields StmtExprBits;
1261
1262
1263 CXXOperatorCallExprBitfields CXXOperatorCallExprBits;
1264 CXXRewrittenBinaryOperatorBitfields CXXRewrittenBinaryOperatorBits;
1265 CXXBoolLiteralExprBitfields CXXBoolLiteralExprBits;
1266 CXXNullPtrLiteralExprBitfields CXXNullPtrLiteralExprBits;
1267 CXXThisExprBitfields CXXThisExprBits;
1268 CXXThrowExprBitfields CXXThrowExprBits;
1269 CXXDefaultArgExprBitfields CXXDefaultArgExprBits;
1270 CXXDefaultInitExprBitfields CXXDefaultInitExprBits;
1271 CXXScalarValueInitExprBitfields CXXScalarValueInitExprBits;
1272 CXXNewExprBitfields CXXNewExprBits;
1273 CXXDeleteExprBitfields CXXDeleteExprBits;
1274 TypeTraitExprBitfields TypeTraitExprBits;
1275 DependentScopeDeclRefExprBitfields DependentScopeDeclRefExprBits;
1276 CXXConstructExprBitfields CXXConstructExprBits;
1277 ExprWithCleanupsBitfields ExprWithCleanupsBits;
1278 CXXUnresolvedConstructExprBitfields CXXUnresolvedConstructExprBits;
1279 CXXDependentScopeMemberExprBitfields CXXDependentScopeMemberExprBits;
1280 OverloadExprBitfields OverloadExprBits;
1281 UnresolvedLookupExprBitfields UnresolvedLookupExprBits;
1282 UnresolvedMemberExprBitfields UnresolvedMemberExprBits;
1283 CXXNoexceptExprBitfields CXXNoexceptExprBits;
1284 SubstNonTypeTemplateParmExprBitfields SubstNonTypeTemplateParmExprBits;
1285 LambdaExprBitfields LambdaExprBits;
1286 RequiresExprBitfields RequiresExprBits;
1287
1288
1289 CoawaitExprBitfields CoawaitBits;
1290
1291
1292 ObjCIndirectCopyRestoreExprBitfields ObjCIndirectCopyRestoreExprBits;
1293
1294
1295 OpaqueValueExprBitfields OpaqueValueExprBits;
1296 };
1297
1298 public:
1299
1300
1301 void* operator new(size_t bytes, const ASTContext& C,
1302 unsigned alignment = 8);
1303
1304 void* operator new(size_t bytes, const ASTContext* C,
1305 unsigned alignment = 8) {
1306 return operator new(bytes, *C, alignment);
1307 }
1308
1309 void *operator new(size_t bytes, void *mem) noexcept { return mem; }
1310
1311 void operator delete(void *, const ASTContext &, unsigned) noexcept {}
1312 void operator delete(void *, const ASTContext *, unsigned) noexcept {}
1313 void operator delete(void *, size_t) noexcept {}
1314 void operator delete(void *, void *) noexcept {}
1315
1316 public:
1317
1318
1319
1320 struct EmptyShell {};
1321
1322
1323 enum Likelihood {
1324 LH_Unlikely = -1,
1325 LH_None,
1326
1327 LH_Likely
1328 };
1329
1330 protected:
1331
1332
1333
1334
1335 template<typename T, typename TPtr = T *, typename StmtPtr = Stmt *>
1336 struct CastIterator
1337 : llvm::iterator_adaptor_base<CastIterator<T, TPtr, StmtPtr>, StmtPtr *,
1338 std::random_access_iterator_tag, TPtr> {
1339 using Base = typename CastIterator::iterator_adaptor_base;
1340
1341 CastIterator() : Base(nullptr) {}
1342 CastIterator(StmtPtr *I) : Base(I) {}
1343
1344 typename Base::value_type operator*() const {
1345 return cast_or_null<T>(*this->I);
1346 }
1347 };
1348
1349
1350 template <typename T>
1351 using ConstCastIterator = CastIterator<T, const T *const, const Stmt *const>;
1352
1353 using ExprIterator = CastIterator<Expr>;
1354 using ConstExprIterator = ConstCastIterator<Expr>;
1355
1356 private:
1357
1358 static bool StatisticsEnabled;
1359
1360 protected:
1361
1362 explicit Stmt(StmtClass SC, EmptyShell) : Stmt(SC) {}
1363
1364 public:
1365 Stmt() = delete;
1366 Stmt(const Stmt &) = delete;
1367 Stmt(Stmt &&) = delete;
1368 Stmt &operator=(const Stmt &) = delete;
1369 Stmt &operator=(Stmt &&) = delete;
1370
1371 Stmt(StmtClass SC) {
1372 static_assert(sizeof(*this) <= 8,
1373 "changing bitfields changed sizeof(Stmt)");
1374 static_assert(sizeof(*this) % alignof(void *) == 0,
1375 "Insufficient alignment!");
1376 StmtBits.sClass = SC;
1377 if (StatisticsEnabled) Stmt::addStmtClass(SC);
1378 }
1379
1380 StmtClass getStmtClass() const {
1381 return static_cast<StmtClass>(StmtBits.sClass);
1382 }
1383
1384 const char *getStmtClassName() const;
1385
1386
1387
1388
1389 SourceRange getSourceRange() const LLVM_READONLY;
1390 SourceLocation getBeginLoc() const LLVM_READONLY;
1391 SourceLocation getEndLoc() const LLVM_READONLY;
1392
1393
1394 static void addStmtClass(const StmtClass s);
1395 static void EnableStatistics();
1396 static void PrintStats();
1397
1398
1399 static Likelihood getLikelihood(ArrayRef<const Attr *> Attrs);
1400
1401
1402 static Likelihood getLikelihood(const Stmt *S);
1403
1404
1405 static const Attr *getLikelihoodAttr(const Stmt *S);
1406
1407
1408
1409
1410 static Likelihood getLikelihood(const Stmt *Then, const Stmt *Else);
1411
1412
1413
1414
1415 static std::tuple<bool, const Attr *, const Attr *>
1416 determineLikelihoodConflict(const Stmt *Then, const Stmt *Else);
1417
1418
1419
1420 void dump() const;
1421 void dump(raw_ostream &OS, const ASTContext &Context) const;
1422
1423
1424 int64_t getID(const ASTContext &Context) const;
1425
1426
1427 void dumpColor() const;
1428
1429
1430
1431 void dumpPretty(const ASTContext &Context) const;
1432 void printPretty(raw_ostream &OS, PrinterHelper *Helper,
1433 const PrintingPolicy &Policy, unsigned Indentation = 0,
1434 StringRef NewlineSymbol = "\n",
1435 const ASTContext *Context = nullptr) const;
1436 void printPrettyControlled(raw_ostream &OS, PrinterHelper *Helper,
1437 const PrintingPolicy &Policy,
1438 unsigned Indentation = 0,
1439 StringRef NewlineSymbol = "\n",
1440 const ASTContext *Context = nullptr) const;
1441
1442
1443 void printJson(raw_ostream &Out, PrinterHelper *Helper,
1444 const PrintingPolicy &Policy, bool AddQuotes) const;
1445
1446
1447
1448 void viewAST() const;
1449
1450
1451
1452 Stmt *IgnoreContainers(bool IgnoreCaptured = false);
1453 const Stmt *IgnoreContainers(bool IgnoreCaptured = false) const {
1454 return const_cast<Stmt *>(this)->IgnoreContainers(IgnoreCaptured);
1455 }
1456
1457 const Stmt *stripLabelLikeStatements() const;
1458 Stmt *stripLabelLikeStatements() {
1459 return const_cast<Stmt*>(
1460 const_cast<const Stmt*>(this)->stripLabelLikeStatements());
1461 }
1462
1463
1464
1465
1466 using child_iterator = StmtIterator;
1467 using const_child_iterator = ConstStmtIterator;
1468
1469 using child_range = llvm::iterator_range<child_iterator>;
1470 using const_child_range = llvm::iterator_range<const_child_iterator>;
1471
1472 child_range children();
1473
1474 const_child_range children() const {
1475 auto Children = const_cast<Stmt *>(this)->children();
1476 return const_child_range(Children.begin(), Children.end());
1477 }
1478
1479 child_iterator child_begin() { return children().begin(); }
1480 child_iterator child_end() { return children().end(); }
1481
1482 const_child_iterator child_begin() const { return children().begin(); }
1483 const_child_iterator child_end() const { return children().end(); }
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
1503 bool Canonical, bool ProfileLambdaExpr = false) const;
1504
1505
1506
1507
1508
1509
1510
1511
1512 void ProcessODRHash(llvm::FoldingSetNodeID &ID, ODRHash& Hash) const;
1513 };
1514
1515
1516
1517
1518
1519 class DeclStmt : public Stmt {
1520 DeclGroupRef DG;
1521 SourceLocation StartLoc, EndLoc;
1522
1523 public:
1524 DeclStmt(DeclGroupRef dg, SourceLocation startLoc, SourceLocation endLoc)
1525 : Stmt(DeclStmtClass), DG(dg), StartLoc(startLoc), EndLoc(endLoc) {}
1526
1527
1528 explicit DeclStmt(EmptyShell Empty) : Stmt(DeclStmtClass, Empty) {}
1529
1530
1531
1532 bool isSingleDecl() const { return DG.isSingleDecl(); }
1533
1534 const Decl *getSingleDecl() const { return DG.getSingleDecl(); }
1535 Decl *getSingleDecl() { return DG.getSingleDecl(); }
1536
1537 const DeclGroupRef getDeclGroup() const { return DG; }
1538 DeclGroupRef getDeclGroup() { return DG; }
1539 void setDeclGroup(DeclGroupRef DGR) { DG = DGR; }
1540
1541 void setStartLoc(SourceLocation L) { StartLoc = L; }
1542 SourceLocation getEndLoc() const { return EndLoc; }
1543 void setEndLoc(SourceLocation L) { EndLoc = L; }
1544
1545 SourceLocation getBeginLoc() const LLVM_READONLY { return StartLoc; }
1546
1547 static bool classof(const Stmt *T) {
1548 return T->getStmtClass() == DeclStmtClass;
1549 }
1550
1551
1552 child_range children() {
1553 return child_range(child_iterator(DG.begin(), DG.end()),
1554 child_iterator(DG.end(), DG.end()));
1555 }
1556
1557 const_child_range children() const {
1558 auto Children = const_cast<DeclStmt *>(this)->children();
1559 return const_child_range(Children);
1560 }
1561
1562 using decl_iterator = DeclGroupRef::iterator;
1563 using const_decl_iterator = DeclGroupRef::const_iterator;
1564 using decl_range = llvm::iterator_range<decl_iterator>;
1565 using decl_const_range = llvm::iterator_range<const_decl_iterator>;
1566
1567 decl_range decls() { return decl_range(decl_begin(), decl_end()); }
1568
1569 decl_const_range decls() const {
1570 return decl_const_range(decl_begin(), decl_end());
1571 }
1572
1573 decl_iterator decl_begin() { return DG.begin(); }
1574 decl_iterator decl_end() { return DG.end(); }
1575 const_decl_iterator decl_begin() const { return DG.begin(); }
1576 const_decl_iterator decl_end() const { return DG.end(); }
1577
1578 using reverse_decl_iterator = std::reverse_iterator<decl_iterator>;
1579
1580 reverse_decl_iterator decl_rbegin() {
1581 return reverse_decl_iterator(decl_end());
1582 }
1583
1584 reverse_decl_iterator decl_rend() {
1585 return reverse_decl_iterator(decl_begin());
1586 }
1587 };
1588
1589
1590
1591 class NullStmt : public Stmt {
1592 public:
1593 NullStmt(SourceLocation L, bool hasLeadingEmptyMacro = false)
1594 : Stmt(NullStmtClass) {
1595 NullStmtBits.HasLeadingEmptyMacro = hasLeadingEmptyMacro;
1596 setSemiLoc(L);
1597 }
1598
1599
1600 explicit NullStmt(EmptyShell Empty) : Stmt(NullStmtClass, Empty) {}
1601
1602 SourceLocation getSemiLoc() const { return NullStmtBits.SemiLoc; }
1603 void setSemiLoc(SourceLocation L) { NullStmtBits.SemiLoc = L; }
1604
1605 bool hasLeadingEmptyMacro() const {
1606 return NullStmtBits.HasLeadingEmptyMacro;
1607 }
1608
1609 SourceLocation getBeginLoc() const { return getSemiLoc(); }
1610 SourceLocation getEndLoc() const { return getSemiLoc(); }
1611
1612 static bool classof(const Stmt *T) {
1613 return T->getStmtClass() == NullStmtClass;
1614 }
1615
1616 child_range children() {
1617 return child_range(child_iterator(), child_iterator());
1618 }
1619
1620 const_child_range children() const {
1621 return const_child_range(const_child_iterator(), const_child_iterator());
1622 }
1623 };
1624
1625
1626 class CompoundStmt final
1627 : public Stmt,
1628 private llvm::TrailingObjects<CompoundStmt, Stmt *, FPOptionsOverride> {
1629 friend class ASTStmtReader;
1630 friend TrailingObjects;
1631
1632
1633 SourceLocation LBraceLoc;
1634
1635
1636 SourceLocation RBraceLoc;
1637
1638 CompoundStmt(ArrayRef<Stmt *> Stmts, FPOptionsOverride FPFeatures,
1639 SourceLocation LB, SourceLocation RB);
1640 explicit CompoundStmt(EmptyShell Empty) : Stmt(CompoundStmtClass, Empty) {}
1641
1642 void setStmts(ArrayRef<Stmt *> Stmts);
1643
1644
1645 void setStoredFPFeatures(FPOptionsOverride F) {
1646 assert(hasStoredFPFeatures());
1647 *getTrailingObjects<FPOptionsOverride>() = F;
1648 }
1649
1650 size_t numTrailingObjects(OverloadToken<Stmt *>) const {
1651 return CompoundStmtBits.NumStmts;
1652 }
1653
1654 public:
1655 static CompoundStmt *Create(const ASTContext &C, ArrayRef<Stmt *> Stmts,
1656 FPOptionsOverride FPFeatures, SourceLocation LB,
1657 SourceLocation RB);
1658
1659
1660 explicit CompoundStmt(SourceLocation Loc) : CompoundStmt(Loc, Loc) {}
1661
1662 CompoundStmt(SourceLocation Loc, SourceLocation EndLoc)
1663 : Stmt(CompoundStmtClass), LBraceLoc(Loc), RBraceLoc(EndLoc) {
1664 CompoundStmtBits.NumStmts = 0;
1665 CompoundStmtBits.HasFPFeatures = 0;
1666 }
1667
1668
1669 static CompoundStmt *CreateEmpty(const ASTContext &C, unsigned NumStmts,
1670 bool HasFPFeatures);
1671
1672 bool body_empty() const { return CompoundStmtBits.NumStmts == 0; }
1673 unsigned size() const { return CompoundStmtBits.NumStmts; }
1674
1675 bool hasStoredFPFeatures() const { return CompoundStmtBits.HasFPFeatures; }
1676
1677
1678 FPOptionsOverride getStoredFPFeatures() const {
1679 assert(hasStoredFPFeatures());
1680 return *getTrailingObjects<FPOptionsOverride>();
1681 }
1682
1683
1684 FPOptionsOverride getStoredFPFeaturesOrDefault() const {
1685 return hasStoredFPFeatures() ? getStoredFPFeatures() : FPOptionsOverride();
1686 }
1687
1688 using body_iterator = Stmt **;
1689 using body_range = llvm::iterator_range<body_iterator>;
1690
1691 body_range body() { return body_range(body_begin(), body_end()); }
1692 body_iterator body_begin() { return getTrailingObjects<Stmt *>(); }
1693 body_iterator body_end() { return body_begin() + size(); }
1694 Stmt *body_front() { return !body_empty() ? body_begin()[0] : nullptr; }
1695
1696 Stmt *body_back() {
1697 return !body_empty() ? body_begin()[size() - 1] : nullptr;
1698 }
1699
1700 using const_body_iterator = Stmt *const *;
1701 using body_const_range = llvm::iterator_range<const_body_iterator>;
1702
1703 body_const_range body() const {
1704 return body_const_range(body_begin(), body_end());
1705 }
1706
1707 const_body_iterator body_begin() const {
1708 return getTrailingObjects<Stmt *>();
1709 }
1710
1711 const_body_iterator body_end() const { return body_begin() + size(); }
1712
1713 const Stmt *body_front() const {
1714 return !body_empty() ? body_begin()[0] : nullptr;
1715 }
1716
1717 const Stmt *body_back() const {
1718 return !body_empty() ? body_begin()[size() - 1] : nullptr;
1719 }
1720
1721 using reverse_body_iterator = std::reverse_iterator<body_iterator>;
1722
1723 reverse_body_iterator body_rbegin() {
1724 return reverse_body_iterator(body_end());
1725 }
1726
1727 reverse_body_iterator body_rend() {
1728 return reverse_body_iterator(body_begin());
1729 }
1730
1731 using const_reverse_body_iterator =
1732 std::reverse_iterator<const_body_iterator>;
1733
1734 const_reverse_body_iterator body_rbegin() const {
1735 return const_reverse_body_iterator(body_end());
1736 }
1737
1738 const_reverse_body_iterator body_rend() const {
1739 return const_reverse_body_iterator(body_begin());
1740 }
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750 Stmt *getStmtExprResult() {
1751 for (auto *B : llvm::reverse(body())) {
1752 if (!isa<NullStmt>(B))
1753 return B;
1754 }
1755 return body_back();
1756 }
1757
1758 const Stmt *getStmtExprResult() const {
1759 return const_cast<CompoundStmt *>(this)->getStmtExprResult();
1760 }
1761
1762 SourceLocation getBeginLoc() const { return LBraceLoc; }
1763 SourceLocation getEndLoc() const { return RBraceLoc; }
1764
1765 SourceLocation getLBracLoc() const { return LBraceLoc; }
1766 SourceLocation getRBracLoc() const { return RBraceLoc; }
1767
1768 static bool classof(const Stmt *T) {
1769 return T->getStmtClass() == CompoundStmtClass;
1770 }
1771
1772
1773 child_range children() { return child_range(body_begin(), body_end()); }
1774
1775 const_child_range children() const {
1776 return const_child_range(body_begin(), body_end());
1777 }
1778 };
1779
1780
1781 class SwitchCase : public Stmt {
1782 protected:
1783
1784 SourceLocation ColonLoc;
1785
1786
1787
1788
1789
1790
1791 SwitchCase *NextSwitchCase = nullptr;
1792
1793 SwitchCase(StmtClass SC, SourceLocation KWLoc, SourceLocation ColonLoc)
1794 : Stmt(SC), ColonLoc(ColonLoc) {
1795 setKeywordLoc(KWLoc);
1796 }
1797
1798 SwitchCase(StmtClass SC, EmptyShell) : Stmt(SC) {}
1799
1800 public:
1801 const SwitchCase *getNextSwitchCase() const { return NextSwitchCase; }
1802 SwitchCase *getNextSwitchCase() { return NextSwitchCase; }
1803 void setNextSwitchCase(SwitchCase *SC) { NextSwitchCase = SC; }
1804
1805 SourceLocation getKeywordLoc() const { return SwitchCaseBits.KeywordLoc; }
1806 void setKeywordLoc(SourceLocation L) { SwitchCaseBits.KeywordLoc = L; }
1807 SourceLocation getColonLoc() const { return ColonLoc; }
1808 void setColonLoc(SourceLocation L) { ColonLoc = L; }
1809
1810 inline Stmt *getSubStmt();
1811 const Stmt *getSubStmt() const {
1812 return const_cast<SwitchCase *>(this)->getSubStmt();
1813 }
1814
1815 SourceLocation getBeginLoc() const { return getKeywordLoc(); }
1816 inline SourceLocation getEndLoc() const LLVM_READONLY;
1817
1818 static bool classof(const Stmt *T) {
1819 return T->getStmtClass() == CaseStmtClass ||
1820 T->getStmtClass() == DefaultStmtClass;
1821 }
1822 };
1823
1824
1825
1826 class CaseStmt final
1827 : public SwitchCase,
1828 private llvm::TrailingObjects<CaseStmt, Stmt *, SourceLocation> {
1829 friend TrailingObjects;
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846 enum { LhsOffset = 0, SubStmtOffsetFromRhs = 1 };
1847 enum { NumMandatoryStmtPtr = 2 };
1848
1849 unsigned numTrailingObjects(OverloadToken<Stmt *>) const {
1850 return NumMandatoryStmtPtr + caseStmtIsGNURange();
1851 }
1852
1853 unsigned numTrailingObjects(OverloadToken<SourceLocation>) const {
1854 return caseStmtIsGNURange();
1855 }
1856
1857 unsigned lhsOffset() const { return LhsOffset; }
1858 unsigned rhsOffset() const { return LhsOffset + caseStmtIsGNURange(); }
1859 unsigned subStmtOffset() const { return rhsOffset() + SubStmtOffsetFromRhs; }
1860
1861
1862
1863 CaseStmt(Expr *lhs, Expr *rhs, SourceLocation caseLoc,
1864 SourceLocation ellipsisLoc, SourceLocation colonLoc)
1865 : SwitchCase(CaseStmtClass, caseLoc, colonLoc) {
1866
1867 bool IsGNURange = rhs != nullptr;
1868 SwitchCaseBits.CaseStmtIsGNURange = IsGNURange;
1869 setLHS(lhs);
1870 setSubStmt(nullptr);
1871 if (IsGNURange) {
1872 setRHS(rhs);
1873 setEllipsisLoc(ellipsisLoc);
1874 }
1875 }
1876
1877
1878 explicit CaseStmt(EmptyShell Empty, bool CaseStmtIsGNURange)
1879 : SwitchCase(CaseStmtClass, Empty) {
1880 SwitchCaseBits.CaseStmtIsGNURange = CaseStmtIsGNURange;
1881 }
1882
1883 public:
1884
1885 static CaseStmt *Create(const ASTContext &Ctx, Expr *lhs, Expr *rhs,
1886 SourceLocation caseLoc, SourceLocation ellipsisLoc,
1887 SourceLocation colonLoc);
1888
1889
1890 static CaseStmt *CreateEmpty(const ASTContext &Ctx, bool CaseStmtIsGNURange);
1891
1892
1893
1894
1895 bool caseStmtIsGNURange() const { return SwitchCaseBits.CaseStmtIsGNURange; }
1896
1897 SourceLocation getCaseLoc() const { return getKeywordLoc(); }
1898 void setCaseLoc(SourceLocation L) { setKeywordLoc(L); }
1899
1900
1901 SourceLocation getEllipsisLoc() const {
1902 return caseStmtIsGNURange() ? *getTrailingObjects<SourceLocation>()
1903 : SourceLocation();
1904 }
1905
1906
1907
1908 void setEllipsisLoc(SourceLocation L) {
1909 assert(
1910 caseStmtIsGNURange() &&
1911 "setEllipsisLoc but this is not a case stmt of the form LHS ... RHS!");
1912 *getTrailingObjects<SourceLocation>() = L;
1913 }
1914
1915 Expr *getLHS() {
1916 return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[lhsOffset()]);
1917 }
1918
1919 const Expr *getLHS() const {
1920 return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[lhsOffset()]);
1921 }
1922
1923 void setLHS(Expr *Val) {
1924 getTrailingObjects<Stmt *>()[lhsOffset()] = reinterpret_cast<Stmt *>(Val);
1925 }
1926
1927 Expr *getRHS() {
1928 return caseStmtIsGNURange() ? reinterpret_cast<Expr *>(
1929 getTrailingObjects<Stmt *>()[rhsOffset()])
1930 : nullptr;
1931 }
1932
1933 const Expr *getRHS() const {
1934 return caseStmtIsGNURange() ? reinterpret_cast<Expr *>(
1935 getTrailingObjects<Stmt *>()[rhsOffset()])
1936 : nullptr;
1937 }
1938
1939 void setRHS(Expr *Val) {
1940 assert(caseStmtIsGNURange() &&
1941 "setRHS but this is not a case stmt of the form LHS ... RHS!");
1942 getTrailingObjects<Stmt *>()[rhsOffset()] = reinterpret_cast<Stmt *>(Val);
1943 }
1944
1945 Stmt *getSubStmt() { return getTrailingObjects<Stmt *>()[subStmtOffset()]; }
1946 const Stmt *getSubStmt() const {
1947 return getTrailingObjects<Stmt *>()[subStmtOffset()];
1948 }
1949
1950 void setSubStmt(Stmt *S) {
1951 getTrailingObjects<Stmt *>()[subStmtOffset()] = S;
1952 }
1953
1954 SourceLocation getBeginLoc() const { return getKeywordLoc(); }
1955 SourceLocation getEndLoc() const LLVM_READONLY {
1956
1957 const CaseStmt *CS = this;
1958 while (const auto *CS2 = dyn_cast<CaseStmt>(CS->getSubStmt()))
1959 CS = CS2;
1960
1961 return CS->getSubStmt()->getEndLoc();
1962 }
1963
1964 static bool classof(const Stmt *T) {
1965 return T->getStmtClass() == CaseStmtClass;
1966 }
1967
1968
1969 child_range children() {
1970 return child_range(getTrailingObjects<Stmt *>(),
1971 getTrailingObjects<Stmt *>() +
1972 numTrailingObjects(OverloadToken<Stmt *>()));
1973 }
1974
1975 const_child_range children() const {
1976 return const_child_range(getTrailingObjects<Stmt *>(),
1977 getTrailingObjects<Stmt *>() +
1978 numTrailingObjects(OverloadToken<Stmt *>()));
1979 }
1980 };
1981
1982 class DefaultStmt : public SwitchCase {
1983 Stmt *SubStmt;
1984
1985 public:
1986 DefaultStmt(SourceLocation DL, SourceLocation CL, Stmt *substmt)
1987 : SwitchCase(DefaultStmtClass, DL, CL), SubStmt(substmt) {}
1988
1989
1990 explicit DefaultStmt(EmptyShell Empty)
1991 : SwitchCase(DefaultStmtClass, Empty) {}
1992
1993 Stmt *getSubStmt() { return SubStmt; }
1994 const Stmt *getSubStmt() const { return SubStmt; }
1995 void setSubStmt(Stmt *S) { SubStmt = S; }
1996
1997 SourceLocation getDefaultLoc() const { return getKeywordLoc(); }
1998 void setDefaultLoc(SourceLocation L) { setKeywordLoc(L); }
1999
2000 SourceLocation getBeginLoc() const { return getKeywordLoc(); }
2001 SourceLocation getEndLoc() const LLVM_READONLY {
2002 return SubStmt->getEndLoc();
2003 }
2004
2005 static bool classof(const Stmt *T) {
2006 return T->getStmtClass() == DefaultStmtClass;
2007 }
2008
2009
2010 child_range children() { return child_range(&SubStmt, &SubStmt + 1); }
2011
2012 const_child_range children() const {
2013 return const_child_range(&SubStmt, &SubStmt + 1);
2014 }
2015 };
2016
2017 SourceLocation SwitchCase::getEndLoc() const {
2018 if (const auto *CS = dyn_cast<CaseStmt>(this))
2019 return CS->getEndLoc();
2020 else if (const auto *DS = dyn_cast<DefaultStmt>(this))
2021 return DS->getEndLoc();
2022 llvm_unreachable("SwitchCase is neither a CaseStmt nor a DefaultStmt!");
2023 }
2024
2025 Stmt *SwitchCase::getSubStmt() {
2026 if (auto *CS = dyn_cast<CaseStmt>(this))
2027 return CS->getSubStmt();
2028 else if (auto *DS = dyn_cast<DefaultStmt>(this))
2029 return DS->getSubStmt();
2030 llvm_unreachable("SwitchCase is neither a CaseStmt nor a DefaultStmt!");
2031 }
2032
2033
2034
2035
2036
2037
2038
2039 class ValueStmt : public Stmt {
2040 protected:
2041 using Stmt::Stmt;
2042
2043 public:
2044 const Expr *getExprStmt() const;
2045 Expr *getExprStmt() {
2046 const ValueStmt *ConstThis = this;
2047 return const_cast<Expr*>(ConstThis->getExprStmt());
2048 }
2049
2050 static bool classof(const Stmt *T) {
2051 return T->getStmtClass() >= firstValueStmtConstant &&
2052 T->getStmtClass() <= lastValueStmtConstant;
2053 }
2054 };
2055
2056
2057
2058 class LabelStmt : public ValueStmt {
2059 LabelDecl *TheDecl;
2060 Stmt *SubStmt;
2061 bool SideEntry = false;
2062
2063 public:
2064
2065 LabelStmt(SourceLocation IL, LabelDecl *D, Stmt *substmt)
2066 : ValueStmt(LabelStmtClass), TheDecl(D), SubStmt(substmt) {
2067 setIdentLoc(IL);
2068 }
2069
2070
2071 explicit LabelStmt(EmptyShell Empty) : ValueStmt(LabelStmtClass, Empty) {}
2072
2073 SourceLocation getIdentLoc() const { return LabelStmtBits.IdentLoc; }
2074 void setIdentLoc(SourceLocation L) { LabelStmtBits.IdentLoc = L; }
2075
2076 LabelDecl *getDecl() const { return TheDecl; }
2077 void setDecl(LabelDecl *D) { TheDecl = D; }
2078
2079 const char *getName() const;
2080 Stmt *getSubStmt() { return SubStmt; }
2081
2082 const Stmt *getSubStmt() const { return SubStmt; }
2083 void setSubStmt(Stmt *SS) { SubStmt = SS; }
2084
2085 SourceLocation getBeginLoc() const { return getIdentLoc(); }
2086 SourceLocation getEndLoc() const LLVM_READONLY { return SubStmt->getEndLoc();}
2087
2088 child_range children() { return child_range(&SubStmt, &SubStmt + 1); }
2089
2090 const_child_range children() const {
2091 return const_child_range(&SubStmt, &SubStmt + 1);
2092 }
2093
2094 static bool classof(const Stmt *T) {
2095 return T->getStmtClass() == LabelStmtClass;
2096 }
2097 bool isSideEntry() const { return SideEntry; }
2098 void setSideEntry(bool SE) { SideEntry = SE; }
2099 };
2100
2101
2102
2103
2104
2105 class AttributedStmt final
2106 : public ValueStmt,
2107 private llvm::TrailingObjects<AttributedStmt, const Attr *> {
2108 friend class ASTStmtReader;
2109 friend TrailingObjects;
2110
2111 Stmt *SubStmt;
2112
2113 AttributedStmt(SourceLocation Loc, ArrayRef<const Attr *> Attrs,
2114 Stmt *SubStmt)
2115 : ValueStmt(AttributedStmtClass), SubStmt(SubStmt) {
2116 AttributedStmtBits.NumAttrs = Attrs.size();
2117 AttributedStmtBits.AttrLoc = Loc;
2118 std::copy(Attrs.begin(), Attrs.end(), getAttrArrayPtr());
2119 }
2120
2121 explicit AttributedStmt(EmptyShell Empty, unsigned NumAttrs)
2122 : ValueStmt(AttributedStmtClass, Empty) {
2123 AttributedStmtBits.NumAttrs = NumAttrs;
2124 AttributedStmtBits.AttrLoc = SourceLocation{};
2125 std::fill_n(getAttrArrayPtr(), NumAttrs, nullptr);
2126 }
2127
2128 const Attr *const *getAttrArrayPtr() const {
2129 return getTrailingObjects<const Attr *>();
2130 }
2131 const Attr **getAttrArrayPtr() { return getTrailingObjects<const Attr *>(); }
2132
2133 public:
2134 static AttributedStmt *Create(const ASTContext &C, SourceLocation Loc,
2135 ArrayRef<const Attr *> Attrs, Stmt *SubStmt);
2136
2137
2138 static AttributedStmt *CreateEmpty(const ASTContext &C, unsigned NumAttrs);
2139
2140 SourceLocation getAttrLoc() const { return AttributedStmtBits.AttrLoc; }
2141 ArrayRef<const Attr *> getAttrs() const {
2142 return llvm::ArrayRef(getAttrArrayPtr(), AttributedStmtBits.NumAttrs);
2143 }
2144
2145 Stmt *getSubStmt() { return SubStmt; }
2146 const Stmt *getSubStmt() const { return SubStmt; }
2147
2148 SourceLocation getBeginLoc() const { return getAttrLoc(); }
2149 SourceLocation getEndLoc() const LLVM_READONLY { return SubStmt->getEndLoc();}
2150
2151 child_range children() { return child_range(&SubStmt, &SubStmt + 1); }
2152
2153 const_child_range children() const {
2154 return const_child_range(&SubStmt, &SubStmt + 1);
2155 }
2156
2157 static bool classof(const Stmt *T) {
2158 return T->getStmtClass() == AttributedStmtClass;
2159 }
2160 };
2161
2162
2163 class IfStmt final
2164 : public Stmt,
2165 private llvm::TrailingObjects<IfStmt, Stmt *, SourceLocation> {
2166 friend TrailingObjects;
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190 enum { InitOffset = 0, ThenOffsetFromCond = 1, ElseOffsetFromCond = 2 };
2191 enum { NumMandatoryStmtPtr = 2 };
2192 SourceLocation LParenLoc;
2193 SourceLocation RParenLoc;
2194
2195 unsigned numTrailingObjects(OverloadToken<Stmt *>) const {
2196 return NumMandatoryStmtPtr + hasElseStorage() + hasVarStorage() +
2197 hasInitStorage();
2198 }
2199
2200 unsigned numTrailingObjects(OverloadToken<SourceLocation>) const {
2201 return hasElseStorage();
2202 }
2203
2204 unsigned initOffset() const { return InitOffset; }
2205 unsigned varOffset() const { return InitOffset + hasInitStorage(); }
2206 unsigned condOffset() const {
2207 return InitOffset + hasInitStorage() + hasVarStorage();
2208 }
2209 unsigned thenOffset() const { return condOffset() + ThenOffsetFromCond; }
2210 unsigned elseOffset() const { return condOffset() + ElseOffsetFromCond; }
2211
2212
2213 IfStmt(const ASTContext &Ctx, SourceLocation IL, IfStatementKind Kind,
2214 Stmt *Init, VarDecl *Var, Expr *Cond, SourceLocation LParenLoc,
2215 SourceLocation RParenLoc, Stmt *Then, SourceLocation EL, Stmt *Else);
2216
2217
2218 explicit IfStmt(EmptyShell Empty, bool HasElse, bool HasVar, bool HasInit);
2219
2220 public:
2221
2222 static IfStmt *Create(const ASTContext &Ctx, SourceLocation IL,
2223 IfStatementKind Kind, Stmt *Init, VarDecl *Var,
2224 Expr *Cond, SourceLocation LPL, SourceLocation RPL,
2225 Stmt *Then, SourceLocation EL = SourceLocation(),
2226 Stmt *Else = nullptr);
2227
2228
2229
2230 static IfStmt *CreateEmpty(const ASTContext &Ctx, bool HasElse, bool HasVar,
2231 bool HasInit);
2232
2233
2234 bool hasInitStorage() const { return IfStmtBits.HasInit; }
2235
2236
2237 bool hasVarStorage() const { return IfStmtBits.HasVar; }
2238
2239
2240 bool hasElseStorage() const { return IfStmtBits.HasElse; }
2241
2242 Expr *getCond() {
2243 return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[condOffset()]);
2244 }
2245
2246 const Expr *getCond() const {
2247 return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[condOffset()]);
2248 }
2249
2250 void setCond(Expr *Cond) {
2251 getTrailingObjects<Stmt *>()[condOffset()] = reinterpret_cast<Stmt *>(Cond);
2252 }
2253
2254 Stmt *getThen() { return getTrailingObjects<Stmt *>()[thenOffset()]; }
2255 const Stmt *getThen() const {
2256 return getTrailingObjects<Stmt *>()[thenOffset()];
2257 }
2258
2259 void setThen(Stmt *Then) {
2260 getTrailingObjects<Stmt *>()[thenOffset()] = Then;
2261 }
2262
2263 Stmt *getElse() {
2264 return hasElseStorage() ? getTrailingObjects<Stmt *>()[elseOffset()]
2265 : nullptr;
2266 }
2267
2268 const Stmt *getElse() const {
2269 return hasElseStorage() ? getTrailingObjects<Stmt *>()[elseOffset()]
2270 : nullptr;
2271 }
2272
2273 void setElse(Stmt *Else) {
2274 assert(hasElseStorage() &&
2275 "This if statement has no storage for an else statement!");
2276 getTrailingObjects<Stmt *>()[elseOffset()] = Else;
2277 }
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287 VarDecl *getConditionVariable();
2288 const VarDecl *getConditionVariable() const {
2289 return const_cast<IfStmt *>(this)->getConditionVariable();
2290 }
2291
2292
2293
2294 void setConditionVariable(const ASTContext &Ctx, VarDecl *V);
2295
2296
2297
2298 DeclStmt *getConditionVariableDeclStmt() {
2299 return hasVarStorage() ? static_cast<DeclStmt *>(
2300 getTrailingObjects<Stmt *>()[varOffset()])
2301 : nullptr;
2302 }
2303
2304 const DeclStmt *getConditionVariableDeclStmt() const {
2305 return hasVarStorage() ? static_cast<DeclStmt *>(
2306 getTrailingObjects<Stmt *>()[varOffset()])
2307 : nullptr;
2308 }
2309
2310 void setConditionVariableDeclStmt(DeclStmt *CondVar) {
2311 assert(hasVarStorage());
2312 getTrailingObjects<Stmt *>()[varOffset()] = CondVar;
2313 }
2314
2315 Stmt *getInit() {
2316 return hasInitStorage() ? getTrailingObjects<Stmt *>()[initOffset()]
2317 : nullptr;
2318 }
2319
2320 const Stmt *getInit() const {
2321 return hasInitStorage() ? getTrailingObjects<Stmt *>()[initOffset()]
2322 : nullptr;
2323 }
2324
2325 void setInit(Stmt *Init) {
2326 assert(hasInitStorage() &&
2327 "This if statement has no storage for an init statement!");
2328 getTrailingObjects<Stmt *>()[initOffset()] = Init;
2329 }
2330
2331 SourceLocation getIfLoc() const { return IfStmtBits.IfLoc; }
2332 void setIfLoc(SourceLocation IfLoc) { IfStmtBits.IfLoc = IfLoc; }
2333
2334 SourceLocation getElseLoc() const {
2335 return hasElseStorage() ? *getTrailingObjects<SourceLocation>()
2336 : SourceLocation();
2337 }
2338
2339 void setElseLoc(SourceLocation ElseLoc) {
2340 assert(hasElseStorage() &&
2341 "This if statement has no storage for an else statement!");
2342 *getTrailingObjects<SourceLocation>() = ElseLoc;
2343 }
2344
2345 bool isConsteval() const {
2346 return getStatementKind() == IfStatementKind::ConstevalNonNegated ||
2347 getStatementKind() == IfStatementKind::ConstevalNegated;
2348 }
2349
2350 bool isNonNegatedConsteval() const {
2351 return getStatementKind() == IfStatementKind::ConstevalNonNegated;
2352 }
2353
2354 bool isNegatedConsteval() const {
2355 return getStatementKind() == IfStatementKind::ConstevalNegated;
2356 }
2357
2358 bool isConstexpr() const {
2359 return getStatementKind() == IfStatementKind::Constexpr;
2360 }
2361
2362 void setStatementKind(IfStatementKind Kind) {
2363 IfStmtBits.Kind = static_cast<unsigned>(Kind);
2364 }
2365
2366 IfStatementKind getStatementKind() const {
2367 return static_cast<IfStatementKind>(IfStmtBits.Kind);
2368 }
2369
2370
2371
2372 std::optional<const Stmt *> getNondiscardedCase(const ASTContext &Ctx) const;
2373 std::optional<Stmt *> getNondiscardedCase(const ASTContext &Ctx);
2374
2375 bool isObjCAvailabilityCheck() const;
2376
2377 SourceLocation getBeginLoc() const { return getIfLoc(); }
2378 SourceLocation getEndLoc() const LLVM_READONLY {
2379 if (getElse())
2380 return getElse()->getEndLoc();
2381 return getThen()->getEndLoc();
2382 }
2383 SourceLocation getLParenLoc() const { return LParenLoc; }
2384 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
2385 SourceLocation getRParenLoc() const { return RParenLoc; }
2386 void setRParenLoc(SourceLocation Loc) { RParenLoc = Loc; }
2387
2388
2389
2390 child_range children() {
2391
2392
2393 return child_range(getTrailingObjects<Stmt *>() +
2394 (isConsteval() ? thenOffset() : 0),
2395 getTrailingObjects<Stmt *>() +
2396 numTrailingObjects(OverloadToken<Stmt *>()));
2397 }
2398
2399 const_child_range children() const {
2400
2401
2402 return const_child_range(getTrailingObjects<Stmt *>() +
2403 (isConsteval() ? thenOffset() : 0),
2404 getTrailingObjects<Stmt *>() +
2405 numTrailingObjects(OverloadToken<Stmt *>()));
2406 }
2407
2408 static bool classof(const Stmt *T) {
2409 return T->getStmtClass() == IfStmtClass;
2410 }
2411 };
2412
2413
2414 class SwitchStmt final : public Stmt,
2415 private llvm::TrailingObjects<SwitchStmt, Stmt *> {
2416 friend TrailingObjects;
2417
2418
2419 SwitchCase *FirstCase = nullptr;
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438 enum { InitOffset = 0, BodyOffsetFromCond = 1 };
2439 enum { NumMandatoryStmtPtr = 2 };
2440 SourceLocation LParenLoc;
2441 SourceLocation RParenLoc;
2442
2443 unsigned numTrailingObjects(OverloadToken<Stmt *>) const {
2444 return NumMandatoryStmtPtr + hasInitStorage() + hasVarStorage();
2445 }
2446
2447 unsigned initOffset() const { return InitOffset; }
2448 unsigned varOffset() const { return InitOffset + hasInitStorage(); }
2449 unsigned condOffset() const {
2450 return InitOffset + hasInitStorage() + hasVarStorage();
2451 }
2452 unsigned bodyOffset() const { return condOffset() + BodyOffsetFromCond; }
2453
2454
2455 SwitchStmt(const ASTContext &Ctx, Stmt *Init, VarDecl *Var, Expr *Cond,
2456 SourceLocation LParenLoc, SourceLocation RParenLoc);
2457
2458
2459 explicit SwitchStmt(EmptyShell Empty, bool HasInit, bool HasVar);
2460
2461 public:
2462
2463 static SwitchStmt *Create(const ASTContext &Ctx, Stmt *Init, VarDecl *Var,
2464 Expr *Cond, SourceLocation LParenLoc,
2465 SourceLocation RParenLoc);
2466
2467
2468
2469 static SwitchStmt *CreateEmpty(const ASTContext &Ctx, bool HasInit,
2470 bool HasVar);
2471
2472
2473 bool hasInitStorage() const { return SwitchStmtBits.HasInit; }
2474
2475
2476 bool hasVarStorage() const { return SwitchStmtBits.HasVar; }
2477
2478 Expr *getCond() {
2479 return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[condOffset()]);
2480 }
2481
2482 const Expr *getCond() const {
2483 return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[condOffset()]);
2484 }
2485
2486 void setCond(Expr *Cond) {
2487 getTrailingObjects<Stmt *>()[condOffset()] = reinterpret_cast<Stmt *>(Cond);
2488 }
2489
2490 Stmt *getBody() { return getTrailingObjects<Stmt *>()[bodyOffset()]; }
2491 const Stmt *getBody() const {
2492 return getTrailingObjects<Stmt *>()[bodyOffset()];
2493 }
2494
2495 void setBody(Stmt *Body) {
2496 getTrailingObjects<Stmt *>()[bodyOffset()] = Body;
2497 }
2498
2499 Stmt *getInit() {
2500 return hasInitStorage() ? getTrailingObjects<Stmt *>()[initOffset()]
2501 : nullptr;
2502 }
2503
2504 const Stmt *getInit() const {
2505 return hasInitStorage() ? getTrailingObjects<Stmt *>()[initOffset()]
2506 : nullptr;
2507 }
2508
2509 void setInit(Stmt *Init) {
2510 assert(hasInitStorage() &&
2511 "This switch statement has no storage for an init statement!");
2512 getTrailingObjects<Stmt *>()[initOffset()] = Init;
2513 }
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524 VarDecl *getConditionVariable();
2525 const VarDecl *getConditionVariable() const {
2526 return const_cast<SwitchStmt *>(this)->getConditionVariable();
2527 }
2528
2529
2530
2531 void setConditionVariable(const ASTContext &Ctx, VarDecl *VD);
2532
2533
2534
2535 DeclStmt *getConditionVariableDeclStmt() {
2536 return hasVarStorage() ? static_cast<DeclStmt *>(
2537 getTrailingObjects<Stmt *>()[varOffset()])
2538 : nullptr;
2539 }
2540
2541 const DeclStmt *getConditionVariableDeclStmt() const {
2542 return hasVarStorage() ? static_cast<DeclStmt *>(
2543 getTrailingObjects<Stmt *>()[varOffset()])
2544 : nullptr;
2545 }
2546
2547 void setConditionVariableDeclStmt(DeclStmt *CondVar) {
2548 assert(hasVarStorage());
2549 getTrailingObjects<Stmt *>()[varOffset()] = CondVar;
2550 }
2551
2552 SwitchCase *getSwitchCaseList() { return FirstCase; }
2553 const SwitchCase *getSwitchCaseList() const { return FirstCase; }
2554 void setSwitchCaseList(SwitchCase *SC) { FirstCase = SC; }
2555
2556 SourceLocation getSwitchLoc() const { return SwitchStmtBits.SwitchLoc; }
2557 void setSwitchLoc(SourceLocation L) { SwitchStmtBits.SwitchLoc = L; }
2558 SourceLocation getLParenLoc() const { return LParenLoc; }
2559 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
2560 SourceLocation getRParenLoc() const { return RParenLoc; }
2561 void setRParenLoc(SourceLocation Loc) { RParenLoc = Loc; }
2562
2563 void setBody(Stmt *S, SourceLocation SL) {
2564 setBody(S);
2565 setSwitchLoc(SL);
2566 }
2567
2568 void addSwitchCase(SwitchCase *SC) {
2569 assert(!SC->getNextSwitchCase() &&
2570 "case/default already added to a switch");
2571 SC->setNextSwitchCase(FirstCase);
2572 FirstCase = SC;
2573 }
2574
2575
2576
2577 void setAllEnumCasesCovered() { SwitchStmtBits.AllEnumCasesCovered = true; }
2578
2579
2580
2581 bool isAllEnumCasesCovered() const {
2582 return SwitchStmtBits.AllEnumCasesCovered;
2583 }
2584
2585 SourceLocation getBeginLoc() const { return getSwitchLoc(); }
2586 SourceLocation getEndLoc() const LLVM_READONLY {
2587 return getBody() ? getBody()->getEndLoc()
2588 : reinterpret_cast<const Stmt *>(getCond())->getEndLoc();
2589 }
2590
2591
2592 child_range children() {
2593 return child_range(getTrailingObjects<Stmt *>(),
2594 getTrailingObjects<Stmt *>() +
2595 numTrailingObjects(OverloadToken<Stmt *>()));
2596 }
2597
2598 const_child_range children() const {
2599 return const_child_range(getTrailingObjects<Stmt *>(),
2600 getTrailingObjects<Stmt *>() +
2601 numTrailingObjects(OverloadToken<Stmt *>()));
2602 }
2603
2604 static bool classof(const Stmt *T) {
2605 return T->getStmtClass() == SwitchStmtClass;
2606 }
2607 };
2608
2609
2610 class WhileStmt final : public Stmt,
2611 private llvm::TrailingObjects<WhileStmt, Stmt *> {
2612 friend TrailingObjects;
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629 enum { VarOffset = 0, BodyOffsetFromCond = 1 };
2630 enum { NumMandatoryStmtPtr = 2 };
2631
2632 SourceLocation LParenLoc, RParenLoc;
2633
2634 unsigned varOffset() const { return VarOffset; }
2635 unsigned condOffset() const { return VarOffset + hasVarStorage(); }
2636 unsigned bodyOffset() const { return condOffset() + BodyOffsetFromCond; }
2637
2638 unsigned numTrailingObjects(OverloadToken<Stmt *>) const {
2639 return NumMandatoryStmtPtr + hasVarStorage();
2640 }
2641
2642
2643 WhileStmt(const ASTContext &Ctx, VarDecl *Var, Expr *Cond, Stmt *Body,
2644 SourceLocation WL, SourceLocation LParenLoc,
2645 SourceLocation RParenLoc);
2646
2647
2648 explicit WhileStmt(EmptyShell Empty, bool HasVar);
2649
2650 public:
2651
2652 static WhileStmt *Create(const ASTContext &Ctx, VarDecl *Var, Expr *Cond,
2653 Stmt *Body, SourceLocation WL,
2654 SourceLocation LParenLoc, SourceLocation RParenLoc);
2655
2656
2657
2658 static WhileStmt *CreateEmpty(const ASTContext &Ctx, bool HasVar);
2659
2660
2661 bool hasVarStorage() const { return WhileStmtBits.HasVar; }
2662
2663 Expr *getCond() {
2664 return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[condOffset()]);
2665 }
2666
2667 const Expr *getCond() const {
2668 return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[condOffset()]);
2669 }
2670
2671 void setCond(Expr *Cond) {
2672 getTrailingObjects<Stmt *>()[condOffset()] = reinterpret_cast<Stmt *>(Cond);
2673 }
2674
2675 Stmt *getBody() { return getTrailingObjects<Stmt *>()[bodyOffset()]; }
2676 const Stmt *getBody() const {
2677 return getTrailingObjects<Stmt *>()[bodyOffset()];
2678 }
2679
2680 void setBody(Stmt *Body) {
2681 getTrailingObjects<Stmt *>()[bodyOffset()] = Body;
2682 }
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692 VarDecl *getConditionVariable();
2693 const VarDecl *getConditionVariable() const {
2694 return const_cast<WhileStmt *>(this)->getConditionVariable();
2695 }
2696
2697
2698
2699 void setConditionVariable(const ASTContext &Ctx, VarDecl *V);
2700
2701
2702
2703 DeclStmt *getConditionVariableDeclStmt() {
2704 return hasVarStorage() ? static_cast<DeclStmt *>(
2705 getTrailingObjects<Stmt *>()[varOffset()])
2706 : nullptr;
2707 }
2708
2709 const DeclStmt *getConditionVariableDeclStmt() const {
2710 return hasVarStorage() ? static_cast<DeclStmt *>(
2711 getTrailingObjects<Stmt *>()[varOffset()])
2712 : nullptr;
2713 }
2714
2715 void setConditionVariableDeclStmt(DeclStmt *CondVar) {
2716 assert(hasVarStorage());
2717 getTrailingObjects<Stmt *>()[varOffset()] = CondVar;
2718 }
2719
2720 SourceLocation getWhileLoc() const { return WhileStmtBits.WhileLoc; }
2721 void setWhileLoc(SourceLocation L) { WhileStmtBits.WhileLoc = L; }
2722
2723 SourceLocation getLParenLoc() const { return LParenLoc; }
2724 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2725 SourceLocation getRParenLoc() const { return RParenLoc; }
2726 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2727
2728 SourceLocation getBeginLoc() const { return getWhileLoc(); }
2729 SourceLocation getEndLoc() const LLVM_READONLY {
2730 return getBody()->getEndLoc();
2731 }
2732
2733 static bool classof(const Stmt *T) {
2734 return T->getStmtClass() == WhileStmtClass;
2735 }
2736
2737
2738 child_range children() {
2739 return child_range(getTrailingObjects<Stmt *>(),
2740 getTrailingObjects<Stmt *>() +
2741 numTrailingObjects(OverloadToken<Stmt *>()));
2742 }
2743
2744 const_child_range children() const {
2745 return const_child_range(getTrailingObjects<Stmt *>(),
2746 getTrailingObjects<Stmt *>() +
2747 numTrailingObjects(OverloadToken<Stmt *>()));
2748 }
2749 };
2750
2751
2752 class DoStmt : public Stmt {
2753 enum { BODY, COND, END_EXPR };
2754 Stmt *SubExprs[END_EXPR];
2755 SourceLocation WhileLoc;
2756 SourceLocation RParenLoc;
2757
2758 public:
2759 DoStmt(Stmt *Body, Expr *Cond, SourceLocation DL, SourceLocation WL,
2760 SourceLocation RP)
2761 : Stmt(DoStmtClass), WhileLoc(WL), RParenLoc(RP) {
2762 setCond(Cond);
2763 setBody(Body);
2764 setDoLoc(DL);
2765 }
2766
2767
2768 explicit DoStmt(EmptyShell Empty) : Stmt(DoStmtClass, Empty) {}
2769
2770 Expr *getCond() { return reinterpret_cast<Expr *>(SubExprs[COND]); }
2771 const Expr *getCond() const {
2772 return reinterpret_cast<Expr *>(SubExprs[COND]);
2773 }
2774
2775 void setCond(Expr *Cond) { SubExprs[COND] = reinterpret_cast<Stmt *>(Cond); }
2776
2777 Stmt *getBody() { return SubExprs[BODY]; }
2778 const Stmt *getBody() const { return SubExprs[BODY]; }
2779 void setBody(Stmt *Body) { SubExprs[BODY] = Body; }
2780
2781 SourceLocation getDoLoc() const { return DoStmtBits.DoLoc; }
2782 void setDoLoc(SourceLocation L) { DoStmtBits.DoLoc = L; }
2783 SourceLocation getWhileLoc() const { return WhileLoc; }
2784 void setWhileLoc(SourceLocation L) { WhileLoc = L; }
2785 SourceLocation getRParenLoc() const { return RParenLoc; }
2786 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2787
2788 SourceLocation getBeginLoc() const { return getDoLoc(); }
2789 SourceLocation getEndLoc() const { return getRParenLoc(); }
2790
2791 static bool classof(const Stmt *T) {
2792 return T->getStmtClass() == DoStmtClass;
2793 }
2794
2795
2796 child_range children() {
2797 return child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
2798 }
2799
2800 const_child_range children() const {
2801 return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
2802 }
2803 };
2804
2805
2806
2807
2808 class ForStmt : public Stmt {
2809 friend class ASTStmtReader;
2810
2811 enum { INIT, CONDVAR, COND, INC, BODY, END_EXPR };
2812 Stmt* SubExprs[END_EXPR];
2813 SourceLocation LParenLoc, RParenLoc;
2814
2815 public:
2816 ForStmt(const ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar,
2817 Expr *Inc, Stmt *Body, SourceLocation FL, SourceLocation LP,
2818 SourceLocation RP);
2819
2820
2821 explicit ForStmt(EmptyShell Empty) : Stmt(ForStmtClass, Empty) {}
2822
2823 Stmt *getInit() { return SubExprs[INIT]; }
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833 VarDecl *getConditionVariable() const;
2834 void setConditionVariable(const ASTContext &C, VarDecl *V);
2835
2836
2837
2838 DeclStmt *getConditionVariableDeclStmt() {
2839 return reinterpret_cast<DeclStmt*>(SubExprs[CONDVAR]);
2840 }
2841
2842 const DeclStmt *getConditionVariableDeclStmt() const {
2843 return reinterpret_cast<DeclStmt*>(SubExprs[CONDVAR]);
2844 }
2845
2846 void setConditionVariableDeclStmt(DeclStmt *CondVar) {
2847 SubExprs[CONDVAR] = CondVar;
2848 }
2849
2850 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
2851 Expr *getInc() { return reinterpret_cast<Expr*>(SubExprs[INC]); }
2852 Stmt *getBody() { return SubExprs[BODY]; }
2853
2854 const Stmt *getInit() const { return SubExprs[INIT]; }
2855 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
2856 const Expr *getInc() const { return reinterpret_cast<Expr*>(SubExprs[INC]); }
2857 const Stmt *getBody() const { return SubExprs[BODY]; }
2858
2859 void setInit(Stmt *S) { SubExprs[INIT] = S; }
2860 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
2861 void setInc(Expr *E) { SubExprs[INC] = reinterpret_cast<Stmt*>(E); }
2862 void setBody(Stmt *S) { SubExprs[BODY] = S; }
2863
2864 SourceLocation getForLoc() const { return ForStmtBits.ForLoc; }
2865 void setForLoc(SourceLocation L) { ForStmtBits.ForLoc = L; }
2866 SourceLocation getLParenLoc() const { return LParenLoc; }
2867 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2868 SourceLocation getRParenLoc() const { return RParenLoc; }
2869 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2870
2871 SourceLocation getBeginLoc() const { return getForLoc(); }
2872 SourceLocation getEndLoc() const { return getBody()->getEndLoc(); }
2873
2874 static bool classof(const Stmt *T) {
2875 return T->getStmtClass() == ForStmtClass;
2876 }
2877
2878
2879 child_range children() {
2880 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
2881 }
2882
2883 const_child_range children() const {
2884 return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
2885 }
2886 };
2887
2888
2889 class GotoStmt : public Stmt {
2890 LabelDecl *Label;
2891 SourceLocation LabelLoc;
2892
2893 public:
2894 GotoStmt(LabelDecl *label, SourceLocation GL, SourceLocation LL)
2895 : Stmt(GotoStmtClass), Label(label), LabelLoc(LL) {
2896 setGotoLoc(GL);
2897 }
2898
2899
2900 explicit GotoStmt(EmptyShell Empty) : Stmt(GotoStmtClass, Empty) {}
2901
2902 LabelDecl *getLabel() const { return Label; }
2903 void setLabel(LabelDecl *D) { Label = D; }
2904
2905 SourceLocation getGotoLoc() const { return GotoStmtBits.GotoLoc; }
2906 void setGotoLoc(SourceLocation L) { GotoStmtBits.GotoLoc = L; }
2907 SourceLocation getLabelLoc() const { return LabelLoc; }
2908 void setLabelLoc(SourceLocation L) { LabelLoc = L; }
2909
2910 SourceLocation getBeginLoc() const { return getGotoLoc(); }
2911 SourceLocation getEndLoc() const { return getLabelLoc(); }
2912
2913 static bool classof(const Stmt *T) {
2914 return T->getStmtClass() == GotoStmtClass;
2915 }
2916
2917
2918 child_range children() {
2919 return child_range(child_iterator(), child_iterator());
2920 }
2921
2922 const_child_range children() const {
2923 return const_child_range(const_child_iterator(), const_child_iterator());
2924 }
2925 };
2926
2927
2928 class IndirectGotoStmt : public Stmt {
2929 SourceLocation StarLoc;
2930 Stmt *Target;
2931
2932 public:
2933 IndirectGotoStmt(SourceLocation gotoLoc, SourceLocation starLoc, Expr *target)
2934 : Stmt(IndirectGotoStmtClass), StarLoc(starLoc) {
2935 setTarget(target);
2936 setGotoLoc(gotoLoc);
2937 }
2938
2939
2940 explicit IndirectGotoStmt(EmptyShell Empty)
2941 : Stmt(IndirectGotoStmtClass, Empty) {}
2942
2943 void setGotoLoc(SourceLocation L) { GotoStmtBits.GotoLoc = L; }
2944 SourceLocation getGotoLoc() const { return GotoStmtBits.GotoLoc; }
2945 void setStarLoc(SourceLocation L) { StarLoc = L; }
2946 SourceLocation getStarLoc() const { return StarLoc; }
2947
2948 Expr *getTarget() { return reinterpret_cast<Expr *>(Target); }
2949 const Expr *getTarget() const {
2950 return reinterpret_cast<const Expr *>(Target);
2951 }
2952 void setTarget(Expr *E) { Target = reinterpret_cast<Stmt *>(E); }
2953
2954
2955
2956 LabelDecl *getConstantTarget();
2957 const LabelDecl *getConstantTarget() const {
2958 return const_cast<IndirectGotoStmt *>(this)->getConstantTarget();
2959 }
2960
2961 SourceLocation getBeginLoc() const { return getGotoLoc(); }
2962 SourceLocation getEndLoc() const LLVM_READONLY { return Target->getEndLoc(); }
2963
2964 static bool classof(const Stmt *T) {
2965 return T->getStmtClass() == IndirectGotoStmtClass;
2966 }
2967
2968
2969 child_range children() { return child_range(&Target, &Target + 1); }
2970
2971 const_child_range children() const {
2972 return const_child_range(&Target, &Target + 1);
2973 }
2974 };
2975
2976
2977 class ContinueStmt : public Stmt {
2978 public:
2979 ContinueStmt(SourceLocation CL) : Stmt(ContinueStmtClass) {
2980 setContinueLoc(CL);
2981 }
2982
2983
2984 explicit ContinueStmt(EmptyShell Empty) : Stmt(ContinueStmtClass, Empty) {}
2985
2986 SourceLocation getContinueLoc() const { return ContinueStmtBits.ContinueLoc; }
2987 void setContinueLoc(SourceLocation L) { ContinueStmtBits.ContinueLoc = L; }
2988
2989 SourceLocation getBeginLoc() const { return getContinueLoc(); }
2990 SourceLocation getEndLoc() const { return getContinueLoc(); }
2991
2992 static bool classof(const Stmt *T) {
2993 return T->getStmtClass() == ContinueStmtClass;
2994 }
2995
2996
2997 child_range children() {
2998 return child_range(child_iterator(), child_iterator());
2999 }
3000
3001 const_child_range children() const {
3002 return const_child_range(const_child_iterator(), const_child_iterator());
3003 }
3004 };
3005
3006
3007 class BreakStmt : public Stmt {
3008 public:
3009 BreakStmt(SourceLocation BL) : Stmt(BreakStmtClass) {
3010 setBreakLoc(BL);
3011 }
3012
3013
3014 explicit BreakStmt(EmptyShell Empty) : Stmt(BreakStmtClass, Empty) {}
3015
3016 SourceLocation getBreakLoc() const { return BreakStmtBits.BreakLoc; }
3017 void setBreakLoc(SourceLocation L) { BreakStmtBits.BreakLoc = L; }
3018
3019 SourceLocation getBeginLoc() const { return getBreakLoc(); }
3020 SourceLocation getEndLoc() const { return getBreakLoc(); }
3021
3022 static bool classof(const Stmt *T) {
3023 return T->getStmtClass() == BreakStmtClass;
3024 }
3025
3026
3027 child_range children() {
3028 return child_range(child_iterator(), child_iterator());
3029 }
3030
3031 const_child_range children() const {
3032 return const_child_range(const_child_iterator(), const_child_iterator());
3033 }
3034 };
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044 class ReturnStmt final
3045 : public Stmt,
3046 private llvm::TrailingObjects<ReturnStmt, const VarDecl *> {
3047 friend TrailingObjects;
3048
3049
3050 Stmt *RetExpr;
3051
3052
3053
3054
3055
3056 bool hasNRVOCandidate() const { return ReturnStmtBits.HasNRVOCandidate; }
3057
3058 unsigned numTrailingObjects(OverloadToken<const VarDecl *>) const {
3059 return hasNRVOCandidate();
3060 }
3061
3062
3063 ReturnStmt(SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate);
3064
3065
3066 explicit ReturnStmt(EmptyShell Empty, bool HasNRVOCandidate);
3067
3068 public:
3069
3070 static ReturnStmt *Create(const ASTContext &Ctx, SourceLocation RL, Expr *E,
3071 const VarDecl *NRVOCandidate);
3072
3073
3074
3075 static ReturnStmt *CreateEmpty(const ASTContext &Ctx, bool HasNRVOCandidate);
3076
3077 Expr *getRetValue() { return reinterpret_cast<Expr *>(RetExpr); }
3078 const Expr *getRetValue() const { return reinterpret_cast<Expr *>(RetExpr); }
3079 void setRetValue(Expr *E) { RetExpr = reinterpret_cast<Stmt *>(E); }
3080
3081
3082
3083
3084
3085
3086 const VarDecl *getNRVOCandidate() const {
3087 return hasNRVOCandidate() ? *getTrailingObjects<const VarDecl *>()
3088 : nullptr;
3089 }
3090
3091
3092
3093
3094 void setNRVOCandidate(const VarDecl *Var) {
3095 assert(hasNRVOCandidate() &&
3096 "This return statement has no storage for an NRVO candidate!");
3097 *getTrailingObjects<const VarDecl *>() = Var;
3098 }
3099
3100 SourceLocation getReturnLoc() const { return ReturnStmtBits.RetLoc; }
3101 void setReturnLoc(SourceLocation L) { ReturnStmtBits.RetLoc = L; }
3102
3103 SourceLocation getBeginLoc() const { return getReturnLoc(); }
3104 SourceLocation getEndLoc() const LLVM_READONLY {
3105 return RetExpr ? RetExpr->getEndLoc() : getReturnLoc();
3106 }
3107
3108 static bool classof(const Stmt *T) {
3109 return T->getStmtClass() == ReturnStmtClass;
3110 }
3111
3112
3113 child_range children() {
3114 if (RetExpr)
3115 return child_range(&RetExpr, &RetExpr + 1);
3116 return child_range(child_iterator(), child_iterator());
3117 }
3118
3119 const_child_range children() const {
3120 if (RetExpr)
3121 return const_child_range(&RetExpr, &RetExpr + 1);
3122 return const_child_range(const_child_iterator(), const_child_iterator());
3123 }
3124 };
3125
3126
3127 class AsmStmt : public Stmt {
3128 protected:
3129 friend class ASTStmtReader;
3130
3131 SourceLocation AsmLoc;
3132
3133
3134
3135 bool IsSimple;
3136
3137
3138
3139 bool IsVolatile;
3140
3141 unsigned NumOutputs;
3142 unsigned NumInputs;
3143 unsigned NumClobbers;
3144
3145 Stmt **Exprs = nullptr;
3146
3147 AsmStmt(StmtClass SC, SourceLocation asmloc, bool issimple, bool isvolatile,
3148 unsigned numoutputs, unsigned numinputs, unsigned numclobbers)
3149 : Stmt (SC), AsmLoc(asmloc), IsSimple(issimple), IsVolatile(isvolatile),
3150 NumOutputs(numoutputs), NumInputs(numinputs),
3151 NumClobbers(numclobbers) {}
3152
3153 public:
3154
3155 explicit AsmStmt(StmtClass SC, EmptyShell Empty) : Stmt(SC, Empty) {}
3156
3157 SourceLocation getAsmLoc() const { return AsmLoc; }
3158 void setAsmLoc(SourceLocation L) { AsmLoc = L; }
3159
3160 bool isSimple() const { return IsSimple; }
3161 void setSimple(bool V) { IsSimple = V; }
3162
3163 bool isVolatile() const { return IsVolatile; }
3164 void setVolatile(bool V) { IsVolatile = V; }
3165
3166 SourceLocation getBeginLoc() const LLVM_READONLY { return {}; }
3167 SourceLocation getEndLoc() const LLVM_READONLY { return {}; }
3168
3169
3170
3171
3172 std::string generateAsmString(const ASTContext &C) const;
3173
3174
3175
3176 unsigned getNumOutputs() const { return NumOutputs; }
3177
3178
3179
3180
3181 StringRef getOutputConstraint(unsigned i) const;
3182
3183
3184
3185
3186 bool isOutputPlusConstraint(unsigned i) const {
3187 return getOutputConstraint(i)[0] == '+';
3188 }
3189
3190 const Expr *getOutputExpr(unsigned i) const;
3191
3192
3193
3194 unsigned getNumPlusOperands() const;
3195
3196
3197
3198 unsigned getNumInputs() const { return NumInputs; }
3199
3200
3201
3202 StringRef getInputConstraint(unsigned i) const;
3203
3204 const Expr *getInputExpr(unsigned i) const;
3205
3206
3207
3208 unsigned getNumClobbers() const { return NumClobbers; }
3209 StringRef getClobber(unsigned i) const;
3210
3211 static bool classof(const Stmt *T) {
3212 return T->getStmtClass() == GCCAsmStmtClass ||
3213 T->getStmtClass() == MSAsmStmtClass;
3214 }
3215
3216
3217
3218 using inputs_iterator = ExprIterator;
3219 using const_inputs_iterator = ConstExprIterator;
3220 using inputs_range = llvm::iterator_range<inputs_iterator>;
3221 using inputs_const_range = llvm::iterator_range<const_inputs_iterator>;
3222
3223 inputs_iterator begin_inputs() {
3224 return &Exprs[0] + NumOutputs;
3225 }
3226
3227 inputs_iterator end_inputs() {
3228 return &Exprs[0] + NumOutputs + NumInputs;
3229 }
3230
3231 inputs_range inputs() { return inputs_range(begin_inputs(), end_inputs()); }
3232
3233 const_inputs_iterator begin_inputs() const {
3234 return &Exprs[0] + NumOutputs;
3235 }
3236
3237 const_inputs_iterator end_inputs() const {
3238 return &Exprs[0] + NumOutputs + NumInputs;
3239 }
3240
3241 inputs_const_range inputs() const {
3242 return inputs_const_range(begin_inputs(), end_inputs());
3243 }
3244
3245
3246
3247 using outputs_iterator = ExprIterator;
3248 using const_outputs_iterator = ConstExprIterator;
3249 using outputs_range = llvm::iterator_range<outputs_iterator>;
3250 using outputs_const_range = llvm::iterator_range<const_outputs_iterator>;
3251
3252 outputs_iterator begin_outputs() {
3253 return &Exprs[0];
3254 }
3255
3256 outputs_iterator end_outputs() {
3257 return &Exprs[0] + NumOutputs;
3258 }
3259
3260 outputs_range outputs() {
3261 return outputs_range(begin_outputs(), end_outputs());
3262 }
3263
3264 const_outputs_iterator begin_outputs() const {
3265 return &Exprs[0];
3266 }
3267
3268 const_outputs_iterator end_outputs() const {
3269 return &Exprs[0] + NumOutputs;
3270 }
3271
3272 outputs_const_range outputs() const {
3273 return outputs_const_range(begin_outputs(), end_outputs());
3274 }
3275
3276 child_range children() {
3277 return child_range(&Exprs[0], &Exprs[0] + NumOutputs + NumInputs);
3278 }
3279
3280 const_child_range children() const {
3281 return const_child_range(&Exprs[0], &Exprs[0] + NumOutputs + NumInputs);
3282 }
3283 };
3284
3285
3286 class GCCAsmStmt : public AsmStmt {
3287 friend class ASTStmtReader;
3288
3289 SourceLocation RParenLoc;
3290 StringLiteral *AsmStr;
3291
3292
3293 StringLiteral **Constraints = nullptr;
3294 StringLiteral **Clobbers = nullptr;
3295 IdentifierInfo **Names = nullptr;
3296 unsigned NumLabels = 0;
3297
3298 public:
3299 GCCAsmStmt(const ASTContext &C, SourceLocation asmloc, bool issimple,
3300 bool isvolatile, unsigned numoutputs, unsigned numinputs,
3301 IdentifierInfo **names, StringLiteral **constraints, Expr **exprs,
3302 StringLiteral *asmstr, unsigned numclobbers,
3303 StringLiteral **clobbers, unsigned numlabels,
3304 SourceLocation rparenloc);
3305
3306
3307 explicit GCCAsmStmt(EmptyShell Empty) : AsmStmt(GCCAsmStmtClass, Empty) {}
3308
3309 SourceLocation getRParenLoc() const { return RParenLoc; }
3310 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
3311
3312
3313
3314 const StringLiteral *getAsmString() const { return AsmStr; }
3315 StringLiteral *getAsmString() { return AsmStr; }
3316 void setAsmString(StringLiteral *E) { AsmStr = E; }
3317
3318
3319
3320
3321 class AsmStringPiece {
3322 public:
3323 enum Kind {
3324 String,
3325 Operand
3326 };
3327
3328 private:
3329 Kind MyKind;
3330 std::string Str;
3331 unsigned OperandNo;
3332
3333
3334 CharSourceRange Range;
3335
3336 public:
3337 AsmStringPiece(const std::string &S) : MyKind(String), Str(S) {}
3338 AsmStringPiece(unsigned OpNo, const std::string &S, SourceLocation Begin,
3339 SourceLocation End)
3340 : MyKind(Operand), Str(S), OperandNo(OpNo),
3341 Range(CharSourceRange::getCharRange(Begin, End)) {}
3342
3343 bool isString() const { return MyKind == String; }
3344 bool isOperand() const { return MyKind == Operand; }
3345
3346 const std::string &getString() const { return Str; }
3347
3348 unsigned getOperandNo() const {
3349 assert(isOperand());
3350 return OperandNo;
3351 }
3352
3353 CharSourceRange getRange() const {
3354 assert(isOperand() && "Range is currently used only for Operands.");
3355 return Range;
3356 }
3357
3358
3359
3360 char getModifier() const;
3361 };
3362
3363
3364
3365
3366
3367
3368 unsigned AnalyzeAsmString(SmallVectorImpl<AsmStringPiece> &Pieces,
3369 const ASTContext &C, unsigned &DiagOffs) const;
3370
3371
3372 std::string generateAsmString(const ASTContext &C) const;
3373
3374
3375
3376 IdentifierInfo *getOutputIdentifier(unsigned i) const { return Names[i]; }
3377
3378 StringRef getOutputName(unsigned i) const {
3379 if (IdentifierInfo *II = getOutputIdentifier(i))
3380 return II->getName();
3381
3382 return {};
3383 }
3384
3385 StringRef getOutputConstraint(unsigned i) const;
3386
3387 const StringLiteral *getOutputConstraintLiteral(unsigned i) const {
3388 return Constraints[i];
3389 }
3390 StringLiteral *getOutputConstraintLiteral(unsigned i) {
3391 return Constraints[i];
3392 }
3393
3394 Expr *getOutputExpr(unsigned i);
3395
3396 const Expr *getOutputExpr(unsigned i) const {
3397 return const_cast<GCCAsmStmt*>(this)->getOutputExpr(i);
3398 }
3399
3400
3401
3402 IdentifierInfo *getInputIdentifier(unsigned i) const {
3403 return Names[i + NumOutputs];
3404 }
3405
3406 StringRef getInputName(unsigned i) const {
3407 if (IdentifierInfo *II = getInputIdentifier(i))
3408 return II->getName();
3409
3410 return {};
3411 }
3412
3413 StringRef getInputConstraint(unsigned i) const;
3414
3415 const StringLiteral *getInputConstraintLiteral(unsigned i) const {
3416 return Constraints[i + NumOutputs];
3417 }
3418 StringLiteral *getInputConstraintLiteral(unsigned i) {
3419 return Constraints[i + NumOutputs];
3420 }
3421
3422 Expr *getInputExpr(unsigned i);
3423 void setInputExpr(unsigned i, Expr *E);
3424
3425 const Expr *getInputExpr(unsigned i) const {
3426 return const_cast<GCCAsmStmt*>(this)->getInputExpr(i);
3427 }
3428
3429
3430
3431 bool isAsmGoto() const {
3432 return NumLabels > 0;
3433 }
3434
3435 unsigned getNumLabels() const {
3436 return NumLabels;
3437 }
3438
3439 IdentifierInfo *getLabelIdentifier(unsigned i) const {
3440 return Names[i + NumOutputs + NumInputs];
3441 }
3442
3443 AddrLabelExpr *getLabelExpr(unsigned i) const;
3444 StringRef getLabelName(unsigned i) const;
3445 using labels_iterator = CastIterator<AddrLabelExpr>;
3446 using const_labels_iterator = ConstCastIterator<AddrLabelExpr>;
3447 using labels_range = llvm::iterator_range<labels_iterator>;
3448 using labels_const_range = llvm::iterator_range<const_labels_iterator>;
3449
3450 labels_iterator begin_labels() {
3451 return &Exprs[0] + NumOutputs + NumInputs;
3452 }
3453
3454 labels_iterator end_labels() {
3455 return &Exprs[0] + NumOutputs + NumInputs + NumLabels;
3456 }
3457
3458 labels_range labels() {
3459 return labels_range(begin_labels(), end_labels());
3460 }
3461
3462 const_labels_iterator begin_labels() const {
3463 return &Exprs[0] + NumOutputs + NumInputs;
3464 }
3465
3466 const_labels_iterator end_labels() const {
3467 return &Exprs[0] + NumOutputs + NumInputs + NumLabels;
3468 }
3469
3470 labels_const_range labels() const {
3471 return labels_const_range(begin_labels(), end_labels());
3472 }
3473
3474 private:
3475 void setOutputsAndInputsAndClobbers(const ASTContext &C,
3476 IdentifierInfo **Names,
3477 StringLiteral **Constraints,
3478 Stmt **Exprs,
3479 unsigned NumOutputs,
3480 unsigned NumInputs,
3481 unsigned NumLabels,
3482 StringLiteral **Clobbers,
3483 unsigned NumClobbers);
3484
3485 public:
3486
3487
3488
3489
3490
3491 int getNamedOperand(StringRef SymbolicName) const;
3492
3493 StringRef getClobber(unsigned i) const;
3494
3495 StringLiteral *getClobberStringLiteral(unsigned i) { return Clobbers[i]; }
3496 const StringLiteral *getClobberStringLiteral(unsigned i) const {
3497 return Clobbers[i];
3498 }
3499
3500 SourceLocation getBeginLoc() const LLVM_READONLY { return AsmLoc; }
3501 SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
3502
3503 static bool classof(const Stmt *T) {
3504 return T->getStmtClass() == GCCAsmStmtClass;
3505 }
3506 };
3507
3508
3509 class MSAsmStmt : public AsmStmt {
3510 friend class ASTStmtReader;
3511
3512 SourceLocation LBraceLoc, EndLoc;
3513 StringRef AsmStr;
3514
3515 unsigned NumAsmToks = 0;
3516
3517 Token *AsmToks = nullptr;
3518 StringRef *Constraints = nullptr;
3519 StringRef *Clobbers = nullptr;
3520
3521 public:
3522 MSAsmStmt(const ASTContext &C, SourceLocation asmloc,
3523 SourceLocation lbraceloc, bool issimple, bool isvolatile,
3524 ArrayRef<Token> asmtoks, unsigned numoutputs, unsigned numinputs,
3525 ArrayRef<StringRef> constraints,
3526 ArrayRef<Expr*> exprs, StringRef asmstr,
3527 ArrayRef<StringRef> clobbers, SourceLocation endloc);
3528
3529
3530 explicit MSAsmStmt(EmptyShell Empty) : AsmStmt(MSAsmStmtClass, Empty) {}
3531
3532 SourceLocation getLBraceLoc() const { return LBraceLoc; }
3533 void setLBraceLoc(SourceLocation L) { LBraceLoc = L; }
3534 SourceLocation getEndLoc() const { return EndLoc; }
3535 void setEndLoc(SourceLocation L) { EndLoc = L; }
3536
3537 bool hasBraces() const { return LBraceLoc.isValid(); }
3538
3539 unsigned getNumAsmToks() { return NumAsmToks; }
3540 Token *getAsmToks() { return AsmToks; }
3541
3542
3543 StringRef getAsmString() const { return AsmStr; }
3544
3545
3546 std::string generateAsmString(const ASTContext &C) const;
3547
3548
3549
3550 StringRef getOutputConstraint(unsigned i) const {
3551 assert(i < NumOutputs);
3552 return Constraints[i];
3553 }
3554
3555 Expr *getOutputExpr(unsigned i);
3556
3557 const Expr *getOutputExpr(unsigned i) const {
3558 return const_cast<MSAsmStmt*>(this)->getOutputExpr(i);
3559 }
3560
3561
3562
3563 StringRef getInputConstraint(unsigned i) const {
3564 assert(i < NumInputs);
3565 return Constraints[i + NumOutputs];
3566 }
3567
3568 Expr *getInputExpr(unsigned i);
3569 void setInputExpr(unsigned i, Expr *E);
3570
3571 const Expr *getInputExpr(unsigned i) const {
3572 return const_cast<MSAsmStmt*>(this)->getInputExpr(i);
3573 }
3574
3575
3576
3577 ArrayRef<StringRef> getAllConstraints() const {
3578 return llvm::ArrayRef(Constraints, NumInputs + NumOutputs);
3579 }
3580
3581 ArrayRef<StringRef> getClobbers() const {
3582 return llvm::ArrayRef(Clobbers, NumClobbers);
3583 }
3584
3585 ArrayRef<Expr*> getAllExprs() const {
3586 return llvm::ArrayRef(reinterpret_cast<Expr **>(Exprs),
3587 NumInputs + NumOutputs);
3588 }
3589
3590 StringRef getClobber(unsigned i) const { return getClobbers()[i]; }
3591
3592 private:
3593 void initialize(const ASTContext &C, StringRef AsmString,
3594 ArrayRef<Token> AsmToks, ArrayRef<StringRef> Constraints,
3595 ArrayRef<Expr*> Exprs, ArrayRef<StringRef> Clobbers);
3596
3597 public:
3598 SourceLocation getBeginLoc() const LLVM_READONLY { return AsmLoc; }
3599
3600 static bool classof(const Stmt *T) {
3601 return T->getStmtClass() == MSAsmStmtClass;
3602 }
3603
3604 child_range children() {
3605 return child_range(&Exprs[0], &Exprs[NumInputs + NumOutputs]);
3606 }
3607
3608 const_child_range children() const {
3609 return const_child_range(&Exprs[0], &Exprs[NumInputs + NumOutputs]);
3610 }
3611 };
3612
3613 class SEHExceptStmt : public Stmt {
3614 friend class ASTReader;
3615 friend class ASTStmtReader;
3616
3617 SourceLocation Loc;
3618 Stmt *Children[2];
3619
3620 enum { FILTER_EXPR, BLOCK };
3621
3622 SEHExceptStmt(SourceLocation Loc, Expr *FilterExpr, Stmt *Block);
3623 explicit SEHExceptStmt(EmptyShell E) : Stmt(SEHExceptStmtClass, E) {}
3624
3625 public:
3626 static SEHExceptStmt* Create(const ASTContext &C,
3627 SourceLocation ExceptLoc,
3628 Expr *FilterExpr,
3629 Stmt *Block);
3630
3631 SourceLocation getBeginLoc() const LLVM_READONLY { return getExceptLoc(); }
3632
3633 SourceLocation getExceptLoc() const { return Loc; }
3634 SourceLocation getEndLoc() const { return getBlock()->getEndLoc(); }
3635
3636 Expr *getFilterExpr() const {
3637 return reinterpret_cast<Expr*>(Children[FILTER_EXPR]);
3638 }
3639
3640 CompoundStmt *getBlock() const {
3641 return cast<CompoundStmt>(Children[BLOCK]);
3642 }
3643
3644 child_range children() {
3645 return child_range(Children, Children+2);
3646 }
3647
3648 const_child_range children() const {
3649 return const_child_range(Children, Children + 2);
3650 }
3651
3652 static bool classof(const Stmt *T) {
3653 return T->getStmtClass() == SEHExceptStmtClass;
3654 }
3655 };
3656
3657 class SEHFinallyStmt : public Stmt {
3658 friend class ASTReader;
3659 friend class ASTStmtReader;
3660
3661 SourceLocation Loc;
3662 Stmt *Block;
3663
3664 SEHFinallyStmt(SourceLocation Loc, Stmt *Block);
3665 explicit SEHFinallyStmt(EmptyShell E) : Stmt(SEHFinallyStmtClass, E) {}
3666
3667 public:
3668 static SEHFinallyStmt* Create(const ASTContext &C,
3669 SourceLocation FinallyLoc,
3670 Stmt *Block);
3671
3672 SourceLocation getBeginLoc() const LLVM_READONLY { return getFinallyLoc(); }
3673
3674 SourceLocation getFinallyLoc() const { return Loc; }
3675 SourceLocation getEndLoc() const { return Block->getEndLoc(); }
3676
3677 CompoundStmt *getBlock() const { return cast<CompoundStmt>(Block); }
3678
3679 child_range children() {
3680 return child_range(&Block,&Block+1);
3681 }
3682
3683 const_child_range children() const {
3684 return const_child_range(&Block, &Block + 1);
3685 }
3686
3687 static bool classof(const Stmt *T) {
3688 return T->getStmtClass() == SEHFinallyStmtClass;
3689 }
3690 };
3691
3692 class SEHTryStmt : public Stmt {
3693 friend class ASTReader;
3694 friend class ASTStmtReader;
3695
3696 bool IsCXXTry;
3697 SourceLocation TryLoc;
3698 Stmt *Children[2];
3699
3700 enum { TRY = 0, HANDLER = 1 };
3701
3702 SEHTryStmt(bool isCXXTry,
3703 SourceLocation TryLoc,
3704 Stmt *TryBlock,
3705 Stmt *Handler);
3706
3707 explicit SEHTryStmt(EmptyShell E) : Stmt(SEHTryStmtClass, E) {}
3708
3709 public:
3710 static SEHTryStmt* Create(const ASTContext &C, bool isCXXTry,
3711 SourceLocation TryLoc, Stmt *TryBlock,
3712 Stmt *Handler);
3713
3714 SourceLocation getBeginLoc() const LLVM_READONLY { return getTryLoc(); }
3715
3716 SourceLocation getTryLoc() const { return TryLoc; }
3717 SourceLocation getEndLoc() const { return Children[HANDLER]->getEndLoc(); }
3718
3719 bool getIsCXXTry() const { return IsCXXTry; }
3720
3721 CompoundStmt* getTryBlock() const {
3722 return cast<CompoundStmt>(Children[TRY]);
3723 }
3724
3725 Stmt *getHandler() const { return Children[HANDLER]; }
3726
3727
3728 SEHExceptStmt *getExceptHandler() const;
3729 SEHFinallyStmt *getFinallyHandler() const;
3730
3731 child_range children() {
3732 return child_range(Children, Children+2);
3733 }
3734
3735 const_child_range children() const {
3736 return const_child_range(Children, Children + 2);
3737 }
3738
3739 static bool classof(const Stmt *T) {
3740 return T->getStmtClass() == SEHTryStmtClass;
3741 }
3742 };
3743
3744
3745 class SEHLeaveStmt : public Stmt {
3746 SourceLocation LeaveLoc;
3747
3748 public:
3749 explicit SEHLeaveStmt(SourceLocation LL)
3750 : Stmt(SEHLeaveStmtClass), LeaveLoc(LL) {}
3751
3752
3753 explicit SEHLeaveStmt(EmptyShell Empty) : Stmt(SEHLeaveStmtClass, Empty) {}
3754
3755 SourceLocation getLeaveLoc() const { return LeaveLoc; }
3756 void setLeaveLoc(SourceLocation L) { LeaveLoc = L; }
3757
3758 SourceLocation getBeginLoc() const LLVM_READONLY { return LeaveLoc; }
3759 SourceLocation getEndLoc() const LLVM_READONLY { return LeaveLoc; }
3760
3761 static bool classof(const Stmt *T) {
3762 return T->getStmtClass() == SEHLeaveStmtClass;
3763 }
3764
3765
3766 child_range children() {
3767 return child_range(child_iterator(), child_iterator());
3768 }
3769
3770 const_child_range children() const {
3771 return const_child_range(const_child_iterator(), const_child_iterator());
3772 }
3773 };
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784 class CapturedStmt : public Stmt {
3785 public:
3786
3787
3788 enum VariableCaptureKind {
3789 VCK_This,
3790 VCK_ByRef,
3791 VCK_ByCopy,
3792 VCK_VLAType,
3793 };
3794
3795
3796
3797 class Capture {
3798 llvm::PointerIntPair<VarDecl *, 2, VariableCaptureKind> VarAndKind;
3799 SourceLocation Loc;
3800
3801 Capture() = default;
3802
3803 public:
3804 friend class ASTStmtReader;
3805 friend class CapturedStmt;
3806
3807
3808
3809
3810
3811
3812
3813
3814 Capture(SourceLocation Loc, VariableCaptureKind Kind,
3815 VarDecl *Var = nullptr);
3816
3817
3818 VariableCaptureKind getCaptureKind() const;
3819
3820
3821
3822 SourceLocation getLocation() const { return Loc; }
3823
3824
3825 bool capturesThis() const { return getCaptureKind() == VCK_This; }
3826
3827
3828 bool capturesVariable() const { return getCaptureKind() == VCK_ByRef; }
3829
3830
3831 bool capturesVariableByCopy() const {
3832 return getCaptureKind() == VCK_ByCopy;
3833 }
3834
3835
3836
3837 bool capturesVariableArrayType() const {
3838 return getCaptureKind() == VCK_VLAType;
3839 }
3840
3841
3842
3843
3844 VarDecl *getCapturedVar() const;
3845 };
3846
3847 private:
3848
3849 unsigned NumCaptures;
3850
3851
3852
3853 llvm::PointerIntPair<CapturedDecl *, 2, CapturedRegionKind> CapDeclAndKind;
3854
3855
3856 RecordDecl *TheRecordDecl = nullptr;
3857
3858
3859 CapturedStmt(Stmt *S, CapturedRegionKind Kind, ArrayRef<Capture> Captures,
3860 ArrayRef<Expr *> CaptureInits, CapturedDecl *CD, RecordDecl *RD);
3861
3862
3863 CapturedStmt(EmptyShell Empty, unsigned NumCaptures);
3864
3865 Stmt **getStoredStmts() { return reinterpret_cast<Stmt **>(this + 1); }
3866
3867 Stmt *const *getStoredStmts() const {
3868 return reinterpret_cast<Stmt *const *>(this + 1);
3869 }
3870
3871 Capture *getStoredCaptures() const;
3872
3873 void setCapturedStmt(Stmt *S) { getStoredStmts()[NumCaptures] = S; }
3874
3875 public:
3876 friend class ASTStmtReader;
3877
3878 static CapturedStmt *Create(const ASTContext &Context, Stmt *S,
3879 CapturedRegionKind Kind,
3880 ArrayRef<Capture> Captures,
3881 ArrayRef<Expr *> CaptureInits,
3882 CapturedDecl *CD, RecordDecl *RD);
3883
3884 static CapturedStmt *CreateDeserialized(const ASTContext &Context,
3885 unsigned NumCaptures);
3886
3887
3888 Stmt *getCapturedStmt() { return getStoredStmts()[NumCaptures]; }
3889 const Stmt *getCapturedStmt() const { return getStoredStmts()[NumCaptures]; }
3890
3891
3892 CapturedDecl *getCapturedDecl();
3893 const CapturedDecl *getCapturedDecl() const;
3894
3895
3896 void setCapturedDecl(CapturedDecl *D);
3897
3898
3899 CapturedRegionKind getCapturedRegionKind() const;
3900
3901
3902 void setCapturedRegionKind(CapturedRegionKind Kind);
3903
3904
3905 const RecordDecl *getCapturedRecordDecl() const { return TheRecordDecl; }
3906
3907
3908 void setCapturedRecordDecl(RecordDecl *D) {
3909 assert(D && "null RecordDecl");
3910 TheRecordDecl = D;
3911 }
3912
3913
3914 bool capturesVariable(const VarDecl *Var) const;
3915
3916
3917 using capture_iterator = Capture *;
3918 using const_capture_iterator = const Capture *;
3919 using capture_range = llvm::iterator_range<capture_iterator>;
3920 using capture_const_range = llvm::iterator_range<const_capture_iterator>;
3921
3922 capture_range captures() {
3923 return capture_range(capture_begin(), capture_end());
3924 }
3925 capture_const_range captures() const {
3926 return capture_const_range(capture_begin(), capture_end());
3927 }
3928
3929
3930 capture_iterator capture_begin() { return getStoredCaptures(); }
3931 const_capture_iterator capture_begin() const { return getStoredCaptures(); }
3932
3933
3934
3935 capture_iterator capture_end() const {
3936 return getStoredCaptures() + NumCaptures;
3937 }
3938
3939
3940 unsigned capture_size() const { return NumCaptures; }
3941
3942
3943 using capture_init_iterator = Expr **;
3944 using capture_init_range = llvm::iterator_range<capture_init_iterator>;
3945
3946
3947
3948 using const_capture_init_iterator = Expr *const *;
3949 using const_capture_init_range =
3950 llvm::iterator_range<const_capture_init_iterator>;
3951
3952 capture_init_range capture_inits() {
3953 return capture_init_range(capture_init_begin(), capture_init_end());
3954 }
3955
3956 const_capture_init_range capture_inits() const {
3957 return const_capture_init_range(capture_init_begin(), capture_init_end());
3958 }
3959
3960
3961 capture_init_iterator capture_init_begin() {
3962 return reinterpret_cast<Expr **>(getStoredStmts());
3963 }
3964
3965 const_capture_init_iterator capture_init_begin() const {
3966 return reinterpret_cast<Expr *const *>(getStoredStmts());
3967 }
3968
3969
3970
3971 capture_init_iterator capture_init_end() {
3972 return capture_init_begin() + NumCaptures;
3973 }
3974
3975 const_capture_init_iterator capture_init_end() const {
3976 return capture_init_begin() + NumCaptures;
3977 }
3978
3979 SourceLocation getBeginLoc() const LLVM_READONLY {
3980 return getCapturedStmt()->getBeginLoc();
3981 }
3982
3983 SourceLocation getEndLoc() const LLVM_READONLY {
3984 return getCapturedStmt()->getEndLoc();
3985 }
3986
3987 SourceRange getSourceRange() const LLVM_READONLY {
3988 return getCapturedStmt()->getSourceRange();
3989 }
3990
3991 static bool classof(const Stmt *T) {
3992 return T->getStmtClass() == CapturedStmtClass;
3993 }
3994
3995 child_range children();
3996
3997 const_child_range children() const;
3998 };
3999
4000 }
4001
4002 #endif