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