clang 24.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"
24#include "clang/Basic/LLVM.h"
25#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/STLFunctionalExtras.h"
35#include "llvm/ADT/StringRef.h"
36#include "llvm/ADT/iterator.h"
37#include "llvm/ADT/iterator_range.h"
38#include "llvm/Support/Casting.h"
39#include "llvm/Support/Compiler.h"
40#include "llvm/Support/ErrorHandling.h"
41#include <algorithm>
42#include <cassert>
43#include <cstddef>
44#include <iterator>
45#include <optional>
46#include <string>
47
48namespace llvm {
49
50class FoldingSetNodeID;
51
52} // namespace llvm
53
54namespace clang {
55
56class ASTContext;
57class Attr;
58class CapturedDecl;
59class Decl;
60class Expr;
61class AddrLabelExpr;
62class LabelDecl;
63class ODRHash;
64class PrinterHelper;
65struct PrintingPolicy;
66class RecordDecl;
67class SourceManager;
68class StringLiteral;
69class Token;
70class VarDecl;
71enum class CharacterLiteralKind;
73enum class CXXConstructionKind;
75enum class PredefinedIdentKind;
76enum class SourceLocIdentKind;
77enum class StringLiteralKind;
78
79//===----------------------------------------------------------------------===//
80// AST classes for statements.
81//===----------------------------------------------------------------------===//
82
83/// Stmt - This represents one statement.
84///
85class alignas(void *) Stmt {
86public:
87 enum StmtClass {
89#define STMT(CLASS, PARENT) CLASS##Class,
90#define STMT_RANGE(BASE, FIRST, LAST) \
91 first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class,
92#define LAST_STMT_RANGE(BASE, FIRST, LAST) \
93 first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class
94#define ABSTRACT_STMT(STMT)
95#include "clang/AST/StmtNodes.inc"
96 };
97
98 // Make vanilla 'new' and 'delete' illegal for Stmts.
99protected:
100 friend class ASTStmtReader;
101 friend class ASTStmtWriter;
102
103 void *operator new(size_t bytes) noexcept {
104 llvm_unreachable("Stmts cannot be allocated with regular 'new'.");
105 }
106
107 void operator delete(void *data) noexcept {
108 llvm_unreachable("Stmts cannot be released with regular 'delete'.");
109 }
110
111 //===--- Statement bitfields classes ---===//
112
113 #define NumStmtBits 9
114
116 friend class ASTStmtReader;
117 friend class ASTStmtWriter;
118 friend class Stmt;
119
120 /// The statement class.
121 LLVM_PREFERRED_TYPE(StmtClass)
122 unsigned sClass : NumStmtBits;
123 };
124
126 friend class ASTStmtReader;
127 friend class ASTStmtWriter;
128 friend class NullStmt;
129
130 LLVM_PREFERRED_TYPE(StmtBitfields)
132
133 /// True if the null statement was preceded by an empty macro, e.g:
134 /// @code
135 /// #define CALL(x)
136 /// CALL(0);
137 /// @endcode
138 LLVM_PREFERRED_TYPE(bool)
139 unsigned HasLeadingEmptyMacro : 1;
140
141 /// The location of the semi-colon.
142 SourceLocation SemiLoc;
143 };
144
146 friend class ASTStmtReader;
147 friend class CompoundStmt;
148
149 LLVM_PREFERRED_TYPE(StmtBitfields)
151
152 /// True if the compound statement has one or more pragmas that set some
153 /// floating-point features.
154 LLVM_PREFERRED_TYPE(bool)
155 unsigned HasFPFeatures : 1;
156
157 unsigned NumStmts;
158 };
159
161 friend class LabelStmt;
162
163 LLVM_PREFERRED_TYPE(StmtBitfields)
165
166 SourceLocation IdentLoc;
167 };
168
170 friend class ASTStmtReader;
171 friend class AttributedStmt;
172
173 LLVM_PREFERRED_TYPE(StmtBitfields)
175
176 /// Number of attributes.
177 unsigned NumAttrs : 32 - NumStmtBits;
178
179 /// The location of the attribute.
180 SourceLocation AttrLoc;
181 };
182
184 friend class ASTStmtReader;
185 friend class IfStmt;
186
187 LLVM_PREFERRED_TYPE(StmtBitfields)
189
190 /// Whether this is a constexpr if, or a consteval if, or neither.
191 LLVM_PREFERRED_TYPE(IfStatementKind)
192 unsigned Kind : 3;
193
194 /// True if this if statement has storage for an else statement.
195 LLVM_PREFERRED_TYPE(bool)
196 unsigned HasElse : 1;
197
198 /// True if this if statement has storage for a variable declaration.
199 LLVM_PREFERRED_TYPE(bool)
200 unsigned HasVar : 1;
201
202 /// True if this if statement has storage for an init statement.
203 LLVM_PREFERRED_TYPE(bool)
204 unsigned HasInit : 1;
205
206 /// The location of the "if".
207 SourceLocation IfLoc;
208 };
209
211 friend class SwitchStmt;
212
213 LLVM_PREFERRED_TYPE(StmtBitfields)
215
216 /// True if the SwitchStmt has storage for an init statement.
217 LLVM_PREFERRED_TYPE(bool)
218 unsigned HasInit : 1;
219
220 /// True if the SwitchStmt has storage for a condition variable.
221 LLVM_PREFERRED_TYPE(bool)
222 unsigned HasVar : 1;
223
224 /// If the SwitchStmt is a switch on an enum value, records whether all
225 /// the enum values were covered by CaseStmts. The coverage information
226 /// value is meant to be a hint for possible clients.
227 LLVM_PREFERRED_TYPE(bool)
228 unsigned AllEnumCasesCovered : 1;
229
230 /// The location of the "switch".
231 SourceLocation SwitchLoc;
232 };
233
235 friend class ASTStmtReader;
236 friend class WhileStmt;
237
238 LLVM_PREFERRED_TYPE(StmtBitfields)
240
241 /// True if the WhileStmt has storage for a condition variable.
242 LLVM_PREFERRED_TYPE(bool)
243 unsigned HasVar : 1;
244
245 /// The location of the "while".
246 SourceLocation WhileLoc;
247 };
248
250 friend class DoStmt;
251
252 LLVM_PREFERRED_TYPE(StmtBitfields)
254
255 /// The location of the "do".
256 SourceLocation DoLoc;
257 };
258
260 friend class ForStmt;
261
262 LLVM_PREFERRED_TYPE(StmtBitfields)
264
265 /// The location of the "for".
266 SourceLocation ForLoc;
267 };
268
270 friend class GotoStmt;
271 friend class IndirectGotoStmt;
272
273 LLVM_PREFERRED_TYPE(StmtBitfields)
275
276 /// The location of the "goto".
277 SourceLocation GotoLoc;
278 };
279
281 friend class LoopControlStmt;
282
283 LLVM_PREFERRED_TYPE(StmtBitfields)
285
286 /// The location of the "continue"/"break".
287 SourceLocation KwLoc;
288 };
289
291 friend class ReturnStmt;
292
293 LLVM_PREFERRED_TYPE(StmtBitfields)
295
296 /// True if this ReturnStmt has storage for an NRVO candidate.
297 LLVM_PREFERRED_TYPE(bool)
298 unsigned HasNRVOCandidate : 1;
299
300 /// The location of the "return".
301 SourceLocation RetLoc;
302 };
303
305 friend class SwitchCase;
306 friend class CaseStmt;
307
308 LLVM_PREFERRED_TYPE(StmtBitfields)
310
311 /// Used by CaseStmt to store whether it is a case statement
312 /// of the form case LHS ... RHS (a GNU extension).
313 LLVM_PREFERRED_TYPE(bool)
314 unsigned CaseStmtIsGNURange : 1;
315
316 /// The location of the "case" or "default" keyword.
317 SourceLocation KeywordLoc;
318 };
319
321 friend class DeferStmt;
322
323 LLVM_PREFERRED_TYPE(StmtBitfields)
325
326 /// The location of the "defer".
327 SourceLocation DeferLoc;
328 };
329
330 //===--- Expression bitfields classes ---===//
331
333 friend class ASTStmtReader; // deserialization
334 friend class AtomicExpr; // ctor
335 friend class BlockDeclRefExpr; // ctor
336 friend class CallExpr; // ctor
337 friend class CXXConstructExpr; // ctor
338 friend class CXXDependentScopeMemberExpr; // ctor
339 friend class CXXNewExpr; // ctor
340 friend class CXXUnresolvedConstructExpr; // ctor
341 friend class DeclRefExpr; // computeDependence
342 friend class DependentScopeDeclRefExpr; // ctor
343 friend class DesignatedInitExpr; // ctor
344 friend class Expr;
345 friend class InitListExpr; // ctor
346 friend class ObjCArrayLiteral; // ctor
347 friend class ObjCDictionaryLiteral; // ctor
348 friend class ObjCMessageExpr; // ctor
349 friend class OffsetOfExpr; // ctor
350 friend class OpaqueValueExpr; // ctor
351 friend class OverloadExpr; // ctor
352 friend class ParenListExpr; // ctor
353 friend class PseudoObjectExpr; // ctor
354 friend class ShuffleVectorExpr; // ctor
355
356 LLVM_PREFERRED_TYPE(StmtBitfields)
358
359 LLVM_PREFERRED_TYPE(ExprValueKind)
360 unsigned ValueKind : 2;
361 LLVM_PREFERRED_TYPE(ExprObjectKind)
362 unsigned ObjectKind : 3;
363 LLVM_PREFERRED_TYPE(ExprDependence)
364 unsigned Dependent : llvm::BitWidth<ExprDependence>;
365 };
366 enum { NumExprBits = NumStmtBits + 5 + llvm::BitWidth<ExprDependence> };
367
369 friend class ASTStmtReader;
370 friend class ASTStmtWriter;
371 friend class ConstantExpr;
372
373 LLVM_PREFERRED_TYPE(ExprBitfields)
375
376 /// The kind of result that is tail-allocated.
377 LLVM_PREFERRED_TYPE(ConstantResultStorageKind)
378 unsigned ResultKind : 2;
379
380 /// The kind of Result as defined by APValue::ValueKind.
381 LLVM_PREFERRED_TYPE(APValue::ValueKind)
382 unsigned APValueKind : 4;
383
384 /// When ResultKind == ConstantResultStorageKind::Int64, true if the
385 /// tail-allocated integer is unsigned.
386 LLVM_PREFERRED_TYPE(bool)
387 unsigned IsUnsigned : 1;
388
389 /// When ResultKind == ConstantResultStorageKind::Int64. the BitWidth of the
390 /// tail-allocated integer. 7 bits because it is the minimal number of bits
391 /// to represent a value from 0 to 64 (the size of the tail-allocated
392 /// integer).
393 unsigned BitWidth : 7;
394
395 /// When ResultKind == ConstantResultStorageKind::APValue, true if the
396 /// ASTContext will cleanup the tail-allocated APValue.
397 LLVM_PREFERRED_TYPE(bool)
398 unsigned HasCleanup : 1;
399
400 /// True if this ConstantExpr was created for immediate invocation.
401 LLVM_PREFERRED_TYPE(bool)
402 unsigned IsImmediateInvocation : 1;
403 };
404
406 friend class ASTStmtReader;
407 friend class PredefinedExpr;
408
409 LLVM_PREFERRED_TYPE(ExprBitfields)
411
412 LLVM_PREFERRED_TYPE(PredefinedIdentKind)
413 unsigned Kind : 4;
414
415 /// True if this PredefinedExpr has a trailing "StringLiteral *"
416 /// for the predefined identifier.
417 LLVM_PREFERRED_TYPE(bool)
418 unsigned HasFunctionName : 1;
419
420 /// True if this PredefinedExpr should be treated as a StringLiteral (for
421 /// MSVC compatibility).
422 LLVM_PREFERRED_TYPE(bool)
423 unsigned IsTransparent : 1;
424
425 /// The location of this PredefinedExpr.
426 SourceLocation Loc;
427 };
428
430 friend class ASTStmtReader; // deserialization
431 friend class DeclRefExpr;
432
433 LLVM_PREFERRED_TYPE(ExprBitfields)
435
436 LLVM_PREFERRED_TYPE(bool)
437 unsigned HasQualifier : 1;
438 LLVM_PREFERRED_TYPE(bool)
439 unsigned HasTemplateKWAndArgsInfo : 1;
440 LLVM_PREFERRED_TYPE(bool)
441 unsigned HasFoundDecl : 1;
442 LLVM_PREFERRED_TYPE(bool)
443 unsigned HadMultipleCandidates : 1;
444 LLVM_PREFERRED_TYPE(bool)
445 unsigned RefersToEnclosingVariableOrCapture : 1;
446 LLVM_PREFERRED_TYPE(bool)
447 unsigned CapturedByCopyInLambdaWithExplicitObjectParameter : 1;
448 LLVM_PREFERRED_TYPE(NonOdrUseReason)
449 unsigned NonOdrUseReason : 2;
450 LLVM_PREFERRED_TYPE(bool)
451 unsigned IsImmediateEscalating : 1;
452
453 /// The location of the declaration name itself.
454 SourceLocation Loc;
455 };
456
457
459 friend class FloatingLiteral;
460
461 LLVM_PREFERRED_TYPE(ExprBitfields)
463
464 static_assert(
465 llvm::APFloat::S_MaxSemantics < 32,
466 "Too many Semantics enum values to fit in bitfield of size 5");
467 LLVM_PREFERRED_TYPE(llvm::APFloat::Semantics)
468 unsigned Semantics : 5; // Provides semantics for APFloat construction
469 LLVM_PREFERRED_TYPE(bool)
470 unsigned IsExact : 1;
471 };
472
474 friend class ASTStmtReader;
475 friend class StringLiteral;
476
477 LLVM_PREFERRED_TYPE(ExprBitfields)
479
480 /// The kind of this string literal.
481 /// One of the enumeration values of StringLiteral::StringKind.
482 LLVM_PREFERRED_TYPE(StringLiteralKind)
483 unsigned Kind : 3;
484
485 /// The width of a single character in bytes. Only values of 1, 2,
486 /// and 4 bytes are supported. StringLiteral::mapCharByteWidth maps
487 /// the target + string kind to the appropriate CharByteWidth.
488 unsigned CharByteWidth : 3;
489
490 LLVM_PREFERRED_TYPE(bool)
491 unsigned IsPascal : 1;
492
493 /// The number of concatenated token this string is made of.
494 /// This is the number of trailing SourceLocation.
495 unsigned NumConcatenated;
496 };
497
499 friend class CharacterLiteral;
500
501 LLVM_PREFERRED_TYPE(ExprBitfields)
503
504 LLVM_PREFERRED_TYPE(CharacterLiteralKind)
505 unsigned Kind : 3;
506 };
507
509 friend class UnaryOperator;
510
511 LLVM_PREFERRED_TYPE(ExprBitfields)
513
514 LLVM_PREFERRED_TYPE(UnaryOperatorKind)
515 unsigned Opc : 5;
516 LLVM_PREFERRED_TYPE(bool)
517 unsigned CanOverflow : 1;
518 //
519 /// This is only meaningful for operations on floating point
520 /// types when additional values need to be in trailing storage.
521 /// It is 0 otherwise.
522 LLVM_PREFERRED_TYPE(bool)
523 unsigned HasFPFeatures : 1;
524
525 SourceLocation Loc;
526 };
527
530
531 LLVM_PREFERRED_TYPE(ExprBitfields)
533
534 LLVM_PREFERRED_TYPE(UnaryExprOrTypeTrait)
535 unsigned Kind : 4;
536 LLVM_PREFERRED_TYPE(bool)
537 unsigned IsType : 1; // true if operand is a type, false if an expression.
538 };
539
541 friend class ArraySubscriptExpr;
544
545 LLVM_PREFERRED_TYPE(ExprBitfields)
547
548 SourceLocation RBracketLoc;
549 };
550
552 friend class CallExpr;
553
554 LLVM_PREFERRED_TYPE(ExprBitfields)
556
557 unsigned NumPreArgs : 1;
558
559 /// True if the callee of the call expression was found using ADL.
560 LLVM_PREFERRED_TYPE(bool)
561 unsigned UsesADL : 1;
562
563 /// True if the call expression has some floating-point features.
564 LLVM_PREFERRED_TYPE(bool)
565 unsigned HasFPFeatures : 1;
566
567 /// True if the call expression is a must-elide call to a coroutine.
568 LLVM_PREFERRED_TYPE(bool)
569 unsigned IsCoroElideSafe : 1;
570
571 /// Tracks when CallExpr is used to represent an explicit object
572 /// member function, in order to adjust the begin location.
573 LLVM_PREFERRED_TYPE(bool)
574 unsigned ExplicitObjectMemFunUsingMemberSyntax : 1;
575
576 /// Indicates that SourceLocations are cached as
577 /// Trailing objects. See the definition of CallExpr.
578 LLVM_PREFERRED_TYPE(bool)
579 unsigned HasTrailingSourceLoc : 1;
580 };
581
582 enum { NumCallExprBits = 25 };
583
585 friend class ASTStmtReader;
586 friend class MemberExpr;
587
588 LLVM_PREFERRED_TYPE(ExprBitfields)
590
591 /// IsArrow - True if this is "X->F", false if this is "X.F".
592 LLVM_PREFERRED_TYPE(bool)
593 unsigned IsArrow : 1;
594
595 /// True if this member expression used a nested-name-specifier to
596 /// refer to the member, e.g., "x->Base::f".
597 LLVM_PREFERRED_TYPE(bool)
598 unsigned HasQualifier : 1;
599
600 // True if this member expression found its member via a using declaration.
601 LLVM_PREFERRED_TYPE(bool)
602 unsigned HasFoundDecl : 1;
603
604 /// True if this member expression specified a template keyword
605 /// and/or a template argument list explicitly, e.g., x->f<int>,
606 /// x->template f, x->template f<int>.
607 /// When true, an ASTTemplateKWAndArgsInfo structure and its
608 /// TemplateArguments (if any) are present.
609 LLVM_PREFERRED_TYPE(bool)
610 unsigned HasTemplateKWAndArgsInfo : 1;
611
612 /// True if this member expression refers to a method that
613 /// was resolved from an overloaded set having size greater than 1.
614 LLVM_PREFERRED_TYPE(bool)
615 unsigned HadMultipleCandidates : 1;
616
617 /// Value of type NonOdrUseReason indicating why this MemberExpr does
618 /// not constitute an odr-use of the named declaration. Meaningful only
619 /// when naming a static member.
620 LLVM_PREFERRED_TYPE(NonOdrUseReason)
621 unsigned NonOdrUseReason : 2;
622
623 /// This is the location of the -> or . in the expression.
624 SourceLocation OperatorLoc;
625 };
626
628 friend class CastExpr;
629 friend class ImplicitCastExpr;
630
631 LLVM_PREFERRED_TYPE(ExprBitfields)
633
634 LLVM_PREFERRED_TYPE(CastKind)
635 unsigned Kind : 7;
636 LLVM_PREFERRED_TYPE(bool)
637 unsigned PartOfExplicitCast : 1; // Only set for ImplicitCastExpr.
638
639 /// True if the call expression has some floating-point features.
640 LLVM_PREFERRED_TYPE(bool)
641 unsigned HasFPFeatures : 1;
642
643 /// The number of CXXBaseSpecifiers in the cast. 14 bits would be enough
644 /// here. ([implimits] Direct and indirect base classes [16384]).
645 unsigned BasePathSize;
646 };
647
649 friend class BinaryOperator;
650
651 LLVM_PREFERRED_TYPE(ExprBitfields)
653
654 LLVM_PREFERRED_TYPE(BinaryOperatorKind)
655 unsigned Opc : 6;
656
657 /// This is only meaningful for operations on floating point
658 /// types when additional values need to be in trailing storage.
659 /// It is 0 otherwise.
660 LLVM_PREFERRED_TYPE(bool)
661 unsigned HasFPFeatures : 1;
662
663 /// Whether or not this BinaryOperator should be excluded from integer
664 /// overflow sanitization.
665 LLVM_PREFERRED_TYPE(bool)
666 unsigned ExcludedOverflowPattern : 1;
667
668 SourceLocation OpLoc;
669 };
670
672 friend class ASTStmtReader;
673 friend class InitListExpr;
674
675 LLVM_PREFERRED_TYPE(ExprBitfields)
677
678 /// Whether this initializer list originally had a GNU array-range
679 /// designator in it. This is a temporary marker used by CodeGen.
680 LLVM_PREFERRED_TYPE(bool)
681 unsigned HadArrayRangeDesignator : 1;
682 // Whether this list is explicitly written in the source (with braces).
683 LLVM_PREFERRED_TYPE(bool)
684 unsigned IsExplicit : 1;
685 };
686
688 friend class ASTStmtReader;
689 friend class ParenListExpr;
690
691 LLVM_PREFERRED_TYPE(ExprBitfields)
693
694 /// The number of expressions in the paren list.
695 unsigned NumExprs;
696 };
697
699 friend class ASTStmtReader;
701
702 LLVM_PREFERRED_TYPE(ExprBitfields)
704
705 /// The location of the "_Generic".
706 SourceLocation GenericLoc;
707 };
708
710 friend class ASTStmtReader; // deserialization
711 friend class PseudoObjectExpr;
712
713 LLVM_PREFERRED_TYPE(ExprBitfields)
715
716 unsigned NumSubExprs : 16;
717 unsigned ResultIndex : 16;
718 };
719
721 friend class ASTStmtReader;
722 friend class SourceLocExpr;
723
724 LLVM_PREFERRED_TYPE(ExprBitfields)
726
727 /// The kind of source location builtin represented by the SourceLocExpr.
728 /// Ex. __builtin_LINE, __builtin_FUNCTION, etc.
729 LLVM_PREFERRED_TYPE(SourceLocIdentKind)
730 unsigned Kind : 3;
731 };
732
734 friend class ASTStmtReader;
735 friend class ASTStmtWriter;
736 friend class ParenExpr;
737
738 LLVM_PREFERRED_TYPE(ExprBitfields)
740
741 LLVM_PREFERRED_TYPE(bool)
742 unsigned ProducedByFoldExpansion : 1;
743 };
744
746 friend class ShuffleVectorExpr;
747
748 LLVM_PREFERRED_TYPE(ExprBitfields)
750
751 unsigned NumExprs;
752 };
753
755 friend class ASTStmtReader;
756 friend class StmtExpr;
757
758 LLVM_PREFERRED_TYPE(ExprBitfields)
760
761 /// The number of levels of template parameters enclosing this statement
762 /// expression. Used to determine if a statement expression remains
763 /// dependent after instantiation.
764 unsigned TemplateDepth;
765 };
766
768 friend class ASTStmtReader;
769 friend class ChooseExpr;
770
771 LLVM_PREFERRED_TYPE(ExprBitfields)
773
774 LLVM_PREFERRED_TYPE(bool)
775 bool CondIsTrue : 1;
776 };
777
778 //===--- C++ Expression bitfields classes ---===//
779
781 friend class ASTStmtReader;
783
784 LLVM_PREFERRED_TYPE(CallExprBitfields)
786
787 /// The kind of this overloaded operator. One of the enumerator
788 /// value of OverloadedOperatorKind.
789 LLVM_PREFERRED_TYPE(OverloadedOperatorKind)
790 unsigned OperatorKind : 6;
791
792 /// Whether this is a C++20 rewritten reversed operator, where the
793 /// arguments are in reversed source order.
794 LLVM_PREFERRED_TYPE(bool)
795 unsigned IsReversed : 1;
796 };
797
799 friend class ASTStmtReader;
801
802 LLVM_PREFERRED_TYPE(CallExprBitfields)
804
805 LLVM_PREFERRED_TYPE(bool)
806 unsigned IsReversed : 1;
807 };
808
810 friend class CXXBoolLiteralExpr;
811
812 LLVM_PREFERRED_TYPE(ExprBitfields)
814
815 /// The value of the boolean literal.
816 LLVM_PREFERRED_TYPE(bool)
817 unsigned Value : 1;
818
819 /// The location of the boolean literal.
820 SourceLocation Loc;
821 };
822
825
826 LLVM_PREFERRED_TYPE(ExprBitfields)
828
829 /// The location of the null pointer literal.
830 SourceLocation Loc;
831 };
832
834 friend class CXXThisExpr;
835
836 LLVM_PREFERRED_TYPE(ExprBitfields)
838
839 /// Whether this is an implicit "this".
840 LLVM_PREFERRED_TYPE(bool)
841 unsigned IsImplicit : 1;
842
843 /// Whether there is a lambda with an explicit object parameter that
844 /// captures this "this" by copy.
845 LLVM_PREFERRED_TYPE(bool)
846 unsigned CapturedByCopyInLambdaWithExplicitObjectParameter : 1;
847
848 /// The location of the "this".
849 SourceLocation Loc;
850 };
851
853 friend class ASTStmtReader;
854 friend class CXXThrowExpr;
855
856 LLVM_PREFERRED_TYPE(ExprBitfields)
858
859 /// Whether the thrown variable (if any) is in scope.
860 LLVM_PREFERRED_TYPE(bool)
861 unsigned IsThrownVariableInScope : 1;
862
863 /// The location of the "throw".
864 SourceLocation ThrowLoc;
865 };
866
868 friend class ASTStmtReader;
869 friend class CXXDefaultArgExpr;
870
871 LLVM_PREFERRED_TYPE(ExprBitfields)
873
874 /// Whether this CXXDefaultArgExpr rewrote its argument and stores a copy.
875 LLVM_PREFERRED_TYPE(bool)
876 unsigned HasRewrittenInit : 1;
877
878 /// The location where the default argument expression was used.
879 SourceLocation Loc;
880 };
881
883 friend class ASTStmtReader;
884 friend class CXXDefaultInitExpr;
885
886 LLVM_PREFERRED_TYPE(ExprBitfields)
888
889 /// Whether this CXXDefaultInitExprBitfields rewrote its argument and stores
890 /// a copy.
891 LLVM_PREFERRED_TYPE(bool)
892 unsigned HasRewrittenInit : 1;
893
894 /// The location where the default initializer expression was used.
895 SourceLocation Loc;
896 };
897
899 friend class ASTStmtReader;
901
902 LLVM_PREFERRED_TYPE(ExprBitfields)
904
905 SourceLocation RParenLoc;
906 };
907
909 friend class ASTStmtReader;
910 friend class ASTStmtWriter;
911 friend class CXXNewExpr;
912
913 LLVM_PREFERRED_TYPE(ExprBitfields)
915
916 /// Was the usage ::new, i.e. is the global new to be used?
917 LLVM_PREFERRED_TYPE(bool)
918 unsigned IsGlobalNew : 1;
919
920 /// Do we allocate an array? If so, the first trailing "Stmt *" is the
921 /// size expression.
922 LLVM_PREFERRED_TYPE(bool)
923 unsigned IsArray : 1;
924
925 /// Should the alignment be passed to the allocation function?
926 LLVM_PREFERRED_TYPE(bool)
927 unsigned ShouldPassAlignment : 1;
928
929 /// Should the type identity be passed to the allocation function?
930 LLVM_PREFERRED_TYPE(bool)
931 unsigned ShouldPassTypeIdentity : 1;
932
933 /// If this is an array allocation, does the usual deallocation
934 /// function for the allocated type want to know the allocated size?
935 LLVM_PREFERRED_TYPE(bool)
936 unsigned UsualArrayDeleteWantsSize : 1;
937
938 // Is initializer expr present?
939 LLVM_PREFERRED_TYPE(bool)
940 unsigned HasInitializer : 1;
941
942 /// What kind of initializer syntax used? Could be none, parens, or braces.
943 LLVM_PREFERRED_TYPE(CXXNewInitializationStyle)
944 unsigned StoredInitializationStyle : 2;
945
946 /// True if the allocated type was expressed as a parenthesized type-id.
947 LLVM_PREFERRED_TYPE(bool)
948 unsigned IsParenTypeId : 1;
949
950 /// The number of placement new arguments.
951 unsigned NumPlacementArgs;
952 };
953
955 friend class ASTStmtReader;
956 friend class CXXDeleteExpr;
957
958 LLVM_PREFERRED_TYPE(ExprBitfields)
960
961 /// Is this a forced global delete, i.e. "::delete"?
962 LLVM_PREFERRED_TYPE(bool)
963 unsigned GlobalDelete : 1;
964
965 /// Is this the array form of delete, i.e. "delete[]"?
966 LLVM_PREFERRED_TYPE(bool)
967 unsigned ArrayForm : 1;
968
969 /// ArrayFormAsWritten can be different from ArrayForm if 'delete' is
970 /// applied to pointer-to-array type (ArrayFormAsWritten will be false
971 /// while ArrayForm will be true).
972 LLVM_PREFERRED_TYPE(bool)
973 unsigned ArrayFormAsWritten : 1;
974
975 /// Does the usual deallocation function for the element type require
976 /// a size_t argument?
977 LLVM_PREFERRED_TYPE(bool)
978 unsigned UsualArrayDeleteWantsSize : 1;
979
980 /// Location of the expression.
981 SourceLocation Loc;
982 };
983
985 friend class ASTStmtReader;
986 friend class ASTStmtWriter;
987 friend class TypeTraitExpr;
988
989 LLVM_PREFERRED_TYPE(ExprBitfields)
991
992 /// The kind of type trait, which is a value of a TypeTrait enumerator.
993 LLVM_PREFERRED_TYPE(TypeTrait)
994 unsigned Kind : 8;
995
996 LLVM_PREFERRED_TYPE(bool)
997 unsigned IsBooleanTypeTrait : 1;
998
999 /// If this expression is a non value-dependent boolean trait,
1000 /// this indicates whether the trait evaluated true or false.
1001 LLVM_PREFERRED_TYPE(bool)
1002 unsigned Value : 1;
1003 /// The number of arguments to this type trait. According to [implimits]
1004 /// 8 bits would be enough, but we require (and test for) at least 16 bits
1005 /// to mirror FunctionType.
1006 unsigned NumArgs;
1007 };
1008
1010 friend class ASTStmtReader;
1011 friend class ASTStmtWriter;
1013
1014 LLVM_PREFERRED_TYPE(ExprBitfields)
1016
1017 /// Whether the name includes info for explicit template
1018 /// keyword and arguments.
1019 LLVM_PREFERRED_TYPE(bool)
1020 unsigned HasTemplateKWAndArgsInfo : 1;
1021 };
1022
1024 friend class ASTStmtReader;
1025 friend class CXXConstructExpr;
1026
1027 LLVM_PREFERRED_TYPE(ExprBitfields)
1029
1030 LLVM_PREFERRED_TYPE(bool)
1031 unsigned Elidable : 1;
1032 LLVM_PREFERRED_TYPE(bool)
1033 unsigned HadMultipleCandidates : 1;
1034 LLVM_PREFERRED_TYPE(bool)
1035 unsigned ListInitialization : 1;
1036 LLVM_PREFERRED_TYPE(bool)
1037 unsigned StdInitListInitialization : 1;
1038 LLVM_PREFERRED_TYPE(bool)
1039 unsigned ZeroInitialization : 1;
1040 LLVM_PREFERRED_TYPE(CXXConstructionKind)
1041 unsigned ConstructionKind : 3;
1042 LLVM_PREFERRED_TYPE(bool)
1043 unsigned IsImmediateEscalating : 1;
1044
1045 SourceLocation Loc;
1046 };
1047
1049 friend class ASTStmtReader; // deserialization
1050 friend class ExprWithCleanups;
1051
1052 LLVM_PREFERRED_TYPE(ExprBitfields)
1054
1055 // When false, it must not have side effects.
1056 LLVM_PREFERRED_TYPE(bool)
1057 unsigned CleanupsHaveSideEffects : 1;
1058
1059 unsigned NumObjects : 32 - 1 - NumExprBits;
1060 };
1061
1063 friend class ASTStmtReader;
1065
1066 LLVM_PREFERRED_TYPE(ExprBitfields)
1068
1069 /// The number of arguments used to construct the type.
1070 unsigned NumArgs;
1071 };
1072
1074 friend class ASTStmtReader;
1076
1077 LLVM_PREFERRED_TYPE(ExprBitfields)
1079
1080 /// Whether this member expression used the '->' operator or
1081 /// the '.' operator.
1082 LLVM_PREFERRED_TYPE(bool)
1083 unsigned IsArrow : 1;
1084
1085 /// Whether this member expression has info for explicit template
1086 /// keyword and arguments.
1087 LLVM_PREFERRED_TYPE(bool)
1088 unsigned HasTemplateKWAndArgsInfo : 1;
1089
1090 /// See getFirstQualifierFoundInScope() and the comment listing
1091 /// the trailing objects.
1092 LLVM_PREFERRED_TYPE(bool)
1093 unsigned HasFirstQualifierFoundInScope : 1;
1094
1095 /// The location of the '->' or '.' operator.
1096 SourceLocation OperatorLoc;
1097 };
1098
1100 friend class ASTStmtReader;
1101 friend class OverloadExpr;
1102
1103 LLVM_PREFERRED_TYPE(ExprBitfields)
1105
1106 /// Whether the name includes info for explicit template
1107 /// keyword and arguments.
1108 LLVM_PREFERRED_TYPE(bool)
1109 unsigned HasTemplateKWAndArgsInfo : 1;
1110
1111 /// Padding used by the derived classes to store various bits. If you
1112 /// need to add some data here, shrink this padding and add your data
1113 /// above. NumOverloadExprBits also needs to be updated.
1114 unsigned : 32 - NumExprBits - 1;
1115
1116 /// The number of results.
1117 unsigned NumResults;
1118 };
1120
1122 friend class ASTStmtReader;
1124
1125 LLVM_PREFERRED_TYPE(OverloadExprBitfields)
1127
1128 /// True if these lookup results should be extended by
1129 /// argument-dependent lookup if this is the operand of a function call.
1130 LLVM_PREFERRED_TYPE(bool)
1131 unsigned RequiresADL : 1;
1132 };
1133 static_assert(sizeof(UnresolvedLookupExprBitfields) <= 4,
1134 "UnresolvedLookupExprBitfields must be <= than 4 bytes to"
1135 "avoid trashing OverloadExprBitfields::NumResults!");
1136
1138 friend class ASTStmtReader;
1140
1141 LLVM_PREFERRED_TYPE(OverloadExprBitfields)
1143
1144 /// Whether this member expression used the '->' operator or
1145 /// the '.' operator.
1146 LLVM_PREFERRED_TYPE(bool)
1147 unsigned IsArrow : 1;
1148
1149 /// Whether the lookup results contain an unresolved using declaration.
1150 LLVM_PREFERRED_TYPE(bool)
1151 unsigned HasUnresolvedUsing : 1;
1152 };
1153 static_assert(sizeof(UnresolvedMemberExprBitfields) <= 4,
1154 "UnresolvedMemberExprBitfields must be <= than 4 bytes to"
1155 "avoid trashing OverloadExprBitfields::NumResults!");
1156
1158 friend class ASTStmtReader;
1159 friend class CXXNoexceptExpr;
1160
1161 LLVM_PREFERRED_TYPE(ExprBitfields)
1163
1164 LLVM_PREFERRED_TYPE(bool)
1165 unsigned Value : 1;
1166 };
1167
1169 friend class ASTStmtReader;
1171
1172 LLVM_PREFERRED_TYPE(ExprBitfields)
1174
1175 /// The location of the non-type template parameter reference.
1176 SourceLocation NameLoc;
1177 };
1178
1180 friend class ASTStmtReader;
1181 friend class ASTStmtWriter;
1182 friend class LambdaExpr;
1183
1184 LLVM_PREFERRED_TYPE(ExprBitfields)
1186
1187 /// The default capture kind, which is a value of type
1188 /// LambdaCaptureDefault.
1189 LLVM_PREFERRED_TYPE(LambdaCaptureDefault)
1190 unsigned CaptureDefault : 2;
1191
1192 /// Whether this lambda had an explicit parameter list vs. an
1193 /// implicit (and empty) parameter list.
1194 LLVM_PREFERRED_TYPE(bool)
1195 unsigned ExplicitParams : 1;
1196
1197 /// Whether this lambda had the result type explicitly specified.
1198 LLVM_PREFERRED_TYPE(bool)
1199 unsigned ExplicitResultType : 1;
1200
1201 /// The number of captures.
1202 unsigned NumCaptures : 16;
1203 };
1204
1206 friend class ASTStmtReader;
1207 friend class ASTStmtWriter;
1208 friend class RequiresExpr;
1209
1210 LLVM_PREFERRED_TYPE(ExprBitfields)
1212
1213 LLVM_PREFERRED_TYPE(bool)
1214 unsigned IsSatisfied : 1;
1215 SourceLocation RequiresKWLoc;
1216 };
1217
1220 friend class ASTStmtReader;
1221 LLVM_PREFERRED_TYPE(ExprBitfields)
1223
1224 /// The trait. An ArrayTypeTrait enum in MSVC compat unsigned.
1225 LLVM_PREFERRED_TYPE(ArrayTypeTrait)
1226 unsigned ATT : 2;
1227 };
1228
1231 friend class ASTStmtReader;
1232 LLVM_PREFERRED_TYPE(ExprBitfields)
1234
1235 /// The trait. A ExpressionTrait enum in MSVC compatible unsigned.
1236 LLVM_PREFERRED_TYPE(ExpressionTrait)
1237 unsigned ET : 31;
1238
1239 /// The value of the type trait. Unspecified if dependent.
1240 LLVM_PREFERRED_TYPE(bool)
1241 unsigned Value : 1;
1242 };
1243
1245 friend class CXXFoldExpr;
1246 friend class ASTStmtReader;
1247 friend class ASTStmtWriter;
1248
1249 LLVM_PREFERRED_TYPE(ExprBitfields)
1251
1252 BinaryOperatorKind Opcode;
1253 };
1254
1256 friend class PackIndexingExpr;
1257 friend class ASTStmtWriter;
1258 friend class ASTStmtReader;
1259
1260 LLVM_PREFERRED_TYPE(ExprBitfields)
1262 // The size of the trailing expressions.
1263 unsigned TransformedExpressions : 31;
1264
1265 LLVM_PREFERRED_TYPE(bool)
1266 unsigned FullySubstituted : 1;
1267 };
1268
1269 //===--- C++ Coroutines bitfields classes ---===//
1270
1272 friend class CoawaitExpr;
1273
1274 LLVM_PREFERRED_TYPE(ExprBitfields)
1276
1277 LLVM_PREFERRED_TYPE(bool)
1278 unsigned IsImplicit : 1;
1279 };
1280
1281 //===--- Obj-C Expression bitfields classes ---===//
1282
1284 friend class ObjCObjectLiteral;
1285
1287
1288 unsigned IsExpressibleAsConstantInitializer : 1;
1289 };
1290
1293
1294 LLVM_PREFERRED_TYPE(ExprBitfields)
1296
1297 LLVM_PREFERRED_TYPE(bool)
1298 unsigned ShouldCopy : 1;
1299 };
1300
1301 //===--- Clang Extensions bitfields classes ---===//
1302
1304 friend class ASTStmtReader;
1305 friend class OpaqueValueExpr;
1306
1307 LLVM_PREFERRED_TYPE(ExprBitfields)
1309
1310 /// The OVE is a unique semantic reference to its source expression if this
1311 /// bit is set to true.
1312 LLVM_PREFERRED_TYPE(bool)
1313 unsigned IsUnique : 1;
1314
1315 SourceLocation Loc;
1316 };
1317
1319 friend class ConvertVectorExpr;
1320
1321 LLVM_PREFERRED_TYPE(ExprBitfields)
1323
1324 //
1325 /// This is only meaningful for operations on floating point
1326 /// types when additional values need to be in trailing storage.
1327 /// It is 0 otherwise.
1328 LLVM_PREFERRED_TYPE(bool)
1329 unsigned HasFPFeatures : 1;
1330 };
1331
1332 union {
1333 // Same order as in StmtNodes.td.
1334 // Statements
1350
1351 // Expressions
1373
1374 // GNU Extensions.
1377
1378 // C++ Expressions
1407
1408 // C++ Coroutines expressions
1410
1411 // Obj-C Expressions
1414
1415 // Clang Extensions
1418 };
1419
1420public:
1421 // Only allow allocation of Stmts using the allocator in ASTContext
1422 // or by doing a placement new.
1423 void* operator new(size_t bytes, const ASTContext& C,
1424 unsigned alignment = 8);
1425
1426 void* operator new(size_t bytes, const ASTContext* C,
1427 unsigned alignment = 8) {
1428 return operator new(bytes, *C, alignment);
1429 }
1430
1431 void *operator new(size_t bytes, void *mem) noexcept { return mem; }
1432
1433 void operator delete(void *, const ASTContext &, unsigned) noexcept {}
1434 void operator delete(void *, const ASTContext *, unsigned) noexcept {}
1435 void operator delete(void *, size_t) noexcept {}
1436 void operator delete(void *, void *) noexcept {}
1437
1438public:
1439 /// A placeholder type used to construct an empty shell of a
1440 /// type, that will be filled in later (e.g., by some
1441 /// de-serialization).
1442 struct EmptyShell {};
1443
1444 /// The likelihood of a branch being taken.
1446 LH_Unlikely = -1, ///< Branch has the [[unlikely]] attribute.
1447 LH_None, ///< No attribute set or branches of the IfStmt have
1448 ///< the same attribute.
1449 LH_Likely ///< Branch has the [[likely]] attribute.
1450 };
1451
1452protected:
1453 /// Iterator for iterating over Stmt * arrays that contain only T *.
1454 ///
1455 /// This is needed because AST nodes use Stmt* arrays to store
1456 /// references to children (to be compatible with StmtIterator).
1457 template<typename T, typename TPtr = T *, typename StmtPtr = Stmt *>
1459 : llvm::iterator_adaptor_base<CastIterator<T, TPtr, StmtPtr>, StmtPtr *,
1460 std::random_access_iterator_tag, TPtr> {
1461 using Base = typename CastIterator::iterator_adaptor_base;
1462
1464 CastIterator(StmtPtr *I) : Base(I) {}
1465
1466 typename Base::value_type operator*() const {
1467 return cast_or_null<T>(*this->I);
1468 }
1469 };
1470
1471 /// Const iterator for iterating over Stmt * arrays that contain only T *.
1472 template <typename T>
1474
1477
1478private:
1479 /// Whether statistic collection is enabled.
1480 static bool StatisticsEnabled;
1481
1482protected:
1483 /// Construct an empty statement.
1484 explicit Stmt(StmtClass SC, EmptyShell) : Stmt(SC) {}
1485
1486public:
1487 Stmt() = delete;
1488 Stmt(const Stmt &) = delete;
1489 Stmt(Stmt &&) = delete;
1490 Stmt &operator=(const Stmt &) = delete;
1491 Stmt &operator=(Stmt &&) = delete;
1492
1494 static_assert(sizeof(*this) <= 8,
1495 "changing bitfields changed sizeof(Stmt)");
1496 static_assert(sizeof(*this) % alignof(void *) == 0,
1497 "Insufficient alignment!");
1498 StmtBits.sClass = SC;
1499 if (StatisticsEnabled) Stmt::addStmtClass(SC);
1500 }
1501
1503 return static_cast<StmtClass>(StmtBits.sClass);
1504 }
1505
1506 const char *getStmtClassName() const;
1507
1508 /// SourceLocation tokens are not useful in isolation - they are low level
1509 /// value objects created/interpreted by SourceManager. We assume AST
1510 /// clients will have a pointer to the respective SourceManager.
1511 SourceRange getSourceRange() const LLVM_READONLY;
1512 SourceLocation getBeginLoc() const LLVM_READONLY;
1513 SourceLocation getEndLoc() const LLVM_READONLY;
1514
1515 // global temp stats (until we have a per-module visitor)
1516 static void addStmtClass(const StmtClass s);
1517 static void EnableStatistics();
1518 static void PrintStats();
1519
1520 /// \returns the likelihood of a set of attributes.
1521 static Likelihood getLikelihood(ArrayRef<const Attr *> Attrs);
1522
1523 /// \returns the likelihood of a statement.
1524 static Likelihood getLikelihood(const Stmt *S);
1525
1526 /// \returns the likelihood attribute of a statement.
1527 static const Attr *getLikelihoodAttr(const Stmt *S);
1528
1529 /// \returns the likelihood of the 'then' branch of an 'if' statement. The
1530 /// 'else' branch is required to determine whether both branches specify the
1531 /// same likelihood, which affects the result.
1532 static Likelihood getLikelihood(const Stmt *Then, const Stmt *Else);
1533
1534 /// \returns whether the likelihood of the branches of an if statement are
1535 /// conflicting. When the first element is \c true there's a conflict and
1536 /// the Attr's are the conflicting attributes of the Then and Else Stmt.
1537 static std::tuple<bool, const Attr *, const Attr *>
1538 determineLikelihoodConflict(const Stmt *Then, const Stmt *Else);
1539
1540 /// Dumps the specified AST fragment and all subtrees to
1541 /// \c llvm::errs().
1542 void dump() const;
1543 void dump(raw_ostream &OS, const ASTContext &Context) const;
1544
1545 /// \return Unique reproducible object identifier
1546 int64_t getID(const ASTContext &Context) const;
1547
1548 /// dumpColor - same as dump(), but forces color highlighting.
1549 void dumpColor() const;
1550
1551 /// dumpPretty/printPretty - These two methods do a "pretty print" of the AST
1552 /// back to its original source language syntax.
1553 void dumpPretty(const ASTContext &Context) const;
1554 void printPretty(raw_ostream &OS, PrinterHelper *Helper,
1555 const PrintingPolicy &Policy, unsigned Indentation = 0,
1556 StringRef NewlineSymbol = "\n",
1557 const ASTContext *Context = nullptr) const;
1558 void printPrettyControlled(raw_ostream &OS, PrinterHelper *Helper,
1559 const PrintingPolicy &Policy,
1560 unsigned Indentation = 0,
1561 StringRef NewlineSymbol = "\n",
1562 const ASTContext *Context = nullptr) const;
1563
1564 /// Pretty-prints in JSON format.
1565 void printJson(raw_ostream &Out, PrinterHelper *Helper,
1566 const PrintingPolicy &Policy, bool AddQuotes) const;
1567
1568 /// viewAST - Visualize an AST rooted at this Stmt* using GraphViz. Only
1569 /// works on systems with GraphViz (Mac OS X) or dot+gv installed.
1570 void viewAST() const;
1571
1572 /// Skip no-op (attributed, compound) container stmts and skip captured
1573 /// stmt at the top, if \a IgnoreCaptured is true.
1574 Stmt *IgnoreContainers(bool IgnoreCaptured = false);
1575 const Stmt *IgnoreContainers(bool IgnoreCaptured = false) const {
1576 return const_cast<Stmt *>(this)->IgnoreContainers(IgnoreCaptured);
1577 }
1578
1579 const Stmt *stripLabelLikeStatements() const;
1581 return const_cast<Stmt*>(
1582 const_cast<const Stmt*>(this)->stripLabelLikeStatements());
1583 }
1584
1585 /// Child Iterators: All subclasses must implement 'children'
1586 /// to permit easy iteration over the substatements/subexpressions of an
1587 /// AST node. This permits easy iteration over all nodes in the AST.
1590
1591 using child_range = llvm::iterator_range<child_iterator>;
1592 using const_child_range = llvm::iterator_range<const_child_iterator>;
1593
1595
1597 return const_cast<Stmt *>(this)->children();
1598 }
1599
1600 child_iterator child_begin() { return children().begin(); }
1601 child_iterator child_end() { return children().end(); }
1602
1603 const_child_iterator child_begin() const { return children().begin(); }
1604 const_child_iterator child_end() const { return children().end(); }
1605
1606 /// Produce a unique representation of the given statement.
1607 ///
1608 /// \param ID once the profiling operation is complete, will contain
1609 /// the unique representation of the given statement.
1610 ///
1611 /// \param Context the AST context in which the statement resides
1612 ///
1613 /// \param Canonical whether the profile should be based on the canonical
1614 /// representation of this statement (e.g., where non-type template
1615 /// parameters are identified by index/level rather than their
1616 /// declaration pointers) or the exact representation of the statement as
1617 /// written in the source.
1618 /// \param ProfileLambdaExpr whether or not to profile lambda expressions.
1619 /// When false, the lambda expressions are never considered to be equal to
1620 /// other lambda expressions. When true, the lambda expressions with the same
1621 /// implementation will be considered to be the same. ProfileLambdaExpr should
1622 /// only be true when we try to merge two declarations within modules.
1623 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
1624 bool Canonical, bool ProfileLambdaExpr = false) const;
1625
1626 /// Calculate a unique representation for a statement that is
1627 /// stable across compiler invocations.
1628 ///
1629 /// \param ID profile information will be stored in ID.
1630 ///
1631 /// \param Hash an ODRHash object which will be called where pointers would
1632 /// have been used in the Profile function.
1633 void ProcessODRHash(llvm::FoldingSetNodeID &ID, ODRHash& Hash) const;
1634};
1635
1636/// DeclStmt - Adaptor class for mixing declarations with statements and
1637/// expressions. For example, CompoundStmt mixes statements, expressions
1638/// and declarations (variables, types). Another example is ForStmt, where
1639/// the first statement can be an expression or a declaration.
1640class DeclStmt : public Stmt {
1641 DeclGroupRef DG;
1642 SourceLocation StartLoc, EndLoc;
1643
1644public:
1646 : Stmt(DeclStmtClass), DG(dg), StartLoc(startLoc), EndLoc(endLoc) {}
1647
1648 /// Build an empty declaration statement.
1649 explicit DeclStmt(EmptyShell Empty) : Stmt(DeclStmtClass, Empty) {}
1650
1651 /// isSingleDecl - This method returns true if this DeclStmt refers
1652 /// to a single Decl.
1653 bool isSingleDecl() const { return DG.isSingleDecl(); }
1654
1655 const Decl *getSingleDecl() const { return DG.getSingleDecl(); }
1656 Decl *getSingleDecl() { return DG.getSingleDecl(); }
1657
1658 const DeclGroupRef getDeclGroup() const { return DG; }
1660 void setDeclGroup(DeclGroupRef DGR) { DG = DGR; }
1661
1662 void setStartLoc(SourceLocation L) { StartLoc = L; }
1663 SourceLocation getEndLoc() const { return EndLoc; }
1664 void setEndLoc(SourceLocation L) { EndLoc = L; }
1665
1666 SourceLocation getBeginLoc() const LLVM_READONLY { return StartLoc; }
1667
1668 static bool classof(const Stmt *T) {
1669 return T->getStmtClass() == DeclStmtClass;
1670 }
1671
1672 // Iterators over subexpressions.
1674 return child_range(child_iterator(DG.begin(), DG.end()),
1675 child_iterator(DG.end(), DG.end()));
1676 }
1677
1679 auto Children = const_cast<DeclStmt *>(this)->children();
1681 }
1682
1685 using decl_range = llvm::iterator_range<decl_iterator>;
1686 using decl_const_range = llvm::iterator_range<const_decl_iterator>;
1687
1689
1692 }
1693
1694 decl_iterator decl_begin() { return DG.begin(); }
1695 decl_iterator decl_end() { return DG.end(); }
1696 const_decl_iterator decl_begin() const { return DG.begin(); }
1697 const_decl_iterator decl_end() const { return DG.end(); }
1698
1699 using reverse_decl_iterator = std::reverse_iterator<decl_iterator>;
1700
1704
1708};
1709
1710/// NullStmt - This is the null statement ";": C99 6.8.3p3.
1711///
1712class NullStmt : public Stmt {
1713public:
1715 : Stmt(NullStmtClass) {
1716 NullStmtBits.HasLeadingEmptyMacro = hasLeadingEmptyMacro;
1717 setSemiLoc(L);
1718 }
1719
1720 /// Build an empty null statement.
1721 explicit NullStmt(EmptyShell Empty) : Stmt(NullStmtClass, Empty) {}
1722
1723 SourceLocation getSemiLoc() const { return NullStmtBits.SemiLoc; }
1724 void setSemiLoc(SourceLocation L) { NullStmtBits.SemiLoc = L; }
1725
1727 return NullStmtBits.HasLeadingEmptyMacro;
1728 }
1729
1732
1733 static bool classof(const Stmt *T) {
1734 return T->getStmtClass() == NullStmtClass;
1735 }
1736
1740
1744};
1745
1746/// CompoundStmt - This represents a group of statements like { stmt stmt }.
1747class CompoundStmt final
1748 : public Stmt,
1749 private llvm::TrailingObjects<CompoundStmt, Stmt *, FPOptionsOverride> {
1750 friend class ASTStmtReader;
1751 friend TrailingObjects;
1752
1753 /// The location of the opening "{".
1754 SourceLocation LBraceLoc;
1755
1756 /// The location of the closing "}".
1757 SourceLocation RBraceLoc;
1758
1761 explicit CompoundStmt(EmptyShell Empty) : Stmt(CompoundStmtClass, Empty) {}
1762
1763 void setStmts(ArrayRef<Stmt *> Stmts);
1764
1765 /// Set FPOptionsOverride in trailing storage. Used only by Serialization.
1766 void setStoredFPFeatures(FPOptionsOverride F) {
1767 assert(hasStoredFPFeatures());
1768 *getTrailingObjects<FPOptionsOverride>() = F;
1769 }
1770
1771 size_t numTrailingObjects(OverloadToken<Stmt *>) const {
1772 return CompoundStmtBits.NumStmts;
1773 }
1774
1775public:
1776 static CompoundStmt *Create(const ASTContext &C, ArrayRef<Stmt *> Stmts,
1777 FPOptionsOverride FPFeatures, SourceLocation LB,
1778 SourceLocation RB);
1779
1780 // Build an empty compound statement with a location.
1781 explicit CompoundStmt(SourceLocation Loc) : CompoundStmt(Loc, Loc) {}
1782
1784 : Stmt(CompoundStmtClass), LBraceLoc(Loc), RBraceLoc(EndLoc) {
1785 CompoundStmtBits.NumStmts = 0;
1786 CompoundStmtBits.HasFPFeatures = 0;
1787 }
1788
1789 // Build an empty compound statement.
1790 static CompoundStmt *CreateEmpty(const ASTContext &C, unsigned NumStmts,
1791 bool HasFPFeatures);
1792
1793 bool body_empty() const { return CompoundStmtBits.NumStmts == 0; }
1794 unsigned size() const { return CompoundStmtBits.NumStmts; }
1795
1796 bool hasStoredFPFeatures() const { return CompoundStmtBits.HasFPFeatures; }
1797
1798 /// Get FPOptionsOverride from trailing storage.
1800 assert(hasStoredFPFeatures());
1801 return *getTrailingObjects<FPOptionsOverride>();
1802 }
1803
1804 /// Get the store FPOptionsOverride or default if not stored.
1808
1810 using body_range = llvm::iterator_range<body_iterator>;
1811
1813 body_iterator body_begin() { return getTrailingObjects<Stmt *>(); }
1815 Stmt *body_front() { return !body_empty() ? body_begin()[0] : nullptr; }
1816
1818 return !body_empty() ? body_begin()[size() - 1] : nullptr;
1819 }
1820
1821 using const_body_iterator = Stmt *const *;
1822 using body_const_range = llvm::iterator_range<const_body_iterator>;
1823
1826 }
1827
1829 return getTrailingObjects<Stmt *>();
1830 }
1831
1833
1834 const Stmt *body_front() const {
1835 return !body_empty() ? body_begin()[0] : nullptr;
1836 }
1837
1838 const Stmt *body_back() const {
1839 return !body_empty() ? body_begin()[size() - 1] : nullptr;
1840 }
1841
1842 using reverse_body_iterator = std::reverse_iterator<body_iterator>;
1843
1847
1851
1853 std::reverse_iterator<const_body_iterator>;
1854
1858
1862
1863 SourceLocation getBeginLoc() const { return LBraceLoc; }
1864 SourceLocation getEndLoc() const { return RBraceLoc; }
1865
1866 SourceLocation getLBracLoc() const { return LBraceLoc; }
1867 SourceLocation getRBracLoc() const { return RBraceLoc; }
1868
1869 static bool classof(const Stmt *T) {
1870 return T->getStmtClass() == CompoundStmtClass;
1871 }
1872
1873 // Iterators
1875
1879};
1880
1881// SwitchCase is the base class for CaseStmt and DefaultStmt,
1882class SwitchCase : public Stmt {
1883protected:
1884 /// The location of the ":".
1886
1887 // The location of the "case" or "default" keyword. Stored in SwitchCaseBits.
1888 // SourceLocation KeywordLoc;
1889
1890 /// A pointer to the following CaseStmt or DefaultStmt class,
1891 /// used by SwitchStmt.
1893
1898
1900
1901public:
1905
1906 SourceLocation getKeywordLoc() const { return SwitchCaseBits.KeywordLoc; }
1907 void setKeywordLoc(SourceLocation L) { SwitchCaseBits.KeywordLoc = L; }
1910
1911 inline Stmt *getSubStmt();
1912 const Stmt *getSubStmt() const {
1913 return const_cast<SwitchCase *>(this)->getSubStmt();
1914 }
1915
1917 inline SourceLocation getEndLoc() const LLVM_READONLY;
1918
1919 static bool classof(const Stmt *T) {
1920 return T->getStmtClass() == CaseStmtClass ||
1921 T->getStmtClass() == DefaultStmtClass;
1922 }
1923};
1924
1925/// CaseStmt - Represent a case statement. It can optionally be a GNU case
1926/// statement of the form LHS ... RHS representing a range of cases.
1927class CaseStmt final
1928 : public SwitchCase,
1929 private llvm::TrailingObjects<CaseStmt, Stmt *, SourceLocation> {
1930 friend TrailingObjects;
1931
1932 // CaseStmt is followed by several trailing objects, some of which optional.
1933 // Note that it would be more convenient to put the optional trailing objects
1934 // at the end but this would impact children().
1935 // The trailing objects are in order:
1936 //
1937 // * A "Stmt *" for the LHS of the case statement. Always present.
1938 //
1939 // * A "Stmt *" for the RHS of the case statement. This is a GNU extension
1940 // which allow ranges in cases statement of the form LHS ... RHS.
1941 // Present if and only if caseStmtIsGNURange() is true.
1942 //
1943 // * A "Stmt *" for the substatement of the case statement. Always present.
1944 //
1945 // * A SourceLocation for the location of the ... if this is a case statement
1946 // with a range. Present if and only if caseStmtIsGNURange() is true.
1947 enum { LhsOffset = 0, SubStmtOffsetFromRhs = 1 };
1948 enum { NumMandatoryStmtPtr = 2 };
1949
1950 unsigned numTrailingObjects(OverloadToken<Stmt *>) const {
1951 return NumMandatoryStmtPtr + caseStmtIsGNURange();
1952 }
1953
1954 unsigned lhsOffset() const { return LhsOffset; }
1955 unsigned rhsOffset() const { return LhsOffset + caseStmtIsGNURange(); }
1956 unsigned subStmtOffset() const { return rhsOffset() + SubStmtOffsetFromRhs; }
1957
1958 /// Build a case statement assuming that the storage for the
1959 /// trailing objects has been properly allocated.
1960 CaseStmt(Expr *lhs, Expr *rhs, SourceLocation caseLoc,
1961 SourceLocation ellipsisLoc, SourceLocation colonLoc)
1962 : SwitchCase(CaseStmtClass, caseLoc, colonLoc) {
1963 // Handle GNU case statements of the form LHS ... RHS.
1964 bool IsGNURange = rhs != nullptr;
1965 SwitchCaseBits.CaseStmtIsGNURange = IsGNURange;
1966 setLHS(lhs);
1967 setSubStmt(nullptr);
1968 if (IsGNURange) {
1969 setRHS(rhs);
1970 setEllipsisLoc(ellipsisLoc);
1971 }
1972 }
1973
1974 /// Build an empty switch case statement.
1975 explicit CaseStmt(EmptyShell Empty, bool CaseStmtIsGNURange)
1976 : SwitchCase(CaseStmtClass, Empty) {
1977 SwitchCaseBits.CaseStmtIsGNURange = CaseStmtIsGNURange;
1978 }
1979
1980public:
1981 /// Build a case statement.
1982 static CaseStmt *Create(const ASTContext &Ctx, Expr *lhs, Expr *rhs,
1983 SourceLocation caseLoc, SourceLocation ellipsisLoc,
1984 SourceLocation colonLoc);
1985
1986 /// Build an empty case statement.
1987 static CaseStmt *CreateEmpty(const ASTContext &Ctx, bool CaseStmtIsGNURange);
1988
1989 /// True if this case statement is of the form case LHS ... RHS, which
1990 /// is a GNU extension. In this case the RHS can be obtained with getRHS()
1991 /// and the location of the ellipsis can be obtained with getEllipsisLoc().
1992 bool caseStmtIsGNURange() const { return SwitchCaseBits.CaseStmtIsGNURange; }
1993
1996
1997 /// Get the location of the ... in a case statement of the form LHS ... RHS.
1999 return caseStmtIsGNURange() ? *getTrailingObjects<SourceLocation>()
2000 : SourceLocation();
2001 }
2002
2003 /// Set the location of the ... in a case statement of the form LHS ... RHS.
2004 /// Assert that this case statement is of this form.
2006 assert(
2008 "setEllipsisLoc but this is not a case stmt of the form LHS ... RHS!");
2009 *getTrailingObjects<SourceLocation>() = L;
2010 }
2011
2013 return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[lhsOffset()]);
2014 }
2015
2016 const Expr *getLHS() const {
2017 return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[lhsOffset()]);
2018 }
2019
2020 void setLHS(Expr *Val) {
2021 getTrailingObjects<Stmt *>()[lhsOffset()] = reinterpret_cast<Stmt *>(Val);
2022 }
2023
2025 return caseStmtIsGNURange() ? reinterpret_cast<Expr *>(
2026 getTrailingObjects<Stmt *>()[rhsOffset()])
2027 : nullptr;
2028 }
2029
2030 const Expr *getRHS() const {
2031 return caseStmtIsGNURange() ? reinterpret_cast<Expr *>(
2032 getTrailingObjects<Stmt *>()[rhsOffset()])
2033 : nullptr;
2034 }
2035
2036 void setRHS(Expr *Val) {
2037 assert(caseStmtIsGNURange() &&
2038 "setRHS but this is not a case stmt of the form LHS ... RHS!");
2039 getTrailingObjects<Stmt *>()[rhsOffset()] = reinterpret_cast<Stmt *>(Val);
2040 }
2041
2042 Stmt *getSubStmt() { return getTrailingObjects<Stmt *>()[subStmtOffset()]; }
2043 const Stmt *getSubStmt() const {
2044 return getTrailingObjects<Stmt *>()[subStmtOffset()];
2045 }
2046
2047 void setSubStmt(Stmt *S) {
2048 getTrailingObjects<Stmt *>()[subStmtOffset()] = S;
2049 }
2050
2052 SourceLocation getEndLoc() const LLVM_READONLY {
2053 // Handle deeply nested case statements with iteration instead of recursion.
2054 const CaseStmt *CS = this;
2055 while (const auto *CS2 = dyn_cast<CaseStmt>(CS->getSubStmt()))
2056 CS = CS2;
2057
2058 return CS->getSubStmt()->getEndLoc();
2059 }
2060
2061 static bool classof(const Stmt *T) {
2062 return T->getStmtClass() == CaseStmtClass;
2063 }
2064
2065 // Iterators
2067 return child_range(getTrailingObjects<Stmt *>(),
2068 getTrailingObjects<Stmt *>() +
2069 numTrailingObjects(OverloadToken<Stmt *>()));
2070 }
2071
2073 return const_child_range(getTrailingObjects<Stmt *>(),
2074 getTrailingObjects<Stmt *>() +
2075 numTrailingObjects(OverloadToken<Stmt *>()));
2076 }
2077};
2078
2079class DefaultStmt : public SwitchCase {
2080 Stmt *SubStmt;
2081
2082public:
2084 : SwitchCase(DefaultStmtClass, DL, CL), SubStmt(substmt) {}
2085
2086 /// Build an empty default statement.
2088 : SwitchCase(DefaultStmtClass, Empty) {}
2089
2090 Stmt *getSubStmt() { return SubStmt; }
2091 const Stmt *getSubStmt() const { return SubStmt; }
2092 void setSubStmt(Stmt *S) { SubStmt = S; }
2093
2096
2098 SourceLocation getEndLoc() const LLVM_READONLY {
2099 return SubStmt->getEndLoc();
2100 }
2101
2102 static bool classof(const Stmt *T) {
2103 return T->getStmtClass() == DefaultStmtClass;
2104 }
2105
2106 // Iterators
2107 child_range children() { return child_range(&SubStmt, &SubStmt + 1); }
2108
2110 return const_child_range(&SubStmt, &SubStmt + 1);
2111 }
2112};
2113
2115 if (const auto *CS = dyn_cast<CaseStmt>(this))
2116 return CS->getEndLoc();
2117 else if (const auto *DS = dyn_cast<DefaultStmt>(this))
2118 return DS->getEndLoc();
2119 llvm_unreachable("SwitchCase is neither a CaseStmt nor a DefaultStmt!");
2120}
2121
2123 if (auto *CS = dyn_cast<CaseStmt>(this))
2124 return CS->getSubStmt();
2125 else if (auto *DS = dyn_cast<DefaultStmt>(this))
2126 return DS->getSubStmt();
2127 llvm_unreachable("SwitchCase is neither a CaseStmt nor a DefaultStmt!");
2128}
2129
2130/// Represents a statement that could possibly have a value and type. This
2131/// covers expression-statements, as well as labels and attributed statements.
2132///
2133/// Value statements have a special meaning when they are the last non-null
2134/// statement in a GNU statement expression, where they determine the value
2135/// of the statement expression.
2136class ValueStmt : public Stmt {
2137protected:
2138 using Stmt::Stmt;
2139
2140public:
2141 const Expr *getExprStmt() const;
2143 const ValueStmt *ConstThis = this;
2144 return const_cast<Expr*>(ConstThis->getExprStmt());
2145 }
2146
2147 static bool classof(const Stmt *T) {
2148 return T->getStmtClass() >= firstValueStmtConstant &&
2149 T->getStmtClass() <= lastValueStmtConstant;
2150 }
2151};
2152
2153/// LabelStmt - Represents a label, which has a substatement. For example:
2154/// foo: return;
2155class LabelStmt : public ValueStmt {
2156 LabelDecl *TheDecl;
2157 Stmt *SubStmt;
2158 bool SideEntry = false;
2159
2160public:
2161 /// Build a label statement.
2163 : ValueStmt(LabelStmtClass), TheDecl(D), SubStmt(substmt) {
2164 setIdentLoc(IL);
2165 }
2166
2167 /// Build an empty label statement.
2168 explicit LabelStmt(EmptyShell Empty) : ValueStmt(LabelStmtClass, Empty) {}
2169
2170 SourceLocation getIdentLoc() const { return LabelStmtBits.IdentLoc; }
2171 void setIdentLoc(SourceLocation L) { LabelStmtBits.IdentLoc = L; }
2172
2173 LabelDecl *getDecl() const { return TheDecl; }
2174 void setDecl(LabelDecl *D) { TheDecl = D; }
2175
2176 const char *getName() const;
2177 Stmt *getSubStmt() { return SubStmt; }
2178
2179 const Stmt *getSubStmt() const { return SubStmt; }
2180 void setSubStmt(Stmt *SS) { SubStmt = SS; }
2181
2183 SourceLocation getEndLoc() const LLVM_READONLY { return SubStmt->getEndLoc();}
2184
2185 /// Look through nested labels and return the first non-label statement; e.g.
2186 /// if this is 'a:' in 'a: b: c: for(;;)', this returns the for loop.
2187 const Stmt *getInnermostLabeledStmt() const;
2189 return const_cast<Stmt *>(
2190 const_cast<const LabelStmt *>(this)->getInnermostLabeledStmt());
2191 }
2192
2193 child_range children() { return child_range(&SubStmt, &SubStmt + 1); }
2194
2196 return const_child_range(&SubStmt, &SubStmt + 1);
2197 }
2198
2199 static bool classof(const Stmt *T) {
2200 return T->getStmtClass() == LabelStmtClass;
2201 }
2202 bool isSideEntry() const { return SideEntry; }
2203 void setSideEntry(bool SE) { SideEntry = SE; }
2204};
2205
2206/// Represents an attribute applied to a statement.
2207///
2208/// Represents an attribute applied to a statement. For example:
2209/// [[omp::for(...)]] for (...) { ... }
2210class AttributedStmt final
2211 : public ValueStmt,
2212 private llvm::TrailingObjects<AttributedStmt, const Attr *> {
2213 friend class ASTStmtReader;
2214 friend TrailingObjects;
2215
2216 Stmt *SubStmt;
2217
2218 AttributedStmt(SourceLocation Loc, ArrayRef<const Attr *> Attrs,
2219 Stmt *SubStmt)
2220 : ValueStmt(AttributedStmtClass), SubStmt(SubStmt) {
2221 AttributedStmtBits.NumAttrs = Attrs.size();
2222 AttributedStmtBits.AttrLoc = Loc;
2223 llvm::copy(Attrs, getAttrArrayPtr());
2224 }
2225
2226 explicit AttributedStmt(EmptyShell Empty, unsigned NumAttrs)
2227 : ValueStmt(AttributedStmtClass, Empty) {
2228 AttributedStmtBits.NumAttrs = NumAttrs;
2230 std::fill_n(getAttrArrayPtr(), NumAttrs, nullptr);
2231 }
2232
2233 const Attr *const *getAttrArrayPtr() const { return getTrailingObjects(); }
2234 const Attr **getAttrArrayPtr() { return getTrailingObjects(); }
2235
2236public:
2237 static AttributedStmt *Create(const ASTContext &C, SourceLocation Loc,
2238 ArrayRef<const Attr *> Attrs, Stmt *SubStmt);
2239
2240 // Build an empty attributed statement.
2241 static AttributedStmt *CreateEmpty(const ASTContext &C, unsigned NumAttrs);
2242
2245 return {getAttrArrayPtr(), AttributedStmtBits.NumAttrs};
2246 }
2247
2248 Stmt *getSubStmt() { return SubStmt; }
2249 const Stmt *getSubStmt() const { return SubStmt; }
2250
2252 SourceLocation getEndLoc() const LLVM_READONLY { return SubStmt->getEndLoc();}
2253
2254 child_range children() { return child_range(&SubStmt, &SubStmt + 1); }
2255
2257 return const_child_range(&SubStmt, &SubStmt + 1);
2258 }
2259
2260 static bool classof(const Stmt *T) {
2261 return T->getStmtClass() == AttributedStmtClass;
2262 }
2263};
2264
2265/// IfStmt - This represents an if/then/else.
2266class IfStmt final
2267 : public Stmt,
2268 private llvm::TrailingObjects<IfStmt, Stmt *, SourceLocation> {
2269 friend TrailingObjects;
2270
2271 // IfStmt is followed by several trailing objects, some of which optional.
2272 // Note that it would be more convenient to put the optional trailing
2273 // objects at then end but this would change the order of the children.
2274 // The trailing objects are in order:
2275 //
2276 // * A "Stmt *" for the init statement.
2277 // Present if and only if hasInitStorage().
2278 //
2279 // * A "Stmt *" for the condition variable.
2280 // Present if and only if hasVarStorage(). This is in fact a "DeclStmt *".
2281 //
2282 // * A "Stmt *" for the condition.
2283 // Always present. This is in fact a "Expr *".
2284 //
2285 // * A "Stmt *" for the then statement.
2286 // Always present.
2287 //
2288 // * A "Stmt *" for the else statement.
2289 // Present if and only if hasElseStorage().
2290 //
2291 // * A "SourceLocation" for the location of the "else".
2292 // Present if and only if hasElseStorage().
2293 enum { InitOffset = 0, ThenOffsetFromCond = 1, ElseOffsetFromCond = 2 };
2294 enum { NumMandatoryStmtPtr = 2 };
2295 SourceLocation LParenLoc;
2296 SourceLocation RParenLoc;
2297
2298 unsigned numTrailingObjects(OverloadToken<Stmt *>) const {
2299 return NumMandatoryStmtPtr + hasElseStorage() + hasVarStorage() +
2301 }
2302
2303 unsigned numTrailingObjects(OverloadToken<SourceLocation>) const {
2304 return hasElseStorage();
2305 }
2306
2307 unsigned initOffset() const { return InitOffset; }
2308 unsigned varOffset() const { return InitOffset + hasInitStorage(); }
2309 unsigned condOffset() const {
2310 return InitOffset + hasInitStorage() + hasVarStorage();
2311 }
2312 unsigned thenOffset() const { return condOffset() + ThenOffsetFromCond; }
2313 unsigned elseOffset() const { return condOffset() + ElseOffsetFromCond; }
2314
2315 /// Build an if/then/else statement.
2316 IfStmt(const ASTContext &Ctx, SourceLocation IL, IfStatementKind Kind,
2317 Stmt *Init, VarDecl *Var, Expr *Cond, SourceLocation LParenLoc,
2318 SourceLocation RParenLoc, Stmt *Then, SourceLocation EL, Stmt *Else);
2319
2320 /// Build an empty if/then/else statement.
2321 explicit IfStmt(EmptyShell Empty, bool HasElse, bool HasVar, bool HasInit);
2322
2323public:
2324 /// Create an IfStmt.
2325 static IfStmt *Create(const ASTContext &Ctx, SourceLocation IL,
2326 IfStatementKind Kind, Stmt *Init, VarDecl *Var,
2328 Stmt *Then, SourceLocation EL = SourceLocation(),
2329 Stmt *Else = nullptr);
2330
2331 /// Create an empty IfStmt optionally with storage for an else statement,
2332 /// condition variable and init expression.
2333 static IfStmt *CreateEmpty(const ASTContext &Ctx, bool HasElse, bool HasVar,
2334 bool HasInit);
2335
2336 /// True if this IfStmt has the storage for an init statement.
2337 bool hasInitStorage() const { return IfStmtBits.HasInit; }
2338
2339 /// True if this IfStmt has storage for a variable declaration.
2340 bool hasVarStorage() const { return IfStmtBits.HasVar; }
2341
2342 /// True if this IfStmt has storage for an else statement.
2343 bool hasElseStorage() const { return IfStmtBits.HasElse; }
2344
2346 return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[condOffset()]);
2347 }
2348
2349 const Expr *getCond() const {
2350 return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[condOffset()]);
2351 }
2352
2354 getTrailingObjects<Stmt *>()[condOffset()] = reinterpret_cast<Stmt *>(Cond);
2355 }
2356
2357 Stmt *getThen() { return getTrailingObjects<Stmt *>()[thenOffset()]; }
2358 const Stmt *getThen() const {
2359 return getTrailingObjects<Stmt *>()[thenOffset()];
2360 }
2361
2362 void setThen(Stmt *Then) {
2363 getTrailingObjects<Stmt *>()[thenOffset()] = Then;
2364 }
2365
2367 return hasElseStorage() ? getTrailingObjects<Stmt *>()[elseOffset()]
2368 : nullptr;
2369 }
2370
2371 const Stmt *getElse() const {
2372 return hasElseStorage() ? getTrailingObjects<Stmt *>()[elseOffset()]
2373 : nullptr;
2374 }
2375
2376 void setElse(Stmt *Else) {
2377 assert(hasElseStorage() &&
2378 "This if statement has no storage for an else statement!");
2379 getTrailingObjects<Stmt *>()[elseOffset()] = Else;
2380 }
2381
2382 /// Retrieve the variable declared in this "if" statement, if any.
2383 ///
2384 /// In the following example, "x" is the condition variable.
2385 /// \code
2386 /// if (int x = foo()) {
2387 /// printf("x is %d", x);
2388 /// }
2389 /// \endcode
2392 return const_cast<IfStmt *>(this)->getConditionVariable();
2393 }
2394
2395 /// Set the condition variable for this if statement.
2396 /// The if statement must have storage for the condition variable.
2397 void setConditionVariable(const ASTContext &Ctx, VarDecl *V);
2398
2399 /// If this IfStmt has a condition variable, return the faux DeclStmt
2400 /// associated with the creation of that condition variable.
2402 return hasVarStorage() ? static_cast<DeclStmt *>(
2403 getTrailingObjects<Stmt *>()[varOffset()])
2404 : nullptr;
2405 }
2406
2408 return hasVarStorage() ? static_cast<DeclStmt *>(
2409 getTrailingObjects<Stmt *>()[varOffset()])
2410 : nullptr;
2411 }
2412
2414 assert(hasVarStorage());
2415 getTrailingObjects<Stmt *>()[varOffset()] = CondVar;
2416 }
2417
2419 return hasInitStorage() ? getTrailingObjects<Stmt *>()[initOffset()]
2420 : nullptr;
2421 }
2422
2423 const Stmt *getInit() const {
2424 return hasInitStorage() ? getTrailingObjects<Stmt *>()[initOffset()]
2425 : nullptr;
2426 }
2427
2429 assert(hasInitStorage() &&
2430 "This if statement has no storage for an init statement!");
2431 getTrailingObjects<Stmt *>()[initOffset()] = Init;
2432 }
2433
2434 SourceLocation getIfLoc() const { return IfStmtBits.IfLoc; }
2435 void setIfLoc(SourceLocation IfLoc) { IfStmtBits.IfLoc = IfLoc; }
2436
2438 return hasElseStorage() ? *getTrailingObjects<SourceLocation>()
2439 : SourceLocation();
2440 }
2441
2443 assert(hasElseStorage() &&
2444 "This if statement has no storage for an else statement!");
2445 *getTrailingObjects<SourceLocation>() = ElseLoc;
2446 }
2447
2452
2456
2460
2461 bool isConstexpr() const {
2463 }
2464
2466 IfStmtBits.Kind = static_cast<unsigned>(Kind);
2467 }
2468
2470 return static_cast<IfStatementKind>(IfStmtBits.Kind);
2471 }
2472
2473 /// If this is an 'if constexpr', determine which substatement will be taken.
2474 /// Otherwise, or if the condition is value-dependent, returns std::nullopt.
2475 std::optional<const Stmt *> getNondiscardedCase(const ASTContext &Ctx) const;
2476 std::optional<Stmt *> getNondiscardedCase(const ASTContext &Ctx);
2477
2478 bool isObjCAvailabilityCheck() const;
2479
2481 SourceLocation getEndLoc() const LLVM_READONLY {
2482 if (getElse())
2483 return getElse()->getEndLoc();
2484 return getThen()->getEndLoc();
2485 }
2486 SourceLocation getLParenLoc() const { return LParenLoc; }
2487 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
2488 SourceLocation getRParenLoc() const { return RParenLoc; }
2489 void setRParenLoc(SourceLocation Loc) { RParenLoc = Loc; }
2490
2491 // Iterators over subexpressions. The iterators will include iterating
2492 // over the initialization expression referenced by the condition variable.
2494 // We always store a condition, but there is none for consteval if
2495 // statements, so skip it.
2496 return child_range(getTrailingObjects<Stmt *>() +
2497 (isConsteval() ? thenOffset() : 0),
2498 getTrailingObjects<Stmt *>() +
2499 numTrailingObjects(OverloadToken<Stmt *>()));
2500 }
2501
2503 // We always store a condition, but there is none for consteval if
2504 // statements, so skip it.
2505 return const_child_range(getTrailingObjects<Stmt *>() +
2506 (isConsteval() ? thenOffset() : 0),
2507 getTrailingObjects<Stmt *>() +
2508 numTrailingObjects(OverloadToken<Stmt *>()));
2509 }
2510
2511 static bool classof(const Stmt *T) {
2512 return T->getStmtClass() == IfStmtClass;
2513 }
2514};
2515
2516/// SwitchStmt - This represents a 'switch' stmt.
2517class SwitchStmt final : public Stmt,
2518 private llvm::TrailingObjects<SwitchStmt, Stmt *> {
2519 friend TrailingObjects;
2520
2521 /// Points to a linked list of case and default statements.
2522 SwitchCase *FirstCase = nullptr;
2523
2524 // SwitchStmt is followed by several trailing objects,
2525 // some of which optional. Note that it would be more convenient to
2526 // put the optional trailing objects at the end but this would change
2527 // the order in children().
2528 // The trailing objects are in order:
2529 //
2530 // * A "Stmt *" for the init statement.
2531 // Present if and only if hasInitStorage().
2532 //
2533 // * A "Stmt *" for the condition variable.
2534 // Present if and only if hasVarStorage(). This is in fact a "DeclStmt *".
2535 //
2536 // * A "Stmt *" for the condition.
2537 // Always present. This is in fact an "Expr *".
2538 //
2539 // * A "Stmt *" for the body.
2540 // Always present.
2541 enum { InitOffset = 0, BodyOffsetFromCond = 1 };
2542 enum { NumMandatoryStmtPtr = 2 };
2543 SourceLocation LParenLoc;
2544 SourceLocation RParenLoc;
2545
2546 unsigned numTrailingStatements() const {
2547 return NumMandatoryStmtPtr + hasInitStorage() + hasVarStorage();
2548 }
2549
2550 unsigned initOffset() const { return InitOffset; }
2551 unsigned varOffset() const { return InitOffset + hasInitStorage(); }
2552 unsigned condOffset() const {
2553 return InitOffset + hasInitStorage() + hasVarStorage();
2554 }
2555 unsigned bodyOffset() const { return condOffset() + BodyOffsetFromCond; }
2556
2557 /// Build a switch statement.
2558 SwitchStmt(const ASTContext &Ctx, Stmt *Init, VarDecl *Var, Expr *Cond,
2559 SourceLocation LParenLoc, SourceLocation RParenLoc);
2560
2561 /// Build a empty switch statement.
2562 explicit SwitchStmt(EmptyShell Empty, bool HasInit, bool HasVar);
2563
2564public:
2565 /// Create a switch statement.
2566 static SwitchStmt *Create(const ASTContext &Ctx, Stmt *Init, VarDecl *Var,
2567 Expr *Cond, SourceLocation LParenLoc,
2568 SourceLocation RParenLoc);
2569
2570 /// Create an empty switch statement optionally with storage for
2571 /// an init expression and a condition variable.
2572 static SwitchStmt *CreateEmpty(const ASTContext &Ctx, bool HasInit,
2573 bool HasVar);
2574
2575 /// True if this SwitchStmt has storage for an init statement.
2576 bool hasInitStorage() const { return SwitchStmtBits.HasInit; }
2577
2578 /// True if this SwitchStmt has storage for a condition variable.
2579 bool hasVarStorage() const { return SwitchStmtBits.HasVar; }
2580
2582 return reinterpret_cast<Expr *>(getTrailingObjects()[condOffset()]);
2583 }
2584
2585 const Expr *getCond() const {
2586 return reinterpret_cast<Expr *>(getTrailingObjects()[condOffset()]);
2587 }
2588
2590 getTrailingObjects()[condOffset()] = reinterpret_cast<Stmt *>(Cond);
2591 }
2592
2593 Stmt *getBody() { return getTrailingObjects()[bodyOffset()]; }
2594 const Stmt *getBody() const { return getTrailingObjects()[bodyOffset()]; }
2595
2596 void setBody(Stmt *Body) { getTrailingObjects()[bodyOffset()] = Body; }
2597
2599 return hasInitStorage() ? getTrailingObjects()[initOffset()] : nullptr;
2600 }
2601
2602 const Stmt *getInit() const {
2603 return hasInitStorage() ? getTrailingObjects()[initOffset()] : nullptr;
2604 }
2605
2607 assert(hasInitStorage() &&
2608 "This switch statement has no storage for an init statement!");
2609 getTrailingObjects()[initOffset()] = Init;
2610 }
2611
2612 /// Retrieve the variable declared in this "switch" statement, if any.
2613 ///
2614 /// In the following example, "x" is the condition variable.
2615 /// \code
2616 /// switch (int x = foo()) {
2617 /// case 0: break;
2618 /// // ...
2619 /// }
2620 /// \endcode
2623 return const_cast<SwitchStmt *>(this)->getConditionVariable();
2624 }
2625
2626 /// Set the condition variable in this switch statement.
2627 /// The switch statement must have storage for it.
2628 void setConditionVariable(const ASTContext &Ctx, VarDecl *VD);
2629
2630 /// If this SwitchStmt has a condition variable, return the faux DeclStmt
2631 /// associated with the creation of that condition variable.
2633 return hasVarStorage()
2634 ? static_cast<DeclStmt *>(getTrailingObjects()[varOffset()])
2635 : nullptr;
2636 }
2637
2639 return hasVarStorage()
2640 ? static_cast<DeclStmt *>(getTrailingObjects()[varOffset()])
2641 : nullptr;
2642 }
2643
2645 assert(hasVarStorage());
2646 getTrailingObjects()[varOffset()] = CondVar;
2647 }
2648
2649 SwitchCase *getSwitchCaseList() { return FirstCase; }
2650 const SwitchCase *getSwitchCaseList() const { return FirstCase; }
2651 void setSwitchCaseList(SwitchCase *SC) { FirstCase = SC; }
2652
2653 SourceLocation getSwitchLoc() const { return SwitchStmtBits.SwitchLoc; }
2654 void setSwitchLoc(SourceLocation L) { SwitchStmtBits.SwitchLoc = L; }
2655 SourceLocation getLParenLoc() const { return LParenLoc; }
2656 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
2657 SourceLocation getRParenLoc() const { return RParenLoc; }
2658 void setRParenLoc(SourceLocation Loc) { RParenLoc = Loc; }
2659
2661 setBody(S);
2662 setSwitchLoc(SL);
2663 }
2664
2666 assert(!SC->getNextSwitchCase() &&
2667 "case/default already added to a switch");
2668 SC->setNextSwitchCase(FirstCase);
2669 FirstCase = SC;
2670 }
2671
2672 /// Set a flag in the SwitchStmt indicating that if the 'switch (X)' is a
2673 /// switch over an enum value then all cases have been explicitly covered.
2674 void setAllEnumCasesCovered() { SwitchStmtBits.AllEnumCasesCovered = true; }
2675
2676 /// Returns true if the SwitchStmt is a switch of an enum value and all cases
2677 /// have been explicitly covered.
2679 return SwitchStmtBits.AllEnumCasesCovered;
2680 }
2681
2683 SourceLocation getEndLoc() const LLVM_READONLY {
2684 return getBody() ? getBody()->getEndLoc()
2685 : reinterpret_cast<const Stmt *>(getCond())->getEndLoc();
2686 }
2687
2688 // Iterators
2690 return child_range(getTrailingObjects(),
2691 getTrailingObjects() + numTrailingStatements());
2692 }
2693
2695 return const_child_range(getTrailingObjects(),
2696 getTrailingObjects() + numTrailingStatements());
2697 }
2698
2699 static bool classof(const Stmt *T) {
2700 return T->getStmtClass() == SwitchStmtClass;
2701 }
2702};
2703
2704/// WhileStmt - This represents a 'while' stmt.
2705class WhileStmt final : public Stmt,
2706 private llvm::TrailingObjects<WhileStmt, Stmt *> {
2707 friend TrailingObjects;
2708
2709 // WhileStmt is followed by several trailing objects,
2710 // some of which optional. Note that it would be more
2711 // convenient to put the optional trailing object at the end
2712 // but this would affect children().
2713 // The trailing objects are in order:
2714 //
2715 // * A "Stmt *" for the condition variable.
2716 // Present if and only if hasVarStorage(). This is in fact a "DeclStmt *".
2717 //
2718 // * A "Stmt *" for the condition.
2719 // Always present. This is in fact an "Expr *".
2720 //
2721 // * A "Stmt *" for the body.
2722 // Always present.
2723 //
2724 enum { VarOffset = 0, BodyOffsetFromCond = 1 };
2725 enum { NumMandatoryStmtPtr = 2 };
2726
2727 SourceLocation LParenLoc, RParenLoc;
2728
2729 unsigned varOffset() const { return VarOffset; }
2730 unsigned condOffset() const { return VarOffset + hasVarStorage(); }
2731 unsigned bodyOffset() const { return condOffset() + BodyOffsetFromCond; }
2732
2733 unsigned numTrailingStatements() const {
2734 return NumMandatoryStmtPtr + hasVarStorage();
2735 }
2736
2737 /// Build a while statement.
2738 WhileStmt(const ASTContext &Ctx, VarDecl *Var, Expr *Cond, Stmt *Body,
2739 SourceLocation WL, SourceLocation LParenLoc,
2740 SourceLocation RParenLoc);
2741
2742 /// Build an empty while statement.
2743 explicit WhileStmt(EmptyShell Empty, bool HasVar);
2744
2745public:
2746 /// Create a while statement.
2747 static WhileStmt *Create(const ASTContext &Ctx, VarDecl *Var, Expr *Cond,
2748 Stmt *Body, SourceLocation WL,
2749 SourceLocation LParenLoc, SourceLocation RParenLoc);
2750
2751 /// Create an empty while statement optionally with storage for
2752 /// a condition variable.
2753 static WhileStmt *CreateEmpty(const ASTContext &Ctx, bool HasVar);
2754
2755 /// True if this WhileStmt has storage for a condition variable.
2756 bool hasVarStorage() const { return WhileStmtBits.HasVar; }
2757
2759 return reinterpret_cast<Expr *>(getTrailingObjects()[condOffset()]);
2760 }
2761
2762 const Expr *getCond() const {
2763 return reinterpret_cast<Expr *>(getTrailingObjects()[condOffset()]);
2764 }
2765
2767 getTrailingObjects()[condOffset()] = reinterpret_cast<Stmt *>(Cond);
2768 }
2769
2770 Stmt *getBody() { return getTrailingObjects()[bodyOffset()]; }
2771 const Stmt *getBody() const { return getTrailingObjects()[bodyOffset()]; }
2772
2773 void setBody(Stmt *Body) { getTrailingObjects()[bodyOffset()] = Body; }
2774
2775 /// Retrieve the variable declared in this "while" statement, if any.
2776 ///
2777 /// In the following example, "x" is the condition variable.
2778 /// \code
2779 /// while (int x = random()) {
2780 /// // ...
2781 /// }
2782 /// \endcode
2785 return const_cast<WhileStmt *>(this)->getConditionVariable();
2786 }
2787
2788 /// Set the condition variable of this while statement.
2789 /// The while statement must have storage for it.
2790 void setConditionVariable(const ASTContext &Ctx, VarDecl *V);
2791
2792 /// If this WhileStmt has a condition variable, return the faux DeclStmt
2793 /// associated with the creation of that condition variable.
2795 return hasVarStorage()
2796 ? static_cast<DeclStmt *>(getTrailingObjects()[varOffset()])
2797 : nullptr;
2798 }
2799
2801 return hasVarStorage()
2802 ? static_cast<DeclStmt *>(getTrailingObjects()[varOffset()])
2803 : nullptr;
2804 }
2805
2807 assert(hasVarStorage());
2808 getTrailingObjects()[varOffset()] = CondVar;
2809 }
2810
2811 SourceLocation getWhileLoc() const { return WhileStmtBits.WhileLoc; }
2812 void setWhileLoc(SourceLocation L) { WhileStmtBits.WhileLoc = L; }
2813
2814 SourceLocation getLParenLoc() const { return LParenLoc; }
2815 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2816 SourceLocation getRParenLoc() const { return RParenLoc; }
2817 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2818
2820 SourceLocation getEndLoc() const LLVM_READONLY {
2821 return getBody()->getEndLoc();
2822 }
2823
2824 static bool classof(const Stmt *T) {
2825 return T->getStmtClass() == WhileStmtClass;
2826 }
2827
2828 // Iterators
2830 return child_range(getTrailingObjects(),
2831 getTrailingObjects() + numTrailingStatements());
2832 }
2833
2835 return const_child_range(getTrailingObjects(),
2836 getTrailingObjects() + numTrailingStatements());
2837 }
2838};
2839
2840/// DoStmt - This represents a 'do/while' stmt.
2841class DoStmt : public Stmt {
2842 enum { BODY, COND, END_EXPR };
2843 Stmt *SubExprs[END_EXPR];
2844 SourceLocation WhileLoc;
2845 SourceLocation RParenLoc; // Location of final ')' in do stmt condition.
2846
2847public:
2849 SourceLocation RP)
2850 : Stmt(DoStmtClass), WhileLoc(WL), RParenLoc(RP) {
2851 setCond(Cond);
2852 setBody(Body);
2853 setDoLoc(DL);
2854 }
2855
2856 /// Build an empty do-while statement.
2857 explicit DoStmt(EmptyShell Empty) : Stmt(DoStmtClass, Empty) {}
2858
2859 Expr *getCond() { return reinterpret_cast<Expr *>(SubExprs[COND]); }
2860 const Expr *getCond() const {
2861 return reinterpret_cast<Expr *>(SubExprs[COND]);
2862 }
2863
2864 void setCond(Expr *Cond) { SubExprs[COND] = reinterpret_cast<Stmt *>(Cond); }
2865
2866 Stmt *getBody() { return SubExprs[BODY]; }
2867 const Stmt *getBody() const { return SubExprs[BODY]; }
2868 void setBody(Stmt *Body) { SubExprs[BODY] = Body; }
2869
2870 SourceLocation getDoLoc() const { return DoStmtBits.DoLoc; }
2871 void setDoLoc(SourceLocation L) { DoStmtBits.DoLoc = L; }
2872 SourceLocation getWhileLoc() const { return WhileLoc; }
2873 void setWhileLoc(SourceLocation L) { WhileLoc = L; }
2874 SourceLocation getRParenLoc() const { return RParenLoc; }
2875 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2876
2879
2880 static bool classof(const Stmt *T) {
2881 return T->getStmtClass() == DoStmtClass;
2882 }
2883
2884 // Iterators
2886 return child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
2887 }
2888
2890 return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
2891 }
2892};
2893
2894/// ForStmt - This represents a 'for (init;cond;inc)' stmt. Note that any of
2895/// the init/cond/inc parts of the ForStmt will be null if they were not
2896/// specified in the source.
2897class ForStmt : public Stmt {
2898 friend class ASTStmtReader;
2899
2900 enum { INIT, CONDVAR, COND, INC, BODY, END_EXPR };
2901 Stmt* SubExprs[END_EXPR]; // SubExprs[INIT] is an expression or declstmt.
2902 SourceLocation LParenLoc, RParenLoc;
2903
2904public:
2905 ForStmt(const ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar,
2906 Expr *Inc, Stmt *Body, SourceLocation FL, SourceLocation LP,
2907 SourceLocation RP);
2908
2909 /// Build an empty for statement.
2910 explicit ForStmt(EmptyShell Empty) : Stmt(ForStmtClass, Empty) {}
2911
2912 Stmt *getInit() { return SubExprs[INIT]; }
2913
2914 /// Retrieve the variable declared in this "for" statement, if any.
2915 ///
2916 /// In the following example, "y" is the condition variable.
2917 /// \code
2918 /// for (int x = random(); int y = mangle(x); ++x) {
2919 /// // ...
2920 /// }
2921 /// \endcode
2923 void setConditionVariable(const ASTContext &C, VarDecl *V);
2924
2925 /// If this ForStmt has a condition variable, return the faux DeclStmt
2926 /// associated with the creation of that condition variable.
2928 return reinterpret_cast<DeclStmt*>(SubExprs[CONDVAR]);
2929 }
2930
2932 return reinterpret_cast<DeclStmt*>(SubExprs[CONDVAR]);
2933 }
2934
2936 SubExprs[CONDVAR] = CondVar;
2937 }
2938
2939 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
2940 Expr *getInc() { return reinterpret_cast<Expr*>(SubExprs[INC]); }
2941 Stmt *getBody() { return SubExprs[BODY]; }
2942
2943 const Stmt *getInit() const { return SubExprs[INIT]; }
2944 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
2945 const Expr *getInc() const { return reinterpret_cast<Expr*>(SubExprs[INC]); }
2946 const Stmt *getBody() const { return SubExprs[BODY]; }
2947
2948 void setInit(Stmt *S) { SubExprs[INIT] = S; }
2949 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
2950 void setInc(Expr *E) { SubExprs[INC] = reinterpret_cast<Stmt*>(E); }
2951 void setBody(Stmt *S) { SubExprs[BODY] = S; }
2952
2953 SourceLocation getForLoc() const { return ForStmtBits.ForLoc; }
2954 void setForLoc(SourceLocation L) { ForStmtBits.ForLoc = L; }
2955 SourceLocation getLParenLoc() const { return LParenLoc; }
2956 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2957 SourceLocation getRParenLoc() const { return RParenLoc; }
2958 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2959
2962
2963 static bool classof(const Stmt *T) {
2964 return T->getStmtClass() == ForStmtClass;
2965 }
2966
2967 // Iterators
2969 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
2970 }
2971
2973 return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
2974 }
2975};
2976
2977/// GotoStmt - This represents a direct goto.
2978class GotoStmt : public Stmt {
2979 LabelDecl *Label;
2980 SourceLocation LabelLoc;
2981
2982public:
2984 : Stmt(GotoStmtClass), Label(label), LabelLoc(LL) {
2985 setGotoLoc(GL);
2986 }
2987
2988 /// Build an empty goto statement.
2989 explicit GotoStmt(EmptyShell Empty) : Stmt(GotoStmtClass, Empty) {}
2990
2991 LabelDecl *getLabel() const { return Label; }
2992 void setLabel(LabelDecl *D) { Label = D; }
2993
2994 SourceLocation getGotoLoc() const { return GotoStmtBits.GotoLoc; }
2995 void setGotoLoc(SourceLocation L) { GotoStmtBits.GotoLoc = L; }
2996 SourceLocation getLabelLoc() const { return LabelLoc; }
2997 void setLabelLoc(SourceLocation L) { LabelLoc = L; }
2998
3001
3002 static bool classof(const Stmt *T) {
3003 return T->getStmtClass() == GotoStmtClass;
3004 }
3005
3006 // Iterators
3010
3014};
3015
3016/// IndirectGotoStmt - This represents an indirect goto.
3017class IndirectGotoStmt : public Stmt {
3018 SourceLocation StarLoc;
3019 Stmt *Target;
3020
3021public:
3023 : Stmt(IndirectGotoStmtClass), StarLoc(starLoc) {
3024 setTarget(target);
3025 setGotoLoc(gotoLoc);
3026 }
3027
3028 /// Build an empty indirect goto statement.
3030 : Stmt(IndirectGotoStmtClass, Empty) {}
3031
3032 void setGotoLoc(SourceLocation L) { GotoStmtBits.GotoLoc = L; }
3033 SourceLocation getGotoLoc() const { return GotoStmtBits.GotoLoc; }
3034 void setStarLoc(SourceLocation L) { StarLoc = L; }
3035 SourceLocation getStarLoc() const { return StarLoc; }
3036
3037 Expr *getTarget() { return reinterpret_cast<Expr *>(Target); }
3038 const Expr *getTarget() const {
3039 return reinterpret_cast<const Expr *>(Target);
3040 }
3041 void setTarget(Expr *E) { Target = reinterpret_cast<Stmt *>(E); }
3042
3043 /// getConstantTarget - Returns the fixed target of this indirect
3044 /// goto, if one exists.
3047 return const_cast<IndirectGotoStmt *>(this)->getConstantTarget();
3048 }
3049
3051 SourceLocation getEndLoc() const LLVM_READONLY { return Target->getEndLoc(); }
3052
3053 static bool classof(const Stmt *T) {
3054 return T->getStmtClass() == IndirectGotoStmtClass;
3055 }
3056
3057 // Iterators
3058 child_range children() { return child_range(&Target, &Target + 1); }
3059
3061 return const_child_range(&Target, &Target + 1);
3062 }
3063};
3064
3065/// Base class for BreakStmt and ContinueStmt.
3066class LoopControlStmt : public Stmt {
3067 /// If this is a named break/continue, the label whose statement we're
3068 /// targeting, as well as the source location of the label after the
3069 /// keyword; for example:
3070 ///
3071 /// a: // <-- TargetLabel
3072 /// for (;;)
3073 /// break a; // <-- LabelLoc
3074 ///
3075 LabelDecl *TargetLabel = nullptr;
3076 SourceLocation LabelLoc;
3077
3078protected:
3081 : Stmt(Class), TargetLabel(Target), LabelLoc(LabelLoc) {
3082 setKwLoc(Loc);
3083 }
3084
3087
3089
3090public:
3093
3096 return hasLabelTarget() ? getLabelLoc() : getKwLoc();
3097 }
3098
3099 bool hasLabelTarget() const { return TargetLabel != nullptr; }
3100
3101 SourceLocation getLabelLoc() const { return LabelLoc; }
3102 void setLabelLoc(SourceLocation L) { LabelLoc = L; }
3103
3104 LabelDecl *getLabelDecl() { return TargetLabel; }
3105 const LabelDecl *getLabelDecl() const { return TargetLabel; }
3106 void setLabelDecl(LabelDecl *S) { TargetLabel = S; }
3107
3108 /// If this is a named break/continue, get the loop or switch statement
3109 /// that this targets.
3110 const Stmt *getNamedLoopOrSwitch() const;
3111
3112 // Iterators
3116
3120
3121 static bool classof(const Stmt *T) {
3122 StmtClass Class = T->getStmtClass();
3123 return Class == ContinueStmtClass || Class == BreakStmtClass;
3124 }
3125};
3126
3127/// ContinueStmt - This represents a continue.
3129public:
3132 : LoopControlStmt(ContinueStmtClass, CL, LabelLoc, Target) {}
3133
3134 /// Build an empty continue statement.
3136 : LoopControlStmt(ContinueStmtClass, Empty) {}
3137
3138 static bool classof(const Stmt *T) {
3139 return T->getStmtClass() == ContinueStmtClass;
3140 }
3141};
3142
3143/// BreakStmt - This represents a break.
3145public:
3146 BreakStmt(SourceLocation BL) : LoopControlStmt(BreakStmtClass, BL) {}
3148 : LoopControlStmt(BreakStmtClass, CL, LabelLoc, Target) {}
3149
3150 /// Build an empty break statement.
3152 : LoopControlStmt(BreakStmtClass, Empty) {}
3153
3154 static bool classof(const Stmt *T) {
3155 return T->getStmtClass() == BreakStmtClass;
3156 }
3157};
3158
3159/// ReturnStmt - This represents a return, optionally of an expression:
3160/// return;
3161/// return 4;
3162///
3163/// Note that GCC allows return with no argument in a function declared to
3164/// return a value, and it allows returning a value in functions declared to
3165/// return void. We explicitly model this in the AST, which means you can't
3166/// depend on the return type of the function and the presence of an argument.
3167class ReturnStmt final
3168 : public Stmt,
3169 private llvm::TrailingObjects<ReturnStmt, const VarDecl *> {
3170 friend TrailingObjects;
3171
3172 /// The return expression.
3173 Stmt *RetExpr;
3174
3175 // ReturnStmt is followed optionally by a trailing "const VarDecl *"
3176 // for the NRVO candidate. Present if and only if hasNRVOCandidate().
3177
3178 /// True if this ReturnStmt has storage for an NRVO candidate.
3179 bool hasNRVOCandidate() const { return ReturnStmtBits.HasNRVOCandidate; }
3180
3181 /// Build a return statement.
3182 ReturnStmt(SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate);
3183
3184 /// Build an empty return statement.
3185 explicit ReturnStmt(EmptyShell Empty, bool HasNRVOCandidate);
3186
3187public:
3188 /// Create a return statement.
3189 static ReturnStmt *Create(const ASTContext &Ctx, SourceLocation RL, Expr *E,
3190 const VarDecl *NRVOCandidate);
3191
3192 /// Create an empty return statement, optionally with
3193 /// storage for an NRVO candidate.
3194 static ReturnStmt *CreateEmpty(const ASTContext &Ctx, bool HasNRVOCandidate);
3195
3196 Expr *getRetValue() { return reinterpret_cast<Expr *>(RetExpr); }
3197 const Expr *getRetValue() const { return reinterpret_cast<Expr *>(RetExpr); }
3198 void setRetValue(Expr *E) { RetExpr = reinterpret_cast<Stmt *>(E); }
3199
3200 /// Retrieve the variable that might be used for the named return
3201 /// value optimization.
3202 ///
3203 /// The optimization itself can only be performed if the variable is
3204 /// also marked as an NRVO object.
3205 const VarDecl *getNRVOCandidate() const {
3206 return hasNRVOCandidate() ? *getTrailingObjects() : nullptr;
3207 }
3208
3209 /// Set the variable that might be used for the named return value
3210 /// optimization. The return statement must have storage for it,
3211 /// which is the case if and only if hasNRVOCandidate() is true.
3212 void setNRVOCandidate(const VarDecl *Var) {
3213 assert(hasNRVOCandidate() &&
3214 "This return statement has no storage for an NRVO candidate!");
3215 *getTrailingObjects() = Var;
3216 }
3217
3218 SourceLocation getReturnLoc() const { return ReturnStmtBits.RetLoc; }
3220
3222 SourceLocation getEndLoc() const LLVM_READONLY {
3223 return RetExpr ? RetExpr->getEndLoc() : getReturnLoc();
3224 }
3225
3226 static bool classof(const Stmt *T) {
3227 return T->getStmtClass() == ReturnStmtClass;
3228 }
3229
3230 // Iterators
3232 if (RetExpr)
3233 return child_range(&RetExpr, &RetExpr + 1);
3235 }
3236
3238 if (RetExpr)
3239 return const_child_range(&RetExpr, &RetExpr + 1);
3241 }
3242};
3243
3244/// DeferStmt - This represents a deferred statement.
3245class DeferStmt : public Stmt {
3246 friend class ASTStmtReader;
3247
3248 /// The deferred statement.
3249 Stmt *Body;
3250
3251 DeferStmt(EmptyShell Empty);
3252 DeferStmt(SourceLocation DeferLoc, Stmt *Body);
3253
3254public:
3255 static DeferStmt *CreateEmpty(ASTContext &Context, EmptyShell Empty);
3256 static DeferStmt *Create(ASTContext &Context, SourceLocation DeferLoc,
3257 Stmt *Body);
3258
3259 SourceLocation getDeferLoc() const { return DeferStmtBits.DeferLoc; }
3261 DeferStmtBits.DeferLoc = DeferLoc;
3262 }
3263
3264 Stmt *getBody() { return Body; }
3265 const Stmt *getBody() const { return Body; }
3266 void setBody(Stmt *S) {
3267 assert(S && "defer body must not be null");
3268 Body = S;
3269 }
3270
3272 SourceLocation getEndLoc() const { return Body->getEndLoc(); }
3273
3274 child_range children() { return child_range(&Body, &Body + 1); }
3275
3277 return const_child_range(&Body, &Body + 1);
3278 }
3279
3280 static bool classof(const Stmt *S) {
3281 return S->getStmtClass() == DeferStmtClass;
3282 }
3283};
3284
3285/// AsmStmt is the base class for GCCAsmStmt and MSAsmStmt.
3286class AsmStmt : public Stmt {
3287protected:
3288 friend class ASTStmtReader;
3289
3291
3292 /// True if the assembly statement does not have any input or output
3293 /// operands.
3295
3296 /// If true, treat this inline assembly as having side effects.
3297 /// This assembly statement should not be optimized, deleted or moved.
3299
3300 unsigned NumOutputs;
3301 unsigned NumInputs;
3302 unsigned NumClobbers;
3303
3304 Stmt **Exprs = nullptr;
3305
3306 AsmStmt(StmtClass SC, SourceLocation asmloc, bool issimple, bool isvolatile,
3307 unsigned numoutputs, unsigned numinputs, unsigned numclobbers)
3308 : Stmt (SC), AsmLoc(asmloc), IsSimple(issimple), IsVolatile(isvolatile),
3309 NumOutputs(numoutputs), NumInputs(numinputs),
3310 NumClobbers(numclobbers) {}
3311
3312public:
3313 /// Build an empty inline-assembly statement.
3314 explicit AsmStmt(StmtClass SC, EmptyShell Empty) : Stmt(SC, Empty) {}
3315
3316 SourceLocation getAsmLoc() const { return AsmLoc; }
3318
3319 bool isSimple() const { return IsSimple; }
3320 void setSimple(bool V) { IsSimple = V; }
3321
3322 bool isVolatile() const { return IsVolatile; }
3323 void setVolatile(bool V) { IsVolatile = V; }
3324
3325 SourceLocation getBeginLoc() const LLVM_READONLY { return {}; }
3326 SourceLocation getEndLoc() const LLVM_READONLY { return {}; }
3327
3328 //===--- Asm String Analysis ---===//
3329
3330 /// Assemble final IR asm string.
3331 std::string generateAsmString(const ASTContext &C) const;
3332
3334 llvm::function_ref<void(const Stmt *, StringRef)>;
3335 /// Look at AsmExpr and if it is a variable declared as using a particular
3336 /// register add that as a constraint that will be used in this asm stmt.
3337 std::string
3338 addVariableConstraints(StringRef Constraint, const Expr &AsmExpr,
3339 const TargetInfo &Target, bool EarlyClobber,
3340 UnsupportedConstraintCallbackTy UnsupportedCB,
3341 std::string *GCCReg = nullptr) const;
3342
3343 //===--- Output operands ---===//
3344
3345 unsigned getNumOutputs() const { return NumOutputs; }
3346
3347 /// getOutputConstraint - Return the constraint string for the specified
3348 /// output operand. All output constraints are known to be non-empty (either
3349 /// '=' or '+').
3350 std::string getOutputConstraint(unsigned i) const;
3351
3352 /// isOutputPlusConstraint - Return true if the specified output constraint
3353 /// is a "+" constraint (which is both an input and an output) or false if it
3354 /// is an "=" constraint (just an output).
3355 bool isOutputPlusConstraint(unsigned i) const {
3356 return getOutputConstraint(i)[0] == '+';
3357 }
3358
3359 const Expr *getOutputExpr(unsigned i) const;
3360
3361 /// getNumPlusOperands - Return the number of output operands that have a "+"
3362 /// constraint.
3363 unsigned getNumPlusOperands() const;
3364
3365 //===--- Input operands ---===//
3366
3367 unsigned getNumInputs() const { return NumInputs; }
3368
3369 /// getInputConstraint - Return the specified input constraint. Unlike output
3370 /// constraints, these can be empty.
3371 std::string getInputConstraint(unsigned i) const;
3372
3373 const Expr *getInputExpr(unsigned i) const;
3374
3375 //===--- Other ---===//
3376
3377 unsigned getNumClobbers() const { return NumClobbers; }
3378 std::string getClobber(unsigned i) const;
3379
3380 static bool classof(const Stmt *T) {
3381 return T->getStmtClass() == GCCAsmStmtClass ||
3382 T->getStmtClass() == MSAsmStmtClass;
3383 }
3384
3385 // Input expr iterators.
3386
3389 using inputs_range = llvm::iterator_range<inputs_iterator>;
3390 using inputs_const_range = llvm::iterator_range<const_inputs_iterator>;
3391
3393 return &Exprs[0] + NumOutputs;
3394 }
3395
3397 return &Exprs[0] + NumOutputs + NumInputs;
3398 }
3399
3401
3403 return &Exprs[0] + NumOutputs;
3404 }
3405
3407 return &Exprs[0] + NumOutputs + NumInputs;
3408 }
3409
3413
3414 // Output expr iterators.
3415
3418 using outputs_range = llvm::iterator_range<outputs_iterator>;
3419 using outputs_const_range = llvm::iterator_range<const_outputs_iterator>;
3420
3422 return &Exprs[0];
3423 }
3424
3426 return &Exprs[0] + NumOutputs;
3427 }
3428
3432
3434 return &Exprs[0];
3435 }
3436
3438 return &Exprs[0] + NumOutputs;
3439 }
3440
3444
3446 return child_range(&Exprs[0], &Exprs[0] + NumOutputs + NumInputs);
3447 }
3448
3450 return const_child_range(&Exprs[0], &Exprs[0] + NumOutputs + NumInputs);
3451 }
3452};
3453
3454/// This represents a GCC inline-assembly statement extension.
3455class GCCAsmStmt : public AsmStmt {
3456 friend class ASTStmtReader;
3457
3458 SourceLocation RParenLoc;
3459 Expr *AsmStr;
3460
3461 // FIXME: If we wanted to, we could allocate all of these in one big array.
3462 Expr **Constraints = nullptr;
3463 Expr **Clobbers = nullptr;
3464 IdentifierInfo **Names = nullptr;
3465 unsigned NumLabels = 0;
3466
3467public:
3468 GCCAsmStmt(const ASTContext &C, SourceLocation asmloc, bool issimple,
3469 bool isvolatile, unsigned numoutputs, unsigned numinputs,
3470 IdentifierInfo **names, Expr **constraints, Expr **exprs,
3471 Expr *asmstr, unsigned numclobbers, Expr **clobbers,
3472 unsigned numlabels, SourceLocation rparenloc);
3473
3474 /// Build an empty inline-assembly statement.
3475 explicit GCCAsmStmt(EmptyShell Empty) : AsmStmt(GCCAsmStmtClass, Empty) {}
3476
3477 SourceLocation getRParenLoc() const { return RParenLoc; }
3478 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
3479
3480 //===--- Asm String Analysis ---===//
3481
3482 const Expr *getAsmStringExpr() const { return AsmStr; }
3483 Expr *getAsmStringExpr() { return AsmStr; }
3484 void setAsmStringExpr(Expr *E) { AsmStr = E; }
3485
3486 std::string getAsmString() const;
3487
3488 /// AsmStringPiece - this is part of a decomposed asm string specification
3489 /// (for use with the AnalyzeAsmString function below). An asm string is
3490 /// considered to be a concatenation of these parts.
3492 public:
3493 enum Kind {
3494 String, // String in .ll asm string form, "$" -> "$$" and "%%" -> "%".
3495 Operand // Operand reference, with optional modifier %c4.
3496 };
3497
3498 private:
3499 Kind MyKind;
3500 std::string Str;
3501 unsigned OperandNo;
3502
3503 // Source range for operand references.
3504 CharSourceRange Range;
3505
3506 public:
3507 AsmStringPiece(const std::string &S) : MyKind(String), Str(S) {}
3508 AsmStringPiece(unsigned OpNo, const std::string &S, SourceLocation Begin,
3509 SourceLocation End)
3510 : MyKind(Operand), Str(S), OperandNo(OpNo),
3511 Range(CharSourceRange::getCharRange(Begin, End)) {}
3512
3513 bool isString() const { return MyKind == String; }
3514 bool isOperand() const { return MyKind == Operand; }
3515
3516 const std::string &getString() const { return Str; }
3517
3518 unsigned getOperandNo() const {
3519 assert(isOperand());
3520 return OperandNo;
3521 }
3522
3524 assert(isOperand() && "Range is currently used only for Operands.");
3525 return Range;
3526 }
3527
3528 /// getModifier - Get the modifier for this operand, if present. This
3529 /// returns '\0' if there was no modifier.
3530 char getModifier() const;
3531 };
3532
3533 /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing
3534 /// it into pieces. If the asm string is erroneous, emit errors and return
3535 /// true, otherwise return false. This handles canonicalization and
3536 /// translation of strings from GCC syntax to LLVM IR syntax, and handles
3537 //// flattening of named references like %[foo] to Operand AsmStringPiece's.
3539 const ASTContext &C, unsigned &DiagOffs) const;
3540
3541 /// Assemble final IR asm string.
3542 std::string generateAsmString(const ASTContext &C) const;
3543
3544 //===--- Output operands ---===//
3545
3546 IdentifierInfo *getOutputIdentifier(unsigned i) const { return Names[i]; }
3547
3548 StringRef getOutputName(unsigned i) const {
3550 return II->getName();
3551
3552 return {};
3553 }
3554
3555 std::string getOutputConstraint(unsigned i) const;
3556
3557 const Expr *getOutputConstraintExpr(unsigned i) const {
3558 return Constraints[i];
3559 }
3560 Expr *getOutputConstraintExpr(unsigned i) { return Constraints[i]; }
3561
3562 Expr *getOutputExpr(unsigned i);
3563
3564 const Expr *getOutputExpr(unsigned i) const {
3565 return const_cast<GCCAsmStmt*>(this)->getOutputExpr(i);
3566 }
3567
3568 //===--- Input operands ---===//
3569
3571 return Names[i + NumOutputs];
3572 }
3573
3574 StringRef getInputName(unsigned i) const {
3576 return II->getName();
3577
3578 return {};
3579 }
3580
3581 std::string getInputConstraint(unsigned i) const;
3582
3583 const Expr *getInputConstraintExpr(unsigned i) const {
3584 return Constraints[i + NumOutputs];
3585 }
3587 return Constraints[i + NumOutputs];
3588 }
3589
3590 Expr *getInputExpr(unsigned i);
3591 void setInputExpr(unsigned i, Expr *E);
3592
3593 const Expr *getInputExpr(unsigned i) const {
3594 return const_cast<GCCAsmStmt*>(this)->getInputExpr(i);
3595 }
3596
3597 static std::string ExtractStringFromGCCAsmStmtComponent(const Expr *E);
3598
3599 //===--- Labels ---===//
3600
3601 bool isAsmGoto() const {
3602 return NumLabels > 0;
3603 }
3604
3605 unsigned getNumLabels() const {
3606 return NumLabels;
3607 }
3608
3610 return Names[i + NumOutputs + NumInputs];
3611 }
3612
3613 AddrLabelExpr *getLabelExpr(unsigned i) const;
3614 StringRef getLabelName(unsigned i) const;
3617 using labels_range = llvm::iterator_range<labels_iterator>;
3618 using labels_const_range = llvm::iterator_range<const_labels_iterator>;
3619
3621 return &Exprs[0] + NumOutputs + NumInputs;
3622 }
3623
3625 return &Exprs[0] + NumOutputs + NumInputs + NumLabels;
3626 }
3627
3631
3633 return &Exprs[0] + NumOutputs + NumInputs;
3634 }
3635
3637 return &Exprs[0] + NumOutputs + NumInputs + NumLabels;
3638 }
3639
3643
3644private:
3645 void setOutputsAndInputsAndClobbers(const ASTContext &C,
3646 IdentifierInfo **Names,
3647 Expr **Constraints, Stmt **Exprs,
3648 unsigned NumOutputs, unsigned NumInputs,
3649 unsigned NumLabels, Expr **Clobbers,
3650 unsigned NumClobbers);
3651
3652public:
3653 //===--- Other ---===//
3654
3655 /// getNamedOperand - Given a symbolic operand reference like %[foo],
3656 /// translate this into a numeric value needed to reference the same operand.
3657 /// This returns -1 if the operand name is invalid.
3658 int getNamedOperand(StringRef SymbolicName) const;
3659
3660 std::string getClobber(unsigned i) const;
3661
3662 Expr *getClobberExpr(unsigned i) { return Clobbers[i]; }
3663 const Expr *getClobberExpr(unsigned i) const { return Clobbers[i]; }
3664
3665 SourceLocation getBeginLoc() const LLVM_READONLY { return AsmLoc; }
3666 SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
3667
3668 static bool classof(const Stmt *T) {
3669 return T->getStmtClass() == GCCAsmStmtClass;
3670 }
3671};
3672
3673/// This represents a Microsoft inline-assembly statement extension.
3674class MSAsmStmt : public AsmStmt {
3675 friend class ASTStmtReader;
3676
3677 SourceLocation LBraceLoc, EndLoc;
3678 StringRef AsmStr;
3679
3680 unsigned NumAsmToks = 0;
3681
3682 Token *AsmToks = nullptr;
3683 StringRef *Constraints = nullptr;
3684 StringRef *Clobbers = nullptr;
3685
3686public:
3687 MSAsmStmt(const ASTContext &C, SourceLocation asmloc,
3688 SourceLocation lbraceloc, bool issimple, bool isvolatile,
3689 ArrayRef<Token> asmtoks, unsigned numoutputs, unsigned numinputs,
3690 ArrayRef<StringRef> constraints,
3691 ArrayRef<Expr*> exprs, StringRef asmstr,
3692 ArrayRef<StringRef> clobbers, SourceLocation endloc);
3693
3694 /// Build an empty MS-style inline-assembly statement.
3695 explicit MSAsmStmt(EmptyShell Empty) : AsmStmt(MSAsmStmtClass, Empty) {}
3696
3697 SourceLocation getLBraceLoc() const { return LBraceLoc; }
3698 void setLBraceLoc(SourceLocation L) { LBraceLoc = L; }
3699 SourceLocation getEndLoc() const { return EndLoc; }
3700 void setEndLoc(SourceLocation L) { EndLoc = L; }
3701
3702 bool hasBraces() const { return LBraceLoc.isValid(); }
3703
3704 unsigned getNumAsmToks() { return NumAsmToks; }
3705 Token *getAsmToks() { return AsmToks; }
3706
3707 //===--- Asm String Analysis ---===//
3708 StringRef getAsmString() const { return AsmStr; }
3709
3710 /// Assemble final IR asm string.
3711 std::string generateAsmString(const ASTContext &C) const;
3712
3713 //===--- Output operands ---===//
3714
3715 StringRef getOutputConstraint(unsigned i) const {
3716 assert(i < NumOutputs);
3717 return Constraints[i];
3718 }
3719
3720 Expr *getOutputExpr(unsigned i);
3721
3722 const Expr *getOutputExpr(unsigned i) const {
3723 return const_cast<MSAsmStmt*>(this)->getOutputExpr(i);
3724 }
3725
3726 //===--- Input operands ---===//
3727
3728 StringRef getInputConstraint(unsigned i) const {
3729 assert(i < NumInputs);
3730 return Constraints[i + NumOutputs];
3731 }
3732
3733 Expr *getInputExpr(unsigned i);
3734 void setInputExpr(unsigned i, Expr *E);
3735
3736 const Expr *getInputExpr(unsigned i) const {
3737 return const_cast<MSAsmStmt*>(this)->getInputExpr(i);
3738 }
3739
3740 //===--- Other ---===//
3741
3743 return {Constraints, NumInputs + NumOutputs};
3744 }
3745
3746 ArrayRef<StringRef> getClobbers() const { return {Clobbers, NumClobbers}; }
3747
3749 return {reinterpret_cast<Expr **>(Exprs), NumInputs + NumOutputs};
3750 }
3751
3752 StringRef getClobber(unsigned i) const { return getClobbers()[i]; }
3753
3754private:
3755 void initialize(const ASTContext &C, StringRef AsmString,
3756 ArrayRef<Token> AsmToks, ArrayRef<StringRef> Constraints,
3758
3759public:
3760 SourceLocation getBeginLoc() const LLVM_READONLY { return AsmLoc; }
3761
3762 static bool classof(const Stmt *T) {
3763 return T->getStmtClass() == MSAsmStmtClass;
3764 }
3765
3769
3773};
3774
3775class SEHExceptStmt : public Stmt {
3776 friend class ASTReader;
3777 friend class ASTStmtReader;
3778
3779 SourceLocation Loc;
3780 Stmt *Children[2];
3781
3782 enum { FILTER_EXPR, BLOCK };
3783
3784 SEHExceptStmt(SourceLocation Loc, Expr *FilterExpr, Stmt *Block);
3785 explicit SEHExceptStmt(EmptyShell E) : Stmt(SEHExceptStmtClass, E) {}
3786
3787public:
3788 static SEHExceptStmt* Create(const ASTContext &C,
3789 SourceLocation ExceptLoc,
3790 Expr *FilterExpr,
3791 Stmt *Block);
3792
3793 SourceLocation getBeginLoc() const LLVM_READONLY { return getExceptLoc(); }
3794
3795 SourceLocation getExceptLoc() const { return Loc; }
3797
3799 return reinterpret_cast<Expr*>(Children[FILTER_EXPR]);
3800 }
3801
3803 return cast<CompoundStmt>(Children[BLOCK]);
3804 }
3805
3807 return child_range(Children, Children+2);
3808 }
3809
3811 return const_child_range(Children, Children + 2);
3812 }
3813
3814 static bool classof(const Stmt *T) {
3815 return T->getStmtClass() == SEHExceptStmtClass;
3816 }
3817};
3818
3819class SEHFinallyStmt : public Stmt {
3820 friend class ASTReader;
3821 friend class ASTStmtReader;
3822
3823 SourceLocation Loc;
3824 Stmt *Block;
3825
3826 SEHFinallyStmt(SourceLocation Loc, Stmt *Block);
3827 explicit SEHFinallyStmt(EmptyShell E) : Stmt(SEHFinallyStmtClass, E) {}
3828
3829public:
3830 static SEHFinallyStmt* Create(const ASTContext &C,
3831 SourceLocation FinallyLoc,
3832 Stmt *Block);
3833
3834 SourceLocation getBeginLoc() const LLVM_READONLY { return getFinallyLoc(); }
3835
3836 SourceLocation getFinallyLoc() const { return Loc; }
3837 SourceLocation getEndLoc() const { return Block->getEndLoc(); }
3838
3839 CompoundStmt *getBlock() const { return cast<CompoundStmt>(Block); }
3840
3842 return child_range(&Block,&Block+1);
3843 }
3844
3846 return const_child_range(&Block, &Block + 1);
3847 }
3848
3849 static bool classof(const Stmt *T) {
3850 return T->getStmtClass() == SEHFinallyStmtClass;
3851 }
3852};
3853
3854class SEHTryStmt : public Stmt {
3855 friend class ASTReader;
3856 friend class ASTStmtReader;
3857
3858 bool IsCXXTry;
3859 SourceLocation TryLoc;
3860 Stmt *Children[2];
3861
3862 enum { TRY = 0, HANDLER = 1 };
3863
3864 SEHTryStmt(bool isCXXTry, // true if 'try' otherwise '__try'
3865 SourceLocation TryLoc,
3866 Stmt *TryBlock,
3867 Stmt *Handler);
3868
3869 explicit SEHTryStmt(EmptyShell E) : Stmt(SEHTryStmtClass, E) {}
3870
3871public:
3872 static SEHTryStmt* Create(const ASTContext &C, bool isCXXTry,
3873 SourceLocation TryLoc, Stmt *TryBlock,
3874 Stmt *Handler);
3875
3876 SourceLocation getBeginLoc() const LLVM_READONLY { return getTryLoc(); }
3877
3878 SourceLocation getTryLoc() const { return TryLoc; }
3879 SourceLocation getEndLoc() const { return Children[HANDLER]->getEndLoc(); }
3880
3881 bool getIsCXXTry() const { return IsCXXTry; }
3882
3884 return cast<CompoundStmt>(Children[TRY]);
3885 }
3886
3887 Stmt *getHandler() const { return Children[HANDLER]; }
3888
3889 /// Returns 0 if not defined
3892
3894 return child_range(Children, Children+2);
3895 }
3896
3898 return const_child_range(Children, Children + 2);
3899 }
3900
3901 static bool classof(const Stmt *T) {
3902 return T->getStmtClass() == SEHTryStmtClass;
3903 }
3904};
3905
3906/// Represents a __leave statement.
3907class SEHLeaveStmt : public Stmt {
3908 SourceLocation LeaveLoc;
3909
3910public:
3912 : Stmt(SEHLeaveStmtClass), LeaveLoc(LL) {}
3913
3914 /// Build an empty __leave statement.
3915 explicit SEHLeaveStmt(EmptyShell Empty) : Stmt(SEHLeaveStmtClass, Empty) {}
3916
3917 SourceLocation getLeaveLoc() const { return LeaveLoc; }
3918 void setLeaveLoc(SourceLocation L) { LeaveLoc = L; }
3919
3920 SourceLocation getBeginLoc() const LLVM_READONLY { return LeaveLoc; }
3921 SourceLocation getEndLoc() const LLVM_READONLY { return LeaveLoc; }
3922
3923 static bool classof(const Stmt *T) {
3924 return T->getStmtClass() == SEHLeaveStmtClass;
3925 }
3926
3927 // Iterators
3931
3935};
3936
3937/// This captures a statement into a function. For example, the following
3938/// pragma annotated compound statement can be represented as a CapturedStmt,
3939/// and this compound statement is the body of an anonymous outlined function.
3940/// @code
3941/// #pragma omp parallel
3942/// {
3943/// compute();
3944/// }
3945/// @endcode
3946class CapturedStmt : public Stmt {
3947public:
3948 /// The different capture forms: by 'this', by reference, capture for
3949 /// variable-length array type etc.
3956
3957 /// Describes the capture of either a variable, or 'this', or
3958 /// variable-length array type.
3959 class Capture {
3960 llvm::PointerIntPair<VarDecl *, 2, VariableCaptureKind> VarAndKind;
3961 SourceLocation Loc;
3962
3963 Capture() = default;
3964
3965 public:
3966 friend class ASTStmtReader;
3967 friend class CapturedStmt;
3968
3969 /// Create a new capture.
3970 ///
3971 /// \param Loc The source location associated with this capture.
3972 ///
3973 /// \param Kind The kind of capture (this, ByRef, ...).
3974 ///
3975 /// \param Var The variable being captured, or null if capturing this.
3977 VarDecl *Var = nullptr);
3978
3979 /// Determine the kind of capture.
3981
3982 /// Retrieve the source location at which the variable or 'this' was
3983 /// first used.
3984 SourceLocation getLocation() const { return Loc; }
3985
3986 /// Determine whether this capture handles the C++ 'this' pointer.
3987 bool capturesThis() const { return getCaptureKind() == VCK_This; }
3988
3989 /// Determine whether this capture handles a variable (by reference).
3990 bool capturesVariable() const { return getCaptureKind() == VCK_ByRef; }
3991
3992 /// Determine whether this capture handles a variable by copy.
3994 return getCaptureKind() == VCK_ByCopy;
3995 }
3996
3997 /// Determine whether this capture handles a variable-length array
3998 /// type.
4000 return getCaptureKind() == VCK_VLAType;
4001 }
4002
4003 /// Retrieve the declaration of the variable being captured.
4004 ///
4005 /// This operation is only valid if this capture captures a variable.
4006 VarDecl *getCapturedVar() const;
4007 };
4008
4009private:
4010 /// The number of variable captured, including 'this'.
4011 unsigned NumCaptures;
4012
4013 /// The pointer part is the implicit the outlined function and the
4014 /// int part is the captured region kind, 'CR_Default' etc.
4015 llvm::PointerIntPair<CapturedDecl *, 2, CapturedRegionKind> CapDeclAndKind;
4016
4017 /// The record for captured variables, a RecordDecl or CXXRecordDecl.
4018 RecordDecl *TheRecordDecl = nullptr;
4019
4020 /// Construct a captured statement.
4022 ArrayRef<Expr *> CaptureInits, CapturedDecl *CD, RecordDecl *RD);
4023
4024 /// Construct an empty captured statement.
4025 CapturedStmt(EmptyShell Empty, unsigned NumCaptures);
4026
4027 Stmt **getStoredStmts() { return reinterpret_cast<Stmt **>(this + 1); }
4028
4029 Stmt *const *getStoredStmts() const {
4030 return reinterpret_cast<Stmt *const *>(this + 1);
4031 }
4032
4033 Capture *getStoredCaptures() const;
4034
4035 void setCapturedStmt(Stmt *S) { getStoredStmts()[NumCaptures] = S; }
4036
4037public:
4038 friend class ASTStmtReader;
4039
4040 static CapturedStmt *Create(const ASTContext &Context, Stmt *S,
4041 CapturedRegionKind Kind,
4042 ArrayRef<Capture> Captures,
4043 ArrayRef<Expr *> CaptureInits,
4044 CapturedDecl *CD, RecordDecl *RD);
4045
4046 static CapturedStmt *CreateDeserialized(const ASTContext &Context,
4047 unsigned NumCaptures);
4048
4049 /// Retrieve the statement being captured.
4050 Stmt *getCapturedStmt() { return getStoredStmts()[NumCaptures]; }
4051 const Stmt *getCapturedStmt() const { return getStoredStmts()[NumCaptures]; }
4052
4053 /// Retrieve the outlined function declaration.
4055 const CapturedDecl *getCapturedDecl() const;
4056
4057 /// Set the outlined function declaration.
4059
4060 /// Retrieve the captured region kind.
4062
4063 /// Set the captured region kind.
4065
4066 /// Retrieve the record declaration for captured variables.
4067 const RecordDecl *getCapturedRecordDecl() const { return TheRecordDecl; }
4068
4069 /// Set the record declaration for captured variables.
4071 assert(D && "null RecordDecl");
4072 TheRecordDecl = D;
4073 }
4074
4075 /// True if this variable has been captured.
4076 bool capturesVariable(const VarDecl *Var) const;
4077
4078 /// An iterator that walks over the captures.
4081 using capture_range = llvm::iterator_range<capture_iterator>;
4082 using capture_const_range = llvm::iterator_range<const_capture_iterator>;
4083
4090
4091 /// Retrieve an iterator pointing to the first capture.
4092 capture_iterator capture_begin() { return getStoredCaptures(); }
4093 const_capture_iterator capture_begin() const { return getStoredCaptures(); }
4094
4095 /// Retrieve an iterator pointing past the end of the sequence of
4096 /// captures.
4098 return getStoredCaptures() + NumCaptures;
4099 }
4100
4101 /// Retrieve the number of captures, including 'this'.
4102 unsigned capture_size() const { return NumCaptures; }
4103
4104 /// Iterator that walks over the capture initialization arguments.
4106 using capture_init_range = llvm::iterator_range<capture_init_iterator>;
4107
4108 /// Const iterator that walks over the capture initialization
4109 /// arguments.
4112 llvm::iterator_range<const_capture_init_iterator>;
4113
4117
4121
4122 /// Retrieve the first initialization argument.
4124 return reinterpret_cast<Expr **>(getStoredStmts());
4125 }
4126
4128 return reinterpret_cast<Expr *const *>(getStoredStmts());
4129 }
4130
4131 /// Retrieve the iterator pointing one past the last initialization
4132 /// argument.
4134 return capture_init_begin() + NumCaptures;
4135 }
4136
4138 return capture_init_begin() + NumCaptures;
4139 }
4140
4141 SourceLocation getBeginLoc() const LLVM_READONLY {
4142 return getCapturedStmt()->getBeginLoc();
4143 }
4144
4145 SourceLocation getEndLoc() const LLVM_READONLY {
4146 return getCapturedStmt()->getEndLoc();
4147 }
4148
4149 SourceRange getSourceRange() const LLVM_READONLY {
4150 return getCapturedStmt()->getSourceRange();
4151 }
4152
4153 static bool classof(const Stmt *T) {
4154 return T->getStmtClass() == CapturedStmtClass;
4155 }
4156
4158
4160};
4161
4162} // namespace clang
4163
4164#endif // LLVM_CLANG_AST_STMT_H
#define V(N, I)
static StringRef bytes(const std::vector< T, Allocator > &v)
Defines enumerations for traits support.
static void dump(llvm::raw_ostream &OS, StringRef FunctionName, ArrayRef< CounterExpression > Expressions, ArrayRef< CounterMappingRegion > Regions)
SmallVector< AnnotatedLine *, 1 > Children
If this token starts a block, this contains all the unwrapped lines in it.
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.
static std::pair< Stmt::Likelihood, const Attr * > getLikelihood(ArrayRef< const Attr * > Attrs)
Definition Stmt.cpp:149
#define NumStmtBits
Definition Stmt.h:113
__SIZE_TYPE__ size_t
The unsigned integer type of the result of the sizeof operator.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:223
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:223
AddrLabelExpr - The GNU address of label extension, representing &&label.
Definition Expr.h:4556
Stmt ** Exprs
Definition Stmt.h:3304
void setSimple(bool V)
Definition Stmt.h:3320
outputs_iterator begin_outputs()
Definition Stmt.h:3421
void setAsmLoc(SourceLocation L)
Definition Stmt.h:3317
const_outputs_iterator end_outputs() const
Definition Stmt.h:3437
std::string getInputConstraint(unsigned i) const
getInputConstraint - Return the specified input constraint.
Definition Stmt.cpp:515
SourceLocation AsmLoc
Definition Stmt.h:3290
bool isVolatile() const
Definition Stmt.h:3322
llvm::function_ref< void(const Stmt *, StringRef)> UnsupportedConstraintCallbackTy
Definition Stmt.h:3333
outputs_iterator end_outputs()
Definition Stmt.h:3425
const_inputs_iterator begin_inputs() const
Definition Stmt.h:3402
unsigned getNumPlusOperands() const
getNumPlusOperands - Return the number of output operands that have a "+" constraint.
Definition Stmt.cpp:541
std::string getOutputConstraint(unsigned i) const
getOutputConstraint - Return the constraint string for the specified output operand.
Definition Stmt.cpp:499
AsmStmt(StmtClass SC, SourceLocation asmloc, bool issimple, bool isvolatile, unsigned numoutputs, unsigned numinputs, unsigned numclobbers)
Definition Stmt.h:3306
void setVolatile(bool V)
Definition Stmt.h:3323
static bool classof(const Stmt *T)
Definition Stmt.h:3380
outputs_range outputs()
Definition Stmt.h:3429
inputs_const_range inputs() const
Definition Stmt.h:3410
SourceLocation getAsmLoc() const
Definition Stmt.h:3316
const Expr * getInputExpr(unsigned i) const
Definition Stmt.cpp:523
unsigned NumInputs
Definition Stmt.h:3301
SourceLocation getEndLoc() const LLVM_READONLY
Definition Stmt.h:3326
std::string addVariableConstraints(StringRef Constraint, const Expr &AsmExpr, const TargetInfo &Target, bool EarlyClobber, UnsupportedConstraintCallbackTy UnsupportedCB, std::string *GCCReg=nullptr) const
Look at AsmExpr and if it is a variable declared as using a particular register add that as a constra...
Definition Stmt.cpp:459
inputs_range inputs()
Definition Stmt.h:3400
llvm::iterator_range< inputs_iterator > inputs_range
Definition Stmt.h:3389
bool isOutputPlusConstraint(unsigned i) const
isOutputPlusConstraint - Return true if the specified output constraint is a "+" constraint (which is...
Definition Stmt.h:3355
unsigned getNumClobbers() const
Definition Stmt.h:3377
ExprIterator outputs_iterator
Definition Stmt.h:3416
const_inputs_iterator end_inputs() const
Definition Stmt.h:3406
llvm::iterator_range< const_inputs_iterator > inputs_const_range
Definition Stmt.h:3390
const_child_range children() const
Definition Stmt.h:3449
ExprIterator inputs_iterator
Definition Stmt.h:3387
bool IsSimple
True if the assembly statement does not have any input or output operands.
Definition Stmt.h:3294
const Expr * getOutputExpr(unsigned i) const
Definition Stmt.cpp:507
outputs_const_range outputs() const
Definition Stmt.h:3441
inputs_iterator end_inputs()
Definition Stmt.h:3396
unsigned getNumOutputs() const
Definition Stmt.h:3345
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.h:3325
inputs_iterator begin_inputs()
Definition Stmt.h:3392
AsmStmt(StmtClass SC, EmptyShell Empty)
Build an empty inline-assembly statement.
Definition Stmt.h:3314
unsigned NumOutputs
Definition Stmt.h:3300
child_range children()
Definition Stmt.h:3445
ConstExprIterator const_outputs_iterator
Definition Stmt.h:3417
ConstExprIterator const_inputs_iterator
Definition Stmt.h:3388
std::string generateAsmString(const ASTContext &C) const
Assemble final IR asm string.
Definition Stmt.cpp:491
unsigned NumClobbers
Definition Stmt.h:3302
bool IsVolatile
If true, treat this inline assembly as having side effects.
Definition Stmt.h:3298
friend class ASTStmtReader
Definition Stmt.h:3288
unsigned getNumInputs() const
Definition Stmt.h:3367
bool isSimple() const
Definition Stmt.h:3319
llvm::iterator_range< outputs_iterator > outputs_range
Definition Stmt.h:3418
const_outputs_iterator begin_outputs() const
Definition Stmt.h:3433
std::string getClobber(unsigned i) const
Definition Stmt.cpp:531
llvm::iterator_range< const_outputs_iterator > outputs_const_range
Definition Stmt.h:3419
Attr - This represents one attribute.
Definition Attr.h:46
Represents an attribute applied to a statement.
Definition Stmt.h:2212
static AttributedStmt * CreateEmpty(const ASTContext &C, unsigned NumAttrs)
Definition Stmt.cpp:450
Stmt * getSubStmt()
Definition Stmt.h:2248
const Stmt * getSubStmt() const
Definition Stmt.h:2249
SourceLocation getAttrLoc() const
Definition Stmt.h:2243
ArrayRef< const Attr * > getAttrs() const
Definition Stmt.h:2244
child_range children()
Definition Stmt.h:2254
const_child_range children() const
Definition Stmt.h:2256
friend class ASTStmtReader
Definition Stmt.h:2213
static bool classof(const Stmt *T)
Definition Stmt.h:2260
SourceLocation getEndLoc() const LLVM_READONLY
Definition Stmt.h:2252
SourceLocation getBeginLoc() const
Definition Stmt.h:2251
BreakStmt(SourceLocation BL)
Definition Stmt.h:3146
static bool classof(const Stmt *T)
Definition Stmt.h:3154
BreakStmt(EmptyShell Empty)
Build an empty break statement.
Definition Stmt.h:3151
BreakStmt(SourceLocation CL, SourceLocation LabelLoc, LabelDecl *Target)
Definition Stmt.h:3147
Represents the body of a CapturedStmt, and serves as its DeclContext.
Definition Decl.h:4988
Describes the capture of either a variable, or 'this', or variable-length array type.
Definition Stmt.h:3959
bool capturesVariableByCopy() const
Determine whether this capture handles a variable by copy.
Definition Stmt.h:3993
VariableCaptureKind getCaptureKind() const
Determine the kind of capture.
Definition Stmt.cpp:1387
VarDecl * getCapturedVar() const
Retrieve the declaration of the variable being captured.
Definition Stmt.cpp:1391
bool capturesVariableArrayType() const
Determine whether this capture handles a variable-length array type.
Definition Stmt.h:3999
friend class CapturedStmt
Definition Stmt.h:3967
bool capturesThis() const
Determine whether this capture handles the C++ 'this' pointer.
Definition Stmt.h:3987
bool capturesVariable() const
Determine whether this capture handles a variable (by reference).
Definition Stmt.h:3990
SourceLocation getLocation() const
Retrieve the source location at which the variable or 'this' was first used.
Definition Stmt.h:3984
friend class ASTStmtReader
Definition Stmt.h:3966
This captures a statement into a function.
Definition Stmt.h:3946
unsigned capture_size() const
Retrieve the number of captures, including 'this'.
Definition Stmt.h:4102
const_capture_iterator capture_begin() const
Definition Stmt.h:4093
static CapturedStmt * CreateDeserialized(const ASTContext &Context, unsigned NumCaptures)
Definition Stmt.cpp:1471
SourceLocation getEndLoc() const LLVM_READONLY
Definition Stmt.h:4145
capture_init_range capture_inits()
Definition Stmt.h:4114
Expr ** capture_init_iterator
Iterator that walks over the capture initialization arguments.
Definition Stmt.h:4105
void setCapturedRegionKind(CapturedRegionKind Kind)
Set the captured region kind.
Definition Stmt.cpp:1513
const_capture_init_iterator capture_init_begin() const
Definition Stmt.h:4127
const Capture * const_capture_iterator
Definition Stmt.h:4080
CapturedDecl * getCapturedDecl()
Retrieve the outlined function declaration.
Definition Stmt.cpp:1493
SourceRange getSourceRange() const LLVM_READONLY
Definition Stmt.h:4149
capture_iterator capture_end() const
Retrieve an iterator pointing past the end of the sequence of captures.
Definition Stmt.h:4097
child_range children()
Definition Stmt.cpp:1484
const RecordDecl * getCapturedRecordDecl() const
Retrieve the record declaration for captured variables.
Definition Stmt.h:4067
llvm::iterator_range< const_capture_init_iterator > const_capture_init_range
Definition Stmt.h:4111
Stmt * getCapturedStmt()
Retrieve the statement being captured.
Definition Stmt.h:4050
llvm::iterator_range< capture_init_iterator > capture_init_range
Definition Stmt.h:4106
Capture * capture_iterator
An iterator that walks over the captures.
Definition Stmt.h:4079
llvm::iterator_range< capture_iterator > capture_range
Definition Stmt.h:4081
bool capturesVariable(const VarDecl *Var) const
True if this variable has been captured.
Definition Stmt.cpp:1517
static bool classof(const Stmt *T)
Definition Stmt.h:4153
capture_init_iterator capture_init_begin()
Retrieve the first initialization argument.
Definition Stmt.h:4123
void setCapturedDecl(CapturedDecl *D)
Set the outlined function declaration.
Definition Stmt.cpp:1502
capture_iterator capture_begin()
Retrieve an iterator pointing to the first capture.
Definition Stmt.h:4092
const_capture_init_iterator capture_init_end() const
Definition Stmt.h:4137
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.h:4141
void setCapturedRecordDecl(RecordDecl *D)
Set the record declaration for captured variables.
Definition Stmt.h:4070
friend class ASTStmtReader
Definition Stmt.h:4038
llvm::iterator_range< const_capture_iterator > capture_const_range
Definition Stmt.h:4082
capture_init_iterator capture_init_end()
Retrieve the iterator pointing one past the last initialization argument.
Definition Stmt.h:4133
capture_range captures()
Definition Stmt.h:4084
Expr *const * const_capture_init_iterator
Const iterator that walks over the capture initialization arguments.
Definition Stmt.h:4110
const Stmt * getCapturedStmt() const
Definition Stmt.h:4051
capture_const_range captures() const
Definition Stmt.h:4087
CapturedRegionKind getCapturedRegionKind() const
Retrieve the captured region kind.
Definition Stmt.cpp:1508
VariableCaptureKind
The different capture forms: by 'this', by reference, capture for variable-length array type etc.
Definition Stmt.h:3950
const_capture_init_range capture_inits() const
Definition Stmt.h:4118
Stmt * getSubStmt()
Definition Stmt.h:2042
const Expr * getRHS() const
Definition Stmt.h:2030
Expr * getLHS()
Definition Stmt.h:2012
const_child_range children() const
Definition Stmt.h:2072
SourceLocation getBeginLoc() const
Definition Stmt.h:2051
void setEllipsisLoc(SourceLocation L)
Set the location of the ... in a case statement of the form LHS ... RHS.
Definition Stmt.h:2005
static bool classof(const Stmt *T)
Definition Stmt.h:2061
bool caseStmtIsGNURange() const
True if this case statement is of the form case LHS ... RHS, which is a GNU extension.
Definition Stmt.h:1992
const Expr * getLHS() const
Definition Stmt.h:2016
SourceLocation getEllipsisLoc() const
Get the location of the ... in a case statement of the form LHS ... RHS.
Definition Stmt.h:1998
void setCaseLoc(SourceLocation L)
Definition Stmt.h:1995
child_range children()
Definition Stmt.h:2066
SourceLocation getCaseLoc() const
Definition Stmt.h:1994
static CaseStmt * CreateEmpty(const ASTContext &Ctx, bool CaseStmtIsGNURange)
Build an empty case statement.
Definition Stmt.cpp:1317
void setLHS(Expr *Val)
Definition Stmt.h:2020
void setSubStmt(Stmt *S)
Definition Stmt.h:2047
const Stmt * getSubStmt() const
Definition Stmt.h:2043
Expr * getRHS()
Definition Stmt.h:2024
SourceLocation getEndLoc() const LLVM_READONLY
Definition Stmt.h:2052
void setRHS(Expr *Val)
Definition Stmt.h:2036
Represents a byte-granular source range.
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition Stmt.h:1749
Stmt * body_front()
Definition Stmt.h:1815
static bool classof(const Stmt *T)
Definition Stmt.h:1869
bool body_empty() const
Definition Stmt.h:1793
unsigned size() const
Definition Stmt.h:1794
body_const_range body() const
Definition Stmt.h:1824
Stmt *const * const_body_iterator
Definition Stmt.h:1821
const_reverse_body_iterator body_rend() const
Definition Stmt.h:1859
llvm::iterator_range< const_body_iterator > body_const_range
Definition Stmt.h:1822
std::reverse_iterator< body_iterator > reverse_body_iterator
Definition Stmt.h:1842
reverse_body_iterator body_rbegin()
Definition Stmt.h:1844
llvm::iterator_range< body_iterator > body_range
Definition Stmt.h:1810
std::reverse_iterator< const_body_iterator > const_reverse_body_iterator
Definition Stmt.h:1852
body_iterator body_end()
Definition Stmt.h:1814
FPOptionsOverride getStoredFPFeatures() const
Get FPOptionsOverride from trailing storage.
Definition Stmt.h:1799
const Stmt * body_front() const
Definition Stmt.h:1834
body_range body()
Definition Stmt.h:1812
SourceLocation getBeginLoc() const
Definition Stmt.h:1863
static CompoundStmt * CreateEmpty(const ASTContext &C, unsigned NumStmts, bool HasFPFeatures)
Definition Stmt.cpp:409
SourceLocation getLBracLoc() const
Definition Stmt.h:1866
body_iterator body_begin()
Definition Stmt.h:1813
SourceLocation getEndLoc() const
Definition Stmt.h:1864
bool hasStoredFPFeatures() const
Definition Stmt.h:1796
const_child_range children() const
Definition Stmt.h:1876
CompoundStmt(SourceLocation Loc, SourceLocation EndLoc)
Definition Stmt.h:1783
reverse_body_iterator body_rend()
Definition Stmt.h:1848
CompoundStmt(SourceLocation Loc)
Definition Stmt.h:1781
const_body_iterator body_begin() const
Definition Stmt.h:1828
Stmt ** body_iterator
Definition Stmt.h:1809
const Stmt * body_back() const
Definition Stmt.h:1838
friend class ASTStmtReader
Definition Stmt.h:1750
const_reverse_body_iterator body_rbegin() const
Definition Stmt.h:1855
child_range children()
Definition Stmt.h:1874
Stmt * body_back()
Definition Stmt.h:1817
FPOptionsOverride getStoredFPFeaturesOrDefault() const
Get the store FPOptionsOverride or default if not stored.
Definition Stmt.h:1805
SourceLocation getRBracLoc() const
Definition Stmt.h:1867
const_body_iterator body_end() const
Definition Stmt.h:1832
ContinueStmt(EmptyShell Empty)
Build an empty continue statement.
Definition Stmt.h:3135
ContinueStmt(SourceLocation CL)
Definition Stmt.h:3130
static bool classof(const Stmt *T)
Definition Stmt.h:3138
ContinueStmt(SourceLocation CL, SourceLocation LabelLoc, LabelDecl *Target)
Definition Stmt.h:3131
Decl *const * const_iterator
Definition DeclGroup.h:73
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition Stmt.h:1640
std::reverse_iterator< decl_iterator > reverse_decl_iterator
Definition Stmt.h:1699
llvm::iterator_range< decl_iterator > decl_range
Definition Stmt.h:1685
child_range children()
Definition Stmt.h:1673
const_child_range children() const
Definition Stmt.h:1678
Decl * getSingleDecl()
Definition Stmt.h:1656
SourceLocation getEndLoc() const
Definition Stmt.h:1663
const DeclGroupRef getDeclGroup() const
Definition Stmt.h:1658
DeclStmt(EmptyShell Empty)
Build an empty declaration statement.
Definition Stmt.h:1649
bool isSingleDecl() const
isSingleDecl - This method returns true if this DeclStmt refers to a single Decl.
Definition Stmt.h:1653
decl_iterator decl_end()
Definition Stmt.h:1695
const_decl_iterator decl_begin() const
Definition Stmt.h:1696
void setStartLoc(SourceLocation L)
Definition Stmt.h:1662
DeclGroupRef::const_iterator const_decl_iterator
Definition Stmt.h:1684
static bool classof(const Stmt *T)
Definition Stmt.h:1668
void setEndLoc(SourceLocation L)
Definition Stmt.h:1664
decl_iterator decl_begin()
Definition Stmt.h:1694
decl_range decls()
Definition Stmt.h:1688
void setDeclGroup(DeclGroupRef DGR)
Definition Stmt.h:1660
const Decl * getSingleDecl() const
Definition Stmt.h:1655
decl_const_range decls() const
Definition Stmt.h:1690
const_decl_iterator decl_end() const
Definition Stmt.h:1697
DeclGroupRef::iterator decl_iterator
Definition Stmt.h:1683
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.h:1666
DeclGroupRef getDeclGroup()
Definition Stmt.h:1659
reverse_decl_iterator decl_rend()
Definition Stmt.h:1705
llvm::iterator_range< const_decl_iterator > decl_const_range
Definition Stmt.h:1686
reverse_decl_iterator decl_rbegin()
Definition Stmt.h:1701
DeclStmt(DeclGroupRef dg, SourceLocation startLoc, SourceLocation endLoc)
Definition Stmt.h:1645
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
void setSubStmt(Stmt *S)
Definition Stmt.h:2092
const Stmt * getSubStmt() const
Definition Stmt.h:2091
child_range children()
Definition Stmt.h:2107
SourceLocation getEndLoc() const LLVM_READONLY
Definition Stmt.h:2098
void setDefaultLoc(SourceLocation L)
Definition Stmt.h:2095
SourceLocation getDefaultLoc() const
Definition Stmt.h:2094
DefaultStmt(EmptyShell Empty)
Build an empty default statement.
Definition Stmt.h:2087
static bool classof(const Stmt *T)
Definition Stmt.h:2102
DefaultStmt(SourceLocation DL, SourceLocation CL, Stmt *substmt)
Definition Stmt.h:2083
const_child_range children() const
Definition Stmt.h:2109
SourceLocation getBeginLoc() const
Definition Stmt.h:2097
Stmt * getSubStmt()
Definition Stmt.h:2090
const Stmt * getBody() const
Definition Stmt.h:3265
SourceLocation getEndLoc() const
Definition Stmt.h:3272
void setBody(Stmt *S)
Definition Stmt.h:3266
SourceLocation getBeginLoc() const
Definition Stmt.h:3271
void setDeferLoc(SourceLocation DeferLoc)
Definition Stmt.h:3260
Stmt * getBody()
Definition Stmt.h:3264
const_child_range children() const
Definition Stmt.h:3276
SourceLocation getDeferLoc() const
Definition Stmt.h:3259
static bool classof(const Stmt *S)
Definition Stmt.h:3280
static DeferStmt * CreateEmpty(ASTContext &Context, EmptyShell Empty)
Definition Stmt.cpp:1548
friend class ASTStmtReader
Definition Stmt.h:3246
child_range children()
Definition Stmt.h:3274
void setWhileLoc(SourceLocation L)
Definition Stmt.h:2873
SourceLocation getBeginLoc() const
Definition Stmt.h:2877
Stmt * getBody()
Definition Stmt.h:2866
Expr * getCond()
Definition Stmt.h:2859
void setDoLoc(SourceLocation L)
Definition Stmt.h:2871
SourceLocation getEndLoc() const
Definition Stmt.h:2878
SourceLocation getWhileLoc() const
Definition Stmt.h:2872
static bool classof(const Stmt *T)
Definition Stmt.h:2880
const_child_range children() const
Definition Stmt.h:2889
DoStmt(EmptyShell Empty)
Build an empty do-while statement.
Definition Stmt.h:2857
SourceLocation getDoLoc() const
Definition Stmt.h:2870
void setRParenLoc(SourceLocation L)
Definition Stmt.h:2875
SourceLocation getRParenLoc() const
Definition Stmt.h:2874
const Stmt * getBody() const
Definition Stmt.h:2867
child_range children()
Definition Stmt.h:2885
void setBody(Stmt *Body)
Definition Stmt.h:2868
DoStmt(Stmt *Body, Expr *Cond, SourceLocation DL, SourceLocation WL, SourceLocation RP)
Definition Stmt.h:2848
const Expr * getCond() const
Definition Stmt.h:2860
void setCond(Expr *Cond)
Definition Stmt.h:2864
This represents one expression.
Definition Expr.h:112
Represents difference between two FPOptions values.
Stmt * getInit()
Definition Stmt.h:2912
ForStmt(const ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar, Expr *Inc, Stmt *Body, SourceLocation FL, SourceLocation LP, SourceLocation RP)
Definition Stmt.cpp:1107
child_range children()
Definition Stmt.h:2968
VarDecl * getConditionVariable() const
Retrieve the variable declared in this "for" statement, if any.
Definition Stmt.cpp:1120
SourceLocation getEndLoc() const
Definition Stmt.h:2961
void setBody(Stmt *S)
Definition Stmt.h:2951
SourceLocation getRParenLoc() const
Definition Stmt.h:2957
const_child_range children() const
Definition Stmt.h:2972
void setCond(Expr *E)
Definition Stmt.h:2949
const DeclStmt * getConditionVariableDeclStmt() const
Definition Stmt.h:2931
void setForLoc(SourceLocation L)
Definition Stmt.h:2954
Stmt * getBody()
Definition Stmt.h:2941
const Expr * getInc() const
Definition Stmt.h:2945
ForStmt(EmptyShell Empty)
Build an empty for statement.
Definition Stmt.h:2910
void setInc(Expr *E)
Definition Stmt.h:2950
void setLParenLoc(SourceLocation L)
Definition Stmt.h:2956
Expr * getInc()
Definition Stmt.h:2940
const Expr * getCond() const
Definition Stmt.h:2944
void setInit(Stmt *S)
Definition Stmt.h:2948
void setConditionVariableDeclStmt(DeclStmt *CondVar)
Definition Stmt.h:2935
SourceLocation getBeginLoc() const
Definition Stmt.h:2960
static bool classof(const Stmt *T)
Definition Stmt.h:2963
const Stmt * getInit() const
Definition Stmt.h:2943
void setConditionVariable(const ASTContext &C, VarDecl *V)
Definition Stmt.cpp:1128
SourceLocation getForLoc() const
Definition Stmt.h:2953
friend class ASTStmtReader
Definition Stmt.h:2898
const Stmt * getBody() const
Definition Stmt.h:2946
Expr * getCond()
Definition Stmt.h:2939
SourceLocation getLParenLoc() const
Definition Stmt.h:2955
DeclStmt * getConditionVariableDeclStmt()
If this ForStmt has a condition variable, return the faux DeclStmt associated with the creation of th...
Definition Stmt.h:2927
void setRParenLoc(SourceLocation L)
Definition Stmt.h:2958
AsmStringPiece(const std::string &S)
Definition Stmt.h:3507
const std::string & getString() const
Definition Stmt.h:3516
unsigned getOperandNo() const
Definition Stmt.h:3518
CharSourceRange getRange() const
Definition Stmt.h:3523
AsmStringPiece(unsigned OpNo, const std::string &S, SourceLocation Begin, SourceLocation End)
Definition Stmt.h:3508
char getModifier() const
getModifier - Get the modifier for this operand, if present.
Definition Stmt.cpp:549
const Expr * getInputExpr(unsigned i) const
Definition Stmt.h:3593
const_labels_iterator end_labels() const
Definition Stmt.h:3636
std::string getOutputConstraint(unsigned i) const
getOutputConstraint - Return the constraint string for the specified output operand.
Definition Stmt.cpp:589
unsigned getNumLabels() const
Definition Stmt.h:3605
std::string generateAsmString(const ASTContext &C) const
Assemble final IR asm string.
Definition Stmt.cpp:872
labels_range labels()
Definition Stmt.h:3628
SourceLocation getRParenLoc() const
Definition Stmt.h:3477
std::string getAsmString() const
Definition Stmt.cpp:574
labels_const_range labels() const
Definition Stmt.h:3640
llvm::iterator_range< labels_iterator > labels_range
Definition Stmt.h:3617
Expr * getInputConstraintExpr(unsigned i)
Definition Stmt.h:3586
void setAsmStringExpr(Expr *E)
Definition Stmt.h:3484
labels_iterator begin_labels()
Definition Stmt.h:3620
IdentifierInfo * getInputIdentifier(unsigned i) const
Definition Stmt.h:3570
bool isAsmGoto() const
Definition Stmt.h:3601
ConstCastIterator< AddrLabelExpr > const_labels_iterator
Definition Stmt.h:3616
CastIterator< AddrLabelExpr > labels_iterator
Definition Stmt.h:3615
const Expr * getClobberExpr(unsigned i) const
Definition Stmt.h:3663
std::string getInputConstraint(unsigned i) const
getInputConstraint - Return the specified input constraint.
Definition Stmt.cpp:611
labels_iterator end_labels()
Definition Stmt.h:3624
const Expr * getOutputConstraintExpr(unsigned i) const
Definition Stmt.h:3557
StringRef getLabelName(unsigned i) const
Definition Stmt.cpp:605
unsigned AnalyzeAsmString(SmallVectorImpl< AsmStringPiece > &Pieces, const ASTContext &C, unsigned &DiagOffs) const
AnalyzeAsmString - Analyze the asm string of the current asm, decomposing it into pieces.
Definition Stmt.cpp:670
void setRParenLoc(SourceLocation L)
Definition Stmt.h:3478
void setInputExpr(unsigned i, Expr *E)
Definition Stmt.cpp:597
Expr * getAsmStringExpr()
Definition Stmt.h:3483
std::string getClobber(unsigned i) const
Definition Stmt.cpp:578
static bool classof(const Stmt *T)
Definition Stmt.h:3668
StringRef getInputName(unsigned i) const
Definition Stmt.h:3574
SourceLocation getEndLoc() const LLVM_READONLY
Definition Stmt.h:3666
StringRef getOutputName(unsigned i) const
Definition Stmt.h:3548
const_labels_iterator begin_labels() const
Definition Stmt.h:3632
GCCAsmStmt(EmptyShell Empty)
Build an empty inline-assembly statement.
Definition Stmt.h:3475
IdentifierInfo * getLabelIdentifier(unsigned i) const
Definition Stmt.h:3609
const Expr * getInputConstraintExpr(unsigned i) const
Definition Stmt.h:3583
IdentifierInfo * getOutputIdentifier(unsigned i) const
Definition Stmt.h:3546
const Expr * getAsmStringExpr() const
Definition Stmt.h:3482
Expr * getOutputExpr(unsigned i)
Definition Stmt.cpp:582
llvm::iterator_range< const_labels_iterator > labels_const_range
Definition Stmt.h:3618
GCCAsmStmt(const ASTContext &C, SourceLocation asmloc, bool issimple, bool isvolatile, unsigned numoutputs, unsigned numinputs, IdentifierInfo **names, Expr **constraints, Expr **exprs, Expr *asmstr, unsigned numclobbers, Expr **clobbers, unsigned numlabels, SourceLocation rparenloc)
Definition Stmt.cpp:935
Expr * getOutputConstraintExpr(unsigned i)
Definition Stmt.h:3560
Expr * getClobberExpr(unsigned i)
Definition Stmt.h:3662
int getNamedOperand(StringRef SymbolicName) const
getNamedOperand - Given a symbolic operand reference like %[foo], translate this into a numeric value...
Definition Stmt.cpp:647
friend class ASTStmtReader
Definition Stmt.h:3456
const Expr * getOutputExpr(unsigned i) const
Definition Stmt.h:3564
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.h:3665
Expr * getInputExpr(unsigned i)
Definition Stmt.cpp:593
AddrLabelExpr * getLabelExpr(unsigned i) const
Definition Stmt.cpp:601
static std::string ExtractStringFromGCCAsmStmtComponent(const Expr *E)
Definition Stmt.cpp:554
GotoStmt(LabelDecl *label, SourceLocation GL, SourceLocation LL)
Definition Stmt.h:2983
SourceLocation getLabelLoc() const
Definition Stmt.h:2996
SourceLocation getGotoLoc() const
Definition Stmt.h:2994
child_range children()
Definition Stmt.h:3007
void setLabel(LabelDecl *D)
Definition Stmt.h:2992
GotoStmt(EmptyShell Empty)
Build an empty goto statement.
Definition Stmt.h:2989
void setLabelLoc(SourceLocation L)
Definition Stmt.h:2997
LabelDecl * getLabel() const
Definition Stmt.h:2991
SourceLocation getEndLoc() const
Definition Stmt.h:3000
const_child_range children() const
Definition Stmt.h:3011
static bool classof(const Stmt *T)
Definition Stmt.h:3002
void setGotoLoc(SourceLocation L)
Definition Stmt.h:2995
SourceLocation getBeginLoc() const
Definition Stmt.h:2999
One of these records is kept for each identifier that is lexed.
Stmt * getThen()
Definition Stmt.h:2357
bool hasElseStorage() const
True if this IfStmt has storage for an else statement.
Definition Stmt.h:2343
const Stmt * getElse() const
Definition Stmt.h:2371
void setThen(Stmt *Then)
Definition Stmt.h:2362
void setConditionVariableDeclStmt(DeclStmt *CondVar)
Definition Stmt.h:2413
void setCond(Expr *Cond)
Definition Stmt.h:2353
void setLParenLoc(SourceLocation Loc)
Definition Stmt.h:2487
SourceLocation getIfLoc() const
Definition Stmt.h:2434
void setConditionVariable(const ASTContext &Ctx, VarDecl *V)
Set the condition variable for this if statement.
Definition Stmt.cpp:1075
bool hasVarStorage() const
True if this IfStmt has storage for a variable declaration.
Definition Stmt.h:2340
const DeclStmt * getConditionVariableDeclStmt() const
Definition Stmt.h:2407
IfStatementKind getStatementKind() const
Definition Stmt.h:2469
SourceLocation getElseLoc() const
Definition Stmt.h:2437
Stmt * getInit()
Definition Stmt.h:2418
bool isNonNegatedConsteval() const
Definition Stmt.h:2453
SourceLocation getLParenLoc() const
Definition Stmt.h:2486
static bool classof(const Stmt *T)
Definition Stmt.h:2511
void setElse(Stmt *Else)
Definition Stmt.h:2376
Expr * getCond()
Definition Stmt.h:2345
const Stmt * getThen() const
Definition Stmt.h:2358
bool isConstexpr() const
Definition Stmt.h:2461
const Expr * getCond() const
Definition Stmt.h:2349
const VarDecl * getConditionVariable() const
Definition Stmt.h:2391
void setElseLoc(SourceLocation ElseLoc)
Definition Stmt.h:2442
const Stmt * getInit() const
Definition Stmt.h:2423
static IfStmt * CreateEmpty(const ASTContext &Ctx, bool HasElse, bool HasVar, bool HasInit)
Create an empty IfStmt optionally with storage for an else statement, condition variable and init exp...
Definition Stmt.cpp:1059
bool hasInitStorage() const
True if this IfStmt has the storage for an init statement.
Definition Stmt.h:2337
void setStatementKind(IfStatementKind Kind)
Definition Stmt.h:2465
std::optional< const Stmt * > getNondiscardedCase(const ASTContext &Ctx) const
If this is an 'if constexpr', determine which substatement will be taken.
Definition Stmt.cpp:1100
bool isObjCAvailabilityCheck() const
Definition Stmt.cpp:1089
child_range children()
Definition Stmt.h:2493
bool isNegatedConsteval() const
Definition Stmt.h:2457
Stmt * getElse()
Definition Stmt.h:2366
DeclStmt * getConditionVariableDeclStmt()
If this IfStmt has a condition variable, return the faux DeclStmt associated with the creation of tha...
Definition Stmt.h:2401
const_child_range children() const
Definition Stmt.h:2502
SourceLocation getRParenLoc() const
Definition Stmt.h:2488
void setRParenLoc(SourceLocation Loc)
Definition Stmt.h:2489
SourceLocation getBeginLoc() const
Definition Stmt.h:2480
SourceLocation getEndLoc() const LLVM_READONLY
Definition Stmt.h:2481
bool isConsteval() const
Definition Stmt.h:2448
void setIfLoc(SourceLocation IfLoc)
Definition Stmt.h:2435
VarDecl * getConditionVariable()
Retrieve the variable declared in this "if" statement, if any.
Definition Stmt.cpp:1068
void setInit(Stmt *Init)
Definition Stmt.h:2428
SourceLocation getEndLoc() const LLVM_READONLY
Definition Stmt.h:3051
static bool classof(const Stmt *T)
Definition Stmt.h:3053
LabelDecl * getConstantTarget()
getConstantTarget - Returns the fixed target of this indirect goto, if one exists.
Definition Stmt.cpp:1269
IndirectGotoStmt(SourceLocation gotoLoc, SourceLocation starLoc, Expr *target)
Definition Stmt.h:3022
void setTarget(Expr *E)
Definition Stmt.h:3041
SourceLocation getGotoLoc() const
Definition Stmt.h:3033
SourceLocation getBeginLoc() const
Definition Stmt.h:3050
child_range children()
Definition Stmt.h:3058
void setGotoLoc(SourceLocation L)
Definition Stmt.h:3032
const_child_range children() const
Definition Stmt.h:3060
const LabelDecl * getConstantTarget() const
Definition Stmt.h:3046
void setStarLoc(SourceLocation L)
Definition Stmt.h:3034
IndirectGotoStmt(EmptyShell Empty)
Build an empty indirect goto statement.
Definition Stmt.h:3029
const Expr * getTarget() const
Definition Stmt.h:3038
SourceLocation getStarLoc() const
Definition Stmt.h:3035
Represents the declaration of a label.
Definition Decl.h:524
Stmt * getInnermostLabeledStmt()
Definition Stmt.h:2188
LabelStmt(SourceLocation IL, LabelDecl *D, Stmt *substmt)
Build a label statement.
Definition Stmt.h:2162
static bool classof(const Stmt *T)
Definition Stmt.h:2199
LabelDecl * getDecl() const
Definition Stmt.h:2173
LabelStmt(EmptyShell Empty)
Build an empty label statement.
Definition Stmt.h:2168
bool isSideEntry() const
Definition Stmt.h:2202
Stmt * getSubStmt()
Definition Stmt.h:2177
SourceLocation getIdentLoc() const
Definition Stmt.h:2170
void setSubStmt(Stmt *SS)
Definition Stmt.h:2180
void setDecl(LabelDecl *D)
Definition Stmt.h:2174
SourceLocation getBeginLoc() const
Definition Stmt.h:2182
void setIdentLoc(SourceLocation L)
Definition Stmt.h:2171
const_child_range children() const
Definition Stmt.h:2195
const Stmt * getInnermostLabeledStmt() const
Look through nested labels and return the first non-label statement; e.g.
Definition Stmt.cpp:1528
SourceLocation getEndLoc() const LLVM_READONLY
Definition Stmt.h:2183
child_range children()
Definition Stmt.h:2193
void setSideEntry(bool SE)
Definition Stmt.h:2203
const char * getName() const
Definition Stmt.cpp:437
const Stmt * getSubStmt() const
Definition Stmt.h:2179
SourceLocation getBeginLoc() const
Definition Stmt.h:3094
LoopControlStmt(StmtClass Class, SourceLocation Loc)
Definition Stmt.h:3085
LoopControlStmt(StmtClass Class, EmptyShell ES)
Definition Stmt.h:3088
void setLabelDecl(LabelDecl *S)
Definition Stmt.h:3106
LoopControlStmt(StmtClass Class, SourceLocation Loc, SourceLocation LabelLoc, LabelDecl *Target)
Definition Stmt.h:3079
static bool classof(const Stmt *T)
Definition Stmt.h:3121
SourceLocation getLabelLoc() const
Definition Stmt.h:3101
LabelDecl * getLabelDecl()
Definition Stmt.h:3104
const LabelDecl * getLabelDecl() const
Definition Stmt.h:3105
void setLabelLoc(SourceLocation L)
Definition Stmt.h:3102
const_child_range children() const
Definition Stmt.h:3117
SourceLocation getKwLoc() const
Definition Stmt.h:3091
child_range children()
Definition Stmt.h:3113
void setKwLoc(SourceLocation L)
Definition Stmt.h:3092
const Stmt * getNamedLoopOrSwitch() const
If this is a named break/continue, get the loop or switch statement that this targets.
Definition Stmt.cpp:1535
bool hasLabelTarget() const
Definition Stmt.h:3099
SourceLocation getEndLoc() const
Definition Stmt.h:3095
Token * getAsmToks()
Definition Stmt.h:3705
const Expr * getOutputExpr(unsigned i) const
Definition Stmt.h:3722
Expr * getOutputExpr(unsigned i)
Definition Stmt.cpp:919
ArrayRef< StringRef > getClobbers() const
Definition Stmt.h:3746
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.h:3760
StringRef getAsmString() const
Definition Stmt.h:3708
child_range children()
Definition Stmt.h:3766
SourceLocation getLBraceLoc() const
Definition Stmt.h:3697
bool hasBraces() const
Definition Stmt.h:3702
SourceLocation getEndLoc() const
Definition Stmt.h:3699
StringRef getInputConstraint(unsigned i) const
Definition Stmt.h:3728
void setEndLoc(SourceLocation L)
Definition Stmt.h:3700
void setInputExpr(unsigned i, Expr *E)
Definition Stmt.cpp:927
StringRef getOutputConstraint(unsigned i) const
Definition Stmt.h:3715
ArrayRef< StringRef > getAllConstraints() const
Definition Stmt.h:3742
static bool classof(const Stmt *T)
Definition Stmt.h:3762
friend class ASTStmtReader
Definition Stmt.h:3675
StringRef getClobber(unsigned i) const
Definition Stmt.h:3752
const Expr * getInputExpr(unsigned i) const
Definition Stmt.h:3736
MSAsmStmt(const ASTContext &C, SourceLocation asmloc, SourceLocation lbraceloc, bool issimple, bool isvolatile, ArrayRef< Token > asmtoks, unsigned numoutputs, unsigned numinputs, ArrayRef< StringRef > constraints, ArrayRef< Expr * > exprs, StringRef asmstr, ArrayRef< StringRef > clobbers, SourceLocation endloc)
Definition Stmt.cpp:960
unsigned getNumAsmToks()
Definition Stmt.h:3704
void setLBraceLoc(SourceLocation L)
Definition Stmt.h:3698
MSAsmStmt(EmptyShell Empty)
Build an empty MS-style inline-assembly statement.
Definition Stmt.h:3695
std::string generateAsmString(const ASTContext &C) const
Assemble final IR asm string.
Definition Stmt.cpp:893
const_child_range children() const
Definition Stmt.h:3770
ArrayRef< Expr * > getAllExprs() const
Definition Stmt.h:3748
Expr * getInputExpr(unsigned i)
Definition Stmt.cpp:923
void setSemiLoc(SourceLocation L)
Definition Stmt.h:1724
bool hasLeadingEmptyMacro() const
Definition Stmt.h:1726
SourceLocation getBeginLoc() const
Definition Stmt.h:1730
child_range children()
Definition Stmt.h:1737
SourceLocation getSemiLoc() const
Definition Stmt.h:1723
static bool classof(const Stmt *T)
Definition Stmt.h:1733
NullStmt(SourceLocation L, bool hasLeadingEmptyMacro=false)
Definition Stmt.h:1714
NullStmt(EmptyShell Empty)
Build an empty null statement.
Definition Stmt.h:1721
const_child_range children() const
Definition Stmt.h:1741
SourceLocation getEndLoc() const
Definition Stmt.h:1731
Represents a struct/union/class.
Definition Decl.h:4369
void setRetValue(Expr *E)
Definition Stmt.h:3198
void setReturnLoc(SourceLocation L)
Definition Stmt.h:3219
SourceLocation getReturnLoc() const
Definition Stmt.h:3218
static bool classof(const Stmt *T)
Definition Stmt.h:3226
SourceLocation getEndLoc() const LLVM_READONLY
Definition Stmt.h:3222
void setNRVOCandidate(const VarDecl *Var)
Set the variable that might be used for the named return value optimization.
Definition Stmt.h:3212
SourceLocation getBeginLoc() const
Definition Stmt.h:3221
const VarDecl * getNRVOCandidate() const
Retrieve the variable that might be used for the named return value optimization.
Definition Stmt.h:3205
const_child_range children() const
Definition Stmt.h:3237
Expr * getRetValue()
Definition Stmt.h:3196
static ReturnStmt * CreateEmpty(const ASTContext &Ctx, bool HasNRVOCandidate)
Create an empty return statement, optionally with storage for an NRVO candidate.
Definition Stmt.cpp:1298
child_range children()
Definition Stmt.h:3231
const Expr * getRetValue() const
Definition Stmt.h:3197
const_child_range children() const
Definition Stmt.h:3810
child_range children()
Definition Stmt.h:3806
CompoundStmt * getBlock() const
Definition Stmt.h:3802
friend class ASTReader
Definition Stmt.h:3776
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.h:3793
SourceLocation getExceptLoc() const
Definition Stmt.h:3795
friend class ASTStmtReader
Definition Stmt.h:3777
SourceLocation getEndLoc() const
Definition Stmt.h:3796
static bool classof(const Stmt *T)
Definition Stmt.h:3814
Expr * getFilterExpr() const
Definition Stmt.h:3798
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.h:3834
SourceLocation getEndLoc() const
Definition Stmt.h:3837
const_child_range children() const
Definition Stmt.h:3845
child_range children()
Definition Stmt.h:3841
friend class ASTReader
Definition Stmt.h:3820
SourceLocation getFinallyLoc() const
Definition Stmt.h:3836
static bool classof(const Stmt *T)
Definition Stmt.h:3849
friend class ASTStmtReader
Definition Stmt.h:3821
CompoundStmt * getBlock() const
Definition Stmt.h:3839
SourceLocation getLeaveLoc() const
Definition Stmt.h:3917
child_range children()
Definition Stmt.h:3928
SourceLocation getEndLoc() const LLVM_READONLY
Definition Stmt.h:3921
SEHLeaveStmt(EmptyShell Empty)
Build an empty __leave statement.
Definition Stmt.h:3915
SEHLeaveStmt(SourceLocation LL)
Definition Stmt.h:3911
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.h:3920
static bool classof(const Stmt *T)
Definition Stmt.h:3923
void setLeaveLoc(SourceLocation L)
Definition Stmt.h:3918
const_child_range children() const
Definition Stmt.h:3932
child_range children()
Definition Stmt.h:3893
const_child_range children() const
Definition Stmt.h:3897
CompoundStmt * getTryBlock() const
Definition Stmt.h:3883
static bool classof(const Stmt *T)
Definition Stmt.h:3901
SourceLocation getTryLoc() const
Definition Stmt.h:3878
bool getIsCXXTry() const
Definition Stmt.h:3881
SEHFinallyStmt * getFinallyHandler() const
Definition Stmt.cpp:1343
friend class ASTReader
Definition Stmt.h:3855
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.h:3876
friend class ASTStmtReader
Definition Stmt.h:3856
SourceLocation getEndLoc() const
Definition Stmt.h:3879
SEHExceptStmt * getExceptHandler() const
Returns 0 if not defined.
Definition Stmt.cpp:1339
Stmt * getHandler() const
Definition Stmt.h:3887
Encodes a location in the source.
This class handles loading and caching of source files into memory.
A trivial tuple used to represent a source range.
friend class ImplicitCastExpr
Definition Stmt.h:629
friend class BlockDeclRefExpr
Definition Stmt.h:335
friend class ParenListExpr
Definition Stmt.h:352
friend class DesignatedInitExpr
Definition Stmt.h:343
friend class PseudoObjectExpr
Definition Stmt.h:353
friend class ObjCMessageExpr
Definition Stmt.h:348
friend class ObjCDictionaryLiteral
Definition Stmt.h:347
friend class ObjCArrayLiteral
Definition Stmt.h:346
friend class DeclRefExpr
Definition Stmt.h:341
friend class CXXDependentScopeMemberExpr
Definition Stmt.h:338
friend class CXXConstructExpr
Definition Stmt.h:337
friend class OpaqueValueExpr
Definition Stmt.h:350
friend class DependentScopeDeclRefExpr
Definition Stmt.h:342
friend class AtomicExpr
Definition Stmt.h:334
friend class Expr
Definition Stmt.h:344
friend class CallExpr
Definition Stmt.h:336
friend class CXXUnresolvedConstructExpr
Definition Stmt.h:340
friend class InitListExpr
Definition Stmt.h:345
friend class CXXNewExpr
Definition Stmt.h:339
friend class ASTStmtReader
Definition Stmt.h:333
friend class OverloadExpr
Definition Stmt.h:351
friend class OffsetOfExpr
Definition Stmt.h:349
friend class ShuffleVectorExpr
Definition Stmt.h:354
friend class IndirectGotoStmt
Definition Stmt.h:271
friend class ASTStmtReader
Definition Stmt.h:184
friend class ASTStmtWriter
Definition Stmt.h:127
friend class ASTStmtReader
Definition Stmt.h:126
friend class Stmt
Definition Stmt.h:118
friend class ASTStmtWriter
Definition Stmt.h:117
friend class ASTStmtReader
Definition Stmt.h:116
friend class ASTStmtReader
Definition Stmt.h:755
Stmt - This represents one statement.
Definition Stmt.h:85
ExpressionTraitExprBitfields ExpressionTraitExprBits
Definition Stmt.h:1404
LoopControlStmtBitfields LoopControlStmtBits
Definition Stmt.h:1346
SourceLocation getEndLoc() const LLVM_READONLY
Definition Stmt.cpp:367
void ProcessODRHash(llvm::FoldingSetNodeID &ID, ODRHash &Hash) const
Calculate a unique representation for a statement that is stable across compiler invocations.
@ NoStmtClass
Definition Stmt.h:88
Stmt(const Stmt &)=delete
UnaryExprOrTypeTraitExprBitfields UnaryExprOrTypeTraitExprBits
Definition Stmt.h:1360
CXXUnresolvedConstructExprBitfields CXXUnresolvedConstructExprBits
Definition Stmt.h:1394
WhileStmtBitfields WhileStmtBits
Definition Stmt.h:1342
SwitchCaseBitfields SwitchCaseBits
Definition Stmt.h:1348
GenericSelectionExprBitfields GenericSelectionExprBits
Definition Stmt.h:1368
ObjCObjectLiteralBitfields ObjCObjectLiteralBits
Definition Stmt.h:1412
InitListExprBitfields InitListExprBits
Definition Stmt.h:1366
static void EnableStatistics()
Definition Stmt.cpp:144
LambdaExprBitfields LambdaExprBits
Definition Stmt.h:1401
AttributedStmtBitfields AttributedStmtBits
Definition Stmt.h:1339
Stmt(StmtClass SC)
Definition Stmt.h:1493
ParenListExprBitfields ParenListExprBits
Definition Stmt.h:1367
ArrayOrMatrixSubscriptExprBitfields ArrayOrMatrixSubscriptExprBits
Definition Stmt.h:1361
UnresolvedLookupExprBitfields UnresolvedLookupExprBits
Definition Stmt.h:1397
SwitchStmtBitfields SwitchStmtBits
Definition Stmt.h:1341
SubstNonTypeTemplateParmExprBitfields SubstNonTypeTemplateParmExprBits
Definition Stmt.h:1400
CXXNoexceptExprBitfields CXXNoexceptExprBits
Definition Stmt.h:1399
ParenExprBitfields ParenExprBits
Definition Stmt.h:1371
StmtIterator child_iterator
Child Iterators: All subclasses must implement 'children' to permit easy iteration over the substatem...
Definition Stmt.h:1588
CXXRewrittenBinaryOperatorBitfields CXXRewrittenBinaryOperatorBits
Definition Stmt.h:1380
CallExprBitfields CallExprBits
Definition Stmt.h:1362
Stmt * stripLabelLikeStatements()
Definition Stmt.h:1580
void printPretty(raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, StringRef NewlineSymbol="\n", const ASTContext *Context=nullptr) const
CastIterator< T, const T *const, const Stmt *const > ConstCastIterator
Const iterator for iterating over Stmt * arrays that contain only T *.
Definition Stmt.h:1473
const Stmt * stripLabelLikeStatements() const
Strip off all label-like statements.
Definition Stmt.cpp:232
child_range children()
Definition Stmt.cpp:304
ShuffleVectorExprBitfields ShuffleVectorExprBits
Definition Stmt.h:1372
ExprWithCleanupsBitfields ExprWithCleanupsBits
Definition Stmt.h:1393
FloatingLiteralBitfields FloatingLiteralBits
Definition Stmt.h:1356
const_child_range children() const
Definition Stmt.h:1596
child_iterator child_begin()
Definition Stmt.h:1600
void printJson(raw_ostream &Out, PrinterHelper *Helper, const PrintingPolicy &Policy, bool AddQuotes) const
Pretty-prints in JSON format.
StmtClass getStmtClass() const
Definition Stmt.h:1502
CXXScalarValueInitExprBitfields CXXScalarValueInitExprBits
Definition Stmt.h:1387
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition Stmt.cpp:343
CharacterLiteralBitfields CharacterLiteralBits
Definition Stmt.h:1358
OverloadExprBitfields OverloadExprBits
Definition Stmt.h:1396
CXXConstructExprBitfields CXXConstructExprBits
Definition Stmt.h:1392
void printPrettyControlled(raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, StringRef NewlineSymbol="\n", const ASTContext *Context=nullptr) const
UnaryOperatorBitfields UnaryOperatorBits
Definition Stmt.h:1359
static std::tuple< bool, const Attr *, const Attr * > determineLikelihoodConflict(const Stmt *Then, const Stmt *Else)
Definition Stmt.cpp:198
CXXDependentScopeMemberExprBitfields CXXDependentScopeMemberExprBits
Definition Stmt.h:1395
static void PrintStats()
Definition Stmt.cpp:108
GotoStmtBitfields GotoStmtBits
Definition Stmt.h:1345
child_iterator child_end()
Definition Stmt.h:1601
ConstCastIterator< Expr > ConstExprIterator
Definition Stmt.h:1476
TypeTraitExprBitfields TypeTraitExprBits
Definition Stmt.h:1390
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, bool Canonical, bool ProfileLambdaExpr=false) const
Produce a unique representation of the given statement.
CXXNewExprBitfields CXXNewExprBits
Definition Stmt.h:1388
SourceLocExprBitfields SourceLocExprBits
Definition Stmt.h:1370
CXXNullPtrLiteralExprBitfields CXXNullPtrLiteralExprBits
Definition Stmt.h:1382
CoawaitExprBitfields CoawaitBits
Definition Stmt.h:1409
Stmt(StmtClass SC, EmptyShell)
Construct an empty statement.
Definition Stmt.h:1484
ChooseExprBitfields ChooseExprBits
Definition Stmt.h:1376
ConstantExprBitfields ConstantExprBits
Definition Stmt.h:1353
llvm::iterator_range< child_iterator > child_range
Definition Stmt.h:1591
DeferStmtBitfields DeferStmtBits
Definition Stmt.h:1349
CompoundStmtBitfields CompoundStmtBits
Definition Stmt.h:1337
RequiresExprBitfields RequiresExprBits
Definition Stmt.h:1402
CXXFoldExprBitfields CXXFoldExprBits
Definition Stmt.h:1405
StmtExprBitfields StmtExprBits
Definition Stmt.h:1375
StringLiteralBitfields StringLiteralBits
Definition Stmt.h:1357
OpaqueValueExprBitfields OpaqueValueExprBits
Definition Stmt.h:1416
CastExprBitfields CastExprBits
Definition Stmt.h:1364
Likelihood
The likelihood of a branch being taken.
Definition Stmt.h:1445
@ LH_Unlikely
Branch has the [[unlikely]] attribute.
Definition Stmt.h:1446
@ LH_None
No attribute set or branches of the IfStmt have the same attribute.
Definition Stmt.h:1447
@ LH_Likely
Branch has the [[likely]] attribute.
Definition Stmt.h:1449
CXXThrowExprBitfields CXXThrowExprBits
Definition Stmt.h:1384
static void addStmtClass(const StmtClass s)
Definition Stmt.cpp:139
MemberExprBitfields MemberExprBits
Definition Stmt.h:1363
PackIndexingExprBitfields PackIndexingExprBits
Definition Stmt.h:1406
friend class ASTStmtWriter
Definition Stmt.h:101
ForStmtBitfields ForStmtBits
Definition Stmt.h:1344
@ NumOverloadExprBits
Definition Stmt.h:1119
DeclRefExprBitfields DeclRefExprBits
Definition Stmt.h:1355
const_child_iterator child_end() const
Definition Stmt.h:1604
const char * getStmtClassName() const
Definition Stmt.cpp:86
ConstStmtIterator const_child_iterator
Definition Stmt.h:1589
void dumpPretty(const ASTContext &Context) const
dumpPretty/printPretty - These two methods do a "pretty print" of the AST back to its original source...
CXXBoolLiteralExprBitfields CXXBoolLiteralExprBits
Definition Stmt.h:1381
CXXOperatorCallExprBitfields CXXOperatorCallExprBits
Definition Stmt.h:1379
Stmt(Stmt &&)=delete
CXXDefaultInitExprBitfields CXXDefaultInitExprBits
Definition Stmt.h:1386
Stmt & operator=(const Stmt &)=delete
NullStmtBitfields NullStmtBits
Definition Stmt.h:1336
static const Attr * getLikelihoodAttr(const Stmt *S)
Definition Stmt.cpp:176
Stmt * IgnoreContainers(bool IgnoreCaptured=false)
Skip no-op (attributed, compound) container stmts and skip captured stmt at the top,...
Definition Stmt.cpp:210
DependentScopeDeclRefExprBitfields DependentScopeDeclRefExprBits
Definition Stmt.h:1391
friend class ASTStmtReader
Definition Stmt.h:100
ArrayTypeTraitExprBitfields ArrayTypeTraitExprBits
Definition Stmt.h:1403
StmtBitfields StmtBits
Definition Stmt.h:1335
IfStmtBitfields IfStmtBits
Definition Stmt.h:1340
Stmt & operator=(Stmt &&)=delete
PredefinedExprBitfields PredefinedExprBits
Definition Stmt.h:1354
ConvertVectorExprBitfields ConvertVectorExprBits
Definition Stmt.h:1417
@ NumExprBits
Definition Stmt.h:366
int64_t getID(const ASTContext &Context) const
Definition Stmt.cpp:379
ReturnStmtBitfields ReturnStmtBits
Definition Stmt.h:1347
LabelStmtBitfields LabelStmtBits
Definition Stmt.h:1338
ObjCIndirectCopyRestoreExprBitfields ObjCIndirectCopyRestoreExprBits
Definition Stmt.h:1413
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.cpp:355
void dumpColor() const
dumpColor - same as dump(), but forces color highlighting.
BinaryOperatorBitfields BinaryOperatorBits
Definition Stmt.h:1365
Stmt()=delete
UnresolvedMemberExprBitfields UnresolvedMemberExprBits
Definition Stmt.h:1398
PseudoObjectExprBitfields PseudoObjectExprBits
Definition Stmt.h:1369
ExprBitfields ExprBits
Definition Stmt.h:1352
void viewAST() const
viewAST - Visualize an AST rooted at this Stmt* using GraphViz.
Definition StmtViz.cpp:20
llvm::iterator_range< const_child_iterator > const_child_range
Definition Stmt.h:1592
const_child_iterator child_begin() const
Definition Stmt.h:1603
CXXDeleteExprBitfields CXXDeleteExprBits
Definition Stmt.h:1389
CXXDefaultArgExprBitfields CXXDefaultArgExprBits
Definition Stmt.h:1385
DoStmtBitfields DoStmtBits
Definition Stmt.h:1343
@ NumCallExprBits
Definition Stmt.h:582
CXXThisExprBitfields CXXThisExprBits
Definition Stmt.h:1383
CastIterator< Expr > ExprIterator
Definition Stmt.h:1475
StringLiteral - This represents a string literal expression, e.g.
Definition Expr.h:1805
SwitchCase * NextSwitchCase
A pointer to the following CaseStmt or DefaultStmt class, used by SwitchStmt.
Definition Stmt.h:1892
void setColonLoc(SourceLocation L)
Definition Stmt.h:1909
static bool classof(const Stmt *T)
Definition Stmt.h:1919
SwitchCase(StmtClass SC, EmptyShell)
Definition Stmt.h:1899
SourceLocation getKeywordLoc() const
Definition Stmt.h:1906
Stmt * getSubStmt()
Definition Stmt.h:2122
SwitchCase(StmtClass SC, SourceLocation KWLoc, SourceLocation ColonLoc)
Definition Stmt.h:1894
void setKeywordLoc(SourceLocation L)
Definition Stmt.h:1907
const Stmt * getSubStmt() const
Definition Stmt.h:1912
void setNextSwitchCase(SwitchCase *SC)
Definition Stmt.h:1904
SourceLocation getColonLoc() const
Definition Stmt.h:1908
SourceLocation getBeginLoc() const
Definition Stmt.h:1916
const SwitchCase * getNextSwitchCase() const
Definition Stmt.h:1902
SourceLocation ColonLoc
The location of the ":".
Definition Stmt.h:1885
SourceLocation getEndLoc() const LLVM_READONLY
Definition Stmt.h:2114
SwitchCase * getNextSwitchCase()
Definition Stmt.h:1903
void setCond(Expr *Cond)
Definition Stmt.h:2589
const Stmt * getInit() const
Definition Stmt.h:2602
SourceLocation getSwitchLoc() const
Definition Stmt.h:2653
void addSwitchCase(SwitchCase *SC)
Definition Stmt.h:2665
void setBody(Stmt *S, SourceLocation SL)
Definition Stmt.h:2660
SourceLocation getLParenLoc() const
Definition Stmt.h:2655
const Expr * getCond() const
Definition Stmt.h:2585
bool isAllEnumCasesCovered() const
Returns true if the SwitchStmt is a switch of an enum value and all cases have been explicitly covere...
Definition Stmt.h:2678
void setSwitchLoc(SourceLocation L)
Definition Stmt.h:2654
void setConditionVariableDeclStmt(DeclStmt *CondVar)
Definition Stmt.h:2644
void setBody(Stmt *Body)
Definition Stmt.h:2596
void setRParenLoc(SourceLocation Loc)
Definition Stmt.h:2658
SourceLocation getEndLoc() const LLVM_READONLY
Definition Stmt.h:2683
SourceLocation getRParenLoc() const
Definition Stmt.h:2657
void setInit(Stmt *Init)
Definition Stmt.h:2606
void setConditionVariable(const ASTContext &Ctx, VarDecl *VD)
Set the condition variable in this switch statement.
Definition Stmt.cpp:1193
void setLParenLoc(SourceLocation Loc)
Definition Stmt.h:2656
child_range children()
Definition Stmt.h:2689
const Stmt * getBody() const
Definition Stmt.h:2594
const VarDecl * getConditionVariable() const
Definition Stmt.h:2622
static SwitchStmt * CreateEmpty(const ASTContext &Ctx, bool HasInit, bool HasVar)
Create an empty switch statement optionally with storage for an init expression and a condition varia...
Definition Stmt.cpp:1178
const DeclStmt * getConditionVariableDeclStmt() const
Definition Stmt.h:2638
Expr * getCond()
Definition Stmt.h:2581
bool hasVarStorage() const
True if this SwitchStmt has storage for a condition variable.
Definition Stmt.h:2579
Stmt * getBody()
Definition Stmt.h:2593
const_child_range children() const
Definition Stmt.h:2694
VarDecl * getConditionVariable()
Retrieve the variable declared in this "switch" statement, if any.
Definition Stmt.cpp:1186
Stmt * getInit()
Definition Stmt.h:2598
SourceLocation getBeginLoc() const
Definition Stmt.h:2682
bool hasInitStorage() const
True if this SwitchStmt has storage for an init statement.
Definition Stmt.h:2576
SwitchCase * getSwitchCaseList()
Definition Stmt.h:2649
const SwitchCase * getSwitchCaseList() const
Definition Stmt.h:2650
DeclStmt * getConditionVariableDeclStmt()
If this SwitchStmt has a condition variable, return the faux DeclStmt associated with the creation of...
Definition Stmt.h:2632
void setAllEnumCasesCovered()
Set a flag in the SwitchStmt indicating that if the 'switch (X)' is a switch over an enum value then ...
Definition Stmt.h:2674
void setSwitchCaseList(SwitchCase *SC)
Definition Stmt.h:2651
static bool classof(const Stmt *T)
Definition Stmt.h:2699
Exposes information about the current target.
Definition TargetInfo.h:227
Token - This structure provides full information about a lexed token.
Definition Token.h:36
Represents a statement that could possibly have a value and type.
Definition Stmt.h:2136
const Expr * getExprStmt() const
Definition Stmt.cpp:420
Stmt(StmtClass SC, EmptyShell)
Construct an empty statement.
Definition Stmt.h:1484
static bool classof(const Stmt *T)
Definition Stmt.h:2147
Expr * getExprStmt()
Definition Stmt.h:2142
Represents a variable declaration or definition.
Definition Decl.h:932
Expr * getCond()
Definition Stmt.h:2758
SourceLocation getWhileLoc() const
Definition Stmt.h:2811
void setCond(Expr *Cond)
Definition Stmt.h:2766
SourceLocation getRParenLoc() const
Definition Stmt.h:2816
DeclStmt * getConditionVariableDeclStmt()
If this WhileStmt has a condition variable, return the faux DeclStmt associated with the creation of ...
Definition Stmt.h:2794
void setBody(Stmt *Body)
Definition Stmt.h:2773
void setLParenLoc(SourceLocation L)
Definition Stmt.h:2815
VarDecl * getConditionVariable()
Retrieve the variable declared in this "while" statement, if any.
Definition Stmt.cpp:1247
SourceLocation getEndLoc() const LLVM_READONLY
Definition Stmt.h:2820
void setConditionVariable(const ASTContext &Ctx, VarDecl *V)
Set the condition variable of this while statement.
Definition Stmt.cpp:1254
bool hasVarStorage() const
True if this WhileStmt has storage for a condition variable.
Definition Stmt.h:2756
SourceLocation getLParenLoc() const
Definition Stmt.h:2814
SourceLocation getBeginLoc() const
Definition Stmt.h:2819
const Stmt * getBody() const
Definition Stmt.h:2771
void setRParenLoc(SourceLocation L)
Definition Stmt.h:2817
const VarDecl * getConditionVariable() const
Definition Stmt.h:2784
void setWhileLoc(SourceLocation L)
Definition Stmt.h:2812
const Expr * getCond() const
Definition Stmt.h:2762
static WhileStmt * CreateEmpty(const ASTContext &Ctx, bool HasVar)
Create an empty while statement optionally with storage for a condition variable.
Definition Stmt.cpp:1240
const DeclStmt * getConditionVariableDeclStmt() const
Definition Stmt.h:2800
void setConditionVariableDeclStmt(DeclStmt *CondVar)
Definition Stmt.h:2806
static bool classof(const Stmt *T)
Definition Stmt.h:2824
const_child_range children() const
Definition Stmt.h:2834
child_range children()
Definition Stmt.h:2829
Stmt * getBody()
Definition Stmt.h:2770
Definition SPIR.cpp:35
The JSON file list parser is used to communicate input to InstallAPI.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
ConstantResultStorageKind
Describes the kind of result that can be tail-allocated.
Definition Expr.h:1082
ExprDependenceScope::ExprDependence ExprDependence
IfStatementKind
In an if statement, this denotes whether the statement is a constexpr or consteval if statement.
Definition Specifiers.h:40
CXXConstructionKind
Definition ExprCXX.h:1543
ExprObjectKind
A further classification of the kind of object referenced by an l-value or x-value.
Definition Specifiers.h:150
@ Create
'create' clause, allowed on Compute and Combined constructs, plus 'data', 'enter data',...
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
CapturedRegionKind
The different kinds of captured statement.
Expr * Cond
};
const FunctionProtoType * T
CastKind
CastKind - The kind of operation required for a conversion.
LambdaCaptureDefault
The default, if any, capture method for a lambda expression.
Definition Lambda.h:22
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
Definition Specifiers.h:133
StringLiteralKind
Definition Expr.h:1769
U cast(CodeGen::Address addr)
Definition Address.h:327
SourceLocIdentKind
Definition Expr.h:5019
@ Class
The "class" keyword introduces the elaborated-type-specifier.
Definition TypeBase.h:6016
CXXNewInitializationStyle
Definition ExprCXX.h:2243
PredefinedIdentKind
Definition Expr.h:1995
CharacterLiteralKind
Definition Expr.h:1609
Diagnostic wrappers for TextAPI types for error reporting.
Definition Dominators.h:30
#define false
Definition stdbool.h:26
Describes how types, statements, expressions, and declarations should be printed.
Iterator for iterating over Stmt * arrays that contain only T *.
Definition Stmt.h:1460
typename CastIterator::iterator_adaptor_base Base
Definition Stmt.h:1461
CastIterator(StmtPtr *I)
Definition Stmt.h:1464
Base::value_type operator*() const
Definition Stmt.h:1466
A placeholder type used to construct an empty shell of a type, that will be filled in later (e....
Definition Stmt.h:1442