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