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 LLVM_PREFERRED_TYPE(bool)
1000 unsigned IsComparisonResult : 1;
1001
1002 /// If this expression is a non value-dependent boolean trait,
1003 /// this indicates whether the trait evaluated true or false.
1004 LLVM_PREFERRED_TYPE(bool)
1005 unsigned Value : 1;
1006 /// The number of arguments to this type trait. According to [implimits]
1007 /// 8 bits would be enough, but we require (and test for) at least 16 bits
1008 /// to mirror FunctionType.
1009 unsigned NumArgs;
1010 };
1011
1013 friend class ASTStmtReader;
1014 friend class ASTStmtWriter;
1016
1017 LLVM_PREFERRED_TYPE(ExprBitfields)
1019
1020 /// Whether the name includes info for explicit template
1021 /// keyword and arguments.
1022 LLVM_PREFERRED_TYPE(bool)
1023 unsigned HasTemplateKWAndArgsInfo : 1;
1024 };
1025
1027 friend class ASTStmtReader;
1028 friend class CXXConstructExpr;
1029
1030 LLVM_PREFERRED_TYPE(ExprBitfields)
1032
1033 LLVM_PREFERRED_TYPE(bool)
1034 unsigned Elidable : 1;
1035 LLVM_PREFERRED_TYPE(bool)
1036 unsigned HadMultipleCandidates : 1;
1037 LLVM_PREFERRED_TYPE(bool)
1038 unsigned ListInitialization : 1;
1039 LLVM_PREFERRED_TYPE(bool)
1040 unsigned StdInitListInitialization : 1;
1041 LLVM_PREFERRED_TYPE(bool)
1042 unsigned ZeroInitialization : 1;
1043 LLVM_PREFERRED_TYPE(CXXConstructionKind)
1044 unsigned ConstructionKind : 3;
1045 LLVM_PREFERRED_TYPE(bool)
1046 unsigned IsImmediateEscalating : 1;
1047
1048 SourceLocation Loc;
1049 };
1050
1052 friend class ASTStmtReader; // deserialization
1053 friend class ExprWithCleanups;
1054
1055 LLVM_PREFERRED_TYPE(ExprBitfields)
1057
1058 // When false, it must not have side effects.
1059 LLVM_PREFERRED_TYPE(bool)
1060 unsigned CleanupsHaveSideEffects : 1;
1061
1062 unsigned NumObjects : 32 - 1 - NumExprBits;
1063 };
1064
1066 friend class ASTStmtReader;
1068
1069 LLVM_PREFERRED_TYPE(ExprBitfields)
1071
1072 /// The number of arguments used to construct the type.
1073 unsigned NumArgs;
1074 };
1075
1077 friend class ASTStmtReader;
1079
1080 LLVM_PREFERRED_TYPE(ExprBitfields)
1082
1083 /// Whether this member expression used the '->' operator or
1084 /// the '.' operator.
1085 LLVM_PREFERRED_TYPE(bool)
1086 unsigned IsArrow : 1;
1087
1088 /// Whether this member expression has info for explicit template
1089 /// keyword and arguments.
1090 LLVM_PREFERRED_TYPE(bool)
1091 unsigned HasTemplateKWAndArgsInfo : 1;
1092
1093 /// See getFirstQualifierFoundInScope() and the comment listing
1094 /// the trailing objects.
1095 LLVM_PREFERRED_TYPE(bool)
1096 unsigned HasFirstQualifierFoundInScope : 1;
1097
1098 /// The location of the '->' or '.' operator.
1099 SourceLocation OperatorLoc;
1100 };
1101
1103 friend class ASTStmtReader;
1104 friend class OverloadExpr;
1105
1106 LLVM_PREFERRED_TYPE(ExprBitfields)
1108
1109 /// Whether the name includes info for explicit template
1110 /// keyword and arguments.
1111 LLVM_PREFERRED_TYPE(bool)
1112 unsigned HasTemplateKWAndArgsInfo : 1;
1113
1114 /// Padding used by the derived classes to store various bits. If you
1115 /// need to add some data here, shrink this padding and add your data
1116 /// above. NumOverloadExprBits also needs to be updated.
1117 unsigned : 32 - NumExprBits - 1;
1118
1119 /// The number of results.
1120 unsigned NumResults;
1121 };
1123
1125 friend class ASTStmtReader;
1127
1128 LLVM_PREFERRED_TYPE(OverloadExprBitfields)
1130
1131 /// True if these lookup results should be extended by
1132 /// argument-dependent lookup if this is the operand of a function call.
1133 LLVM_PREFERRED_TYPE(bool)
1134 unsigned RequiresADL : 1;
1135 };
1136 static_assert(sizeof(UnresolvedLookupExprBitfields) <= 4,
1137 "UnresolvedLookupExprBitfields must be <= than 4 bytes to"
1138 "avoid trashing OverloadExprBitfields::NumResults!");
1139
1141 friend class ASTStmtReader;
1143
1144 LLVM_PREFERRED_TYPE(OverloadExprBitfields)
1146
1147 /// Whether this member expression used the '->' operator or
1148 /// the '.' operator.
1149 LLVM_PREFERRED_TYPE(bool)
1150 unsigned IsArrow : 1;
1151
1152 /// Whether the lookup results contain an unresolved using declaration.
1153 LLVM_PREFERRED_TYPE(bool)
1154 unsigned HasUnresolvedUsing : 1;
1155 };
1156 static_assert(sizeof(UnresolvedMemberExprBitfields) <= 4,
1157 "UnresolvedMemberExprBitfields must be <= than 4 bytes to"
1158 "avoid trashing OverloadExprBitfields::NumResults!");
1159
1161 friend class ASTStmtReader;
1162 friend class CXXNoexceptExpr;
1163
1164 LLVM_PREFERRED_TYPE(ExprBitfields)
1166
1167 LLVM_PREFERRED_TYPE(bool)
1168 unsigned Value : 1;
1169 };
1170
1172 friend class ASTStmtReader;
1174
1175 LLVM_PREFERRED_TYPE(ExprBitfields)
1177
1178 /// The location of the non-type template parameter reference.
1179 SourceLocation NameLoc;
1180 };
1181
1183 friend class ASTStmtReader;
1184 friend class ASTStmtWriter;
1185 friend class LambdaExpr;
1186
1187 LLVM_PREFERRED_TYPE(ExprBitfields)
1189
1190 /// The default capture kind, which is a value of type
1191 /// LambdaCaptureDefault.
1192 LLVM_PREFERRED_TYPE(LambdaCaptureDefault)
1193 unsigned CaptureDefault : 2;
1194
1195 /// Whether this lambda had an explicit parameter list vs. an
1196 /// implicit (and empty) parameter list.
1197 LLVM_PREFERRED_TYPE(bool)
1198 unsigned ExplicitParams : 1;
1199
1200 /// Whether this lambda had the result type explicitly specified.
1201 LLVM_PREFERRED_TYPE(bool)
1202 unsigned ExplicitResultType : 1;
1203
1204 /// The number of captures.
1205 unsigned NumCaptures : 16;
1206 };
1207
1209 friend class ASTStmtReader;
1210 friend class ASTStmtWriter;
1211 friend class RequiresExpr;
1212
1213 LLVM_PREFERRED_TYPE(ExprBitfields)
1215
1216 LLVM_PREFERRED_TYPE(bool)
1217 unsigned IsSatisfied : 1;
1218 SourceLocation RequiresKWLoc;
1219 };
1220
1223 friend class ASTStmtReader;
1224 LLVM_PREFERRED_TYPE(ExprBitfields)
1226
1227 /// The trait. An ArrayTypeTrait enum in MSVC compat unsigned.
1228 LLVM_PREFERRED_TYPE(ArrayTypeTrait)
1229 unsigned ATT : 2;
1230 };
1231
1234 friend class ASTStmtReader;
1235 LLVM_PREFERRED_TYPE(ExprBitfields)
1237
1238 /// The trait. A ExpressionTrait enum in MSVC compatible unsigned.
1239 LLVM_PREFERRED_TYPE(ExpressionTrait)
1240 unsigned ET : 31;
1241
1242 /// The value of the type trait. Unspecified if dependent.
1243 LLVM_PREFERRED_TYPE(bool)
1244 unsigned Value : 1;
1245 };
1246
1248 friend class CXXFoldExpr;
1249 friend class ASTStmtReader;
1250 friend class ASTStmtWriter;
1251
1252 LLVM_PREFERRED_TYPE(ExprBitfields)
1254
1255 BinaryOperatorKind Opcode;
1256 };
1257
1259 friend class PackIndexingExpr;
1260 friend class ASTStmtWriter;
1261 friend class ASTStmtReader;
1262
1263 LLVM_PREFERRED_TYPE(ExprBitfields)
1265 // The size of the trailing expressions.
1266 unsigned TransformedExpressions : 31;
1267
1268 LLVM_PREFERRED_TYPE(bool)
1269 unsigned FullySubstituted : 1;
1270 };
1271
1272 //===--- C++ Coroutines bitfields classes ---===//
1273
1275 friend class CoawaitExpr;
1276
1277 LLVM_PREFERRED_TYPE(ExprBitfields)
1279
1280 LLVM_PREFERRED_TYPE(bool)
1281 unsigned IsImplicit : 1;
1282 };
1283
1284 //===--- Obj-C Expression bitfields classes ---===//
1285
1287 friend class ObjCObjectLiteral;
1288
1290
1291 unsigned IsExpressibleAsConstantInitializer : 1;
1292 };
1293
1296
1297 LLVM_PREFERRED_TYPE(ExprBitfields)
1299
1300 LLVM_PREFERRED_TYPE(bool)
1301 unsigned ShouldCopy : 1;
1302 };
1303
1304 //===--- Clang Extensions bitfields classes ---===//
1305
1307 friend class ASTStmtReader;
1308 friend class OpaqueValueExpr;
1309
1310 LLVM_PREFERRED_TYPE(ExprBitfields)
1312
1313 /// The OVE is a unique semantic reference to its source expression if this
1314 /// bit is set to true.
1315 LLVM_PREFERRED_TYPE(bool)
1316 unsigned IsUnique : 1;
1317
1318 SourceLocation Loc;
1319 };
1320
1322 friend class ConvertVectorExpr;
1323
1324 LLVM_PREFERRED_TYPE(ExprBitfields)
1326
1327 //
1328 /// This is only meaningful for operations on floating point
1329 /// types when additional values need to be in trailing storage.
1330 /// It is 0 otherwise.
1331 LLVM_PREFERRED_TYPE(bool)
1332 unsigned HasFPFeatures : 1;
1333 };
1334
1335 union {
1336 // Same order as in StmtNodes.td.
1337 // Statements
1353
1354 // Expressions
1376
1377 // GNU Extensions.
1380
1381 // C++ Expressions
1410
1411 // C++ Coroutines expressions
1413
1414 // Obj-C Expressions
1417
1418 // Clang Extensions
1421 };
1422
1423public:
1424 // Only allow allocation of Stmts using the allocator in ASTContext
1425 // or by doing a placement new.
1426 void* operator new(size_t bytes, const ASTContext& C,
1427 unsigned alignment = 8);
1428
1429 void* operator new(size_t bytes, const ASTContext* C,
1430 unsigned alignment = 8) {
1431 return operator new(bytes, *C, alignment);
1432 }
1433
1434 void *operator new(size_t bytes, void *mem) noexcept { return mem; }
1435
1436 void operator delete(void *, const ASTContext &, unsigned) noexcept {}
1437 void operator delete(void *, const ASTContext *, unsigned) noexcept {}
1438 void operator delete(void *, size_t) noexcept {}
1439 void operator delete(void *, void *) noexcept {}
1440
1441public:
1442 /// A placeholder type used to construct an empty shell of a
1443 /// type, that will be filled in later (e.g., by some
1444 /// de-serialization).
1445 struct EmptyShell {};
1446
1447 /// The likelihood of a branch being taken.
1449 LH_Unlikely = -1, ///< Branch has the [[unlikely]] attribute.
1450 LH_None, ///< No attribute set or branches of the IfStmt have
1451 ///< the same attribute.
1452 LH_Likely ///< Branch has the [[likely]] attribute.
1453 };
1454
1455protected:
1456 /// Iterator for iterating over Stmt * arrays that contain only T *.
1457 ///
1458 /// This is needed because AST nodes use Stmt* arrays to store
1459 /// references to children (to be compatible with StmtIterator).
1460 template<typename T, typename TPtr = T *, typename StmtPtr = Stmt *>
1462 : llvm::iterator_adaptor_base<CastIterator<T, TPtr, StmtPtr>, StmtPtr *,
1463 std::random_access_iterator_tag, TPtr> {
1464 using Base = typename CastIterator::iterator_adaptor_base;
1465
1467 CastIterator(StmtPtr *I) : Base(I) {}
1468
1469 typename Base::value_type operator*() const {
1470 return cast_or_null<T>(*this->I);
1471 }
1472 };
1473
1474 /// Const iterator for iterating over Stmt * arrays that contain only T *.
1475 template <typename T>
1477
1480
1481private:
1482 /// Whether statistic collection is enabled.
1483 static bool StatisticsEnabled;
1484
1485protected:
1486 /// Construct an empty statement.
1487 explicit Stmt(StmtClass SC, EmptyShell) : Stmt(SC) {}
1488
1489public:
1490 Stmt() = delete;
1491 Stmt(const Stmt &) = delete;
1492 Stmt(Stmt &&) = delete;
1493 Stmt &operator=(const Stmt &) = delete;
1494 Stmt &operator=(Stmt &&) = delete;
1495
1497 static_assert(sizeof(*this) <= 8,
1498 "changing bitfields changed sizeof(Stmt)");
1499 static_assert(sizeof(*this) % alignof(void *) == 0,
1500 "Insufficient alignment!");
1501 StmtBits.sClass = SC;
1502 if (StatisticsEnabled) Stmt::addStmtClass(SC);
1503 }
1504
1506 return static_cast<StmtClass>(StmtBits.sClass);
1507 }
1508
1509 const char *getStmtClassName() const;
1510
1511 /// SourceLocation tokens are not useful in isolation - they are low level
1512 /// value objects created/interpreted by SourceManager. We assume AST
1513 /// clients will have a pointer to the respective SourceManager.
1514 SourceRange getSourceRange() const LLVM_READONLY;
1515 SourceLocation getBeginLoc() const LLVM_READONLY;
1516 SourceLocation getEndLoc() const LLVM_READONLY;
1517
1518 // global temp stats (until we have a per-module visitor)
1519 static void addStmtClass(const StmtClass s);
1520 static void EnableStatistics();
1521 static void PrintStats();
1522
1523 /// \returns the likelihood of a set of attributes.
1524 static Likelihood getLikelihood(ArrayRef<const Attr *> Attrs);
1525
1526 /// \returns the likelihood of a statement.
1527 static Likelihood getLikelihood(const Stmt *S);
1528
1529 /// \returns the likelihood attribute of a statement.
1530 static const Attr *getLikelihoodAttr(const Stmt *S);
1531
1532 /// \returns the likelihood of the 'then' branch of an 'if' statement. The
1533 /// 'else' branch is required to determine whether both branches specify the
1534 /// same likelihood, which affects the result.
1535 static Likelihood getLikelihood(const Stmt *Then, const Stmt *Else);
1536
1537 /// \returns whether the likelihood of the branches of an if statement are
1538 /// conflicting. When the first element is \c true there's a conflict and
1539 /// the Attr's are the conflicting attributes of the Then and Else Stmt.
1540 static std::tuple<bool, const Attr *, const Attr *>
1541 determineLikelihoodConflict(const Stmt *Then, const Stmt *Else);
1542
1543 /// Dumps the specified AST fragment and all subtrees to
1544 /// \c llvm::errs().
1545 void dump() const;
1546 void dump(raw_ostream &OS, const ASTContext &Context) const;
1547
1548 /// \return Unique reproducible object identifier
1549 int64_t getID(const ASTContext &Context) const;
1550
1551 /// dumpColor - same as dump(), but forces color highlighting.
1552 void dumpColor() const;
1553
1554 /// dumpPretty/printPretty - These two methods do a "pretty print" of the AST
1555 /// back to its original source language syntax.
1556 void dumpPretty(const ASTContext &Context) const;
1557 void printPretty(raw_ostream &OS, PrinterHelper *Helper,
1558 const PrintingPolicy &Policy, unsigned Indentation = 0,
1559 StringRef NewlineSymbol = "\n",
1560 const ASTContext *Context = nullptr) const;
1561 void printPrettyControlled(raw_ostream &OS, PrinterHelper *Helper,
1562 const PrintingPolicy &Policy,
1563 unsigned Indentation = 0,
1564 StringRef NewlineSymbol = "\n",
1565 const ASTContext *Context = nullptr) const;
1566
1567 /// Pretty-prints in JSON format.
1568 void printJson(raw_ostream &Out, PrinterHelper *Helper,
1569 const PrintingPolicy &Policy, bool AddQuotes) const;
1570
1571 /// viewAST - Visualize an AST rooted at this Stmt* using GraphViz. Only
1572 /// works on systems with GraphViz (Mac OS X) or dot+gv installed.
1573 void viewAST() const;
1574
1575 /// Skip no-op (attributed, compound) container stmts and skip captured
1576 /// stmt at the top, if \a IgnoreCaptured is true.
1577 Stmt *IgnoreContainers(bool IgnoreCaptured = false);
1578 const Stmt *IgnoreContainers(bool IgnoreCaptured = false) const {
1579 return const_cast<Stmt *>(this)->IgnoreContainers(IgnoreCaptured);
1580 }
1581
1582 const Stmt *stripLabelLikeStatements() const;
1584 return const_cast<Stmt*>(
1585 const_cast<const Stmt*>(this)->stripLabelLikeStatements());
1586 }
1587
1588 /// Child Iterators: All subclasses must implement 'children'
1589 /// to permit easy iteration over the substatements/subexpressions of an
1590 /// AST node. This permits easy iteration over all nodes in the AST.
1593
1594 using child_range = llvm::iterator_range<child_iterator>;
1595 using const_child_range = llvm::iterator_range<const_child_iterator>;
1596
1598
1600 return const_cast<Stmt *>(this)->children();
1601 }
1602
1603 child_iterator child_begin() { return children().begin(); }
1604 child_iterator child_end() { return children().end(); }
1605
1606 const_child_iterator child_begin() const { return children().begin(); }
1607 const_child_iterator child_end() const { return children().end(); }
1608
1609 /// Produce a unique representation of the given statement.
1610 ///
1611 /// \param ID once the profiling operation is complete, will contain
1612 /// the unique representation of the given statement.
1613 ///
1614 /// \param Context the AST context in which the statement resides
1615 ///
1616 /// \param Canonical whether the profile should be based on the canonical
1617 /// representation of this statement (e.g., where non-type template
1618 /// parameters are identified by index/level rather than their
1619 /// declaration pointers) or the exact representation of the statement as
1620 /// written in the source.
1621 /// \param ProfileLambdaExpr whether or not to profile lambda expressions.
1622 /// When false, the lambda expressions are never considered to be equal to
1623 /// other lambda expressions. When true, the lambda expressions with the same
1624 /// implementation will be considered to be the same. ProfileLambdaExpr should
1625 /// only be true when we try to merge two declarations within modules.
1626 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
1627 bool Canonical, bool ProfileLambdaExpr = false) const;
1628
1629 /// Calculate a unique representation for a statement that is
1630 /// stable across compiler invocations.
1631 ///
1632 /// \param ID profile information will be stored in ID.
1633 ///
1634 /// \param Hash an ODRHash object which will be called where pointers would
1635 /// have been used in the Profile function.
1636 void ProcessODRHash(llvm::FoldingSetNodeID &ID, ODRHash& Hash) const;
1637};
1638
1639/// DeclStmt - Adaptor class for mixing declarations with statements and
1640/// expressions. For example, CompoundStmt mixes statements, expressions
1641/// and declarations (variables, types). Another example is ForStmt, where
1642/// the first statement can be an expression or a declaration.
1643class DeclStmt : public Stmt {
1644 DeclGroupRef DG;
1645 SourceLocation StartLoc, EndLoc;
1646
1647public:
1649 : Stmt(DeclStmtClass), DG(dg), StartLoc(startLoc), EndLoc(endLoc) {}
1650
1651 /// Build an empty declaration statement.
1652 explicit DeclStmt(EmptyShell Empty) : Stmt(DeclStmtClass, Empty) {}
1653
1654 /// isSingleDecl - This method returns true if this DeclStmt refers
1655 /// to a single Decl.
1656 bool isSingleDecl() const { return DG.isSingleDecl(); }
1657
1658 const Decl *getSingleDecl() const { return DG.getSingleDecl(); }
1659 Decl *getSingleDecl() { return DG.getSingleDecl(); }
1660
1661 const DeclGroupRef getDeclGroup() const { return DG; }
1663 void setDeclGroup(DeclGroupRef DGR) { DG = DGR; }
1664
1665 void setStartLoc(SourceLocation L) { StartLoc = L; }
1666 SourceLocation getEndLoc() const { return EndLoc; }
1667 void setEndLoc(SourceLocation L) { EndLoc = L; }
1668
1669 SourceLocation getBeginLoc() const LLVM_READONLY { return StartLoc; }
1670
1671 static bool classof(const Stmt *T) {
1672 return T->getStmtClass() == DeclStmtClass;
1673 }
1674
1675 // Iterators over subexpressions.
1677 return child_range(child_iterator(DG.begin(), DG.end()),
1678 child_iterator(DG.end(), DG.end()));
1679 }
1680
1682 auto Children = const_cast<DeclStmt *>(this)->children();
1684 }
1685
1688 using decl_range = llvm::iterator_range<decl_iterator>;
1689 using decl_const_range = llvm::iterator_range<const_decl_iterator>;
1690
1692
1695 }
1696
1697 decl_iterator decl_begin() { return DG.begin(); }
1698 decl_iterator decl_end() { return DG.end(); }
1699 const_decl_iterator decl_begin() const { return DG.begin(); }
1700 const_decl_iterator decl_end() const { return DG.end(); }
1701
1702 using reverse_decl_iterator = std::reverse_iterator<decl_iterator>;
1703
1707
1711};
1712
1713/// NullStmt - This is the null statement ";": C99 6.8.3p3.
1714///
1715class NullStmt : public Stmt {
1716public:
1718 : Stmt(NullStmtClass) {
1719 NullStmtBits.HasLeadingEmptyMacro = hasLeadingEmptyMacro;
1720 setSemiLoc(L);
1721 }
1722
1723 /// Build an empty null statement.
1724 explicit NullStmt(EmptyShell Empty) : Stmt(NullStmtClass, Empty) {}
1725
1726 SourceLocation getSemiLoc() const { return NullStmtBits.SemiLoc; }
1727 void setSemiLoc(SourceLocation L) { NullStmtBits.SemiLoc = L; }
1728
1730 return NullStmtBits.HasLeadingEmptyMacro;
1731 }
1732
1735
1736 static bool classof(const Stmt *T) {
1737 return T->getStmtClass() == NullStmtClass;
1738 }
1739
1743
1747};
1748
1749/// CompoundStmt - This represents a group of statements like { stmt stmt }.
1750class CompoundStmt final
1751 : public Stmt,
1752 private llvm::TrailingObjects<CompoundStmt, Stmt *, FPOptionsOverride> {
1753 friend class ASTStmtReader;
1754 friend TrailingObjects;
1755
1756 /// The location of the opening "{".
1757 SourceLocation LBraceLoc;
1758
1759 /// The location of the closing "}".
1760 SourceLocation RBraceLoc;
1761
1764 explicit CompoundStmt(EmptyShell Empty) : Stmt(CompoundStmtClass, Empty) {}
1765
1766 void setStmts(ArrayRef<Stmt *> Stmts);
1767
1768 /// Set FPOptionsOverride in trailing storage. Used only by Serialization.
1769 void setStoredFPFeatures(FPOptionsOverride F) {
1770 assert(hasStoredFPFeatures());
1771 *getTrailingObjects<FPOptionsOverride>() = F;
1772 }
1773
1774 size_t numTrailingObjects(OverloadToken<Stmt *>) const {
1775 return CompoundStmtBits.NumStmts;
1776 }
1777
1778public:
1779 static CompoundStmt *Create(const ASTContext &C, ArrayRef<Stmt *> Stmts,
1780 FPOptionsOverride FPFeatures, SourceLocation LB,
1781 SourceLocation RB);
1782
1783 // Build an empty compound statement with a location.
1784 explicit CompoundStmt(SourceLocation Loc) : CompoundStmt(Loc, Loc) {}
1785
1787 : Stmt(CompoundStmtClass), LBraceLoc(Loc), RBraceLoc(EndLoc) {
1788 CompoundStmtBits.NumStmts = 0;
1789 CompoundStmtBits.HasFPFeatures = 0;
1790 }
1791
1792 // Build an empty compound statement.
1793 static CompoundStmt *CreateEmpty(const ASTContext &C, unsigned NumStmts,
1794 bool HasFPFeatures);
1795
1796 bool body_empty() const { return CompoundStmtBits.NumStmts == 0; }
1797 unsigned size() const { return CompoundStmtBits.NumStmts; }
1798
1799 bool hasStoredFPFeatures() const { return CompoundStmtBits.HasFPFeatures; }
1800
1801 /// Get FPOptionsOverride from trailing storage.
1803 assert(hasStoredFPFeatures());
1804 return *getTrailingObjects<FPOptionsOverride>();
1805 }
1806
1807 /// Get the store FPOptionsOverride or default if not stored.
1811
1813 using body_range = llvm::iterator_range<body_iterator>;
1814
1816 body_iterator body_begin() { return getTrailingObjects<Stmt *>(); }
1818 Stmt *body_front() { return !body_empty() ? body_begin()[0] : nullptr; }
1819
1821 return !body_empty() ? body_begin()[size() - 1] : nullptr;
1822 }
1823
1824 using const_body_iterator = Stmt *const *;
1825 using body_const_range = llvm::iterator_range<const_body_iterator>;
1826
1829 }
1830
1832 return getTrailingObjects<Stmt *>();
1833 }
1834
1836
1837 const Stmt *body_front() const {
1838 return !body_empty() ? body_begin()[0] : nullptr;
1839 }
1840
1841 const Stmt *body_back() const {
1842 return !body_empty() ? body_begin()[size() - 1] : nullptr;
1843 }
1844
1845 using reverse_body_iterator = std::reverse_iterator<body_iterator>;
1846
1850
1854
1856 std::reverse_iterator<const_body_iterator>;
1857
1861
1865
1866 SourceLocation getBeginLoc() const { return LBraceLoc; }
1867 SourceLocation getEndLoc() const { return RBraceLoc; }
1868
1869 SourceLocation getLBracLoc() const { return LBraceLoc; }
1870 SourceLocation getRBracLoc() const { return RBraceLoc; }
1871
1872 static bool classof(const Stmt *T) {
1873 return T->getStmtClass() == CompoundStmtClass;
1874 }
1875
1876 // Iterators
1878
1882};
1883
1884// SwitchCase is the base class for CaseStmt and DefaultStmt,
1885class SwitchCase : public Stmt {
1886protected:
1887 /// The location of the ":".
1889
1890 // The location of the "case" or "default" keyword. Stored in SwitchCaseBits.
1891 // SourceLocation KeywordLoc;
1892
1893 /// A pointer to the following CaseStmt or DefaultStmt class,
1894 /// used by SwitchStmt.
1896
1901
1903
1904public:
1908
1909 SourceLocation getKeywordLoc() const { return SwitchCaseBits.KeywordLoc; }
1910 void setKeywordLoc(SourceLocation L) { SwitchCaseBits.KeywordLoc = L; }
1913
1914 inline Stmt *getSubStmt();
1915 const Stmt *getSubStmt() const {
1916 return const_cast<SwitchCase *>(this)->getSubStmt();
1917 }
1918
1920 inline SourceLocation getEndLoc() const LLVM_READONLY;
1921
1922 static bool classof(const Stmt *T) {
1923 return T->getStmtClass() == CaseStmtClass ||
1924 T->getStmtClass() == DefaultStmtClass;
1925 }
1926};
1927
1928/// CaseStmt - Represent a case statement. It can optionally be a GNU case
1929/// statement of the form LHS ... RHS representing a range of cases.
1930class CaseStmt final
1931 : public SwitchCase,
1932 private llvm::TrailingObjects<CaseStmt, Stmt *, SourceLocation> {
1933 friend TrailingObjects;
1934
1935 // CaseStmt is followed by several trailing objects, some of which optional.
1936 // Note that it would be more convenient to put the optional trailing objects
1937 // at the end but this would impact children().
1938 // The trailing objects are in order:
1939 //
1940 // * A "Stmt *" for the LHS of the case statement. Always present.
1941 //
1942 // * A "Stmt *" for the RHS of the case statement. This is a GNU extension
1943 // which allow ranges in cases statement of the form LHS ... RHS.
1944 // Present if and only if caseStmtIsGNURange() is true.
1945 //
1946 // * A "Stmt *" for the substatement of the case statement. Always present.
1947 //
1948 // * A SourceLocation for the location of the ... if this is a case statement
1949 // with a range. Present if and only if caseStmtIsGNURange() is true.
1950 enum { LhsOffset = 0, SubStmtOffsetFromRhs = 1 };
1951 enum { NumMandatoryStmtPtr = 2 };
1952
1953 unsigned numTrailingObjects(OverloadToken<Stmt *>) const {
1954 return NumMandatoryStmtPtr + caseStmtIsGNURange();
1955 }
1956
1957 unsigned lhsOffset() const { return LhsOffset; }
1958 unsigned rhsOffset() const { return LhsOffset + caseStmtIsGNURange(); }
1959 unsigned subStmtOffset() const { return rhsOffset() + SubStmtOffsetFromRhs; }
1960
1961 /// Build a case statement assuming that the storage for the
1962 /// trailing objects has been properly allocated.
1963 CaseStmt(Expr *lhs, Expr *rhs, SourceLocation caseLoc,
1964 SourceLocation ellipsisLoc, SourceLocation colonLoc)
1965 : SwitchCase(CaseStmtClass, caseLoc, colonLoc) {
1966 // Handle GNU case statements of the form LHS ... RHS.
1967 bool IsGNURange = rhs != nullptr;
1968 SwitchCaseBits.CaseStmtIsGNURange = IsGNURange;
1969 setLHS(lhs);
1970 setSubStmt(nullptr);
1971 if (IsGNURange) {
1972 setRHS(rhs);
1973 setEllipsisLoc(ellipsisLoc);
1974 }
1975 }
1976
1977 /// Build an empty switch case statement.
1978 explicit CaseStmt(EmptyShell Empty, bool CaseStmtIsGNURange)
1979 : SwitchCase(CaseStmtClass, Empty) {
1980 SwitchCaseBits.CaseStmtIsGNURange = CaseStmtIsGNURange;
1981 }
1982
1983public:
1984 /// Build a case statement.
1985 static CaseStmt *Create(const ASTContext &Ctx, Expr *lhs, Expr *rhs,
1986 SourceLocation caseLoc, SourceLocation ellipsisLoc,
1987 SourceLocation colonLoc);
1988
1989 /// Build an empty case statement.
1990 static CaseStmt *CreateEmpty(const ASTContext &Ctx, bool CaseStmtIsGNURange);
1991
1992 /// True if this case statement is of the form case LHS ... RHS, which
1993 /// is a GNU extension. In this case the RHS can be obtained with getRHS()
1994 /// and the location of the ellipsis can be obtained with getEllipsisLoc().
1995 bool caseStmtIsGNURange() const { return SwitchCaseBits.CaseStmtIsGNURange; }
1996
1999
2000 /// Get the location of the ... in a case statement of the form LHS ... RHS.
2002 return caseStmtIsGNURange() ? *getTrailingObjects<SourceLocation>()
2003 : SourceLocation();
2004 }
2005
2006 /// Set the location of the ... in a case statement of the form LHS ... RHS.
2007 /// Assert that this case statement is of this form.
2009 assert(
2011 "setEllipsisLoc but this is not a case stmt of the form LHS ... RHS!");
2012 *getTrailingObjects<SourceLocation>() = L;
2013 }
2014
2016 return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[lhsOffset()]);
2017 }
2018
2019 const Expr *getLHS() const {
2020 return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[lhsOffset()]);
2021 }
2022
2023 void setLHS(Expr *Val) {
2024 getTrailingObjects<Stmt *>()[lhsOffset()] = reinterpret_cast<Stmt *>(Val);
2025 }
2026
2028 return caseStmtIsGNURange() ? reinterpret_cast<Expr *>(
2029 getTrailingObjects<Stmt *>()[rhsOffset()])
2030 : nullptr;
2031 }
2032
2033 const Expr *getRHS() const {
2034 return caseStmtIsGNURange() ? reinterpret_cast<Expr *>(
2035 getTrailingObjects<Stmt *>()[rhsOffset()])
2036 : nullptr;
2037 }
2038
2039 void setRHS(Expr *Val) {
2040 assert(caseStmtIsGNURange() &&
2041 "setRHS but this is not a case stmt of the form LHS ... RHS!");
2042 getTrailingObjects<Stmt *>()[rhsOffset()] = reinterpret_cast<Stmt *>(Val);
2043 }
2044
2045 Stmt *getSubStmt() { return getTrailingObjects<Stmt *>()[subStmtOffset()]; }
2046 const Stmt *getSubStmt() const {
2047 return getTrailingObjects<Stmt *>()[subStmtOffset()];
2048 }
2049
2050 void setSubStmt(Stmt *S) {
2051 getTrailingObjects<Stmt *>()[subStmtOffset()] = S;
2052 }
2053
2055 SourceLocation getEndLoc() const LLVM_READONLY {
2056 // Handle deeply nested case statements with iteration instead of recursion.
2057 const CaseStmt *CS = this;
2058 while (const auto *CS2 = dyn_cast<CaseStmt>(CS->getSubStmt()))
2059 CS = CS2;
2060
2061 return CS->getSubStmt()->getEndLoc();
2062 }
2063
2064 static bool classof(const Stmt *T) {
2065 return T->getStmtClass() == CaseStmtClass;
2066 }
2067
2068 // Iterators
2070 return child_range(getTrailingObjects<Stmt *>(),
2071 getTrailingObjects<Stmt *>() +
2072 numTrailingObjects(OverloadToken<Stmt *>()));
2073 }
2074
2076 return const_child_range(getTrailingObjects<Stmt *>(),
2077 getTrailingObjects<Stmt *>() +
2078 numTrailingObjects(OverloadToken<Stmt *>()));
2079 }
2080};
2081
2082class DefaultStmt : public SwitchCase {
2083 Stmt *SubStmt;
2084
2085public:
2087 : SwitchCase(DefaultStmtClass, DL, CL), SubStmt(substmt) {}
2088
2089 /// Build an empty default statement.
2091 : SwitchCase(DefaultStmtClass, Empty) {}
2092
2093 Stmt *getSubStmt() { return SubStmt; }
2094 const Stmt *getSubStmt() const { return SubStmt; }
2095 void setSubStmt(Stmt *S) { SubStmt = S; }
2096
2099
2101 SourceLocation getEndLoc() const LLVM_READONLY {
2102 return SubStmt->getEndLoc();
2103 }
2104
2105 static bool classof(const Stmt *T) {
2106 return T->getStmtClass() == DefaultStmtClass;
2107 }
2108
2109 // Iterators
2110 child_range children() { return child_range(&SubStmt, &SubStmt + 1); }
2111
2113 return const_child_range(&SubStmt, &SubStmt + 1);
2114 }
2115};
2116
2118 if (const auto *CS = dyn_cast<CaseStmt>(this))
2119 return CS->getEndLoc();
2120 else if (const auto *DS = dyn_cast<DefaultStmt>(this))
2121 return DS->getEndLoc();
2122 llvm_unreachable("SwitchCase is neither a CaseStmt nor a DefaultStmt!");
2123}
2124
2126 if (auto *CS = dyn_cast<CaseStmt>(this))
2127 return CS->getSubStmt();
2128 else if (auto *DS = dyn_cast<DefaultStmt>(this))
2129 return DS->getSubStmt();
2130 llvm_unreachable("SwitchCase is neither a CaseStmt nor a DefaultStmt!");
2131}
2132
2133/// Represents a statement that could possibly have a value and type. This
2134/// covers expression-statements, as well as labels and attributed statements.
2135///
2136/// Value statements have a special meaning when they are the last non-null
2137/// statement in a GNU statement expression, where they determine the value
2138/// of the statement expression.
2139class ValueStmt : public Stmt {
2140protected:
2141 using Stmt::Stmt;
2142
2143public:
2144 const Expr *getExprStmt() const;
2146 const ValueStmt *ConstThis = this;
2147 return const_cast<Expr*>(ConstThis->getExprStmt());
2148 }
2149
2150 static bool classof(const Stmt *T) {
2151 return T->getStmtClass() >= firstValueStmtConstant &&
2152 T->getStmtClass() <= lastValueStmtConstant;
2153 }
2154};
2155
2156/// LabelStmt - Represents a label, which has a substatement. For example:
2157/// foo: return;
2158class LabelStmt : public ValueStmt {
2159 LabelDecl *TheDecl;
2160 Stmt *SubStmt;
2161 bool SideEntry = false;
2162
2163public:
2164 /// Build a label statement.
2166 : ValueStmt(LabelStmtClass), TheDecl(D), SubStmt(substmt) {
2167 setIdentLoc(IL);
2168 }
2169
2170 /// Build an empty label statement.
2171 explicit LabelStmt(EmptyShell Empty) : ValueStmt(LabelStmtClass, Empty) {}
2172
2173 SourceLocation getIdentLoc() const { return LabelStmtBits.IdentLoc; }
2174 void setIdentLoc(SourceLocation L) { LabelStmtBits.IdentLoc = L; }
2175
2176 LabelDecl *getDecl() const { return TheDecl; }
2177 void setDecl(LabelDecl *D) { TheDecl = D; }
2178
2179 const char *getName() const;
2180 Stmt *getSubStmt() { return SubStmt; }
2181
2182 const Stmt *getSubStmt() const { return SubStmt; }
2183 void setSubStmt(Stmt *SS) { SubStmt = SS; }
2184
2186 SourceLocation getEndLoc() const LLVM_READONLY { return SubStmt->getEndLoc();}
2187
2188 /// Look through nested labels and return the first non-label statement; e.g.
2189 /// if this is 'a:' in 'a: b: c: for(;;)', this returns the for loop.
2190 const Stmt *getInnermostLabeledStmt() const;
2192 return const_cast<Stmt *>(
2193 const_cast<const LabelStmt *>(this)->getInnermostLabeledStmt());
2194 }
2195
2196 child_range children() { return child_range(&SubStmt, &SubStmt + 1); }
2197
2199 return const_child_range(&SubStmt, &SubStmt + 1);
2200 }
2201
2202 static bool classof(const Stmt *T) {
2203 return T->getStmtClass() == LabelStmtClass;
2204 }
2205 bool isSideEntry() const { return SideEntry; }
2206 void setSideEntry(bool SE) { SideEntry = SE; }
2207};
2208
2209/// Represents an attribute applied to a statement.
2210///
2211/// Represents an attribute applied to a statement. For example:
2212/// [[omp::for(...)]] for (...) { ... }
2213class AttributedStmt final
2214 : public ValueStmt,
2215 private llvm::TrailingObjects<AttributedStmt, const Attr *> {
2216 friend class ASTStmtReader;
2217 friend TrailingObjects;
2218
2219 Stmt *SubStmt;
2220
2221 AttributedStmt(SourceLocation Loc, ArrayRef<const Attr *> Attrs,
2222 Stmt *SubStmt)
2223 : ValueStmt(AttributedStmtClass), SubStmt(SubStmt) {
2224 AttributedStmtBits.NumAttrs = Attrs.size();
2225 AttributedStmtBits.AttrLoc = Loc;
2226 llvm::copy(Attrs, getAttrArrayPtr());
2227 }
2228
2229 explicit AttributedStmt(EmptyShell Empty, unsigned NumAttrs)
2230 : ValueStmt(AttributedStmtClass, Empty) {
2231 AttributedStmtBits.NumAttrs = NumAttrs;
2233 std::fill_n(getAttrArrayPtr(), NumAttrs, nullptr);
2234 }
2235
2236 const Attr *const *getAttrArrayPtr() const { return getTrailingObjects(); }
2237 const Attr **getAttrArrayPtr() { return getTrailingObjects(); }
2238
2239public:
2240 static AttributedStmt *Create(const ASTContext &C, SourceLocation Loc,
2241 ArrayRef<const Attr *> Attrs, Stmt *SubStmt);
2242
2243 // Build an empty attributed statement.
2244 static AttributedStmt *CreateEmpty(const ASTContext &C, unsigned NumAttrs);
2245
2248 return {getAttrArrayPtr(), AttributedStmtBits.NumAttrs};
2249 }
2250
2251 Stmt *getSubStmt() { return SubStmt; }
2252 const Stmt *getSubStmt() const { return SubStmt; }
2253
2255 SourceLocation getEndLoc() const LLVM_READONLY { return SubStmt->getEndLoc();}
2256
2257 child_range children() { return child_range(&SubStmt, &SubStmt + 1); }
2258
2260 return const_child_range(&SubStmt, &SubStmt + 1);
2261 }
2262
2263 static bool classof(const Stmt *T) {
2264 return T->getStmtClass() == AttributedStmtClass;
2265 }
2266};
2267
2268/// IfStmt - This represents an if/then/else.
2269class IfStmt final
2270 : public Stmt,
2271 private llvm::TrailingObjects<IfStmt, Stmt *, SourceLocation> {
2272 friend TrailingObjects;
2273
2274 // IfStmt is followed by several trailing objects, some of which optional.
2275 // Note that it would be more convenient to put the optional trailing
2276 // objects at then end but this would change the order of the children.
2277 // The trailing objects are in order:
2278 //
2279 // * A "Stmt *" for the init statement.
2280 // Present if and only if hasInitStorage().
2281 //
2282 // * A "Stmt *" for the condition variable.
2283 // Present if and only if hasVarStorage(). This is in fact a "DeclStmt *".
2284 //
2285 // * A "Stmt *" for the condition.
2286 // Always present. This is in fact a "Expr *".
2287 //
2288 // * A "Stmt *" for the then statement.
2289 // Always present.
2290 //
2291 // * A "Stmt *" for the else statement.
2292 // Present if and only if hasElseStorage().
2293 //
2294 // * A "SourceLocation" for the location of the "else".
2295 // Present if and only if hasElseStorage().
2296 enum { InitOffset = 0, ThenOffsetFromCond = 1, ElseOffsetFromCond = 2 };
2297 enum { NumMandatoryStmtPtr = 2 };
2298 SourceLocation LParenLoc;
2299 SourceLocation RParenLoc;
2300
2301 unsigned numTrailingObjects(OverloadToken<Stmt *>) const {
2302 return NumMandatoryStmtPtr + hasElseStorage() + hasVarStorage() +
2304 }
2305
2306 unsigned numTrailingObjects(OverloadToken<SourceLocation>) const {
2307 return hasElseStorage();
2308 }
2309
2310 unsigned initOffset() const { return InitOffset; }
2311 unsigned varOffset() const { return InitOffset + hasInitStorage(); }
2312 unsigned condOffset() const {
2313 return InitOffset + hasInitStorage() + hasVarStorage();
2314 }
2315 unsigned thenOffset() const { return condOffset() + ThenOffsetFromCond; }
2316 unsigned elseOffset() const { return condOffset() + ElseOffsetFromCond; }
2317
2318 /// Build an if/then/else statement.
2319 IfStmt(const ASTContext &Ctx, SourceLocation IL, IfStatementKind Kind,
2320 Stmt *Init, VarDecl *Var, Expr *Cond, SourceLocation LParenLoc,
2321 SourceLocation RParenLoc, Stmt *Then, SourceLocation EL, Stmt *Else);
2322
2323 /// Build an empty if/then/else statement.
2324 explicit IfStmt(EmptyShell Empty, bool HasElse, bool HasVar, bool HasInit);
2325
2326public:
2327 /// Create an IfStmt.
2328 static IfStmt *Create(const ASTContext &Ctx, SourceLocation IL,
2329 IfStatementKind Kind, Stmt *Init, VarDecl *Var,
2331 Stmt *Then, SourceLocation EL = SourceLocation(),
2332 Stmt *Else = nullptr);
2333
2334 /// Create an empty IfStmt optionally with storage for an else statement,
2335 /// condition variable and init expression.
2336 static IfStmt *CreateEmpty(const ASTContext &Ctx, bool HasElse, bool HasVar,
2337 bool HasInit);
2338
2339 /// True if this IfStmt has the storage for an init statement.
2340 bool hasInitStorage() const { return IfStmtBits.HasInit; }
2341
2342 /// True if this IfStmt has storage for a variable declaration.
2343 bool hasVarStorage() const { return IfStmtBits.HasVar; }
2344
2345 /// True if this IfStmt has storage for an else statement.
2346 bool hasElseStorage() const { return IfStmtBits.HasElse; }
2347
2349 return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[condOffset()]);
2350 }
2351
2352 const Expr *getCond() const {
2353 return reinterpret_cast<Expr *>(getTrailingObjects<Stmt *>()[condOffset()]);
2354 }
2355
2357 getTrailingObjects<Stmt *>()[condOffset()] = reinterpret_cast<Stmt *>(Cond);
2358 }
2359
2360 Stmt *getThen() { return getTrailingObjects<Stmt *>()[thenOffset()]; }
2361 const Stmt *getThen() const {
2362 return getTrailingObjects<Stmt *>()[thenOffset()];
2363 }
2364
2365 void setThen(Stmt *Then) {
2366 getTrailingObjects<Stmt *>()[thenOffset()] = Then;
2367 }
2368
2370 return hasElseStorage() ? getTrailingObjects<Stmt *>()[elseOffset()]
2371 : nullptr;
2372 }
2373
2374 const Stmt *getElse() const {
2375 return hasElseStorage() ? getTrailingObjects<Stmt *>()[elseOffset()]
2376 : nullptr;
2377 }
2378
2379 void setElse(Stmt *Else) {
2380 assert(hasElseStorage() &&
2381 "This if statement has no storage for an else statement!");
2382 getTrailingObjects<Stmt *>()[elseOffset()] = Else;
2383 }
2384
2385 /// Retrieve the variable declared in this "if" statement, if any.
2386 ///
2387 /// In the following example, "x" is the condition variable.
2388 /// \code
2389 /// if (int x = foo()) {
2390 /// printf("x is %d", x);
2391 /// }
2392 /// \endcode
2395 return const_cast<IfStmt *>(this)->getConditionVariable();
2396 }
2397
2398 /// Set the condition variable for this if statement.
2399 /// The if statement must have storage for the condition variable.
2400 void setConditionVariable(const ASTContext &Ctx, VarDecl *V);
2401
2402 /// If this IfStmt has a condition variable, return the faux DeclStmt
2403 /// associated with the creation of that condition variable.
2405 return hasVarStorage() ? static_cast<DeclStmt *>(
2406 getTrailingObjects<Stmt *>()[varOffset()])
2407 : nullptr;
2408 }
2409
2411 return hasVarStorage() ? static_cast<DeclStmt *>(
2412 getTrailingObjects<Stmt *>()[varOffset()])
2413 : nullptr;
2414 }
2415
2417 assert(hasVarStorage());
2418 getTrailingObjects<Stmt *>()[varOffset()] = CondVar;
2419 }
2420
2422 return hasInitStorage() ? getTrailingObjects<Stmt *>()[initOffset()]
2423 : nullptr;
2424 }
2425
2426 const Stmt *getInit() const {
2427 return hasInitStorage() ? getTrailingObjects<Stmt *>()[initOffset()]
2428 : nullptr;
2429 }
2430
2432 assert(hasInitStorage() &&
2433 "This if statement has no storage for an init statement!");
2434 getTrailingObjects<Stmt *>()[initOffset()] = Init;
2435 }
2436
2437 SourceLocation getIfLoc() const { return IfStmtBits.IfLoc; }
2438 void setIfLoc(SourceLocation IfLoc) { IfStmtBits.IfLoc = IfLoc; }
2439
2441 return hasElseStorage() ? *getTrailingObjects<SourceLocation>()
2442 : SourceLocation();
2443 }
2444
2446 assert(hasElseStorage() &&
2447 "This if statement has no storage for an else statement!");
2448 *getTrailingObjects<SourceLocation>() = ElseLoc;
2449 }
2450
2455
2459
2463
2464 bool isConstexpr() const {
2466 }
2467
2469 IfStmtBits.Kind = static_cast<unsigned>(Kind);
2470 }
2471
2473 return static_cast<IfStatementKind>(IfStmtBits.Kind);
2474 }
2475
2476 /// If this is an 'if constexpr', determine which substatement will be taken.
2477 /// Otherwise, or if the condition is value-dependent, returns std::nullopt.
2478 std::optional<const Stmt *> getNondiscardedCase(const ASTContext &Ctx) const;
2479 std::optional<Stmt *> getNondiscardedCase(const ASTContext &Ctx);
2480
2481 bool isObjCAvailabilityCheck() const;
2482
2484 SourceLocation getEndLoc() const LLVM_READONLY {
2485 if (getElse())
2486 return getElse()->getEndLoc();
2487 return getThen()->getEndLoc();
2488 }
2489 SourceLocation getLParenLoc() const { return LParenLoc; }
2490 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
2491 SourceLocation getRParenLoc() const { return RParenLoc; }
2492 void setRParenLoc(SourceLocation Loc) { RParenLoc = Loc; }
2493
2494 // Iterators over subexpressions. The iterators will include iterating
2495 // over the initialization expression referenced by the condition variable.
2497 // We always store a condition, but there is none for consteval if
2498 // statements, so skip it.
2499 return child_range(getTrailingObjects<Stmt *>() +
2500 (isConsteval() ? thenOffset() : 0),
2501 getTrailingObjects<Stmt *>() +
2502 numTrailingObjects(OverloadToken<Stmt *>()));
2503 }
2504
2506 // We always store a condition, but there is none for consteval if
2507 // statements, so skip it.
2508 return const_child_range(getTrailingObjects<Stmt *>() +
2509 (isConsteval() ? thenOffset() : 0),
2510 getTrailingObjects<Stmt *>() +
2511 numTrailingObjects(OverloadToken<Stmt *>()));
2512 }
2513
2514 static bool classof(const Stmt *T) {
2515 return T->getStmtClass() == IfStmtClass;
2516 }
2517};
2518
2519/// SwitchStmt - This represents a 'switch' stmt.
2520class SwitchStmt final : public Stmt,
2521 private llvm::TrailingObjects<SwitchStmt, Stmt *> {
2522 friend TrailingObjects;
2523
2524 /// Points to a linked list of case and default statements.
2525 SwitchCase *FirstCase = nullptr;
2526
2527 // SwitchStmt is followed by several trailing objects,
2528 // some of which optional. Note that it would be more convenient to
2529 // put the optional trailing objects at the end but this would change
2530 // the order in children().
2531 // The trailing objects are in order:
2532 //
2533 // * A "Stmt *" for the init statement.
2534 // Present if and only if hasInitStorage().
2535 //
2536 // * A "Stmt *" for the condition variable.
2537 // Present if and only if hasVarStorage(). This is in fact a "DeclStmt *".
2538 //
2539 // * A "Stmt *" for the condition.
2540 // Always present. This is in fact an "Expr *".
2541 //
2542 // * A "Stmt *" for the body.
2543 // Always present.
2544 enum { InitOffset = 0, BodyOffsetFromCond = 1 };
2545 enum { NumMandatoryStmtPtr = 2 };
2546 SourceLocation LParenLoc;
2547 SourceLocation RParenLoc;
2548
2549 unsigned numTrailingStatements() const {
2550 return NumMandatoryStmtPtr + hasInitStorage() + hasVarStorage();
2551 }
2552
2553 unsigned initOffset() const { return InitOffset; }
2554 unsigned varOffset() const { return InitOffset + hasInitStorage(); }
2555 unsigned condOffset() const {
2556 return InitOffset + hasInitStorage() + hasVarStorage();
2557 }
2558 unsigned bodyOffset() const { return condOffset() + BodyOffsetFromCond; }
2559
2560 /// Build a switch statement.
2561 SwitchStmt(const ASTContext &Ctx, Stmt *Init, VarDecl *Var, Expr *Cond,
2562 SourceLocation LParenLoc, SourceLocation RParenLoc);
2563
2564 /// Build a empty switch statement.
2565 explicit SwitchStmt(EmptyShell Empty, bool HasInit, bool HasVar);
2566
2567public:
2568 /// Create a switch statement.
2569 static SwitchStmt *Create(const ASTContext &Ctx, Stmt *Init, VarDecl *Var,
2570 Expr *Cond, SourceLocation LParenLoc,
2571 SourceLocation RParenLoc);
2572
2573 /// Create an empty switch statement optionally with storage for
2574 /// an init expression and a condition variable.
2575 static SwitchStmt *CreateEmpty(const ASTContext &Ctx, bool HasInit,
2576 bool HasVar);
2577
2578 /// True if this SwitchStmt has storage for an init statement.
2579 bool hasInitStorage() const { return SwitchStmtBits.HasInit; }
2580
2581 /// True if this SwitchStmt has storage for a condition variable.
2582 bool hasVarStorage() const { return SwitchStmtBits.HasVar; }
2583
2585 return reinterpret_cast<Expr *>(getTrailingObjects()[condOffset()]);
2586 }
2587
2588 const Expr *getCond() const {
2589 return reinterpret_cast<Expr *>(getTrailingObjects()[condOffset()]);
2590 }
2591
2593 getTrailingObjects()[condOffset()] = reinterpret_cast<Stmt *>(Cond);
2594 }
2595
2596 Stmt *getBody() { return getTrailingObjects()[bodyOffset()]; }
2597 const Stmt *getBody() const { return getTrailingObjects()[bodyOffset()]; }
2598
2599 void setBody(Stmt *Body) { getTrailingObjects()[bodyOffset()] = Body; }
2600
2602 return hasInitStorage() ? getTrailingObjects()[initOffset()] : nullptr;
2603 }
2604
2605 const Stmt *getInit() const {
2606 return hasInitStorage() ? getTrailingObjects()[initOffset()] : nullptr;
2607 }
2608
2610 assert(hasInitStorage() &&
2611 "This switch statement has no storage for an init statement!");
2612 getTrailingObjects()[initOffset()] = Init;
2613 }
2614
2615 /// Retrieve the variable declared in this "switch" statement, if any.
2616 ///
2617 /// In the following example, "x" is the condition variable.
2618 /// \code
2619 /// switch (int x = foo()) {
2620 /// case 0: break;
2621 /// // ...
2622 /// }
2623 /// \endcode
2626 return const_cast<SwitchStmt *>(this)->getConditionVariable();
2627 }
2628
2629 /// Set the condition variable in this switch statement.
2630 /// The switch statement must have storage for it.
2631 void setConditionVariable(const ASTContext &Ctx, VarDecl *VD);
2632
2633 /// If this SwitchStmt has a condition variable, return the faux DeclStmt
2634 /// associated with the creation of that condition variable.
2636 return hasVarStorage()
2637 ? static_cast<DeclStmt *>(getTrailingObjects()[varOffset()])
2638 : nullptr;
2639 }
2640
2642 return hasVarStorage()
2643 ? static_cast<DeclStmt *>(getTrailingObjects()[varOffset()])
2644 : nullptr;
2645 }
2646
2648 assert(hasVarStorage());
2649 getTrailingObjects()[varOffset()] = CondVar;
2650 }
2651
2652 SwitchCase *getSwitchCaseList() { return FirstCase; }
2653 const SwitchCase *getSwitchCaseList() const { return FirstCase; }
2654 void setSwitchCaseList(SwitchCase *SC) { FirstCase = SC; }
2655
2656 SourceLocation getSwitchLoc() const { return SwitchStmtBits.SwitchLoc; }
2657 void setSwitchLoc(SourceLocation L) { SwitchStmtBits.SwitchLoc = L; }
2658 SourceLocation getLParenLoc() const { return LParenLoc; }
2659 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
2660 SourceLocation getRParenLoc() const { return RParenLoc; }
2661 void setRParenLoc(SourceLocation Loc) { RParenLoc = Loc; }
2662
2664 setBody(S);
2665 setSwitchLoc(SL);
2666 }
2667
2669 assert(!SC->getNextSwitchCase() &&
2670 "case/default already added to a switch");
2671 SC->setNextSwitchCase(FirstCase);
2672 FirstCase = SC;
2673 }
2674
2675 /// Set a flag in the SwitchStmt indicating that if the 'switch (X)' is a
2676 /// switch over an enum value then all cases have been explicitly covered.
2677 void setAllEnumCasesCovered() { SwitchStmtBits.AllEnumCasesCovered = true; }
2678
2679 /// Returns true if the SwitchStmt is a switch of an enum value and all cases
2680 /// have been explicitly covered.
2682 return SwitchStmtBits.AllEnumCasesCovered;
2683 }
2684
2686 SourceLocation getEndLoc() const LLVM_READONLY {
2687 return getBody() ? getBody()->getEndLoc()
2688 : reinterpret_cast<const Stmt *>(getCond())->getEndLoc();
2689 }
2690
2691 // Iterators
2693 return child_range(getTrailingObjects(),
2694 getTrailingObjects() + numTrailingStatements());
2695 }
2696
2698 return const_child_range(getTrailingObjects(),
2699 getTrailingObjects() + numTrailingStatements());
2700 }
2701
2702 static bool classof(const Stmt *T) {
2703 return T->getStmtClass() == SwitchStmtClass;
2704 }
2705};
2706
2707/// WhileStmt - This represents a 'while' stmt.
2708class WhileStmt final : public Stmt,
2709 private llvm::TrailingObjects<WhileStmt, Stmt *> {
2710 friend TrailingObjects;
2711
2712 // WhileStmt is followed by several trailing objects,
2713 // some of which optional. Note that it would be more
2714 // convenient to put the optional trailing object at the end
2715 // but this would affect children().
2716 // The trailing objects are in order:
2717 //
2718 // * A "Stmt *" for the condition variable.
2719 // Present if and only if hasVarStorage(). This is in fact a "DeclStmt *".
2720 //
2721 // * A "Stmt *" for the condition.
2722 // Always present. This is in fact an "Expr *".
2723 //
2724 // * A "Stmt *" for the body.
2725 // Always present.
2726 //
2727 enum { VarOffset = 0, BodyOffsetFromCond = 1 };
2728 enum { NumMandatoryStmtPtr = 2 };
2729
2730 SourceLocation LParenLoc, RParenLoc;
2731
2732 unsigned varOffset() const { return VarOffset; }
2733 unsigned condOffset() const { return VarOffset + hasVarStorage(); }
2734 unsigned bodyOffset() const { return condOffset() + BodyOffsetFromCond; }
2735
2736 unsigned numTrailingStatements() const {
2737 return NumMandatoryStmtPtr + hasVarStorage();
2738 }
2739
2740 /// Build a while statement.
2741 WhileStmt(const ASTContext &Ctx, VarDecl *Var, Expr *Cond, Stmt *Body,
2742 SourceLocation WL, SourceLocation LParenLoc,
2743 SourceLocation RParenLoc);
2744
2745 /// Build an empty while statement.
2746 explicit WhileStmt(EmptyShell Empty, bool HasVar);
2747
2748public:
2749 /// Create a while statement.
2750 static WhileStmt *Create(const ASTContext &Ctx, VarDecl *Var, Expr *Cond,
2751 Stmt *Body, SourceLocation WL,
2752 SourceLocation LParenLoc, SourceLocation RParenLoc);
2753
2754 /// Create an empty while statement optionally with storage for
2755 /// a condition variable.
2756 static WhileStmt *CreateEmpty(const ASTContext &Ctx, bool HasVar);
2757
2758 /// True if this WhileStmt has storage for a condition variable.
2759 bool hasVarStorage() const { return WhileStmtBits.HasVar; }
2760
2762 return reinterpret_cast<Expr *>(getTrailingObjects()[condOffset()]);
2763 }
2764
2765 const Expr *getCond() const {
2766 return reinterpret_cast<Expr *>(getTrailingObjects()[condOffset()]);
2767 }
2768
2770 getTrailingObjects()[condOffset()] = reinterpret_cast<Stmt *>(Cond);
2771 }
2772
2773 Stmt *getBody() { return getTrailingObjects()[bodyOffset()]; }
2774 const Stmt *getBody() const { return getTrailingObjects()[bodyOffset()]; }
2775
2776 void setBody(Stmt *Body) { getTrailingObjects()[bodyOffset()] = Body; }
2777
2778 /// Retrieve the variable declared in this "while" statement, if any.
2779 ///
2780 /// In the following example, "x" is the condition variable.
2781 /// \code
2782 /// while (int x = random()) {
2783 /// // ...
2784 /// }
2785 /// \endcode
2788 return const_cast<WhileStmt *>(this)->getConditionVariable();
2789 }
2790
2791 /// Set the condition variable of this while statement.
2792 /// The while statement must have storage for it.
2793 void setConditionVariable(const ASTContext &Ctx, VarDecl *V);
2794
2795 /// If this WhileStmt has a condition variable, return the faux DeclStmt
2796 /// associated with the creation of that condition variable.
2798 return hasVarStorage()
2799 ? static_cast<DeclStmt *>(getTrailingObjects()[varOffset()])
2800 : nullptr;
2801 }
2802
2804 return hasVarStorage()
2805 ? static_cast<DeclStmt *>(getTrailingObjects()[varOffset()])
2806 : nullptr;
2807 }
2808
2810 assert(hasVarStorage());
2811 getTrailingObjects()[varOffset()] = CondVar;
2812 }
2813
2814 SourceLocation getWhileLoc() const { return WhileStmtBits.WhileLoc; }
2815 void setWhileLoc(SourceLocation L) { WhileStmtBits.WhileLoc = L; }
2816
2817 SourceLocation getLParenLoc() const { return LParenLoc; }
2818 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2819 SourceLocation getRParenLoc() const { return RParenLoc; }
2820 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2821
2823 SourceLocation getEndLoc() const LLVM_READONLY {
2824 return getBody()->getEndLoc();
2825 }
2826
2827 static bool classof(const Stmt *T) {
2828 return T->getStmtClass() == WhileStmtClass;
2829 }
2830
2831 // Iterators
2833 return child_range(getTrailingObjects(),
2834 getTrailingObjects() + numTrailingStatements());
2835 }
2836
2838 return const_child_range(getTrailingObjects(),
2839 getTrailingObjects() + numTrailingStatements());
2840 }
2841};
2842
2843/// DoStmt - This represents a 'do/while' stmt.
2844class DoStmt : public Stmt {
2845 enum { BODY, COND, END_EXPR };
2846 Stmt *SubExprs[END_EXPR];
2847 SourceLocation WhileLoc;
2848 SourceLocation RParenLoc; // Location of final ')' in do stmt condition.
2849
2850public:
2852 SourceLocation RP)
2853 : Stmt(DoStmtClass), WhileLoc(WL), RParenLoc(RP) {
2854 setCond(Cond);
2855 setBody(Body);
2856 setDoLoc(DL);
2857 }
2858
2859 /// Build an empty do-while statement.
2860 explicit DoStmt(EmptyShell Empty) : Stmt(DoStmtClass, Empty) {}
2861
2862 Expr *getCond() { return reinterpret_cast<Expr *>(SubExprs[COND]); }
2863 const Expr *getCond() const {
2864 return reinterpret_cast<Expr *>(SubExprs[COND]);
2865 }
2866
2867 void setCond(Expr *Cond) { SubExprs[COND] = reinterpret_cast<Stmt *>(Cond); }
2868
2869 Stmt *getBody() { return SubExprs[BODY]; }
2870 const Stmt *getBody() const { return SubExprs[BODY]; }
2871 void setBody(Stmt *Body) { SubExprs[BODY] = Body; }
2872
2873 SourceLocation getDoLoc() const { return DoStmtBits.DoLoc; }
2874 void setDoLoc(SourceLocation L) { DoStmtBits.DoLoc = L; }
2875 SourceLocation getWhileLoc() const { return WhileLoc; }
2876 void setWhileLoc(SourceLocation L) { WhileLoc = L; }
2877 SourceLocation getRParenLoc() const { return RParenLoc; }
2878 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2879
2882
2883 static bool classof(const Stmt *T) {
2884 return T->getStmtClass() == DoStmtClass;
2885 }
2886
2887 // Iterators
2889 return child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
2890 }
2891
2893 return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
2894 }
2895};
2896
2897/// ForStmt - This represents a 'for (init;cond;inc)' stmt. Note that any of
2898/// the init/cond/inc parts of the ForStmt will be null if they were not
2899/// specified in the source.
2900class ForStmt : public Stmt {
2901 friend class ASTStmtReader;
2902
2903 enum { INIT, CONDVAR, COND, INC, BODY, END_EXPR };
2904 Stmt* SubExprs[END_EXPR]; // SubExprs[INIT] is an expression or declstmt.
2905 SourceLocation LParenLoc, RParenLoc;
2906
2907public:
2908 ForStmt(const ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar,
2909 Expr *Inc, Stmt *Body, SourceLocation FL, SourceLocation LP,
2910 SourceLocation RP);
2911
2912 /// Build an empty for statement.
2913 explicit ForStmt(EmptyShell Empty) : Stmt(ForStmtClass, Empty) {}
2914
2915 Stmt *getInit() { return SubExprs[INIT]; }
2916
2917 /// Retrieve the variable declared in this "for" statement, if any.
2918 ///
2919 /// In the following example, "y" is the condition variable.
2920 /// \code
2921 /// for (int x = random(); int y = mangle(x); ++x) {
2922 /// // ...
2923 /// }
2924 /// \endcode
2926 void setConditionVariable(const ASTContext &C, VarDecl *V);
2927
2928 /// If this ForStmt has a condition variable, return the faux DeclStmt
2929 /// associated with the creation of that condition variable.
2931 return reinterpret_cast<DeclStmt*>(SubExprs[CONDVAR]);
2932 }
2933
2935 return reinterpret_cast<DeclStmt*>(SubExprs[CONDVAR]);
2936 }
2937
2939 SubExprs[CONDVAR] = CondVar;
2940 }
2941
2942 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
2943 Expr *getInc() { return reinterpret_cast<Expr*>(SubExprs[INC]); }
2944 Stmt *getBody() { return SubExprs[BODY]; }
2945
2946 const Stmt *getInit() const { return SubExprs[INIT]; }
2947 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
2948 const Expr *getInc() const { return reinterpret_cast<Expr*>(SubExprs[INC]); }
2949 const Stmt *getBody() const { return SubExprs[BODY]; }
2950
2951 void setInit(Stmt *S) { SubExprs[INIT] = S; }
2952 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
2953 void setInc(Expr *E) { SubExprs[INC] = reinterpret_cast<Stmt*>(E); }
2954 void setBody(Stmt *S) { SubExprs[BODY] = S; }
2955
2956 SourceLocation getForLoc() const { return ForStmtBits.ForLoc; }
2957 void setForLoc(SourceLocation L) { ForStmtBits.ForLoc = L; }
2958 SourceLocation getLParenLoc() const { return LParenLoc; }
2959 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2960 SourceLocation getRParenLoc() const { return RParenLoc; }
2961 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2962
2965
2966 static bool classof(const Stmt *T) {
2967 return T->getStmtClass() == ForStmtClass;
2968 }
2969
2970 // Iterators
2972 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
2973 }
2974
2976 return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
2977 }
2978};
2979
2980/// GotoStmt - This represents a direct goto.
2981class GotoStmt : public Stmt {
2982 LabelDecl *Label;
2983 SourceLocation LabelLoc;
2984
2985public:
2987 : Stmt(GotoStmtClass), Label(label), LabelLoc(LL) {
2988 setGotoLoc(GL);
2989 }
2990
2991 /// Build an empty goto statement.
2992 explicit GotoStmt(EmptyShell Empty) : Stmt(GotoStmtClass, Empty) {}
2993
2994 LabelDecl *getLabel() const { return Label; }
2995 void setLabel(LabelDecl *D) { Label = D; }
2996
2997 SourceLocation getGotoLoc() const { return GotoStmtBits.GotoLoc; }
2998 void setGotoLoc(SourceLocation L) { GotoStmtBits.GotoLoc = L; }
2999 SourceLocation getLabelLoc() const { return LabelLoc; }
3000 void setLabelLoc(SourceLocation L) { LabelLoc = L; }
3001
3004
3005 static bool classof(const Stmt *T) {
3006 return T->getStmtClass() == GotoStmtClass;
3007 }
3008
3009 // Iterators
3013
3017};
3018
3019/// IndirectGotoStmt - This represents an indirect goto.
3020class IndirectGotoStmt : public Stmt {
3021 SourceLocation StarLoc;
3022 Stmt *Target;
3023
3024public:
3026 : Stmt(IndirectGotoStmtClass), StarLoc(starLoc) {
3027 setTarget(target);
3028 setGotoLoc(gotoLoc);
3029 }
3030
3031 /// Build an empty indirect goto statement.
3033 : Stmt(IndirectGotoStmtClass, Empty) {}
3034
3035 void setGotoLoc(SourceLocation L) { GotoStmtBits.GotoLoc = L; }
3036 SourceLocation getGotoLoc() const { return GotoStmtBits.GotoLoc; }
3037 void setStarLoc(SourceLocation L) { StarLoc = L; }
3038 SourceLocation getStarLoc() const { return StarLoc; }
3039
3040 Expr *getTarget() { return reinterpret_cast<Expr *>(Target); }
3041 const Expr *getTarget() const {
3042 return reinterpret_cast<const Expr *>(Target);
3043 }
3044 void setTarget(Expr *E) { Target = reinterpret_cast<Stmt *>(E); }
3045
3046 /// getConstantTarget - Returns the fixed target of this indirect
3047 /// goto, if one exists.
3050 return const_cast<IndirectGotoStmt *>(this)->getConstantTarget();
3051 }
3052
3054 SourceLocation getEndLoc() const LLVM_READONLY { return Target->getEndLoc(); }
3055
3056 static bool classof(const Stmt *T) {
3057 return T->getStmtClass() == IndirectGotoStmtClass;
3058 }
3059
3060 // Iterators
3061 child_range children() { return child_range(&Target, &Target + 1); }
3062
3064 return const_child_range(&Target, &Target + 1);
3065 }
3066};
3067
3068/// Base class for BreakStmt and ContinueStmt.
3069class LoopControlStmt : public Stmt {
3070 /// If this is a named break/continue, the label whose statement we're
3071 /// targeting, as well as the source location of the label after the
3072 /// keyword; for example:
3073 ///
3074 /// a: // <-- TargetLabel
3075 /// for (;;)
3076 /// break a; // <-- LabelLoc
3077 ///
3078 LabelDecl *TargetLabel = nullptr;
3079 SourceLocation LabelLoc;
3080
3081protected:
3084 : Stmt(Class), TargetLabel(Target), LabelLoc(LabelLoc) {
3085 setKwLoc(Loc);
3086 }
3087
3090
3092
3093public:
3096
3099 return hasLabelTarget() ? getLabelLoc() : getKwLoc();
3100 }
3101
3102 bool hasLabelTarget() const { return TargetLabel != nullptr; }
3103
3104 SourceLocation getLabelLoc() const { return LabelLoc; }
3105 void setLabelLoc(SourceLocation L) { LabelLoc = L; }
3106
3107 LabelDecl *getLabelDecl() { return TargetLabel; }
3108 const LabelDecl *getLabelDecl() const { return TargetLabel; }
3109 void setLabelDecl(LabelDecl *S) { TargetLabel = S; }
3110
3111 /// If this is a named break/continue, get the loop or switch statement
3112 /// that this targets.
3113 const Stmt *getNamedLoopOrSwitch() const;
3114
3115 // Iterators
3119
3123
3124 static bool classof(const Stmt *T) {
3125 StmtClass Class = T->getStmtClass();
3126 return Class == ContinueStmtClass || Class == BreakStmtClass;
3127 }
3128};
3129
3130/// ContinueStmt - This represents a continue.
3132public:
3135 : LoopControlStmt(ContinueStmtClass, CL, LabelLoc, Target) {}
3136
3137 /// Build an empty continue statement.
3139 : LoopControlStmt(ContinueStmtClass, Empty) {}
3140
3141 static bool classof(const Stmt *T) {
3142 return T->getStmtClass() == ContinueStmtClass;
3143 }
3144};
3145
3146/// BreakStmt - This represents a break.
3148public:
3149 BreakStmt(SourceLocation BL) : LoopControlStmt(BreakStmtClass, BL) {}
3151 : LoopControlStmt(BreakStmtClass, CL, LabelLoc, Target) {}
3152
3153 /// Build an empty break statement.
3155 : LoopControlStmt(BreakStmtClass, Empty) {}
3156
3157 static bool classof(const Stmt *T) {
3158 return T->getStmtClass() == BreakStmtClass;
3159 }
3160};
3161
3162/// ReturnStmt - This represents a return, optionally of an expression:
3163/// return;
3164/// return 4;
3165///
3166/// Note that GCC allows return with no argument in a function declared to
3167/// return a value, and it allows returning a value in functions declared to
3168/// return void. We explicitly model this in the AST, which means you can't
3169/// depend on the return type of the function and the presence of an argument.
3170class ReturnStmt final
3171 : public Stmt,
3172 private llvm::TrailingObjects<ReturnStmt, const VarDecl *> {
3173 friend TrailingObjects;
3174
3175 /// The return expression.
3176 Stmt *RetExpr;
3177
3178 // ReturnStmt is followed optionally by a trailing "const VarDecl *"
3179 // for the NRVO candidate. Present if and only if hasNRVOCandidate().
3180
3181 /// True if this ReturnStmt has storage for an NRVO candidate.
3182 bool hasNRVOCandidate() const { return ReturnStmtBits.HasNRVOCandidate; }
3183
3184 /// Build a return statement.
3185 ReturnStmt(SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate);
3186
3187 /// Build an empty return statement.
3188 explicit ReturnStmt(EmptyShell Empty, bool HasNRVOCandidate);
3189
3190public:
3191 /// Create a return statement.
3192 static ReturnStmt *Create(const ASTContext &Ctx, SourceLocation RL, Expr *E,
3193 const VarDecl *NRVOCandidate);
3194
3195 /// Create an empty return statement, optionally with
3196 /// storage for an NRVO candidate.
3197 static ReturnStmt *CreateEmpty(const ASTContext &Ctx, bool HasNRVOCandidate);
3198
3199 Expr *getRetValue() { return reinterpret_cast<Expr *>(RetExpr); }
3200 const Expr *getRetValue() const { return reinterpret_cast<Expr *>(RetExpr); }
3201 void setRetValue(Expr *E) { RetExpr = reinterpret_cast<Stmt *>(E); }
3202
3203 /// Retrieve the variable that might be used for the named return
3204 /// value optimization.
3205 ///
3206 /// The optimization itself can only be performed if the variable is
3207 /// also marked as an NRVO object.
3208 const VarDecl *getNRVOCandidate() const {
3209 return hasNRVOCandidate() ? *getTrailingObjects() : nullptr;
3210 }
3211
3212 /// Set the variable that might be used for the named return value
3213 /// optimization. The return statement must have storage for it,
3214 /// which is the case if and only if hasNRVOCandidate() is true.
3215 void setNRVOCandidate(const VarDecl *Var) {
3216 assert(hasNRVOCandidate() &&
3217 "This return statement has no storage for an NRVO candidate!");
3218 *getTrailingObjects() = Var;
3219 }
3220
3221 SourceLocation getReturnLoc() const { return ReturnStmtBits.RetLoc; }
3223
3225 SourceLocation getEndLoc() const LLVM_READONLY {
3226 return RetExpr ? RetExpr->getEndLoc() : getReturnLoc();
3227 }
3228
3229 static bool classof(const Stmt *T) {
3230 return T->getStmtClass() == ReturnStmtClass;
3231 }
3232
3233 // Iterators
3235 if (RetExpr)
3236 return child_range(&RetExpr, &RetExpr + 1);
3238 }
3239
3241 if (RetExpr)
3242 return const_child_range(&RetExpr, &RetExpr + 1);
3244 }
3245};
3246
3247/// DeferStmt - This represents a deferred statement.
3248class DeferStmt : public Stmt {
3249 friend class ASTStmtReader;
3250
3251 /// The deferred statement.
3252 Stmt *Body;
3253
3254 DeferStmt(EmptyShell Empty);
3255 DeferStmt(SourceLocation DeferLoc, Stmt *Body);
3256
3257public:
3258 static DeferStmt *CreateEmpty(ASTContext &Context, EmptyShell Empty);
3259 static DeferStmt *Create(ASTContext &Context, SourceLocation DeferLoc,
3260 Stmt *Body);
3261
3262 SourceLocation getDeferLoc() const { return DeferStmtBits.DeferLoc; }
3264 DeferStmtBits.DeferLoc = DeferLoc;
3265 }
3266
3267 Stmt *getBody() { return Body; }
3268 const Stmt *getBody() const { return Body; }
3269 void setBody(Stmt *S) {
3270 assert(S && "defer body must not be null");
3271 Body = S;
3272 }
3273
3275 SourceLocation getEndLoc() const { return Body->getEndLoc(); }
3276
3277 child_range children() { return child_range(&Body, &Body + 1); }
3278
3280 return const_child_range(&Body, &Body + 1);
3281 }
3282
3283 static bool classof(const Stmt *S) {
3284 return S->getStmtClass() == DeferStmtClass;
3285 }
3286};
3287
3288/// AsmStmt is the base class for GCCAsmStmt and MSAsmStmt.
3289class AsmStmt : public Stmt {
3290protected:
3291 friend class ASTStmtReader;
3292
3294
3295 /// True if the assembly statement does not have any input or output
3296 /// operands.
3298
3299 /// If true, treat this inline assembly as having side effects.
3300 /// This assembly statement should not be optimized, deleted or moved.
3302
3303 unsigned NumOutputs;
3304 unsigned NumInputs;
3305 unsigned NumClobbers;
3306
3307 Stmt **Exprs = nullptr;
3308
3309 AsmStmt(StmtClass SC, SourceLocation asmloc, bool issimple, bool isvolatile,
3310 unsigned numoutputs, unsigned numinputs, unsigned numclobbers)
3311 : Stmt (SC), AsmLoc(asmloc), IsSimple(issimple), IsVolatile(isvolatile),
3312 NumOutputs(numoutputs), NumInputs(numinputs),
3313 NumClobbers(numclobbers) {}
3314
3315public:
3316 /// Build an empty inline-assembly statement.
3317 explicit AsmStmt(StmtClass SC, EmptyShell Empty) : Stmt(SC, Empty) {}
3318
3319 SourceLocation getAsmLoc() const { return AsmLoc; }
3321
3322 bool isSimple() const { return IsSimple; }
3323 void setSimple(bool V) { IsSimple = V; }
3324
3325 bool isVolatile() const { return IsVolatile; }
3326 void setVolatile(bool V) { IsVolatile = V; }
3327
3328 SourceLocation getBeginLoc() const LLVM_READONLY { return {}; }
3329 SourceLocation getEndLoc() const LLVM_READONLY { return {}; }
3330
3331 //===--- Asm String Analysis ---===//
3332
3333 /// Assemble final IR asm string.
3334 std::string generateAsmString(const ASTContext &C) const;
3335
3337 llvm::function_ref<void(const Stmt *, StringRef)>;
3338 /// Look at AsmExpr and if it is a variable declared as using a particular
3339 /// register add that as a constraint that will be used in this asm stmt.
3340 std::string
3341 addVariableConstraints(StringRef Constraint, const Expr &AsmExpr,
3342 const TargetInfo &Target, bool EarlyClobber,
3343 UnsupportedConstraintCallbackTy UnsupportedCB,
3344 std::string *GCCReg = nullptr) const;
3345
3346 //===--- Output operands ---===//
3347
3348 unsigned getNumOutputs() const { return NumOutputs; }
3349
3350 /// getOutputConstraint - Return the constraint string for the specified
3351 /// output operand. All output constraints are known to be non-empty (either
3352 /// '=' or '+').
3353 std::string getOutputConstraint(unsigned i) const;
3354
3355 /// isOutputPlusConstraint - Return true if the specified output constraint
3356 /// is a "+" constraint (which is both an input and an output) or false if it
3357 /// is an "=" constraint (just an output).
3358 bool isOutputPlusConstraint(unsigned i) const {
3359 return getOutputConstraint(i)[0] == '+';
3360 }
3361
3362 const Expr *getOutputExpr(unsigned i) const;
3363
3364 /// getNumPlusOperands - Return the number of output operands that have a "+"
3365 /// constraint.
3366 unsigned getNumPlusOperands() const;
3367
3368 //===--- Input operands ---===//
3369
3370 unsigned getNumInputs() const { return NumInputs; }
3371
3372 /// getInputConstraint - Return the specified input constraint. Unlike output
3373 /// constraints, these can be empty.
3374 std::string getInputConstraint(unsigned i) const;
3375
3376 const Expr *getInputExpr(unsigned i) const;
3377
3378 //===--- Other ---===//
3379
3380 unsigned getNumClobbers() const { return NumClobbers; }
3381 std::string getClobber(unsigned i) const;
3382
3383 static bool classof(const Stmt *T) {
3384 return T->getStmtClass() == GCCAsmStmtClass ||
3385 T->getStmtClass() == MSAsmStmtClass;
3386 }
3387
3388 // Input expr iterators.
3389
3392 using inputs_range = llvm::iterator_range<inputs_iterator>;
3393 using inputs_const_range = llvm::iterator_range<const_inputs_iterator>;
3394
3396 return &Exprs[0] + NumOutputs;
3397 }
3398
3400 return &Exprs[0] + NumOutputs + NumInputs;
3401 }
3402
3404
3406 return &Exprs[0] + NumOutputs;
3407 }
3408
3410 return &Exprs[0] + NumOutputs + NumInputs;
3411 }
3412
3416
3417 // Output expr iterators.
3418
3421 using outputs_range = llvm::iterator_range<outputs_iterator>;
3422 using outputs_const_range = llvm::iterator_range<const_outputs_iterator>;
3423
3425 return &Exprs[0];
3426 }
3427
3429 return &Exprs[0] + NumOutputs;
3430 }
3431
3435
3437 return &Exprs[0];
3438 }
3439
3441 return &Exprs[0] + NumOutputs;
3442 }
3443
3447
3449 return child_range(&Exprs[0], &Exprs[0] + NumOutputs + NumInputs);
3450 }
3451
3453 return const_child_range(&Exprs[0], &Exprs[0] + NumOutputs + NumInputs);
3454 }
3455};
3456
3457/// This represents a GCC inline-assembly statement extension.
3458class GCCAsmStmt : public AsmStmt {
3459 friend class ASTStmtReader;
3460
3461 SourceLocation RParenLoc;
3462 Expr *AsmStr;
3463
3464 // FIXME: If we wanted to, we could allocate all of these in one big array.
3465 Expr **Constraints = nullptr;
3466 Expr **Clobbers = nullptr;
3467 IdentifierInfo **Names = nullptr;
3468 unsigned NumLabels = 0;
3469
3470public:
3471 GCCAsmStmt(const ASTContext &C, SourceLocation asmloc, bool issimple,
3472 bool isvolatile, unsigned numoutputs, unsigned numinputs,
3473 IdentifierInfo **names, Expr **constraints, Expr **exprs,
3474 Expr *asmstr, unsigned numclobbers, Expr **clobbers,
3475 unsigned numlabels, SourceLocation rparenloc);
3476
3477 /// Build an empty inline-assembly statement.
3478 explicit GCCAsmStmt(EmptyShell Empty) : AsmStmt(GCCAsmStmtClass, Empty) {}
3479
3480 SourceLocation getRParenLoc() const { return RParenLoc; }
3481 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
3482
3483 //===--- Asm String Analysis ---===//
3484
3485 const Expr *getAsmStringExpr() const { return AsmStr; }
3486 Expr *getAsmStringExpr() { return AsmStr; }
3487 void setAsmStringExpr(Expr *E) { AsmStr = E; }
3488
3489 std::string getAsmString() const;
3490
3491 /// AsmStringPiece - this is part of a decomposed asm string specification
3492 /// (for use with the AnalyzeAsmString function below). An asm string is
3493 /// considered to be a concatenation of these parts.
3495 public:
3496 enum Kind {
3497 String, // String in .ll asm string form, "$" -> "$$" and "%%" -> "%".
3498 Operand // Operand reference, with optional modifier %c4.
3499 };
3500
3501 private:
3502 Kind MyKind;
3503 std::string Str;
3504 unsigned OperandNo;
3505
3506 // Source range for operand references.
3507 CharSourceRange Range;
3508
3509 public:
3510 AsmStringPiece(const std::string &S) : MyKind(String), Str(S) {}
3511 AsmStringPiece(unsigned OpNo, const std::string &S, SourceLocation Begin,
3512 SourceLocation End)
3513 : MyKind(Operand), Str(S), OperandNo(OpNo),
3514 Range(CharSourceRange::getCharRange(Begin, End)) {}
3515
3516 bool isString() const { return MyKind == String; }
3517 bool isOperand() const { return MyKind == Operand; }
3518
3519 const std::string &getString() const { return Str; }
3520
3521 unsigned getOperandNo() const {
3522 assert(isOperand());
3523 return OperandNo;
3524 }
3525
3527 assert(isOperand() && "Range is currently used only for Operands.");
3528 return Range;
3529 }
3530
3531 /// getModifier - Get the modifier for this operand, if present. This
3532 /// returns '\0' if there was no modifier.
3533 char getModifier() const;
3534 };
3535
3536 /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing
3537 /// it into pieces. If the asm string is erroneous, emit errors and return
3538 /// true, otherwise return false. This handles canonicalization and
3539 /// translation of strings from GCC syntax to LLVM IR syntax, and handles
3540 //// flattening of named references like %[foo] to Operand AsmStringPiece's.
3542 const ASTContext &C, unsigned &DiagOffs) const;
3543
3544 /// Assemble final IR asm string.
3545 std::string generateAsmString(const ASTContext &C) const;
3546
3547 //===--- Output operands ---===//
3548
3549 IdentifierInfo *getOutputIdentifier(unsigned i) const { return Names[i]; }
3550
3551 StringRef getOutputName(unsigned i) const {
3553 return II->getName();
3554
3555 return {};
3556 }
3557
3558 std::string getOutputConstraint(unsigned i) const;
3559
3560 const Expr *getOutputConstraintExpr(unsigned i) const {
3561 return Constraints[i];
3562 }
3563 Expr *getOutputConstraintExpr(unsigned i) { return Constraints[i]; }
3564
3565 Expr *getOutputExpr(unsigned i);
3566
3567 const Expr *getOutputExpr(unsigned i) const {
3568 return const_cast<GCCAsmStmt*>(this)->getOutputExpr(i);
3569 }
3570
3571 //===--- Input operands ---===//
3572
3574 return Names[i + NumOutputs];
3575 }
3576
3577 StringRef getInputName(unsigned i) const {
3579 return II->getName();
3580
3581 return {};
3582 }
3583
3584 std::string getInputConstraint(unsigned i) const;
3585
3586 const Expr *getInputConstraintExpr(unsigned i) const {
3587 return Constraints[i + NumOutputs];
3588 }
3590 return Constraints[i + NumOutputs];
3591 }
3592
3593 Expr *getInputExpr(unsigned i);
3594 void setInputExpr(unsigned i, Expr *E);
3595
3596 const Expr *getInputExpr(unsigned i) const {
3597 return const_cast<GCCAsmStmt*>(this)->getInputExpr(i);
3598 }
3599
3600 static std::string ExtractStringFromGCCAsmStmtComponent(const Expr *E);
3601
3602 //===--- Labels ---===//
3603
3604 bool isAsmGoto() const {
3605 return NumLabels > 0;
3606 }
3607
3608 unsigned getNumLabels() const {
3609 return NumLabels;
3610 }
3611
3613 return Names[i + NumOutputs + NumInputs];
3614 }
3615
3616 AddrLabelExpr *getLabelExpr(unsigned i) const;
3617 StringRef getLabelName(unsigned i) const;
3620 using labels_range = llvm::iterator_range<labels_iterator>;
3621 using labels_const_range = llvm::iterator_range<const_labels_iterator>;
3622
3624 return &Exprs[0] + NumOutputs + NumInputs;
3625 }
3626
3628 return &Exprs[0] + NumOutputs + NumInputs + NumLabels;
3629 }
3630
3634
3636 return &Exprs[0] + NumOutputs + NumInputs;
3637 }
3638
3640 return &Exprs[0] + NumOutputs + NumInputs + NumLabels;
3641 }
3642
3646
3647private:
3648 void setOutputsAndInputsAndClobbers(const ASTContext &C,
3649 IdentifierInfo **Names,
3650 Expr **Constraints, Stmt **Exprs,
3651 unsigned NumOutputs, unsigned NumInputs,
3652 unsigned NumLabels, Expr **Clobbers,
3653 unsigned NumClobbers);
3654
3655public:
3656 //===--- Other ---===//
3657
3658 /// getNamedOperand - Given a symbolic operand reference like %[foo],
3659 /// translate this into a numeric value needed to reference the same operand.
3660 /// This returns -1 if the operand name is invalid.
3661 int getNamedOperand(StringRef SymbolicName) const;
3662
3663 std::string getClobber(unsigned i) const;
3664
3665 Expr *getClobberExpr(unsigned i) { return Clobbers[i]; }
3666 const Expr *getClobberExpr(unsigned i) const { return Clobbers[i]; }
3667
3668 SourceLocation getBeginLoc() const LLVM_READONLY { return AsmLoc; }
3669 SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
3670
3671 static bool classof(const Stmt *T) {
3672 return T->getStmtClass() == GCCAsmStmtClass;
3673 }
3674};
3675
3676/// This represents a Microsoft inline-assembly statement extension.
3677class MSAsmStmt : public AsmStmt {
3678 friend class ASTStmtReader;
3679
3680 SourceLocation LBraceLoc, EndLoc;
3681 StringRef AsmStr;
3682
3683 unsigned NumAsmToks = 0;
3684
3685 Token *AsmToks = nullptr;
3686 StringRef *Constraints = nullptr;
3687 StringRef *Clobbers = nullptr;
3688
3689public:
3690 MSAsmStmt(const ASTContext &C, SourceLocation asmloc,
3691 SourceLocation lbraceloc, bool issimple, bool isvolatile,
3692 ArrayRef<Token> asmtoks, unsigned numoutputs, unsigned numinputs,
3693 ArrayRef<StringRef> constraints,
3694 ArrayRef<Expr*> exprs, StringRef asmstr,
3695 ArrayRef<StringRef> clobbers, SourceLocation endloc);
3696
3697 /// Build an empty MS-style inline-assembly statement.
3698 explicit MSAsmStmt(EmptyShell Empty) : AsmStmt(MSAsmStmtClass, Empty) {}
3699
3700 SourceLocation getLBraceLoc() const { return LBraceLoc; }
3701 void setLBraceLoc(SourceLocation L) { LBraceLoc = L; }
3702 SourceLocation getEndLoc() const { return EndLoc; }
3703 void setEndLoc(SourceLocation L) { EndLoc = L; }
3704
3705 bool hasBraces() const { return LBraceLoc.isValid(); }
3706
3707 unsigned getNumAsmToks() { return NumAsmToks; }
3708 Token *getAsmToks() { return AsmToks; }
3709
3710 //===--- Asm String Analysis ---===//
3711 StringRef getAsmString() const { return AsmStr; }
3712
3713 /// Assemble final IR asm string.
3714 std::string generateAsmString(const ASTContext &C) const;
3715
3716 //===--- Output operands ---===//
3717
3718 StringRef getOutputConstraint(unsigned i) const {
3719 assert(i < NumOutputs);
3720 return Constraints[i];
3721 }
3722
3723 Expr *getOutputExpr(unsigned i);
3724
3725 const Expr *getOutputExpr(unsigned i) const {
3726 return const_cast<MSAsmStmt*>(this)->getOutputExpr(i);
3727 }
3728
3729 //===--- Input operands ---===//
3730
3731 StringRef getInputConstraint(unsigned i) const {
3732 assert(i < NumInputs);
3733 return Constraints[i + NumOutputs];
3734 }
3735
3736 Expr *getInputExpr(unsigned i);
3737 void setInputExpr(unsigned i, Expr *E);
3738
3739 const Expr *getInputExpr(unsigned i) const {
3740 return const_cast<MSAsmStmt*>(this)->getInputExpr(i);
3741 }
3742
3743 //===--- Other ---===//
3744
3746 return {Constraints, NumInputs + NumOutputs};
3747 }
3748
3749 ArrayRef<StringRef> getClobbers() const { return {Clobbers, NumClobbers}; }
3750
3752 return {reinterpret_cast<Expr **>(Exprs), NumInputs + NumOutputs};
3753 }
3754
3755 StringRef getClobber(unsigned i) const { return getClobbers()[i]; }
3756
3757private:
3758 void initialize(const ASTContext &C, StringRef AsmString,
3759 ArrayRef<Token> AsmToks, ArrayRef<StringRef> Constraints,
3761
3762public:
3763 SourceLocation getBeginLoc() const LLVM_READONLY { return AsmLoc; }
3764
3765 static bool classof(const Stmt *T) {
3766 return T->getStmtClass() == MSAsmStmtClass;
3767 }
3768
3772
3776};
3777
3778class SEHExceptStmt : public Stmt {
3779 friend class ASTReader;
3780 friend class ASTStmtReader;
3781
3782 SourceLocation Loc;
3783 Stmt *Children[2];
3784
3785 enum { FILTER_EXPR, BLOCK };
3786
3787 SEHExceptStmt(SourceLocation Loc, Expr *FilterExpr, Stmt *Block);
3788 explicit SEHExceptStmt(EmptyShell E) : Stmt(SEHExceptStmtClass, E) {}
3789
3790public:
3791 static SEHExceptStmt* Create(const ASTContext &C,
3792 SourceLocation ExceptLoc,
3793 Expr *FilterExpr,
3794 Stmt *Block);
3795
3796 SourceLocation getBeginLoc() const LLVM_READONLY { return getExceptLoc(); }
3797
3798 SourceLocation getExceptLoc() const { return Loc; }
3800
3802 return reinterpret_cast<Expr*>(Children[FILTER_EXPR]);
3803 }
3804
3806 return cast<CompoundStmt>(Children[BLOCK]);
3807 }
3808
3810 return child_range(Children, Children+2);
3811 }
3812
3814 return const_child_range(Children, Children + 2);
3815 }
3816
3817 static bool classof(const Stmt *T) {
3818 return T->getStmtClass() == SEHExceptStmtClass;
3819 }
3820};
3821
3822class SEHFinallyStmt : public Stmt {
3823 friend class ASTReader;
3824 friend class ASTStmtReader;
3825
3826 SourceLocation Loc;
3827 Stmt *Block;
3828
3829 SEHFinallyStmt(SourceLocation Loc, Stmt *Block);
3830 explicit SEHFinallyStmt(EmptyShell E) : Stmt(SEHFinallyStmtClass, E) {}
3831
3832public:
3833 static SEHFinallyStmt* Create(const ASTContext &C,
3834 SourceLocation FinallyLoc,
3835 Stmt *Block);
3836
3837 SourceLocation getBeginLoc() const LLVM_READONLY { return getFinallyLoc(); }
3838
3839 SourceLocation getFinallyLoc() const { return Loc; }
3840 SourceLocation getEndLoc() const { return Block->getEndLoc(); }
3841
3842 CompoundStmt *getBlock() const { return cast<CompoundStmt>(Block); }
3843
3845 return child_range(&Block,&Block+1);
3846 }
3847
3849 return const_child_range(&Block, &Block + 1);
3850 }
3851
3852 static bool classof(const Stmt *T) {
3853 return T->getStmtClass() == SEHFinallyStmtClass;
3854 }
3855};
3856
3857class SEHTryStmt : public Stmt {
3858 friend class ASTReader;
3859 friend class ASTStmtReader;
3860
3861 bool IsCXXTry;
3862 SourceLocation TryLoc;
3863 Stmt *Children[2];
3864
3865 enum { TRY = 0, HANDLER = 1 };
3866
3867 SEHTryStmt(bool isCXXTry, // true if 'try' otherwise '__try'
3868 SourceLocation TryLoc,
3869 Stmt *TryBlock,
3870 Stmt *Handler);
3871
3872 explicit SEHTryStmt(EmptyShell E) : Stmt(SEHTryStmtClass, E) {}
3873
3874public:
3875 static SEHTryStmt* Create(const ASTContext &C, bool isCXXTry,
3876 SourceLocation TryLoc, Stmt *TryBlock,
3877 Stmt *Handler);
3878
3879 SourceLocation getBeginLoc() const LLVM_READONLY { return getTryLoc(); }
3880
3881 SourceLocation getTryLoc() const { return TryLoc; }
3882 SourceLocation getEndLoc() const { return Children[HANDLER]->getEndLoc(); }
3883
3884 bool getIsCXXTry() const { return IsCXXTry; }
3885
3887 return cast<CompoundStmt>(Children[TRY]);
3888 }
3889
3890 Stmt *getHandler() const { return Children[HANDLER]; }
3891
3892 /// Returns 0 if not defined
3895
3897 return child_range(Children, Children+2);
3898 }
3899
3901 return const_child_range(Children, Children + 2);
3902 }
3903
3904 static bool classof(const Stmt *T) {
3905 return T->getStmtClass() == SEHTryStmtClass;
3906 }
3907};
3908
3909/// Represents a __leave statement.
3910class SEHLeaveStmt : public Stmt {
3911 SourceLocation LeaveLoc;
3912
3913public:
3915 : Stmt(SEHLeaveStmtClass), LeaveLoc(LL) {}
3916
3917 /// Build an empty __leave statement.
3918 explicit SEHLeaveStmt(EmptyShell Empty) : Stmt(SEHLeaveStmtClass, Empty) {}
3919
3920 SourceLocation getLeaveLoc() const { return LeaveLoc; }
3921 void setLeaveLoc(SourceLocation L) { LeaveLoc = L; }
3922
3923 SourceLocation getBeginLoc() const LLVM_READONLY { return LeaveLoc; }
3924 SourceLocation getEndLoc() const LLVM_READONLY { return LeaveLoc; }
3925
3926 static bool classof(const Stmt *T) {
3927 return T->getStmtClass() == SEHLeaveStmtClass;
3928 }
3929
3930 // Iterators
3934
3938};
3939
3940/// This captures a statement into a function. For example, the following
3941/// pragma annotated compound statement can be represented as a CapturedStmt,
3942/// and this compound statement is the body of an anonymous outlined function.
3943/// @code
3944/// #pragma omp parallel
3945/// {
3946/// compute();
3947/// }
3948/// @endcode
3949class CapturedStmt : public Stmt {
3950public:
3951 /// The different capture forms: by 'this', by reference, capture for
3952 /// variable-length array type etc.
3959
3960 /// Describes the capture of either a variable, or 'this', or
3961 /// variable-length array type.
3962 class Capture {
3963 llvm::PointerIntPair<VarDecl *, 2, VariableCaptureKind> VarAndKind;
3964 SourceLocation Loc;
3965
3966 Capture() = default;
3967
3968 public:
3969 friend class ASTStmtReader;
3970 friend class CapturedStmt;
3971
3972 /// Create a new capture.
3973 ///
3974 /// \param Loc The source location associated with this capture.
3975 ///
3976 /// \param Kind The kind of capture (this, ByRef, ...).
3977 ///
3978 /// \param Var The variable being captured, or null if capturing this.
3980 VarDecl *Var = nullptr);
3981
3982 /// Determine the kind of capture.
3984
3985 /// Retrieve the source location at which the variable or 'this' was
3986 /// first used.
3987 SourceLocation getLocation() const { return Loc; }
3988
3989 /// Determine whether this capture handles the C++ 'this' pointer.
3990 bool capturesThis() const { return getCaptureKind() == VCK_This; }
3991
3992 /// Determine whether this capture handles a variable (by reference).
3993 bool capturesVariable() const { return getCaptureKind() == VCK_ByRef; }
3994
3995 /// Determine whether this capture handles a variable by copy.
3997 return getCaptureKind() == VCK_ByCopy;
3998 }
3999
4000 /// Determine whether this capture handles a variable-length array
4001 /// type.
4003 return getCaptureKind() == VCK_VLAType;
4004 }
4005
4006 /// Retrieve the declaration of the variable being captured.
4007 ///
4008 /// This operation is only valid if this capture captures a variable.
4009 VarDecl *getCapturedVar() const;
4010 };
4011
4012private:
4013 /// The number of variable captured, including 'this'.
4014 unsigned NumCaptures;
4015
4016 /// The pointer part is the implicit the outlined function and the
4017 /// int part is the captured region kind, 'CR_Default' etc.
4018 llvm::PointerIntPair<CapturedDecl *, 2, CapturedRegionKind> CapDeclAndKind;
4019
4020 /// The record for captured variables, a RecordDecl or CXXRecordDecl.
4021 RecordDecl *TheRecordDecl = nullptr;
4022
4023 /// Construct a captured statement.
4025 ArrayRef<Expr *> CaptureInits, CapturedDecl *CD, RecordDecl *RD);
4026
4027 /// Construct an empty captured statement.
4028 CapturedStmt(EmptyShell Empty, unsigned NumCaptures);
4029
4030 Stmt **getStoredStmts() { return reinterpret_cast<Stmt **>(this + 1); }
4031
4032 Stmt *const *getStoredStmts() const {
4033 return reinterpret_cast<Stmt *const *>(this + 1);
4034 }
4035
4036 Capture *getStoredCaptures() const;
4037
4038 void setCapturedStmt(Stmt *S) { getStoredStmts()[NumCaptures] = S; }
4039
4040public:
4041 friend class ASTStmtReader;
4042
4043 static CapturedStmt *Create(const ASTContext &Context, Stmt *S,
4044 CapturedRegionKind Kind,
4045 ArrayRef<Capture> Captures,
4046 ArrayRef<Expr *> CaptureInits,
4047 CapturedDecl *CD, RecordDecl *RD);
4048
4049 static CapturedStmt *CreateDeserialized(const ASTContext &Context,
4050 unsigned NumCaptures);
4051
4052 /// Retrieve the statement being captured.
4053 Stmt *getCapturedStmt() { return getStoredStmts()[NumCaptures]; }
4054 const Stmt *getCapturedStmt() const { return getStoredStmts()[NumCaptures]; }
4055
4056 /// Retrieve the outlined function declaration.
4058 const CapturedDecl *getCapturedDecl() const;
4059
4060 /// Set the outlined function declaration.
4062
4063 /// Retrieve the captured region kind.
4065
4066 /// Set the captured region kind.
4068
4069 /// Retrieve the record declaration for captured variables.
4070 const RecordDecl *getCapturedRecordDecl() const { return TheRecordDecl; }
4071
4072 /// Set the record declaration for captured variables.
4074 assert(D && "null RecordDecl");
4075 TheRecordDecl = D;
4076 }
4077
4078 /// True if this variable has been captured.
4079 bool capturesVariable(const VarDecl *Var) const;
4080
4081 /// An iterator that walks over the captures.
4084 using capture_range = llvm::iterator_range<capture_iterator>;
4085 using capture_const_range = llvm::iterator_range<const_capture_iterator>;
4086
4093
4094 /// Retrieve an iterator pointing to the first capture.
4095 capture_iterator capture_begin() { return getStoredCaptures(); }
4096 const_capture_iterator capture_begin() const { return getStoredCaptures(); }
4097
4098 /// Retrieve an iterator pointing past the end of the sequence of
4099 /// captures.
4101 return getStoredCaptures() + NumCaptures;
4102 }
4103
4104 /// Retrieve the number of captures, including 'this'.
4105 unsigned capture_size() const { return NumCaptures; }
4106
4107 /// Iterator that walks over the capture initialization arguments.
4109 using capture_init_range = llvm::iterator_range<capture_init_iterator>;
4110
4111 /// Const iterator that walks over the capture initialization
4112 /// arguments.
4115 llvm::iterator_range<const_capture_init_iterator>;
4116
4120
4124
4125 /// Retrieve the first initialization argument.
4127 return reinterpret_cast<Expr **>(getStoredStmts());
4128 }
4129
4131 return reinterpret_cast<Expr *const *>(getStoredStmts());
4132 }
4133
4134 /// Retrieve the iterator pointing one past the last initialization
4135 /// argument.
4137 return capture_init_begin() + NumCaptures;
4138 }
4139
4141 return capture_init_begin() + NumCaptures;
4142 }
4143
4144 SourceLocation getBeginLoc() const LLVM_READONLY {
4145 return getCapturedStmt()->getBeginLoc();
4146 }
4147
4148 SourceLocation getEndLoc() const LLVM_READONLY {
4149 return getCapturedStmt()->getEndLoc();
4150 }
4151
4152 SourceRange getSourceRange() const LLVM_READONLY {
4153 return getCapturedStmt()->getSourceRange();
4154 }
4155
4156 static bool classof(const Stmt *T) {
4157 return T->getStmtClass() == CapturedStmtClass;
4158 }
4159
4161
4163};
4164
4165} // namespace clang
4166
4167#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:4570
Stmt ** Exprs
Definition Stmt.h:3307
void setSimple(bool V)
Definition Stmt.h:3323
outputs_iterator begin_outputs()
Definition Stmt.h:3424
void setAsmLoc(SourceLocation L)
Definition Stmt.h:3320
const_outputs_iterator end_outputs() const
Definition Stmt.h:3440
std::string getInputConstraint(unsigned i) const
getInputConstraint - Return the specified input constraint.
Definition Stmt.cpp:515
SourceLocation AsmLoc
Definition Stmt.h:3293
bool isVolatile() const
Definition Stmt.h:3325
llvm::function_ref< void(const Stmt *, StringRef)> UnsupportedConstraintCallbackTy
Definition Stmt.h:3336
outputs_iterator end_outputs()
Definition Stmt.h:3428
const_inputs_iterator begin_inputs() const
Definition Stmt.h:3405
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:3309
void setVolatile(bool V)
Definition Stmt.h:3326
static bool classof(const Stmt *T)
Definition Stmt.h:3383
outputs_range outputs()
Definition Stmt.h:3432
inputs_const_range inputs() const
Definition Stmt.h:3413
SourceLocation getAsmLoc() const
Definition Stmt.h:3319
const Expr * getInputExpr(unsigned i) const
Definition Stmt.cpp:523
unsigned NumInputs
Definition Stmt.h:3304
SourceLocation getEndLoc() const LLVM_READONLY
Definition Stmt.h:3329
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:3403
llvm::iterator_range< inputs_iterator > inputs_range
Definition Stmt.h:3392
bool isOutputPlusConstraint(unsigned i) const
isOutputPlusConstraint - Return true if the specified output constraint is a "+" constraint (which is...
Definition Stmt.h:3358
unsigned getNumClobbers() const
Definition Stmt.h:3380
ExprIterator outputs_iterator
Definition Stmt.h:3419
const_inputs_iterator end_inputs() const
Definition Stmt.h:3409
llvm::iterator_range< const_inputs_iterator > inputs_const_range
Definition Stmt.h:3393
const_child_range children() const
Definition Stmt.h:3452
ExprIterator inputs_iterator
Definition Stmt.h:3390
bool IsSimple
True if the assembly statement does not have any input or output operands.
Definition Stmt.h:3297
const Expr * getOutputExpr(unsigned i) const
Definition Stmt.cpp:507
outputs_const_range outputs() const
Definition Stmt.h:3444
inputs_iterator end_inputs()
Definition Stmt.h:3399
unsigned getNumOutputs() const
Definition Stmt.h:3348
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.h:3328
inputs_iterator begin_inputs()
Definition Stmt.h:3395
AsmStmt(StmtClass SC, EmptyShell Empty)
Build an empty inline-assembly statement.
Definition Stmt.h:3317
unsigned NumOutputs
Definition Stmt.h:3303
child_range children()
Definition Stmt.h:3448
ConstExprIterator const_outputs_iterator
Definition Stmt.h:3420
ConstExprIterator const_inputs_iterator
Definition Stmt.h:3391
std::string generateAsmString(const ASTContext &C) const
Assemble final IR asm string.
Definition Stmt.cpp:491
unsigned NumClobbers
Definition Stmt.h:3305
bool IsVolatile
If true, treat this inline assembly as having side effects.
Definition Stmt.h:3301
friend class ASTStmtReader
Definition Stmt.h:3291
unsigned getNumInputs() const
Definition Stmt.h:3370
bool isSimple() const
Definition Stmt.h:3322
llvm::iterator_range< outputs_iterator > outputs_range
Definition Stmt.h:3421
const_outputs_iterator begin_outputs() const
Definition Stmt.h:3436
std::string getClobber(unsigned i) const
Definition Stmt.cpp:531
llvm::iterator_range< const_outputs_iterator > outputs_const_range
Definition Stmt.h:3422
Attr - This represents one attribute.
Definition Attr.h:46
Represents an attribute applied to a statement.
Definition Stmt.h:2215
static AttributedStmt * CreateEmpty(const ASTContext &C, unsigned NumAttrs)
Definition Stmt.cpp:450
Stmt * getSubStmt()
Definition Stmt.h:2251
const Stmt * getSubStmt() const
Definition Stmt.h:2252
SourceLocation getAttrLoc() const
Definition Stmt.h:2246
ArrayRef< const Attr * > getAttrs() const
Definition Stmt.h:2247
child_range children()
Definition Stmt.h:2257
const_child_range children() const
Definition Stmt.h:2259
friend class ASTStmtReader
Definition Stmt.h:2216
static bool classof(const Stmt *T)
Definition Stmt.h:2263
SourceLocation getEndLoc() const LLVM_READONLY
Definition Stmt.h:2255
SourceLocation getBeginLoc() const
Definition Stmt.h:2254
BreakStmt(SourceLocation BL)
Definition Stmt.h:3149
static bool classof(const Stmt *T)
Definition Stmt.h:3157
BreakStmt(EmptyShell Empty)
Build an empty break statement.
Definition Stmt.h:3154
BreakStmt(SourceLocation CL, SourceLocation LabelLoc, LabelDecl *Target)
Definition Stmt.h:3150
Represents the body of a CapturedStmt, and serves as its DeclContext.
Definition Decl.h:5078
Describes the capture of either a variable, or 'this', or variable-length array type.
Definition Stmt.h:3962
bool capturesVariableByCopy() const
Determine whether this capture handles a variable by copy.
Definition Stmt.h:3996
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:4002
friend class CapturedStmt
Definition Stmt.h:3970
bool capturesThis() const
Determine whether this capture handles the C++ 'this' pointer.
Definition Stmt.h:3990
bool capturesVariable() const
Determine whether this capture handles a variable (by reference).
Definition Stmt.h:3993
SourceLocation getLocation() const
Retrieve the source location at which the variable or 'this' was first used.
Definition Stmt.h:3987
friend class ASTStmtReader
Definition Stmt.h:3969
This captures a statement into a function.
Definition Stmt.h:3949
unsigned capture_size() const
Retrieve the number of captures, including 'this'.
Definition Stmt.h:4105
const_capture_iterator capture_begin() const
Definition Stmt.h:4096
static CapturedStmt * CreateDeserialized(const ASTContext &Context, unsigned NumCaptures)
Definition Stmt.cpp:1471
SourceLocation getEndLoc() const LLVM_READONLY
Definition Stmt.h:4148
capture_init_range capture_inits()
Definition Stmt.h:4117
Expr ** capture_init_iterator
Iterator that walks over the capture initialization arguments.
Definition Stmt.h:4108
void setCapturedRegionKind(CapturedRegionKind Kind)
Set the captured region kind.
Definition Stmt.cpp:1513
const_capture_init_iterator capture_init_begin() const
Definition Stmt.h:4130
const Capture * const_capture_iterator
Definition Stmt.h:4083
CapturedDecl * getCapturedDecl()
Retrieve the outlined function declaration.
Definition Stmt.cpp:1493
SourceRange getSourceRange() const LLVM_READONLY
Definition Stmt.h:4152
capture_iterator capture_end() const
Retrieve an iterator pointing past the end of the sequence of captures.
Definition Stmt.h:4100
child_range children()
Definition Stmt.cpp:1484
const RecordDecl * getCapturedRecordDecl() const
Retrieve the record declaration for captured variables.
Definition Stmt.h:4070
llvm::iterator_range< const_capture_init_iterator > const_capture_init_range
Definition Stmt.h:4114
Stmt * getCapturedStmt()
Retrieve the statement being captured.
Definition Stmt.h:4053
llvm::iterator_range< capture_init_iterator > capture_init_range
Definition Stmt.h:4109
Capture * capture_iterator
An iterator that walks over the captures.
Definition Stmt.h:4082
llvm::iterator_range< capture_iterator > capture_range
Definition Stmt.h:4084
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:4156
capture_init_iterator capture_init_begin()
Retrieve the first initialization argument.
Definition Stmt.h:4126
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:4095
const_capture_init_iterator capture_init_end() const
Definition Stmt.h:4140
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.h:4144
void setCapturedRecordDecl(RecordDecl *D)
Set the record declaration for captured variables.
Definition Stmt.h:4073
friend class ASTStmtReader
Definition Stmt.h:4041
llvm::iterator_range< const_capture_iterator > capture_const_range
Definition Stmt.h:4085
capture_init_iterator capture_init_end()
Retrieve the iterator pointing one past the last initialization argument.
Definition Stmt.h:4136
capture_range captures()
Definition Stmt.h:4087
Expr *const * const_capture_init_iterator
Const iterator that walks over the capture initialization arguments.
Definition Stmt.h:4113
const Stmt * getCapturedStmt() const
Definition Stmt.h:4054
capture_const_range captures() const
Definition Stmt.h:4090
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:3953
const_capture_init_range capture_inits() const
Definition Stmt.h:4121
Stmt * getSubStmt()
Definition Stmt.h:2045
const Expr * getRHS() const
Definition Stmt.h:2033
Expr * getLHS()
Definition Stmt.h:2015
const_child_range children() const
Definition Stmt.h:2075
SourceLocation getBeginLoc() const
Definition Stmt.h:2054
void setEllipsisLoc(SourceLocation L)
Set the location of the ... in a case statement of the form LHS ... RHS.
Definition Stmt.h:2008
static bool classof(const Stmt *T)
Definition Stmt.h:2064
bool caseStmtIsGNURange() const
True if this case statement is of the form case LHS ... RHS, which is a GNU extension.
Definition Stmt.h:1995
const Expr * getLHS() const
Definition Stmt.h:2019
SourceLocation getEllipsisLoc() const
Get the location of the ... in a case statement of the form LHS ... RHS.
Definition Stmt.h:2001
void setCaseLoc(SourceLocation L)
Definition Stmt.h:1998
child_range children()
Definition Stmt.h:2069
SourceLocation getCaseLoc() const
Definition Stmt.h:1997
static CaseStmt * CreateEmpty(const ASTContext &Ctx, bool CaseStmtIsGNURange)
Build an empty case statement.
Definition Stmt.cpp:1317
void setLHS(Expr *Val)
Definition Stmt.h:2023
void setSubStmt(Stmt *S)
Definition Stmt.h:2050
const Stmt * getSubStmt() const
Definition Stmt.h:2046
Expr * getRHS()
Definition Stmt.h:2027
SourceLocation getEndLoc() const LLVM_READONLY
Definition Stmt.h:2055
void setRHS(Expr *Val)
Definition Stmt.h:2039
Represents a byte-granular source range.
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition Stmt.h:1752
Stmt * body_front()
Definition Stmt.h:1818
static bool classof(const Stmt *T)
Definition Stmt.h:1872
bool body_empty() const
Definition Stmt.h:1796
unsigned size() const
Definition Stmt.h:1797
body_const_range body() const
Definition Stmt.h:1827
Stmt *const * const_body_iterator
Definition Stmt.h:1824
const_reverse_body_iterator body_rend() const
Definition Stmt.h:1862
llvm::iterator_range< const_body_iterator > body_const_range
Definition Stmt.h:1825
std::reverse_iterator< body_iterator > reverse_body_iterator
Definition Stmt.h:1845
reverse_body_iterator body_rbegin()
Definition Stmt.h:1847
llvm::iterator_range< body_iterator > body_range
Definition Stmt.h:1813
std::reverse_iterator< const_body_iterator > const_reverse_body_iterator
Definition Stmt.h:1855
body_iterator body_end()
Definition Stmt.h:1817
FPOptionsOverride getStoredFPFeatures() const
Get FPOptionsOverride from trailing storage.
Definition Stmt.h:1802
const Stmt * body_front() const
Definition Stmt.h:1837
body_range body()
Definition Stmt.h:1815
SourceLocation getBeginLoc() const
Definition Stmt.h:1866
static CompoundStmt * CreateEmpty(const ASTContext &C, unsigned NumStmts, bool HasFPFeatures)
Definition Stmt.cpp:409
SourceLocation getLBracLoc() const
Definition Stmt.h:1869
body_iterator body_begin()
Definition Stmt.h:1816
SourceLocation getEndLoc() const
Definition Stmt.h:1867
bool hasStoredFPFeatures() const
Definition Stmt.h:1799
const_child_range children() const
Definition Stmt.h:1879
CompoundStmt(SourceLocation Loc, SourceLocation EndLoc)
Definition Stmt.h:1786
reverse_body_iterator body_rend()
Definition Stmt.h:1851
CompoundStmt(SourceLocation Loc)
Definition Stmt.h:1784
const_body_iterator body_begin() const
Definition Stmt.h:1831
Stmt ** body_iterator
Definition Stmt.h:1812
const Stmt * body_back() const
Definition Stmt.h:1841
friend class ASTStmtReader
Definition Stmt.h:1753
const_reverse_body_iterator body_rbegin() const
Definition Stmt.h:1858
child_range children()
Definition Stmt.h:1877
Stmt * body_back()
Definition Stmt.h:1820
FPOptionsOverride getStoredFPFeaturesOrDefault() const
Get the store FPOptionsOverride or default if not stored.
Definition Stmt.h:1808
SourceLocation getRBracLoc() const
Definition Stmt.h:1870
const_body_iterator body_end() const
Definition Stmt.h:1835
ContinueStmt(EmptyShell Empty)
Build an empty continue statement.
Definition Stmt.h:3138
ContinueStmt(SourceLocation CL)
Definition Stmt.h:3133
static bool classof(const Stmt *T)
Definition Stmt.h:3141
ContinueStmt(SourceLocation CL, SourceLocation LabelLoc, LabelDecl *Target)
Definition Stmt.h:3134
Decl *const * const_iterator
Definition DeclGroup.h:73
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition Stmt.h:1643
std::reverse_iterator< decl_iterator > reverse_decl_iterator
Definition Stmt.h:1702
llvm::iterator_range< decl_iterator > decl_range
Definition Stmt.h:1688
child_range children()
Definition Stmt.h:1676
const_child_range children() const
Definition Stmt.h:1681
Decl * getSingleDecl()
Definition Stmt.h:1659
SourceLocation getEndLoc() const
Definition Stmt.h:1666
const DeclGroupRef getDeclGroup() const
Definition Stmt.h:1661
DeclStmt(EmptyShell Empty)
Build an empty declaration statement.
Definition Stmt.h:1652
bool isSingleDecl() const
isSingleDecl - This method returns true if this DeclStmt refers to a single Decl.
Definition Stmt.h:1656
decl_iterator decl_end()
Definition Stmt.h:1698
const_decl_iterator decl_begin() const
Definition Stmt.h:1699
void setStartLoc(SourceLocation L)
Definition Stmt.h:1665
DeclGroupRef::const_iterator const_decl_iterator
Definition Stmt.h:1687
static bool classof(const Stmt *T)
Definition Stmt.h:1671
void setEndLoc(SourceLocation L)
Definition Stmt.h:1667
decl_iterator decl_begin()
Definition Stmt.h:1697
decl_range decls()
Definition Stmt.h:1691
void setDeclGroup(DeclGroupRef DGR)
Definition Stmt.h:1663
const Decl * getSingleDecl() const
Definition Stmt.h:1658
decl_const_range decls() const
Definition Stmt.h:1693
const_decl_iterator decl_end() const
Definition Stmt.h:1700
DeclGroupRef::iterator decl_iterator
Definition Stmt.h:1686
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.h:1669
DeclGroupRef getDeclGroup()
Definition Stmt.h:1662
reverse_decl_iterator decl_rend()
Definition Stmt.h:1708
llvm::iterator_range< const_decl_iterator > decl_const_range
Definition Stmt.h:1689
reverse_decl_iterator decl_rbegin()
Definition Stmt.h:1704
DeclStmt(DeclGroupRef dg, SourceLocation startLoc, SourceLocation endLoc)
Definition Stmt.h:1648
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
void setSubStmt(Stmt *S)
Definition Stmt.h:2095
const Stmt * getSubStmt() const
Definition Stmt.h:2094
child_range children()
Definition Stmt.h:2110
SourceLocation getEndLoc() const LLVM_READONLY
Definition Stmt.h:2101
void setDefaultLoc(SourceLocation L)
Definition Stmt.h:2098
SourceLocation getDefaultLoc() const
Definition Stmt.h:2097
DefaultStmt(EmptyShell Empty)
Build an empty default statement.
Definition Stmt.h:2090
static bool classof(const Stmt *T)
Definition Stmt.h:2105
DefaultStmt(SourceLocation DL, SourceLocation CL, Stmt *substmt)
Definition Stmt.h:2086
const_child_range children() const
Definition Stmt.h:2112
SourceLocation getBeginLoc() const
Definition Stmt.h:2100
Stmt * getSubStmt()
Definition Stmt.h:2093
const Stmt * getBody() const
Definition Stmt.h:3268
SourceLocation getEndLoc() const
Definition Stmt.h:3275
void setBody(Stmt *S)
Definition Stmt.h:3269
SourceLocation getBeginLoc() const
Definition Stmt.h:3274
void setDeferLoc(SourceLocation DeferLoc)
Definition Stmt.h:3263
Stmt * getBody()
Definition Stmt.h:3267
const_child_range children() const
Definition Stmt.h:3279
SourceLocation getDeferLoc() const
Definition Stmt.h:3262
static bool classof(const Stmt *S)
Definition Stmt.h:3283
static DeferStmt * CreateEmpty(ASTContext &Context, EmptyShell Empty)
Definition Stmt.cpp:1548
friend class ASTStmtReader
Definition Stmt.h:3249
child_range children()
Definition Stmt.h:3277
void setWhileLoc(SourceLocation L)
Definition Stmt.h:2876
SourceLocation getBeginLoc() const
Definition Stmt.h:2880
Stmt * getBody()
Definition Stmt.h:2869
Expr * getCond()
Definition Stmt.h:2862
void setDoLoc(SourceLocation L)
Definition Stmt.h:2874
SourceLocation getEndLoc() const
Definition Stmt.h:2881
SourceLocation getWhileLoc() const
Definition Stmt.h:2875
static bool classof(const Stmt *T)
Definition Stmt.h:2883
const_child_range children() const
Definition Stmt.h:2892
DoStmt(EmptyShell Empty)
Build an empty do-while statement.
Definition Stmt.h:2860
SourceLocation getDoLoc() const
Definition Stmt.h:2873
void setRParenLoc(SourceLocation L)
Definition Stmt.h:2878
SourceLocation getRParenLoc() const
Definition Stmt.h:2877
const Stmt * getBody() const
Definition Stmt.h:2870
child_range children()
Definition Stmt.h:2888
void setBody(Stmt *Body)
Definition Stmt.h:2871
DoStmt(Stmt *Body, Expr *Cond, SourceLocation DL, SourceLocation WL, SourceLocation RP)
Definition Stmt.h:2851
const Expr * getCond() const
Definition Stmt.h:2863
void setCond(Expr *Cond)
Definition Stmt.h:2867
This represents one expression.
Definition Expr.h:113
Represents difference between two FPOptions values.
Stmt * getInit()
Definition Stmt.h:2915
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:2971
VarDecl * getConditionVariable() const
Retrieve the variable declared in this "for" statement, if any.
Definition Stmt.cpp:1120
SourceLocation getEndLoc() const
Definition Stmt.h:2964
void setBody(Stmt *S)
Definition Stmt.h:2954
SourceLocation getRParenLoc() const
Definition Stmt.h:2960
const_child_range children() const
Definition Stmt.h:2975
void setCond(Expr *E)
Definition Stmt.h:2952
const DeclStmt * getConditionVariableDeclStmt() const
Definition Stmt.h:2934
void setForLoc(SourceLocation L)
Definition Stmt.h:2957
Stmt * getBody()
Definition Stmt.h:2944
const Expr * getInc() const
Definition Stmt.h:2948
ForStmt(EmptyShell Empty)
Build an empty for statement.
Definition Stmt.h:2913
void setInc(Expr *E)
Definition Stmt.h:2953
void setLParenLoc(SourceLocation L)
Definition Stmt.h:2959
Expr * getInc()
Definition Stmt.h:2943
const Expr * getCond() const
Definition Stmt.h:2947
void setInit(Stmt *S)
Definition Stmt.h:2951
void setConditionVariableDeclStmt(DeclStmt *CondVar)
Definition Stmt.h:2938
SourceLocation getBeginLoc() const
Definition Stmt.h:2963
static bool classof(const Stmt *T)
Definition Stmt.h:2966
const Stmt * getInit() const
Definition Stmt.h:2946
void setConditionVariable(const ASTContext &C, VarDecl *V)
Definition Stmt.cpp:1128
SourceLocation getForLoc() const
Definition Stmt.h:2956
friend class ASTStmtReader
Definition Stmt.h:2901
const Stmt * getBody() const
Definition Stmt.h:2949
Expr * getCond()
Definition Stmt.h:2942
SourceLocation getLParenLoc() const
Definition Stmt.h:2958
DeclStmt * getConditionVariableDeclStmt()
If this ForStmt has a condition variable, return the faux DeclStmt associated with the creation of th...
Definition Stmt.h:2930
void setRParenLoc(SourceLocation L)
Definition Stmt.h:2961
AsmStringPiece(const std::string &S)
Definition Stmt.h:3510
const std::string & getString() const
Definition Stmt.h:3519
unsigned getOperandNo() const
Definition Stmt.h:3521
CharSourceRange getRange() const
Definition Stmt.h:3526
AsmStringPiece(unsigned OpNo, const std::string &S, SourceLocation Begin, SourceLocation End)
Definition Stmt.h:3511
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:3596
const_labels_iterator end_labels() const
Definition Stmt.h:3639
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:3608
std::string generateAsmString(const ASTContext &C) const
Assemble final IR asm string.
Definition Stmt.cpp:872
labels_range labels()
Definition Stmt.h:3631
SourceLocation getRParenLoc() const
Definition Stmt.h:3480
std::string getAsmString() const
Definition Stmt.cpp:574
labels_const_range labels() const
Definition Stmt.h:3643
llvm::iterator_range< labels_iterator > labels_range
Definition Stmt.h:3620
Expr * getInputConstraintExpr(unsigned i)
Definition Stmt.h:3589
void setAsmStringExpr(Expr *E)
Definition Stmt.h:3487
labels_iterator begin_labels()
Definition Stmt.h:3623
IdentifierInfo * getInputIdentifier(unsigned i) const
Definition Stmt.h:3573
bool isAsmGoto() const
Definition Stmt.h:3604
ConstCastIterator< AddrLabelExpr > const_labels_iterator
Definition Stmt.h:3619
CastIterator< AddrLabelExpr > labels_iterator
Definition Stmt.h:3618
const Expr * getClobberExpr(unsigned i) const
Definition Stmt.h:3666
std::string getInputConstraint(unsigned i) const
getInputConstraint - Return the specified input constraint.
Definition Stmt.cpp:611
labels_iterator end_labels()
Definition Stmt.h:3627
const Expr * getOutputConstraintExpr(unsigned i) const
Definition Stmt.h:3560
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:3481
void setInputExpr(unsigned i, Expr *E)
Definition Stmt.cpp:597
Expr * getAsmStringExpr()
Definition Stmt.h:3486
std::string getClobber(unsigned i) const
Definition Stmt.cpp:578
static bool classof(const Stmt *T)
Definition Stmt.h:3671
StringRef getInputName(unsigned i) const
Definition Stmt.h:3577
SourceLocation getEndLoc() const LLVM_READONLY
Definition Stmt.h:3669
StringRef getOutputName(unsigned i) const
Definition Stmt.h:3551
const_labels_iterator begin_labels() const
Definition Stmt.h:3635
GCCAsmStmt(EmptyShell Empty)
Build an empty inline-assembly statement.
Definition Stmt.h:3478
IdentifierInfo * getLabelIdentifier(unsigned i) const
Definition Stmt.h:3612
const Expr * getInputConstraintExpr(unsigned i) const
Definition Stmt.h:3586
IdentifierInfo * getOutputIdentifier(unsigned i) const
Definition Stmt.h:3549
const Expr * getAsmStringExpr() const
Definition Stmt.h:3485
Expr * getOutputExpr(unsigned i)
Definition Stmt.cpp:582
llvm::iterator_range< const_labels_iterator > labels_const_range
Definition Stmt.h:3621
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:3563
Expr * getClobberExpr(unsigned i)
Definition Stmt.h:3665
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:3459
const Expr * getOutputExpr(unsigned i) const
Definition Stmt.h:3567
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.h:3668
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:2986
SourceLocation getLabelLoc() const
Definition Stmt.h:2999
SourceLocation getGotoLoc() const
Definition Stmt.h:2997
child_range children()
Definition Stmt.h:3010
void setLabel(LabelDecl *D)
Definition Stmt.h:2995
GotoStmt(EmptyShell Empty)
Build an empty goto statement.
Definition Stmt.h:2992
void setLabelLoc(SourceLocation L)
Definition Stmt.h:3000
LabelDecl * getLabel() const
Definition Stmt.h:2994
SourceLocation getEndLoc() const
Definition Stmt.h:3003
const_child_range children() const
Definition Stmt.h:3014
static bool classof(const Stmt *T)
Definition Stmt.h:3005
void setGotoLoc(SourceLocation L)
Definition Stmt.h:2998
SourceLocation getBeginLoc() const
Definition Stmt.h:3002
One of these records is kept for each identifier that is lexed.
Stmt * getThen()
Definition Stmt.h:2360
bool hasElseStorage() const
True if this IfStmt has storage for an else statement.
Definition Stmt.h:2346
const Stmt * getElse() const
Definition Stmt.h:2374
void setThen(Stmt *Then)
Definition Stmt.h:2365
void setConditionVariableDeclStmt(DeclStmt *CondVar)
Definition Stmt.h:2416
void setCond(Expr *Cond)
Definition Stmt.h:2356
void setLParenLoc(SourceLocation Loc)
Definition Stmt.h:2490
SourceLocation getIfLoc() const
Definition Stmt.h:2437
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:2343
const DeclStmt * getConditionVariableDeclStmt() const
Definition Stmt.h:2410
IfStatementKind getStatementKind() const
Definition Stmt.h:2472
SourceLocation getElseLoc() const
Definition Stmt.h:2440
Stmt * getInit()
Definition Stmt.h:2421
bool isNonNegatedConsteval() const
Definition Stmt.h:2456
SourceLocation getLParenLoc() const
Definition Stmt.h:2489
static bool classof(const Stmt *T)
Definition Stmt.h:2514
void setElse(Stmt *Else)
Definition Stmt.h:2379
Expr * getCond()
Definition Stmt.h:2348
const Stmt * getThen() const
Definition Stmt.h:2361
bool isConstexpr() const
Definition Stmt.h:2464
const Expr * getCond() const
Definition Stmt.h:2352
const VarDecl * getConditionVariable() const
Definition Stmt.h:2394
void setElseLoc(SourceLocation ElseLoc)
Definition Stmt.h:2445
const Stmt * getInit() const
Definition Stmt.h:2426
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:2340
void setStatementKind(IfStatementKind Kind)
Definition Stmt.h:2468
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:2496
bool isNegatedConsteval() const
Definition Stmt.h:2460
Stmt * getElse()
Definition Stmt.h:2369
DeclStmt * getConditionVariableDeclStmt()
If this IfStmt has a condition variable, return the faux DeclStmt associated with the creation of tha...
Definition Stmt.h:2404
const_child_range children() const
Definition Stmt.h:2505
SourceLocation getRParenLoc() const
Definition Stmt.h:2491
void setRParenLoc(SourceLocation Loc)
Definition Stmt.h:2492
SourceLocation getBeginLoc() const
Definition Stmt.h:2483
SourceLocation getEndLoc() const LLVM_READONLY
Definition Stmt.h:2484
bool isConsteval() const
Definition Stmt.h:2451
void setIfLoc(SourceLocation IfLoc)
Definition Stmt.h:2438
VarDecl * getConditionVariable()
Retrieve the variable declared in this "if" statement, if any.
Definition Stmt.cpp:1068
void setInit(Stmt *Init)
Definition Stmt.h:2431
SourceLocation getEndLoc() const LLVM_READONLY
Definition Stmt.h:3054
static bool classof(const Stmt *T)
Definition Stmt.h:3056
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:3025
void setTarget(Expr *E)
Definition Stmt.h:3044
SourceLocation getGotoLoc() const
Definition Stmt.h:3036
SourceLocation getBeginLoc() const
Definition Stmt.h:3053
child_range children()
Definition Stmt.h:3061
void setGotoLoc(SourceLocation L)
Definition Stmt.h:3035
const_child_range children() const
Definition Stmt.h:3063
const LabelDecl * getConstantTarget() const
Definition Stmt.h:3049
void setStarLoc(SourceLocation L)
Definition Stmt.h:3037
IndirectGotoStmt(EmptyShell Empty)
Build an empty indirect goto statement.
Definition Stmt.h:3032
const Expr * getTarget() const
Definition Stmt.h:3041
SourceLocation getStarLoc() const
Definition Stmt.h:3038
Represents the declaration of a label.
Definition Decl.h:524
Stmt * getInnermostLabeledStmt()
Definition Stmt.h:2191
LabelStmt(SourceLocation IL, LabelDecl *D, Stmt *substmt)
Build a label statement.
Definition Stmt.h:2165
static bool classof(const Stmt *T)
Definition Stmt.h:2202
LabelDecl * getDecl() const
Definition Stmt.h:2176
LabelStmt(EmptyShell Empty)
Build an empty label statement.
Definition Stmt.h:2171
bool isSideEntry() const
Definition Stmt.h:2205
Stmt * getSubStmt()
Definition Stmt.h:2180
SourceLocation getIdentLoc() const
Definition Stmt.h:2173
void setSubStmt(Stmt *SS)
Definition Stmt.h:2183
void setDecl(LabelDecl *D)
Definition Stmt.h:2177
SourceLocation getBeginLoc() const
Definition Stmt.h:2185
void setIdentLoc(SourceLocation L)
Definition Stmt.h:2174
const_child_range children() const
Definition Stmt.h:2198
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:2186
child_range children()
Definition Stmt.h:2196
void setSideEntry(bool SE)
Definition Stmt.h:2206
const char * getName() const
Definition Stmt.cpp:437
const Stmt * getSubStmt() const
Definition Stmt.h:2182
SourceLocation getBeginLoc() const
Definition Stmt.h:3097
LoopControlStmt(StmtClass Class, SourceLocation Loc)
Definition Stmt.h:3088
LoopControlStmt(StmtClass Class, EmptyShell ES)
Definition Stmt.h:3091
void setLabelDecl(LabelDecl *S)
Definition Stmt.h:3109
LoopControlStmt(StmtClass Class, SourceLocation Loc, SourceLocation LabelLoc, LabelDecl *Target)
Definition Stmt.h:3082
static bool classof(const Stmt *T)
Definition Stmt.h:3124
SourceLocation getLabelLoc() const
Definition Stmt.h:3104
LabelDecl * getLabelDecl()
Definition Stmt.h:3107
const LabelDecl * getLabelDecl() const
Definition Stmt.h:3108
void setLabelLoc(SourceLocation L)
Definition Stmt.h:3105
const_child_range children() const
Definition Stmt.h:3120
SourceLocation getKwLoc() const
Definition Stmt.h:3094
child_range children()
Definition Stmt.h:3116
void setKwLoc(SourceLocation L)
Definition Stmt.h:3095
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:3102
SourceLocation getEndLoc() const
Definition Stmt.h:3098
Token * getAsmToks()
Definition Stmt.h:3708
const Expr * getOutputExpr(unsigned i) const
Definition Stmt.h:3725
Expr * getOutputExpr(unsigned i)
Definition Stmt.cpp:919
ArrayRef< StringRef > getClobbers() const
Definition Stmt.h:3749
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.h:3763
StringRef getAsmString() const
Definition Stmt.h:3711
child_range children()
Definition Stmt.h:3769
SourceLocation getLBraceLoc() const
Definition Stmt.h:3700
bool hasBraces() const
Definition Stmt.h:3705
SourceLocation getEndLoc() const
Definition Stmt.h:3702
StringRef getInputConstraint(unsigned i) const
Definition Stmt.h:3731
void setEndLoc(SourceLocation L)
Definition Stmt.h:3703
void setInputExpr(unsigned i, Expr *E)
Definition Stmt.cpp:927
StringRef getOutputConstraint(unsigned i) const
Definition Stmt.h:3718
ArrayRef< StringRef > getAllConstraints() const
Definition Stmt.h:3745
static bool classof(const Stmt *T)
Definition Stmt.h:3765
friend class ASTStmtReader
Definition Stmt.h:3678
StringRef getClobber(unsigned i) const
Definition Stmt.h:3755
const Expr * getInputExpr(unsigned i) const
Definition Stmt.h:3739
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:3707
void setLBraceLoc(SourceLocation L)
Definition Stmt.h:3701
MSAsmStmt(EmptyShell Empty)
Build an empty MS-style inline-assembly statement.
Definition Stmt.h:3698
std::string generateAsmString(const ASTContext &C) const
Assemble final IR asm string.
Definition Stmt.cpp:893
const_child_range children() const
Definition Stmt.h:3773
ArrayRef< Expr * > getAllExprs() const
Definition Stmt.h:3751
Expr * getInputExpr(unsigned i)
Definition Stmt.cpp:923
void setSemiLoc(SourceLocation L)
Definition Stmt.h:1727
bool hasLeadingEmptyMacro() const
Definition Stmt.h:1729
SourceLocation getBeginLoc() const
Definition Stmt.h:1733
child_range children()
Definition Stmt.h:1740
SourceLocation getSemiLoc() const
Definition Stmt.h:1726
static bool classof(const Stmt *T)
Definition Stmt.h:1736
NullStmt(SourceLocation L, bool hasLeadingEmptyMacro=false)
Definition Stmt.h:1717
NullStmt(EmptyShell Empty)
Build an empty null statement.
Definition Stmt.h:1724
const_child_range children() const
Definition Stmt.h:1744
SourceLocation getEndLoc() const
Definition Stmt.h:1734
Represents a struct/union/class.
Definition Decl.h:4459
void setRetValue(Expr *E)
Definition Stmt.h:3201
void setReturnLoc(SourceLocation L)
Definition Stmt.h:3222
SourceLocation getReturnLoc() const
Definition Stmt.h:3221
static bool classof(const Stmt *T)
Definition Stmt.h:3229
SourceLocation getEndLoc() const LLVM_READONLY
Definition Stmt.h:3225
void setNRVOCandidate(const VarDecl *Var)
Set the variable that might be used for the named return value optimization.
Definition Stmt.h:3215
SourceLocation getBeginLoc() const
Definition Stmt.h:3224
const VarDecl * getNRVOCandidate() const
Retrieve the variable that might be used for the named return value optimization.
Definition Stmt.h:3208
const_child_range children() const
Definition Stmt.h:3240
Expr * getRetValue()
Definition Stmt.h:3199
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:3234
const Expr * getRetValue() const
Definition Stmt.h:3200
const_child_range children() const
Definition Stmt.h:3813
child_range children()
Definition Stmt.h:3809
CompoundStmt * getBlock() const
Definition Stmt.h:3805
friend class ASTReader
Definition Stmt.h:3779
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.h:3796
SourceLocation getExceptLoc() const
Definition Stmt.h:3798
friend class ASTStmtReader
Definition Stmt.h:3780
SourceLocation getEndLoc() const
Definition Stmt.h:3799
static bool classof(const Stmt *T)
Definition Stmt.h:3817
Expr * getFilterExpr() const
Definition Stmt.h:3801
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.h:3837
SourceLocation getEndLoc() const
Definition Stmt.h:3840
const_child_range children() const
Definition Stmt.h:3848
child_range children()
Definition Stmt.h:3844
friend class ASTReader
Definition Stmt.h:3823
SourceLocation getFinallyLoc() const
Definition Stmt.h:3839
static bool classof(const Stmt *T)
Definition Stmt.h:3852
friend class ASTStmtReader
Definition Stmt.h:3824
CompoundStmt * getBlock() const
Definition Stmt.h:3842
SourceLocation getLeaveLoc() const
Definition Stmt.h:3920
child_range children()
Definition Stmt.h:3931
SourceLocation getEndLoc() const LLVM_READONLY
Definition Stmt.h:3924
SEHLeaveStmt(EmptyShell Empty)
Build an empty __leave statement.
Definition Stmt.h:3918
SEHLeaveStmt(SourceLocation LL)
Definition Stmt.h:3914
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.h:3923
static bool classof(const Stmt *T)
Definition Stmt.h:3926
void setLeaveLoc(SourceLocation L)
Definition Stmt.h:3921
const_child_range children() const
Definition Stmt.h:3935
child_range children()
Definition Stmt.h:3896
const_child_range children() const
Definition Stmt.h:3900
CompoundStmt * getTryBlock() const
Definition Stmt.h:3886
static bool classof(const Stmt *T)
Definition Stmt.h:3904
SourceLocation getTryLoc() const
Definition Stmt.h:3881
bool getIsCXXTry() const
Definition Stmt.h:3884
SEHFinallyStmt * getFinallyHandler() const
Definition Stmt.cpp:1343
friend class ASTReader
Definition Stmt.h:3858
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.h:3879
friend class ASTStmtReader
Definition Stmt.h:3859
SourceLocation getEndLoc() const
Definition Stmt.h:3882
SEHExceptStmt * getExceptHandler() const
Returns 0 if not defined.
Definition Stmt.cpp:1339
Stmt * getHandler() const
Definition Stmt.h:3890
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:1407
LoopControlStmtBitfields LoopControlStmtBits
Definition Stmt.h:1349
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:1363
CXXUnresolvedConstructExprBitfields CXXUnresolvedConstructExprBits
Definition Stmt.h:1397
WhileStmtBitfields WhileStmtBits
Definition Stmt.h:1345
SwitchCaseBitfields SwitchCaseBits
Definition Stmt.h:1351
GenericSelectionExprBitfields GenericSelectionExprBits
Definition Stmt.h:1371
ObjCObjectLiteralBitfields ObjCObjectLiteralBits
Definition Stmt.h:1415
InitListExprBitfields InitListExprBits
Definition Stmt.h:1369
static void EnableStatistics()
Definition Stmt.cpp:144
LambdaExprBitfields LambdaExprBits
Definition Stmt.h:1404
AttributedStmtBitfields AttributedStmtBits
Definition Stmt.h:1342
Stmt(StmtClass SC)
Definition Stmt.h:1496
ParenListExprBitfields ParenListExprBits
Definition Stmt.h:1370
ArrayOrMatrixSubscriptExprBitfields ArrayOrMatrixSubscriptExprBits
Definition Stmt.h:1364
UnresolvedLookupExprBitfields UnresolvedLookupExprBits
Definition Stmt.h:1400
SwitchStmtBitfields SwitchStmtBits
Definition Stmt.h:1344
SubstNonTypeTemplateParmExprBitfields SubstNonTypeTemplateParmExprBits
Definition Stmt.h:1403
CXXNoexceptExprBitfields CXXNoexceptExprBits
Definition Stmt.h:1402
ParenExprBitfields ParenExprBits
Definition Stmt.h:1374
StmtIterator child_iterator
Child Iterators: All subclasses must implement 'children' to permit easy iteration over the substatem...
Definition Stmt.h:1591
CXXRewrittenBinaryOperatorBitfields CXXRewrittenBinaryOperatorBits
Definition Stmt.h:1383
CallExprBitfields CallExprBits
Definition Stmt.h:1365
Stmt * stripLabelLikeStatements()
Definition Stmt.h:1583
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:1476
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:1375
ExprWithCleanupsBitfields ExprWithCleanupsBits
Definition Stmt.h:1396
FloatingLiteralBitfields FloatingLiteralBits
Definition Stmt.h:1359
const_child_range children() const
Definition Stmt.h:1599
child_iterator child_begin()
Definition Stmt.h:1603
void printJson(raw_ostream &Out, PrinterHelper *Helper, const PrintingPolicy &Policy, bool AddQuotes) const
Pretty-prints in JSON format.
StmtClass getStmtClass() const
Definition Stmt.h:1505
CXXScalarValueInitExprBitfields CXXScalarValueInitExprBits
Definition Stmt.h:1390
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:1361
OverloadExprBitfields OverloadExprBits
Definition Stmt.h:1399
CXXConstructExprBitfields CXXConstructExprBits
Definition Stmt.h:1395
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:1362
static std::tuple< bool, const Attr *, const Attr * > determineLikelihoodConflict(const Stmt *Then, const Stmt *Else)
Definition Stmt.cpp:198
CXXDependentScopeMemberExprBitfields CXXDependentScopeMemberExprBits
Definition Stmt.h:1398
static void PrintStats()
Definition Stmt.cpp:108
GotoStmtBitfields GotoStmtBits
Definition Stmt.h:1348
child_iterator child_end()
Definition Stmt.h:1604
ConstCastIterator< Expr > ConstExprIterator
Definition Stmt.h:1479
TypeTraitExprBitfields TypeTraitExprBits
Definition Stmt.h:1393
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:1391
SourceLocExprBitfields SourceLocExprBits
Definition Stmt.h:1373
CXXNullPtrLiteralExprBitfields CXXNullPtrLiteralExprBits
Definition Stmt.h:1385
CoawaitExprBitfields CoawaitBits
Definition Stmt.h:1412
Stmt(StmtClass SC, EmptyShell)
Construct an empty statement.
Definition Stmt.h:1487
ChooseExprBitfields ChooseExprBits
Definition Stmt.h:1379
ConstantExprBitfields ConstantExprBits
Definition Stmt.h:1356
llvm::iterator_range< child_iterator > child_range
Definition Stmt.h:1594
DeferStmtBitfields DeferStmtBits
Definition Stmt.h:1352
CompoundStmtBitfields CompoundStmtBits
Definition Stmt.h:1340
RequiresExprBitfields RequiresExprBits
Definition Stmt.h:1405
CXXFoldExprBitfields CXXFoldExprBits
Definition Stmt.h:1408
StmtExprBitfields StmtExprBits
Definition Stmt.h:1378
StringLiteralBitfields StringLiteralBits
Definition Stmt.h:1360
OpaqueValueExprBitfields OpaqueValueExprBits
Definition Stmt.h:1419
CastExprBitfields CastExprBits
Definition Stmt.h:1367
Likelihood
The likelihood of a branch being taken.
Definition Stmt.h:1448
@ LH_Unlikely
Branch has the [[unlikely]] attribute.
Definition Stmt.h:1449
@ LH_None
No attribute set or branches of the IfStmt have the same attribute.
Definition Stmt.h:1450
@ LH_Likely
Branch has the [[likely]] attribute.
Definition Stmt.h:1452
CXXThrowExprBitfields CXXThrowExprBits
Definition Stmt.h:1387
static void addStmtClass(const StmtClass s)
Definition Stmt.cpp:139
MemberExprBitfields MemberExprBits
Definition Stmt.h:1366
PackIndexingExprBitfields PackIndexingExprBits
Definition Stmt.h:1409
friend class ASTStmtWriter
Definition Stmt.h:101
ForStmtBitfields ForStmtBits
Definition Stmt.h:1347
@ NumOverloadExprBits
Definition Stmt.h:1122
DeclRefExprBitfields DeclRefExprBits
Definition Stmt.h:1358
const_child_iterator child_end() const
Definition Stmt.h:1607
const char * getStmtClassName() const
Definition Stmt.cpp:86
ConstStmtIterator const_child_iterator
Definition Stmt.h:1592
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:1384
CXXOperatorCallExprBitfields CXXOperatorCallExprBits
Definition Stmt.h:1382
Stmt(Stmt &&)=delete
CXXDefaultInitExprBitfields CXXDefaultInitExprBits
Definition Stmt.h:1389
Stmt & operator=(const Stmt &)=delete
NullStmtBitfields NullStmtBits
Definition Stmt.h:1339
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:1394
friend class ASTStmtReader
Definition Stmt.h:100
ArrayTypeTraitExprBitfields ArrayTypeTraitExprBits
Definition Stmt.h:1406
StmtBitfields StmtBits
Definition Stmt.h:1338
IfStmtBitfields IfStmtBits
Definition Stmt.h:1343
Stmt & operator=(Stmt &&)=delete
PredefinedExprBitfields PredefinedExprBits
Definition Stmt.h:1357
ConvertVectorExprBitfields ConvertVectorExprBits
Definition Stmt.h:1420
@ NumExprBits
Definition Stmt.h:366
int64_t getID(const ASTContext &Context) const
Definition Stmt.cpp:379
ReturnStmtBitfields ReturnStmtBits
Definition Stmt.h:1350
LabelStmtBitfields LabelStmtBits
Definition Stmt.h:1341
ObjCIndirectCopyRestoreExprBitfields ObjCIndirectCopyRestoreExprBits
Definition Stmt.h:1416
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:1368
Stmt()=delete
UnresolvedMemberExprBitfields UnresolvedMemberExprBits
Definition Stmt.h:1401
PseudoObjectExprBitfields PseudoObjectExprBits
Definition Stmt.h:1372
ExprBitfields ExprBits
Definition Stmt.h:1355
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:1595
const_child_iterator child_begin() const
Definition Stmt.h:1606
CXXDeleteExprBitfields CXXDeleteExprBits
Definition Stmt.h:1392
CXXDefaultArgExprBitfields CXXDefaultArgExprBits
Definition Stmt.h:1388
DoStmtBitfields DoStmtBits
Definition Stmt.h:1346
@ NumCallExprBits
Definition Stmt.h:582
CXXThisExprBitfields CXXThisExprBits
Definition Stmt.h:1386
CastIterator< Expr > ExprIterator
Definition Stmt.h:1478
StringLiteral - This represents a string literal expression, e.g.
Definition Expr.h:1819
SwitchCase * NextSwitchCase
A pointer to the following CaseStmt or DefaultStmt class, used by SwitchStmt.
Definition Stmt.h:1895
void setColonLoc(SourceLocation L)
Definition Stmt.h:1912
static bool classof(const Stmt *T)
Definition Stmt.h:1922
SwitchCase(StmtClass SC, EmptyShell)
Definition Stmt.h:1902
SourceLocation getKeywordLoc() const
Definition Stmt.h:1909
Stmt * getSubStmt()
Definition Stmt.h:2125
SwitchCase(StmtClass SC, SourceLocation KWLoc, SourceLocation ColonLoc)
Definition Stmt.h:1897
void setKeywordLoc(SourceLocation L)
Definition Stmt.h:1910
const Stmt * getSubStmt() const
Definition Stmt.h:1915
void setNextSwitchCase(SwitchCase *SC)
Definition Stmt.h:1907
SourceLocation getColonLoc() const
Definition Stmt.h:1911
SourceLocation getBeginLoc() const
Definition Stmt.h:1919
const SwitchCase * getNextSwitchCase() const
Definition Stmt.h:1905
SourceLocation ColonLoc
The location of the ":".
Definition Stmt.h:1888
SourceLocation getEndLoc() const LLVM_READONLY
Definition Stmt.h:2117
SwitchCase * getNextSwitchCase()
Definition Stmt.h:1906
void setCond(Expr *Cond)
Definition Stmt.h:2592
const Stmt * getInit() const
Definition Stmt.h:2605
SourceLocation getSwitchLoc() const
Definition Stmt.h:2656
void addSwitchCase(SwitchCase *SC)
Definition Stmt.h:2668
void setBody(Stmt *S, SourceLocation SL)
Definition Stmt.h:2663
SourceLocation getLParenLoc() const
Definition Stmt.h:2658
const Expr * getCond() const
Definition Stmt.h:2588
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:2681
void setSwitchLoc(SourceLocation L)
Definition Stmt.h:2657
void setConditionVariableDeclStmt(DeclStmt *CondVar)
Definition Stmt.h:2647
void setBody(Stmt *Body)
Definition Stmt.h:2599
void setRParenLoc(SourceLocation Loc)
Definition Stmt.h:2661
SourceLocation getEndLoc() const LLVM_READONLY
Definition Stmt.h:2686
SourceLocation getRParenLoc() const
Definition Stmt.h:2660
void setInit(Stmt *Init)
Definition Stmt.h:2609
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:2659
child_range children()
Definition Stmt.h:2692
const Stmt * getBody() const
Definition Stmt.h:2597
const VarDecl * getConditionVariable() const
Definition Stmt.h:2625
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:2641
Expr * getCond()
Definition Stmt.h:2584
bool hasVarStorage() const
True if this SwitchStmt has storage for a condition variable.
Definition Stmt.h:2582
Stmt * getBody()
Definition Stmt.h:2596
const_child_range children() const
Definition Stmt.h:2697
VarDecl * getConditionVariable()
Retrieve the variable declared in this "switch" statement, if any.
Definition Stmt.cpp:1186
Stmt * getInit()
Definition Stmt.h:2601
SourceLocation getBeginLoc() const
Definition Stmt.h:2685
bool hasInitStorage() const
True if this SwitchStmt has storage for an init statement.
Definition Stmt.h:2579
SwitchCase * getSwitchCaseList()
Definition Stmt.h:2652
const SwitchCase * getSwitchCaseList() const
Definition Stmt.h:2653
DeclStmt * getConditionVariableDeclStmt()
If this SwitchStmt has a condition variable, return the faux DeclStmt associated with the creation of...
Definition Stmt.h:2635
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:2677
void setSwitchCaseList(SwitchCase *SC)
Definition Stmt.h:2654
static bool classof(const Stmt *T)
Definition Stmt.h:2702
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:2139
const Expr * getExprStmt() const
Definition Stmt.cpp:420
Stmt(StmtClass SC, EmptyShell)
Construct an empty statement.
Definition Stmt.h:1487
static bool classof(const Stmt *T)
Definition Stmt.h:2150
Expr * getExprStmt()
Definition Stmt.h:2145
Represents a variable declaration or definition.
Definition Decl.h:932
Expr * getCond()
Definition Stmt.h:2761
SourceLocation getWhileLoc() const
Definition Stmt.h:2814
void setCond(Expr *Cond)
Definition Stmt.h:2769
SourceLocation getRParenLoc() const
Definition Stmt.h:2819
DeclStmt * getConditionVariableDeclStmt()
If this WhileStmt has a condition variable, return the faux DeclStmt associated with the creation of ...
Definition Stmt.h:2797
void setBody(Stmt *Body)
Definition Stmt.h:2776
void setLParenLoc(SourceLocation L)
Definition Stmt.h:2818
VarDecl * getConditionVariable()
Retrieve the variable declared in this "while" statement, if any.
Definition Stmt.cpp:1247
SourceLocation getEndLoc() const LLVM_READONLY
Definition Stmt.h:2823
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:2759
SourceLocation getLParenLoc() const
Definition Stmt.h:2817
SourceLocation getBeginLoc() const
Definition Stmt.h:2822
const Stmt * getBody() const
Definition Stmt.h:2774
void setRParenLoc(SourceLocation L)
Definition Stmt.h:2820
const VarDecl * getConditionVariable() const
Definition Stmt.h:2787
void setWhileLoc(SourceLocation L)
Definition Stmt.h:2815
const Expr * getCond() const
Definition Stmt.h:2765
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:2803
void setConditionVariableDeclStmt(DeclStmt *CondVar)
Definition Stmt.h:2809
static bool classof(const Stmt *T)
Definition Stmt.h:2827
const_child_range children() const
Definition Stmt.h:2837
child_range children()
Definition Stmt.h:2832
Stmt * getBody()
Definition Stmt.h:2773
Definition SPIR.cpp:35
Top level wrappers for InstallAPI frontend operations.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
ConstantResultStorageKind
Describes the kind of result that can be tail-allocated.
Definition Expr.h:1096
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:1544
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:1783
U cast(CodeGen::Address addr)
Definition Address.h:327
SourceLocIdentKind
Definition Expr.h:5033
@ Class
The "class" keyword introduces the elaborated-type-specifier.
Definition TypeBase.h:6031
CXXNewInitializationStyle
Definition ExprCXX.h:2244
PredefinedIdentKind
Definition Expr.h:2009
CharacterLiteralKind
Definition Expr.h:1623
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:1463
typename CastIterator::iterator_adaptor_base Base
Definition Stmt.h:1464
CastIterator(StmtPtr *I)
Definition Stmt.h:1467
Base::value_type operator*() const
Definition Stmt.h:1469
A placeholder type used to construct an empty shell of a type, that will be filled in later (e....
Definition Stmt.h:1445