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