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