clang 18.0.0git
Stmt.h
Go to the documentation of this file.
1//===- Stmt.h - Classes for representing statements -------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the Stmt interface and subclasses.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_AST_STMT_H
14#define LLVM_CLANG_AST_STMT_H
15
16#include "clang/AST/APValue.h"
17#include "clang/AST/DeclGroup.h"
23#include "clang/Basic/LLVM.h"
24#include "clang/Basic/Lambda.h"
30#include "llvm/ADT/APFloat.h"
31#include "llvm/ADT/ArrayRef.h"
32#include "llvm/ADT/BitmaskEnum.h"
33#include "llvm/ADT/PointerIntPair.h"
34#include "llvm/ADT/StringRef.h"
35#include "llvm/ADT/iterator.h"
36#include "llvm/ADT/iterator_range.h"
37#include "llvm/Support/Casting.h"
38#include "llvm/Support/Compiler.h"
39#include "llvm/Support/ErrorHandling.h"
40#include <algorithm>
41#include <cassert>
42#include <cstddef>
43#include <iterator>
44#include <optional>
45#include <string>
46
47namespace llvm {
48
49class FoldingSetNodeID;
50
51} // namespace llvm
52
53namespace clang {
54
55class ASTContext;
56class Attr;
57class CapturedDecl;
58class Decl;
59class Expr;
60class AddrLabelExpr;
61class LabelDecl;
62class ODRHash;
63class PrinterHelper;
64struct PrintingPolicy;
65class RecordDecl;
66class SourceManager;
67class StringLiteral;
68class Token;
69class VarDecl;
70enum class CharacterLiteralKind;
72enum class CXXConstructionKind;
74enum class PredefinedIdentKind;
75enum class SourceLocIdentKind;
76enum class StringLiteralKind;
77
78//===----------------------------------------------------------------------===//
79// AST classes for statements.
80//===----------------------------------------------------------------------===//
81
82/// Stmt - This represents one statement.
83///
84class alignas(void *) Stmt {
85public:
86 enum StmtClass {
88#define STMT(CLASS, PARENT) CLASS##Class,
89#define STMT_RANGE(BASE, FIRST, LAST) \
90 first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class,
91#define LAST_STMT_RANGE(BASE, FIRST, LAST) \
92 first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class
93#define ABSTRACT_STMT(STMT)
94#include "clang/AST/StmtNodes.inc"
95 };
96
97 // Make vanilla 'new' and 'delete' illegal for Stmts.
98protected:
99 friend class ASTStmtReader;
100 friend class ASTStmtWriter;
101
102 void *operator new(size_t bytes) noexcept {
103 llvm_unreachable("Stmts cannot be allocated with regular 'new'.");
104 }
105
106 void operator delete(void *data) noexcept {
107 llvm_unreachable("Stmts cannot be released with regular 'delete'.");
108 }
109
110 //===--- Statement bitfields classes ---===//
111
113 friend class ASTStmtReader;
114 friend class ASTStmtWriter;
115 friend class Stmt;
116
117 /// The statement class.
118 LLVM_PREFERRED_TYPE(StmtClass)
119 unsigned sClass : 8;
120 };
121 enum { NumStmtBits = 8 };
122
124 friend class ASTStmtReader;
125 friend class ASTStmtWriter;
126 friend class NullStmt;
127
128 LLVM_PREFERRED_TYPE(StmtBitfields)
130
131 /// True if the null statement was preceded by an empty macro, e.g:
132 /// @code
133 /// #define CALL(x)
134 /// CALL(0);
135 /// @endcode
136 LLVM_PREFERRED_TYPE(bool)
137 unsigned HasLeadingEmptyMacro : 1;
138
139 /// The location of the semi-colon.
140 SourceLocation SemiLoc;
141 };
142
144 friend class ASTStmtReader;
145 friend class CompoundStmt;
146
147 LLVM_PREFERRED_TYPE(StmtBitfields)
149
150 /// True if the compound statement has one or more pragmas that set some
151 /// floating-point features.
152 LLVM_PREFERRED_TYPE(bool)
153 unsigned HasFPFeatures : 1;
154
155 unsigned NumStmts;
156 };
157
159 friend class LabelStmt;
160
161 LLVM_PREFERRED_TYPE(StmtBitfields)
163
164 SourceLocation IdentLoc;
165 };
166
168 friend class ASTStmtReader;
169 friend class AttributedStmt;
170
171 LLVM_PREFERRED_TYPE(StmtBitfields)
173
174 /// Number of attributes.
175 unsigned NumAttrs : 32 - NumStmtBits;
176
177 /// The location of the attribute.
178 SourceLocation AttrLoc;
179 };
180
182 friend class ASTStmtReader;
183 friend class IfStmt;
184
185 LLVM_PREFERRED_TYPE(StmtBitfields)
187
188 /// Whether this is a constexpr if, or a consteval if, or neither.
189 LLVM_PREFERRED_TYPE(IfStatementKind)
190 unsigned Kind : 3;
191
192 /// True if this if statement has storage for an else statement.
193 LLVM_PREFERRED_TYPE(bool)
194 unsigned HasElse : 1;
195
196 /// True if this if statement has storage for a variable declaration.
197 LLVM_PREFERRED_TYPE(bool)
198 unsigned HasVar : 1;
199
200 /// True if this if statement has storage for an init statement.
201 LLVM_PREFERRED_TYPE(bool)
202 unsigned HasInit : 1;
203
204 /// The location of the "if".
205 SourceLocation IfLoc;
206 };
207
209 friend class SwitchStmt;
210
211 LLVM_PREFERRED_TYPE(StmtBitfields)
213
214 /// True if the SwitchStmt has storage for an init statement.
215 LLVM_PREFERRED_TYPE(bool)
216 unsigned HasInit : 1;
217
218 /// True if the SwitchStmt has storage for a condition variable.
219 LLVM_PREFERRED_TYPE(bool)
220 unsigned HasVar : 1;
221
222 /// If the SwitchStmt is a switch on an enum value, records whether all
223 /// the enum values were covered by CaseStmts. The coverage information
224 /// value is meant to be a hint for possible clients.
225 LLVM_PREFERRED_TYPE(bool)
226 unsigned AllEnumCasesCovered : 1;
227
228 /// The location of the "switch".
229 SourceLocation SwitchLoc;
230 };
231
233 friend class ASTStmtReader;
234 friend class WhileStmt;
235
236 LLVM_PREFERRED_TYPE(StmtBitfields)
238
239 /// True if the WhileStmt has storage for a condition variable.
240 LLVM_PREFERRED_TYPE(bool)
241 unsigned HasVar : 1;
242
243 /// The location of the "while".
244 SourceLocation WhileLoc;
245 };
246
248 friend class DoStmt;
249
250 LLVM_PREFERRED_TYPE(StmtBitfields)
252
253 /// The location of the "do".
254 SourceLocation DoLoc;
255 };
256
258 friend class ForStmt;
259
260 LLVM_PREFERRED_TYPE(StmtBitfields)
262
263 /// The location of the "for".
264 SourceLocation ForLoc;
265 };
266
268 friend class GotoStmt;
269 friend class IndirectGotoStmt;
270
271 LLVM_PREFERRED_TYPE(StmtBitfields)
273
274 /// The location of the "goto".
275 SourceLocation GotoLoc;
276 };
277
279 friend class ContinueStmt;
280
281 LLVM_PREFERRED_TYPE(StmtBitfields)
283
284 /// The location of the "continue".
285 SourceLocation ContinueLoc;
286 };
287
289 friend class BreakStmt;
290
291 LLVM_PREFERRED_TYPE(StmtBitfields)
293
294 /// The location of the "break".
295 SourceLocation BreakLoc;
296 };
297
299 friend class ReturnStmt;
300
301 LLVM_PREFERRED_TYPE(StmtBitfields)
303
304 /// True if this ReturnStmt has storage for an NRVO candidate.
305 LLVM_PREFERRED_TYPE(bool)
306 unsigned HasNRVOCandidate : 1;
307
308 /// The location of the "return".
309 SourceLocation RetLoc;
310 };
311
313 friend class SwitchCase;
314 friend class CaseStmt;
315
316 LLVM_PREFERRED_TYPE(StmtBitfields)
318
319 /// Used by CaseStmt to store whether it is a case statement
320 /// of the form case LHS ... RHS (a GNU extension).
321 LLVM_PREFERRED_TYPE(bool)
322 unsigned CaseStmtIsGNURange : 1;
323
324 /// The location of the "case" or "default" keyword.
325 SourceLocation KeywordLoc;
326 };
327
328 //===--- Expression bitfields classes ---===//
329
331 friend class ASTStmtReader; // deserialization
332 friend class AtomicExpr; // ctor
333 friend class BlockDeclRefExpr; // ctor
334 friend class CallExpr; // ctor
335 friend class CXXConstructExpr; // ctor
336 friend class CXXDependentScopeMemberExpr; // ctor
337 friend class CXXNewExpr; // ctor
338 friend class CXXUnresolvedConstructExpr; // ctor
339 friend class DeclRefExpr; // computeDependence
340 friend class DependentScopeDeclRefExpr; // ctor
341 friend class DesignatedInitExpr; // ctor
342 friend class Expr;
343 friend class InitListExpr; // ctor
344 friend class ObjCArrayLiteral; // ctor
345 friend class ObjCDictionaryLiteral; // ctor
346 friend class ObjCMessageExpr; // ctor
347 friend class OffsetOfExpr; // ctor
348 friend class OpaqueValueExpr; // ctor
349 friend class OverloadExpr; // ctor
350 friend class ParenListExpr; // ctor
351 friend class PseudoObjectExpr; // ctor
352 friend class ShuffleVectorExpr; // ctor
353
354 LLVM_PREFERRED_TYPE(StmtBitfields)
356
357 LLVM_PREFERRED_TYPE(ExprValueKind)
358 unsigned ValueKind : 2;
359 LLVM_PREFERRED_TYPE(ExprObjectKind)
360 unsigned ObjectKind : 3;
361 LLVM_PREFERRED_TYPE(ExprDependence)
362 unsigned Dependent : llvm::BitWidth<ExprDependence>;
363 };
364 enum { NumExprBits = NumStmtBits + 5 + llvm::BitWidth<ExprDependence> };
365
367 friend class ASTStmtReader;
368 friend class ASTStmtWriter;
369 friend class ConstantExpr;
370
371 LLVM_PREFERRED_TYPE(ExprBitfields)
373
374 /// The kind of result that is tail-allocated.
375 LLVM_PREFERRED_TYPE(ConstantResultStorageKind)
376 unsigned ResultKind : 2;
377
378 /// The kind of Result as defined by APValue::ValueKind.
379 LLVM_PREFERRED_TYPE(APValue::ValueKind)
380 unsigned APValueKind : 4;
381
382 /// When ResultKind == ConstantResultStorageKind::Int64, true if the
383 /// tail-allocated integer is unsigned.
384 LLVM_PREFERRED_TYPE(bool)
385 unsigned IsUnsigned : 1;
386
387 /// When ResultKind == ConstantResultStorageKind::Int64. the BitWidth of the
388 /// tail-allocated integer. 7 bits because it is the minimal number of bits
389 /// to represent a value from 0 to 64 (the size of the tail-allocated
390 /// integer).
391 unsigned BitWidth : 7;
392
393 /// When ResultKind == ConstantResultStorageKind::APValue, true if the
394 /// ASTContext will cleanup the tail-allocated APValue.
395 LLVM_PREFERRED_TYPE(bool)
396 unsigned HasCleanup : 1;
397
398 /// True if this ConstantExpr was created for immediate invocation.
399 LLVM_PREFERRED_TYPE(bool)
400 unsigned IsImmediateInvocation : 1;
401 };
402
404 friend class ASTStmtReader;
405 friend class PredefinedExpr;
406
407 LLVM_PREFERRED_TYPE(ExprBitfields)
409
410 LLVM_PREFERRED_TYPE(PredefinedIdentKind)
411 unsigned Kind : 4;
412
413 /// True if this PredefinedExpr has a trailing "StringLiteral *"
414 /// for the predefined identifier.
415 LLVM_PREFERRED_TYPE(bool)
416 unsigned HasFunctionName : 1;
417
418 /// True if this PredefinedExpr should be treated as a StringLiteral (for
419 /// MSVC compatibility).
420 LLVM_PREFERRED_TYPE(bool)
421 unsigned IsTransparent : 1;
422
423 /// The location of this PredefinedExpr.
424 SourceLocation Loc;
425 };
426
428 friend class ASTStmtReader; // deserialization
429 friend class DeclRefExpr;
430
431 LLVM_PREFERRED_TYPE(ExprBitfields)
433
434 LLVM_PREFERRED_TYPE(bool)
435 unsigned HasQualifier : 1;
436 LLVM_PREFERRED_TYPE(bool)
437 unsigned HasTemplateKWAndArgsInfo : 1;
438 LLVM_PREFERRED_TYPE(bool)
439 unsigned HasFoundDecl : 1;
440 LLVM_PREFERRED_TYPE(bool)
441 unsigned HadMultipleCandidates : 1;
442 LLVM_PREFERRED_TYPE(bool)
443 unsigned RefersToEnclosingVariableOrCapture : 1;
444 LLVM_PREFERRED_TYPE(bool)
445 unsigned CapturedByCopyInLambdaWithExplicitObjectParameter : 1;
446 LLVM_PREFERRED_TYPE(NonOdrUseReason)
447 unsigned NonOdrUseReason : 2;
448 LLVM_PREFERRED_TYPE(bool)
449 unsigned IsImmediateEscalating : 1;
450
451 /// The location of the declaration name itself.
452 SourceLocation Loc;
453 };
454
455
457 friend class FloatingLiteral;
458
459 LLVM_PREFERRED_TYPE(ExprBitfields)
461
462 static_assert(
463 llvm::APFloat::S_MaxSemantics < 16,
464 "Too many Semantics enum values to fit in bitfield of size 4");
465 LLVM_PREFERRED_TYPE(llvm::APFloat::Semantics)
466 unsigned Semantics : 4; // Provides semantics for APFloat construction
467 LLVM_PREFERRED_TYPE(bool)
468 unsigned IsExact : 1;
469 };
470
472 friend class ASTStmtReader;
473 friend class StringLiteral;
474
475 LLVM_PREFERRED_TYPE(ExprBitfields)
477
478 /// The kind of this string literal.
479 /// One of the enumeration values of StringLiteral::StringKind.
480 LLVM_PREFERRED_TYPE(StringLiteralKind)
481 unsigned Kind : 3;
482
483 /// The width of a single character in bytes. Only values of 1, 2,
484 /// and 4 bytes are supported. StringLiteral::mapCharByteWidth maps
485 /// the target + string kind to the appropriate CharByteWidth.
486 unsigned CharByteWidth : 3;
487
488 LLVM_PREFERRED_TYPE(bool)
489 unsigned IsPascal : 1;
490
491 /// The number of concatenated token this string is made of.
492 /// This is the number of trailing SourceLocation.
493 unsigned NumConcatenated;
494 };
495
497 friend class CharacterLiteral;
498
499 LLVM_PREFERRED_TYPE(ExprBitfields)
501
502 LLVM_PREFERRED_TYPE(CharacterLiteralKind)
503 unsigned Kind : 3;
504 };
505
507 friend class UnaryOperator;
508
509 LLVM_PREFERRED_TYPE(ExprBitfields)
511
512 LLVM_PREFERRED_TYPE(UnaryOperatorKind)
513 unsigned Opc : 5;
514 LLVM_PREFERRED_TYPE(bool)
515 unsigned CanOverflow : 1;
516 //
517 /// This is only meaningful for operations on floating point
518 /// types when additional values need to be in trailing storage.
519 /// It is 0 otherwise.
520 LLVM_PREFERRED_TYPE(bool)
521 unsigned HasFPFeatures : 1;
522
523 SourceLocation Loc;
524 };
525
528
529 LLVM_PREFERRED_TYPE(ExprBitfields)
531
532 LLVM_PREFERRED_TYPE(UnaryExprOrTypeTrait)
533 unsigned Kind : 3;
534 LLVM_PREFERRED_TYPE(bool)
535 unsigned IsType : 1; // true if operand is a type, false if an expression.
536 };
537
539 friend class ArraySubscriptExpr;
541
542 LLVM_PREFERRED_TYPE(ExprBitfields)
544
545 SourceLocation RBracketLoc;
546 };
547
549 friend class CallExpr;
550
551 LLVM_PREFERRED_TYPE(ExprBitfields)
553
554 unsigned NumPreArgs : 1;
555
556 /// True if the callee of the call expression was found using ADL.
557 LLVM_PREFERRED_TYPE(bool)
558 unsigned UsesADL : 1;
559
560 /// True if the call expression has some floating-point features.
561 LLVM_PREFERRED_TYPE(bool)
562 unsigned HasFPFeatures : 1;
563
564 /// Padding used to align OffsetToTrailingObjects to a byte multiple.
565 unsigned : 24 - 3 - NumExprBits;
566
567 /// The offset in bytes from the this pointer to the start of the
568 /// trailing objects belonging to CallExpr. Intentionally byte sized
569 /// for faster access.
570 unsigned OffsetToTrailingObjects : 8;
571 };
572 enum { NumCallExprBits = 32 };
573
575 friend class ASTStmtReader;
576 friend class MemberExpr;
577
578 LLVM_PREFERRED_TYPE(ExprBitfields)
580
581 /// IsArrow - True if this is "X->F", false if this is "X.F".
582 LLVM_PREFERRED_TYPE(bool)
583 unsigned IsArrow : 1;
584
585 /// True if this member expression used a nested-name-specifier to
586 /// refer to the member, e.g., "x->Base::f", or found its member via
587 /// a using declaration. When true, a MemberExprNameQualifier
588 /// structure is allocated immediately after the MemberExpr.
589 LLVM_PREFERRED_TYPE(bool)
590 unsigned HasQualifierOrFoundDecl : 1;
591
592 /// True if this member expression specified a template keyword
593 /// and/or a template argument list explicitly, e.g., x->f<int>,
594 /// x->template f, x->template f<int>.
595 /// When true, an ASTTemplateKWAndArgsInfo structure and its
596 /// TemplateArguments (if any) are present.
597 LLVM_PREFERRED_TYPE(bool)
598 unsigned HasTemplateKWAndArgsInfo : 1;
599
600 /// True if this member expression refers to a method that
601 /// was resolved from an overloaded set having size greater than 1.
602 LLVM_PREFERRED_TYPE(bool)
603 unsigned HadMultipleCandidates : 1;
604
605 /// Value of type NonOdrUseReason indicating why this MemberExpr does
606 /// not constitute an odr-use of the named declaration. Meaningful only
607 /// when naming a static member.
608 LLVM_PREFERRED_TYPE(NonOdrUseReason)
609 unsigned NonOdrUseReason : 2;
610
611 /// This is the location of the -> or . in the expression.
612 SourceLocation OperatorLoc;
613 };
614
616 friend class CastExpr;
617 friend class ImplicitCastExpr;
618
619 LLVM_PREFERRED_TYPE(ExprBitfields)
621
622 LLVM_PREFERRED_TYPE(CastKind)
623 unsigned Kind : 7;
624 LLVM_PREFERRED_TYPE(bool)
625 unsigned PartOfExplicitCast : 1; // Only set for ImplicitCastExpr.
626
627 /// True if the call expression has some floating-point features.
628 LLVM_PREFERRED_TYPE(bool)
629 unsigned HasFPFeatures : 1;
630
631 /// The number of CXXBaseSpecifiers in the cast. 14 bits would be enough
632 /// here. ([implimits] Direct and indirect base classes [16384]).
633 unsigned BasePathSize;
634 };
635
637 friend class BinaryOperator;
638
639 LLVM_PREFERRED_TYPE(ExprBitfields)
641
642 LLVM_PREFERRED_TYPE(BinaryOperatorKind)
643 unsigned Opc : 6;
644
645 /// This is only meaningful for operations on floating point
646 /// types when additional values need to be in trailing storage.
647 /// It is 0 otherwise.
648 LLVM_PREFERRED_TYPE(bool)
649 unsigned HasFPFeatures : 1;
650
651 SourceLocation OpLoc;
652 };
653
655 friend class InitListExpr;
656
657 LLVM_PREFERRED_TYPE(ExprBitfields)
659
660 /// Whether this initializer list originally had a GNU array-range
661 /// designator in it. This is a temporary marker used by CodeGen.
662 LLVM_PREFERRED_TYPE(bool)
663 unsigned HadArrayRangeDesignator : 1;
664 };
665
667 friend class ASTStmtReader;
668 friend class ParenListExpr;
669
670 LLVM_PREFERRED_TYPE(ExprBitfields)
672
673 /// The number of expressions in the paren list.
674 unsigned NumExprs;
675 };
676
678 friend class ASTStmtReader;
680
681 LLVM_PREFERRED_TYPE(ExprBitfields)
683
684 /// The location of the "_Generic".
685 SourceLocation GenericLoc;
686 };
687
689 friend class ASTStmtReader; // deserialization
690 friend class PseudoObjectExpr;
691
692 LLVM_PREFERRED_TYPE(ExprBitfields)
694
695 unsigned NumSubExprs : 16;
696 unsigned ResultIndex : 16;
697 };
698
700 friend class ASTStmtReader;
701 friend class SourceLocExpr;
702
703 LLVM_PREFERRED_TYPE(ExprBitfields)
705
706 /// The kind of source location builtin represented by the SourceLocExpr.
707 /// Ex. __builtin_LINE, __builtin_FUNCTION, etc.
708 LLVM_PREFERRED_TYPE(SourceLocIdentKind)
709 unsigned Kind : 3;
710 };
711
713 friend class ASTStmtReader;
714 friend class StmtExpr;
715
716 LLVM_PREFERRED_TYPE(ExprBitfields)
718
719 /// The number of levels of template parameters enclosing this statement
720 /// expression. Used to determine if a statement expression remains
721 /// dependent after instantiation.
722 unsigned TemplateDepth;
723 };
724
725 //===--- C++ Expression bitfields classes ---===//
726
728 friend class ASTStmtReader;
730
731 LLVM_PREFERRED_TYPE(CallExprBitfields)
733
734 /// The kind of this overloaded operator. One of the enumerator
735 /// value of OverloadedOperatorKind.
736 LLVM_PREFERRED_TYPE(OverloadedOperatorKind)
737 unsigned OperatorKind : 6;
738 };
739
741 friend class ASTStmtReader;
743
744 LLVM_PREFERRED_TYPE(CallExprBitfields)
746
747 LLVM_PREFERRED_TYPE(bool)
748 unsigned IsReversed : 1;
749 };
750
752 friend class CXXBoolLiteralExpr;
753
754 LLVM_PREFERRED_TYPE(ExprBitfields)
756
757 /// The value of the boolean literal.
758 LLVM_PREFERRED_TYPE(bool)
759 unsigned Value : 1;
760
761 /// The location of the boolean literal.
762 SourceLocation Loc;
763 };
764
767
768 LLVM_PREFERRED_TYPE(ExprBitfields)
770
771 /// The location of the null pointer literal.
772 SourceLocation Loc;
773 };
774
776 friend class CXXThisExpr;
777
778 LLVM_PREFERRED_TYPE(ExprBitfields)
780
781 /// Whether this is an implicit "this".
782 LLVM_PREFERRED_TYPE(bool)
783 unsigned IsImplicit : 1;
784
785 /// The location of the "this".
786 SourceLocation Loc;
787 };
788
790 friend class ASTStmtReader;
791 friend class CXXThrowExpr;
792
793 LLVM_PREFERRED_TYPE(ExprBitfields)
795
796 /// Whether the thrown variable (if any) is in scope.
797 LLVM_PREFERRED_TYPE(bool)
798 unsigned IsThrownVariableInScope : 1;
799
800 /// The location of the "throw".
801 SourceLocation ThrowLoc;
802 };
803
805 friend class ASTStmtReader;
806 friend class CXXDefaultArgExpr;
807
808 LLVM_PREFERRED_TYPE(ExprBitfields)
810
811 /// Whether this CXXDefaultArgExpr rewrote its argument and stores a copy.
812 LLVM_PREFERRED_TYPE(bool)
813 unsigned HasRewrittenInit : 1;
814
815 /// The location where the default argument expression was used.
816 SourceLocation Loc;
817 };
818
820 friend class ASTStmtReader;
821 friend class CXXDefaultInitExpr;
822
823 LLVM_PREFERRED_TYPE(ExprBitfields)
825
826 /// Whether this CXXDefaultInitExprBitfields rewrote its argument and stores
827 /// a copy.
828 LLVM_PREFERRED_TYPE(bool)
829 unsigned HasRewrittenInit : 1;
830
831 /// The location where the default initializer expression was used.
832 SourceLocation Loc;
833 };
834
836 friend class ASTStmtReader;
838
839 LLVM_PREFERRED_TYPE(ExprBitfields)
841
842 SourceLocation RParenLoc;
843 };
844
846 friend class ASTStmtReader;
847 friend class ASTStmtWriter;
848 friend class CXXNewExpr;
849
850 LLVM_PREFERRED_TYPE(ExprBitfields)
852
853 /// Was the usage ::new, i.e. is the global new to be used?
854 LLVM_PREFERRED_TYPE(bool)
855 unsigned IsGlobalNew : 1;
856
857 /// Do we allocate an array? If so, the first trailing "Stmt *" is the
858 /// size expression.
859 LLVM_PREFERRED_TYPE(bool)
860 unsigned IsArray : 1;
861
862 /// Should the alignment be passed to the allocation function?
863 LLVM_PREFERRED_TYPE(bool)
864 unsigned ShouldPassAlignment : 1;
865
866 /// If this is an array allocation, does the usual deallocation
867 /// function for the allocated type want to know the allocated size?
868 LLVM_PREFERRED_TYPE(bool)
869 unsigned UsualArrayDeleteWantsSize : 1;
870
871 /// What kind of initializer do we have? Could be none, parens, or braces.
872 /// In storage, we distinguish between "none, and no initializer expr", and
873 /// "none, but an implicit initializer expr".
874 LLVM_PREFERRED_TYPE(CXXNewInitializationStyle)
875 unsigned StoredInitializationStyle : 2;
876
877 /// True if the allocated type was expressed as a parenthesized type-id.
878 LLVM_PREFERRED_TYPE(bool)
879 unsigned IsParenTypeId : 1;
880
881 /// The number of placement new arguments.
882 unsigned NumPlacementArgs;
883 };
884
886 friend class ASTStmtReader;
887 friend class CXXDeleteExpr;
888
889 LLVM_PREFERRED_TYPE(ExprBitfields)
891
892 /// Is this a forced global delete, i.e. "::delete"?
893 LLVM_PREFERRED_TYPE(bool)
894 unsigned GlobalDelete : 1;
895
896 /// Is this the array form of delete, i.e. "delete[]"?
897 LLVM_PREFERRED_TYPE(bool)
898 unsigned ArrayForm : 1;
899
900 /// ArrayFormAsWritten can be different from ArrayForm if 'delete' is
901 /// applied to pointer-to-array type (ArrayFormAsWritten will be false
902 /// while ArrayForm will be true).
903 LLVM_PREFERRED_TYPE(bool)
904 unsigned ArrayFormAsWritten : 1;
905
906 /// Does the usual deallocation function for the element type require
907 /// a size_t argument?
908 LLVM_PREFERRED_TYPE(bool)
909 unsigned UsualArrayDeleteWantsSize : 1;
910
911 /// Location of the expression.
912 SourceLocation Loc;
913 };
914
916 friend class ASTStmtReader;
917 friend class ASTStmtWriter;
918 friend class TypeTraitExpr;
919
920 LLVM_PREFERRED_TYPE(ExprBitfields)
922
923 /// The kind of type trait, which is a value of a TypeTrait enumerator.
924 LLVM_PREFERRED_TYPE(TypeTrait)
925 unsigned Kind : 8;
926
927 /// If this expression is not value-dependent, this indicates whether
928 /// the trait evaluated true or false.
929 LLVM_PREFERRED_TYPE(bool)
930 unsigned Value : 1;
931
932 /// The number of arguments to this type trait. According to [implimits]
933 /// 8 bits would be enough, but we require (and test for) at least 16 bits
934 /// to mirror FunctionType.
935 unsigned NumArgs;
936 };
937
939 friend class ASTStmtReader;
940 friend class ASTStmtWriter;
942
943 LLVM_PREFERRED_TYPE(ExprBitfields)
945
946 /// Whether the name includes info for explicit template
947 /// keyword and arguments.
948 LLVM_PREFERRED_TYPE(bool)
949 unsigned HasTemplateKWAndArgsInfo : 1;
950 };
951
953 friend class ASTStmtReader;
954 friend class CXXConstructExpr;
955
956 LLVM_PREFERRED_TYPE(ExprBitfields)
958
959 LLVM_PREFERRED_TYPE(bool)
960 unsigned Elidable : 1;
961 LLVM_PREFERRED_TYPE(bool)
962 unsigned HadMultipleCandidates : 1;
963 LLVM_PREFERRED_TYPE(bool)
964 unsigned ListInitialization : 1;
965 LLVM_PREFERRED_TYPE(bool)
966 unsigned StdInitListInitialization : 1;
967 LLVM_PREFERRED_TYPE(bool)
968 unsigned ZeroInitialization : 1;
969 LLVM_PREFERRED_TYPE(CXXConstructionKind)
970 unsigned ConstructionKind : 3;
971 LLVM_PREFERRED_TYPE(bool)
972 unsigned IsImmediateEscalating : 1;
973
974 SourceLocation Loc;
975 };
976
978 friend class ASTStmtReader; // deserialization
979 friend class ExprWithCleanups;
980
981 LLVM_PREFERRED_TYPE(ExprBitfields)
983
984 // When false, it must not have side effects.
985 LLVM_PREFERRED_TYPE(bool)
986 unsigned CleanupsHaveSideEffects : 1;
987
988 unsigned NumObjects : 32 - 1 - NumExprBits;
989 };
990
992 friend class ASTStmtReader;
994
995 LLVM_PREFERRED_TYPE(ExprBitfields)
997
998 /// The number of arguments used to construct the type.
999 unsigned NumArgs;
1000 };
1001
1003 friend class ASTStmtReader;
1005
1006 LLVM_PREFERRED_TYPE(ExprBitfields)
1008
1009 /// Whether this member expression used the '->' operator or
1010 /// the '.' operator.
1011 LLVM_PREFERRED_TYPE(bool)
1012 unsigned IsArrow : 1;
1013
1014 /// Whether this member expression has info for explicit template
1015 /// keyword and arguments.
1016 LLVM_PREFERRED_TYPE(bool)
1017 unsigned HasTemplateKWAndArgsInfo : 1;
1018
1019 /// See getFirstQualifierFoundInScope() and the comment listing
1020 /// the trailing objects.
1021 LLVM_PREFERRED_TYPE(bool)
1022 unsigned HasFirstQualifierFoundInScope : 1;
1023
1024 /// The location of the '->' or '.' operator.
1025 SourceLocation OperatorLoc;
1026 };
1027
1029 friend class ASTStmtReader;
1030 friend class OverloadExpr;
1031
1032 LLVM_PREFERRED_TYPE(ExprBitfields)
1034
1035 /// Whether the name includes info for explicit template
1036 /// keyword and arguments.
1037 LLVM_PREFERRED_TYPE(bool)
1038 unsigned HasTemplateKWAndArgsInfo : 1;
1039
1040 /// Padding used by the derived classes to store various bits. If you
1041 /// need to add some data here, shrink this padding and add your data
1042 /// above. NumOverloadExprBits also needs to be updated.
1043 unsigned : 32 - NumExprBits - 1;
1044
1045 /// The number of results.
1046 unsigned NumResults;
1047 };
1049
1051 friend class ASTStmtReader;
1053
1054 LLVM_PREFERRED_TYPE(OverloadExprBitfields)
1056
1057 /// True if these lookup results should be extended by
1058 /// argument-dependent lookup if this is the operand of a function call.
1059 LLVM_PREFERRED_TYPE(bool)
1060 unsigned RequiresADL : 1;
1061
1062 /// True if these lookup results are overloaded. This is pretty trivially
1063 /// rederivable if we urgently need to kill this field.
1064 LLVM_PREFERRED_TYPE(bool)
1065 unsigned Overloaded : 1;
1066 };
1067 static_assert(sizeof(UnresolvedLookupExprBitfields) <= 4,
1068 "UnresolvedLookupExprBitfields must be <= than 4 bytes to"
1069 "avoid trashing OverloadExprBitfields::NumResults!");
1070
1072 friend class ASTStmtReader;
1074
1075 LLVM_PREFERRED_TYPE(OverloadExprBitfields)
1077
1078 /// Whether this member expression used the '->' operator or
1079 /// the '.' operator.
1080 LLVM_PREFERRED_TYPE(bool)
1081 unsigned IsArrow : 1;
1082
1083 /// Whether the lookup results contain an unresolved using declaration.
1084 LLVM_PREFERRED_TYPE(bool)
1085 unsigned HasUnresolvedUsing : 1;
1086 };
1087 static_assert(sizeof(UnresolvedMemberExprBitfields) <= 4,
1088 "UnresolvedMemberExprBitfields must be <= than 4 bytes to"
1089 "avoid trashing OverloadExprBitfields::NumResults!");
1090
1092 friend class ASTStmtReader;
1093 friend class CXXNoexceptExpr;
1094
1095 LLVM_PREFERRED_TYPE(ExprBitfields)
1097
1098 LLVM_PREFERRED_TYPE(bool)
1099 unsigned Value : 1;
1100 };
1101
1103 friend class ASTStmtReader;
1105
1106 LLVM_PREFERRED_TYPE(ExprBitfields)
1108
1109 /// The location of the non-type template parameter reference.
1110 SourceLocation NameLoc;
1111 };
1112
1114 friend class ASTStmtReader;
1115 friend class ASTStmtWriter;
1116 friend class LambdaExpr;
1117
1118 LLVM_PREFERRED_TYPE(ExprBitfields)
1120
1121 /// The default capture kind, which is a value of type
1122 /// LambdaCaptureDefault.
1123 LLVM_PREFERRED_TYPE(LambdaCaptureDefault)
1124 unsigned CaptureDefault : 2;
1125
1126 /// Whether this lambda had an explicit parameter list vs. an
1127 /// implicit (and empty) parameter list.
1128 LLVM_PREFERRED_TYPE(bool)
1129 unsigned ExplicitParams : 1;
1130
1131 /// Whether this lambda had the result type explicitly specified.
1132 LLVM_PREFERRED_TYPE(bool)
1133 unsigned ExplicitResultType : 1;
1134
1135 /// The number of captures.
1136 unsigned NumCaptures : 16;
1137 };
1138
1140 friend class ASTStmtReader;
1141 friend class ASTStmtWriter;
1142 friend class RequiresExpr;
1143
1144 LLVM_PREFERRED_TYPE(ExprBitfields)
1146
1147 LLVM_PREFERRED_TYPE(bool)
1148 unsigned IsSatisfied : 1;
1149 SourceLocation RequiresKWLoc;
1150 };
1151
1152 //===--- C++ Coroutines bitfields classes ---===//
1153
1155 friend class CoawaitExpr;
1156
1157 LLVM_PREFERRED_TYPE(ExprBitfields)
1159
1160 LLVM_PREFERRED_TYPE(bool)
1161 unsigned IsImplicit : 1;
1162 };
1163
1164 //===--- Obj-C Expression bitfields classes ---===//
1165
1168
1169 LLVM_PREFERRED_TYPE(ExprBitfields)
1171
1172 LLVM_PREFERRED_TYPE(bool)
1173 unsigned ShouldCopy : 1;
1174 };
1175
1176 //===--- Clang Extensions bitfields classes ---===//
1177
1179 friend class ASTStmtReader;
1180 friend class OpaqueValueExpr;
1181
1182 LLVM_PREFERRED_TYPE(ExprBitfields)
1184
1185 /// The OVE is a unique semantic reference to its source expression if this
1186 /// bit is set to true.
1187 LLVM_PREFERRED_TYPE(bool)
1188 unsigned IsUnique : 1;
1189
1190 SourceLocation Loc;
1191 };
1192
1193 union {
1194 // Same order as in StmtNodes.td.
1195 // Statements
1211
1212 // Expressions
1232
1233 // GNU Extensions.
1235
1236 // C++ Expressions
1261
1262 // C++ Coroutines expressions
1264
1265 // Obj-C Expressions
1267
1268 // Clang Extensions
1270 };
1271
1272public:
1273 // Only allow allocation of Stmts using the allocator in ASTContext
1274 // or by doing a placement new.
1275 void* operator new(size_t bytes, const ASTContext& C,
1276 unsigned alignment = 8);
1277
1278 void* operator new(size_t bytes, const ASTContext* C,
1279 unsigned alignment = 8) {
1280 return operator new(bytes, *C, alignment);
1281 }
1282
1283 void *operator new(size_t bytes, void *mem) noexcept { return mem; }
1284
1285 void operator delete(void *, const ASTContext &, unsigned) noexcept {}
1286 void operator delete(void *, const ASTContext *, unsigned) noexcept {}
1287 void operator delete(void *, size_t) noexcept {}
1288 void operator delete(void *, void *) noexcept {}
1289
1290public:
1291 /// A placeholder type used to construct an empty shell of a
1292 /// type, that will be filled in later (e.g., by some
1293 /// de-serialization).
1294 struct EmptyShell {};
1295
1296 /// The likelihood of a branch being taken.
1298 LH_Unlikely = -1, ///< Branch has the [[unlikely]] attribute.
1299 LH_None, ///< No attribute set or branches of the IfStmt have
1300 ///< the same attribute.
1301 LH_Likely ///< Branch has the [[likely]] attribute.
1303
1304protected:
1305 /// Iterator for iterating over Stmt * arrays that contain only T *.
1306 ///
1307 /// This is needed because AST nodes use Stmt* arrays to store
1308 /// references to children (to be compatible with StmtIterator).
1309 template<typename T, typename TPtr = T *, typename StmtPtr = Stmt *>
1311 : llvm::iterator_adaptor_base<CastIterator<T, TPtr, StmtPtr>, StmtPtr *,
1312 std::random_access_iterator_tag, TPtr> {
1313 using Base = typename CastIterator::iterator_adaptor_base;
1314
1315 CastIterator() : Base(nullptr) {}
1316 CastIterator(StmtPtr *I) : Base(I) {}
1317
1318 typename Base::value_type operator*() const {
1319 return cast_or_null<T>(*this->I);
1320 }
1321 };
1322
1323 /// Const iterator for iterating over Stmt * arrays that contain only T *.
1324 template <typename T>
1326
1329
1330private:
1331 /// Whether statistic collection is enabled.
1332 static bool StatisticsEnabled;
1333
1334protected:
1335 /// Construct an empty statement.
1336 explicit Stmt(StmtClass SC, EmptyShell) : Stmt(SC) {}
1337
1338public:
1339 Stmt() = delete;
1340 Stmt(const Stmt &) = delete;
1341 Stmt(Stmt &&) = delete;
1342 Stmt &operator=(const Stmt &) = delete;
1343 Stmt &operator=(Stmt &&) = delete;
1344
1346 static_assert(sizeof(*this) <= 8,
1347 "changing bitfields changed sizeof(Stmt)");
1348 static_assert(sizeof(*this) % alignof(void *) == 0,
1349 "Insufficient alignment!");
1350 StmtBits.sClass = SC;
1351 if (StatisticsEnabled) Stmt::addStmtClass(SC);
1352 }
1353
1355 return static_cast<StmtClass>(StmtBits.sClass);
1356 }
1357
1358 const char *getStmtClassName() const;
1359
1360 /// SourceLocation tokens are not useful in isolation - they are low level
1361 /// value objects created/interpreted by SourceManager. We assume AST
1362 /// clients will have a pointer to the respective SourceManager.
1363 SourceRange getSourceRange() const LLVM_READONLY;
1364 SourceLocation getBeginLoc() const LLVM_READONLY;
1365 SourceLocation getEndLoc() const LLVM_READONLY;
1366
1367 // global temp stats (until we have a per-module visitor)
1368 static void addStmtClass(const StmtClass s);
1369 static void EnableStatistics();
1370 static void PrintStats();
1371
1372 /// \returns the likelihood of a set of attributes.
1373 static Likelihood getLikelihood(ArrayRef<const Attr *> Attrs);
1374
1375 /// \returns the likelihood of a statement.
1376 static Likelihood getLikelihood(const Stmt *S);
1377
1378 /// \returns the likelihood attribute of a statement.
1379 static const Attr *getLikelihoodAttr(const Stmt *S);
1380
1381 /// \returns the likelihood of the 'then' branch of an 'if' statement. The
1382 /// 'else' branch is required to determine whether both branches specify the
1383 /// same likelihood, which affects the result.
1384 static Likelihood getLikelihood(const Stmt *Then, const Stmt *Else);
1385
1386 /// \returns whether the likelihood of the branches of an if statement are
1387 /// conflicting. When the first element is \c true there's a conflict and
1388 /// the Attr's are the conflicting attributes of the Then and Else Stmt.
1389 static std::tuple<bool, const Attr *, const Attr *>
1390 determineLikelihoodConflict(const Stmt *Then, const Stmt *Else);
1391
1392 /// Dumps the specified AST fragment and all subtrees to
1393 /// \c llvm::errs().
1394 void dump() const;
1395 void dump(raw_ostream &OS, const ASTContext &Context) const;
1396
1397 /// \return Unique reproducible object identifier
1398 int64_t getID(const ASTContext &Context) const;
1399
1400 /// dumpColor - same as dump(), but forces color highlighting.
1401 void dumpColor() const;
1402
1403 /// dumpPretty/printPretty - These two methods do a "pretty print" of the AST
1404 /// back to its original source language syntax.
1405 void dumpPretty(const ASTContext &Context) const;
1406 void printPretty(raw_ostream &OS, PrinterHelper *Helper,
1407 const PrintingPolicy &Policy, unsigned Indentation = 0,
1408 StringRef NewlineSymbol = "\n",
1409 const ASTContext *Context = nullptr) const;
1410 void printPrettyControlled(raw_ostream &OS, PrinterHelper *Helper,
1411 const PrintingPolicy &Policy,
1412 unsigned Indentation = 0,
1413 StringRef NewlineSymbol = "\n",
1414 const ASTContext *Context = nullptr) const;
1415
1416 /// Pretty-prints in JSON format.
1417 void printJson(raw_ostream &Out, PrinterHelper *Helper,
1418 const PrintingPolicy &Policy, bool AddQuotes) const;
1419
1420 /// viewAST - Visualize an AST rooted at this Stmt* using GraphViz. Only
1421 /// works on systems with GraphViz (Mac OS X) or dot+gv installed.
1422 void viewAST() const;
1423
1424 /// Skip no-op (attributed, compound) container stmts and skip captured
1425 /// stmt at the top, if \a IgnoreCaptured is true.
1426 Stmt *IgnoreContainers(bool IgnoreCaptured = false);
1427 const Stmt *IgnoreContainers(bool IgnoreCaptured = false) const {
1428 return const_cast<Stmt *>(this)->IgnoreContainers(IgnoreCaptured);
1429 }
1430
1431 const Stmt *stripLabelLikeStatements() const;
1433 return const_cast<Stmt*>(
1434 const_cast<const Stmt*>(this)->stripLabelLikeStatements());
1435 }
1436
1437 /// Child Iterators: All subclasses must implement 'children'
1438 /// to permit easy iteration over the substatements/subexpressions of an
1439 /// AST node. This permits easy iteration over all nodes in the AST.
1442
1443 using child_range = llvm::iterator_range<child_iterator>;
1444 using const_child_range = llvm::iterator_range<const_child_iterator>;
1445
1447
1449 auto Children = const_cast<Stmt *>(this)->children();
1450 return const_child_range(Children.begin(), Children.end());
1451 }
1452
1453 child_iterator child_begin() { return children().begin(); }
1454 child_iterator child_end() { return children().end(); }
1455
1456 const_child_iterator child_begin() const { return children().begin(); }
1457 const_child_iterator child_end() const { return children().end(); }
1458
1459 /// Produce a unique representation of the given statement.
1460 ///
1461 /// \param ID once the profiling operation is complete, will contain
1462 /// the unique representation of the given statement.
1463 ///
1464 /// \param Context the AST context in which the statement resides
1465 ///
1466 /// \param Canonical whether the profile should be based on the canonical
1467 /// representation of this statement (e.g., where non-type template
1468 /// parameters are identified by index/level rather than their
1469 /// declaration pointers) or the exact representation of the statement as
1470 /// written in the source.
1471 /// \param ProfileLambdaExpr whether or not to profile lambda expressions.
1472 /// When false, the lambda expressions are never considered to be equal to
1473 /// other lambda expressions. When true, the lambda expressions with the same
1474 /// implementation will be considered to be the same. ProfileLambdaExpr should
1475 /// only be true when we try to merge two declarations within modules.
1476 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
1477 bool Canonical, bool ProfileLambdaExpr = false) const;
1478
1479 /// Calculate a unique representation for a statement that is
1480 /// stable across compiler invocations.
1481 ///
1482 /// \param ID profile information will be stored in ID.
1483 ///
1484 /// \param Hash an ODRHash object which will be called where pointers would
1485 /// have been used in the Profile function.
1486 void ProcessODRHash(llvm::FoldingSetNodeID &ID, ODRHash& Hash) const;
1487};
1488
1489/// DeclStmt - Adaptor class for mixing declarations with statements and
1490/// expressions. For example, CompoundStmt mixes statements, expressions
1491/// and declarations (variables, types). Another example is ForStmt, where
1492/// the first statement can be an expression or a declaration.
1493class DeclStmt : public Stmt {
1494 DeclGroupRef DG;
1495 SourceLocation StartLoc, EndLoc;
1496
1497public:
1499 : Stmt(DeclStmtClass), DG(dg), StartLoc(startLoc), EndLoc(endLoc) {}
1500
1501 /// Build an empty declaration statement.
1502 explicit DeclStmt(EmptyShell Empty) : Stmt(DeclStmtClass, Empty) {}
1503
1504 /// isSingleDecl - This method returns true if this DeclStmt refers
1505 /// to a single Decl.
1506 bool isSingleDecl() const { return DG.isSingleDecl(); }
1507
1508 const Decl *getSingleDecl() const { return DG.getSingleDecl(); }
1510
1511 const DeclGroupRef getDeclGroup() const { return DG; }
1513 void setDeclGroup(DeclGroupRef DGR) { DG = DGR; }
1514
1515 void setStartLoc(SourceLocation L) { StartLoc = L; }
1516 SourceLocation getEndLoc() const { return EndLoc; }
1517 void setEndLoc(SourceLocation L) { EndLoc = L; }
1518
1519 SourceLocation getBeginLoc() const LLVM_READONLY { return StartLoc; }
1520
1521 static bool classof(const Stmt *T) {
1522 return T->getStmtClass() == DeclStmtClass;
1523 }
1524
1525 // Iterators over subexpressions.
1527 return child_range(child_iterator(DG.begin(), DG.end()),
1528 child_iterator(DG.end(), DG.end()));
1529 }
1530
1532 auto Children = const_cast<DeclStmt *>(this)->children();
1533 return const_child_range(Children);
1534 }
1535
1538 using decl_range = llvm::iterator_range<decl_iterator>;
1539 using decl_const_range = llvm::iterator_range<const_decl_iterator>;
1540
1542
1545 }
1546
1547 decl_iterator decl_begin() { return DG.begin(); }
1548 decl_iterator decl_end() { return DG.end(); }
1549 const_decl_iterator decl_begin() const { return DG.begin(); }
1550 const_decl_iterator decl_end() const { return DG.end(); }
1551
1552 using reverse_decl_iterator = std::reverse_iterator<decl_iterator>;
1553
1556 }
1557
1560 }
1561};
1562
1563/// NullStmt - This is the null statement ";": C99 6.8.3p3.
1564///
1565class NullStmt : public Stmt {
1566public:
1568 : Stmt(NullStmtClass) {
1569 NullStmtBits.HasLeadingEmptyMacro = hasLeadingEmptyMacro;
1570 setSemiLoc(L);
1571 }
1572
1573 /// Build an empty null statement.
1574 explicit NullStmt(EmptyShell Empty) : Stmt(NullStmtClass, Empty) {}
1575
1576 SourceLocation getSemiLoc() const { return NullStmtBits.SemiLoc; }
1577 void setSemiLoc(SourceLocation L) { NullStmtBits.SemiLoc = L; }
1578
1580 return NullStmtBits.HasLeadingEmptyMacro;
1581 }
1582
1585
1586 static bool classof(const Stmt *T) {
1587 return T->getStmtClass() == NullStmtClass;
1588 }
1589
1592 }
1593
1596 }
1597};
1598
1599/// CompoundStmt - This represents a group of statements like { stmt stmt }.
1600class CompoundStmt final
1601 : public Stmt,
1602 private llvm::TrailingObjects<CompoundStmt, Stmt *, FPOptionsOverride> {
1603 friend class ASTStmtReader;
1604 friend TrailingObjects;
1605
1606 /// The location of the opening "{".
1607 SourceLocation LBraceLoc;
1608
1609 /// The location of the closing "}".
1610 SourceLocation RBraceLoc;
1611
1614 explicit CompoundStmt(EmptyShell Empty) : Stmt(CompoundStmtClass, Empty) {}
1615
1616 void setStmts(ArrayRef<Stmt *> Stmts);
1617
1618 /// Set FPOptionsOverride in trailing storage. Used only by Serialization.
1619 void setStoredFPFeatures(FPOptionsOverride F) {
1620 assert(hasStoredFPFeatures());
1621 *getTrailingObjects<FPOptionsOverride>() = F;
1622 }
1623
1624 size_t numTrailingObjects(OverloadToken<Stmt *>) const {
1625 return CompoundStmtBits.NumStmts;
1626 }
1627
1628public:
1629 static CompoundStmt *Create(const ASTContext &C, ArrayRef<Stmt *> Stmts,
1630 FPOptionsOverride FPFeatures, SourceLocation LB,
1631 SourceLocation RB);
1632
1633 // Build an empty compound statement with a location.
1635 : Stmt(CompoundStmtClass), LBraceLoc(Loc), RBraceLoc(Loc) {
1636 CompoundStmtBits.NumStmts = 0;
1637 CompoundStmtBits.HasFPFeatures = 0;
1638 }
1639
1640 // Build an empty compound statement.
1641 static CompoundStmt *CreateEmpty(const ASTContext &C, unsigned NumStmts,
1642 bool HasFPFeatures);
1643
1644 bool body_empty() const { return CompoundStmtBits.NumStmts == 0; }
1645 unsigned size() const { return CompoundStmtBits.NumStmts; }
1646
1647 bool hasStoredFPFeatures() const { return CompoundStmtBits.HasFPFeatures; }
1648
1649 /// Get FPOptionsOverride from trailing storage.
1651 assert(hasStoredFPFeatures());
1652 return *getTrailingObjects<FPOptionsOverride>();
1653 }
1654
1656 using body_range = llvm::iterator_range<body_iterator>;
1657
1659 body_iterator body_begin() { return getTrailingObjects<Stmt *>(); }
1661 Stmt *body_front() { return !body_empty() ? body_begin()[0] : nullptr; }
1662
1664 return !body_empty() ? body_begin()[size() - 1] : nullptr;
1665 }
1666
1667 using const_body_iterator = Stmt *const *;
1668 using body_const_range = llvm::iterator_range<const_body_iterator>;
1669
1672 }
1673
1675 return getTrailingObjects<Stmt *>();
1676 }
1677
1679
1680 const Stmt *body_front() const {
1681 return !body_empty() ? body_begin()[0] : nullptr;
1682 }
1683
1684 const Stmt *body_back() const {
1685 return !body_empty() ? body_begin()[size() - 1] : nullptr;
1686 }
1687
1688 using reverse_body_iterator = std::reverse_iterator<body_iterator>;
1689
1692 }
1693
1696 }
1697
1699 std::reverse_iterator<const_body_iterator>;
1700
1703 }
1704
1707 }
1708
1709 // Get the Stmt that StmtExpr would consider to be the result of this
1710 // compound statement. This is used by StmtExpr to properly emulate the GCC
1711 // compound expression extension, which ignores trailing NullStmts when
1712 // getting the result of the expression.
1713 // i.e. ({ 5;;; })
1714 // ^^ ignored
1715 // If we don't find something that isn't a NullStmt, just return the last
1716 // Stmt.
1718 for (auto *B : llvm::reverse(body())) {
1719 if (!isa<NullStmt>(B))
1720 return B;
1721 }
1722 return body_back();
1723 }
1724
1725 const Stmt *getStmtExprResult() const {
1726 return const_cast<CompoundStmt *>(this)->getStmtExprResult();
1727 }
1728
1729 SourceLocation getBeginLoc() const { return LBraceLoc; }
1730 SourceLocation getEndLoc() const { return RBraceLoc; }
1731
1732 SourceLocation getLBracLoc() const { return LBraceLoc; }
1733 SourceLocation getRBracLoc() const { return RBraceLoc; }
1734
1735 static bool classof(const Stmt *T) {
1736 return T->getStmtClass() == CompoundStmtClass;
1737 }
1738
1739 // Iterators
1741
1744 }
1745};
1746
1747// SwitchCase is the base class for CaseStmt and DefaultStmt,
1748class SwitchCase : public Stmt {
1749protected:
1750 /// The location of the ":".
1752
1753 // The location of the "case" or "default" keyword. Stored in SwitchCaseBits.
1754 // SourceLocation KeywordLoc;
1755
1756 /// A pointer to the following CaseStmt or DefaultStmt class,
1757 /// used by SwitchStmt.
1759
1761 : Stmt(SC), ColonLoc(ColonLoc) {
1762 setKeywordLoc(KWLoc);
1763 }
1764
1766
1767public:
1771
1772 SourceLocation getKeywordLoc() const { return SwitchCaseBits.KeywordLoc; }
1773 void setKeywordLoc(SourceLocation L) { SwitchCaseBits.KeywordLoc = L; }
1776
1777 inline Stmt *getSubStmt();
1778 const Stmt *getSubStmt() const {
1779 return const_cast<SwitchCase *>(this)->getSubStmt();
1780 }
1781
1783 inline SourceLocation getEndLoc() const LLVM_READONLY;
1784
1785 static bool classof(const Stmt *T) {
1786 return T->getStmtClass() == CaseStmtClass ||
1787 T->getStmtClass() == DefaultStmtClass;
1788 }
1789};
1790
1791/// CaseStmt - Represent a case statement. It can optionally be a GNU case
1792/// statement of the form LHS ... RHS representing a range of cases.
1793class CaseStmt final
1794 : public SwitchCase,
1795 private llvm::TrailingObjects<CaseStmt, Stmt *, SourceLocation> {
1796 friend TrailingObjects;
1797
1798 // CaseStmt is followed by several trailing objects, some of which optional.
1799 // Note that it would be more convenient to put the optional trailing objects
1800 // at the end but this would impact children().
1801 // The trailing objects are in order:
1802 //
1803 // * A "Stmt *" for the LHS of the case statement. Always present.
1804 //
1805 // * A "Stmt *" for the RHS of the case statement. This is a GNU extension
1806 // which allow ranges in cases statement of the form LHS ... RHS.
1807 // Present if and only if caseStmtIsGNURange() is true.
1808 //
1809 // * A "Stmt *" for the substatement of the case statement. Always present.
1810 //
1811 // * A SourceLocation for the location of the ... if this is a case statement
1812 // with a range. Present if and only if caseStmtIsGNURange() is true.
1813 enum { LhsOffset = 0, SubStmtOffsetFromRhs = 1 };
1814 enum { NumMandatoryStmtPtr = 2 };
1815
1816 unsigned numTrailingObjects(OverloadToken<Stmt *>) const {
1817 return NumMandatoryStmtPtr + caseStmtIsGNURange();
1818 }
1819
1820 unsigned numTrailingObjects(OverloadToken<SourceLocation>) const {
1821 return caseStmtIsGNURange();
1822 }
1823
1824 unsigned lhsOffset() const { return LhsOffset; }
1825 unsigned rhsOffset() const { return LhsOffset + caseStmtIsGNURange(); }
1826 unsigned subStmtOffset() const { return rhsOffset() + SubStmtOffsetFromRhs; }
1827
1828 /// Build a case statement assuming that the storage for the
1829 /// trailing objects has been properly allocated.
1830 CaseStmt(Expr *lhs, Expr *rhs, SourceLocation caseLoc,
1831 SourceLocation ellipsisLoc, SourceLocation colonLoc)
1832 : SwitchCase(CaseStmtClass, caseLoc, colonLoc) {
1833 // Handle GNU case statements of the form LHS ... RHS.
1834 bool IsGNURange = rhs != nullptr;
1835 SwitchCaseBits.CaseStmtIsGNURange = IsGNURange;
1836 setLHS(lhs);
1837 setSubStmt(nullptr);
1838 if (IsGNURange) {
1839 setRHS(rhs);
1840 setEllipsisLoc(ellipsisLoc);
1841 }
1842 }
1843
1844 /// Build an empty switch case statement.
1845 explicit CaseStmt(EmptyShell Empty, bool CaseStmtIsGNURange)
1846 : SwitchCase(CaseStmtClass, Empty) {
1847 SwitchCaseBits.CaseStmtIsGNURange = CaseStmtIsGNURange;
1848 }
1849
1850public:
1851 /// Build a case statement.
1852 static CaseStmt *Create(const ASTContext &Ctx, Expr *lhs, Expr *rhs,
1853 SourceLocation caseLoc, SourceLocation ellipsisLoc,
1854 SourceLocation colonLoc);
1855
1856 /// Build an empty case statement.
1857 static CaseStmt *CreateEmpty(const ASTContext &Ctx, bool CaseStmtIsGNURange);
1858
1859 /// True if this case statement is of the form case LHS ... RHS, which
1860 /// is a GNU extension. In this case the RHS can be obtained with getRHS()
1861 /// and the location of the ellipsis can be obtained with getEllipsisLoc().
1862 bool caseStmtIsGNURange() const { return SwitchCaseBits.CaseStmtIsGNURange; }
1863
1866
1867 /// Get the location of the ... in a case statement of the form LHS ... RHS.
1869 return caseStmtIsGNURange() ? *getTrailingObjects<SourceLocation>()
1870 : SourceLocation();
1871 }
1872
1873 /// Set the location of the ... in a case statement of the form LHS ... RHS.
1874 /// Assert that this case statement is of this form.
1876 assert(
1878 "setEllipsisLoc but this is not a case stmt of the form LHS ... RHS!");
1879 *getTrailingObjects<SourceLocation>() = L;
1880 }
1881
1883 return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[lhsOffset()]);
1884 }
1885
1886 const Expr *getLHS() const {
1887 return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[lhsOffset()]);
1888 }
1889
1890 void setLHS(Expr *Val) {
1891 getTrailingObjects<Stmt *>()[lhsOffset()] = reinterpret_cast<Stmt *>(Val);
1892 }
1893
1895 return caseStmtIsGNURange() ? reinterpret_cast<Expr *>(
1896 getTrailingObjects<Stmt *>()[rhsOffset()])
1897 : nullptr;
1898 }
1899
1900 const Expr *getRHS() const {
1901 return caseStmtIsGNURange() ? reinterpret_cast<Expr *>(
1902 getTrailingObjects<Stmt *>()[rhsOffset()])
1903 : nullptr;
1904 }
1905
1906 void setRHS(Expr *Val) {
1907 assert(caseStmtIsGNURange() &&
1908 "setRHS but this is not a case stmt of the form LHS ... RHS!");
1909 getTrailingObjects<Stmt *>()[rhsOffset()] = reinterpret_cast<Stmt *>(Val);
1910 }
1911
1912 Stmt *getSubStmt() { return getTrailingObjects<Stmt *>()[subStmtOffset()]; }
1913 const Stmt *getSubStmt() const {
1914 return getTrailingObjects<Stmt *>()[subStmtOffset()];
1915 }
1916
1917 void setSubStmt(Stmt *S) {
1918 getTrailingObjects<Stmt *>()[subStmtOffset()] = S;
1919 }
1920
1922 SourceLocation getEndLoc() const LLVM_READONLY {
1923 // Handle deeply nested case statements with iteration instead of recursion.
1924 const CaseStmt *CS = this;
1925 while (const auto *CS2 = dyn_cast<CaseStmt>(CS->getSubStmt()))
1926 CS = CS2;
1927
1928 return CS->getSubStmt()->getEndLoc();
1929 }
1930
1931 static bool classof(const Stmt *T) {
1932 return T->getStmtClass() == CaseStmtClass;
1933 }
1934
1935 // Iterators
1937 return child_range(getTrailingObjects<Stmt *>(),
1938 getTrailingObjects<Stmt *>() +
1939 numTrailingObjects(OverloadToken<Stmt *>()));
1940 }
1941
1943 return const_child_range(getTrailingObjects<Stmt *>(),
1944 getTrailingObjects<Stmt *>() +
1945 numTrailingObjects(OverloadToken<Stmt *>()));
1946 }
1947};
1948
1949class DefaultStmt : public SwitchCase {
1950 Stmt *SubStmt;
1951
1952public:
1954 : SwitchCase(DefaultStmtClass, DL, CL), SubStmt(substmt) {}
1955
1956 /// Build an empty default statement.
1957 explicit DefaultStmt(EmptyShell Empty)
1958 : SwitchCase(DefaultStmtClass, Empty) {}
1959
1960 Stmt *getSubStmt() { return SubStmt; }
1961 const Stmt *getSubStmt() const { return SubStmt; }
1962 void setSubStmt(Stmt *S) { SubStmt = S; }
1963
1966
1968 SourceLocation getEndLoc() const LLVM_READONLY {
1969 return SubStmt->getEndLoc();
1970 }
1971
1972 static bool classof(const Stmt *T) {
1973 return T->getStmtClass() == DefaultStmtClass;
1974 }
1975
1976 // Iterators
1977 child_range children() { return child_range(&SubStmt, &SubStmt + 1); }
1978
1980 return const_child_range(&SubStmt, &SubStmt + 1);
1981 }
1982};
1983
1985 if (const auto *CS = dyn_cast<CaseStmt>(this))
1986 return CS->getEndLoc();
1987 else if (const auto *DS = dyn_cast<DefaultStmt>(this))
1988 return DS->getEndLoc();
1989 llvm_unreachable("SwitchCase is neither a CaseStmt nor a DefaultStmt!");
1990}
1991
1993 if (auto *CS = dyn_cast<CaseStmt>(this))
1994 return CS->getSubStmt();
1995 else if (auto *DS = dyn_cast<DefaultStmt>(this))
1996 return DS->getSubStmt();
1997 llvm_unreachable("SwitchCase is neither a CaseStmt nor a DefaultStmt!");
1998}
1999
2000/// Represents a statement that could possibly have a value and type. This
2001/// covers expression-statements, as well as labels and attributed statements.
2002///
2003/// Value statements have a special meaning when they are the last non-null
2004/// statement in a GNU statement expression, where they determine the value
2005/// of the statement expression.
2006class ValueStmt : public Stmt {
2007protected:
2008 using Stmt::Stmt;
2009
2010public:
2011 const Expr *getExprStmt() const;
2013 const ValueStmt *ConstThis = this;
2014 return const_cast<Expr*>(ConstThis->getExprStmt());
2015 }
2016
2017 static bool classof(const Stmt *T) {
2018 return T->getStmtClass() >= firstValueStmtConstant &&
2019 T->getStmtClass() <= lastValueStmtConstant;
2020 }
2021};
2022
2023/// LabelStmt - Represents a label, which has a substatement. For example:
2024/// foo: return;
2025class LabelStmt : public ValueStmt {
2026 LabelDecl *TheDecl;
2027 Stmt *SubStmt;
2028 bool SideEntry = false;
2029
2030public:
2031 /// Build a label statement.
2033 : ValueStmt(LabelStmtClass), TheDecl(D), SubStmt(substmt) {
2034 setIdentLoc(IL);
2035 }
2036
2037 /// Build an empty label statement.
2038 explicit LabelStmt(EmptyShell Empty) : ValueStmt(LabelStmtClass, Empty) {}
2039
2040 SourceLocation getIdentLoc() const { return LabelStmtBits.IdentLoc; }
2041 void setIdentLoc(SourceLocation L) { LabelStmtBits.IdentLoc = L; }
2042
2043 LabelDecl *getDecl() const { return TheDecl; }
2044 void setDecl(LabelDecl *D) { TheDecl = D; }
2045
2046 const char *getName() const;
2047 Stmt *getSubStmt() { return SubStmt; }
2048
2049 const Stmt *getSubStmt() const { return SubStmt; }
2050 void setSubStmt(Stmt *SS) { SubStmt = SS; }
2051
2053 SourceLocation getEndLoc() const LLVM_READONLY { return SubStmt->getEndLoc();}
2054
2055 child_range children() { return child_range(&SubStmt, &SubStmt + 1); }
2056
2058 return const_child_range(&SubStmt, &SubStmt + 1);
2059 }
2060
2061 static bool classof(const Stmt *T) {
2062 return T->getStmtClass() == LabelStmtClass;
2063 }
2064 bool isSideEntry() const { return SideEntry; }
2065 void setSideEntry(bool SE) { SideEntry = SE; }
2066};
2067
2068/// Represents an attribute applied to a statement.
2069///
2070/// Represents an attribute applied to a statement. For example:
2071/// [[omp::for(...)]] for (...) { ... }
2073 : public ValueStmt,
2074 private llvm::TrailingObjects<AttributedStmt, const Attr *> {
2075 friend class ASTStmtReader;
2076 friend TrailingObjects;
2077
2078 Stmt *SubStmt;
2079
2081 Stmt *SubStmt)
2082 : ValueStmt(AttributedStmtClass), SubStmt(SubStmt) {
2083 AttributedStmtBits.NumAttrs = Attrs.size();
2084 AttributedStmtBits.AttrLoc = Loc;
2085 std::copy(Attrs.begin(), Attrs.end(), getAttrArrayPtr());
2086 }
2087
2088 explicit AttributedStmt(EmptyShell Empty, unsigned NumAttrs)
2089 : ValueStmt(AttributedStmtClass, Empty) {
2090 AttributedStmtBits.NumAttrs = NumAttrs;
2092 std::fill_n(getAttrArrayPtr(), NumAttrs, nullptr);
2093 }
2094
2095 const Attr *const *getAttrArrayPtr() const {
2096 return getTrailingObjects<const Attr *>();
2097 }
2098 const Attr **getAttrArrayPtr() { return getTrailingObjects<const Attr *>(); }
2099
2100public:
2101 static AttributedStmt *Create(const ASTContext &C, SourceLocation Loc,
2102 ArrayRef<const Attr *> Attrs, Stmt *SubStmt);
2103
2104 // Build an empty attributed statement.
2105 static AttributedStmt *CreateEmpty(const ASTContext &C, unsigned NumAttrs);
2106
2109 return llvm::ArrayRef(getAttrArrayPtr(), AttributedStmtBits.NumAttrs);
2110 }
2111
2112 Stmt *getSubStmt() { return SubStmt; }
2113 const Stmt *getSubStmt() const { return SubStmt; }
2114
2116 SourceLocation getEndLoc() const LLVM_READONLY { return SubStmt->getEndLoc();}
2117
2118 child_range children() { return child_range(&SubStmt, &SubStmt + 1); }
2119
2121 return const_child_range(&SubStmt, &SubStmt + 1);
2122 }
2123
2124 static bool classof(const Stmt *T) {
2125 return T->getStmtClass() == AttributedStmtClass;
2126 }
2127};
2128
2129/// IfStmt - This represents an if/then/else.
2130class IfStmt final
2131 : public Stmt,
2132 private llvm::TrailingObjects<IfStmt, Stmt *, SourceLocation> {
2133 friend TrailingObjects;
2134
2135 // IfStmt is followed by several trailing objects, some of which optional.
2136 // Note that it would be more convenient to put the optional trailing
2137 // objects at then end but this would change the order of the children.
2138 // The trailing objects are in order:
2139 //
2140 // * A "Stmt *" for the init statement.
2141 // Present if and only if hasInitStorage().
2142 //
2143 // * A "Stmt *" for the condition variable.
2144 // Present if and only if hasVarStorage(). This is in fact a "DeclStmt *".
2145 //
2146 // * A "Stmt *" for the condition.
2147 // Always present. This is in fact a "Expr *".
2148 //
2149 // * A "Stmt *" for the then statement.
2150 // Always present.
2151 //
2152 // * A "Stmt *" for the else statement.
2153 // Present if and only if hasElseStorage().
2154 //
2155 // * A "SourceLocation" for the location of the "else".
2156 // Present if and only if hasElseStorage().
2157 enum { InitOffset = 0, ThenOffsetFromCond = 1, ElseOffsetFromCond = 2 };
2158 enum { NumMandatoryStmtPtr = 2 };
2159 SourceLocation LParenLoc;
2160 SourceLocation RParenLoc;
2161
2162 unsigned numTrailingObjects(OverloadToken<Stmt *>) const {
2163 return NumMandatoryStmtPtr + hasElseStorage() + hasVarStorage() +
2165 }
2166
2167 unsigned numTrailingObjects(OverloadToken<SourceLocation>) const {
2168 return hasElseStorage();
2169 }
2170
2171 unsigned initOffset() const { return InitOffset; }
2172 unsigned varOffset() const { return InitOffset + hasInitStorage(); }
2173 unsigned condOffset() const {
2174 return InitOffset + hasInitStorage() + hasVarStorage();
2175 }
2176 unsigned thenOffset() const { return condOffset() + ThenOffsetFromCond; }
2177 unsigned elseOffset() const { return condOffset() + ElseOffsetFromCond; }
2178
2179 /// Build an if/then/else statement.
2180 IfStmt(const ASTContext &Ctx, SourceLocation IL, IfStatementKind Kind,
2181 Stmt *Init, VarDecl *Var, Expr *Cond, SourceLocation LParenLoc,
2182 SourceLocation RParenLoc, Stmt *Then, SourceLocation EL, Stmt *Else);
2183
2184 /// Build an empty if/then/else statement.
2185 explicit IfStmt(EmptyShell Empty, bool HasElse, bool HasVar, bool HasInit);
2186
2187public:
2188 /// Create an IfStmt.
2189 static IfStmt *Create(const ASTContext &Ctx, SourceLocation IL,
2190 IfStatementKind Kind, Stmt *Init, VarDecl *Var,
2191 Expr *Cond, SourceLocation LPL, SourceLocation RPL,
2192 Stmt *Then, SourceLocation EL = SourceLocation(),
2193 Stmt *Else = nullptr);
2194
2195 /// Create an empty IfStmt optionally with storage for an else statement,
2196 /// condition variable and init expression.
2197 static IfStmt *CreateEmpty(const ASTContext &Ctx, bool HasElse, bool HasVar,
2198 bool HasInit);
2199
2200 /// True if this IfStmt has the storage for an init statement.
2201 bool hasInitStorage() const { return IfStmtBits.HasInit; }
2202
2203 /// True if this IfStmt has storage for a variable declaration.
2204 bool hasVarStorage() const { return IfStmtBits.HasVar; }
2205
2206 /// True if this IfStmt has storage for an else statement.
2207 bool hasElseStorage() const { return IfStmtBits.HasElse; }
2208
2210 return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[condOffset()]);
2211 }
2212
2213 const Expr *getCond() const {
2214 return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[condOffset()]);
2215 }
2216
2217 void setCond(Expr *Cond) {
2218 getTrailingObjects<Stmt *>()[condOffset()] = reinterpret_cast<Stmt *>(Cond);
2219 }
2220
2221 Stmt *getThen() { return getTrailingObjects<Stmt *>()[thenOffset()]; }
2222 const Stmt *getThen() const {
2223 return getTrailingObjects<Stmt *>()[thenOffset()];
2224 }
2225
2226 void setThen(Stmt *Then) {
2227 getTrailingObjects<Stmt *>()[thenOffset()] = Then;
2228 }
2229
2231 return hasElseStorage() ? getTrailingObjects<Stmt *>()[elseOffset()]
2232 : nullptr;
2233 }
2234
2235 const Stmt *getElse() const {
2236 return hasElseStorage() ? getTrailingObjects<Stmt *>()[elseOffset()]
2237 : nullptr;
2238 }
2239
2240 void setElse(Stmt *Else) {
2241 assert(hasElseStorage() &&
2242 "This if statement has no storage for an else statement!");
2243 getTrailingObjects<Stmt *>()[elseOffset()] = Else;
2244 }
2245
2246 /// Retrieve the variable declared in this "if" statement, if any.
2247 ///
2248 /// In the following example, "x" is the condition variable.
2249 /// \code
2250 /// if (int x = foo()) {
2251 /// printf("x is %d", x);
2252 /// }
2253 /// \endcode
2256 return const_cast<IfStmt *>(this)->getConditionVariable();
2257 }
2258
2259 /// Set the condition variable for this if statement.
2260 /// The if statement must have storage for the condition variable.
2261 void setConditionVariable(const ASTContext &Ctx, VarDecl *V);
2262
2263 /// If this IfStmt has a condition variable, return the faux DeclStmt
2264 /// associated with the creation of that condition variable.
2266 return hasVarStorage() ? static_cast<DeclStmt *>(
2267 getTrailingObjects<Stmt *>()[varOffset()])
2268 : nullptr;
2269 }
2270
2272 return hasVarStorage() ? static_cast<DeclStmt *>(
2273 getTrailingObjects<Stmt *>()[varOffset()])
2274 : nullptr;
2275 }
2276
2278 assert(hasVarStorage());
2279 getTrailingObjects<Stmt *>()[varOffset()] = CondVar;
2280 }
2281
2283 return hasInitStorage() ? getTrailingObjects<Stmt *>()[initOffset()]
2284 : nullptr;
2285 }
2286
2287 const Stmt *getInit() const {
2288 return hasInitStorage() ? getTrailingObjects<Stmt *>()[initOffset()]
2289 : nullptr;
2290 }
2291
2293 assert(hasInitStorage() &&
2294 "This if statement has no storage for an init statement!");
2295 getTrailingObjects<Stmt *>()[initOffset()] = Init;
2296 }
2297
2298 SourceLocation getIfLoc() const { return IfStmtBits.IfLoc; }
2299 void setIfLoc(SourceLocation IfLoc) { IfStmtBits.IfLoc = IfLoc; }
2300
2302 return hasElseStorage() ? *getTrailingObjects<SourceLocation>()
2303 : SourceLocation();
2304 }
2305
2307 assert(hasElseStorage() &&
2308 "This if statement has no storage for an else statement!");
2309 *getTrailingObjects<SourceLocation>() = ElseLoc;
2310 }
2311
2312 bool isConsteval() const {
2315 }
2316
2319 }
2320
2321 bool isNegatedConsteval() const {
2323 }
2324
2325 bool isConstexpr() const {
2327 }
2328
2330 IfStmtBits.Kind = static_cast<unsigned>(Kind);
2331 }
2332
2334 return static_cast<IfStatementKind>(IfStmtBits.Kind);
2335 }
2336
2337 /// If this is an 'if constexpr', determine which substatement will be taken.
2338 /// Otherwise, or if the condition is value-dependent, returns std::nullopt.
2339 std::optional<const Stmt *> getNondiscardedCase(const ASTContext &Ctx) const;
2340 std::optional<Stmt *> getNondiscardedCase(const ASTContext &Ctx);
2341
2342 bool isObjCAvailabilityCheck() const;
2343
2345 SourceLocation getEndLoc() const LLVM_READONLY {
2346 if (getElse())
2347 return getElse()->getEndLoc();
2348 return getThen()->getEndLoc();
2349 }
2350 SourceLocation getLParenLoc() const { return LParenLoc; }
2351 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
2352 SourceLocation getRParenLoc() const { return RParenLoc; }
2353 void setRParenLoc(SourceLocation Loc) { RParenLoc = Loc; }
2354
2355 // Iterators over subexpressions. The iterators will include iterating
2356 // over the initialization expression referenced by the condition variable.
2358 // We always store a condition, but there is none for consteval if
2359 // statements, so skip it.
2360 return child_range(getTrailingObjects<Stmt *>() +
2361 (isConsteval() ? thenOffset() : 0),
2362 getTrailingObjects<Stmt *>() +
2363 numTrailingObjects(OverloadToken<Stmt *>()));
2364 }
2365
2367 // We always store a condition, but there is none for consteval if
2368 // statements, so skip it.
2369 return const_child_range(getTrailingObjects<Stmt *>() +
2370 (isConsteval() ? thenOffset() : 0),
2371 getTrailingObjects<Stmt *>() +
2372 numTrailingObjects(OverloadToken<Stmt *>()));
2373 }
2374
2375 static bool classof(const Stmt *T) {
2376 return T->getStmtClass() == IfStmtClass;
2377 }
2378};
2379
2380/// SwitchStmt - This represents a 'switch' stmt.
2381class SwitchStmt final : public Stmt,
2382 private llvm::TrailingObjects<SwitchStmt, Stmt *> {
2383 friend TrailingObjects;
2384
2385 /// Points to a linked list of case and default statements.
2386 SwitchCase *FirstCase = nullptr;
2387
2388 // SwitchStmt is followed by several trailing objects,
2389 // some of which optional. Note that it would be more convenient to
2390 // put the optional trailing objects at the end but this would change
2391 // the order in children().
2392 // The trailing objects are in order:
2393 //
2394 // * A "Stmt *" for the init statement.
2395 // Present if and only if hasInitStorage().
2396 //
2397 // * A "Stmt *" for the condition variable.
2398 // Present if and only if hasVarStorage(). This is in fact a "DeclStmt *".
2399 //
2400 // * A "Stmt *" for the condition.
2401 // Always present. This is in fact an "Expr *".
2402 //
2403 // * A "Stmt *" for the body.
2404 // Always present.
2405 enum { InitOffset = 0, BodyOffsetFromCond = 1 };
2406 enum { NumMandatoryStmtPtr = 2 };
2407 SourceLocation LParenLoc;
2408 SourceLocation RParenLoc;
2409
2410 unsigned numTrailingObjects(OverloadToken<Stmt *>) const {
2411 return NumMandatoryStmtPtr + hasInitStorage() + hasVarStorage();
2412 }
2413
2414 unsigned initOffset() const { return InitOffset; }
2415 unsigned varOffset() const { return InitOffset + hasInitStorage(); }
2416 unsigned condOffset() const {
2417 return InitOffset + hasInitStorage() + hasVarStorage();
2418 }
2419 unsigned bodyOffset() const { return condOffset() + BodyOffsetFromCond; }
2420
2421 /// Build a switch statement.
2422 SwitchStmt(const ASTContext &Ctx, Stmt *Init, VarDecl *Var, Expr *Cond,
2423 SourceLocation LParenLoc, SourceLocation RParenLoc);
2424
2425 /// Build a empty switch statement.
2426 explicit SwitchStmt(EmptyShell Empty, bool HasInit, bool HasVar);
2427
2428public:
2429 /// Create a switch statement.
2430 static SwitchStmt *Create(const ASTContext &Ctx, Stmt *Init, VarDecl *Var,
2431 Expr *Cond, SourceLocation LParenLoc,
2432 SourceLocation RParenLoc);
2433
2434 /// Create an empty switch statement optionally with storage for
2435 /// an init expression and a condition variable.
2436 static SwitchStmt *CreateEmpty(const ASTContext &Ctx, bool HasInit,
2437 bool HasVar);
2438
2439 /// True if this SwitchStmt has storage for an init statement.
2440 bool hasInitStorage() const { return SwitchStmtBits.HasInit; }
2441
2442 /// True if this SwitchStmt has storage for a condition variable.
2443 bool hasVarStorage() const { return SwitchStmtBits.HasVar; }
2444
2446 return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[condOffset()]);
2447 }
2448
2449 const Expr *getCond() const {
2450 return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[condOffset()]);
2451 }
2452
2453 void setCond(Expr *Cond) {
2454 getTrailingObjects<Stmt *>()[condOffset()] = reinterpret_cast<Stmt *>(Cond);
2455 }
2456
2457 Stmt *getBody() { return getTrailingObjects<Stmt *>()[bodyOffset()]; }
2458 const Stmt *getBody() const {
2459 return getTrailingObjects<Stmt *>()[bodyOffset()];
2460 }
2461
2462 void setBody(Stmt *Body) {
2463 getTrailingObjects<Stmt *>()[bodyOffset()] = Body;
2464 }
2465
2467 return hasInitStorage() ? getTrailingObjects<Stmt *>()[initOffset()]
2468 : nullptr;
2469 }
2470
2471 const Stmt *getInit() const {
2472 return hasInitStorage() ? getTrailingObjects<Stmt *>()[initOffset()]
2473 : nullptr;
2474 }
2475
2477 assert(hasInitStorage() &&
2478 "This switch statement has no storage for an init statement!");
2479 getTrailingObjects<Stmt *>()[initOffset()] = Init;
2480 }
2481
2482 /// Retrieve the variable declared in this "switch" statement, if any.
2483 ///
2484 /// In the following example, "x" is the condition variable.
2485 /// \code
2486 /// switch (int x = foo()) {
2487 /// case 0: break;
2488 /// // ...
2489 /// }
2490 /// \endcode
2493 return const_cast<SwitchStmt *>(this)->getConditionVariable();
2494 }
2495
2496 /// Set the condition variable in this switch statement.
2497 /// The switch statement must have storage for it.
2498 void setConditionVariable(const ASTContext &Ctx, VarDecl *VD);
2499
2500 /// If this SwitchStmt has a condition variable, return the faux DeclStmt
2501 /// associated with the creation of that condition variable.
2503 return hasVarStorage() ? static_cast<DeclStmt *>(
2504 getTrailingObjects<Stmt *>()[varOffset()])
2505 : nullptr;
2506 }
2507
2509 return hasVarStorage() ? static_cast<DeclStmt *>(
2510 getTrailingObjects<Stmt *>()[varOffset()])
2511 : nullptr;
2512 }
2513
2515 assert(hasVarStorage());
2516 getTrailingObjects<Stmt *>()[varOffset()] = CondVar;
2517 }
2518
2519 SwitchCase *getSwitchCaseList() { return FirstCase; }
2520 const SwitchCase *getSwitchCaseList() const { return FirstCase; }
2521 void setSwitchCaseList(SwitchCase *SC) { FirstCase = SC; }
2522
2523 SourceLocation getSwitchLoc() const { return SwitchStmtBits.SwitchLoc; }
2524 void setSwitchLoc(SourceLocation L) { SwitchStmtBits.SwitchLoc = L; }
2525 SourceLocation getLParenLoc() const { return LParenLoc; }
2526 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
2527 SourceLocation getRParenLoc() const { return RParenLoc; }
2528 void setRParenLoc(SourceLocation Loc) { RParenLoc = Loc; }
2529
2531 setBody(S);
2532 setSwitchLoc(SL);
2533 }
2534
2536 assert(!SC->getNextSwitchCase() &&
2537 "case/default already added to a switch");
2538 SC->setNextSwitchCase(FirstCase);
2539 FirstCase = SC;
2540 }
2541
2542 /// Set a flag in the SwitchStmt indicating that if the 'switch (X)' is a
2543 /// switch over an enum value then all cases have been explicitly covered.
2544 void setAllEnumCasesCovered() { SwitchStmtBits.AllEnumCasesCovered = true; }
2545
2546 /// Returns true if the SwitchStmt is a switch of an enum value and all cases
2547 /// have been explicitly covered.
2549 return SwitchStmtBits.AllEnumCasesCovered;
2550 }
2551
2553 SourceLocation getEndLoc() const LLVM_READONLY {
2554 return getBody() ? getBody()->getEndLoc()
2555 : reinterpret_cast<const Stmt *>(getCond())->getEndLoc();
2556 }
2557
2558 // Iterators
2560 return child_range(getTrailingObjects<Stmt *>(),
2561 getTrailingObjects<Stmt *>() +
2562 numTrailingObjects(OverloadToken<Stmt *>()));
2563 }
2564
2566 return const_child_range(getTrailingObjects<Stmt *>(),
2567 getTrailingObjects<Stmt *>() +
2568 numTrailingObjects(OverloadToken<Stmt *>()));
2569 }
2570
2571 static bool classof(const Stmt *T) {
2572 return T->getStmtClass() == SwitchStmtClass;
2573 }
2574};
2575
2576/// WhileStmt - This represents a 'while' stmt.
2577class WhileStmt final : public Stmt,
2578 private llvm::TrailingObjects<WhileStmt, Stmt *> {
2579 friend TrailingObjects;
2580
2581 // WhileStmt is followed by several trailing objects,
2582 // some of which optional. Note that it would be more
2583 // convenient to put the optional trailing object at the end
2584 // but this would affect children().
2585 // The trailing objects are in order:
2586 //
2587 // * A "Stmt *" for the condition variable.
2588 // Present if and only if hasVarStorage(). This is in fact a "DeclStmt *".
2589 //
2590 // * A "Stmt *" for the condition.
2591 // Always present. This is in fact an "Expr *".
2592 //
2593 // * A "Stmt *" for the body.
2594 // Always present.
2595 //
2596 enum { VarOffset = 0, BodyOffsetFromCond = 1 };
2597 enum { NumMandatoryStmtPtr = 2 };
2598
2599 SourceLocation LParenLoc, RParenLoc;
2600
2601 unsigned varOffset() const { return VarOffset; }
2602 unsigned condOffset() const { return VarOffset + hasVarStorage(); }
2603 unsigned bodyOffset() const { return condOffset() + BodyOffsetFromCond; }
2604
2605 unsigned numTrailingObjects(OverloadToken<Stmt *>) const {
2606 return NumMandatoryStmtPtr + hasVarStorage();
2607 }
2608
2609 /// Build a while statement.
2610 WhileStmt(const ASTContext &Ctx, VarDecl *Var, Expr *Cond, Stmt *Body,
2611 SourceLocation WL, SourceLocation LParenLoc,
2612 SourceLocation RParenLoc);
2613
2614 /// Build an empty while statement.
2615 explicit WhileStmt(EmptyShell Empty, bool HasVar);
2616
2617public:
2618 /// Create a while statement.
2619 static WhileStmt *Create(const ASTContext &Ctx, VarDecl *Var, Expr *Cond,
2620 Stmt *Body, SourceLocation WL,
2621 SourceLocation LParenLoc, SourceLocation RParenLoc);
2622
2623 /// Create an empty while statement optionally with storage for
2624 /// a condition variable.
2625 static WhileStmt *CreateEmpty(const ASTContext &Ctx, bool HasVar);
2626
2627 /// True if this WhileStmt has storage for a condition variable.
2628 bool hasVarStorage() const { return WhileStmtBits.HasVar; }
2629
2631 return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[condOffset()]);
2632 }
2633
2634 const Expr *getCond() const {
2635 return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[condOffset()]);
2636 }
2637
2638 void setCond(Expr *Cond) {
2639 getTrailingObjects<Stmt *>()[condOffset()] = reinterpret_cast<Stmt *>(Cond);
2640 }
2641
2642 Stmt *getBody() { return getTrailingObjects<Stmt *>()[bodyOffset()]; }
2643 const Stmt *getBody() const {
2644 return getTrailingObjects<Stmt *>()[bodyOffset()];
2645 }
2646
2647 void setBody(Stmt *Body) {
2648 getTrailingObjects<Stmt *>()[bodyOffset()] = Body;
2649 }
2650
2651 /// Retrieve the variable declared in this "while" statement, if any.
2652 ///
2653 /// In the following example, "x" is the condition variable.
2654 /// \code
2655 /// while (int x = random()) {
2656 /// // ...
2657 /// }
2658 /// \endcode
2661 return const_cast<WhileStmt *>(this)->getConditionVariable();
2662 }
2663
2664 /// Set the condition variable of this while statement.
2665 /// The while statement must have storage for it.
2666 void setConditionVariable(const ASTContext &Ctx, VarDecl *V);
2667
2668 /// If this WhileStmt has a condition variable, return the faux DeclStmt
2669 /// associated with the creation of that condition variable.
2671 return hasVarStorage() ? static_cast<DeclStmt *>(
2672 getTrailingObjects<Stmt *>()[varOffset()])
2673 : nullptr;
2674 }
2675
2677 return hasVarStorage() ? static_cast<DeclStmt *>(
2678 getTrailingObjects<Stmt *>()[varOffset()])
2679 : nullptr;
2680 }
2681
2683 assert(hasVarStorage());
2684 getTrailingObjects<Stmt *>()[varOffset()] = CondVar;
2685 }
2686
2687 SourceLocation getWhileLoc() const { return WhileStmtBits.WhileLoc; }
2688 void setWhileLoc(SourceLocation L) { WhileStmtBits.WhileLoc = L; }
2689
2690 SourceLocation getLParenLoc() const { return LParenLoc; }
2691 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2692 SourceLocation getRParenLoc() const { return RParenLoc; }
2693 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2694
2696 SourceLocation getEndLoc() const LLVM_READONLY {
2697 return getBody()->getEndLoc();
2698 }
2699
2700 static bool classof(const Stmt *T) {
2701 return T->getStmtClass() == WhileStmtClass;
2702 }
2703
2704 // Iterators
2706 return child_range(getTrailingObjects<Stmt *>(),
2707 getTrailingObjects<Stmt *>() +
2708 numTrailingObjects(OverloadToken<Stmt *>()));
2709 }
2710
2712 return const_child_range(getTrailingObjects<Stmt *>(),
2713 getTrailingObjects<Stmt *>() +
2714 numTrailingObjects(OverloadToken<Stmt *>()));
2715 }
2716};
2717
2718/// DoStmt - This represents a 'do/while' stmt.
2719class DoStmt : public Stmt {
2720 enum { BODY, COND, END_EXPR };
2721 Stmt *SubExprs[END_EXPR];
2722 SourceLocation WhileLoc;
2723 SourceLocation RParenLoc; // Location of final ')' in do stmt condition.
2724
2725public:
2727 SourceLocation RP)
2728 : Stmt(DoStmtClass), WhileLoc(WL), RParenLoc(RP) {
2729 setCond(Cond);
2730 setBody(Body);
2731 setDoLoc(DL);
2732 }
2733
2734 /// Build an empty do-while statement.
2735 explicit DoStmt(EmptyShell Empty) : Stmt(DoStmtClass, Empty) {}
2736
2737 Expr *getCond() { return reinterpret_cast<Expr *>(SubExprs[COND]); }
2738 const Expr *getCond() const {
2739 return reinterpret_cast<Expr *>(SubExprs[COND]);
2740 }
2741
2742 void setCond(Expr *Cond) { SubExprs[COND] = reinterpret_cast<Stmt *>(Cond); }
2743
2744 Stmt *getBody() { return SubExprs[BODY]; }
2745 const Stmt *getBody() const { return SubExprs[BODY]; }
2746 void setBody(Stmt *Body) { SubExprs[BODY] = Body; }
2747
2748 SourceLocation getDoLoc() const { return DoStmtBits.DoLoc; }
2749 void setDoLoc(SourceLocation L) { DoStmtBits.DoLoc = L; }
2750 SourceLocation getWhileLoc() const { return WhileLoc; }
2751 void setWhileLoc(SourceLocation L) { WhileLoc = L; }
2752 SourceLocation getRParenLoc() const { return RParenLoc; }
2753 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2754
2757
2758 static bool classof(const Stmt *T) {
2759 return T->getStmtClass() == DoStmtClass;
2760 }
2761
2762 // Iterators
2764 return child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
2765 }
2766
2768 return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
2769 }
2770};
2771
2772/// ForStmt - This represents a 'for (init;cond;inc)' stmt. Note that any of
2773/// the init/cond/inc parts of the ForStmt will be null if they were not
2774/// specified in the source.
2775class ForStmt : public Stmt {
2776 friend class ASTStmtReader;
2777
2778 enum { INIT, CONDVAR, COND, INC, BODY, END_EXPR };
2779 Stmt* SubExprs[END_EXPR]; // SubExprs[INIT] is an expression or declstmt.
2780 SourceLocation LParenLoc, RParenLoc;
2781
2782public:
2783 ForStmt(const ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar,
2784 Expr *Inc, Stmt *Body, SourceLocation FL, SourceLocation LP,
2785 SourceLocation RP);
2786
2787 /// Build an empty for statement.
2788 explicit ForStmt(EmptyShell Empty) : Stmt(ForStmtClass, Empty) {}
2789
2790 Stmt *getInit() { return SubExprs[INIT]; }
2791
2792 /// Retrieve the variable declared in this "for" statement, if any.
2793 ///
2794 /// In the following example, "y" is the condition variable.
2795 /// \code
2796 /// for (int x = random(); int y = mangle(x); ++x) {
2797 /// // ...
2798 /// }
2799 /// \endcode
2801 void setConditionVariable(const ASTContext &C, VarDecl *V);
2802
2803 /// If this ForStmt has a condition variable, return the faux DeclStmt
2804 /// associated with the creation of that condition variable.
2806 return reinterpret_cast<DeclStmt*>(SubExprs[CONDVAR]);
2807 }
2808
2810 return reinterpret_cast<DeclStmt*>(SubExprs[CONDVAR]);
2811 }
2812
2814 SubExprs[CONDVAR] = CondVar;
2815 }
2816
2817 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
2818 Expr *getInc() { return reinterpret_cast<Expr*>(SubExprs[INC]); }
2819 Stmt *getBody() { return SubExprs[BODY]; }
2820
2821 const Stmt *getInit() const { return SubExprs[INIT]; }
2822 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
2823 const Expr *getInc() const { return reinterpret_cast<Expr*>(SubExprs[INC]); }
2824 const Stmt *getBody() const { return SubExprs[BODY]; }
2825
2826 void setInit(Stmt *S) { SubExprs[INIT] = S; }
2827 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
2828 void setInc(Expr *E) { SubExprs[INC] = reinterpret_cast<Stmt*>(E); }
2829 void setBody(Stmt *S) { SubExprs[BODY] = S; }
2830
2831 SourceLocation getForLoc() const { return ForStmtBits.ForLoc; }
2832 void setForLoc(SourceLocation L) { ForStmtBits.ForLoc = L; }
2833 SourceLocation getLParenLoc() const { return LParenLoc; }
2834 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2835 SourceLocation getRParenLoc() const { return RParenLoc; }
2836 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2837
2840
2841 static bool classof(const Stmt *T) {
2842 return T->getStmtClass() == ForStmtClass;
2843 }
2844
2845 // Iterators
2847 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
2848 }
2849
2851 return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
2852 }
2853};
2854
2855/// GotoStmt - This represents a direct goto.
2856class GotoStmt : public Stmt {
2857 LabelDecl *Label;
2858 SourceLocation LabelLoc;
2859
2860public:
2862 : Stmt(GotoStmtClass), Label(label), LabelLoc(LL) {
2863 setGotoLoc(GL);
2864 }
2865
2866 /// Build an empty goto statement.
2867 explicit GotoStmt(EmptyShell Empty) : Stmt(GotoStmtClass, Empty) {}
2868
2869 LabelDecl *getLabel() const { return Label; }
2870 void setLabel(LabelDecl *D) { Label = D; }
2871
2872 SourceLocation getGotoLoc() const { return GotoStmtBits.GotoLoc; }
2873 void setGotoLoc(SourceLocation L) { GotoStmtBits.GotoLoc = L; }
2874 SourceLocation getLabelLoc() const { return LabelLoc; }
2875 void setLabelLoc(SourceLocation L) { LabelLoc = L; }
2876
2879
2880 static bool classof(const Stmt *T) {
2881 return T->getStmtClass() == GotoStmtClass;
2882 }
2883
2884 // Iterators
2887 }
2888
2891 }
2892};
2893
2894/// IndirectGotoStmt - This represents an indirect goto.
2895class IndirectGotoStmt : public Stmt {
2896 SourceLocation StarLoc;
2897 Stmt *Target;
2898
2899public:
2901 : Stmt(IndirectGotoStmtClass), StarLoc(starLoc) {
2902 setTarget(target);
2903 setGotoLoc(gotoLoc);
2904 }
2905
2906 /// Build an empty indirect goto statement.
2908 : Stmt(IndirectGotoStmtClass, Empty) {}
2909
2910 void setGotoLoc(SourceLocation L) { GotoStmtBits.GotoLoc = L; }
2911 SourceLocation getGotoLoc() const { return GotoStmtBits.GotoLoc; }
2912 void setStarLoc(SourceLocation L) { StarLoc = L; }
2913 SourceLocation getStarLoc() const { return StarLoc; }
2914
2915 Expr *getTarget() { return reinterpret_cast<Expr *>(Target); }
2916 const Expr *getTarget() const {
2917 return reinterpret_cast<const Expr *>(Target);
2918 }
2919 void setTarget(Expr *E) { Target = reinterpret_cast<Stmt *>(E); }
2920
2921 /// getConstantTarget - Returns the fixed target of this indirect
2922 /// goto, if one exists.
2925 return const_cast<IndirectGotoStmt *>(this)->getConstantTarget();
2926 }
2927
2929 SourceLocation getEndLoc() const LLVM_READONLY { return Target->getEndLoc(); }
2930
2931 static bool classof(const Stmt *T) {
2932 return T->getStmtClass() == IndirectGotoStmtClass;
2933 }
2934
2935 // Iterators
2937
2939 return const_child_range(&Target, &Target + 1);
2940 }
2941};
2942
2943/// ContinueStmt - This represents a continue.
2944class ContinueStmt : public Stmt {
2945public:
2946 ContinueStmt(SourceLocation CL) : Stmt(ContinueStmtClass) {
2947 setContinueLoc(CL);
2948 }
2949
2950 /// Build an empty continue statement.
2951 explicit ContinueStmt(EmptyShell Empty) : Stmt(ContinueStmtClass, Empty) {}
2952
2953 SourceLocation getContinueLoc() const { return ContinueStmtBits.ContinueLoc; }
2955
2958
2959 static bool classof(const Stmt *T) {
2960 return T->getStmtClass() == ContinueStmtClass;
2961 }
2962
2963 // Iterators
2966 }
2967
2970 }
2971};
2972
2973/// BreakStmt - This represents a break.
2974class BreakStmt : public Stmt {
2975public:
2976 BreakStmt(SourceLocation BL) : Stmt(BreakStmtClass) {
2977 setBreakLoc(BL);
2978 }
2979
2980 /// Build an empty break statement.
2981 explicit BreakStmt(EmptyShell Empty) : Stmt(BreakStmtClass, Empty) {}
2982
2983 SourceLocation getBreakLoc() const { return BreakStmtBits.BreakLoc; }
2984 void setBreakLoc(SourceLocation L) { BreakStmtBits.BreakLoc = L; }
2985
2988
2989 static bool classof(const Stmt *T) {
2990 return T->getStmtClass() == BreakStmtClass;
2991 }
2992
2993 // Iterators
2996 }
2997
3000 }
3001};
3002
3003/// ReturnStmt - This represents a return, optionally of an expression:
3004/// return;
3005/// return 4;
3006///
3007/// Note that GCC allows return with no argument in a function declared to
3008/// return a value, and it allows returning a value in functions declared to
3009/// return void. We explicitly model this in the AST, which means you can't
3010/// depend on the return type of the function and the presence of an argument.
3011class ReturnStmt final
3012 : public Stmt,
3013 private llvm::TrailingObjects<ReturnStmt, const VarDecl *> {
3014 friend TrailingObjects;
3015
3016 /// The return expression.
3017 Stmt *RetExpr;
3018
3019 // ReturnStmt is followed optionally by a trailing "const VarDecl *"
3020 // for the NRVO candidate. Present if and only if hasNRVOCandidate().
3021
3022 /// True if this ReturnStmt has storage for an NRVO candidate.
3023 bool hasNRVOCandidate() const { return ReturnStmtBits.HasNRVOCandidate; }
3024
3025 unsigned numTrailingObjects(OverloadToken<const VarDecl *>) const {
3026 return hasNRVOCandidate();
3027 }
3028
3029 /// Build a return statement.
3030 ReturnStmt(SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate);
3031
3032 /// Build an empty return statement.
3033 explicit ReturnStmt(EmptyShell Empty, bool HasNRVOCandidate);
3034
3035public:
3036 /// Create a return statement.
3037 static ReturnStmt *Create(const ASTContext &Ctx, SourceLocation RL, Expr *E,
3038 const VarDecl *NRVOCandidate);
3039
3040 /// Create an empty return statement, optionally with
3041 /// storage for an NRVO candidate.
3042 static ReturnStmt *CreateEmpty(const ASTContext &Ctx, bool HasNRVOCandidate);
3043
3044 Expr *getRetValue() { return reinterpret_cast<Expr *>(RetExpr); }
3045 const Expr *getRetValue() const { return reinterpret_cast<Expr *>(RetExpr); }
3046 void setRetValue(Expr *E) { RetExpr = reinterpret_cast<Stmt *>(E); }
3047
3048 /// Retrieve the variable that might be used for the named return
3049 /// value optimization.
3050 ///
3051 /// The optimization itself can only be performed if the variable is
3052 /// also marked as an NRVO object.
3053 const VarDecl *getNRVOCandidate() const {
3054 return hasNRVOCandidate() ? *getTrailingObjects<const VarDecl *>()
3055 : nullptr;
3056 }
3057
3058 /// Set the variable that might be used for the named return value
3059 /// optimization. The return statement must have storage for it,
3060 /// which is the case if and only if hasNRVOCandidate() is true.
3061 void setNRVOCandidate(const VarDecl *Var) {
3062 assert(hasNRVOCandidate() &&
3063 "This return statement has no storage for an NRVO candidate!");
3064 *getTrailingObjects<const VarDecl *>() = Var;
3065 }
3066
3067 SourceLocation getReturnLoc() const { return ReturnStmtBits.RetLoc; }
3069
3071 SourceLocation getEndLoc() const LLVM_READONLY {
3072 return RetExpr ? RetExpr->getEndLoc() : getReturnLoc();
3073 }
3074
3075 static bool classof(const Stmt *T) {
3076 return T->getStmtClass() == ReturnStmtClass;
3077 }
3078
3079 // Iterators
3081 if (RetExpr)
3082 return child_range(&RetExpr, &RetExpr + 1);
3084 }
3085
3087 if (RetExpr)
3088 return const_child_range(&RetExpr, &RetExpr + 1);
3090 }
3091};
3092
3093/// AsmStmt is the base class for GCCAsmStmt and MSAsmStmt.
3094class AsmStmt : public Stmt {
3095protected:
3096 friend class ASTStmtReader;
3097
3099
3100 /// True if the assembly statement does not have any input or output
3101 /// operands.
3103
3104 /// If true, treat this inline assembly as having side effects.
3105 /// This assembly statement should not be optimized, deleted or moved.
3107
3108 unsigned NumOutputs;
3109 unsigned NumInputs;
3110 unsigned NumClobbers;
3111
3112 Stmt **Exprs = nullptr;
3113
3114 AsmStmt(StmtClass SC, SourceLocation asmloc, bool issimple, bool isvolatile,
3115 unsigned numoutputs, unsigned numinputs, unsigned numclobbers)
3116 : Stmt (SC), AsmLoc(asmloc), IsSimple(issimple), IsVolatile(isvolatile),
3117 NumOutputs(numoutputs), NumInputs(numinputs),
3118 NumClobbers(numclobbers) {}
3119
3120public:
3121 /// Build an empty inline-assembly statement.
3122 explicit AsmStmt(StmtClass SC, EmptyShell Empty) : Stmt(SC, Empty) {}
3123
3124 SourceLocation getAsmLoc() const { return AsmLoc; }
3126
3127 bool isSimple() const { return IsSimple; }
3128 void setSimple(bool V) { IsSimple = V; }
3129
3130 bool isVolatile() const { return IsVolatile; }
3131 void setVolatile(bool V) { IsVolatile = V; }
3132
3133 SourceLocation getBeginLoc() const LLVM_READONLY { return {}; }
3134 SourceLocation getEndLoc() const LLVM_READONLY { return {}; }
3135
3136 //===--- Asm String Analysis ---===//
3137
3138 /// Assemble final IR asm string.
3139 std::string generateAsmString(const ASTContext &C) const;
3140
3141 //===--- Output operands ---===//
3142
3143 unsigned getNumOutputs() const { return NumOutputs; }
3144
3145 /// getOutputConstraint - Return the constraint string for the specified
3146 /// output operand. All output constraints are known to be non-empty (either
3147 /// '=' or '+').
3148 StringRef getOutputConstraint(unsigned i) const;
3149
3150 /// isOutputPlusConstraint - Return true if the specified output constraint
3151 /// is a "+" constraint (which is both an input and an output) or false if it
3152 /// is an "=" constraint (just an output).
3153 bool isOutputPlusConstraint(unsigned i) const {
3154 return getOutputConstraint(i)[0] == '+';
3155 }
3156
3157 const Expr *getOutputExpr(unsigned i) const;
3158
3159 /// getNumPlusOperands - Return the number of output operands that have a "+"
3160 /// constraint.
3161 unsigned getNumPlusOperands() const;
3162
3163 //===--- Input operands ---===//
3164
3165 unsigned getNumInputs() const { return NumInputs; }
3166
3167 /// getInputConstraint - Return the specified input constraint. Unlike output
3168 /// constraints, these can be empty.
3169 StringRef getInputConstraint(unsigned i) const;
3170
3171 const Expr *getInputExpr(unsigned i) const;
3172
3173 //===--- Other ---===//
3174
3175 unsigned getNumClobbers() const { return NumClobbers; }
3176 StringRef getClobber(unsigned i) const;
3177
3178 static bool classof(const Stmt *T) {
3179 return T->getStmtClass() == GCCAsmStmtClass ||
3180 T->getStmtClass() == MSAsmStmtClass;
3181 }
3182
3183 // Input expr iterators.
3184
3187 using inputs_range = llvm::iterator_range<inputs_iterator>;
3188 using inputs_const_range = llvm::iterator_range<const_inputs_iterator>;
3189
3191 return &Exprs[0] + NumOutputs;
3192 }
3193
3195 return &Exprs[0] + NumOutputs + NumInputs;
3196 }
3197
3199
3201 return &Exprs[0] + NumOutputs;
3202 }
3203
3205 return &Exprs[0] + NumOutputs + NumInputs;
3206 }
3207
3210 }
3211
3212 // Output expr iterators.
3213
3216 using outputs_range = llvm::iterator_range<outputs_iterator>;
3217 using outputs_const_range = llvm::iterator_range<const_outputs_iterator>;
3218
3220 return &Exprs[0];
3221 }
3222
3224 return &Exprs[0] + NumOutputs;
3225 }
3226
3229 }
3230
3232 return &Exprs[0];
3233 }
3234
3236 return &Exprs[0] + NumOutputs;
3237 }
3238
3241 }
3242
3244 return child_range(&Exprs[0], &Exprs[0] + NumOutputs + NumInputs);
3245 }
3246
3248 return const_child_range(&Exprs[0], &Exprs[0] + NumOutputs + NumInputs);
3249 }
3250};
3251
3252/// This represents a GCC inline-assembly statement extension.
3253class GCCAsmStmt : public AsmStmt {
3254 friend class ASTStmtReader;
3255
3256 SourceLocation RParenLoc;
3257 StringLiteral *AsmStr;
3258
3259 // FIXME: If we wanted to, we could allocate all of these in one big array.
3260 StringLiteral **Constraints = nullptr;
3261 StringLiteral **Clobbers = nullptr;
3262 IdentifierInfo **Names = nullptr;
3263 unsigned NumLabels = 0;
3264
3265public:
3266 GCCAsmStmt(const ASTContext &C, SourceLocation asmloc, bool issimple,
3267 bool isvolatile, unsigned numoutputs, unsigned numinputs,
3268 IdentifierInfo **names, StringLiteral **constraints, Expr **exprs,
3269 StringLiteral *asmstr, unsigned numclobbers,
3270 StringLiteral **clobbers, unsigned numlabels,
3271 SourceLocation rparenloc);
3272
3273 /// Build an empty inline-assembly statement.
3274 explicit GCCAsmStmt(EmptyShell Empty) : AsmStmt(GCCAsmStmtClass, Empty) {}
3275
3276 SourceLocation getRParenLoc() const { return RParenLoc; }
3277 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
3278
3279 //===--- Asm String Analysis ---===//
3280
3281 const StringLiteral *getAsmString() const { return AsmStr; }
3282 StringLiteral *getAsmString() { return AsmStr; }
3283 void setAsmString(StringLiteral *E) { AsmStr = E; }
3284
3285 /// AsmStringPiece - this is part of a decomposed asm string specification
3286 /// (for use with the AnalyzeAsmString function below). An asm string is
3287 /// considered to be a concatenation of these parts.
3289 public:
3290 enum Kind {
3291 String, // String in .ll asm string form, "$" -> "$$" and "%%" -> "%".
3292 Operand // Operand reference, with optional modifier %c4.
3294
3295 private:
3296 Kind MyKind;
3297 std::string Str;
3298 unsigned OperandNo;
3299
3300 // Source range for operand references.
3301 CharSourceRange Range;
3302
3303 public:
3304 AsmStringPiece(const std::string &S) : MyKind(String), Str(S) {}
3305 AsmStringPiece(unsigned OpNo, const std::string &S, SourceLocation Begin,
3306 SourceLocation End)
3307 : MyKind(Operand), Str(S), OperandNo(OpNo),
3308 Range(CharSourceRange::getCharRange(Begin, End)) {}
3309
3310 bool isString() const { return MyKind == String; }
3311 bool isOperand() const { return MyKind == Operand; }
3312
3313 const std::string &getString() const { return Str; }
3314
3315 unsigned getOperandNo() const {
3316 assert(isOperand());
3317 return OperandNo;
3318 }
3319
3321 assert(isOperand() && "Range is currently used only for Operands.");
3322 return Range;
3323 }
3324
3325 /// getModifier - Get the modifier for this operand, if present. This
3326 /// returns '\0' if there was no modifier.
3327 char getModifier() const;
3328 };
3329
3330 /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing
3331 /// it into pieces. If the asm string is erroneous, emit errors and return
3332 /// true, otherwise return false. This handles canonicalization and
3333 /// translation of strings from GCC syntax to LLVM IR syntax, and handles
3334 //// flattening of named references like %[foo] to Operand AsmStringPiece's.
3336 const ASTContext &C, unsigned &DiagOffs) const;
3337
3338 /// Assemble final IR asm string.
3339 std::string generateAsmString(const ASTContext &C) const;
3340
3341 //===--- Output operands ---===//
3342
3343 IdentifierInfo *getOutputIdentifier(unsigned i) const { return Names[i]; }
3344
3345 StringRef getOutputName(unsigned i) const {
3347 return II->getName();
3348
3349 return {};
3350 }
3351
3352 StringRef getOutputConstraint(unsigned i) const;
3353
3355 return Constraints[i];
3356 }
3358 return Constraints[i];
3359 }
3360
3361 Expr *getOutputExpr(unsigned i);
3362
3363 const Expr *getOutputExpr(unsigned i) const {
3364 return const_cast<GCCAsmStmt*>(this)->getOutputExpr(i);
3365 }
3366
3367 //===--- Input operands ---===//
3368
3370 return Names[i + NumOutputs];
3371 }
3372
3373 StringRef getInputName(unsigned i) const {
3375 return II->getName();
3376
3377 return {};
3378 }
3379
3380 StringRef getInputConstraint(unsigned i) const;
3381
3382 const StringLiteral *getInputConstraintLiteral(unsigned i) const {
3383 return Constraints[i + NumOutputs];
3384 }
3386 return Constraints[i + NumOutputs];
3387 }
3388
3389 Expr *getInputExpr(unsigned i);
3390 void setInputExpr(unsigned i, Expr *E);
3391
3392 const Expr *getInputExpr(unsigned i) const {
3393 return const_cast<GCCAsmStmt*>(this)->getInputExpr(i);
3394 }
3395
3396 //===--- Labels ---===//
3397
3398 bool isAsmGoto() const {
3399 return NumLabels > 0;
3400 }
3401
3402 unsigned getNumLabels() const {
3403 return NumLabels;
3404 }
3405
3407 return Names[i + NumOutputs + NumInputs];
3408 }
3409
3410 AddrLabelExpr *getLabelExpr(unsigned i) const;
3411 StringRef getLabelName(unsigned i) const;
3414 using labels_range = llvm::iterator_range<labels_iterator>;
3415 using labels_const_range = llvm::iterator_range<const_labels_iterator>;
3416
3418 return &Exprs[0] + NumOutputs + NumInputs;
3419 }
3420
3422 return &Exprs[0] + NumOutputs + NumInputs + NumLabels;
3423 }
3424
3427 }
3428
3430 return &Exprs[0] + NumOutputs + NumInputs;
3431 }
3432
3434 return &Exprs[0] + NumOutputs + NumInputs + NumLabels;
3435 }
3436
3439 }
3440
3441private:
3442 void setOutputsAndInputsAndClobbers(const ASTContext &C,
3443 IdentifierInfo **Names,
3444 StringLiteral **Constraints,
3445 Stmt **Exprs,
3446 unsigned NumOutputs,
3447 unsigned NumInputs,
3448 unsigned NumLabels,
3449 StringLiteral **Clobbers,
3450 unsigned NumClobbers);
3451
3452public:
3453 //===--- Other ---===//
3454
3455 /// getNamedOperand - Given a symbolic operand reference like %[foo],
3456 /// translate this into a numeric value needed to reference the same operand.
3457 /// This returns -1 if the operand name is invalid.
3458 int getNamedOperand(StringRef SymbolicName) const;
3459
3460 StringRef getClobber(unsigned i) const;
3461
3462 StringLiteral *getClobberStringLiteral(unsigned i) { return Clobbers[i]; }
3463 const StringLiteral *getClobberStringLiteral(unsigned i) const {
3464 return Clobbers[i];
3465 }
3466
3467 SourceLocation getBeginLoc() const LLVM_READONLY { return AsmLoc; }
3468 SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
3469
3470 static bool classof(const Stmt *T) {
3471 return T->getStmtClass() == GCCAsmStmtClass;
3472 }
3473};
3474
3475/// This represents a Microsoft inline-assembly statement extension.
3476class MSAsmStmt : public AsmStmt {
3477 friend class ASTStmtReader;
3478
3479 SourceLocation LBraceLoc, EndLoc;
3480 StringRef AsmStr;
3481
3482 unsigned NumAsmToks = 0;
3483
3484 Token *AsmToks = nullptr;
3485 StringRef *Constraints = nullptr;
3486 StringRef *Clobbers = nullptr;
3487
3488public:
3489 MSAsmStmt(const ASTContext &C, SourceLocation asmloc,
3490 SourceLocation lbraceloc, bool issimple, bool isvolatile,
3491 ArrayRef<Token> asmtoks, unsigned numoutputs, unsigned numinputs,
3492 ArrayRef<StringRef> constraints,
3493 ArrayRef<Expr*> exprs, StringRef asmstr,
3494 ArrayRef<StringRef> clobbers, SourceLocation endloc);
3495
3496 /// Build an empty MS-style inline-assembly statement.
3497 explicit MSAsmStmt(EmptyShell Empty) : AsmStmt(MSAsmStmtClass, Empty) {}
3498
3499 SourceLocation getLBraceLoc() const { return LBraceLoc; }
3500 void setLBraceLoc(SourceLocation L) { LBraceLoc = L; }
3501 SourceLocation getEndLoc() const { return EndLoc; }
3502 void setEndLoc(SourceLocation L) { EndLoc = L; }
3503
3504 bool hasBraces() const { return LBraceLoc.isValid(); }
3505
3506 unsigned getNumAsmToks() { return NumAsmToks; }
3507 Token *getAsmToks() { return AsmToks; }
3508
3509 //===--- Asm String Analysis ---===//
3510 StringRef getAsmString() const { return AsmStr; }
3511
3512 /// Assemble final IR asm string.
3513 std::string generateAsmString(const ASTContext &C) const;
3514
3515 //===--- Output operands ---===//
3516
3517 StringRef getOutputConstraint(unsigned i) const {
3518 assert(i < NumOutputs);
3519 return Constraints[i];
3520 }
3521
3522 Expr *getOutputExpr(unsigned i);
3523
3524 const Expr *getOutputExpr(unsigned i) const {
3525 return const_cast<MSAsmStmt*>(this)->getOutputExpr(i);
3526 }
3527
3528 //===--- Input operands ---===//
3529
3530 StringRef getInputConstraint(unsigned i) const {
3531 assert(i < NumInputs);
3532 return Constraints[i + NumOutputs];
3533 }
3534
3535 Expr *getInputExpr(unsigned i);
3536 void setInputExpr(unsigned i, Expr *E);
3537
3538 const Expr *getInputExpr(unsigned i) const {
3539 return const_cast<MSAsmStmt*>(this)->getInputExpr(i);
3540 }
3541
3542 //===--- Other ---===//
3543
3545 return llvm::ArrayRef(Constraints, NumInputs + NumOutputs);
3546 }
3547
3549 return llvm::ArrayRef(Clobbers, NumClobbers);
3550 }
3551
3553 return llvm::ArrayRef(reinterpret_cast<Expr **>(Exprs),
3555 }
3556
3557 StringRef getClobber(unsigned i) const { return getClobbers()[i]; }
3558
3559private:
3560 void initialize(const ASTContext &C, StringRef AsmString,
3561 ArrayRef<Token> AsmToks, ArrayRef<StringRef> Constraints,
3563
3564public:
3565 SourceLocation getBeginLoc() const LLVM_READONLY { return AsmLoc; }
3566
3567 static bool classof(const Stmt *T) {
3568 return T->getStmtClass() == MSAsmStmtClass;
3569 }
3570
3572 return child_range(&Exprs[0], &Exprs[NumInputs + NumOutputs]);
3573 }
3574
3577 }
3578};
3579
3580class SEHExceptStmt : public Stmt {
3581 friend class ASTReader;
3582 friend class ASTStmtReader;
3583
3584 SourceLocation Loc;
3585 Stmt *Children[2];
3586
3587 enum { FILTER_EXPR, BLOCK };
3588
3589 SEHExceptStmt(SourceLocation Loc, Expr *FilterExpr, Stmt *Block);
3590 explicit SEHExceptStmt(EmptyShell E) : Stmt(SEHExceptStmtClass, E) {}
3591
3592public:
3593 static SEHExceptStmt* Create(const ASTContext &C,
3594 SourceLocation ExceptLoc,
3595 Expr *FilterExpr,
3596 Stmt *Block);
3597
3598 SourceLocation getBeginLoc() const LLVM_READONLY { return getExceptLoc(); }
3599
3600 SourceLocation getExceptLoc() const { return Loc; }
3602
3604 return reinterpret_cast<Expr*>(Children[FILTER_EXPR]);
3605 }
3606
3608 return cast<CompoundStmt>(Children[BLOCK]);
3609 }
3610
3612 return child_range(Children, Children+2);
3613 }
3614
3616 return const_child_range(Children, Children + 2);
3617 }
3618
3619 static bool classof(const Stmt *T) {
3620 return T->getStmtClass() == SEHExceptStmtClass;
3621 }
3622};
3623
3624class SEHFinallyStmt : public Stmt {
3625 friend class ASTReader;
3626 friend class ASTStmtReader;
3627
3628 SourceLocation Loc;
3629 Stmt *Block;
3630
3632 explicit SEHFinallyStmt(EmptyShell E) : Stmt(SEHFinallyStmtClass, E) {}
3633
3634public:
3635 static SEHFinallyStmt* Create(const ASTContext &C,
3636 SourceLocation FinallyLoc,
3637 Stmt *Block);
3638
3639 SourceLocation getBeginLoc() const LLVM_READONLY { return getFinallyLoc(); }
3640
3641 SourceLocation getFinallyLoc() const { return Loc; }
3642 SourceLocation getEndLoc() const { return Block->getEndLoc(); }
3643
3644 CompoundStmt *getBlock() const { return cast<CompoundStmt>(Block); }
3645
3647 return child_range(&Block,&Block+1);
3648 }
3649
3651 return const_child_range(&Block, &Block + 1);
3652 }
3653
3654 static bool classof(const Stmt *T) {
3655 return T->getStmtClass() == SEHFinallyStmtClass;
3656 }
3657};
3658
3659class SEHTryStmt : public Stmt {
3660 friend class ASTReader;
3661 friend class ASTStmtReader;
3662
3663 bool IsCXXTry;
3664 SourceLocation TryLoc;
3665 Stmt *Children[2];
3666
3667 enum { TRY = 0, HANDLER = 1 };
3668
3669 SEHTryStmt(bool isCXXTry, // true if 'try' otherwise '__try'
3670 SourceLocation TryLoc,
3671 Stmt *TryBlock,
3672 Stmt *Handler);
3673
3674 explicit SEHTryStmt(EmptyShell E) : Stmt(SEHTryStmtClass, E) {}
3675
3676public:
3677 static SEHTryStmt* Create(const ASTContext &C, bool isCXXTry,
3678 SourceLocation TryLoc, Stmt *TryBlock,
3679 Stmt *Handler);
3680
3681 SourceLocation getBeginLoc() const LLVM_READONLY { return getTryLoc(); }
3682
3683 SourceLocation getTryLoc() const { return TryLoc; }
3684 SourceLocation getEndLoc() const { return Children[HANDLER]->getEndLoc(); }
3685
3686 bool getIsCXXTry() const { return IsCXXTry; }
3687
3689 return cast<CompoundStmt>(Children[TRY]);
3690 }
3691
3692 Stmt *getHandler() const { return Children[HANDLER]; }
3693
3694 /// Returns 0 if not defined
3697
3699 return child_range(Children, Children+2);
3700 }
3701
3703 return const_child_range(Children, Children + 2);
3704 }
3705
3706 static bool classof(const Stmt *T) {
3707 return T->getStmtClass() == SEHTryStmtClass;
3708 }
3709};
3710
3711/// Represents a __leave statement.
3712class SEHLeaveStmt : public Stmt {
3713 SourceLocation LeaveLoc;
3714
3715public:
3717 : Stmt(SEHLeaveStmtClass), LeaveLoc(LL) {}
3718
3719 /// Build an empty __leave statement.
3720 explicit SEHLeaveStmt(EmptyShell Empty) : Stmt(SEHLeaveStmtClass, Empty) {}
3721
3722 SourceLocation getLeaveLoc() const { return LeaveLoc; }
3723 void setLeaveLoc(SourceLocation L) { LeaveLoc = L; }
3724
3725 SourceLocation getBeginLoc() const LLVM_READONLY { return LeaveLoc; }
3726 SourceLocation getEndLoc() const LLVM_READONLY { return LeaveLoc; }
3727
3728 static bool classof(const Stmt *T) {
3729 return T->getStmtClass() == SEHLeaveStmtClass;
3730 }
3731
3732 // Iterators
3735 }
3736
3739 }
3740};
3741
3742/// This captures a statement into a function. For example, the following
3743/// pragma annotated compound statement can be represented as a CapturedStmt,
3744/// and this compound statement is the body of an anonymous outlined function.
3745/// @code
3746/// #pragma omp parallel
3747/// {
3748/// compute();
3749/// }
3750/// @endcode
3751class CapturedStmt : public Stmt {
3752public:
3753 /// The different capture forms: by 'this', by reference, capture for
3754 /// variable-length array type etc.
3760 };
3761
3762 /// Describes the capture of either a variable, or 'this', or
3763 /// variable-length array type.
3764 class Capture {
3765 llvm::PointerIntPair<VarDecl *, 2, VariableCaptureKind> VarAndKind;
3766 SourceLocation Loc;
3767
3768 Capture() = default;
3769
3770 public:
3771 friend class ASTStmtReader;
3772 friend class CapturedStmt;
3773
3774 /// Create a new capture.
3775 ///
3776 /// \param Loc The source location associated with this capture.
3777 ///
3778 /// \param Kind The kind of capture (this, ByRef, ...).
3779 ///
3780 /// \param Var The variable being captured, or null if capturing this.
3782 VarDecl *Var = nullptr);
3783
3784 /// Determine the kind of capture.
3786
3787 /// Retrieve the source location at which the variable or 'this' was
3788 /// first used.
3789 SourceLocation getLocation() const { return Loc; }
3790
3791 /// Determine whether this capture handles the C++ 'this' pointer.
3792 bool capturesThis() const { return getCaptureKind() == VCK_This; }
3793
3794 /// Determine whether this capture handles a variable (by reference).
3795 bool capturesVariable() const { return getCaptureKind() == VCK_ByRef; }
3796
3797 /// Determine whether this capture handles a variable by copy.
3799 return getCaptureKind() == VCK_ByCopy;
3800 }
3801
3802 /// Determine whether this capture handles a variable-length array
3803 /// type.
3805 return getCaptureKind() == VCK_VLAType;
3806 }
3807
3808 /// Retrieve the declaration of the variable being captured.
3809 ///
3810 /// This operation is only valid if this capture captures a variable.
3811 VarDecl *getCapturedVar() const;
3812 };
3813
3814private:
3815 /// The number of variable captured, including 'this'.
3816 unsigned NumCaptures;
3817
3818 /// The pointer part is the implicit the outlined function and the
3819 /// int part is the captured region kind, 'CR_Default' etc.
3820 llvm::PointerIntPair<CapturedDecl *, 2, CapturedRegionKind> CapDeclAndKind;
3821
3822 /// The record for captured variables, a RecordDecl or CXXRecordDecl.
3823 RecordDecl *TheRecordDecl = nullptr;
3824
3825 /// Construct a captured statement.
3827 ArrayRef<Expr *> CaptureInits, CapturedDecl *CD, RecordDecl *RD);
3828
3829 /// Construct an empty captured statement.
3830 CapturedStmt(EmptyShell Empty, unsigned NumCaptures);
3831
3832 Stmt **getStoredStmts() { return reinterpret_cast<Stmt **>(this + 1); }
3833
3834 Stmt *const *getStoredStmts() const {
3835 return reinterpret_cast<Stmt *const *>(this + 1);
3836 }
3837
3838 Capture *getStoredCaptures() const;
3839
3840 void setCapturedStmt(Stmt *S) { getStoredStmts()[NumCaptures] = S; }
3841
3842public:
3843 friend class ASTStmtReader;
3844
3845 static CapturedStmt *Create(const ASTContext &Context, Stmt *S,
3846 CapturedRegionKind Kind,
3847 ArrayRef<Capture> Captures,
3848 ArrayRef<Expr *> CaptureInits,
3849 CapturedDecl *CD, RecordDecl *RD);
3850
3851 static CapturedStmt *CreateDeserialized(const ASTContext &Context,
3852 unsigned NumCaptures);
3853
3854 /// Retrieve the statement being captured.
3855 Stmt *getCapturedStmt() { return getStoredStmts()[NumCaptures]; }
3856 const Stmt *getCapturedStmt() const { return getStoredStmts()[NumCaptures]; }
3857
3858 /// Retrieve the outlined function declaration.
3860 const CapturedDecl *getCapturedDecl() const;
3861
3862 /// Set the outlined function declaration.
3864
3865 /// Retrieve the captured region kind.
3867
3868 /// Set the captured region kind.
3870
3871 /// Retrieve the record declaration for captured variables.
3872 const RecordDecl *getCapturedRecordDecl() const { return TheRecordDecl; }
3873
3874 /// Set the record declaration for captured variables.
3876 assert(D && "null RecordDecl");
3877 TheRecordDecl = D;
3878 }
3879
3880 /// True if this variable has been captured.
3881 bool capturesVariable(const VarDecl *Var) const;
3882
3883 /// An iterator that walks over the captures.
3886 using capture_range = llvm::iterator_range<capture_iterator>;
3887 using capture_const_range = llvm::iterator_range<const_capture_iterator>;
3888
3891 }
3894 }
3895
3896 /// Retrieve an iterator pointing to the first capture.
3897 capture_iterator capture_begin() { return getStoredCaptures(); }
3898 const_capture_iterator capture_begin() const { return getStoredCaptures(); }
3899
3900 /// Retrieve an iterator pointing past the end of the sequence of
3901 /// captures.
3903 return getStoredCaptures() + NumCaptures;
3904 }
3905
3906 /// Retrieve the number of captures, including 'this'.
3907 unsigned capture_size() const { return NumCaptures; }
3908
3909 /// Iterator that walks over the capture initialization arguments.
3911 using capture_init_range = llvm::iterator_range<capture_init_iterator>;
3912
3913 /// Const iterator that walks over the capture initialization
3914 /// arguments.
3917 llvm::iterator_range<const_capture_init_iterator>;
3918
3921 }
3922
3925 }
3926
3927 /// Retrieve the first initialization argument.
3929 return reinterpret_cast<Expr **>(getStoredStmts());
3930 }
3931
3933 return reinterpret_cast<Expr *const *>(getStoredStmts());
3934 }
3935
3936 /// Retrieve the iterator pointing one past the last initialization
3937 /// argument.
3939 return capture_init_begin() + NumCaptures;
3940 }
3941
3943 return capture_init_begin() + NumCaptures;
3944 }
3945
3946 SourceLocation getBeginLoc() const LLVM_READONLY {
3947 return getCapturedStmt()->getBeginLoc();
3948 }
3949
3950 SourceLocation getEndLoc() const LLVM_READONLY {
3951 return getCapturedStmt()->getEndLoc();
3952 }
3953
3954 SourceRange getSourceRange() const LLVM_READONLY {
3955 return getCapturedStmt()->getSourceRange();
3956 }
3957
3958 static bool classof(const Stmt *T) {
3959 return T->getStmtClass() == CapturedStmtClass;
3960 }
3961
3963
3965};
3966
3967} // namespace clang
3968
3969#endif // LLVM_CLANG_AST_STMT_H
#define V(N, I)
Definition: ASTContext.h:3241
static StringRef bytes(const std::vector< T, Allocator > &v)
Definition: ASTWriter.cpp:123
static char ID
Definition: Arena.cpp:183
const CFGBlock * Block
Definition: HTMLLogger.cpp:149
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines several types used to describe C++ lambda expressions that are shared between the parser and ...
Defines the clang::LangOptions interface.
Defines an enumeration for C++ overloaded operators.
Defines the clang::SourceLocation class and associated facilities.
Defines various enumerations that describe declaration and type specifiers.
#define BLOCK(DERIVED, BASE)
Definition: Template.h:620
Defines enumerations for the type traits support.
SourceLocation Begin
std::string Label
__device__ __2f16 float __ockl_bool s
__SIZE_TYPE__ size_t
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:182
Reads an AST files chain containing the contents of a translation unit.
Definition: ASTReader.h:366
AddrLabelExpr - The GNU address of label extension, representing &&label.
Definition: Expr.h:4360
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition: Expr.h:2691
AsmStmt is the base class for GCCAsmStmt and MSAsmStmt.
Definition: Stmt.h:3094
Stmt ** Exprs
Definition: Stmt.h:3112
void setSimple(bool V)
Definition: Stmt.h:3128
outputs_iterator begin_outputs()
Definition: Stmt.h:3219
void setAsmLoc(SourceLocation L)
Definition: Stmt.h:3125
const_outputs_iterator end_outputs() const
Definition: Stmt.h:3235
SourceLocation AsmLoc
Definition: Stmt.h:3098
bool isVolatile() const
Definition: Stmt.h:3130
outputs_iterator end_outputs()
Definition: Stmt.h:3223
const_inputs_iterator begin_inputs() const
Definition: Stmt.h:3200
unsigned getNumPlusOperands() const
getNumPlusOperands - Return the number of output operands that have a "+" constraint.
Definition: Stmt.cpp:491
AsmStmt(StmtClass SC, SourceLocation asmloc, bool issimple, bool isvolatile, unsigned numoutputs, unsigned numinputs, unsigned numclobbers)
Definition: Stmt.h:3114
void setVolatile(bool V)
Definition: Stmt.h:3131
static bool classof(const Stmt *T)
Definition: Stmt.h:3178
StringRef getOutputConstraint(unsigned i) const
getOutputConstraint - Return the constraint string for the specified output operand.
Definition: Stmt.cpp:449
outputs_range outputs()
Definition: Stmt.h:3227
inputs_const_range inputs() const
Definition: Stmt.h:3208
SourceLocation getAsmLoc() const
Definition: Stmt.h:3124
const Expr * getInputExpr(unsigned i) const
Definition: Stmt.cpp:473
unsigned NumInputs
Definition: Stmt.h:3109
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Stmt.h:3134
inputs_range inputs()
Definition: Stmt.h:3198
llvm::iterator_range< inputs_iterator > inputs_range
Definition: Stmt.h:3187
bool isOutputPlusConstraint(unsigned i) const
isOutputPlusConstraint - Return true if the specified output constraint is a "+" constraint (which is...
Definition: Stmt.h:3153
unsigned getNumClobbers() const
Definition: Stmt.h:3175
const_inputs_iterator end_inputs() const
Definition: Stmt.h:3204
llvm::iterator_range< const_inputs_iterator > inputs_const_range
Definition: Stmt.h:3188
const_child_range children() const
Definition: Stmt.h:3247
bool IsSimple
True if the assembly statement does not have any input or output operands.
Definition: Stmt.h:3102
const Expr * getOutputExpr(unsigned i) const
Definition: Stmt.cpp:457
StringRef getInputConstraint(unsigned i) const
getInputConstraint - Return the specified input constraint.
Definition: Stmt.cpp:465
outputs_const_range outputs() const
Definition: Stmt.h:3239
inputs_iterator end_inputs()
Definition: Stmt.h:3194
unsigned getNumOutputs() const
Definition: Stmt.h:3143
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.h:3133
inputs_iterator begin_inputs()
Definition: Stmt.h:3190
AsmStmt(StmtClass SC, EmptyShell Empty)
Build an empty inline-assembly statement.
Definition: Stmt.h:3122
unsigned NumOutputs
Definition: Stmt.h:3108
child_range children()
Definition: Stmt.h:3243
std::string generateAsmString(const ASTContext &C) const
Assemble final IR asm string.
Definition: Stmt.cpp:441
unsigned NumClobbers
Definition: Stmt.h:3110
bool IsVolatile
If true, treat this inline assembly as having side effects.
Definition: Stmt.h:3106
unsigned getNumInputs() const
Definition: Stmt.h:3165
bool isSimple() const
Definition: Stmt.h:3127
llvm::iterator_range< outputs_iterator > outputs_range
Definition: Stmt.h:3216
StringRef getClobber(unsigned i) const
Definition: Stmt.cpp:481
const_outputs_iterator begin_outputs() const
Definition: Stmt.h:3231
llvm::iterator_range< const_outputs_iterator > outputs_const_range
Definition: Stmt.h:3217
AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, __atomic_load,...
Definition: Expr.h:6448
Attr - This represents one attribute.
Definition: Attr.h:41
Represents an attribute applied to a statement.
Definition: Stmt.h:2074
static AttributedStmt * CreateEmpty(const ASTContext &C, unsigned NumAttrs)
Definition: Stmt.cpp:433
Stmt * getSubStmt()
Definition: Stmt.h:2112
const Stmt * getSubStmt() const
Definition: Stmt.h:2113
SourceLocation getAttrLoc() const
Definition: Stmt.h:2107
ArrayRef< const Attr * > getAttrs() const
Definition: Stmt.h:2108
child_range children()
Definition: Stmt.h:2118
const_child_range children() const
Definition: Stmt.h:2120
static AttributedStmt * Create(const ASTContext &C, SourceLocation Loc, ArrayRef< const Attr * > Attrs, Stmt *SubStmt)
Definition: Stmt.cpp:424
static bool classof(const Stmt *T)
Definition: Stmt.h:2124
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Stmt.h:2116
SourceLocation getBeginLoc() const
Definition: Stmt.h:2115
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:3862
BreakStmt - This represents a break.
Definition: Stmt.h:2974
child_range children()
Definition: Stmt.h:2994
SourceLocation getBreakLoc() const
Definition: Stmt.h:2983
SourceLocation getEndLoc() const
Definition: Stmt.h:2987
SourceLocation getBeginLoc() const
Definition: Stmt.h:2986
BreakStmt(SourceLocation BL)
Definition: Stmt.h:2976
const_child_range children() const
Definition: Stmt.h:2998
static bool classof(const Stmt *T)
Definition: Stmt.h:2989
void setBreakLoc(SourceLocation L)
Definition: Stmt.h:2984
BreakStmt(EmptyShell Empty)
Build an empty break statement.
Definition: Stmt.h:2981
A boolean literal, per ([C++ lex.bool] Boolean literals).
Definition: ExprCXX.h:720
Represents a call to a C++ constructor.
Definition: ExprCXX.h:1530
A default argument (C++ [dcl.fct.default]).
Definition: ExprCXX.h:1254
A use of a default initializer in a constructor or in aggregate initialization.
Definition: ExprCXX.h:1361
Represents a delete expression for memory deallocation and destructor calls, e.g.
Definition: ExprCXX.h:2494
Represents a C++ member access expression where the actual member referenced could not be resolved be...
Definition: ExprCXX.h:3658
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
Definition: ExprCXX.h:2227
Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
Definition: ExprCXX.h:4101
The null pointer literal (C++11 [lex.nullptr])
Definition: ExprCXX.h:765
A call to an overloaded operator written using operator syntax.
Definition: ExprCXX.h:81
A rewritten comparison expression that was originally written using operator syntax.
Definition: ExprCXX.h:283
An expression "T()" which creates a value-initialized rvalue of type T, which is a non-class type.
Definition: ExprCXX.h:2165
Represents the this expression in C++.
Definition: ExprCXX.h:1148
A C++ throw-expression (C++ [except.throw]).
Definition: ExprCXX.h:1192
Describes an explicit type conversion that uses functional notion but could not be resolved because o...
Definition: ExprCXX.h:3532
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2847
Represents the body of a CapturedStmt, and serves as its DeclContext.
Definition: Decl.h:4655
Describes the capture of either a variable, or 'this', or variable-length array type.
Definition: Stmt.h:3764
bool capturesVariableByCopy() const
Determine whether this capture handles a variable by copy.
Definition: Stmt.h:3798
VariableCaptureKind getCaptureKind() const
Determine the kind of capture.
Definition: Stmt.cpp:1299
VarDecl * getCapturedVar() const
Retrieve the declaration of the variable being captured.
Definition: Stmt.cpp:1303
bool capturesVariableArrayType() const
Determine whether this capture handles a variable-length array type.
Definition: Stmt.h:3804
bool capturesThis() const
Determine whether this capture handles the C++ 'this' pointer.
Definition: Stmt.h:3792
bool capturesVariable() const
Determine whether this capture handles a variable (by reference).
Definition: Stmt.h:3795
SourceLocation getLocation() const
Retrieve the source location at which the variable or 'this' was first used.
Definition: Stmt.h:3789
This captures a statement into a function.
Definition: Stmt.h:3751
unsigned capture_size() const
Retrieve the number of captures, including 'this'.
Definition: Stmt.h:3907
const_capture_iterator capture_begin() const
Definition: Stmt.h:3898
static CapturedStmt * CreateDeserialized(const ASTContext &Context, unsigned NumCaptures)
Definition: Stmt.cpp:1383
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Stmt.h:3950
capture_init_range capture_inits()
Definition: Stmt.h:3919
void setCapturedRegionKind(CapturedRegionKind Kind)
Set the captured region kind.
Definition: Stmt.cpp:1425
const_capture_init_iterator capture_init_begin() const
Definition: Stmt.h:3932
CapturedDecl * getCapturedDecl()
Retrieve the outlined function declaration.
Definition: Stmt.cpp:1405
SourceRange getSourceRange() const LLVM_READONLY
Definition: Stmt.h:3954
capture_iterator capture_end() const
Retrieve an iterator pointing past the end of the sequence of captures.
Definition: Stmt.h:3902
child_range children()
Definition: Stmt.cpp:1396
const RecordDecl * getCapturedRecordDecl() const
Retrieve the record declaration for captured variables.
Definition: Stmt.h:3872
Stmt * getCapturedStmt()
Retrieve the statement being captured.
Definition: Stmt.h:3855
llvm::iterator_range< capture_init_iterator > capture_init_range
Definition: Stmt.h:3911
llvm::iterator_range< capture_iterator > capture_range
Definition: Stmt.h:3886
bool capturesVariable(const VarDecl *Var) const
True if this variable has been captured.
Definition: Stmt.cpp:1429
static bool classof(const Stmt *T)
Definition: Stmt.h:3958
capture_init_iterator capture_init_begin()
Retrieve the first initialization argument.
Definition: Stmt.h:3928
void setCapturedDecl(CapturedDecl *D)
Set the outlined function declaration.
Definition: Stmt.cpp:1414
capture_iterator capture_begin()
Retrieve an iterator pointing to the first capture.
Definition: Stmt.h:3897
llvm::iterator_range< const_capture_init_iterator > const_capture_init_range
Definition: Stmt.h:3917
static CapturedStmt * Create(const ASTContext &Context, Stmt *S, CapturedRegionKind Kind, ArrayRef< Capture > Captures, ArrayRef< Expr * > CaptureInits, CapturedDecl *CD, RecordDecl *RD)
Definition: Stmt.cpp:1355
const_capture_init_iterator capture_init_end() const
Definition: Stmt.h:3942
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.h:3946
void setCapturedRecordDecl(RecordDecl *D)
Set the record declaration for captured variables.
Definition: Stmt.h:3875
llvm::iterator_range< const_capture_iterator > capture_const_range
Definition: Stmt.h:3887
capture_init_iterator capture_init_end()
Retrieve the iterator pointing one past the last initialization argument.
Definition: Stmt.h:3938
capture_range captures()
Definition: Stmt.h:3889
Expr *const * const_capture_init_iterator
Const iterator that walks over the capture initialization arguments.
Definition: Stmt.h:3915
const Stmt * getCapturedStmt() const
Definition: Stmt.h:3856
capture_const_range captures() const
Definition: Stmt.h:3892
CapturedRegionKind getCapturedRegionKind() const
Retrieve the captured region kind.
Definition: Stmt.cpp:1420
VariableCaptureKind
The different capture forms: by 'this', by reference, capture for variable-length array type etc.
Definition: Stmt.h:3755
const_capture_init_range capture_inits() const
Definition: Stmt.h:3923
CaseStmt - Represent a case statement.
Definition: Stmt.h:1795
Stmt * getSubStmt()
Definition: Stmt.h:1912
const Expr * getRHS() const
Definition: Stmt.h:1900
Expr * getLHS()
Definition: Stmt.h:1882
const_child_range children() const
Definition: Stmt.h:1942
SourceLocation getBeginLoc() const
Definition: Stmt.h:1921
void setEllipsisLoc(SourceLocation L)
Set the location of the ... in a case statement of the form LHS ... RHS.
Definition: Stmt.h:1875
static bool classof(const Stmt *T)
Definition: Stmt.h:1931
bool caseStmtIsGNURange() const
True if this case statement is of the form case LHS ... RHS, which is a GNU extension.
Definition: Stmt.h:1862
const Expr * getLHS() const
Definition: Stmt.h:1886
SourceLocation getEllipsisLoc() const
Get the location of the ... in a case statement of the form LHS ... RHS.
Definition: Stmt.h:1868
static CaseStmt * Create(const ASTContext &Ctx, Expr *lhs, Expr *rhs, SourceLocation caseLoc, SourceLocation ellipsisLoc, SourceLocation colonLoc)
Build a case statement.
Definition: Stmt.cpp:1218
void setCaseLoc(SourceLocation L)
Definition: Stmt.h:1865
child_range children()
Definition: Stmt.h:1936
SourceLocation getCaseLoc() const
Definition: Stmt.h:1864
static CaseStmt * CreateEmpty(const ASTContext &Ctx, bool CaseStmtIsGNURange)
Build an empty case statement.
Definition: Stmt.cpp:1229
void setLHS(Expr *Val)
Definition: Stmt.h:1890
void setSubStmt(Stmt *S)
Definition: Stmt.h:1917
const Stmt * getSubStmt() const
Definition: Stmt.h:1913
Expr * getRHS()
Definition: Stmt.h:1894
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Stmt.h:1922
void setRHS(Expr *Val)
Definition: Stmt.h:1906
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition: Expr.h:3517
Represents a character-granular source range.
Represents a 'co_await' expression.
Definition: ExprCXX.h:5037
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:1602
Stmt * body_front()
Definition: Stmt.h:1661
static bool classof(const Stmt *T)
Definition: Stmt.h:1735
bool body_empty() const
Definition: Stmt.h:1644
unsigned size() const
Definition: Stmt.h:1645
std::reverse_iterator< const_body_iterator > const_reverse_body_iterator
Definition: Stmt.h:1699
body_const_range body() const
Definition: Stmt.h:1670
Stmt *const * const_body_iterator
Definition: Stmt.h:1667
const_reverse_body_iterator body_rend() const
Definition: Stmt.h:1705
llvm::iterator_range< const_body_iterator > body_const_range
Definition: Stmt.h:1668
std::reverse_iterator< body_iterator > reverse_body_iterator
Definition: Stmt.h:1688
reverse_body_iterator body_rbegin()
Definition: Stmt.h:1690
llvm::iterator_range< body_iterator > body_range
Definition: Stmt.h:1656
const Stmt * getStmtExprResult() const
Definition: Stmt.h:1725
body_iterator body_end()
Definition: Stmt.h:1660
FPOptionsOverride getStoredFPFeatures() const
Get FPOptionsOverride from trailing storage.
Definition: Stmt.h:1650
const Stmt * body_front() const
Definition: Stmt.h:1680
body_range body()
Definition: Stmt.h:1658
SourceLocation getBeginLoc() const
Definition: Stmt.h:1729
static CompoundStmt * CreateEmpty(const ASTContext &C, unsigned NumStmts, bool HasFPFeatures)
Definition: Stmt.cpp:392
SourceLocation getLBracLoc() const
Definition: Stmt.h:1732
body_iterator body_begin()
Definition: Stmt.h:1659
SourceLocation getEndLoc() const
Definition: Stmt.h:1730
bool hasStoredFPFeatures() const
Definition: Stmt.h:1647
const_child_range children() const
Definition: Stmt.h:1742
reverse_body_iterator body_rend()
Definition: Stmt.h:1694
CompoundStmt(SourceLocation Loc)
Definition: Stmt.h:1634
const_body_iterator body_begin() const
Definition: Stmt.h:1674
static CompoundStmt * Create(const ASTContext &C, ArrayRef< Stmt * > Stmts, FPOptionsOverride FPFeatures, SourceLocation LB, SourceLocation RB)
Definition: Stmt.cpp:382
Stmt * getStmtExprResult()
Definition: Stmt.h:1717
const Stmt * body_back() const
Definition: Stmt.h:1684
const_reverse_body_iterator body_rbegin() const
Definition: Stmt.h:1701
child_range children()
Definition: Stmt.h:1740
Stmt * body_back()
Definition: Stmt.h:1663
SourceLocation getRBracLoc() const
Definition: Stmt.h:1733
const_body_iterator body_end() const
Definition: Stmt.h:1678
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
Definition: Expr.h:1059
ContinueStmt - This represents a continue.
Definition: Stmt.h:2944
ContinueStmt(EmptyShell Empty)
Build an empty continue statement.
Definition: Stmt.h:2951
child_range children()
Definition: Stmt.h:2964
ContinueStmt(SourceLocation CL)
Definition: Stmt.h:2946
static bool classof(const Stmt *T)
Definition: Stmt.h:2959
void setContinueLoc(SourceLocation L)
Definition: Stmt.h:2954
SourceLocation getContinueLoc() const
Definition: Stmt.h:2953
SourceLocation getEndLoc() const
Definition: Stmt.h:2957
const_child_range children() const
Definition: Stmt.h:2968
SourceLocation getBeginLoc() const
Definition: Stmt.h:2956
Decl *const * const_iterator
Definition: DeclGroup.h:77
iterator begin()
Definition: DeclGroup.h:99
iterator end()
Definition: DeclGroup.h:105
Decl * getSingleDecl()
Definition: DeclGroup.h:83
bool isSingleDecl() const
Definition: DeclGroup.h:80
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1248
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition: Stmt.h:1493
std::reverse_iterator< decl_iterator > reverse_decl_iterator
Definition: Stmt.h:1552
llvm::iterator_range< decl_iterator > decl_range
Definition: Stmt.h:1538
child_range children()
Definition: Stmt.h:1526
const_child_range children() const
Definition: Stmt.h:1531
Decl * getSingleDecl()
Definition: Stmt.h:1509
SourceLocation getEndLoc() const
Definition: Stmt.h:1516
const DeclGroupRef getDeclGroup() const
Definition: Stmt.h:1511
DeclStmt(EmptyShell Empty)
Build an empty declaration statement.
Definition: Stmt.h:1502
bool isSingleDecl() const
isSingleDecl - This method returns true if this DeclStmt refers to a single Decl.
Definition: Stmt.h:1506
decl_iterator decl_end()
Definition: Stmt.h:1548
const_decl_iterator decl_begin() const
Definition: Stmt.h:1549
void setStartLoc(SourceLocation L)
Definition: Stmt.h:1515
DeclGroupRef::const_iterator const_decl_iterator
Definition: Stmt.h:1537
static bool classof(const Stmt *T)
Definition: Stmt.h:1521
void setEndLoc(SourceLocation L)
Definition: Stmt.h:1517
decl_iterator decl_begin()
Definition: Stmt.h:1547
decl_range decls()
Definition: Stmt.h:1541
void setDeclGroup(DeclGroupRef DGR)
Definition: Stmt.h:1513
const Decl * getSingleDecl() const
Definition: Stmt.h:1508
decl_const_range decls() const
Definition: Stmt.h:1543
const_decl_iterator decl_end() const
Definition: Stmt.h:1550
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.h:1519
DeclGroupRef getDeclGroup()
Definition: Stmt.h:1512
reverse_decl_iterator decl_rend()
Definition: Stmt.h:1558
llvm::iterator_range< const_decl_iterator > decl_const_range
Definition: Stmt.h:1539
reverse_decl_iterator decl_rbegin()
Definition: Stmt.h:1554
DeclStmt(DeclGroupRef dg, SourceLocation startLoc, SourceLocation endLoc)
Definition: Stmt.h:1498
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:85
void setSubStmt(Stmt *S)
Definition: Stmt.h:1962
const Stmt * getSubStmt() const
Definition: Stmt.h:1961
child_range children()
Definition: Stmt.h:1977
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Stmt.h:1968
void setDefaultLoc(SourceLocation L)
Definition: Stmt.h:1965
SourceLocation getDefaultLoc() const
Definition: Stmt.h:1964
DefaultStmt(EmptyShell Empty)
Build an empty default statement.
Definition: Stmt.h:1957
static bool classof(const Stmt *T)
Definition: Stmt.h:1972
DefaultStmt(SourceLocation DL, SourceLocation CL, Stmt *substmt)
Definition: Stmt.h:1953
const_child_range children() const
Definition: Stmt.h:1979
SourceLocation getBeginLoc() const
Definition: Stmt.h:1967
Stmt * getSubStmt()
Definition: Stmt.h:1960
A qualified reference to a name whose declaration cannot yet be resolved.
Definition: ExprCXX.h:3298
Represents a C99 designated initializer expression.
Definition: Expr.h:5103
DoStmt - This represents a 'do/while' stmt.
Definition: Stmt.h:2719
void setWhileLoc(SourceLocation L)
Definition: Stmt.h:2751
SourceLocation getBeginLoc() const
Definition: Stmt.h:2755
Stmt * getBody()
Definition: Stmt.h:2744
Expr * getCond()
Definition: Stmt.h:2737
void setDoLoc(SourceLocation L)
Definition: Stmt.h:2749
SourceLocation getEndLoc() const
Definition: Stmt.h:2756
SourceLocation getWhileLoc() const
Definition: Stmt.h:2750
static bool classof(const Stmt *T)
Definition: Stmt.h:2758
const_child_range children() const
Definition: Stmt.h:2767
DoStmt(EmptyShell Empty)
Build an empty do-while statement.
Definition: Stmt.h:2735
SourceLocation getDoLoc() const
Definition: Stmt.h:2748
void setRParenLoc(SourceLocation L)
Definition: Stmt.h:2753
SourceLocation getRParenLoc() const
Definition: Stmt.h:2752
const Stmt * getBody() const
Definition: Stmt.h:2745
child_range children()
Definition: Stmt.h:2763
void setBody(Stmt *Body)
Definition: Stmt.h:2746
DoStmt(Stmt *Body, Expr *Cond, SourceLocation DL, SourceLocation WL, SourceLocation RP)
Definition: Stmt.h:2726
const Expr * getCond() const
Definition: Stmt.h:2738
void setCond(Expr *Cond)
Definition: Stmt.h:2742
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
Definition: ExprCXX.h:3449
This represents one expression.
Definition: Expr.h:110
Represents difference between two FPOptions values.
Definition: LangOptions.h:829
ForStmt - This represents a 'for (init;cond;inc)' stmt.
Definition: Stmt.h:2775
Stmt * getInit()
Definition: Stmt.h:2790