clang 24.0.0git
Expr.h
Go to the documentation of this file.
1//===--- Expr.h - Classes for representing expressions ----------*- 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 Expr interface and subclasses.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_AST_EXPR_H
14#define LLVM_CLANG_AST_EXPR_H
15
17#include "clang/AST/APValue.h"
18#include "clang/AST/ASTVector.h"
20#include "clang/AST/Decl.h"
24#include "clang/AST/Stmt.h"
26#include "clang/AST/TypeBase.h"
31#include "llvm/ADT/APFloat.h"
32#include "llvm/ADT/APSInt.h"
33#include "llvm/ADT/SmallVector.h"
34#include "llvm/ADT/StringRef.h"
35#include "llvm/ADT/iterator.h"
36#include "llvm/ADT/iterator_range.h"
37#include "llvm/Support/AtomicOrdering.h"
38#include "llvm/Support/Compiler.h"
39#include "llvm/Support/TrailingObjects.h"
40#include <optional>
41
42namespace clang {
43 class AllocSizeAttr;
44 class APValue;
45 class ASTContext;
46 class BlockDecl;
47 class CXXBaseSpecifier;
50 class CastExpr;
51 class Decl;
52 class IdentifierInfo;
54 class NamedDecl;
56 class OpaqueValueExpr;
57 class ParmVarDecl;
58 class StringLiteral;
59 class TargetInfo;
60 class ValueDecl;
61 class WarnUnusedResultAttr;
62
63/// A simple array of base specifiers.
65
66/// An adjustment to be made to the temporary created when emitting a
67/// reference binding, which accesses a particular subobject of that temporary.
69 enum {
73 } Kind;
74
75 struct DTB {
78 };
79
80 struct P {
83 };
84
85 union {
88 struct P Ptr;
89 };
90
92 const CXXRecordDecl *DerivedClass)
94 DerivedToBase.BasePath = BasePath;
95 DerivedToBase.DerivedClass = DerivedClass;
96 }
97
99 this->Field = Field;
100 }
101
104 this->Ptr.MPT = MPT;
105 this->Ptr.RHS = RHS;
106 }
107};
108
109/// This represents one expression. Note that Expr's are subclasses of Stmt.
110/// This allows an expression to be transparently used any place a Stmt is
111/// required.
112class Expr : public ValueStmt {
113 QualType TR;
114
115public:
116 Expr() = delete;
117 Expr(const Expr&) = delete;
118 Expr(Expr &&) = delete;
119 Expr &operator=(const Expr&) = delete;
120 Expr &operator=(Expr&&) = delete;
121
122protected:
124 : ValueStmt(SC) {
125 ExprBits.Dependent = 0;
126 ExprBits.ValueKind = VK;
127 ExprBits.ObjectKind = OK;
128 assert(ExprBits.ObjectKind == OK && "truncated kind");
129 setType(T);
130 }
131
132 /// Construct an empty expression.
133 explicit Expr(StmtClass SC, EmptyShell) : ValueStmt(SC) { }
134
135 /// Each concrete expr subclass is expected to compute its dependence and call
136 /// this in the constructor.
138 ExprBits.Dependent = static_cast<unsigned>(Deps);
139 }
140 friend class ASTImporter; // Sets dependence directly.
141 friend class ASTStmtReader; // Sets dependence directly.
142
143public:
144 QualType getType() const { return TR; }
146 // In C++, the type of an expression is always adjusted so that it
147 // will not have reference type (C++ [expr]p6). Use
148 // QualType::getNonReferenceType() to retrieve the non-reference
149 // type. Additionally, inspect Expr::isLvalue to determine whether
150 // an expression that is adjusted in this manner should be
151 // considered an lvalue.
152 assert((t.isNull() || !t->isReferenceType()) &&
153 "Expressions can't have reference type");
154
155 TR = t;
156 }
157
158 /// If this expression is an enumeration constant, return the
159 /// enumeration type under which said constant was declared.
160 /// Otherwise return the expression's type.
161 /// Note this effectively circumvents the weak typing of C's enum constants
162 QualType getEnumCoercedType(const ASTContext &Ctx) const;
163
165 return static_cast<ExprDependence>(ExprBits.Dependent);
166 }
167
168 /// Determines whether the value of this expression depends on
169 /// - a template parameter (C++ [temp.dep.constexpr])
170 /// - or an error, whose resolution is unknown
171 ///
172 /// For example, the array bound of "Chars" in the following example is
173 /// value-dependent.
174 /// @code
175 /// template<int Size, char (&Chars)[Size]> struct meta_string;
176 /// @endcode
177 bool isValueDependent() const {
178 return static_cast<bool>(getDependence() & ExprDependence::Value);
179 }
180
181 /// Determines whether the type of this expression depends on
182 /// - a template parameter (C++ [temp.dep.expr], which means that its type
183 /// could change from one template instantiation to the next)
184 /// - or an error
185 ///
186 /// For example, the expressions "x" and "x + y" are type-dependent in
187 /// the following code, but "y" is not type-dependent:
188 /// @code
189 /// template<typename T>
190 /// void add(T x, int y) {
191 /// x + y;
192 /// }
193 /// @endcode
194 bool isTypeDependent() const {
195 return static_cast<bool>(getDependence() & ExprDependence::Type);
196 }
197
198 /// Whether this expression is instantiation-dependent, meaning that
199 /// it depends in some way on
200 /// - a template parameter (even if neither its type nor (constant) value
201 /// can change due to the template instantiation)
202 /// - or an error
203 ///
204 /// In the following example, the expression \c sizeof(sizeof(T() + T())) is
205 /// instantiation-dependent (since it involves a template parameter \c T), but
206 /// is neither type- nor value-dependent, since the type of the inner
207 /// \c sizeof is known (\c std::size_t) and therefore the size of the outer
208 /// \c sizeof is known.
209 ///
210 /// \code
211 /// template<typename T>
212 /// void f(T x, T y) {
213 /// sizeof(sizeof(T() + T());
214 /// }
215 /// \endcode
216 ///
217 /// \code
218 /// void func(int) {
219 /// func(); // the expression is instantiation-dependent, because it depends
220 /// // on an error.
221 /// }
222 /// \endcode
224 return static_cast<bool>(getDependence() & ExprDependence::Instantiation);
225 }
226
227 /// Whether this expression contains an unexpanded parameter
228 /// pack (for C++11 variadic templates).
229 ///
230 /// Given the following function template:
231 ///
232 /// \code
233 /// template<typename F, typename ...Types>
234 /// void forward(const F &f, Types &&...args) {
235 /// f(static_cast<Types&&>(args)...);
236 /// }
237 /// \endcode
238 ///
239 /// The expressions \c args and \c static_cast<Types&&>(args) both
240 /// contain parameter packs.
242 return static_cast<bool>(getDependence() & ExprDependence::UnexpandedPack);
243 }
244
245 /// Whether this expression contains subexpressions which had errors.
246 bool containsErrors() const {
247 return static_cast<bool>(getDependence() & ExprDependence::Error);
248 }
249
250 /// getExprLoc - Return the preferred location for the arrow when diagnosing
251 /// a problem with a generic expression.
252 SourceLocation getExprLoc() const LLVM_READONLY;
253
254 /// Determine whether an lvalue-to-rvalue conversion should implicitly be
255 /// applied to this expression if it appears as a discarded-value expression
256 /// in C++11 onwards. This applies to certain forms of volatile glvalues.
258
259 /// isUnusedResultAWarning - Return true if this immediate expression should
260 /// be warned about if the result is unused. If so, fill in expr, location,
261 /// and ranges with expr to warn on and source locations/ranges appropriate
262 /// for a warning.
263 bool isUnusedResultAWarning(const Expr *&WarnExpr, SourceLocation &Loc,
264 SourceRange &R1, SourceRange &R2,
265 ASTContext &Ctx) const;
266
267 /// Returns the WarnUnusedResultAttr that is declared on the callee
268 /// or its return type declaration, together with a NamedDecl that
269 /// refers to the declaration the attribute is attached to.
270 static std::pair<const NamedDecl *, const WarnUnusedResultAttr *>
271 getUnusedResultAttrImpl(const Decl *Callee, QualType ReturnType);
272
273 /// isLValue - True if this expression is an "l-value" according to
274 /// the rules of the current language. C and C++ give somewhat
275 /// different rules for this concept, but in general, the result of
276 /// an l-value expression identifies a specific object whereas the
277 /// result of an r-value expression is a value detached from any
278 /// specific storage.
279 ///
280 /// C++11 divides the concept of "r-value" into pure r-values
281 /// ("pr-values") and so-called expiring values ("x-values"), which
282 /// identify specific objects that can be safely cannibalized for
283 /// their resources.
284 bool isLValue() const { return getValueKind() == VK_LValue; }
285 bool isPRValue() const { return getValueKind() == VK_PRValue; }
286 bool isXValue() const { return getValueKind() == VK_XValue; }
287 bool isGLValue() const { return getValueKind() != VK_PRValue; }
288
302 /// Reasons why an expression might not be an l-value.
304
325 /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type,
326 /// does not have an incomplete type, does not have a const-qualified type,
327 /// and if it is a structure or union, does not have any member (including,
328 /// recursively, any member or element of all contained aggregates or unions)
329 /// with a const-qualified type.
330 ///
331 /// \param Loc [in,out] - A source location which *may* be filled
332 /// in with the location of the expression making this a
333 /// non-modifiable lvalue, if specified.
335 isModifiableLvalue(ASTContext &Ctx, SourceLocation *Loc = nullptr) const;
336
337 /// The return type of classify(). Represents the C++11 expression
338 /// taxonomy.
339 class Classification {
340 public:
341 /// The various classification results. Most of these mean prvalue.
342 enum Kinds {
345 CL_Function, // Functions cannot be lvalues in C.
346 CL_Void, // Void cannot be an lvalue in C.
347 CL_AddressableVoid, // Void expression whose address can be taken in C.
348 CL_DuplicateVectorComponents, // A vector shuffle with dupes.
349 CL_DuplicateMatrixComponents, // A matrix shuffle with dupes.
350 CL_MemberFunction, // An expression referring to a member function
352 CL_ClassTemporary, // A temporary of class type, or subobject thereof.
353 CL_ArrayTemporary, // A temporary of array type.
354 CL_ObjCMessageRValue, // ObjC message is an rvalue
355 CL_PRValue // A prvalue for any other reason, of any other type
356 };
357 /// The results of modification testing.
359 CM_Untested, // testModifiable was false.
361 CM_RValue, // Not modifiable because it's an rvalue
362 CM_Function, // Not modifiable because it's a function; C++ only
363 CM_LValueCast, // Same as CM_RValue, but indicates GCC cast-as-lvalue ext
364 CM_NoSetterProperty,// Implicit assignment to ObjC property without setter
370 };
371
372 private:
373 friend class Expr;
374
375 unsigned short Kind;
376 unsigned short Modifiable;
377
378 explicit Classification(Kinds k, ModifiableType m)
379 : Kind(k), Modifiable(m)
380 {}
381
382 public:
384
385 Kinds getKind() const { return static_cast<Kinds>(Kind); }
387 assert(Modifiable != CM_Untested && "Did not test for modifiability.");
388 return static_cast<ModifiableType>(Modifiable);
389 }
390 bool isLValue() const { return Kind == CL_LValue; }
391 bool isXValue() const { return Kind == CL_XValue; }
392 bool isGLValue() const { return Kind <= CL_XValue; }
393 bool isPRValue() const { return Kind >= CL_Function; }
394 bool isRValue() const { return Kind >= CL_XValue; }
395 bool isModifiable() const { return getModifiable() == CM_Modifiable; }
396
397 /// Create a simple, modifiable lvalue
398 static Classification makeSimpleLValue() {
400 }
401
402 };
403 /// Classify - Classify this expression according to the C++11
404 /// expression taxonomy.
405 ///
406 /// C++11 defines ([basic.lval]) a new taxonomy of expressions to replace the
407 /// old lvalue vs rvalue. This function determines the type of expression this
408 /// is. There are three expression types:
409 /// - lvalues are classical lvalues as in C++03.
410 /// - prvalues are equivalent to rvalues in C++03.
411 /// - xvalues are expressions yielding unnamed rvalue references, e.g. a
412 /// function returning an rvalue reference.
413 /// lvalues and xvalues are collectively referred to as glvalues, while
414 /// prvalues and xvalues together form rvalues.
416 return ClassifyImpl(Ctx, nullptr);
417 }
418
419 /// ClassifyModifiable - Classify this expression according to the
420 /// C++11 expression taxonomy, and see if it is valid on the left side
421 /// of an assignment.
422 ///
423 /// This function extends classify in that it also tests whether the
424 /// expression is modifiable (C99 6.3.2.1p1).
425 /// \param Loc A source location that might be filled with a relevant location
426 /// if the expression is not modifiable.
428 return ClassifyImpl(Ctx, &Loc);
429 }
430
431 /// Returns the set of floating point options that apply to this expression.
432 /// Only meaningful for operations on floating point values.
434
435 /// getValueKindForType - Given a formal return or parameter type,
436 /// give its value kind.
438 if (const ReferenceType *RT = T->getAs<ReferenceType>())
439 return (isa<LValueReferenceType>(RT)
440 ? VK_LValue
441 : (RT->getPointeeType()->isFunctionType()
442 ? VK_LValue : VK_XValue));
443 return VK_PRValue;
444 }
445
446 /// getValueKind - The value kind that this expression produces.
448 return static_cast<ExprValueKind>(ExprBits.ValueKind);
449 }
450
451 /// getObjectKind - The object kind that this expression produces.
452 /// Object kinds are meaningful only for expressions that yield an
453 /// l-value or x-value.
455 return static_cast<ExprObjectKind>(ExprBits.ObjectKind);
456 }
457
460 return (OK == OK_Ordinary || OK == OK_BitField);
461 }
462
463 /// setValueKind - Set the value kind produced by this expression.
464 void setValueKind(ExprValueKind Cat) { ExprBits.ValueKind = Cat; }
465
466 /// setObjectKind - Set the object kind produced by this expression.
467 void setObjectKind(ExprObjectKind Cat) { ExprBits.ObjectKind = Cat; }
468
469private:
470 Classification ClassifyImpl(ASTContext &Ctx, SourceLocation *Loc) const;
471
472public:
473
474 /// Returns true if this expression is a gl-value that
475 /// potentially refers to a bit-field.
476 ///
477 /// In C++, whether a gl-value refers to a bitfield is essentially
478 /// an aspect of the value-kind type system.
479 bool refersToBitField() const { return getObjectKind() == OK_BitField; }
480
481 /// If this expression refers to a bit-field, retrieve the
482 /// declaration of that bit-field.
483 ///
484 /// Note that this returns a non-null pointer in subtly different
485 /// places than refersToBitField returns true. In particular, this can
486 /// return a non-null pointer even for r-values loaded from
487 /// bit-fields, but it will return null for a conditional bit-field.
489
490 /// If this expression refers to an enum constant, retrieve its declaration
492
494 return const_cast<Expr *>(this)->getEnumConstantDecl();
495 }
496
498 return const_cast<Expr*>(this)->getSourceBitField();
499 }
500
503 return const_cast<Expr*>(this)->getReferencedDeclOfCallee();
504 }
505
506 /// If this expression is an l-value for an Objective C
507 /// property, find the underlying property reference expression.
509
510 /// Check if this expression is the ObjC 'self' implicit parameter.
511 bool isObjCSelfExpr() const;
512
513 /// Returns whether this expression refers to a vector element.
514 bool refersToVectorElement() const;
515
516 /// Returns whether this expression refers to a matrix element.
519 }
520
521 /// Returns whether this expression refers to a global register
522 /// variable.
523 bool refersToGlobalRegisterVar() const;
524
525 /// Returns whether this expression has a placeholder type.
526 bool hasPlaceholderType() const {
527 return getType()->isPlaceholderType();
528 }
529
530 /// Returns whether this expression has a specific placeholder type.
533 if (const BuiltinType *BT = dyn_cast<BuiltinType>(getType()))
534 return BT->getKind() == K;
535 return false;
536 }
537
538 /// isKnownToHaveBooleanValue - Return true if this is an integer expression
539 /// that is known to return 0 or 1. This happens for _Bool/bool expressions
540 /// but also int expressions which are produced by things like comparisons in
541 /// C.
542 ///
543 /// \param Semantic If true, only return true for expressions that are known
544 /// to be semantically boolean, which might not be true even for expressions
545 /// that are known to evaluate to 0/1. For instance, reading an unsigned
546 /// bit-field with width '1' will evaluate to 0/1, but doesn't necessarily
547 /// semantically correspond to a bool.
548 bool isKnownToHaveBooleanValue(bool Semantic = true) const;
549
550 /// Check whether this array fits the idiom of a flexible array member,
551 /// depending on the value of -fstrict-flex-array.
552 /// When IgnoreTemplateOrMacroSubstitution is set, it doesn't consider sizes
553 /// resulting from the substitution of a macro or a template as special sizes.
555 const ASTContext &Context,
556 LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel,
557 bool IgnoreTemplateOrMacroSubstitution = false) const;
558
559 /// isIntegerConstantExpr - Return the value if this expression is a valid
560 /// integer constant expression. If not a valid i-c-e, return std::nullopt.
561 ///
562 /// Note: This does not perform the implicit conversions required by C++11
563 /// [expr.const]p5.
564 std::optional<llvm::APSInt>
566 bool AllowRelaxedEval = false) const;
567 bool isIntegerConstantExpr(const ASTContext &Ctx) const;
568
569 /// isCXX98IntegralConstantExpr - Return true if this expression is an
570 /// integral constant expression in C++98. Can only be used in C++.
571 bool isCXX98IntegralConstantExpr(const ASTContext &Ctx) const;
572
573 /// isCXX11ConstantExpr - Return true if this expression is a constant
574 /// expression in C++11. Can only be used in C++.
575 ///
576 /// Note: This does not perform the implicit conversions required by C++11
577 /// [expr.const]p5.
578 bool isCXX11ConstantExpr(const ASTContext &Ctx, APValue *Result = nullptr,
579 bool AllowRelaxedEval = false) const;
580
581 /// isPotentialConstantExpr - Return true if this function's definition
582 /// might be usable in a constant expression in C++11, if it were marked
583 /// constexpr. Return false if the function can never produce a constant
584 /// expression, along with diagnostics describing why not.
585 static bool isPotentialConstantExpr(const FunctionDecl *FD,
587 PartialDiagnosticAt> &Diags);
588
589 /// isPotentialConstantExprUnevaluated - Return true if this expression might
590 /// be usable in a constant expression in C++11 in an unevaluated context, if
591 /// it were in function FD marked constexpr. Return false if the function can
592 /// never produce a constant expression, along with diagnostics describing
593 /// why not.
595 const FunctionDecl *FD,
597 PartialDiagnosticAt> &Diags);
598
599 /// Returns true if this expression can be emitted to
600 /// IR as a constant, and thus can be used as a constant initializer in C.
601 /// If this expression is not constant and Culprit is non-null,
602 /// it is used to store the address of first non constant expr.
603 bool isConstantInitializer(ASTContext &Ctx, bool ForRef = false,
604 const Expr **Culprit = nullptr) const;
605
606 /// If this expression is an unambiguous reference to a single declaration,
607 /// in the style of __builtin_function_start, return that declaration. Note
608 /// that this may return a non-static member function or field in C++ if this
609 /// expression is a member pointer constant.
610 const ValueDecl *getAsBuiltinConstantDeclRef(const ASTContext &Context) const;
611
612 /// EvalStatus is a struct with detailed info about an evaluation in progress.
613 struct EvalStatus {
614 /// Whether the evaluated expression has side effects.
615 /// For example, (f() && 0) can be folded, but it still has side effects.
616 bool HasSideEffects = false;
617
618 /// Whether the evaluation hit undefined behavior.
619 /// For example, 1.0 / 0.0 can be folded to Inf, but has undefined behavior.
620 /// Likewise, INT_MAX + 1 can be folded to INT_MIN, but has UB.
622
623 /// Whether any diagnostic has been emitted. This is set regardless of
624 /// whether @ref #Diag is set or not.
625 bool DiagEmitted = false;
626
627 /// Diag - If this is non-null, it will be filled in with a stack of notes
628 /// indicating why evaluation failed (or why it failed to produce a constant
629 /// expression).
630 /// If the expression is unfoldable, the notes will indicate why it's not
631 /// foldable. If the expression is foldable, but not a constant expression,
632 /// the notes will describes why it isn't a constant expression. If the
633 /// expression *is* a constant expression, no notes will be produced.
634 ///
635 /// FIXME: this causes significant performance concerns and should be
636 /// refactored at some point. Not all evaluations of the constant
637 /// expression interpreter will display the given diagnostics, this means
638 /// those kinds of uses are paying the expense of generating a diagnostic
639 /// (which may include expensive operations like converting APValue objects
640 /// to a string representation).
642
643 /// Location where we spot ptr to int cast or null subobject while
644 /// evaluating constant expression in MS compatibility mode.
646
647 EvalStatus() = default;
648
649 /// Return true if the evaluated expression has
650 /// side effects.
651 bool hasSideEffects() const {
652 return HasSideEffects;
653 }
654 };
655
656 /// EvalResult is a struct with detailed info about an evaluated expression.
658 /// Val - This is the value the expression can be folded to.
660
661 /// Return true if the evaluated lvalue expression
662 /// is global.
663 bool isGlobalLValue() const;
664 };
665
666 /// EvaluateAsRValue - Return true if this is a constant which we can fold to
667 /// an rvalue using any crazy technique (that has nothing to do with language
668 /// standards) that we want to, even if the expression has side-effects. If
669 /// this function returns true, it returns the folded constant in Result. If
670 /// the expression is a glvalue, an lvalue-to-rvalue conversion will be
671 /// applied.
673 bool InConstantContext = false) const;
674
675 /// EvaluateAsBooleanCondition - Return true if this is a constant
676 /// which we can fold and convert to a boolean condition using
677 /// any crazy technique that we want to, even if the expression has
678 /// side-effects.
679 bool EvaluateAsBooleanCondition(bool &Result, const ASTContext &Ctx,
680 bool InConstantContext = false) const;
681
683 SE_NoSideEffects, ///< Strictly evaluate the expression.
684 SE_AllowUndefinedBehavior, ///< Allow UB that we can give a value, but not
685 ///< arbitrary unmodeled side effects.
686 SE_AllowSideEffects ///< Allow any unmodeled side effect.
687 };
688
689 /// EvaluateAsInt - Return true if this is a constant which we can fold and
690 /// convert to an integer, using any crazy technique that we want to.
691 bool EvaluateAsInt(EvalResult &Result, const ASTContext &Ctx,
692 SideEffectsKind AllowSideEffects = SE_NoSideEffects,
693 bool InConstantContext = false) const;
694
695 /// EvaluateAsFloat - Return true if this is a constant which we can fold and
696 /// convert to a floating point value, using any crazy technique that we
697 /// want to.
698 bool EvaluateAsFloat(llvm::APFloat &Result, const ASTContext &Ctx,
699 SideEffectsKind AllowSideEffects = SE_NoSideEffects,
700 bool InConstantContext = false) const;
701
702 /// EvaluateAsFixedPoint - Return true if this is a constant which we can fold
703 /// and convert to a fixed point value.
704 bool EvaluateAsFixedPoint(EvalResult &Result, const ASTContext &Ctx,
705 SideEffectsKind AllowSideEffects = SE_NoSideEffects,
706 bool InConstantContext = false) const;
707
708 /// isEvaluatable - Call EvaluateAsRValue to see if this expression can be
709 /// constant folded without side-effects, but discard the result.
710 bool isEvaluatable(const ASTContext &Ctx,
711 SideEffectsKind AllowSideEffects = SE_NoSideEffects) const;
712
713 /// HasSideEffects - This routine returns true for all those expressions
714 /// which have any effect other than producing a value. Example is a function
715 /// call, volatile variable read, or throwing an exception. If
716 /// IncludePossibleEffects is false, this call treats certain expressions with
717 /// potential side effects (such as function call-like expressions,
718 /// instantiation-dependent expressions, or invocations from a macro) as not
719 /// having side effects.
720 bool HasSideEffects(const ASTContext &Ctx,
721 bool IncludePossibleEffects = true) const;
722
723 /// Determine whether this expression involves a call to any function
724 /// that is not trivial.
725 bool hasNonTrivialCall(const ASTContext &Ctx) const;
726
727 /// EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded
728 /// integer. This must be called on an expression that constant folds to an
729 /// integer.
730 llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx) const;
731
733 const ASTContext &Ctx,
735
736 void EvaluateForOverflow(const ASTContext &Ctx) const;
737
738 /// EvaluateAsLValue - Evaluate an expression to see if we can fold it to an
739 /// lvalue with link time known address, with no side-effects.
740 bool EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx,
741 bool InConstantContext = false) const;
742
743 /// EvaluateAsInitializer - Evaluate an expression as if it were the
744 /// initializer of the given declaration. Returns true if the initializer
745 /// can be folded to a constant, and produces any relevant notes. In C++11,
746 /// notes will be produced if the expression is not a constant expression.
747 bool EvaluateAsInitializer(const ASTContext &Ctx, const VarDecl *VD,
748 EvalResult &Result,
749 bool IsConstantInitializer) const;
750
751 /// EvaluateWithSubstitution - Evaluate an expression as if from the context
752 /// of a call to the given function with the given arguments, inside an
753 /// unevaluated context. Returns true if the expression could be folded to a
754 /// constant.
756 const FunctionDecl *Callee,
758 const Expr *This = nullptr) const;
759
760 enum class ConstantExprKind {
761 /// An integer constant expression (an array bound, enumerator, case value,
762 /// bit-field width, or similar) or similar.
764 /// A non-class template argument. Such a value is only used for mangling,
765 /// not for code generation, so can refer to dllimported functions.
767 /// A class template argument. Such a value is used for code generation.
769 /// An immediate invocation. The destruction of the end result of this
770 /// evaluation is not part of the evaluation, but all other temporaries
771 /// are destroyed.
773 };
774
775 /// Evaluate an expression that is required to be a constant expression. Does
776 /// not check the syntactic constraints for C and C++98 constant expressions.
778 EvalResult &Result, const ASTContext &Ctx,
779 ConstantExprKind Kind = ConstantExprKind::Normal) const;
780
781 /// If the current Expr is a pointer, this will try to statically
782 /// determine the number of bytes available where the pointer is pointing.
783 /// Returns true if all of the above holds and we were able to figure out the
784 /// size, false otherwise.
785 ///
786 /// \param Type - How to evaluate the size of the Expr, as defined by the
787 /// "type" parameter of __builtin_object_size
788 std::optional<uint64_t> tryEvaluateObjectSize(const ASTContext &Ctx,
789 unsigned Type) const;
790
791 /// If the current Expr is a pointer, this will try to statically
792 /// determine the strlen of the string pointed to.
793 /// Returns true if all of the above holds and we were able to figure out the
794 /// strlen, false otherwise.
795 std::optional<uint64_t> tryEvaluateStrLen(const ASTContext &Ctx) const;
796
797 bool EvaluateCharRangeAsString(std::string &Result,
798 const Expr *SizeExpression,
799 const Expr *PtrExpression, ASTContext &Ctx,
800 EvalResult &Status) const;
801
802 bool EvaluateCharRangeAsString(APValue &Result, const Expr *SizeExpression,
803 const Expr *PtrExpression, ASTContext &Ctx,
804 EvalResult &Status) const;
805
806 /// If the current Expr can be evaluated to a pointer to a null-terminated
807 /// constant string, return the constant string (without the terminating
808 /// null).
809 std::optional<std::string> tryEvaluateString(ASTContext &Ctx) const;
810
811 /// Enumeration used to describe the kind of Null pointer constant
812 /// returned from \c isNullPointerConstant().
814 /// Expression is not a Null pointer constant.
816
817 /// Expression is a Null pointer constant built from a zero integer
818 /// expression that is not a simple, possibly parenthesized, zero literal.
819 /// C++ Core Issue 903 will classify these expressions as "not pointers"
820 /// once it is adopted.
821 /// http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#903
823
824 /// Expression is a Null pointer constant built from a literal zero.
826
827 /// Expression is a C++11 nullptr.
829
830 /// Expression is a GNU-style __null constant.
832 };
833
834 /// Enumeration used to describe how \c isNullPointerConstant()
835 /// should cope with value-dependent expressions.
837 /// Specifies that the expression should never be value-dependent.
839
840 /// Specifies that a value-dependent expression of integral or
841 /// dependent type should be considered a null pointer constant.
843
844 /// Specifies that a value-dependent expression should be considered
845 /// to never be a null pointer constant.
847 };
848
849 /// isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to
850 /// a Null pointer constant. The return value can further distinguish the
851 /// kind of NULL pointer constant that was detected.
853 ASTContext &Ctx,
855
856 /// isOBJCGCCandidate - Return true if this expression may be used in a read/
857 /// write barrier.
858 bool isOBJCGCCandidate(ASTContext &Ctx) const;
859
860 /// Returns true if this expression is a bound member function.
861 bool isBoundMemberFunction(ASTContext &Ctx) const;
862
863 /// Given an expression of bound-member type, find the type
864 /// of the member. Returns null if this is an *overloaded* bound
865 /// member expression.
866 static QualType findBoundMemberType(const Expr *expr);
867
868 /// Skip past any invisible AST nodes which might surround this
869 /// statement, such as ExprWithCleanups or ImplicitCastExpr nodes,
870 /// but also injected CXXMemberExpr and CXXConstructExpr which represent
871 /// implicit conversions.
874 return const_cast<Expr *>(this)->IgnoreUnlessSpelledInSource();
875 }
876
877 /// Skip past any implicit casts which might surround this expression until
878 /// reaching a fixed point. Skips:
879 /// * ImplicitCastExpr
880 /// * FullExpr
881 Expr *IgnoreImpCasts() LLVM_READONLY;
882 const Expr *IgnoreImpCasts() const {
883 return const_cast<Expr *>(this)->IgnoreImpCasts();
884 }
885
886 /// Skip past any casts which might surround this expression until reaching
887 /// a fixed point. Skips:
888 /// * CastExpr
889 /// * FullExpr
890 /// * MaterializeTemporaryExpr
891 /// * SubstNonTypeTemplateParmExpr
892 Expr *IgnoreCasts() LLVM_READONLY;
893 const Expr *IgnoreCasts() const {
894 return const_cast<Expr *>(this)->IgnoreCasts();
895 }
896
897 /// Skip past any implicit AST nodes which might surround this expression
898 /// until reaching a fixed point. Skips:
899 /// * What IgnoreImpCasts() skips
900 /// * MaterializeTemporaryExpr
901 /// * CXXBindTemporaryExpr
902 Expr *IgnoreImplicit() LLVM_READONLY;
903 const Expr *IgnoreImplicit() const {
904 return const_cast<Expr *>(this)->IgnoreImplicit();
905 }
906
907 /// Skip past any implicit AST nodes which might surround this expression
908 /// until reaching a fixed point. Same as IgnoreImplicit, except that it
909 /// also skips over implicit calls to constructors and conversion functions.
910 ///
911 /// FIXME: Should IgnoreImplicit do this?
912 Expr *IgnoreImplicitAsWritten() LLVM_READONLY;
914 return const_cast<Expr *>(this)->IgnoreImplicitAsWritten();
915 }
916
917 /// Skip past any parentheses which might surround this expression until
918 /// reaching a fixed point. Skips:
919 /// * ParenExpr
920 /// * UnaryOperator if `UO_Extension`
921 /// * GenericSelectionExpr if `!isResultDependent()`
922 /// * ChooseExpr if `!isConditionDependent()`
923 /// * ConstantExpr
924 Expr *IgnoreParens() LLVM_READONLY;
925 const Expr *IgnoreParens() const {
926 return const_cast<Expr *>(this)->IgnoreParens();
927 }
928
929 /// Skip past any parentheses and implicit casts which might surround this
930 /// expression until reaching a fixed point.
931 /// FIXME: IgnoreParenImpCasts really ought to be equivalent to
932 /// IgnoreParens() + IgnoreImpCasts() until reaching a fixed point. However
933 /// this is currently not the case. Instead IgnoreParenImpCasts() skips:
934 /// * What IgnoreParens() skips
935 /// * What IgnoreImpCasts() skips
936 /// * MaterializeTemporaryExpr
937 /// * SubstNonTypeTemplateParmExpr
938 Expr *IgnoreParenImpCasts() LLVM_READONLY;
939 const Expr *IgnoreParenImpCasts() const {
940 return const_cast<Expr *>(this)->IgnoreParenImpCasts();
941 }
942
943 /// Skip past any parentheses and casts which might surround this expression
944 /// until reaching a fixed point. Skips:
945 /// * What IgnoreParens() skips
946 /// * What IgnoreCasts() skips
947 Expr *IgnoreParenCasts() LLVM_READONLY;
948 const Expr *IgnoreParenCasts() const {
949 return const_cast<Expr *>(this)->IgnoreParenCasts();
950 }
951
952 /// Skip conversion operators. If this Expr is a call to a conversion
953 /// operator, return the argument.
956 return const_cast<Expr *>(this)->IgnoreConversionOperatorSingleStep();
957 }
958
959 /// Skip past any parentheses and lvalue casts which might surround this
960 /// expression until reaching a fixed point. Skips:
961 /// * What IgnoreParens() skips
962 /// * What IgnoreCasts() skips, except that only lvalue-to-rvalue
963 /// casts are skipped
964 /// FIXME: This is intended purely as a temporary workaround for code
965 /// that hasn't yet been rewritten to do the right thing about those
966 /// casts, and may disappear along with the last internal use.
967 Expr *IgnoreParenLValueCasts() LLVM_READONLY;
969 return const_cast<Expr *>(this)->IgnoreParenLValueCasts();
970 }
971
972 /// Skip past any parentheses and casts which do not change the value
973 /// (including ptr->int casts of the same size) until reaching a fixed point.
974 /// Skips:
975 /// * What IgnoreParens() skips
976 /// * CastExpr which do not change the value
977 /// * SubstNonTypeTemplateParmExpr
978 Expr *IgnoreParenNoopCasts(const ASTContext &Ctx) LLVM_READONLY;
979 const Expr *IgnoreParenNoopCasts(const ASTContext &Ctx) const {
980 return const_cast<Expr *>(this)->IgnoreParenNoopCasts(Ctx);
981 }
982
983 /// Skip past any parentheses and derived-to-base casts until reaching a
984 /// fixed point. Skips:
985 /// * What IgnoreParens() skips
986 /// * CastExpr which represent a derived-to-base cast (CK_DerivedToBase,
987 /// CK_UncheckedDerivedToBase and CK_NoOp)
988 Expr *IgnoreParenBaseCasts() LLVM_READONLY;
989 const Expr *IgnoreParenBaseCasts() const {
990 return const_cast<Expr *>(this)->IgnoreParenBaseCasts();
991 }
992
993 /// Determine whether this expression is a default function argument.
994 ///
995 /// Default arguments are implicitly generated in the abstract syntax tree
996 /// by semantic analysis for function calls, object constructions, etc. in
997 /// C++. Default arguments are represented by \c CXXDefaultArgExpr nodes;
998 /// this routine also looks through any implicit casts to determine whether
999 /// the expression is a default argument.
1000 bool isDefaultArgument() const;
1001
1002 /// Determine whether the result of this expression is a
1003 /// temporary object of the given class type.
1004 bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const;
1005
1006 /// Whether this expression is an implicit reference to 'this' in C++.
1007 bool isImplicitCXXThis() const;
1008
1010
1011 /// For an expression of class type or pointer to class type,
1012 /// return the most derived class decl the expression is known to refer to.
1013 ///
1014 /// If this expression is a cast, this method looks through it to find the
1015 /// most derived decl that can be inferred from the expression.
1016 /// This is valid because derived-to-base conversions have undefined
1017 /// behavior if the object isn't dynamically of the derived type.
1019
1020 /// Get the inner expression that determines the best dynamic class.
1021 /// If this is a prvalue, we guarantee that it is of the most-derived type
1022 /// for the object itself.
1023 const Expr *getBestDynamicClassTypeExpr() const;
1024
1025 /// Walk outwards from an expression we want to bind a reference to and
1026 /// find the expression whose lifetime needs to be extended. Record
1027 /// the LHSs of comma expressions and adjustments needed along the path.
1030 SmallVectorImpl<SubobjectAdjustment> &Adjustments) const;
1034 return skipRValueSubobjectAdjustments(CommaLHSs, Adjustments);
1035 }
1036
1037 /// Checks that the two Expr's will refer to the same value as a comparison
1038 /// operand. The caller must ensure that the values referenced by the Expr's
1039 /// are not modified between E1 and E2 or the result my be invalid.
1040 static bool isSameComparisonOperand(const Expr* E1, const Expr* E2);
1041
1042 static bool classof(const Stmt *T) {
1043 return T->getStmtClass() >= firstExprConstant &&
1044 T->getStmtClass() <= lastExprConstant;
1045 }
1046};
1047// PointerLikeTypeTraits is specialized so it can be used with a forward-decl of
1048// Expr. Verify that we got it right.
1050 llvm::ConstantLog2<alignof(Expr)>(),
1051 "PointerLikeTypeTraits<Expr*> assumes too much alignment.");
1052
1054
1055//===----------------------------------------------------------------------===//
1056// Wrapper Expressions.
1057//===----------------------------------------------------------------------===//
1058
1059/// FullExpr - Represents a "full-expression" node.
1060class FullExpr : public Expr {
1061protected:
1063
1065 : Expr(SC, subexpr->getType(), subexpr->getValueKind(),
1066 subexpr->getObjectKind()),
1067 SubExpr(subexpr) {
1069 }
1072public:
1073 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
1075
1076 /// As with any mutator of the AST, be very careful when modifying an
1077 /// existing AST to preserve its invariants.
1078 void setSubExpr(Expr *E) { SubExpr = E; }
1079
1080 static bool classof(const Stmt *T) {
1081 return T->getStmtClass() >= firstFullExprConstant &&
1082 T->getStmtClass() <= lastFullExprConstant;
1083 }
1084};
1085
1086/// Describes the kind of result that can be tail-allocated.
1088
1089/// ConstantExpr - An expression that occurs in a constant context and
1090/// optionally the result of evaluating the expression.
1091class ConstantExpr final
1092 : public FullExpr,
1093 private llvm::TrailingObjects<ConstantExpr, APValue, uint64_t> {
1094 static_assert(std::is_same<uint64_t, llvm::APInt::WordType>::value,
1095 "ConstantExpr assumes that llvm::APInt::WordType is uint64_t "
1096 "for tail-allocated storage");
1097 friend TrailingObjects;
1098 friend class ASTStmtReader;
1099 friend class ASTStmtWriter;
1100
1101 size_t numTrailingObjects(OverloadToken<APValue>) const {
1103 }
1104 size_t numTrailingObjects(OverloadToken<uint64_t>) const {
1106 }
1107
1108 uint64_t &Int64Result() {
1110 "invalid accessor");
1111 return *getTrailingObjects<uint64_t>();
1112 }
1113 const uint64_t &Int64Result() const {
1114 return const_cast<ConstantExpr *>(this)->Int64Result();
1115 }
1116 APValue &APValueResult() {
1118 "invalid accessor");
1119 return *getTrailingObjects<APValue>();
1120 }
1121 APValue &APValueResult() const {
1122 return const_cast<ConstantExpr *>(this)->APValueResult();
1123 }
1124
1125 ConstantExpr(Expr *SubExpr, ConstantResultStorageKind StorageKind,
1126 bool IsImmediateInvocation);
1127 ConstantExpr(EmptyShell Empty, ConstantResultStorageKind StorageKind);
1128
1129public:
1130 static ConstantExpr *Create(const ASTContext &Context, Expr *E,
1131 const APValue &Result);
1132 static ConstantExpr *
1133 Create(const ASTContext &Context, Expr *E,
1135 bool IsImmediateInvocation = false);
1136 static ConstantExpr *CreateEmpty(const ASTContext &Context,
1137 ConstantResultStorageKind StorageKind);
1138
1141 const ASTContext &Context);
1142
1143 SourceLocation getBeginLoc() const LLVM_READONLY {
1144 return SubExpr->getBeginLoc();
1145 }
1146 SourceLocation getEndLoc() const LLVM_READONLY {
1147 return SubExpr->getEndLoc();
1148 }
1149
1150 static bool classof(const Stmt *T) {
1151 return T->getStmtClass() == ConstantExprClass;
1152 }
1153
1154 void SetResult(APValue Value, const ASTContext &Context) {
1155 MoveIntoResult(Value, Context);
1156 }
1157 void MoveIntoResult(APValue &Value, const ASTContext &Context);
1158
1160 return static_cast<APValue::ValueKind>(ConstantExprBits.APValueKind);
1161 }
1166 return ConstantExprBits.IsImmediateInvocation;
1167 }
1168 bool hasAPValueResult() const {
1169 return ConstantExprBits.APValueKind != APValue::None;
1170 }
1171 APValue getAPValueResult() const;
1172 llvm::APSInt getResultAsAPSInt() const;
1173 // Iterators
1176 return const_child_range(&SubExpr, &SubExpr + 1);
1177 }
1178};
1179
1180//===----------------------------------------------------------------------===//
1181// Primary Expressions.
1182//===----------------------------------------------------------------------===//
1183
1184/// OpaqueValueExpr - An expression referring to an opaque object of a
1185/// fixed type and value class. These don't correspond to concrete
1186/// syntax; instead they're used to express operations (usually copy
1187/// operations) on values whose source is generally obvious from
1188/// context.
1189class OpaqueValueExpr : public Expr {
1190 friend class ASTStmtReader;
1191 Expr *SourceExpr;
1192
1193public:
1195 ExprObjectKind OK = OK_Ordinary, Expr *SourceExpr = nullptr)
1196 : Expr(OpaqueValueExprClass, T, VK, OK), SourceExpr(SourceExpr) {
1197 setIsUnique(false);
1198 OpaqueValueExprBits.Loc = Loc;
1200 }
1201
1202 /// Given an expression which invokes a copy constructor --- i.e. a
1203 /// CXXConstructExpr, possibly wrapped in an ExprWithCleanups ---
1204 /// find the OpaqueValueExpr that's the source of the construction.
1205 static const OpaqueValueExpr *findInCopyConstruct(const Expr *expr);
1206
1208 : Expr(OpaqueValueExprClass, Empty) {}
1209
1210 /// Retrieve the location of this expression.
1212
1213 SourceLocation getBeginLoc() const LLVM_READONLY {
1214 return SourceExpr ? SourceExpr->getBeginLoc() : getLocation();
1215 }
1216 SourceLocation getEndLoc() const LLVM_READONLY {
1217 return SourceExpr ? SourceExpr->getEndLoc() : getLocation();
1218 }
1219 SourceLocation getExprLoc() const LLVM_READONLY {
1220 return SourceExpr ? SourceExpr->getExprLoc() : getLocation();
1221 }
1222
1226
1230
1231 /// The source expression of an opaque value expression is the
1232 /// expression which originally generated the value. This is
1233 /// provided as a convenience for analyses that don't wish to
1234 /// precisely model the execution behavior of the program.
1235 ///
1236 /// The source expression is typically set when building the
1237 /// expression which binds the opaque value expression in the first
1238 /// place.
1239 Expr *getSourceExpr() const { return SourceExpr; }
1240
1241 void setIsUnique(bool V) {
1242 assert((!V || SourceExpr) &&
1243 "unique OVEs are expected to have source expressions");
1244 OpaqueValueExprBits.IsUnique = V;
1245 }
1246
1247 bool isUnique() const { return OpaqueValueExprBits.IsUnique; }
1248
1249 static bool classof(const Stmt *T) {
1250 return T->getStmtClass() == OpaqueValueExprClass;
1251 }
1252};
1253
1254/// A reference to a declared variable, function, enum, etc.
1255/// [C99 6.5.1p2]
1256///
1257/// This encodes all the information about how a declaration is referenced
1258/// within an expression.
1259///
1260/// There are several optional constructs attached to DeclRefExprs only when
1261/// they apply in order to conserve memory. These are laid out past the end of
1262/// the object, and flags in the DeclRefExprBitfield track whether they exist:
1263///
1264/// DeclRefExprBits.HasQualifier:
1265/// Specifies when this declaration reference expression has a C++
1266/// nested-name-specifier.
1267/// DeclRefExprBits.HasFoundDecl:
1268/// Specifies when this declaration reference expression has a record of
1269/// a NamedDecl (different from the referenced ValueDecl) which was found
1270/// during name lookup and/or overload resolution.
1271/// DeclRefExprBits.HasTemplateKWAndArgsInfo:
1272/// Specifies when this declaration reference expression has an explicit
1273/// C++ template keyword and/or template argument list.
1274/// DeclRefExprBits.RefersToEnclosingVariableOrCapture
1275/// Specifies when this declaration reference expression (validly)
1276/// refers to an enclosed local or a captured variable.
1277class DeclRefExpr final
1278 : public Expr,
1279 private llvm::TrailingObjects<DeclRefExpr, NestedNameSpecifierLoc,
1280 NamedDecl *, ASTTemplateKWAndArgsInfo,
1281 TemplateArgumentLoc> {
1282 friend class ASTStmtReader;
1283 friend class ASTStmtWriter;
1284 friend TrailingObjects;
1285
1286 /// The declaration that we are referencing.
1287 ValueDecl *D;
1288
1289 /// Provides source/type location info for the declaration name
1290 /// embedded in D.
1291 DeclarationNameLoc DNLoc;
1292
1293 size_t numTrailingObjects(OverloadToken<NestedNameSpecifierLoc>) const {
1294 return hasQualifier();
1295 }
1296
1297 size_t numTrailingObjects(OverloadToken<NamedDecl *>) const {
1298 return hasFoundDecl();
1299 }
1300
1301 size_t numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
1302 return hasTemplateKWAndArgsInfo();
1303 }
1304
1305 /// Test whether there is a distinct FoundDecl attached to the end of
1306 /// this DRE.
1307 bool hasFoundDecl() const { return DeclRefExprBits.HasFoundDecl; }
1308
1309 DeclRefExpr(const ASTContext &Ctx, NestedNameSpecifierLoc QualifierLoc,
1310 SourceLocation TemplateKWLoc, ValueDecl *D,
1311 bool RefersToEnclosingVariableOrCapture,
1312 const DeclarationNameInfo &NameInfo, NamedDecl *FoundD,
1313 const TemplateArgumentListInfo *TemplateArgs, QualType T,
1315
1316 /// Construct an empty declaration reference expression.
1317 explicit DeclRefExpr(EmptyShell Empty) : Expr(DeclRefExprClass, Empty) {}
1318
1319public:
1320 DeclRefExpr(const ASTContext &Ctx, ValueDecl *D,
1321 bool RefersToEnclosingVariableOrCapture, QualType T,
1322 ExprValueKind VK, SourceLocation L,
1323 const DeclarationNameLoc &LocInfo = DeclarationNameLoc(),
1324 NonOdrUseReason NOUR = NOUR_None);
1325
1326 static DeclRefExpr *
1327 Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc,
1328 SourceLocation TemplateKWLoc, ValueDecl *D,
1329 bool RefersToEnclosingVariableOrCapture, SourceLocation NameLoc,
1330 QualType T, ExprValueKind VK, NamedDecl *FoundD = nullptr,
1331 const TemplateArgumentListInfo *TemplateArgs = nullptr,
1332 NonOdrUseReason NOUR = NOUR_None);
1333
1334 static DeclRefExpr *
1335 Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc,
1336 SourceLocation TemplateKWLoc, ValueDecl *D,
1337 bool RefersToEnclosingVariableOrCapture,
1338 const DeclarationNameInfo &NameInfo, QualType T, ExprValueKind VK,
1339 NamedDecl *FoundD = nullptr,
1340 const TemplateArgumentListInfo *TemplateArgs = nullptr,
1341 NonOdrUseReason NOUR = NOUR_None);
1342
1343 /// Construct an empty declaration reference expression.
1344 static DeclRefExpr *CreateEmpty(const ASTContext &Context, bool HasQualifier,
1345 bool HasFoundDecl,
1346 bool HasTemplateKWAndArgsInfo,
1347 unsigned NumTemplateArgs);
1348
1349 ValueDecl *getDecl() { return D; }
1350 const ValueDecl *getDecl() const { return D; }
1351 void setDecl(ValueDecl *NewD);
1352
1354 return DeclarationNameInfo(getDecl()->getDeclName(), getLocation(), DNLoc);
1355 }
1356
1359
1361 if (hasQualifier())
1362 return getQualifierLoc().getBeginLoc();
1363 return DeclRefExprBits.Loc;
1364 }
1365
1366 SourceLocation getEndLoc() const LLVM_READONLY;
1367
1368 /// Determine whether this declaration reference was preceded by a
1369 /// C++ nested-name-specifier, e.g., \c N::foo.
1370 bool hasQualifier() const { return DeclRefExprBits.HasQualifier; }
1371
1372 /// If the name was qualified, retrieves the nested-name-specifier
1373 /// that precedes the name, with source-location information.
1375 if (!hasQualifier())
1376 return NestedNameSpecifierLoc();
1377 return *getTrailingObjects<NestedNameSpecifierLoc>();
1378 }
1379
1380 /// If the name was qualified, retrieves the nested-name-specifier
1381 /// that precedes the name. Otherwise, returns NULL.
1385
1386 /// Get the NamedDecl through which this reference occurred.
1387 ///
1388 /// This Decl may be different from the ValueDecl actually referred to in the
1389 /// presence of using declarations, etc. It always returns non-NULL, and may
1390 /// simple return the ValueDecl when appropriate.
1391
1393 return hasFoundDecl() ? *getTrailingObjects<NamedDecl *>() : D;
1394 }
1395
1396 /// Get the NamedDecl through which this reference occurred.
1397 /// See non-const variant.
1398 const NamedDecl *getFoundDecl() const {
1399 return hasFoundDecl() ? *getTrailingObjects<NamedDecl *>() : D;
1400 }
1401
1403 return DeclRefExprBits.HasTemplateKWAndArgsInfo;
1404 }
1405
1406 /// Retrieve the location of the template keyword preceding
1407 /// this name, if any.
1410 return SourceLocation();
1411 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->TemplateKWLoc;
1412 }
1413
1414 /// Retrieve the location of the left angle bracket starting the
1415 /// explicit template argument list following the name, if any.
1418 return SourceLocation();
1419 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->LAngleLoc;
1420 }
1421
1422 /// Retrieve the location of the right angle bracket ending the
1423 /// explicit template argument list following the name, if any.
1426 return SourceLocation();
1427 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->RAngleLoc;
1428 }
1429
1430 /// Determines whether the name in this declaration reference
1431 /// was preceded by the template keyword.
1433
1434 /// Determines whether this declaration reference was followed by an
1435 /// explicit template argument list.
1436 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
1437
1438 /// Copies the template arguments (if present) into the given
1439 /// structure.
1442 getTrailingObjects<ASTTemplateKWAndArgsInfo>()->copyInto(
1443 getTrailingObjects<TemplateArgumentLoc>(), List);
1444 }
1445
1446 /// Retrieve the template arguments provided as part of this
1447 /// template-id.
1450 return nullptr;
1451 return getTrailingObjects<TemplateArgumentLoc>();
1452 }
1453
1454 /// Retrieve the number of template arguments provided as part of this
1455 /// template-id.
1456 unsigned getNumTemplateArgs() const {
1458 return 0;
1459 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs;
1460 }
1461
1465
1466 /// Returns true if this expression refers to a function that
1467 /// was resolved from an overloaded set having size greater than 1.
1469 return DeclRefExprBits.HadMultipleCandidates;
1470 }
1471 /// Sets the flag telling whether this expression refers to
1472 /// a function that was resolved from an overloaded set having size
1473 /// greater than 1.
1474 void setHadMultipleCandidates(bool V = true) {
1475 DeclRefExprBits.HadMultipleCandidates = V;
1476 }
1477
1478 /// Is this expression a non-odr-use reference, and if so, why?
1480 return static_cast<NonOdrUseReason>(DeclRefExprBits.NonOdrUseReason);
1481 }
1482
1483 /// Does this DeclRefExpr refer to an enclosing local or a captured
1484 /// variable?
1486 return DeclRefExprBits.RefersToEnclosingVariableOrCapture;
1487 }
1488
1490 return DeclRefExprBits.IsImmediateEscalating;
1491 }
1492
1494 DeclRefExprBits.IsImmediateEscalating = Set;
1495 }
1496
1498 return DeclRefExprBits.CapturedByCopyInLambdaWithExplicitObjectParameter;
1499 }
1500
1502 bool Set, const ASTContext &Context) {
1503 DeclRefExprBits.CapturedByCopyInLambdaWithExplicitObjectParameter = Set;
1504 setDependence(computeDependence(this, Context));
1505 }
1506
1507 static bool classof(const Stmt *T) {
1508 return T->getStmtClass() == DeclRefExprClass;
1509 }
1510
1511 // Iterators
1515
1519};
1520
1521class IntegerLiteral : public Expr, public APIntStorage {
1522 SourceLocation Loc;
1523
1524 /// Construct an empty integer literal.
1525 explicit IntegerLiteral(EmptyShell Empty)
1526 : Expr(IntegerLiteralClass, Empty) { }
1527
1528public:
1529 // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy,
1530 // or UnsignedLongLongTy
1531 IntegerLiteral(const ASTContext &C, const llvm::APInt &V, QualType type,
1532 SourceLocation l);
1533
1534 /// Returns a new integer literal with value 'V' and type 'type'.
1535 /// \param type - either IntTy, LongTy, LongLongTy, UnsignedIntTy,
1536 /// UnsignedLongTy, or UnsignedLongLongTy which should match the size of V
1537 /// \param V - the value that the returned integer literal contains.
1538 static IntegerLiteral *Create(const ASTContext &C, const llvm::APInt &V,
1540 /// Returns a new empty integer literal.
1541 static IntegerLiteral *Create(const ASTContext &C, EmptyShell Empty);
1542
1543 SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
1544 SourceLocation getEndLoc() const LLVM_READONLY { return Loc; }
1545
1546 /// Retrieve the location of the literal.
1547 SourceLocation getLocation() const { return Loc; }
1548
1549 void setLocation(SourceLocation Location) { Loc = Location; }
1550
1551 static bool classof(const Stmt *T) {
1552 return T->getStmtClass() == IntegerLiteralClass;
1553 }
1554
1555 // Iterators
1562};
1563
1564class FixedPointLiteral : public Expr, public APIntStorage {
1565 SourceLocation Loc;
1566 unsigned Scale;
1567
1568 /// \brief Construct an empty fixed-point literal.
1569 explicit FixedPointLiteral(EmptyShell Empty)
1570 : Expr(FixedPointLiteralClass, Empty) {}
1571
1572 public:
1573 FixedPointLiteral(const ASTContext &C, const llvm::APInt &V, QualType type,
1574 SourceLocation l, unsigned Scale);
1575
1576 // Store the int as is without any bit shifting.
1577 static FixedPointLiteral *CreateFromRawInt(const ASTContext &C,
1578 const llvm::APInt &V,
1580 unsigned Scale);
1581
1582 /// Returns an empty fixed-point literal.
1583 static FixedPointLiteral *Create(const ASTContext &C, EmptyShell Empty);
1584
1585 /// Returns an internal integer representation of the literal.
1586 llvm::APInt getValue() const { return APIntStorage::getValue(); }
1587
1588 SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
1589 SourceLocation getEndLoc() const LLVM_READONLY { return Loc; }
1590
1591 /// \brief Retrieve the location of the literal.
1592 SourceLocation getLocation() const { return Loc; }
1593
1594 void setLocation(SourceLocation Location) { Loc = Location; }
1595
1596 unsigned getScale() const { return Scale; }
1597 void setScale(unsigned S) { Scale = S; }
1598
1599 static bool classof(const Stmt *T) {
1600 return T->getStmtClass() == FixedPointLiteralClass;
1601 }
1602
1603 std::string getValueAsString(unsigned Radix) const;
1604
1605 // Iterators
1612};
1613
1615
1616class CharacterLiteral : public Expr {
1617 unsigned Value;
1618 SourceLocation Loc;
1619public:
1620 // type should be IntTy
1623 : Expr(CharacterLiteralClass, type, VK_PRValue, OK_Ordinary),
1624 Value(value), Loc(l) {
1625 CharacterLiteralBits.Kind = llvm::to_underlying(kind);
1626 setDependence(ExprDependence::None);
1627 }
1628
1629 /// Construct an empty character literal.
1630 CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { }
1631
1632 SourceLocation getLocation() const { return Loc; }
1634 return static_cast<CharacterLiteralKind>(CharacterLiteralBits.Kind);
1635 }
1636
1637 SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
1638 SourceLocation getEndLoc() const LLVM_READONLY { return Loc; }
1639
1640 unsigned getValue() const { return Value; }
1641
1642 void setLocation(SourceLocation Location) { Loc = Location; }
1644 CharacterLiteralBits.Kind = llvm::to_underlying(kind);
1645 }
1646 void setValue(unsigned Val) { Value = Val; }
1647
1648 static bool classof(const Stmt *T) {
1649 return T->getStmtClass() == CharacterLiteralClass;
1650 }
1651
1652 static void print(unsigned val, CharacterLiteralKind Kind, raw_ostream &OS);
1653
1654 // Iterators
1661};
1662
1663class FloatingLiteral : public Expr, private APFloatStorage {
1664 SourceLocation Loc;
1665
1666 FloatingLiteral(const ASTContext &C, const llvm::APFloat &V, bool isexact,
1668
1669 /// Construct an empty floating-point literal.
1670 explicit FloatingLiteral(const ASTContext &C, EmptyShell Empty);
1671
1672public:
1673 static FloatingLiteral *Create(const ASTContext &C, const llvm::APFloat &V,
1674 bool isexact, QualType Type, SourceLocation L);
1675 static FloatingLiteral *Create(const ASTContext &C, EmptyShell Empty);
1676
1677 llvm::APFloat getValue() const {
1679 }
1680 void setValue(const ASTContext &C, const llvm::APFloat &Val) {
1681 assert(&getSemantics() == &Val.getSemantics() && "Inconsistent semantics");
1683 }
1684
1685 /// Get a raw enumeration value representing the floating-point semantics of
1686 /// this literal (32-bit IEEE, x87, ...), suitable for serialization.
1687 llvm::APFloatBase::Semantics getRawSemantics() const {
1688 return static_cast<llvm::APFloatBase::Semantics>(
1689 FloatingLiteralBits.Semantics);
1690 }
1691
1692 /// Set the raw enumeration value representing the floating-point semantics of
1693 /// this literal (32-bit IEEE, x87, ...), suitable for serialization.
1694 void setRawSemantics(llvm::APFloatBase::Semantics Sem) {
1695 FloatingLiteralBits.Semantics = Sem;
1696 }
1697
1698 /// Return the APFloat semantics this literal uses.
1699 const llvm::fltSemantics &getSemantics() const {
1700 return llvm::APFloatBase::EnumToSemantics(
1701 static_cast<llvm::APFloatBase::Semantics>(
1702 FloatingLiteralBits.Semantics));
1703 }
1704
1705 /// Set the APFloat semantics this literal uses.
1706 void setSemantics(const llvm::fltSemantics &Sem) {
1707 FloatingLiteralBits.Semantics = llvm::APFloatBase::SemanticsToEnum(Sem);
1708 }
1709
1710 bool isExact() const { return FloatingLiteralBits.IsExact; }
1711 void setExact(bool E) { FloatingLiteralBits.IsExact = E; }
1712
1713 /// getValueAsApproximateDouble - This returns the value as an inaccurate
1714 /// double. Note that this may cause loss of precision, but is useful for
1715 /// debugging dumps, etc.
1716 double getValueAsApproximateDouble() const;
1717
1718 SourceLocation getLocation() const { return Loc; }
1719 void setLocation(SourceLocation L) { Loc = L; }
1720
1721 SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
1722 SourceLocation getEndLoc() const LLVM_READONLY { return Loc; }
1723
1724 static bool classof(const Stmt *T) {
1725 return T->getStmtClass() == FloatingLiteralClass;
1726 }
1727
1728 // Iterators
1735};
1736
1737/// ImaginaryLiteral - We support imaginary integer and floating point literals,
1738/// like "1.0i". We represent these as a wrapper around FloatingLiteral and
1739/// IntegerLiteral classes. Instances of this class always have a Complex type
1740/// whose element type matches the subexpression.
1741///
1742class ImaginaryLiteral : public Expr {
1743 Stmt *Val;
1744public:
1746 : Expr(ImaginaryLiteralClass, Ty, VK_PRValue, OK_Ordinary), Val(val) {
1747 setDependence(ExprDependence::None);
1748 }
1749
1750 /// Build an empty imaginary literal.
1752 : Expr(ImaginaryLiteralClass, Empty) { }
1753
1754 const Expr *getSubExpr() const { return cast<Expr>(Val); }
1755 Expr *getSubExpr() { return cast<Expr>(Val); }
1756 void setSubExpr(Expr *E) { Val = E; }
1757
1758 SourceLocation getBeginLoc() const LLVM_READONLY {
1759 return Val->getBeginLoc();
1760 }
1761 SourceLocation getEndLoc() const LLVM_READONLY { return Val->getEndLoc(); }
1762
1763 static bool classof(const Stmt *T) {
1764 return T->getStmtClass() == ImaginaryLiteralClass;
1765 }
1766
1767 // Iterators
1768 child_range children() { return child_range(&Val, &Val+1); }
1770 return const_child_range(&Val, &Val + 1);
1771 }
1772};
1773
1781 // Binary kind of string literal is used for the data coming via #embed
1782 // directive. File's binary contents is transformed to a special kind of
1783 // string literal that in some cases may be used directly as an initializer
1784 // and some features of classic string literals are not applicable to this
1785 // kind of a string literal, for example finding a particular byte's source
1786 // location for better diagnosing.
1788};
1789
1790/// StringLiteral - This represents a string literal expression, e.g. "foo"
1791/// or L"bar" (wide strings). The actual string data can be obtained with
1792/// getBytes() and is NOT null-terminated. The length of the string data is
1793/// determined by calling getByteLength().
1794///
1795/// The C type for a string is always a ConstantArrayType. In C++, the char
1796/// type is const qualified, in C it is not.
1797///
1798/// Note that strings in C can be formed by concatenation of multiple string
1799/// literal pptokens in translation phase #6. This keeps track of the locations
1800/// of each of these pieces.
1801///
1802/// Strings in C can also be truncated and extended by assigning into arrays,
1803/// e.g. with constructs like:
1804/// char X[2] = "foobar";
1805/// In this case, getByteLength() will return 6, but the string literal will
1806/// have type "char[2]".
1807class StringLiteral final
1808 : public Expr,
1809 private llvm::TrailingObjects<StringLiteral, unsigned, SourceLocation,
1810 char> {
1811 friend class ASTStmtReader;
1812 friend TrailingObjects;
1813
1814 /// StringLiteral is followed by several trailing objects. They are in order:
1815 ///
1816 /// * A single unsigned storing the length in characters of this string. The
1817 /// length in bytes is this length times the width of a single character.
1818 /// Always present and stored as a trailing objects because storing it in
1819 /// StringLiteral would increase the size of StringLiteral by sizeof(void *)
1820 /// due to alignment requirements. If you add some data to StringLiteral,
1821 /// consider moving it inside StringLiteral.
1822 ///
1823 /// * An array of getNumConcatenated() SourceLocation, one for each of the
1824 /// token this string is made of.
1825 ///
1826 /// * An array of getByteLength() char used to store the string data.
1827
1828 unsigned numTrailingObjects(OverloadToken<unsigned>) const { return 1; }
1829 unsigned numTrailingObjects(OverloadToken<SourceLocation>) const {
1830 return getNumConcatenated();
1831 }
1832
1833 unsigned numTrailingObjects(OverloadToken<char>) const {
1834 return getByteLength();
1835 }
1836
1837 char *getStrDataAsChar() { return getTrailingObjects<char>(); }
1838 const char *getStrDataAsChar() const { return getTrailingObjects<char>(); }
1839
1840 const uint16_t *getStrDataAsUInt16() const {
1841 return reinterpret_cast<const uint16_t *>(getTrailingObjects<char>());
1842 }
1843
1844 const uint32_t *getStrDataAsUInt32() const {
1845 return reinterpret_cast<const uint32_t *>(getTrailingObjects<char>());
1846 }
1847
1848 /// Build a string literal.
1849 StringLiteral(const ASTContext &Ctx, StringRef Str, StringLiteralKind Kind,
1850 bool Pascal, QualType Ty, ArrayRef<SourceLocation> Locs);
1851
1852 /// Build an empty string literal.
1853 StringLiteral(EmptyShell Empty, unsigned NumConcatenated, unsigned Length,
1854 unsigned CharByteWidth);
1855
1856 /// Map a target and string kind to the appropriate character width.
1857 static unsigned mapCharByteWidth(TargetInfo const &Target,
1859
1860 /// Set one of the string literal token.
1861 void setStrTokenLoc(unsigned TokNum, SourceLocation L) {
1862 assert(TokNum < getNumConcatenated() && "Invalid tok number");
1863 getTrailingObjects<SourceLocation>()[TokNum] = L;
1864 }
1865
1866public:
1867 /// This is the "fully general" constructor that allows representation of
1868 /// strings formed from one or more concatenated tokens.
1869 static StringLiteral *Create(const ASTContext &Ctx, StringRef Str,
1870 StringLiteralKind Kind, bool Pascal, QualType Ty,
1871 ArrayRef<SourceLocation> Locs);
1872
1873 /// Construct an empty string literal.
1874 static StringLiteral *CreateEmpty(const ASTContext &Ctx,
1875 unsigned NumConcatenated, unsigned Length,
1876 unsigned CharByteWidth);
1877
1878 StringRef getString() const {
1879 assert((isUnevaluated() || getCharByteWidth() == 1) &&
1880 "This function is used in places that assume strings use char");
1881 return StringRef(getStrDataAsChar(), getByteLength());
1882 }
1883
1884 /// Allow access to clients that need the byte representation, such as
1885 /// ASTWriterStmt::VisitStringLiteral().
1886 StringRef getBytes() const {
1887 // FIXME: StringRef may not be the right type to use as a result for this.
1888 return StringRef(getStrDataAsChar(), getByteLength());
1889 }
1890
1891 void outputString(raw_ostream &OS) const;
1892
1893 uint32_t getCodeUnit(size_t i) const {
1894 assert(i < getLength() && "out of bounds access");
1895 switch (getCharByteWidth()) {
1896 case 1:
1897 return static_cast<unsigned char>(getStrDataAsChar()[i]);
1898 case 2:
1899 return getStrDataAsUInt16()[i];
1900 case 4:
1901 return getStrDataAsUInt32()[i];
1902 }
1903 llvm_unreachable("Unsupported character width!");
1904 }
1905
1906 // Get code unit but preserve sign info.
1907 int64_t getCodeUnitS(size_t I, uint64_t BitWidth) const {
1908 int64_t V = getCodeUnit(I);
1909 if (isOrdinary() || isWide()) {
1910 // Ordinary and wide string literals have types that can be signed.
1911 // It is important for checking C23 constexpr initializers.
1912 unsigned Width = getCharByteWidth() * BitWidth;
1913 llvm::APInt AInt(Width, (uint64_t)V);
1914 V = AInt.getSExtValue();
1915 }
1916 return V;
1917 }
1918
1919 unsigned getByteLength() const { return getCharByteWidth() * getLength(); }
1920 unsigned getLength() const { return *getTrailingObjects<unsigned>(); }
1921 unsigned getCharByteWidth() const { return StringLiteralBits.CharByteWidth; }
1922
1924 return static_cast<StringLiteralKind>(StringLiteralBits.Kind);
1925 }
1926
1927 bool isOrdinary() const { return getKind() == StringLiteralKind::Ordinary; }
1928 bool isWide() const { return getKind() == StringLiteralKind::Wide; }
1929 bool isUTF8() const { return getKind() == StringLiteralKind::UTF8; }
1930 bool isUTF16() const { return getKind() == StringLiteralKind::UTF16; }
1931 bool isUTF32() const { return getKind() == StringLiteralKind::UTF32; }
1933 bool isPascal() const { return StringLiteralBits.IsPascal; }
1934
1935 bool containsNonAscii() const {
1936 for (auto c : getString())
1937 if (!isASCII(c))
1938 return true;
1939 return false;
1940 }
1941
1943 for (auto c : getString())
1944 if (!isASCII(c) || !c)
1945 return true;
1946 return false;
1947 }
1948
1949 /// getNumConcatenated - Get the number of string literal tokens that were
1950 /// concatenated in translation phase #6 to form this string literal.
1951 unsigned getNumConcatenated() const {
1952 return StringLiteralBits.NumConcatenated;
1953 }
1954
1955 /// Get one of the string literal token.
1956 SourceLocation getStrTokenLoc(unsigned TokNum) const {
1957 assert(TokNum < getNumConcatenated() && "Invalid tok number");
1958 return getTrailingObjects<SourceLocation>()[TokNum];
1959 }
1960
1961 /// getLocationOfByte - Return a source location that points to the specified
1962 /// byte of this string literal.
1963 ///
1964 /// Strings are amazingly complex. They can be formed from multiple tokens
1965 /// and can have escape sequences in them in addition to the usual trigraph
1966 /// and escaped newline business. This routine handles this complexity.
1967 ///
1969 getLocationOfByte(unsigned ByteNo, const SourceManager &SM,
1970 const LangOptions &Features, const TargetInfo &Target,
1971 unsigned *StartToken = nullptr,
1972 unsigned *StartTokenByteOffset = nullptr) const;
1973
1975
1977 return getTrailingObjects<SourceLocation>();
1978 }
1979
1981 return getTrailingObjects<SourceLocation>() + getNumConcatenated();
1982 }
1983
1984 SourceLocation getBeginLoc() const LLVM_READONLY { return *tokloc_begin(); }
1985 SourceLocation getEndLoc() const LLVM_READONLY { return *(tokloc_end() - 1); }
1986
1987 static bool classof(const Stmt *T) {
1988 return T->getStmtClass() == StringLiteralClass;
1989 }
1990
1991 // Iterators
1998};
1999
2003 LFunction, // Same as Function, but as wide string.
2006 LFuncSig, // Same as FuncSig, but as wide string
2008 /// The same as PrettyFunction, except that the
2009 /// 'virtual' keyword is omitted for virtual member functions.
2011};
2012
2013/// [C99 6.4.2.2] - A predefined identifier such as __func__.
2014class PredefinedExpr final
2015 : public Expr,
2016 private llvm::TrailingObjects<PredefinedExpr, Stmt *> {
2017 friend class ASTStmtReader;
2018 friend TrailingObjects;
2019
2020 // PredefinedExpr is optionally followed by a single trailing
2021 // "Stmt *" for the predefined identifier. It is present if and only if
2022 // hasFunctionName() is true and is always a "StringLiteral *".
2023
2024 PredefinedExpr(SourceLocation L, QualType FNTy, PredefinedIdentKind IK,
2025 bool IsTransparent, StringLiteral *SL);
2026
2027 explicit PredefinedExpr(EmptyShell Empty, bool HasFunctionName);
2028
2029 /// True if this PredefinedExpr has storage for a function name.
2030 bool hasFunctionName() const { return PredefinedExprBits.HasFunctionName; }
2031
2032 void setFunctionName(StringLiteral *SL) {
2033 assert(hasFunctionName() &&
2034 "This PredefinedExpr has no storage for a function name!");
2035 *getTrailingObjects() = SL;
2036 }
2037
2038public:
2039 /// Create a PredefinedExpr.
2040 ///
2041 /// If IsTransparent, the PredefinedExpr is transparently handled as a
2042 /// StringLiteral.
2043 static PredefinedExpr *Create(const ASTContext &Ctx, SourceLocation L,
2044 QualType FNTy, PredefinedIdentKind IK,
2045 bool IsTransparent, StringLiteral *SL);
2046
2047 /// Create an empty PredefinedExpr.
2048 static PredefinedExpr *CreateEmpty(const ASTContext &Ctx,
2049 bool HasFunctionName);
2050
2052 return static_cast<PredefinedIdentKind>(PredefinedExprBits.Kind);
2053 }
2054
2055 bool isTransparent() const { return PredefinedExprBits.IsTransparent; }
2056
2059
2061 return hasFunctionName()
2062 ? static_cast<StringLiteral *>(*getTrailingObjects())
2063 : nullptr;
2064 }
2065
2067 return hasFunctionName()
2068 ? static_cast<StringLiteral *>(*getTrailingObjects())
2069 : nullptr;
2070 }
2071
2072 static StringRef getIdentKindName(PredefinedIdentKind IK);
2073 StringRef getIdentKindName() const {
2075 }
2076
2077 static std::string ComputeName(PredefinedIdentKind IK,
2078 const Decl *CurrentDecl,
2079 bool ForceElaboratedPrinting = false);
2080
2083
2084 static bool classof(const Stmt *T) {
2085 return T->getStmtClass() == PredefinedExprClass;
2086 }
2087
2088 // Iterators
2090 return child_range(getTrailingObjects(hasFunctionName()));
2091 }
2092
2094 return const_child_range(getTrailingObjects(hasFunctionName()));
2095 }
2096};
2097
2098/// This expression type represents an asterisk in an OpenACC Size-Expr, used in
2099/// the 'tile' and 'gang' clauses. It is of 'int' type, but should not be
2100/// evaluated.
2101class OpenACCAsteriskSizeExpr final : public Expr {
2102 friend class ASTStmtReader;
2103 SourceLocation AsteriskLoc;
2104
2105 OpenACCAsteriskSizeExpr(SourceLocation AsteriskLoc, QualType IntTy)
2106 : Expr(OpenACCAsteriskSizeExprClass, IntTy, VK_PRValue, OK_Ordinary),
2107 AsteriskLoc(AsteriskLoc) {}
2108
2109 void setAsteriskLocation(SourceLocation Loc) { AsteriskLoc = Loc; }
2110
2111public:
2112 static OpenACCAsteriskSizeExpr *Create(const ASTContext &C,
2113 SourceLocation Loc);
2114 static OpenACCAsteriskSizeExpr *CreateEmpty(const ASTContext &C);
2115
2116 SourceLocation getBeginLoc() const { return AsteriskLoc; }
2117 SourceLocation getEndLoc() const { return AsteriskLoc; }
2118 SourceLocation getLocation() const { return AsteriskLoc; }
2119
2120 static bool classof(const Stmt *T) {
2121 return T->getStmtClass() == OpenACCAsteriskSizeExprClass;
2122 }
2123 // Iterators
2127
2131};
2132
2133// This represents a use of the __builtin_sycl_unique_stable_name, which takes a
2134// type-id, and at CodeGen time emits a unique string representation of the
2135// type in a way that permits us to properly encode information about the SYCL
2136// kernels.
2137class SYCLUniqueStableNameExpr final : public Expr {
2138 friend class ASTStmtReader;
2139 SourceLocation OpLoc, LParen, RParen;
2140 TypeSourceInfo *TypeInfo;
2141
2142 SYCLUniqueStableNameExpr(EmptyShell Empty, QualType ResultTy);
2143 SYCLUniqueStableNameExpr(SourceLocation OpLoc, SourceLocation LParen,
2144 SourceLocation RParen, QualType ResultTy,
2145 TypeSourceInfo *TSI);
2146
2147 void setTypeSourceInfo(TypeSourceInfo *Ty) { TypeInfo = Ty; }
2148
2149 void setLocation(SourceLocation L) { OpLoc = L; }
2150 void setLParenLocation(SourceLocation L) { LParen = L; }
2151 void setRParenLocation(SourceLocation L) { RParen = L; }
2152
2153public:
2154 TypeSourceInfo *getTypeSourceInfo() { return TypeInfo; }
2155
2156 const TypeSourceInfo *getTypeSourceInfo() const { return TypeInfo; }
2157
2159 Create(const ASTContext &Ctx, SourceLocation OpLoc, SourceLocation LParen,
2160 SourceLocation RParen, TypeSourceInfo *TSI);
2161
2163
2165 SourceLocation getEndLoc() const { return RParen; }
2166 SourceLocation getLocation() const { return OpLoc; }
2167 SourceLocation getLParenLocation() const { return LParen; }
2168 SourceLocation getRParenLocation() const { return RParen; }
2169
2170 static bool classof(const Stmt *T) {
2171 return T->getStmtClass() == SYCLUniqueStableNameExprClass;
2172 }
2173
2174 // Iterators
2178
2182
2183 // Convenience function to generate the name of the currently stored type.
2184 std::string ComputeName(ASTContext &Context) const;
2185
2186 // Get the generated name of the type. Note that this only works after all
2187 // kernels have been instantiated.
2188 static std::string ComputeName(ASTContext &Context, QualType Ty);
2189};
2190
2191/// ParenExpr - This represents a parenthesized expression, e.g. "(1)". This
2192/// AST node is only formed if full location information is requested.
2193class ParenExpr : public Expr {
2194 SourceLocation L, R;
2195 Stmt *Val;
2196
2197public:
2199 : Expr(ParenExprClass, val->getType(), val->getValueKind(),
2200 val->getObjectKind()),
2201 L(l), R(r), Val(val) {
2202 ParenExprBits.ProducedByFoldExpansion = false;
2204 }
2205
2206 /// Construct an empty parenthesized expression.
2208 : Expr(ParenExprClass, Empty) { }
2209
2210 const Expr *getSubExpr() const { return cast<Expr>(Val); }
2211 Expr *getSubExpr() { return cast<Expr>(Val); }
2212 void setSubExpr(Expr *E) { Val = E; }
2213
2214 SourceLocation getBeginLoc() const LLVM_READONLY { return L; }
2215 SourceLocation getEndLoc() const LLVM_READONLY { return R; }
2216
2217 /// Get the location of the left parentheses '('.
2218 SourceLocation getLParen() const { return L; }
2219 void setLParen(SourceLocation Loc) { L = Loc; }
2220
2221 /// Get the location of the right parentheses ')'.
2222 SourceLocation getRParen() const { return R; }
2223 void setRParen(SourceLocation Loc) { R = Loc; }
2224
2225 static bool classof(const Stmt *T) {
2226 return T->getStmtClass() == ParenExprClass;
2227 }
2228
2229 // Iterators
2230 child_range children() { return child_range(&Val, &Val+1); }
2232 return const_child_range(&Val, &Val + 1);
2233 }
2234
2236 return ParenExprBits.ProducedByFoldExpansion != 0;
2237 }
2238 void setIsProducedByFoldExpansion(bool ProducedByFoldExpansion = true) {
2239 ParenExprBits.ProducedByFoldExpansion = ProducedByFoldExpansion;
2240 }
2241};
2242
2243/// UnaryOperator - This represents the unary-expression's (except sizeof and
2244/// alignof), the postinc/postdec operators from postfix-expression, and various
2245/// extensions.
2246///
2247/// Notes on various nodes:
2248///
2249/// Real/Imag - These return the real/imag part of a complex operand. If
2250/// applied to a non-complex value, the former returns its operand and the
2251/// later returns zero in the type of the operand.
2252///
2253class UnaryOperator final
2254 : public Expr,
2255 private llvm::TrailingObjects<UnaryOperator, FPOptionsOverride> {
2256 Stmt *Val;
2257
2258 FPOptionsOverride &getTrailingFPFeatures() {
2259 assert(UnaryOperatorBits.HasFPFeatures);
2260 return *getTrailingObjects();
2261 }
2262
2263 const FPOptionsOverride &getTrailingFPFeatures() const {
2264 assert(UnaryOperatorBits.HasFPFeatures);
2265 return *getTrailingObjects();
2266 }
2267
2268public:
2270
2271protected:
2272 UnaryOperator(const ASTContext &Ctx, Expr *input, Opcode opc, QualType type,
2274 bool CanOverflow, FPOptionsOverride FPFeatures);
2275
2276 /// Build an empty unary operator.
2277 explicit UnaryOperator(bool HasFPFeatures, EmptyShell Empty)
2278 : Expr(UnaryOperatorClass, Empty) {
2279 UnaryOperatorBits.Opc = UO_AddrOf;
2280 UnaryOperatorBits.HasFPFeatures = HasFPFeatures;
2281 }
2282
2283public:
2284 static UnaryOperator *CreateEmpty(const ASTContext &C, bool hasFPFeatures);
2285
2286 static UnaryOperator *Create(const ASTContext &C, Expr *input, Opcode opc,
2289 bool CanOverflow, FPOptionsOverride FPFeatures);
2290
2292 return static_cast<Opcode>(UnaryOperatorBits.Opc);
2293 }
2294 void setOpcode(Opcode Opc) { UnaryOperatorBits.Opc = Opc; }
2295
2296 Expr *getSubExpr() const { return cast<Expr>(Val); }
2297 void setSubExpr(Expr *E) { Val = E; }
2298
2299 /// getOperatorLoc - Return the location of the operator.
2302
2303 /// Returns true if the unary operator can cause an overflow. For instance,
2304 /// signed int i = INT_MAX; i++;
2305 /// signed char c = CHAR_MAX; c++;
2306 /// Due to integer promotions, c++ is promoted to an int before the postfix
2307 /// increment, and the result is an int that cannot overflow. However, i++
2308 /// can overflow.
2309 bool canOverflow() const { return UnaryOperatorBits.CanOverflow; }
2310 void setCanOverflow(bool C) { UnaryOperatorBits.CanOverflow = C; }
2311
2312 /// Get the FP contractibility status of this operator. Only meaningful for
2313 /// operations on floating point types.
2317
2318 /// Get the FENV_ACCESS status of this operator. Only meaningful for
2319 /// operations on floating point types.
2320 bool isFEnvAccessOn(const LangOptions &LO) const {
2321 return getFPFeaturesInEffect(LO).getAllowFEnvAccess();
2322 }
2323
2324 /// isPostfix - Return true if this is a postfix operation, like x++.
2325 static bool isPostfix(Opcode Op) {
2326 return Op == UO_PostInc || Op == UO_PostDec;
2327 }
2328
2329 /// isPrefix - Return true if this is a prefix operation, like --x.
2330 static bool isPrefix(Opcode Op) {
2331 return Op == UO_PreInc || Op == UO_PreDec;
2332 }
2333
2334 bool isPrefix() const { return isPrefix(getOpcode()); }
2335 bool isPostfix() const { return isPostfix(getOpcode()); }
2336
2337 static bool isIncrementOp(Opcode Op) {
2338 return Op == UO_PreInc || Op == UO_PostInc;
2339 }
2340 bool isIncrementOp() const {
2341 return isIncrementOp(getOpcode());
2342 }
2343
2344 static bool isDecrementOp(Opcode Op) {
2345 return Op == UO_PreDec || Op == UO_PostDec;
2346 }
2347 bool isDecrementOp() const {
2348 return isDecrementOp(getOpcode());
2349 }
2350
2351 static bool isIncrementDecrementOp(Opcode Op) { return Op <= UO_PreDec; }
2354 }
2355
2356 static bool isArithmeticOp(Opcode Op) {
2357 return Op >= UO_Plus && Op <= UO_LNot;
2358 }
2359 bool isArithmeticOp() const { return isArithmeticOp(getOpcode()); }
2360
2361 /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
2362 /// corresponds to, e.g. "sizeof" or "[pre]++"
2363 static StringRef getOpcodeStr(Opcode Op);
2364
2365 /// Retrieve the unary opcode that corresponds to the given
2366 /// overloaded operator.
2367 static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix);
2368
2369 /// Retrieve the overloaded operator kind that corresponds to
2370 /// the given unary opcode.
2372
2373 SourceLocation getBeginLoc() const LLVM_READONLY {
2374 return isPostfix() ? Val->getBeginLoc() : getOperatorLoc();
2375 }
2376 SourceLocation getEndLoc() const LLVM_READONLY {
2377 return isPostfix() ? getOperatorLoc() : Val->getEndLoc();
2378 }
2380
2381 static bool classof(const Stmt *T) {
2382 return T->getStmtClass() == UnaryOperatorClass;
2383 }
2384
2385 // Iterators
2386 child_range children() { return child_range(&Val, &Val+1); }
2388 return const_child_range(&Val, &Val + 1);
2389 }
2390
2391 /// Is FPFeatures in Trailing Storage?
2392 bool hasStoredFPFeatures() const { return UnaryOperatorBits.HasFPFeatures; }
2393
2394 /// Get FPFeatures from trailing storage.
2396 return getTrailingFPFeatures();
2397 }
2398
2399 /// Get the store FPOptionsOverride or default if not stored.
2403
2404protected:
2405 /// Set FPFeatures in trailing storage, used by Serialization & ASTImporter.
2406 void setStoredFPFeatures(FPOptionsOverride F) { getTrailingFPFeatures() = F; }
2407
2408public:
2409 /// Get the FP features status of this operator. Only meaningful for
2410 /// operations on floating point types.
2412 if (UnaryOperatorBits.HasFPFeatures)
2415 }
2417 if (UnaryOperatorBits.HasFPFeatures)
2418 return getStoredFPFeatures();
2419 return FPOptionsOverride();
2420 }
2421
2423 friend class ASTNodeImporter;
2424 friend class ASTReader;
2425 friend class ASTStmtReader;
2426 friend class ASTStmtWriter;
2427};
2428
2429/// Helper class for OffsetOfExpr.
2430
2431// __builtin_offsetof(type, identifier(.identifier|[expr])*)
2433public:
2434 /// The kind of offsetof node we have.
2435 enum Kind {
2436 /// An index into an array.
2437 Array = 0x00,
2438 /// A field.
2439 Field = 0x01,
2440 /// A field in a dependent type, known only by its name.
2442 /// An implicit indirection through a C++ base class, when the
2443 /// field found is in a base class.
2444 Base = 0x03
2445 };
2446
2447private:
2448 enum { MaskBits = 2, Mask = 0x03 };
2449
2450 /// The source range that covers this part of the designator.
2451 SourceRange Range;
2452
2453 /// The data describing the designator, which comes in three
2454 /// different forms, depending on the lower two bits.
2455 /// - An unsigned index into the array of Expr*'s stored after this node
2456 /// in memory, for [constant-expression] designators.
2457 /// - A FieldDecl*, for references to a known field.
2458 /// - An IdentifierInfo*, for references to a field with a given name
2459 /// when the class type is dependent.
2460 /// - A CXXBaseSpecifier*, for references that look at a field in a
2461 /// base class.
2463
2464public:
2465 /// Create an offsetof node that refers to an array element.
2466 OffsetOfNode(SourceLocation LBracketLoc, unsigned Index,
2467 SourceLocation RBracketLoc)
2468 : Range(LBracketLoc, RBracketLoc), Data((Index << 2) | Array) {}
2469
2470 /// Create an offsetof node that refers to a field.
2472 : Range(DotLoc.isValid() ? DotLoc : NameLoc, NameLoc),
2473 Data(reinterpret_cast<uintptr_t>(Field) | OffsetOfNode::Field) {}
2474
2475 /// Create an offsetof node that refers to an identifier.
2477 SourceLocation NameLoc)
2478 : Range(DotLoc.isValid() ? DotLoc : NameLoc, NameLoc),
2479 Data(reinterpret_cast<uintptr_t>(Name) | Identifier) {}
2480
2481 /// Create an offsetof node that refers into a C++ base class.
2483 : Data(reinterpret_cast<uintptr_t>(Base) | OffsetOfNode::Base) {}
2484
2485 /// Determine what kind of offsetof node this is.
2486 Kind getKind() const { return static_cast<Kind>(Data & Mask); }
2487
2488 /// For an array element node, returns the index into the array
2489 /// of expressions.
2490 unsigned getArrayExprIndex() const {
2491 assert(getKind() == Array);
2492 return Data >> 2;
2493 }
2494
2495 /// For a field offsetof node, returns the field.
2497 assert(getKind() == Field);
2498 return reinterpret_cast<FieldDecl *>(Data & ~(uintptr_t)Mask);
2499 }
2500
2501 /// For a field or identifier offsetof node, returns the name of
2502 /// the field.
2503 const IdentifierInfo *getFieldName() const;
2504
2505 /// For a base class node, returns the base specifier.
2507 assert(getKind() == Base);
2508 return reinterpret_cast<CXXBaseSpecifier *>(Data & ~(uintptr_t)Mask);
2509 }
2510
2511 /// Retrieve the source range that covers this offsetof node.
2512 ///
2513 /// For an array element node, the source range contains the locations of
2514 /// the square brackets. For a field or identifier node, the source range
2515 /// contains the location of the period (if there is one) and the
2516 /// identifier.
2517 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
2518 SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); }
2519 SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); }
2520};
2521
2522/// OffsetOfExpr - [C99 7.17] - This represents an expression of the form
2523/// offsetof(record-type, member-designator). For example, given:
2524/// @code
2525/// struct S {
2526/// float f;
2527/// double d;
2528/// };
2529/// struct T {
2530/// int i;
2531/// struct S s[10];
2532/// };
2533/// @endcode
2534/// we can represent and evaluate the expression @c offsetof(struct T, s[2].d).
2535
2536class OffsetOfExpr final
2537 : public Expr,
2538 private llvm::TrailingObjects<OffsetOfExpr, OffsetOfNode, Expr *> {
2539 SourceLocation OperatorLoc, RParenLoc;
2540 // Base type;
2541 TypeSourceInfo *TSInfo;
2542 // Number of sub-components (i.e. instances of OffsetOfNode).
2543 unsigned NumComps;
2544 // Number of sub-expressions (i.e. array subscript expressions).
2545 unsigned NumExprs;
2546
2547 size_t numTrailingObjects(OverloadToken<OffsetOfNode>) const {
2548 return NumComps;
2549 }
2550
2551 OffsetOfExpr(const ASTContext &C, QualType type,
2552 SourceLocation OperatorLoc, TypeSourceInfo *tsi,
2554 SourceLocation RParenLoc);
2555
2556 explicit OffsetOfExpr(unsigned numComps, unsigned numExprs)
2557 : Expr(OffsetOfExprClass, EmptyShell()),
2558 TSInfo(nullptr), NumComps(numComps), NumExprs(numExprs) {}
2559
2560public:
2561
2562 static OffsetOfExpr *Create(const ASTContext &C, QualType type,
2563 SourceLocation OperatorLoc, TypeSourceInfo *tsi,
2565 ArrayRef<Expr*> exprs, SourceLocation RParenLoc);
2566
2567 static OffsetOfExpr *CreateEmpty(const ASTContext &C,
2568 unsigned NumComps, unsigned NumExprs);
2569
2570 /// getOperatorLoc - Return the location of the operator.
2571 SourceLocation getOperatorLoc() const { return OperatorLoc; }
2572 void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
2573
2574 /// Return the location of the right parentheses.
2575 SourceLocation getRParenLoc() const { return RParenLoc; }
2576 void setRParenLoc(SourceLocation R) { RParenLoc = R; }
2577
2579 return TSInfo;
2580 }
2582 TSInfo = tsi;
2583 }
2584
2585 const OffsetOfNode &getComponent(unsigned Idx) const {
2586 return getTrailingObjects<OffsetOfNode>(NumComps)[Idx];
2587 }
2588
2589 void setComponent(unsigned Idx, OffsetOfNode ON) {
2590 getTrailingObjects<OffsetOfNode>(NumComps)[Idx] = ON;
2591 }
2592
2593 unsigned getNumComponents() const {
2594 return NumComps;
2595 }
2596
2597 Expr* getIndexExpr(unsigned Idx) {
2598 return getTrailingObjects<Expr *>(NumExprs)[Idx];
2599 }
2600
2601 const Expr *getIndexExpr(unsigned Idx) const {
2602 return getTrailingObjects<Expr *>(NumExprs)[Idx];
2603 }
2604
2605 void setIndexExpr(unsigned Idx, Expr* E) {
2606 getTrailingObjects<Expr *>(NumComps)[Idx] = E;
2607 }
2608
2609 unsigned getNumExpressions() const {
2610 return NumExprs;
2611 }
2612
2613 SourceLocation getBeginLoc() const LLVM_READONLY { return OperatorLoc; }
2614 SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
2615
2616 static bool classof(const Stmt *T) {
2617 return T->getStmtClass() == OffsetOfExprClass;
2618 }
2619
2620 // Iterators
2622 Stmt **begin = reinterpret_cast<Stmt **>(getTrailingObjects<Expr *>());
2623 return child_range(begin, begin + NumExprs);
2624 }
2626 Stmt *const *begin =
2627 reinterpret_cast<Stmt *const *>(getTrailingObjects<Expr *>());
2628 return const_child_range(begin, begin + NumExprs);
2629 }
2631};
2632
2633/// UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated)
2634/// expression operand. Used for sizeof/alignof (C99 6.5.3.4) and
2635/// vec_step (OpenCL 1.1 6.11.12).
2637 union {
2640 } Argument;
2641 SourceLocation OpLoc, RParenLoc;
2642
2643public:
2644 UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, TypeSourceInfo *TInfo,
2645 QualType resultType, SourceLocation op,
2646 SourceLocation rp)
2647 : Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_PRValue,
2648 OK_Ordinary),
2649 OpLoc(op), RParenLoc(rp) {
2650 assert(ExprKind <= UETT_Last && "invalid enum value!");
2651 UnaryExprOrTypeTraitExprBits.Kind = ExprKind;
2652 assert(static_cast<unsigned>(ExprKind) ==
2654 "UnaryExprOrTypeTraitExprBits.Kind overflow!");
2655 UnaryExprOrTypeTraitExprBits.IsType = true;
2656 Argument.Ty = TInfo;
2658 }
2659
2660 UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, Expr *E,
2661 QualType resultType, SourceLocation op,
2662 SourceLocation rp);
2663
2664 /// Construct an empty sizeof/alignof expression.
2666 : Expr(UnaryExprOrTypeTraitExprClass, Empty) { }
2667
2668 UnaryExprOrTypeTrait getKind() const {
2669 return static_cast<UnaryExprOrTypeTrait>(UnaryExprOrTypeTraitExprBits.Kind);
2670 }
2671 void setKind(UnaryExprOrTypeTrait K) {
2672 assert(K <= UETT_Last && "invalid enum value!");
2674 assert(static_cast<unsigned>(K) == UnaryExprOrTypeTraitExprBits.Kind &&
2675 "UnaryExprOrTypeTraitExprBits.Kind overflow!");
2676 }
2677
2678 bool isArgumentType() const { return UnaryExprOrTypeTraitExprBits.IsType; }
2680 return getArgumentTypeInfo()->getType();
2681 }
2683 assert(isArgumentType() && "calling getArgumentType() when arg is expr");
2684 return Argument.Ty;
2685 }
2687 assert(!isArgumentType() && "calling getArgumentExpr() when arg is type");
2688 return static_cast<Expr*>(Argument.Ex);
2689 }
2690 const Expr *getArgumentExpr() const {
2691 return const_cast<UnaryExprOrTypeTraitExpr*>(this)->getArgumentExpr();
2692 }
2693
2695 Argument.Ex = E;
2696 UnaryExprOrTypeTraitExprBits.IsType = false;
2697 }
2699 Argument.Ty = TInfo;
2700 UnaryExprOrTypeTraitExprBits.IsType = true;
2701 }
2702
2703 /// Gets the argument type, or the type of the argument expression, whichever
2704 /// is appropriate.
2708
2709 SourceLocation getOperatorLoc() const { return OpLoc; }
2710 void setOperatorLoc(SourceLocation L) { OpLoc = L; }
2711
2712 SourceLocation getRParenLoc() const { return RParenLoc; }
2713 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2714
2715 SourceLocation getBeginLoc() const LLVM_READONLY { return OpLoc; }
2716 SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
2717
2718 static bool classof(const Stmt *T) {
2719 return T->getStmtClass() == UnaryExprOrTypeTraitExprClass;
2720 }
2721
2722 // Iterators
2725};
2726
2727//===----------------------------------------------------------------------===//
2728// Postfix Operators.
2729//===----------------------------------------------------------------------===//
2730
2731/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
2732class ArraySubscriptExpr : public Expr {
2733 enum { LHS, RHS, END_EXPR };
2734 Stmt *SubExprs[END_EXPR];
2735
2736 bool lhsIsBase() const { return getRHS()->getType()->isIntegerType(); }
2737
2738public:
2740 ExprObjectKind OK, SourceLocation rbracketloc)
2741 : Expr(ArraySubscriptExprClass, t, VK, OK) {
2742 SubExprs[LHS] = lhs;
2743 SubExprs[RHS] = rhs;
2744 ArrayOrMatrixSubscriptExprBits.RBracketLoc = rbracketloc;
2746 }
2747
2748 /// Create an empty array subscript expression.
2750 : Expr(ArraySubscriptExprClass, Shell) { }
2751
2752 /// An array access can be written A[4] or 4[A] (both are equivalent).
2753 /// - getBase() and getIdx() always present the normalized view: A[4].
2754 /// In this case getBase() returns "A" and getIdx() returns "4".
2755 /// - getLHS() and getRHS() present the syntactic view. e.g. for
2756 /// 4[A] getLHS() returns "4".
2757 /// Note: Because vector element access is also written A[4] we must
2758 /// predicate the format conversion in getBase and getIdx only on the
2759 /// the type of the RHS, as it is possible for the LHS to be a vector of
2760 /// integer type
2761 Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); }
2762 const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
2763 void setLHS(Expr *E) { SubExprs[LHS] = E; }
2764
2765 Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); }
2766 const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
2767 void setRHS(Expr *E) { SubExprs[RHS] = E; }
2768
2769 Expr *getBase() { return lhsIsBase() ? getLHS() : getRHS(); }
2770 const Expr *getBase() const { return lhsIsBase() ? getLHS() : getRHS(); }
2771
2772 Expr *getIdx() { return lhsIsBase() ? getRHS() : getLHS(); }
2773 const Expr *getIdx() const { return lhsIsBase() ? getRHS() : getLHS(); }
2774
2775 SourceLocation getBeginLoc() const LLVM_READONLY {
2776 return getLHS()->getBeginLoc();
2777 }
2779
2781 return ArrayOrMatrixSubscriptExprBits.RBracketLoc;
2782 }
2784 ArrayOrMatrixSubscriptExprBits.RBracketLoc = L;
2785 }
2786
2787 SourceLocation getExprLoc() const LLVM_READONLY {
2788 return getBase()->getExprLoc();
2789 }
2790
2791 static bool classof(const Stmt *T) {
2792 return T->getStmtClass() == ArraySubscriptExprClass;
2793 }
2794
2795 // Iterators
2797 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
2798 }
2800 return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
2801 }
2802};
2803
2804/// MatrixSingleSubscriptExpr - Matrix single subscript expression for the
2805/// MatrixType extension when you want to get\set a vector from a Matrix.
2807 enum { BASE, ROW_IDX, END_EXPR };
2808 Stmt *SubExprs[END_EXPR];
2809
2810public:
2811 /// matrix[row]
2812 ///
2813 /// \param Base The matrix expression.
2814 /// \param RowIdx The row index expression.
2815 /// \param T The type of the row (usually a vector type).
2816 /// \param RBracketLoc Location of the closing ']'.
2818 SourceLocation RBracketLoc)
2819 : Expr(MatrixSingleSubscriptExprClass, T,
2820 Base->getValueKind(), // lvalue/rvalue follows the matrix base
2822 SubExprs[BASE] = Base;
2823 SubExprs[ROW_IDX] = RowIdx;
2824 ArrayOrMatrixSubscriptExprBits.RBracketLoc = RBracketLoc;
2826 }
2827
2828 /// Create an empty matrix single-subscript expression.
2830 : Expr(MatrixSingleSubscriptExprClass, Shell) {}
2831
2832 Expr *getBase() { return cast<Expr>(SubExprs[BASE]); }
2833 const Expr *getBase() const { return cast<Expr>(SubExprs[BASE]); }
2834 void setBase(Expr *E) { SubExprs[BASE] = E; }
2835
2836 Expr *getRowIdx() { return cast<Expr>(SubExprs[ROW_IDX]); }
2837 const Expr *getRowIdx() const { return cast<Expr>(SubExprs[ROW_IDX]); }
2838 void setRowIdx(Expr *E) { SubExprs[ROW_IDX] = E; }
2839
2840 SourceLocation getBeginLoc() const LLVM_READONLY {
2841 return getBase()->getBeginLoc();
2842 }
2843
2845
2846 SourceLocation getExprLoc() const LLVM_READONLY {
2847 return getBase()->getExprLoc();
2848 }
2849
2851 return ArrayOrMatrixSubscriptExprBits.RBracketLoc;
2852 }
2854 ArrayOrMatrixSubscriptExprBits.RBracketLoc = L;
2855 }
2856
2857 static bool classof(const Stmt *T) {
2858 return T->getStmtClass() == MatrixSingleSubscriptExprClass;
2859 }
2860
2861 // Iterators
2863 return child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
2864 }
2866 return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
2867 }
2868};
2869
2870/// MatrixSubscriptExpr - Matrix subscript expression for the MatrixType
2871/// extension.
2872/// MatrixSubscriptExpr can be either incomplete (only Base and RowIdx are set
2873/// so far, the type is IncompleteMatrixIdx) or complete (Base, RowIdx and
2874/// ColumnIdx refer to valid expressions). Incomplete matrix expressions only
2875/// exist during the initial construction of the AST.
2877 enum { BASE, ROW_IDX, COLUMN_IDX, END_EXPR };
2878 Stmt *SubExprs[END_EXPR];
2879
2880public:
2882 SourceLocation RBracketLoc)
2883 : Expr(MatrixSubscriptExprClass, T, Base->getValueKind(),
2885 SubExprs[BASE] = Base;
2886 SubExprs[ROW_IDX] = RowIdx;
2887 SubExprs[COLUMN_IDX] = ColumnIdx;
2888 ArrayOrMatrixSubscriptExprBits.RBracketLoc = RBracketLoc;
2890 }
2891
2892 /// Create an empty matrix subscript expression.
2894 : Expr(MatrixSubscriptExprClass, Shell) {}
2895
2896 bool isIncomplete() const {
2897 bool IsIncomplete = hasPlaceholderType(BuiltinType::IncompleteMatrixIdx);
2898 assert((SubExprs[COLUMN_IDX] || IsIncomplete) &&
2899 "expressions without column index must be marked as incomplete");
2900 return IsIncomplete;
2901 }
2902 Expr *getBase() { return cast<Expr>(SubExprs[BASE]); }
2903 const Expr *getBase() const { return cast<Expr>(SubExprs[BASE]); }
2904 void setBase(Expr *E) { SubExprs[BASE] = E; }
2905
2906 Expr *getRowIdx() { return cast<Expr>(SubExprs[ROW_IDX]); }
2907 const Expr *getRowIdx() const { return cast<Expr>(SubExprs[ROW_IDX]); }
2908 void setRowIdx(Expr *E) { SubExprs[ROW_IDX] = E; }
2909
2910 Expr *getColumnIdx() { return cast_or_null<Expr>(SubExprs[COLUMN_IDX]); }
2911 const Expr *getColumnIdx() const {
2912 assert(!isIncomplete() &&
2913 "cannot get the column index of an incomplete expression");
2914 return cast<Expr>(SubExprs[COLUMN_IDX]);
2915 }
2916 void setColumnIdx(Expr *E) { SubExprs[COLUMN_IDX] = E; }
2917
2918 SourceLocation getBeginLoc() const LLVM_READONLY {
2919 return getBase()->getBeginLoc();
2920 }
2921
2923
2924 SourceLocation getExprLoc() const LLVM_READONLY {
2925 return getBase()->getExprLoc();
2926 }
2927
2929 return ArrayOrMatrixSubscriptExprBits.RBracketLoc;
2930 }
2932 ArrayOrMatrixSubscriptExprBits.RBracketLoc = L;
2933 }
2934
2935 static bool classof(const Stmt *T) {
2936 return T->getStmtClass() == MatrixSubscriptExprClass;
2937 }
2938
2939 // Iterators
2941 return child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
2942 }
2944 return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
2945 }
2946};
2947
2948/// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
2949/// CallExpr itself represents a normal function call, e.g., "f(x, 2)",
2950/// while its subclasses may represent alternative syntax that (semantically)
2951/// results in a function call. For example, CXXOperatorCallExpr is
2952/// a subclass for overloaded operator calls that use operator syntax, e.g.,
2953/// "str1 + str2" to resolve to a function call.
2954class CallExpr : public Expr {
2955 enum { FN = 0, PREARGS_START = 1 };
2956
2957 /// The number of arguments in the call expression.
2958 unsigned NumArgs;
2959
2960 /// The location of the right parentheses. This has a different meaning for
2961 /// the derived classes of CallExpr.
2962 SourceLocation RParenLoc;
2963
2964 // CallExpr store some data in trailing objects. However since CallExpr
2965 // is used a base of other expression classes we cannot use
2966 // llvm::TrailingObjects. Instead we manually perform the pointer arithmetic
2967 // and casts.
2968 //
2969 // The trailing objects are in order:
2970 //
2971 // * A single "Stmt *" for the callee expression.
2972 //
2973 // * An array of getNumPreArgs() "Stmt *" for the pre-argument expressions.
2974 //
2975 // * An array of getNumArgs() "Stmt *" for the argument expressions.
2976 //
2977 // * An optional of type FPOptionsOverride.
2978 //
2979 // CallExpr subclasses are asssumed to be 32 bytes or less, and CallExpr
2980 // itself is 24 bytes. To avoid having to recompute or store the offset of the
2981 // trailing objects, we put it at 32 bytes (such that it is suitable for all
2982 // subclasses) We use the 8 bytes gap left for instances of CallExpr to store
2983 // the begin source location, which has a significant impact on perf as
2984 // getBeginLoc is assumed to be cheap.
2985 // The layourt is as follow:
2986 // CallExpr | Begin | 4 bytes left | Trailing Objects
2987 // CXXMemberCallExpr | Trailing Objects
2988 // A bit in CallExprBitfields indicates if source locations are present.
2989
2990protected:
2991 static constexpr unsigned OffsetToTrailingObjects = 32;
2992 template <typename T>
2993 static constexpr unsigned
2994 sizeToAllocateForCallExprSubclass(unsigned SizeOfTrailingObjects) {
2995 static_assert(sizeof(T) <= CallExpr::OffsetToTrailingObjects);
2996 return SizeOfTrailingObjects + CallExpr::OffsetToTrailingObjects;
2997 }
2998
2999private:
3000 /// Return a pointer to the start of the trailing array of "Stmt *".
3001 Stmt **getTrailingStmts() {
3002 return reinterpret_cast<Stmt **>(reinterpret_cast<char *>(this) +
3004 }
3005 Stmt *const *getTrailingStmts() const {
3006 return const_cast<CallExpr *>(this)->getTrailingStmts();
3007 }
3008
3009 unsigned getSizeOfTrailingStmts() const {
3010 return (1 + getNumPreArgs() + getNumArgs()) * sizeof(Stmt *);
3011 }
3012
3013 size_t getOffsetOfTrailingFPFeatures() const {
3014 assert(hasStoredFPFeatures());
3015 return OffsetToTrailingObjects + getSizeOfTrailingStmts();
3016 }
3017
3018public:
3019 enum class ADLCallKind : bool { NotADL, UsesADL };
3022
3023protected:
3024 /// Build a call expression, assuming that appropriate storage has been
3025 /// allocated for the trailing objects.
3026 CallExpr(StmtClass SC, Expr *Fn, ArrayRef<Expr *> PreArgs,
3028 SourceLocation RParenLoc, FPOptionsOverride FPFeatures,
3029 unsigned MinNumArgs, ADLCallKind UsesADL);
3030
3031 /// Build an empty call expression, for deserialization.
3032 CallExpr(StmtClass SC, unsigned NumPreArgs, unsigned NumArgs,
3033 bool hasFPFeatures, EmptyShell Empty);
3034
3035 /// Return the size in bytes needed for the trailing objects.
3036 /// Used by the derived classes to allocate the right amount of storage.
3037 static unsigned sizeOfTrailingObjects(unsigned NumPreArgs, unsigned NumArgs,
3038 bool HasFPFeatures) {
3039 return (1 + NumPreArgs + NumArgs) * sizeof(Stmt *) +
3040 HasFPFeatures * sizeof(FPOptionsOverride);
3041 }
3042
3043 Stmt *getPreArg(unsigned I) {
3044 assert(I < getNumPreArgs() && "Prearg access out of range!");
3045 return getTrailingStmts()[PREARGS_START + I];
3046 }
3047 const Stmt *getPreArg(unsigned I) const {
3048 assert(I < getNumPreArgs() && "Prearg access out of range!");
3049 return getTrailingStmts()[PREARGS_START + I];
3050 }
3051 void setPreArg(unsigned I, Stmt *PreArg) {
3052 assert(I < getNumPreArgs() && "Prearg access out of range!");
3053 getTrailingStmts()[PREARGS_START + I] = PreArg;
3054 }
3055
3056 unsigned getNumPreArgs() const { return CallExprBits.NumPreArgs; }
3057
3058 /// Return a pointer to the trailing FPOptions
3060 assert(hasStoredFPFeatures());
3061 return reinterpret_cast<FPOptionsOverride *>(
3062 reinterpret_cast<char *>(this) + OffsetToTrailingObjects +
3063 getSizeOfTrailingStmts());
3064 }
3066 assert(hasStoredFPFeatures());
3067 return reinterpret_cast<const FPOptionsOverride *>(
3068 reinterpret_cast<const char *>(this) + OffsetToTrailingObjects +
3069 getSizeOfTrailingStmts());
3070 }
3071
3072public:
3073 /// Create a call expression.
3074 /// \param Fn The callee expression,
3075 /// \param Args The argument array,
3076 /// \param Ty The type of the call expression (which is *not* the return
3077 /// type in general),
3078 /// \param VK The value kind of the call expression (lvalue, rvalue, ...),
3079 /// \param RParenLoc The location of the right parenthesis in the call
3080 /// expression.
3081 /// \param FPFeatures Floating-point features associated with the call,
3082 /// \param MinNumArgs Specifies the minimum number of arguments. The actual
3083 /// number of arguments will be the greater of Args.size()
3084 /// and MinNumArgs. This is used in a few places to allocate
3085 /// enough storage for the default arguments.
3086 /// \param UsesADL Specifies whether the callee was found through
3087 /// argument-dependent lookup.
3088 ///
3089 /// Note that you can use CreateTemporary if you need a temporary call
3090 /// expression on the stack.
3091 static CallExpr *Create(const ASTContext &Ctx, Expr *Fn,
3093 SourceLocation RParenLoc,
3094 FPOptionsOverride FPFeatures, unsigned MinNumArgs = 0,
3095 ADLCallKind UsesADL = NotADL);
3096
3097 /// Create an empty call expression, for deserialization.
3098 static CallExpr *CreateEmpty(const ASTContext &Ctx, unsigned NumArgs,
3099 bool HasFPFeatures, EmptyShell Empty);
3100
3101 Expr *getCallee() { return cast<Expr>(getTrailingStmts()[FN]); }
3102 const Expr *getCallee() const { return cast<Expr>(getTrailingStmts()[FN]); }
3103 void setCallee(Expr *F) { getTrailingStmts()[FN] = F; }
3104
3106 return static_cast<ADLCallKind>(CallExprBits.UsesADL);
3107 }
3109 CallExprBits.UsesADL = static_cast<bool>(V);
3110 }
3111 bool usesADL() const { return getADLCallKind() == UsesADL; }
3112
3113 bool hasStoredFPFeatures() const { return CallExprBits.HasFPFeatures; }
3114
3115 bool usesMemberSyntax() const {
3116 return CallExprBits.ExplicitObjectMemFunUsingMemberSyntax;
3117 }
3118 void setUsesMemberSyntax(bool V = true) {
3119 CallExprBits.ExplicitObjectMemFunUsingMemberSyntax = V;
3120 // Because the source location may be different for explicit
3121 // member, we reset the cached values.
3122 if (CallExprBits.HasTrailingSourceLoc) {
3123 CallExprBits.HasTrailingSourceLoc = false;
3124 updateTrailingSourceLoc();
3125 }
3126 }
3127
3128 bool isCoroElideSafe() const { return CallExprBits.IsCoroElideSafe; }
3129 void setCoroElideSafe(bool V = true) { CallExprBits.IsCoroElideSafe = V; }
3130
3132 const Decl *getCalleeDecl() const {
3134 }
3135
3136 /// If the callee is a FunctionDecl, return it. Otherwise return null.
3138 return dyn_cast_or_null<FunctionDecl>(getCalleeDecl());
3139 }
3141 return dyn_cast_or_null<FunctionDecl>(getCalleeDecl());
3142 }
3143
3144 /// getNumArgs - Return the number of actual arguments to this call.
3145 unsigned getNumArgs() const { return NumArgs; }
3146
3147 /// Retrieve the call arguments.
3149 return reinterpret_cast<Expr **>(getTrailingStmts() + PREARGS_START +
3150 getNumPreArgs());
3151 }
3152 const Expr *const *getArgs() const {
3153 return reinterpret_cast<const Expr *const *>(
3154 getTrailingStmts() + PREARGS_START + getNumPreArgs());
3155 }
3156
3157 /// getArg - Return the specified argument.
3158 Expr *getArg(unsigned Arg) {
3159 assert(Arg < getNumArgs() && "Arg access out of range!");
3160 return getArgs()[Arg];
3161 }
3162 const Expr *getArg(unsigned Arg) const {
3163 assert(Arg < getNumArgs() && "Arg access out of range!");
3164 return getArgs()[Arg];
3165 }
3166
3167 /// setArg - Set the specified argument.
3168 /// ! the dependence bits might be stale after calling this setter, it is
3169 /// *caller*'s responsibility to recompute them by calling
3170 /// computeDependence().
3171 void setArg(unsigned Arg, Expr *ArgExpr) {
3172 assert(Arg < getNumArgs() && "Arg access out of range!");
3173 getArgs()[Arg] = ArgExpr;
3174 }
3175
3176 /// Compute and set dependence bits.
3179 this,
3180 ArrayRef(reinterpret_cast<Expr **>(getTrailingStmts() + PREARGS_START),
3181 getNumPreArgs())));
3182 }
3183
3184 /// Reduce the number of arguments in this call expression. This is used for
3185 /// example during error recovery to drop extra arguments. There is no way
3186 /// to perform the opposite because: 1.) We don't track how much storage
3187 /// we have for the argument array 2.) This would potentially require growing
3188 /// the argument array, something we cannot support since the arguments are
3189 /// stored in a trailing array.
3190 void shrinkNumArgs(unsigned NewNumArgs) {
3191 assert((NewNumArgs <= getNumArgs()) &&
3192 "shrinkNumArgs cannot increase the number of arguments!");
3193 NumArgs = NewNumArgs;
3194 }
3195
3196 /// Bluntly set a new number of arguments without doing any checks whatsoever.
3197 /// Only used during construction of a CallExpr in a few places in Sema.
3198 /// FIXME: Find a way to remove it.
3199 void setNumArgsUnsafe(unsigned NewNumArgs) { NumArgs = NewNumArgs; }
3200
3203 typedef llvm::iterator_range<arg_iterator> arg_range;
3204 typedef llvm::iterator_range<const_arg_iterator> const_arg_range;
3205
3208 return const_arg_range(arg_begin(), arg_end());
3209 }
3210
3212 return getTrailingStmts() + PREARGS_START + getNumPreArgs();
3213 }
3215
3217 return getTrailingStmts() + PREARGS_START + getNumPreArgs();
3218 }
3220
3221 /// This method provides fast access to all the subexpressions of
3222 /// a CallExpr without going through the slower virtual child_iterator
3223 /// interface. This provides efficient reverse iteration of the
3224 /// subexpressions. This is currently used for CFG construction.
3226 return {getTrailingStmts(), PREARGS_START + getNumPreArgs() + getNumArgs()};
3227 }
3228
3229 /// Get FPOptionsOverride from trailing storage.
3231 assert(hasStoredFPFeatures());
3232 return *getTrailingFPFeatures();
3233 }
3234 /// Set FPOptionsOverride in trailing storage. Used only by Serialization.
3239
3240 /// Get the store FPOptionsOverride or default if not stored.
3244
3245 /// Get the FP features status of this operator. Only meaningful for
3246 /// operations on floating point types.
3252
3254 if (hasStoredFPFeatures())
3255 return getStoredFPFeatures();
3256 return FPOptionsOverride();
3257 }
3258
3259 /// getBuiltinCallee - If this is a call to a builtin, return the builtin ID
3260 /// of the callee. If not, return 0.
3261 unsigned getBuiltinCallee() const;
3262
3263 /// Returns \c true if this is a call to a builtin which does not
3264 /// evaluate side-effects within its arguments.
3265 bool isUnevaluatedBuiltinCall(const ASTContext &Ctx) const;
3266
3267 /// getCallReturnType - Get the return type of the call expr. This is not
3268 /// always the type of the expr itself, if the return type is a reference
3269 /// type.
3270 QualType getCallReturnType(const ASTContext &Ctx) const;
3271
3272 /// Returns the WarnUnusedResultAttr that is declared on the callee
3273 /// or its return type declaration, together with a NamedDecl that
3274 /// refers to the declaration the attribute is attached to.
3275 std::pair<const NamedDecl *, const WarnUnusedResultAttr *>
3279
3280 /// Returns true if this call expression should warn on unused results.
3281 bool hasUnusedResultAttr(const ASTContext &Ctx) const {
3282 return getUnusedResultAttr(Ctx).second != nullptr;
3283 }
3284
3285 SourceLocation getRParenLoc() const { return RParenLoc; }
3286 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
3287
3289 if (CallExprBits.HasTrailingSourceLoc) {
3290 static_assert(sizeof(CallExpr) <=
3292 return *reinterpret_cast<const SourceLocation *>(
3293 reinterpret_cast<const char *>(this + 1));
3294 }
3295
3296 if (usesMemberSyntax())
3297 if (auto FirstArgLoc = getArg(0)->getBeginLoc(); FirstArgLoc.isValid())
3298 return FirstArgLoc;
3299
3300 // FIXME: Some builtins have no callee begin location
3302 if (begin.isInvalid() && getNumArgs() > 0 && getArg(0))
3303 begin = getArg(0)->getBeginLoc();
3304 return begin;
3305 }
3306
3308
3309private:
3310 friend class ASTStmtReader;
3311 bool hasTrailingSourceLoc() const {
3312 return CallExprBits.HasTrailingSourceLoc;
3313 }
3314
3315 void updateTrailingSourceLoc() {
3316 assert(!CallExprBits.HasTrailingSourceLoc &&
3317 "Trailing source loc already set?");
3318 assert(getStmtClass() == CallExprClass &&
3319 "Calling setTrailingSourceLocs on a subclass of CallExpr");
3320 static_assert(sizeof(CallExpr) <=
3322
3323 SourceLocation *Locs =
3324 reinterpret_cast<SourceLocation *>(reinterpret_cast<char *>(this + 1));
3325 new (Locs) SourceLocation(getBeginLoc());
3326 CallExprBits.HasTrailingSourceLoc = true;
3327 }
3328
3329public:
3330 /// Return true if this is a call to __assume() or __builtin_assume() with
3331 /// a non-value-dependent constant parameter evaluating as false.
3332 bool isBuiltinAssumeFalse(const ASTContext &Ctx) const;
3333
3334 /// Used by Sema to implement MSVC-compatible delayed name lookup.
3335 /// (Usually Exprs themselves should set dependence).
3337 setDependence(getDependence() | ExprDependence::TypeValueInstantiation);
3338 }
3339
3340 /// Try to get the alloc_size attribute of the callee. May return null.
3341 const AllocSizeAttr *getCalleeAllocSizeAttr() const;
3342
3343 /// Evaluates the total size in bytes allocated by calling a function
3344 /// decorated with alloc_size. Returns std::nullopt if the the result cannot
3345 /// be evaluated.
3346 std::optional<llvm::APInt>
3348
3349 bool isCallToStdMove() const;
3350
3351 static bool classof(const Stmt *T) {
3352 return T->getStmtClass() >= firstCallExprConstant &&
3353 T->getStmtClass() <= lastCallExprConstant;
3354 }
3355
3356 // Iterators
3358 return child_range(getTrailingStmts(), getTrailingStmts() + PREARGS_START +
3360 }
3361
3363 return const_child_range(getTrailingStmts(),
3364 getTrailingStmts() + PREARGS_START +
3366 }
3367};
3368
3369/// MemberExpr - [C99 6.5.2.3] Structure and Union Members. X->F and X.F.
3370///
3371class MemberExpr final
3372 : public Expr,
3373 private llvm::TrailingObjects<MemberExpr, NestedNameSpecifierLoc,
3374 DeclAccessPair, ASTTemplateKWAndArgsInfo,
3375 TemplateArgumentLoc> {
3376 friend class ASTReader;
3377 friend class ASTStmtReader;
3378 friend class ASTStmtWriter;
3379 friend TrailingObjects;
3380
3381 /// Base - the expression for the base pointer or structure references. In
3382 /// X.F, this is "X".
3383 Stmt *Base;
3384
3385 /// MemberDecl - This is the decl being referenced by the field/member name.
3386 /// In X.F, this is the decl referenced by F.
3387 ValueDecl *MemberDecl;
3388
3389 /// MemberDNLoc - Provides source/type location info for the
3390 /// declaration name embedded in MemberDecl.
3391 DeclarationNameLoc MemberDNLoc;
3392
3393 /// MemberLoc - This is the location of the member name.
3394 SourceLocation MemberLoc;
3395
3396 size_t numTrailingObjects(OverloadToken<NestedNameSpecifierLoc>) const {
3397 return hasQualifier();
3398 }
3399
3400 size_t numTrailingObjects(OverloadToken<DeclAccessPair>) const {
3401 return hasFoundDecl();
3402 }
3403
3404 size_t numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
3405 return hasTemplateKWAndArgsInfo();
3406 }
3407
3408 bool hasFoundDecl() const { return MemberExprBits.HasFoundDecl; }
3409
3410 bool hasTemplateKWAndArgsInfo() const {
3411 return MemberExprBits.HasTemplateKWAndArgsInfo;
3412 }
3413
3414 MemberExpr(Expr *Base, bool IsArrow, SourceLocation OperatorLoc,
3415 NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
3416 ValueDecl *MemberDecl, DeclAccessPair FoundDecl,
3417 const DeclarationNameInfo &NameInfo,
3418 const TemplateArgumentListInfo *TemplateArgs, QualType T,
3420 MemberExpr(EmptyShell Empty)
3421 : Expr(MemberExprClass, Empty), Base(), MemberDecl() {}
3422
3423public:
3424 static MemberExpr *Create(const ASTContext &C, Expr *Base, bool IsArrow,
3425 SourceLocation OperatorLoc,
3426 NestedNameSpecifierLoc QualifierLoc,
3427 SourceLocation TemplateKWLoc, ValueDecl *MemberDecl,
3428 DeclAccessPair FoundDecl,
3429 DeclarationNameInfo MemberNameInfo,
3430 const TemplateArgumentListInfo *TemplateArgs,
3431 QualType T, ExprValueKind VK, ExprObjectKind OK,
3432 NonOdrUseReason NOUR);
3433
3434 /// Create an implicit MemberExpr, with no location, qualifier, template
3435 /// arguments, and so on. Suitable only for non-static member access.
3436 static MemberExpr *CreateImplicit(const ASTContext &C, Expr *Base,
3437 bool IsArrow, ValueDecl *MemberDecl,
3439 ExprObjectKind OK) {
3440 return Create(C, Base, IsArrow, SourceLocation(), NestedNameSpecifierLoc(),
3441 SourceLocation(), MemberDecl,
3442 DeclAccessPair::make(MemberDecl, MemberDecl->getAccess()),
3443 DeclarationNameInfo(), nullptr, T, VK, OK, NOUR_None);
3444 }
3445
3446 static MemberExpr *CreateEmpty(const ASTContext &Context, bool HasQualifier,
3447 bool HasFoundDecl,
3448 bool HasTemplateKWAndArgsInfo,
3449 unsigned NumTemplateArgs);
3450
3451 void setBase(Expr *E) { Base = E; }
3452 Expr *getBase() const { return cast<Expr>(Base); }
3453
3454 /// Retrieve the member declaration to which this expression refers.
3455 ///
3456 /// The returned declaration will be a FieldDecl or (in C++) a VarDecl (for
3457 /// static data members), a CXXMethodDecl, or an EnumConstantDecl.
3458 ValueDecl *getMemberDecl() const { return MemberDecl; }
3459 void setMemberDecl(ValueDecl *D);
3460
3461 /// Retrieves the declaration found by lookup.
3463 if (!hasFoundDecl())
3465 getMemberDecl()->getAccess());
3466 return *getTrailingObjects<DeclAccessPair>();
3467 }
3468
3469 /// Determines whether this member expression actually had
3470 /// a C++ nested-name-specifier prior to the name of the member, e.g.,
3471 /// x->Base::foo.
3472 bool hasQualifier() const { return MemberExprBits.HasQualifier; }
3473
3474 /// If the member name was qualified, retrieves the
3475 /// nested-name-specifier that precedes the member name, with source-location
3476 /// information.
3478 if (!hasQualifier())
3479 return NestedNameSpecifierLoc();
3480 return *getTrailingObjects<NestedNameSpecifierLoc>();
3481 }
3482
3483 /// If the member name was qualified, retrieves the
3484 /// nested-name-specifier that precedes the member name. Otherwise, returns
3485 /// NULL.
3489
3490 /// Retrieve the location of the template keyword preceding
3491 /// the member name, if any.
3493 if (!hasTemplateKWAndArgsInfo())
3494 return SourceLocation();
3495 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->TemplateKWLoc;
3496 }
3497
3498 /// Retrieve the location of the left angle bracket starting the
3499 /// explicit template argument list following the member name, if any.
3501 if (!hasTemplateKWAndArgsInfo())
3502 return SourceLocation();
3503 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->LAngleLoc;
3504 }
3505
3506 /// Retrieve the location of the right angle bracket ending the
3507 /// explicit template argument list following the member name, if any.
3509 if (!hasTemplateKWAndArgsInfo())
3510 return SourceLocation();
3511 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->RAngleLoc;
3512 }
3513
3514 /// Determines whether the member name was preceded by the template keyword.
3516
3517 /// Determines whether the member name was followed by an
3518 /// explicit template argument list.
3519 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
3520
3521 /// Copies the template arguments (if present) into the given
3522 /// structure.
3525 getTrailingObjects<ASTTemplateKWAndArgsInfo>()->copyInto(
3526 getTrailingObjects<TemplateArgumentLoc>(), List);
3527 }
3528
3529 /// Retrieve the template arguments provided as part of this
3530 /// template-id.
3533 return nullptr;
3534
3535 return getTrailingObjects<TemplateArgumentLoc>();
3536 }
3537
3538 /// Retrieve the number of template arguments provided as part of this
3539 /// template-id.
3540 unsigned getNumTemplateArgs() const {
3542 return 0;
3543
3544 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs;
3545 }
3546
3550
3551 /// Retrieve the member declaration name info.
3553 return DeclarationNameInfo(MemberDecl->getDeclName(),
3554 MemberLoc, MemberDNLoc);
3555 }
3556
3557 SourceLocation getOperatorLoc() const { return MemberExprBits.OperatorLoc; }
3558
3559 bool isArrow() const { return MemberExprBits.IsArrow; }
3560 void setArrow(bool A) { MemberExprBits.IsArrow = A; }
3561
3562 /// getMemberLoc - Return the location of the "member", in X->F, it is the
3563 /// location of 'F'.
3564 SourceLocation getMemberLoc() const { return MemberLoc; }
3565 void setMemberLoc(SourceLocation L) { MemberLoc = L; }
3566
3567 SourceLocation getBeginLoc() const LLVM_READONLY;
3568 SourceLocation getEndLoc() const LLVM_READONLY;
3569
3570 SourceLocation getExprLoc() const LLVM_READONLY { return MemberLoc; }
3571
3572 /// Determine whether the base of this explicit is implicit.
3573 bool isImplicitAccess() const {
3574 return getBase() && getBase()->isImplicitCXXThis();
3575 }
3576
3577 /// Returns true if this member expression refers to a method that
3578 /// was resolved from an overloaded set having size greater than 1.
3580 return MemberExprBits.HadMultipleCandidates;
3581 }
3582 /// Sets the flag telling whether this expression refers to
3583 /// a method that was resolved from an overloaded set having size
3584 /// greater than 1.
3585 void setHadMultipleCandidates(bool V = true) {
3586 MemberExprBits.HadMultipleCandidates = V;
3587 }
3588
3589 /// Returns true if virtual dispatch is performed.
3590 /// If the member access is fully qualified, (i.e. X::f()), virtual
3591 /// dispatching is not performed. In -fapple-kext mode qualified
3592 /// calls to virtual method will still go through the vtable.
3593 bool performsVirtualDispatch(const LangOptions &LO) const {
3594 return LO.AppleKext || !hasQualifier();
3595 }
3596
3597 /// Is this expression a non-odr-use reference, and if so, why?
3598 /// This is only meaningful if the named member is a static member.
3600 return static_cast<NonOdrUseReason>(MemberExprBits.NonOdrUseReason);
3601 }
3602
3603 static bool classof(const Stmt *T) {
3604 return T->getStmtClass() == MemberExprClass;
3605 }
3606
3607 // Iterators
3608 child_range children() { return child_range(&Base, &Base+1); }
3610 return const_child_range(&Base, &Base + 1);
3611 }
3612};
3613
3614/// CompoundLiteralExpr - [C99 6.5.2.5]
3615///
3617 /// LParenLoc - If non-null, this is the location of the left paren in a
3618 /// compound literal like "(int){4}". This can be null if this is a
3619 /// synthesized compound expression.
3620 SourceLocation LParenLoc;
3621
3622 /// The type as written. This can be an incomplete array type, in
3623 /// which case the actual expression type will be different.
3624 /// The int part of the pair stores whether this expr is file scope.
3625 llvm::PointerIntPair<TypeSourceInfo *, 1, bool> TInfoAndScope;
3626 Stmt *Init;
3627
3628 /// Value of constant literals with static storage duration.
3629 mutable APValue *StaticValue = nullptr;
3630
3631public:
3633 QualType T, ExprValueKind VK, Expr *init, bool fileScope)
3634 : Expr(CompoundLiteralExprClass, T, VK, OK_Ordinary),
3635 LParenLoc(lparenloc), TInfoAndScope(tinfo, fileScope), Init(init) {
3636 assert(Init && "Init is a nullptr");
3638 }
3639
3640 /// Construct an empty compound literal.
3642 : Expr(CompoundLiteralExprClass, Empty) { }
3643
3644 const Expr *getInitializer() const { return cast<Expr>(Init); }
3645 Expr *getInitializer() { return cast<Expr>(Init); }
3646 void setInitializer(Expr *E) { Init = E; }
3647
3648 bool isFileScope() const { return TInfoAndScope.getInt(); }
3649 void setFileScope(bool FS) { TInfoAndScope.setInt(FS); }
3650
3651 SourceLocation getLParenLoc() const { return LParenLoc; }
3652 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
3653
3655 return TInfoAndScope.getPointer();
3656 }
3658 TInfoAndScope.setPointer(tinfo);
3659 }
3660
3661 bool hasStaticStorage() const { return isFileScope() && isGLValue(); }
3663 APValue &getStaticValue() const;
3664
3665 SourceLocation getBeginLoc() const LLVM_READONLY {
3666 if (LParenLoc.isInvalid())
3667 return Init->getBeginLoc();
3668 return LParenLoc;
3669 }
3670 SourceLocation getEndLoc() const LLVM_READONLY { return Init->getEndLoc(); }
3671
3672 static bool classof(const Stmt *T) {
3673 return T->getStmtClass() == CompoundLiteralExprClass;
3674 }
3675
3676 // Iterators
3677 child_range children() { return child_range(&Init, &Init+1); }
3679 return const_child_range(&Init, &Init + 1);
3680 }
3681};
3682
3683/// CastExpr - Base class for type casts, including both implicit
3684/// casts (ImplicitCastExpr) and explicit casts that have some
3685/// representation in the source code (ExplicitCastExpr's derived
3686/// classes).
3687class CastExpr : public Expr {
3688 Stmt *Op;
3689
3690 bool CastConsistency() const;
3691
3692 const CXXBaseSpecifier * const *path_buffer() const {
3693 return const_cast<CastExpr*>(this)->path_buffer();
3694 }
3695 CXXBaseSpecifier **path_buffer();
3696
3697 friend class ASTStmtReader;
3698
3699protected:
3701 Expr *op, unsigned BasePathSize, bool HasFPFeatures)
3702 : Expr(SC, ty, VK, OK_Ordinary), Op(op) {
3703 CastExprBits.Kind = kind;
3704 CastExprBits.PartOfExplicitCast = false;
3705 CastExprBits.BasePathSize = BasePathSize;
3706 assert((CastExprBits.BasePathSize == BasePathSize) &&
3707 "BasePathSize overflow!");
3708 assert(CastConsistency());
3709 CastExprBits.HasFPFeatures = HasFPFeatures;
3710 }
3711
3712 /// Construct an empty cast.
3713 CastExpr(StmtClass SC, EmptyShell Empty, unsigned BasePathSize,
3714 bool HasFPFeatures)
3715 : Expr(SC, Empty) {
3716 CastExprBits.PartOfExplicitCast = false;
3717 CastExprBits.BasePathSize = BasePathSize;
3718 CastExprBits.HasFPFeatures = HasFPFeatures;
3719 assert((CastExprBits.BasePathSize == BasePathSize) &&
3720 "BasePathSize overflow!");
3721 }
3722
3723 /// Return a pointer to the trailing FPOptions.
3724 /// \pre hasStoredFPFeatures() == true
3727 return const_cast<CastExpr *>(this)->getTrailingFPFeatures();
3728 }
3729
3730public:
3731 CastKind getCastKind() const { return (CastKind) CastExprBits.Kind; }
3732 void setCastKind(CastKind K) { CastExprBits.Kind = K; }
3733
3734 static const char *getCastKindName(CastKind CK);
3735 const char *getCastKindName() const { return getCastKindName(getCastKind()); }
3736
3737 Expr *getSubExpr() { return cast<Expr>(Op); }
3738 const Expr *getSubExpr() const { return cast<Expr>(Op); }
3739 void setSubExpr(Expr *E) { Op = E; }
3740
3741 /// Retrieve the cast subexpression as it was written in the source
3742 /// code, looking through any implicit casts or other intermediate nodes
3743 /// introduced by semantic analysis.
3745 const Expr *getSubExprAsWritten() const {
3746 return const_cast<CastExpr *>(this)->getSubExprAsWritten();
3747 }
3748
3749 /// If this cast applies a user-defined conversion, retrieve the conversion
3750 /// function that it invokes.
3752
3755 bool path_empty() const { return path_size() == 0; }
3756 unsigned path_size() const { return CastExprBits.BasePathSize; }
3757 path_iterator path_begin() { return path_buffer(); }
3758 path_iterator path_end() { return path_buffer() + path_size(); }
3759 path_const_iterator path_begin() const { return path_buffer(); }
3760 path_const_iterator path_end() const { return path_buffer() + path_size(); }
3761
3762 /// Path through the class hierarchy taken by casts between base and derived
3763 /// classes (see implementation of `CastConsistency()` for a full list of
3764 /// cast kinds that have a path).
3765 ///
3766 /// For each derived-to-base edge in the path, the path contains a
3767 /// `CXXBaseSpecifier` for the base class of that edge; the entries are
3768 /// ordered from derived class to base class.
3769 ///
3770 /// For example, given classes `Base`, `Intermediate : public Base` and
3771 /// `Derived : public Intermediate`, the path for a cast from `Derived *` to
3772 /// `Base *` contains two entries: One for `Intermediate`, and one for `Base`,
3773 /// in that order.
3774 llvm::iterator_range<path_iterator> path() {
3775 return llvm::make_range(path_begin(), path_end());
3776 }
3777 llvm::iterator_range<path_const_iterator> path() const {
3778 return llvm::make_range(path_begin(), path_end());
3779 }
3780
3782 assert(getCastKind() == CK_ToUnion);
3784 }
3785
3786 bool hasStoredFPFeatures() const { return CastExprBits.HasFPFeatures; }
3787
3788 /// Get FPOptionsOverride from trailing storage.
3790 assert(hasStoredFPFeatures());
3791 return *getTrailingFPFeatures();
3792 }
3793
3794 /// Get the store FPOptionsOverride or default if not stored.
3798
3799 /// Get the FP features status of this operation. Only meaningful for
3800 /// operations on floating point types.
3806
3808 if (hasStoredFPFeatures())
3809 return getStoredFPFeatures();
3810 return FPOptionsOverride();
3811 }
3812
3813 /// Return
3814 // True : if this conversion changes the volatile-ness of a gl-value.
3815 // Qualification conversions on gl-values currently use CK_NoOp, but
3816 // it's important to recognize volatile-changing conversions in
3817 // clients code generation that normally eagerly peephole loads. Note
3818 // that the query is answering for this specific node; Sema may
3819 // produce multiple cast nodes for any particular conversion sequence.
3820 // False : Otherwise.
3822 return (isGLValue() && (getType().isVolatileQualified() !=
3823 getSubExpr()->getType().isVolatileQualified()));
3824 }
3825
3826 static const FieldDecl *getTargetFieldForToUnionCast(QualType unionType,
3827 QualType opType);
3828 static const FieldDecl *getTargetFieldForToUnionCast(const RecordDecl *RD,
3829 QualType opType);
3830
3831 static bool classof(const Stmt *T) {
3832 return T->getStmtClass() >= firstCastExprConstant &&
3833 T->getStmtClass() <= lastCastExprConstant;
3834 }
3835
3836 // Iterators
3837 child_range children() { return child_range(&Op, &Op+1); }
3838 const_child_range children() const { return const_child_range(&Op, &Op + 1); }
3839};
3840
3841/// ImplicitCastExpr - Allows us to explicitly represent implicit type
3842/// conversions, which have no direct representation in the original
3843/// source code. For example: converting T[]->T*, void f()->void
3844/// (*f)(), float->double, short->int, etc.
3845///
3846/// In C, implicit casts always produce rvalues. However, in C++, an
3847/// implicit cast whose result is being bound to a reference will be
3848/// an lvalue or xvalue. For example:
3849///
3850/// @code
3851/// class Base { };
3852/// class Derived : public Base { };
3853/// Derived &&ref();
3854/// void f(Derived d) {
3855/// Base& b = d; // initializer is an ImplicitCastExpr
3856/// // to an lvalue of type Base
3857/// Base&& r = ref(); // initializer is an ImplicitCastExpr
3858/// // to an xvalue of type Base
3859/// }
3860/// @endcode
3861class ImplicitCastExpr final
3862 : public CastExpr,
3863 private llvm::TrailingObjects<ImplicitCastExpr, CXXBaseSpecifier *,
3864 FPOptionsOverride> {
3865
3866 ImplicitCastExpr(QualType ty, CastKind kind, Expr *op,
3867 unsigned BasePathLength, FPOptionsOverride FPO,
3869 : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, BasePathLength,
3872 if (hasStoredFPFeatures())
3873 *getTrailingFPFeatures() = FPO;
3874 }
3875
3876 /// Construct an empty implicit cast.
3877 explicit ImplicitCastExpr(EmptyShell Shell, unsigned PathSize,
3878 bool HasFPFeatures)
3879 : CastExpr(ImplicitCastExprClass, Shell, PathSize, HasFPFeatures) {}
3880
3881 unsigned numTrailingObjects(OverloadToken<CXXBaseSpecifier *>) const {
3882 return path_size();
3883 }
3884
3885public:
3889 : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, 0,
3890 FPO.requiresTrailingStorage()) {
3891 if (hasStoredFPFeatures())
3892 *getTrailingFPFeatures() = FPO;
3893 }
3894
3895 bool isPartOfExplicitCast() const { return CastExprBits.PartOfExplicitCast; }
3896 void setIsPartOfExplicitCast(bool PartOfExplicitCast) {
3897 CastExprBits.PartOfExplicitCast = PartOfExplicitCast;
3898 }
3899
3900 static ImplicitCastExpr *Create(const ASTContext &Context, QualType T,
3901 CastKind Kind, Expr *Operand,
3902 const CXXCastPath *BasePath,
3904
3905 static ImplicitCastExpr *CreateEmpty(const ASTContext &Context,
3906 unsigned PathSize, bool HasFPFeatures);
3907
3908 SourceLocation getBeginLoc() const LLVM_READONLY {
3909 return getSubExpr()->getBeginLoc();
3910 }
3911 SourceLocation getEndLoc() const LLVM_READONLY {
3912 return getSubExpr()->getEndLoc();
3913 }
3914
3915 static bool classof(const Stmt *T) {
3916 return T->getStmtClass() == ImplicitCastExprClass;
3917 }
3918
3920 friend class CastExpr;
3921};
3922
3923/// ExplicitCastExpr - An explicit cast written in the source
3924/// code.
3925///
3926/// This class is effectively an abstract class, because it provides
3927/// the basic representation of an explicitly-written cast without
3928/// specifying which kind of cast (C cast, functional cast, static
3929/// cast, etc.) was written; specific derived classes represent the
3930/// particular style of cast and its location information.
3931///
3932/// Unlike implicit casts, explicit cast nodes have two different
3933/// types: the type that was written into the source code, and the
3934/// actual type of the expression as determined by semantic
3935/// analysis. These types may differ slightly. For example, in C++ one
3936/// can cast to a reference type, which indicates that the resulting
3937/// expression will be an lvalue or xvalue. The reference type, however,
3938/// will not be used as the type of the expression.
3940 /// TInfo - Source type info for the (written) type
3941 /// this expression is casting to.
3942 TypeSourceInfo *TInfo;
3943
3944protected:
3946 CastKind kind, Expr *op, unsigned PathSize,
3947 bool HasFPFeatures, TypeSourceInfo *writtenTy)
3948 : CastExpr(SC, exprTy, VK, kind, op, PathSize, HasFPFeatures),
3949 TInfo(writtenTy) {
3951 }
3952
3953 /// Construct an empty explicit cast.
3954 ExplicitCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize,
3955 bool HasFPFeatures)
3956 : CastExpr(SC, Shell, PathSize, HasFPFeatures) {}
3957
3958public:
3959 /// getTypeInfoAsWritten - Returns the type source info for the type
3960 /// that this expression is casting to.
3961 TypeSourceInfo *getTypeInfoAsWritten() const { return TInfo; }
3962 void setTypeInfoAsWritten(TypeSourceInfo *writtenTy) { TInfo = writtenTy; }
3963
3964 /// getTypeAsWritten - Returns the type that this expression is
3965 /// casting to, as written in the source code.
3966 QualType getTypeAsWritten() const { return TInfo->getType(); }
3967
3968 static bool classof(const Stmt *T) {
3969 return T->getStmtClass() >= firstExplicitCastExprConstant &&
3970 T->getStmtClass() <= lastExplicitCastExprConstant;
3971 }
3972};
3973
3974/// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style
3975/// cast in C++ (C++ [expr.cast]), which uses the syntax
3976/// (Type)expr. For example: @c (int)f.
3977class CStyleCastExpr final
3978 : public ExplicitCastExpr,
3979 private llvm::TrailingObjects<CStyleCastExpr, CXXBaseSpecifier *,
3980 FPOptionsOverride> {
3981 SourceLocation LPLoc; // the location of the left paren
3982 SourceLocation RPLoc; // the location of the right paren
3983
3984 CStyleCastExpr(QualType exprTy, ExprValueKind vk, CastKind kind, Expr *op,
3985 unsigned PathSize, FPOptionsOverride FPO,
3987 : ExplicitCastExpr(CStyleCastExprClass, exprTy, vk, kind, op, PathSize,
3988 FPO.requiresTrailingStorage(), writtenTy),
3989 LPLoc(l), RPLoc(r) {
3990 if (hasStoredFPFeatures())
3991 *getTrailingFPFeatures() = FPO;
3992 }
3993
3994 /// Construct an empty C-style explicit cast.
3995 explicit CStyleCastExpr(EmptyShell Shell, unsigned PathSize,
3996 bool HasFPFeatures)
3997 : ExplicitCastExpr(CStyleCastExprClass, Shell, PathSize, HasFPFeatures) {}
3998
3999 unsigned numTrailingObjects(OverloadToken<CXXBaseSpecifier *>) const {
4000 return path_size();
4001 }
4002
4003public:
4004 static CStyleCastExpr *
4005 Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind K,
4006 Expr *Op, const CXXCastPath *BasePath, FPOptionsOverride FPO,
4008
4009 static CStyleCastExpr *CreateEmpty(const ASTContext &Context,
4010 unsigned PathSize, bool HasFPFeatures);
4011
4012 SourceLocation getLParenLoc() const { return LPLoc; }
4013 void setLParenLoc(SourceLocation L) { LPLoc = L; }
4014
4015 SourceLocation getRParenLoc() const { return RPLoc; }
4016 void setRParenLoc(SourceLocation L) { RPLoc = L; }
4017
4018 SourceLocation getBeginLoc() const LLVM_READONLY { return LPLoc; }
4019 SourceLocation getEndLoc() const LLVM_READONLY {
4020 return getSubExpr()->getEndLoc();
4021 }
4022
4023 static bool classof(const Stmt *T) {
4024 return T->getStmtClass() == CStyleCastExprClass;
4025 }
4026
4028 friend class CastExpr;
4029};
4030
4031/// A builtin binary operation expression such as "x + y" or "x <= y".
4032///
4033/// This expression node kind describes a builtin binary operation,
4034/// such as "x + y" for integer values "x" and "y". The operands will
4035/// already have been converted to appropriate types (e.g., by
4036/// performing promotions or conversions).
4037///
4038/// In C++, where operators may be overloaded, a different kind of
4039/// expression node (CXXOperatorCallExpr) is used to express the
4040/// invocation of an overloaded operator with operator syntax. Within
4041/// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is
4042/// used to store an expression "x + y" depends on the subexpressions
4043/// for x and y. If neither x or y is type-dependent, and the "+"
4044/// operator resolves to a built-in operation, BinaryOperator will be
4045/// used to express the computation (x and y may still be
4046/// value-dependent). If either x or y is type-dependent, or if the
4047/// "+" resolves to an overloaded operator, CXXOperatorCallExpr will
4048/// be used to express the computation.
4049class BinaryOperator : public Expr {
4050 enum { LHS, RHS, END_EXPR };
4051 Stmt *SubExprs[END_EXPR];
4052
4053public:
4055
4056protected:
4057 size_t offsetOfTrailingStorage() const;
4058
4059 /// Return a pointer to the trailing FPOptions
4061 assert(BinaryOperatorBits.HasFPFeatures);
4062 return reinterpret_cast<FPOptionsOverride *>(
4063 reinterpret_cast<char *>(this) + offsetOfTrailingStorage());
4064 }
4066 assert(BinaryOperatorBits.HasFPFeatures);
4067 return reinterpret_cast<const FPOptionsOverride *>(
4068 reinterpret_cast<const char *>(this) + offsetOfTrailingStorage());
4069 }
4070
4071 /// Build a binary operator, assuming that appropriate storage has been
4072 /// allocated for the trailing objects when needed.
4073 BinaryOperator(const ASTContext &Ctx, Expr *lhs, Expr *rhs, Opcode opc,
4075 SourceLocation opLoc, FPOptionsOverride FPFeatures);
4076
4077 /// Construct an empty binary operator.
4078 explicit BinaryOperator(EmptyShell Empty) : Expr(BinaryOperatorClass, Empty) {
4079 BinaryOperatorBits.Opc = BO_Comma;
4080 BinaryOperatorBits.ExcludedOverflowPattern = false;
4081 }
4082
4083public:
4084 static BinaryOperator *CreateEmpty(const ASTContext &C, bool hasFPFeatures);
4085
4086 static BinaryOperator *Create(const ASTContext &C, Expr *lhs, Expr *rhs,
4087 Opcode opc, QualType ResTy, ExprValueKind VK,
4089 FPOptionsOverride FPFeatures);
4093
4095 return static_cast<Opcode>(BinaryOperatorBits.Opc);
4096 }
4097 void setOpcode(Opcode Opc) { BinaryOperatorBits.Opc = Opc; }
4098
4099 Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
4100 void setLHS(Expr *E) { SubExprs[LHS] = E; }
4101 Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
4102 void setRHS(Expr *E) { SubExprs[RHS] = E; }
4103
4104 SourceLocation getBeginLoc() const LLVM_READONLY {
4105 return getLHS()->getBeginLoc();
4106 }
4107 SourceLocation getEndLoc() const LLVM_READONLY {
4108 return getRHS()->getEndLoc();
4109 }
4110
4111 /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
4112 /// corresponds to, e.g. "<<=".
4113 static StringRef getOpcodeStr(Opcode Op);
4114
4115 StringRef getOpcodeStr() const { return getOpcodeStr(getOpcode()); }
4116
4117 /// Retrieve the binary opcode that corresponds to the given
4118 /// overloaded operator.
4120
4121 /// Retrieve the overloaded operator kind that corresponds to
4122 /// the given binary opcode.
4124
4125 /// predicates to categorize the respective opcodes.
4126 static bool isPtrMemOp(Opcode Opc) {
4127 return Opc == BO_PtrMemD || Opc == BO_PtrMemI;
4128 }
4129 bool isPtrMemOp() const { return isPtrMemOp(getOpcode()); }
4130
4131 static bool isMultiplicativeOp(Opcode Opc) {
4132 return Opc >= BO_Mul && Opc <= BO_Rem;
4133 }
4135 static bool isAdditiveOp(Opcode Opc) { return Opc == BO_Add || Opc==BO_Sub; }
4136 bool isAdditiveOp() const { return isAdditiveOp(getOpcode()); }
4137 static bool isShiftOp(Opcode Opc) { return Opc == BO_Shl || Opc == BO_Shr; }
4138 bool isShiftOp() const { return isShiftOp(getOpcode()); }
4139
4140 static bool isBitwiseOp(Opcode Opc) { return Opc >= BO_And && Opc <= BO_Or; }
4141 bool isBitwiseOp() const { return isBitwiseOp(getOpcode()); }
4142
4143 static bool isRelationalOp(Opcode Opc) { return Opc >= BO_LT && Opc<=BO_GE; }
4144 bool isRelationalOp() const { return isRelationalOp(getOpcode()); }
4145
4146 static bool isEqualityOp(Opcode Opc) { return Opc == BO_EQ || Opc == BO_NE; }
4147 bool isEqualityOp() const { return isEqualityOp(getOpcode()); }
4148
4149 static bool isComparisonOp(Opcode Opc) { return Opc >= BO_Cmp && Opc<=BO_NE; }
4150 bool isComparisonOp() const { return isComparisonOp(getOpcode()); }
4151
4152 static bool isCommaOp(Opcode Opc) { return Opc == BO_Comma; }
4153 bool isCommaOp() const { return isCommaOp(getOpcode()); }
4154
4156 switch (Opc) {
4157 default:
4158 llvm_unreachable("Not a comparison operator.");
4159 case BO_LT: return BO_GE;
4160 case BO_GT: return BO_LE;
4161 case BO_LE: return BO_GT;
4162 case BO_GE: return BO_LT;
4163 case BO_EQ: return BO_NE;
4164 case BO_NE: return BO_EQ;
4165 }
4166 }
4167
4169 switch (Opc) {
4170 default:
4171 llvm_unreachable("Not a comparison operator.");
4172 case BO_LT: return BO_GT;
4173 case BO_GT: return BO_LT;
4174 case BO_LE: return BO_GE;
4175 case BO_GE: return BO_LE;
4176 case BO_EQ:
4177 case BO_NE:
4178 return Opc;
4179 }
4180 }
4181
4182 static bool isLogicalOp(Opcode Opc) { return Opc == BO_LAnd || Opc==BO_LOr; }
4183 bool isLogicalOp() const { return isLogicalOp(getOpcode()); }
4184
4185 static bool isAssignmentOp(Opcode Opc) {
4186 return Opc >= BO_Assign && Opc <= BO_OrAssign;
4187 }
4188 bool isAssignmentOp() const { return isAssignmentOp(getOpcode()); }
4189
4191 return Opc > BO_Assign && Opc <= BO_OrAssign;
4192 }
4195 }
4197 assert(isCompoundAssignmentOp(Opc));
4198 if (Opc >= BO_AndAssign)
4199 return Opcode(unsigned(Opc) - BO_AndAssign + BO_And);
4200 else
4201 return Opcode(unsigned(Opc) - BO_MulAssign + BO_Mul);
4202 }
4203
4204 static bool isShiftAssignOp(Opcode Opc) {
4205 return Opc == BO_ShlAssign || Opc == BO_ShrAssign;
4206 }
4207 bool isShiftAssignOp() const {
4208 return isShiftAssignOp(getOpcode());
4209 }
4210
4211 /// Return true if a binary operator using the specified opcode and operands
4212 /// would match the 'p = (i8*)nullptr + n' idiom for casting a pointer-sized
4213 /// integer to a pointer.
4214 static bool isNullPointerArithmeticExtension(ASTContext &Ctx, Opcode Opc,
4215 const Expr *LHS,
4216 const Expr *RHS);
4217
4218 static bool classof(const Stmt *S) {
4219 return S->getStmtClass() >= firstBinaryOperatorConstant &&
4220 S->getStmtClass() <= lastBinaryOperatorConstant;
4221 }
4222
4223 // Iterators
4225 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
4226 }
4228 return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
4229 }
4230
4231 /// Set and fetch the bit that shows whether FPFeatures needs to be
4232 /// allocated in Trailing Storage
4233 void setHasStoredFPFeatures(bool B) { BinaryOperatorBits.HasFPFeatures = B; }
4234 bool hasStoredFPFeatures() const { return BinaryOperatorBits.HasFPFeatures; }
4235
4236 /// Set and get the bit that informs arithmetic overflow sanitizers whether
4237 /// or not they should exclude certain BinaryOperators from instrumentation
4239 BinaryOperatorBits.ExcludedOverflowPattern = B;
4240 }
4242 return BinaryOperatorBits.ExcludedOverflowPattern;
4243 }
4244
4245 /// Get FPFeatures from trailing storage
4247 assert(hasStoredFPFeatures());
4248 return *getTrailingFPFeatures();
4249 }
4250 /// Set FPFeatures in trailing storage, used only by Serialization
4252 assert(BinaryOperatorBits.HasFPFeatures);
4253 *getTrailingFPFeatures() = F;
4254 }
4255 /// Get the store FPOptionsOverride or default if not stored.
4259
4260 /// Get the FP features status of this operator. Only meaningful for
4261 /// operations on floating point types.
4263 if (BinaryOperatorBits.HasFPFeatures)
4266 }
4267
4268 // This is used in ASTImporter
4270 if (BinaryOperatorBits.HasFPFeatures)
4271 return getStoredFPFeatures();
4272 return FPOptionsOverride();
4273 }
4274
4275 /// Get the FP contractibility status of this operator. Only meaningful for
4276 /// operations on floating point types.
4280
4281 /// Get the FENV_ACCESS status of this operator. Only meaningful for
4282 /// operations on floating point types.
4283 bool isFEnvAccessOn(const LangOptions &LO) const {
4284 return getFPFeaturesInEffect(LO).getAllowFEnvAccess();
4285 }
4286
4287protected:
4288 BinaryOperator(const ASTContext &Ctx, Expr *lhs, Expr *rhs, Opcode opc,
4290 SourceLocation opLoc, FPOptionsOverride FPFeatures,
4291 bool dead2);
4292
4293 /// Construct an empty BinaryOperator, SC is CompoundAssignOperator.
4295 BinaryOperatorBits.Opc = BO_MulAssign;
4296 }
4297
4298 /// Return the size in bytes needed for the trailing objects.
4299 /// Used to allocate the right amount of storage.
4300 static unsigned sizeOfTrailingObjects(bool HasFPFeatures) {
4301 return HasFPFeatures * sizeof(FPOptionsOverride);
4302 }
4303};
4304
4305/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep
4306/// track of the type the operation is performed in. Due to the semantics of
4307/// these operators, the operands are promoted, the arithmetic performed, an
4308/// implicit conversion back to the result type done, then the assignment takes
4309/// place. This captures the intermediate type which the computation is done
4310/// in.
4311class CompoundAssignOperator : public BinaryOperator {
4312 QualType ComputationLHSType;
4313 QualType ComputationResultType;
4314
4315 /// Construct an empty CompoundAssignOperator.
4316 explicit CompoundAssignOperator(const ASTContext &C, EmptyShell Empty,
4317 bool hasFPFeatures)
4318 : BinaryOperator(CompoundAssignOperatorClass, Empty) {}
4319
4320protected:
4323 SourceLocation OpLoc, FPOptionsOverride FPFeatures,
4324 QualType CompLHSType, QualType CompResultType)
4325 : BinaryOperator(C, lhs, rhs, opc, ResType, VK, OK, OpLoc, FPFeatures,
4326 true),
4327 ComputationLHSType(CompLHSType), ComputationResultType(CompResultType) {
4328 assert(isCompoundAssignmentOp() &&
4329 "Only should be used for compound assignments");
4330 }
4331
4332public:
4334 bool hasFPFeatures);
4335
4336 static CompoundAssignOperator *
4337 Create(const ASTContext &C, Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
4339 FPOptionsOverride FPFeatures, QualType CompLHSType = QualType(),
4340 QualType CompResultType = QualType());
4341
4342 // The two computation types are the type the LHS is converted
4343 // to for the computation and the type of the result; the two are
4344 // distinct in a few cases (specifically, int+=ptr and ptr-=ptr).
4345 QualType getComputationLHSType() const { return ComputationLHSType; }
4346 void setComputationLHSType(QualType T) { ComputationLHSType = T; }
4347
4348 QualType getComputationResultType() const { return ComputationResultType; }
4349 void setComputationResultType(QualType T) { ComputationResultType = T; }
4350
4351 static bool classof(const Stmt *S) {
4352 return S->getStmtClass() == CompoundAssignOperatorClass;
4353 }
4354};
4355
4357 assert(BinaryOperatorBits.HasFPFeatures);
4359 : sizeof(BinaryOperator);
4360}
4361
4362/// AbstractConditionalOperator - An abstract base class for
4363/// ConditionalOperator and BinaryConditionalOperator.
4365 SourceLocation QuestionLoc, ColonLoc;
4366 friend class ASTStmtReader;
4367
4368protected:
4371 SourceLocation cloc)
4372 : Expr(SC, T, VK, OK), QuestionLoc(qloc), ColonLoc(cloc) {}
4373
4376
4377public:
4378 /// getCond - Return the expression representing the condition for
4379 /// the ?: operator.
4380 Expr *getCond() const;
4381
4382 /// getTrueExpr - Return the subexpression representing the value of
4383 /// the expression if the condition evaluates to true.
4384 Expr *getTrueExpr() const;
4385
4386 /// getFalseExpr - Return the subexpression representing the value of
4387 /// the expression if the condition evaluates to false. This is
4388 /// the same as getRHS.
4389 Expr *getFalseExpr() const;
4390
4391 SourceLocation getQuestionLoc() const { return QuestionLoc; }
4392 SourceLocation getColonLoc() const { return ColonLoc; }
4393
4394 static bool classof(const Stmt *T) {
4395 return T->getStmtClass() == ConditionalOperatorClass ||
4396 T->getStmtClass() == BinaryConditionalOperatorClass;
4397 }
4398};
4399
4400/// ConditionalOperator - The ?: ternary operator. The GNU "missing
4401/// middle" extension is a BinaryConditionalOperator.
4403 enum { COND, LHS, RHS, END_EXPR };
4404 Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
4405
4406 friend class ASTStmtReader;
4407public:
4409 SourceLocation CLoc, Expr *rhs, QualType t,
4411 : AbstractConditionalOperator(ConditionalOperatorClass, t, VK, OK, QLoc,
4412 CLoc) {
4413 SubExprs[COND] = cond;
4414 SubExprs[LHS] = lhs;
4415 SubExprs[RHS] = rhs;
4417 }
4418
4419 /// Build an empty conditional operator.
4421 : AbstractConditionalOperator(ConditionalOperatorClass, Empty) { }
4422
4423 /// getCond - Return the expression representing the condition for
4424 /// the ?: operator.
4425 Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
4426
4427 /// getTrueExpr - Return the subexpression representing the value of
4428 /// the expression if the condition evaluates to true.
4429 Expr *getTrueExpr() const { return cast<Expr>(SubExprs[LHS]); }
4430
4431 /// getFalseExpr - Return the subexpression representing the value of
4432 /// the expression if the condition evaluates to false. This is
4433 /// the same as getRHS.
4434 Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); }
4435
4436 Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
4437 Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
4438
4439 SourceLocation getBeginLoc() const LLVM_READONLY {
4440 return getCond()->getBeginLoc();
4441 }
4442 SourceLocation getEndLoc() const LLVM_READONLY {
4443 return getRHS()->getEndLoc();
4444 }
4445
4446 static bool classof(const Stmt *T) {
4447 return T->getStmtClass() == ConditionalOperatorClass;
4448 }
4449
4450 // Iterators
4452 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
4453 }
4455 return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
4456 }
4457};
4458
4459/// BinaryConditionalOperator - The GNU extension to the conditional
4460/// operator which allows the middle operand to be omitted.
4461///
4462/// This is a different expression kind on the assumption that almost
4463/// every client ends up needing to know that these are different.
4465 enum { COMMON, COND, LHS, RHS, NUM_SUBEXPRS };
4466
4467 /// - the common condition/left-hand-side expression, which will be
4468 /// evaluated as the opaque value
4469 /// - the condition, expressed in terms of the opaque value
4470 /// - the left-hand-side, expressed in terms of the opaque value
4471 /// - the right-hand-side
4472 Stmt *SubExprs[NUM_SUBEXPRS];
4473 OpaqueValueExpr *OpaqueValue;
4474
4475 friend class ASTStmtReader;
4476public:
4478 Expr *cond, Expr *lhs, Expr *rhs,
4479 SourceLocation qloc, SourceLocation cloc,
4481 : AbstractConditionalOperator(BinaryConditionalOperatorClass, t, VK, OK,
4482 qloc, cloc),
4483 OpaqueValue(opaqueValue) {
4484 SubExprs[COMMON] = common;
4485 SubExprs[COND] = cond;
4486 SubExprs[LHS] = lhs;
4487 SubExprs[RHS] = rhs;
4488 assert(OpaqueValue->getSourceExpr() == common && "Wrong opaque value");
4490 }
4491
4492 /// Build an empty conditional operator.
4494 : AbstractConditionalOperator(BinaryConditionalOperatorClass, Empty) { }
4495
4496 /// getCommon - Return the common expression, written to the
4497 /// left of the condition. The opaque value will be bound to the
4498 /// result of this expression.
4499 Expr *getCommon() const { return cast<Expr>(SubExprs[COMMON]); }
4500
4501 /// getOpaqueValue - Return the opaque value placeholder.
4502 OpaqueValueExpr *getOpaqueValue() const { return OpaqueValue; }
4503
4504 /// getCond - Return the condition expression; this is defined
4505 /// in terms of the opaque value.
4506 Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
4507
4508 /// getTrueExpr - Return the subexpression which will be
4509 /// evaluated if the condition evaluates to true; this is defined
4510 /// in terms of the opaque value.
4512 return cast<Expr>(SubExprs[LHS]);
4513 }
4514
4515 /// getFalseExpr - Return the subexpression which will be
4516 /// evaluated if the condition evaluates to false; this is
4517 /// defined in terms of the opaque value.
4519 return cast<Expr>(SubExprs[RHS]);
4520 }
4521
4522 SourceLocation getBeginLoc() const LLVM_READONLY {
4523 return getCommon()->getBeginLoc();
4524 }
4525 SourceLocation getEndLoc() const LLVM_READONLY {
4526 return getFalseExpr()->getEndLoc();
4527 }
4528
4529 static bool classof(const Stmt *T) {
4530 return T->getStmtClass() == BinaryConditionalOperatorClass;
4531 }
4532
4533 // Iterators
4535 return child_range(SubExprs, SubExprs + NUM_SUBEXPRS);
4536 }
4538 return const_child_range(SubExprs, SubExprs + NUM_SUBEXPRS);
4539 }
4540};
4541
4543 if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this))
4544 return co->getCond();
4545 return cast<BinaryConditionalOperator>(this)->getCond();
4546}
4547
4549 if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this))
4550 return co->getTrueExpr();
4551 return cast<BinaryConditionalOperator>(this)->getTrueExpr();
4552}
4553
4555 if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this))
4556 return co->getFalseExpr();
4557 return cast<BinaryConditionalOperator>(this)->getFalseExpr();
4558}
4559
4560/// AddrLabelExpr - The GNU address of label extension, representing &&label.
4561class AddrLabelExpr : public Expr {
4562 SourceLocation AmpAmpLoc, LabelLoc;
4563 LabelDecl *Label;
4564public:
4566 QualType t)
4567 : Expr(AddrLabelExprClass, t, VK_PRValue, OK_Ordinary), AmpAmpLoc(AALoc),
4568 LabelLoc(LLoc), Label(L) {
4569 setDependence(ExprDependence::None);
4570 }
4571
4572 /// Build an empty address of a label expression.
4574 : Expr(AddrLabelExprClass, Empty) { }
4575
4576 SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; }
4577 void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; }
4578 SourceLocation getLabelLoc() const { return LabelLoc; }
4579 void setLabelLoc(SourceLocation L) { LabelLoc = L; }
4580
4581 SourceLocation getBeginLoc() const LLVM_READONLY { return AmpAmpLoc; }
4582 SourceLocation getEndLoc() const LLVM_READONLY { return LabelLoc; }
4583
4584 LabelDecl *getLabel() const { return Label; }
4585 void setLabel(LabelDecl *L) { Label = L; }
4586
4587 static bool classof(const Stmt *T) {
4588 return T->getStmtClass() == AddrLabelExprClass;
4589 }
4590
4591 // Iterators
4598};
4599
4600/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
4601/// The StmtExpr contains a single CompoundStmt node, which it evaluates and
4602/// takes the value of the last subexpression.
4603///
4604/// A StmtExpr is always an r-value; values "returned" out of a
4605/// StmtExpr will be copied.
4606class StmtExpr : public Expr {
4607 Stmt *SubStmt;
4608 SourceLocation LParenLoc, RParenLoc;
4609public:
4611 SourceLocation RParenLoc, unsigned TemplateDepth)
4612 : Expr(StmtExprClass, T, VK_PRValue, OK_Ordinary), SubStmt(SubStmt),
4613 LParenLoc(LParenLoc), RParenLoc(RParenLoc) {
4614 setDependence(computeDependence(this, TemplateDepth));
4615 // FIXME: A templated statement expression should have an associated
4616 // DeclContext so that nested declarations always have a dependent context.
4617 StmtExprBits.TemplateDepth = TemplateDepth;
4618 }
4619
4620 /// Build an empty statement expression.
4621 explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { }
4622
4624 const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); }
4625 void setSubStmt(CompoundStmt *S) { SubStmt = S; }
4626
4627 SourceLocation getBeginLoc() const LLVM_READONLY { return LParenLoc; }
4628 SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
4629
4630 SourceLocation getLParenLoc() const { return LParenLoc; }
4631 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
4632 SourceLocation getRParenLoc() const { return RParenLoc; }
4633 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
4634
4635 unsigned getTemplateDepth() const { return StmtExprBits.TemplateDepth; }
4636
4637 static bool classof(const Stmt *T) {
4638 return T->getStmtClass() == StmtExprClass;
4639 }
4640
4641 // Iterators
4642 child_range children() { return child_range(&SubStmt, &SubStmt+1); }
4644 return const_child_range(&SubStmt, &SubStmt + 1);
4645 }
4646};
4647
4648/// ShuffleVectorExpr - clang-specific builtin-in function
4649/// __builtin_shufflevector.
4650/// This AST node represents a operator that does a constant
4651/// shuffle, similar to LLVM's shufflevector instruction. It takes
4652/// two vectors and a variable number of constant indices,
4653/// and returns the appropriately shuffled vector.
4654class ShuffleVectorExpr : public Expr {
4655 SourceLocation BuiltinLoc, RParenLoc;
4656
4657 // SubExprs - the list of values passed to the __builtin_shufflevector
4658 // function. The first two are vectors, and the rest are constant
4659 // indices. The number of values in this list is always
4660 // 2+the number of indices in the vector type.
4661 Stmt **SubExprs;
4662
4663public:
4666
4667 /// Build an empty vector-shuffle expression.
4669 : Expr(ShuffleVectorExprClass, Empty), SubExprs(nullptr) { }
4670
4671 SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
4672 void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
4673
4674 SourceLocation getRParenLoc() const { return RParenLoc; }
4675 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
4676
4677 SourceLocation getBeginLoc() const LLVM_READONLY { return BuiltinLoc; }
4678 SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
4679
4680 static bool classof(const Stmt *T) {
4681 return T->getStmtClass() == ShuffleVectorExprClass;
4682 }
4683
4684 /// getNumSubExprs - Return the size of the SubExprs array. This includes the
4685 /// constant expression, the actual arguments passed in, and the function
4686 /// pointers.
4687 unsigned getNumSubExprs() const { return ShuffleVectorExprBits.NumExprs; }
4688
4689 /// Retrieve the array of expressions.
4690 Expr **getSubExprs() { return reinterpret_cast<Expr **>(SubExprs); }
4691
4692 /// getExpr - Return the Expr at the specified index.
4693 Expr *getExpr(unsigned Index) {
4694 assert((Index < ShuffleVectorExprBits.NumExprs) &&
4695 "Arg access out of range!");
4696 return cast<Expr>(SubExprs[Index]);
4697 }
4698 const Expr *getExpr(unsigned Index) const {
4699 assert((Index < ShuffleVectorExprBits.NumExprs) &&
4700 "Arg access out of range!");
4701 return cast<Expr>(SubExprs[Index]);
4702 }
4703
4704 void setExprs(const ASTContext &C, ArrayRef<Expr *> Exprs);
4705
4706 llvm::APSInt getShuffleMaskIdx(unsigned N) const {
4707 assert((N < ShuffleVectorExprBits.NumExprs - 2) &&
4708 "Shuffle idx out of range!");
4709 assert(isa<ConstantExpr>(getExpr(N + 2)) &&
4710 "Index expression must be a ConstantExpr");
4711 return cast<ConstantExpr>(getExpr(N + 2))->getAPValueResult().getInt();
4712 }
4713
4714 // Iterators
4716 return child_range(&SubExprs[0],
4717 &SubExprs[0] + ShuffleVectorExprBits.NumExprs);
4718 }
4720 return const_child_range(&SubExprs[0],
4721 &SubExprs[0] + ShuffleVectorExprBits.NumExprs);
4722 }
4723};
4724
4725/// ConvertVectorExpr - Clang builtin function __builtin_convertvector
4726/// This AST node provides support for converting a vector type to another
4727/// vector type of the same arity.
4728class ConvertVectorExpr final
4729 : public Expr,
4730 private llvm::TrailingObjects<ConvertVectorExpr, FPOptionsOverride> {
4731private:
4732 Stmt *SrcExpr;
4733 TypeSourceInfo *TInfo;
4734 SourceLocation BuiltinLoc, RParenLoc;
4735
4736 friend TrailingObjects;
4737 friend class ASTReader;
4738 friend class ASTStmtReader;
4739 explicit ConvertVectorExpr(bool HasFPFeatures, EmptyShell Empty)
4740 : Expr(ConvertVectorExprClass, Empty) {
4741 ConvertVectorExprBits.HasFPFeatures = HasFPFeatures;
4742 }
4743
4744 ConvertVectorExpr(Expr *SrcExpr, TypeSourceInfo *TI, QualType DstType,
4746 SourceLocation BuiltinLoc, SourceLocation RParenLoc,
4747 FPOptionsOverride FPFeatures)
4748 : Expr(ConvertVectorExprClass, DstType, VK, OK), SrcExpr(SrcExpr),
4749 TInfo(TI), BuiltinLoc(BuiltinLoc), RParenLoc(RParenLoc) {
4750 ConvertVectorExprBits.HasFPFeatures = FPFeatures.requiresTrailingStorage();
4751 if (hasStoredFPFeatures())
4752 setStoredFPFeatures(FPFeatures);
4754 }
4755
4756 size_t numTrailingObjects(OverloadToken<FPOptionsOverride>) const {
4757 return ConvertVectorExprBits.HasFPFeatures ? 1 : 0;
4758 }
4759
4760 FPOptionsOverride &getTrailingFPFeatures() {
4761 assert(ConvertVectorExprBits.HasFPFeatures);
4762 return *getTrailingObjects();
4763 }
4764
4765 const FPOptionsOverride &getTrailingFPFeatures() const {
4766 assert(ConvertVectorExprBits.HasFPFeatures);
4767 return *getTrailingObjects();
4768 }
4769
4770public:
4771 static ConvertVectorExpr *CreateEmpty(const ASTContext &C,
4772 bool hasFPFeatures);
4773
4774 static ConvertVectorExpr *Create(const ASTContext &C, Expr *SrcExpr,
4775 TypeSourceInfo *TI, QualType DstType,
4777 SourceLocation BuiltinLoc,
4778 SourceLocation RParenLoc,
4779 FPOptionsOverride FPFeatures);
4780
4781 /// Get the FP contractibility status of this operator. Only meaningful for
4782 /// operations on floating point types.
4786
4787 /// Is FPFeatures in Trailing Storage?
4788 bool hasStoredFPFeatures() const {
4789 return ConvertVectorExprBits.HasFPFeatures;
4790 }
4791
4792 /// Get FPFeatures from trailing storage.
4794 return getTrailingFPFeatures();
4795 }
4796
4797 /// Get the store FPOptionsOverride or default if not stored.
4801
4802 /// Set FPFeatures in trailing storage, used by Serialization & ASTImporter.
4803 void setStoredFPFeatures(FPOptionsOverride F) { getTrailingFPFeatures() = F; }
4804
4805 /// Get the FP features status of this operator. Only meaningful for
4806 /// operations on floating point types.
4808 if (ConvertVectorExprBits.HasFPFeatures)
4811 }
4812
4814 if (ConvertVectorExprBits.HasFPFeatures)
4815 return getStoredFPFeatures();
4816 return FPOptionsOverride();
4817 }
4818
4819 /// getSrcExpr - Return the Expr to be converted.
4820 Expr *getSrcExpr() const { return cast<Expr>(SrcExpr); }
4821
4822 /// getTypeSourceInfo - Return the destination type.
4824 return TInfo;
4825 }
4827 TInfo = ti;
4828 }
4829
4830 /// getBuiltinLoc - Return the location of the __builtin_convertvector token.
4831 SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
4832
4833 /// getRParenLoc - Return the location of final right parenthesis.
4834 SourceLocation getRParenLoc() const { return RParenLoc; }
4835
4836 SourceLocation getBeginLoc() const LLVM_READONLY { return BuiltinLoc; }
4837 SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
4838
4839 static bool classof(const Stmt *T) {
4840 return T->getStmtClass() == ConvertVectorExprClass;
4841 }
4842
4843 // Iterators
4844 child_range children() { return child_range(&SrcExpr, &SrcExpr+1); }
4846 return const_child_range(&SrcExpr, &SrcExpr + 1);
4847 }
4848};
4849
4850/// ChooseExpr - GNU builtin-in function __builtin_choose_expr.
4851/// This AST node is similar to the conditional operator (?:) in C, with
4852/// the following exceptions:
4853/// - the test expression must be a integer constant expression.
4854/// - the expression returned acts like the chosen subexpression in every
4855/// visible way: the type is the same as that of the chosen subexpression,
4856/// and all predicates (whether it's an l-value, whether it's an integer
4857/// constant expression, etc.) return the same result as for the chosen
4858/// sub-expression.
4859class ChooseExpr : public Expr {
4860 enum { COND, LHS, RHS, END_EXPR };
4861 Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
4862 SourceLocation BuiltinLoc, RParenLoc;
4863
4864public:
4865 ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, QualType t,
4867 bool condIsTrue)
4868 : Expr(ChooseExprClass, t, VK, OK), BuiltinLoc(BLoc), RParenLoc(RP) {
4869 ChooseExprBits.CondIsTrue = condIsTrue;
4870 SubExprs[COND] = cond;
4871 SubExprs[LHS] = lhs;
4872 SubExprs[RHS] = rhs;
4873
4875 }
4876
4877 /// Build an empty __builtin_choose_expr.
4878 explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { }
4879
4880 /// isConditionTrue - Return whether the condition is true (i.e. not
4881 /// equal to zero).
4882 bool isConditionTrue() const {
4883 assert(!isConditionDependent() &&
4884 "Dependent condition isn't true or false");
4885 return ChooseExprBits.CondIsTrue;
4886 }
4887 void setIsConditionTrue(bool isTrue) { ChooseExprBits.CondIsTrue = isTrue; }
4888
4890 return getCond()->isTypeDependent() || getCond()->isValueDependent();
4891 }
4892
4893 /// getChosenSubExpr - Return the subexpression chosen according to the
4894 /// condition.
4896 return isConditionTrue() ? getLHS() : getRHS();
4897 }
4898
4899 Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
4900 void setCond(Expr *E) { SubExprs[COND] = E; }
4901 Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
4902 void setLHS(Expr *E) { SubExprs[LHS] = E; }
4903 Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
4904 void setRHS(Expr *E) { SubExprs[RHS] = E; }
4905
4906 SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
4907 void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
4908
4909 SourceLocation getRParenLoc() const { return RParenLoc; }
4910 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
4911
4912 SourceLocation getBeginLoc() const LLVM_READONLY { return BuiltinLoc; }
4913 SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
4914
4915 static bool classof(const Stmt *T) {
4916 return T->getStmtClass() == ChooseExprClass;
4917 }
4918
4919 // Iterators
4921 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
4922 }
4924 return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
4925 }
4926};
4927
4928/// GNUNullExpr - Implements the GNU __null extension, which is a name
4929/// for a null pointer constant that has integral type (e.g., int or
4930/// long) and is the same size and alignment as a pointer. The __null
4931/// extension is typically only used by system headers, which define
4932/// NULL as __null in C++ rather than using 0 (which is an integer
4933/// that may not match the size of a pointer).
4934class GNUNullExpr : public Expr {
4935 /// TokenLoc - The location of the __null keyword.
4936 SourceLocation TokenLoc;
4937
4938public:
4940 : Expr(GNUNullExprClass, Ty, VK_PRValue, OK_Ordinary), TokenLoc(Loc) {
4941 setDependence(ExprDependence::None);
4942 }
4943
4944 /// Build an empty GNU __null expression.
4945 explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { }
4946
4947 /// getTokenLocation - The location of the __null token.
4948 SourceLocation getTokenLocation() const { return TokenLoc; }
4949 void setTokenLocation(SourceLocation L) { TokenLoc = L; }
4950
4951 SourceLocation getBeginLoc() const LLVM_READONLY { return TokenLoc; }
4952 SourceLocation getEndLoc() const LLVM_READONLY { return TokenLoc; }
4953
4954 static bool classof(const Stmt *T) {
4955 return T->getStmtClass() == GNUNullExprClass;
4956 }
4957
4958 // Iterators
4965};
4966
4967/// Represents a call to the builtin function \c __builtin_va_arg.
4968class VAArgExpr : public Expr {
4969public:
4971
4972private:
4973 Stmt *Val;
4974 llvm::PointerIntPair<TypeSourceInfo *, 2, VarArgKind> TInfo;
4975 SourceLocation BuiltinLoc, RParenLoc;
4976public:
4978 SourceLocation RPLoc, QualType t, VarArgKind VaKind)
4979 : Expr(VAArgExprClass, t, VK_PRValue, OK_Ordinary), Val(e),
4980 TInfo(TInfo, VaKind), BuiltinLoc(BLoc), RParenLoc(RPLoc) {
4982 }
4983
4984 /// Create an empty __builtin_va_arg expression.
4986 : Expr(VAArgExprClass, Empty), Val(nullptr), TInfo(nullptr, VA_Std) {}
4987
4988 const Expr *getSubExpr() const { return cast<Expr>(Val); }
4989 Expr *getSubExpr() { return cast<Expr>(Val); }
4990 void setSubExpr(Expr *E) { Val = E; }
4991
4992 VarArgKind getVarargABI() const { return TInfo.getInt(); }
4993 void setVarargABI(VarArgKind Kind) { TInfo.setInt(Kind); }
4994
4995 /// Returns whether this is really a Win64 ABI va_arg expression.
4996 bool isMicrosoftABI() const { return TInfo.getInt() == VA_MS; }
4997
4998 /// Returns whether this is really a z/OS ABI va_arg expression.
4999 bool isZOSABI() const { return TInfo.getInt() == VA_ZOS; }
5000
5001 TypeSourceInfo *getWrittenTypeInfo() const { return TInfo.getPointer(); }
5002 void setWrittenTypeInfo(TypeSourceInfo *TI) { TInfo.setPointer(TI); }
5003
5004 SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
5005 void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
5006
5007 SourceLocation getRParenLoc() const { return RParenLoc; }
5008 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
5009
5010 SourceLocation getBeginLoc() const LLVM_READONLY { return BuiltinLoc; }
5011 SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
5012
5013 static bool classof(const Stmt *T) {
5014 return T->getStmtClass() == VAArgExprClass;
5015 }
5016
5017 // Iterators
5018 child_range children() { return child_range(&Val, &Val+1); }
5020 return const_child_range(&Val, &Val + 1);
5021 }
5022};
5023
5033
5034/// Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(),
5035/// __builtin_FUNCTION(), __builtin_FUNCSIG(), __builtin_FILE(),
5036/// __builtin_FILE_NAME() or __builtin_source_location().
5037class SourceLocExpr final : public Expr {
5038 SourceLocation BuiltinLoc, RParenLoc;
5039 DeclContext *ParentContext;
5040
5041public:
5043 QualType ResultTy, SourceLocation BLoc,
5044 SourceLocation RParenLoc, DeclContext *Context);
5045
5046 /// Build an empty call expression.
5047 explicit SourceLocExpr(EmptyShell Empty) : Expr(SourceLocExprClass, Empty) {}
5048
5049 /// Return the result of evaluating this SourceLocExpr in the specified
5050 /// (and possibly null) default argument or initialization context.
5052 const Expr *DefaultExpr) const;
5053
5054 /// Return a string representing the name of the specific builtin function.
5055 StringRef getBuiltinStr() const;
5056
5058 return static_cast<SourceLocIdentKind>(SourceLocExprBits.Kind);
5059 }
5060
5061 bool isIntType() const {
5062 switch (getIdentKind()) {
5068 return false;
5071 return true;
5072 }
5073 llvm_unreachable("unknown source location expression kind");
5074 }
5075
5076 /// If the SourceLocExpr has been resolved return the subexpression
5077 /// representing the resolved value. Otherwise return null.
5078 const DeclContext *getParentContext() const { return ParentContext; }
5079 DeclContext *getParentContext() { return ParentContext; }
5080
5081 SourceLocation getLocation() const { return BuiltinLoc; }
5082 SourceLocation getBeginLoc() const { return BuiltinLoc; }
5083 SourceLocation getEndLoc() const { return RParenLoc; }
5084
5088
5092
5093 static bool classof(const Stmt *T) {
5094 return T->getStmtClass() == SourceLocExprClass;
5095 }
5096
5098 switch (Kind) {
5102 return true;
5103 default:
5104 return false;
5105 }
5106 }
5107
5108private:
5109 friend class ASTStmtReader;
5110};
5111
5112/// Stores data related to a single #embed directive.
5115 // FileName string already includes braces, i.e. it is <files/my_file> for a
5116 // directive #embed <files/my_file>.
5117 StringRef FileName;
5118 size_t getDataElementCount() const { return BinaryData->getByteLength(); }
5119};
5120
5121/// Represents a reference to #emded data. By default, this references the whole
5122/// range. Otherwise it represents a subrange of data imported by #embed
5123/// directive. Needed to handle nested initializer lists with #embed directives.
5124/// Example:
5125/// struct S {
5126/// int x, y;
5127/// };
5128///
5129/// struct T {
5130/// int x[2];
5131/// struct S s
5132/// };
5133///
5134/// struct T t[] = {
5135/// #embed "data" // data contains 10 elements;
5136/// };
5137///
5138/// The resulting semantic form of initializer list will contain (EE stands
5139/// for EmbedExpr):
5140/// { {EE(first two data elements), {EE(3rd element), EE(4th element) }},
5141/// { {EE(5th and 6th element), {EE(7th element), EE(8th element) }},
5142/// { {EE(9th and 10th element), { zeroinitializer }}}
5143///
5144/// EmbedExpr inside of a semantic initializer list and referencing more than
5145/// one element can only appear for arrays of scalars.
5146class EmbedExpr final : public Expr {
5147 SourceLocation EmbedKeywordLoc;
5148 IntegerLiteral *FakeChildNode = nullptr;
5149 const ASTContext *Ctx = nullptr;
5150 EmbedDataStorage *Data;
5151 unsigned Begin = 0;
5152 unsigned NumOfElements;
5153
5154public:
5155 EmbedExpr(const ASTContext &Ctx, SourceLocation Loc, EmbedDataStorage *Data,
5156 unsigned Begin, unsigned NumOfElements);
5157 explicit EmbedExpr(EmptyShell Empty) : Expr(EmbedExprClass, Empty) {}
5158
5159 SourceLocation getLocation() const { return EmbedKeywordLoc; }
5160 SourceLocation getBeginLoc() const { return EmbedKeywordLoc; }
5161 SourceLocation getEndLoc() const { return EmbedKeywordLoc; }
5162
5163 StringLiteral *getDataStringLiteral() const { return Data->BinaryData; }
5164 StringRef getFileName() const { return Data->FileName; }
5165 EmbedDataStorage *getData() const { return Data; }
5166
5167 unsigned getStartingElementPos() const { return Begin; }
5168 size_t getDataElementCount() const { return NumOfElements; }
5169
5170 // Allows accessing every byte of EmbedExpr data and iterating over it.
5171 // An Iterator knows the EmbedExpr that it refers to, and an offset value
5172 // within the data.
5173 // Dereferencing an Iterator results in construction of IntegerLiteral AST
5174 // node filled with byte of data of the corresponding EmbedExpr within offset
5175 // that the Iterator currently has.
5176 template <bool Const>
5177 class ChildElementIter
5178 : public llvm::iterator_facade_base<
5179 ChildElementIter<Const>, std::random_access_iterator_tag,
5180 std::conditional_t<Const, const IntegerLiteral *,
5181 IntegerLiteral *>> {
5182 friend class EmbedExpr;
5183
5184 EmbedExpr *EExpr = nullptr;
5185 unsigned long long CurOffset = ULLONG_MAX;
5186 using BaseTy = typename ChildElementIter::iterator_facade_base;
5187
5188 ChildElementIter(EmbedExpr *E) : EExpr(E) {
5189 if (E)
5190 CurOffset = E->getStartingElementPos();
5191 }
5192
5193 public:
5194 ChildElementIter() : CurOffset(ULLONG_MAX) {}
5195 typename BaseTy::reference operator*() const {
5196 assert(EExpr && CurOffset != ULLONG_MAX &&
5197 "trying to dereference an invalid iterator");
5198 IntegerLiteral *N = EExpr->FakeChildNode;
5199 N->setValue(*EExpr->Ctx,
5200 llvm::APInt(N->getBitWidth(),
5201 EExpr->Data->BinaryData->getCodeUnit(CurOffset),
5202 /*Signed=*/true));
5203 // We want to return a reference to the fake child node in the
5204 // EmbedExpr, not the local variable N.
5205 return const_cast<typename BaseTy::reference>(EExpr->FakeChildNode);
5206 }
5207 typename BaseTy::pointer operator->() const { return **this; }
5208 using BaseTy::operator++;
5209 ChildElementIter &operator++() {
5210 assert(EExpr && "trying to increment an invalid iterator");
5211 assert(CurOffset != ULLONG_MAX &&
5212 "Already at the end of what we can iterate over");
5213 if (++CurOffset >=
5214 EExpr->getDataElementCount() + EExpr->getStartingElementPos()) {
5215 CurOffset = ULLONG_MAX;
5216 EExpr = nullptr;
5217 }
5218 return *this;
5219 }
5220 bool operator==(ChildElementIter Other) const {
5221 return (EExpr == Other.EExpr && CurOffset == Other.CurOffset);
5222 }
5223 }; // class ChildElementIter
5224
5225public:
5226 using fake_child_range = llvm::iterator_range<ChildElementIter<false>>;
5227 using const_fake_child_range = llvm::iterator_range<ChildElementIter<true>>;
5228
5233
5239
5243
5247
5248 static bool classof(const Stmt *T) {
5249 return T->getStmtClass() == EmbedExprClass;
5250 }
5251
5253
5255 return ChildElementIter<true>(const_cast<EmbedExpr *>(this));
5256 }
5257
5258 template <typename Call, typename... Targs>
5259 bool doForEachDataElement(Call &&C, unsigned &StartingIndexInArray,
5260 Targs &&...Fargs) const {
5261 for (auto It : underlying_data_elements()) {
5262 if (!std::invoke(std::forward<Call>(C), const_cast<IntegerLiteral *>(It),
5263 StartingIndexInArray, std::forward<Targs>(Fargs)...))
5264 return false;
5265 StartingIndexInArray++;
5266 }
5267 return true;
5268 }
5269
5270private:
5271 friend class ASTStmtReader;
5272};
5273
5274/// Describes an C or C++ initializer list.
5275///
5276/// InitListExpr describes an initializer list, which can be used to
5277/// initialize objects of different types, including
5278/// struct/class/union types, arrays, and vectors. For example:
5279///
5280/// @code
5281/// struct foo x = { 1, { 2, 3 } };
5282/// @endcode
5283///
5284/// Prior to semantic analysis, an initializer list will represent the
5285/// initializer list as written by the user, but will have the
5286/// placeholder type "void". This initializer list is called the
5287/// syntactic form of the initializer, and may contain C99 designated
5288/// initializers (represented as DesignatedInitExprs), initializations
5289/// of subobject members without explicit braces, and so on. Clients
5290/// interested in the original syntax of the initializer list should
5291/// use the syntactic form of the initializer list.
5292///
5293/// After semantic analysis, the initializer list will represent the
5294/// semantic form of the initializer, where the initializations of all
5295/// subobjects are made explicit with nested InitListExpr nodes and
5296/// C99 designators have been eliminated by placing the designated
5297/// initializations into the subobject they initialize. Additionally,
5298/// any "holes" in the initialization, where no initializer has been
5299/// specified for a particular subobject, will be replaced with
5300/// implicitly-generated ImplicitValueInitExpr expressions that
5301/// value-initialize the subobjects. Note, however, that the
5302/// initializer lists may still have fewer initializers than there are
5303/// elements to initialize within the object.
5304///
5305/// After semantic analysis has completed, given an initializer list,
5306/// method isSemanticForm() returns true if and only if this is the
5307/// semantic form of the initializer list (note: the same AST node
5308/// may at the same time be the syntactic form).
5309/// Given the semantic form of the initializer list, one can retrieve
5310/// the syntactic form of that initializer list (when different)
5311/// using method getSyntacticForm(); the method returns null if applied
5312/// to a initializer list which is already in syntactic form.
5313/// Similarly, given the syntactic form (i.e., an initializer list such
5314/// that isSemanticForm() returns false), one can retrieve the semantic
5315/// form using method getSemanticForm().
5316/// Since many initializer lists have the same syntactic and semantic forms,
5317/// getSyntacticForm() may return NULL, indicating that the current
5318/// semantic initializer list also serves as its syntactic form.
5319class InitListExpr : public Expr {
5320 // FIXME: Eliminate this vector in favor of ASTContext allocation
5321 typedef ASTVector<Stmt *> InitExprsTy;
5322 InitExprsTy InitExprs;
5323 SourceLocation LBraceLoc, RBraceLoc;
5324
5325 /// The alternative form of the initializer list (if it exists).
5326 /// The int part of the pair stores whether this initializer list is
5327 /// in semantic form. If not null, the pointer points to:
5328 /// - the syntactic form, if this is in semantic form;
5329 /// - the semantic form, if this is in syntactic form.
5330 llvm::PointerIntPair<InitListExpr *, 1, bool> AltForm;
5331
5332 /// Either:
5333 /// If this initializer list initializes an array with more elements than
5334 /// there are initializers in the list, specifies an expression to be used
5335 /// for value initialization of the rest of the elements.
5336 /// Or
5337 /// If this initializer list initializes a union, specifies which
5338 /// field within the union will be initialized.
5339 llvm::PointerUnion<Expr *, FieldDecl *> ArrayFillerOrUnionFieldInit;
5340
5341public:
5342 InitListExpr(const ASTContext &C, SourceLocation lbraceloc,
5343 ArrayRef<Expr *> initExprs, SourceLocation rbraceloc,
5344 bool isExplicit);
5345
5346 /// Build an empty initializer list.
5348 : Expr(InitListExprClass, Empty), AltForm(nullptr, true) {
5349 InitListExprBits.IsExplicit = false;
5350 }
5351
5352 unsigned getNumInits() const { return InitExprs.size(); }
5353
5354 /// getNumInits but if the list has an EmbedExpr inside includes full length
5355 /// of embedded data.
5357 unsigned Sum = InitExprs.size();
5358 for (auto *IE : InitExprs)
5359 if (auto *EE = dyn_cast<EmbedExpr>(IE))
5360 Sum += EE->getDataElementCount() - 1;
5361 return Sum;
5362 }
5363
5364 /// Retrieve the set of initializers.
5365 Expr **getInits() { return reinterpret_cast<Expr **>(InitExprs.data()); }
5366
5367 /// Retrieve the set of initializers.
5368 Expr * const *getInits() const {
5369 return reinterpret_cast<Expr * const *>(InitExprs.data());
5370 }
5371
5372 ArrayRef<Expr *> inits() const { return {getInits(), getNumInits()}; }
5373
5374 const Expr *getInit(unsigned Init) const {
5375 assert(Init < getNumInits() && "Initializer access out of range!");
5376 return cast_or_null<Expr>(InitExprs[Init]);
5377 }
5378
5379 Expr *getInit(unsigned Init) {
5380 assert(Init < getNumInits() && "Initializer access out of range!");
5381 return cast_or_null<Expr>(InitExprs[Init]);
5382 }
5383
5384 void setInit(unsigned Init, Expr *expr) {
5385 assert(Init < getNumInits() && "Initializer access out of range!");
5386 InitExprs[Init] = expr;
5387
5388 if (expr)
5389 setDependence(getDependence() | expr->getDependence());
5390 }
5391
5392 /// Mark the semantic form of the InitListExpr as error when the semantic
5393 /// analysis fails.
5394 void markError() {
5395 assert(isSemanticForm());
5396 setDependence(getDependence() | ExprDependence::ErrorDependent);
5397 }
5398
5399 /// Reserve space for some number of initializers.
5400 void reserveInits(const ASTContext &C, unsigned NumInits);
5401
5402 /// Specify the number of initializers
5403 ///
5404 /// If there are more than @p NumInits initializers, the remaining
5405 /// initializers will be destroyed. If there are fewer than @p
5406 /// NumInits initializers, NULL expressions will be added for the
5407 /// unknown initializers.
5408 void resizeInits(const ASTContext &Context, unsigned NumInits);
5409
5410 /// Updates the initializer at index @p Init with the new
5411 /// expression @p expr, and returns the old expression at that
5412 /// location.
5413 ///
5414 /// When @p Init is out of range for this initializer list, the
5415 /// initializer list will be extended with NULL expressions to
5416 /// accommodate the new entry.
5417 Expr *updateInit(const ASTContext &C, unsigned Init, Expr *expr);
5418
5419 /// If this initializer list initializes an array with more elements
5420 /// than there are initializers in the list, specifies an expression to be
5421 /// used for value initialization of the rest of the elements.
5423 return dyn_cast_if_present<Expr *>(ArrayFillerOrUnionFieldInit);
5424 }
5425 const Expr *getArrayFiller() const {
5426 return const_cast<InitListExpr *>(this)->getArrayFiller();
5427 }
5428 void setArrayFiller(Expr *filler);
5429
5430 /// Return true if this is an array initializer and its array "filler"
5431 /// has been set.
5432 bool hasArrayFiller() const { return getArrayFiller(); }
5433
5434 /// Determine whether this initializer list contains a designated initializer.
5435 bool hasDesignatedInit() const {
5436 return llvm::any_of(
5437 *this, [](const Stmt *S) { return isa<DesignatedInitExpr>(S); });
5438 }
5439
5440 /// If this initializes a union, specifies which field in the
5441 /// union to initialize.
5442 ///
5443 /// Typically, this field is the first named field within the
5444 /// union. However, a designated initializer can specify the
5445 /// initialization of a different field within the union.
5447 return dyn_cast_if_present<FieldDecl *>(ArrayFillerOrUnionFieldInit);
5448 }
5450 return const_cast<InitListExpr *>(this)->getInitializedFieldInUnion();
5451 }
5453 assert((FD == nullptr
5454 || getInitializedFieldInUnion() == nullptr
5455 || getInitializedFieldInUnion() == FD)
5456 && "Only one field of a union may be initialized at a time!");
5457 ArrayFillerOrUnionFieldInit = FD;
5458 }
5459
5460 // Explicit InitListExpr's originate from source code (and have valid source
5461 // locations). Implicit InitListExpr's are created by the semantic analyzer.
5462 bool isExplicit() const { return InitListExprBits.IsExplicit; }
5463
5464 /// Is this an initializer for an array of characters, initialized by a string
5465 /// literal or an @encode?
5466 bool isStringLiteralInit() const;
5467
5468 /// Is this a transparent initializer list (that is, an InitListExpr that is
5469 /// purely syntactic, and whose semantics are that of the sole contained
5470 /// initializer)?
5471 bool isTransparent() const;
5472
5473 /// Is this the zero initializer {0} in a language which considers it
5474 /// idiomatic?
5475 bool isIdiomaticZeroInitializer(const LangOptions &LangOpts) const;
5476
5477 SourceLocation getLBraceLoc() const { return LBraceLoc; }
5478 void setLBraceLoc(SourceLocation Loc) { LBraceLoc = Loc; }
5479 SourceLocation getRBraceLoc() const { return RBraceLoc; }
5480 void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; }
5481
5482 bool isSemanticForm() const { return AltForm.getInt(); }
5484 return isSemanticForm() ? nullptr : AltForm.getPointer();
5485 }
5486 bool isSyntacticForm() const {
5487 return !AltForm.getInt() || !AltForm.getPointer();
5488 }
5490 return isSemanticForm() ? AltForm.getPointer() : nullptr;
5491 }
5492
5494 AltForm.setPointer(Init);
5495 AltForm.setInt(true);
5496 Init->AltForm.setPointer(this);
5497 Init->AltForm.setInt(false);
5498 }
5499
5501 return InitListExprBits.HadArrayRangeDesignator != 0;
5502 }
5503 void sawArrayRangeDesignator(bool ARD = true) {
5504 InitListExprBits.HadArrayRangeDesignator = ARD;
5505 }
5506
5507 SourceLocation getBeginLoc() const LLVM_READONLY;
5508 SourceLocation getEndLoc() const LLVM_READONLY;
5509
5510 static bool classof(const Stmt *T) {
5511 return T->getStmtClass() == InitListExprClass;
5512 }
5513
5514 // Iterators
5516 const_child_range CCR = const_cast<const InitListExpr *>(this)->children();
5517 return child_range(cast_away_const(CCR.begin()),
5518 cast_away_const(CCR.end()));
5519 }
5520
5522 // FIXME: This does not include the array filler expression.
5523 if (InitExprs.empty())
5525 return const_child_range(&InitExprs[0], &InitExprs[0] + InitExprs.size());
5526 }
5527
5532
5533 iterator begin() { return InitExprs.begin(); }
5534 const_iterator begin() const { return InitExprs.begin(); }
5535 iterator end() { return InitExprs.end(); }
5536 const_iterator end() const { return InitExprs.end(); }
5537 reverse_iterator rbegin() { return InitExprs.rbegin(); }
5538 const_reverse_iterator rbegin() const { return InitExprs.rbegin(); }
5539 reverse_iterator rend() { return InitExprs.rend(); }
5540 const_reverse_iterator rend() const { return InitExprs.rend(); }
5541
5542 friend class ASTStmtReader;
5543 friend class ASTStmtWriter;
5544};
5545
5546/// Represents a C99 designated initializer expression.
5547///
5548/// A designated initializer expression (C99 6.7.8) contains one or
5549/// more designators (which can be field designators, array
5550/// designators, or GNU array-range designators) followed by an
5551/// expression that initializes the field or element(s) that the
5552/// designators refer to. For example, given:
5553///
5554/// @code
5555/// struct point {
5556/// double x;
5557/// double y;
5558/// };
5559/// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 };
5560/// @endcode
5561///
5562/// The InitListExpr contains three DesignatedInitExprs, the first of
5563/// which covers @c [2].y=1.0. This DesignatedInitExpr will have two
5564/// designators, one array designator for @c [2] followed by one field
5565/// designator for @c .y. The initialization expression will be 1.0.
5566class DesignatedInitExpr final
5567 : public Expr,
5568 private llvm::TrailingObjects<DesignatedInitExpr, Stmt *> {
5569public:
5570 /// Forward declaration of the Designator class.
5571 class Designator;
5572
5573private:
5574 /// The location of the '=' or ':' prior to the actual initializer
5575 /// expression.
5576 SourceLocation EqualOrColonLoc;
5577
5578 /// Whether this designated initializer used the GNU deprecated
5579 /// syntax rather than the C99 '=' syntax.
5580 LLVM_PREFERRED_TYPE(bool)
5581 unsigned GNUSyntax : 1;
5582
5583 /// The number of designators in this initializer expression.
5584 unsigned NumDesignators : 15;
5585
5586 /// The number of subexpressions of this initializer expression,
5587 /// which contains both the initializer and any additional
5588 /// expressions used by array and array-range designators.
5589 unsigned NumSubExprs : 16;
5590
5591 /// The designators in this designated initialization
5592 /// expression.
5593 Designator *Designators;
5594
5595 DesignatedInitExpr(const ASTContext &C, QualType Ty,
5596 ArrayRef<Designator> Designators,
5597 SourceLocation EqualOrColonLoc, bool GNUSyntax,
5598 ArrayRef<Expr *> IndexExprs, Expr *Init);
5599
5600 explicit DesignatedInitExpr(unsigned NumSubExprs)
5601 : Expr(DesignatedInitExprClass, EmptyShell()),
5602 NumDesignators(0), NumSubExprs(NumSubExprs), Designators(nullptr) { }
5603
5604public:
5605 /// Represents a single C99 designator.
5606 ///
5607 /// @todo This class is infuriatingly similar to clang::Designator,
5608 /// but minor differences (storing indices vs. storing pointers)
5609 /// keep us from reusing it. Try harder, later, to rectify these
5610 /// differences.
5611 class Designator {
5612 /// A field designator, e.g., ".x".
5613 struct FieldDesignatorInfo {
5614 /// Refers to the field that is being initialized. The low bit
5615 /// of this field determines whether this is actually a pointer
5616 /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When
5617 /// initially constructed, a field designator will store an
5618 /// IdentifierInfo*. After semantic analysis has resolved that
5619 /// name, the field designator will instead store a FieldDecl*.
5620 uintptr_t NameOrField;
5621
5622 /// The location of the '.' in the designated initializer.
5623 SourceLocation DotLoc;
5624
5625 /// The location of the field name in the designated initializer.
5626 SourceLocation FieldLoc;
5627
5628 FieldDesignatorInfo(const IdentifierInfo *II, SourceLocation DotLoc,
5629 SourceLocation FieldLoc)
5630 : NameOrField(reinterpret_cast<uintptr_t>(II) | 0x1), DotLoc(DotLoc),
5631 FieldLoc(FieldLoc) {}
5632 };
5633
5634 /// An array or GNU array-range designator, e.g., "[9]" or "[10...15]".
5635 struct ArrayOrRangeDesignatorInfo {
5636 /// Location of the first index expression within the designated
5637 /// initializer expression's list of subexpressions.
5638 unsigned Index;
5639
5640 /// The location of the '[' starting the array range designator.
5641 SourceLocation LBracketLoc;
5642
5643 /// The location of the ellipsis separating the start and end
5644 /// indices. Only valid for GNU array-range designators.
5645 SourceLocation EllipsisLoc;
5646
5647 /// The location of the ']' terminating the array range designator.
5648 SourceLocation RBracketLoc;
5649
5650 ArrayOrRangeDesignatorInfo(unsigned Index, SourceLocation LBracketLoc,
5651 SourceLocation RBracketLoc)
5652 : Index(Index), LBracketLoc(LBracketLoc), RBracketLoc(RBracketLoc) {}
5653
5654 ArrayOrRangeDesignatorInfo(unsigned Index,
5655 SourceLocation LBracketLoc,
5656 SourceLocation EllipsisLoc,
5657 SourceLocation RBracketLoc)
5658 : Index(Index), LBracketLoc(LBracketLoc), EllipsisLoc(EllipsisLoc),
5659 RBracketLoc(RBracketLoc) {}
5660 };
5661
5662 /// The kind of designator this describes.
5663 enum DesignatorKind {
5664 FieldDesignator,
5665 ArrayDesignator,
5666 ArrayRangeDesignator
5667 };
5668
5669 DesignatorKind Kind;
5670
5671 union {
5672 /// A field designator, e.g., ".x".
5673 struct FieldDesignatorInfo FieldInfo;
5674
5675 /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
5676 struct ArrayOrRangeDesignatorInfo ArrayOrRangeInfo;
5677 };
5678
5679 Designator(DesignatorKind Kind) : Kind(Kind) {}
5680
5681 public:
5683
5684 bool isFieldDesignator() const { return Kind == FieldDesignator; }
5685 bool isArrayDesignator() const { return Kind == ArrayDesignator; }
5686 bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; }
5687
5688 //===------------------------------------------------------------------===//
5689 // FieldDesignatorInfo
5690
5691 /// Creates a field designator.
5692 static Designator CreateFieldDesignator(const IdentifierInfo *FieldName,
5693 SourceLocation DotLoc,
5694 SourceLocation FieldLoc) {
5695 Designator D(FieldDesignator);
5696 new (&D.FieldInfo) FieldDesignatorInfo(FieldName, DotLoc, FieldLoc);
5697 return D;
5698 }
5699
5700 const IdentifierInfo *getFieldName() const;
5701
5703 assert(isFieldDesignator() && "Only valid on a field designator");
5704 if (FieldInfo.NameOrField & 0x01)
5705 return nullptr;
5706 return reinterpret_cast<FieldDecl *>(FieldInfo.NameOrField);
5707 }
5708
5710 assert(isFieldDesignator() && "Only valid on a field designator");
5711 FieldInfo.NameOrField = reinterpret_cast<uintptr_t>(FD);
5712 }
5713
5715 assert(isFieldDesignator() && "Only valid on a field designator");
5716 return FieldInfo.DotLoc;
5717 }
5718
5720 assert(isFieldDesignator() && "Only valid on a field designator");
5721 return FieldInfo.FieldLoc;
5722 }
5723
5724 //===------------------------------------------------------------------===//
5725 // ArrayOrRangeDesignator
5726
5727 /// Creates an array designator.
5728 static Designator CreateArrayDesignator(unsigned Index,
5729 SourceLocation LBracketLoc,
5730 SourceLocation RBracketLoc) {
5731 Designator D(ArrayDesignator);
5732 new (&D.ArrayOrRangeInfo) ArrayOrRangeDesignatorInfo(Index, LBracketLoc,
5733 RBracketLoc);
5734 return D;
5735 }
5736
5737 /// Creates a GNU array-range designator.
5738 static Designator CreateArrayRangeDesignator(unsigned Index,
5739 SourceLocation LBracketLoc,
5740 SourceLocation EllipsisLoc,
5741 SourceLocation RBracketLoc) {
5742 Designator D(ArrayRangeDesignator);
5743 new (&D.ArrayOrRangeInfo) ArrayOrRangeDesignatorInfo(Index, LBracketLoc,
5744 EllipsisLoc,
5745 RBracketLoc);
5746 return D;
5747 }
5748
5749 unsigned getArrayIndex() const {
5750 assert((isArrayDesignator() || isArrayRangeDesignator()) &&
5751 "Only valid on an array or array-range designator");
5752 return ArrayOrRangeInfo.Index;
5753 }
5754
5756 assert((isArrayDesignator() || isArrayRangeDesignator()) &&
5757 "Only valid on an array or array-range designator");
5758 return ArrayOrRangeInfo.LBracketLoc;
5759 }
5760
5762 assert(isArrayRangeDesignator() &&
5763 "Only valid on an array-range designator");
5764 return ArrayOrRangeInfo.EllipsisLoc;
5765 }
5766
5768 assert((isArrayDesignator() || isArrayRangeDesignator()) &&
5769 "Only valid on an array or array-range designator");
5770 return ArrayOrRangeInfo.RBracketLoc;
5771 }
5772
5773 SourceLocation getBeginLoc() const LLVM_READONLY {
5774 if (isFieldDesignator())
5775 return getDotLoc().isInvalid() ? getFieldLoc() : getDotLoc();
5776 return getLBracketLoc();
5777 }
5778
5779 SourceLocation getEndLoc() const LLVM_READONLY {
5781 }
5782
5783 SourceRange getSourceRange() const LLVM_READONLY {
5784 return SourceRange(getBeginLoc(), getEndLoc());
5785 }
5786 };
5787
5788 static DesignatedInitExpr *Create(const ASTContext &C,
5789 ArrayRef<Designator> Designators,
5790 ArrayRef<Expr *> IndexExprs,
5791 SourceLocation EqualOrColonLoc,
5792 bool GNUSyntax, Expr *Init);
5793
5795 unsigned NumIndexExprs);
5796
5797 /// Returns the number of designators in this initializer.
5798 unsigned size() const { return NumDesignators; }
5799
5800 // Iterator access to the designators.
5802 return {Designators, NumDesignators};
5803 }
5804
5806 return {Designators, NumDesignators};
5807 }
5808
5809 Designator *getDesignator(unsigned Idx) { return &designators()[Idx]; }
5810 const Designator *getDesignator(unsigned Idx) const {
5811 return &designators()[Idx];
5812 }
5813
5814 void setDesignators(const ASTContext &C, const Designator *Desigs,
5815 unsigned NumDesigs);
5816
5817 Expr *getArrayIndex(const Designator &D) const;
5818 Expr *getArrayRangeStart(const Designator &D) const;
5819 Expr *getArrayRangeEnd(const Designator &D) const;
5820
5821 /// Retrieve the location of the '=' that precedes the
5822 /// initializer value itself, if present.
5823 SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; }
5824 void setEqualOrColonLoc(SourceLocation L) { EqualOrColonLoc = L; }
5825
5826 /// Whether this designated initializer should result in direct-initialization
5827 /// of the designated subobject (eg, '{.foo{1, 2, 3}}').
5828 bool isDirectInit() const { return EqualOrColonLoc.isInvalid(); }
5829
5830 /// Determines whether this designated initializer used the
5831 /// deprecated GNU syntax for designated initializers.
5832 bool usesGNUSyntax() const { return GNUSyntax; }
5833 void setGNUSyntax(bool GNU) { GNUSyntax = GNU; }
5834
5835 /// Retrieve the initializer value.
5836 Expr *getInit() const {
5837 return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin());
5838 }
5839
5840 void setInit(Expr *init) {
5841 *child_begin() = init;
5842 }
5843
5844 /// Retrieve the total number of subexpressions in this
5845 /// designated initializer expression, including the actual
5846 /// initialized value and any expressions that occur within array
5847 /// and array-range designators.
5848 unsigned getNumSubExprs() const { return NumSubExprs; }
5849
5850 Expr *getSubExpr(unsigned Idx) const {
5851 return cast<Expr>(getTrailingObjects(NumSubExprs)[Idx]);
5852 }
5853
5854 void setSubExpr(unsigned Idx, Expr *E) {
5855 getTrailingObjects(NumSubExprs)[Idx] = E;
5856 }
5857
5858 /// Replaces the designator at index @p Idx with the series
5859 /// of designators in [First, Last).
5860 void ExpandDesignator(const ASTContext &C, unsigned Idx,
5861 const Designator *First, const Designator *Last);
5862
5864
5865 SourceLocation getBeginLoc() const LLVM_READONLY;
5866 SourceLocation getEndLoc() const LLVM_READONLY;
5867
5868 static bool classof(const Stmt *T) {
5869 return T->getStmtClass() == DesignatedInitExprClass;
5870 }
5871
5872 // Iterators
5874 Stmt **begin = getTrailingObjects();
5875 return child_range(begin, begin + NumSubExprs);
5876 }
5878 Stmt *const *begin = getTrailingObjects();
5879 return const_child_range(begin, begin + NumSubExprs);
5880 }
5881
5883};
5884
5885/// Represents a place-holder for an object not to be initialized by
5886/// anything.
5887///
5888/// This only makes sense when it appears as part of an updater of a
5889/// DesignatedInitUpdateExpr (see below). The base expression of a DIUE
5890/// initializes a big object, and the NoInitExpr's mark the spots within the
5891/// big object not to be overwritten by the updater.
5892///
5893/// \see DesignatedInitUpdateExpr
5894class NoInitExpr : public Expr {
5895public:
5897 : Expr(NoInitExprClass, ty, VK_PRValue, OK_Ordinary) {
5899 }
5900
5902 : Expr(NoInitExprClass, Empty) { }
5903
5904 static bool classof(const Stmt *T) {
5905 return T->getStmtClass() == NoInitExprClass;
5906 }
5907
5908 SourceLocation getBeginLoc() const LLVM_READONLY { return SourceLocation(); }
5909 SourceLocation getEndLoc() const LLVM_READONLY { return SourceLocation(); }
5910
5911 // Iterators
5918};
5919
5920// In cases like:
5921// struct Q { int a, b, c; };
5922// Q *getQ();
5923// void foo() {
5924// struct A { Q q; } a = { *getQ(), .q.b = 3 };
5925// }
5926//
5927// We will have an InitListExpr for a, with type A, and then a
5928// DesignatedInitUpdateExpr for "a.q" with type Q. The "base" for this DIUE
5929// is the call expression *getQ(); the "updater" for the DIUE is ".q.b = 3"
5930//
5932 // BaseAndUpdaterExprs[0] is the base expression;
5933 // BaseAndUpdaterExprs[1] is an InitListExpr overwriting part of the base.
5934 Stmt *BaseAndUpdaterExprs[2];
5935
5936public:
5938 Expr *baseExprs, SourceLocation rBraceLoc);
5939
5941 : Expr(DesignatedInitUpdateExprClass, Empty) { }
5942
5943 SourceLocation getBeginLoc() const LLVM_READONLY;
5944 SourceLocation getEndLoc() const LLVM_READONLY;
5945
5946 static bool classof(const Stmt *T) {
5947 return T->getStmtClass() == DesignatedInitUpdateExprClass;
5948 }
5949
5950 Expr *getBase() const { return cast<Expr>(BaseAndUpdaterExprs[0]); }
5951 void setBase(Expr *Base) { BaseAndUpdaterExprs[0] = Base; }
5952
5954 return cast<InitListExpr>(BaseAndUpdaterExprs[1]);
5955 }
5956 void setUpdater(Expr *Updater) { BaseAndUpdaterExprs[1] = Updater; }
5957
5958 // Iterators
5959 // children = the base and the updater
5961 return child_range(&BaseAndUpdaterExprs[0], &BaseAndUpdaterExprs[0] + 2);
5962 }
5964 return const_child_range(&BaseAndUpdaterExprs[0],
5965 &BaseAndUpdaterExprs[0] + 2);
5966 }
5967};
5968
5969/// Represents a loop initializing the elements of an array.
5970///
5971/// The need to initialize the elements of an array occurs in a number of
5972/// contexts:
5973///
5974/// * in the implicit copy/move constructor for a class with an array member
5975/// * when a lambda-expression captures an array by value
5976/// * when a decomposition declaration decomposes an array
5977///
5978/// There are two subexpressions: a common expression (the source array)
5979/// that is evaluated once up-front, and a per-element initializer that
5980/// runs once for each array element.
5981///
5982/// Within the per-element initializer, the common expression may be referenced
5983/// via an OpaqueValueExpr, and the current index may be obtained via an
5984/// ArrayInitIndexExpr.
5985class ArrayInitLoopExpr : public Expr {
5986 Stmt *SubExprs[2];
5987
5988 explicit ArrayInitLoopExpr(EmptyShell Empty)
5989 : Expr(ArrayInitLoopExprClass, Empty), SubExprs{} {}
5990
5991public:
5992 explicit ArrayInitLoopExpr(QualType T, Expr *CommonInit, Expr *ElementInit)
5993 : Expr(ArrayInitLoopExprClass, T, VK_PRValue, OK_Ordinary),
5994 SubExprs{CommonInit, ElementInit} {
5996 }
5997
5998 /// Get the common subexpression shared by all initializations (the source
5999 /// array).
6001 return cast<OpaqueValueExpr>(SubExprs[0]);
6002 }
6003
6004 /// Get the initializer to use for each array element.
6005 Expr *getSubExpr() const { return cast<Expr>(SubExprs[1]); }
6006
6007 llvm::APInt getArraySize() const {
6008 return cast<ConstantArrayType>(getType()->castAsArrayTypeUnsafe())
6009 ->getSize();
6010 }
6011
6012 static bool classof(const Stmt *S) {
6013 return S->getStmtClass() == ArrayInitLoopExprClass;
6014 }
6015
6016 SourceLocation getBeginLoc() const LLVM_READONLY {
6017 return getCommonExpr()->getBeginLoc();
6018 }
6019 SourceLocation getEndLoc() const LLVM_READONLY {
6020 return getCommonExpr()->getEndLoc();
6021 }
6022
6024 return child_range(SubExprs, SubExprs + 2);
6025 }
6027 return const_child_range(SubExprs, SubExprs + 2);
6028 }
6029
6030 friend class ASTReader;
6031 friend class ASTStmtReader;
6032 friend class ASTStmtWriter;
6033};
6034
6035/// Represents the index of the current element of an array being
6036/// initialized by an ArrayInitLoopExpr. This can only appear within the
6037/// subexpression of an ArrayInitLoopExpr.
6038class ArrayInitIndexExpr : public Expr {
6039 explicit ArrayInitIndexExpr(EmptyShell Empty)
6040 : Expr(ArrayInitIndexExprClass, Empty) {}
6041
6042public:
6044 : Expr(ArrayInitIndexExprClass, T, VK_PRValue, OK_Ordinary) {
6045 setDependence(ExprDependence::None);
6046 }
6047
6048 static bool classof(const Stmt *S) {
6049 return S->getStmtClass() == ArrayInitIndexExprClass;
6050 }
6051
6052 SourceLocation getBeginLoc() const LLVM_READONLY { return SourceLocation(); }
6053 SourceLocation getEndLoc() const LLVM_READONLY { return SourceLocation(); }
6054
6061
6062 friend class ASTReader;
6063 friend class ASTStmtReader;
6064};
6065
6066/// Represents an implicitly-generated value initialization of
6067/// an object of a given type.
6068///
6069/// Implicit value initializations occur within semantic initializer
6070/// list expressions (InitListExpr) as placeholders for subobject
6071/// initializations not explicitly specified by the user.
6072///
6073/// \see InitListExpr
6075public:
6077 : Expr(ImplicitValueInitExprClass, ty, VK_PRValue, OK_Ordinary) {
6079 }
6080
6081 /// Construct an empty implicit value initialization.
6083 : Expr(ImplicitValueInitExprClass, Empty) { }
6084
6085 static bool classof(const Stmt *T) {
6086 return T->getStmtClass() == ImplicitValueInitExprClass;
6087 }
6088
6089 SourceLocation getBeginLoc() const LLVM_READONLY { return SourceLocation(); }
6090 SourceLocation getEndLoc() const LLVM_READONLY { return SourceLocation(); }
6091
6092 // Iterators
6099};
6100
6101class ParenListExpr final
6102 : public Expr,
6103 private llvm::TrailingObjects<ParenListExpr, Stmt *> {
6104 friend class ASTStmtReader;
6105 friend TrailingObjects;
6106
6107 /// The location of the left and right parentheses.
6108 SourceLocation LParenLoc, RParenLoc;
6109
6110 /// Build a paren list.
6111 ParenListExpr(SourceLocation LParenLoc, ArrayRef<Expr *> Exprs,
6112 SourceLocation RParenLoc);
6113
6114 /// Build an empty paren list.
6115 ParenListExpr(EmptyShell Empty, unsigned NumExprs);
6116
6117public:
6118 /// Create a paren list.
6119 static ParenListExpr *Create(const ASTContext &Ctx, SourceLocation LParenLoc,
6120 ArrayRef<Expr *> Exprs,
6121 SourceLocation RParenLoc);
6122
6123 /// Create an empty paren list.
6124 static ParenListExpr *CreateEmpty(const ASTContext &Ctx, unsigned NumExprs);
6125
6126 /// Return the number of expressions in this paren list.
6127 unsigned getNumExprs() const { return ParenListExprBits.NumExprs; }
6128
6129 Expr *getExpr(unsigned Init) {
6130 assert(Init < getNumExprs() && "Initializer access out of range!");
6131 return getExprs()[Init];
6132 }
6133
6134 const Expr *getExpr(unsigned Init) const {
6135 return const_cast<ParenListExpr *>(this)->getExpr(Init);
6136 }
6137
6138 Expr **getExprs() { return reinterpret_cast<Expr **>(getTrailingObjects()); }
6139
6140 Expr *const *getExprs() const {
6141 return reinterpret_cast<Expr *const *>(getTrailingObjects());
6142 }
6143
6144 ArrayRef<Expr *> exprs() const { return {getExprs(), getNumExprs()}; }
6145
6146 SourceLocation getLParenLoc() const { return LParenLoc; }
6147 SourceLocation getRParenLoc() const { return RParenLoc; }
6150
6151 static bool classof(const Stmt *T) {
6152 return T->getStmtClass() == ParenListExprClass;
6153 }
6154
6155 // Iterators
6157 return child_range(getTrailingObjects(getNumExprs()));
6158 }
6160 return const_child_range(getTrailingObjects(getNumExprs()));
6161 }
6162};
6163
6164/// Represents a C11 generic selection.
6165///
6166/// A generic selection (C11 6.5.1.1) contains an unevaluated controlling
6167/// expression, followed by one or more generic associations. Each generic
6168/// association specifies a type name and an expression, or "default" and an
6169/// expression (in which case it is known as a default generic association).
6170/// The type and value of the generic selection are identical to those of its
6171/// result expression, which is defined as the expression in the generic
6172/// association with a type name that is compatible with the type of the
6173/// controlling expression, or the expression in the default generic association
6174/// if no types are compatible. For example:
6175///
6176/// @code
6177/// _Generic(X, double: 1, float: 2, default: 3)
6178/// @endcode
6179///
6180/// The above expression evaluates to 1 if 1.0 is substituted for X, 2 if 1.0f
6181/// or 3 if "hello".
6182///
6183/// As an extension, generic selections are allowed in C++, where the following
6184/// additional semantics apply:
6185///
6186/// Any generic selection whose controlling expression is type-dependent or
6187/// which names a dependent type in its association list is result-dependent,
6188/// which means that the choice of result expression is dependent.
6189/// Result-dependent generic associations are both type- and value-dependent.
6190///
6191/// We also allow an extended form in both C and C++ where the controlling
6192/// predicate for the selection expression is a type rather than an expression.
6193/// This type argument form does not perform any conversions for the
6194/// controlling type, which makes it suitable for use with qualified type
6195/// associations, which is not possible with the expression form.
6196class GenericSelectionExpr final
6197 : public Expr,
6198 private llvm::TrailingObjects<GenericSelectionExpr, Stmt *,
6199 TypeSourceInfo *> {
6200 friend class ASTStmtReader;
6201 friend class ASTStmtWriter;
6202 friend TrailingObjects;
6203
6204 /// The number of association expressions and the index of the result
6205 /// expression in the case where the generic selection expression is not
6206 /// result-dependent. The result index is equal to ResultDependentIndex
6207 /// if and only if the generic selection expression is result-dependent.
6208 unsigned NumAssocs : 15;
6209 unsigned ResultIndex : 15; // NB: ResultDependentIndex is tied to this width.
6210 LLVM_PREFERRED_TYPE(bool)
6211 unsigned IsExprPredicate : 1;
6212 enum : unsigned {
6213 ResultDependentIndex = 0x7FFF
6214 };
6215
6216 unsigned getIndexOfControllingExpression() const {
6217 // If controlled by an expression, the first offset into the Stmt *
6218 // trailing array is the controlling expression, the associated expressions
6219 // follow this.
6220 assert(isExprPredicate() && "Asking for the controlling expression of a "
6221 "selection expr predicated by a type");
6222 return 0;
6223 }
6224
6225 unsigned getIndexOfControllingType() const {
6226 // If controlled by a type, the first offset into the TypeSourceInfo *
6227 // trailing array is the controlling type, the associated types follow this.
6228 assert(isTypePredicate() && "Asking for the controlling type of a "
6229 "selection expr predicated by an expression");
6230 return 0;
6231 }
6232
6233 unsigned getIndexOfStartOfAssociatedExprs() const {
6234 // If the predicate is a type, then the associated expressions are the only
6235 // Stmt * in the trailing array, otherwise we need to offset past the
6236 // predicate expression.
6237 return (int)isExprPredicate();
6238 }
6239
6240 unsigned getIndexOfStartOfAssociatedTypes() const {
6241 // If the predicate is a type, then the associated types follow it in the
6242 // trailing array. Otherwise, the associated types are the only
6243 // TypeSourceInfo * in the trailing array.
6244 return (int)isTypePredicate();
6245 }
6246
6247
6248 /// The location of the "default" and of the right parenthesis.
6249 SourceLocation DefaultLoc, RParenLoc;
6250
6251 // GenericSelectionExpr is followed by several trailing objects.
6252 // They are (in order):
6253 //
6254 // * An array of either
6255 // - getNumAssocs() (if what controls the generic is not an expression), or
6256 // - getNumAssocs() + 1 (if what controls the generic is an expression)
6257 // Stmt * for the association expressions.
6258 // * An array of
6259 // - getNumAssocs() (if what controls the generic is not a type), or
6260 // - getNumAssocs() + 1 (if what controls the generic is a type)
6261 // TypeSourceInfo * for the association types.
6262 unsigned numTrailingObjects(OverloadToken<Stmt *>) const {
6263 // Add one to account for the controlling expression; the remainder
6264 // are the associated expressions.
6265 return getNumAssocs() + (int)isExprPredicate();
6266 }
6267
6268 unsigned numTrailingObjects(OverloadToken<TypeSourceInfo *>) const {
6269 // Add one to account for the controlling type predicate, the remainder
6270 // are the associated types.
6271 return getNumAssocs() + (int)isTypePredicate();
6272 }
6273
6274 template <bool Const> class AssociationIteratorTy;
6275 /// Bundle together an association expression and its TypeSourceInfo.
6276 /// The Const template parameter is for the const and non-const versions
6277 /// of AssociationTy.
6278 template <bool Const> class AssociationTy {
6279 friend class GenericSelectionExpr;
6280 template <bool OtherConst> friend class AssociationIteratorTy;
6281 using ExprPtrTy = std::conditional_t<Const, const Expr *, Expr *>;
6282 using TSIPtrTy =
6283 std::conditional_t<Const, const TypeSourceInfo *, TypeSourceInfo *>;
6284 ExprPtrTy E;
6285 TSIPtrTy TSI;
6286 bool Selected;
6287 AssociationTy(ExprPtrTy E, TSIPtrTy TSI, bool Selected)
6288 : E(E), TSI(TSI), Selected(Selected) {}
6289
6290 public:
6291 ExprPtrTy getAssociationExpr() const { return E; }
6292 TSIPtrTy getTypeSourceInfo() const { return TSI; }
6293 QualType getType() const { return TSI ? TSI->getType() : QualType(); }
6294 bool isSelected() const { return Selected; }
6295 AssociationTy *operator->() { return this; }
6296 const AssociationTy *operator->() const { return this; }
6297 }; // class AssociationTy
6298
6299 /// Iterator over const and non-const Association objects. The Association
6300 /// objects are created on the fly when the iterator is dereferenced.
6301 /// This abstract over how exactly the association expressions and the
6302 /// corresponding TypeSourceInfo * are stored.
6303 template <bool Const>
6304 class AssociationIteratorTy
6305 : public llvm::iterator_facade_base<
6306 AssociationIteratorTy<Const>, std::input_iterator_tag,
6307 AssociationTy<Const>, std::ptrdiff_t, AssociationTy<Const>,
6308 AssociationTy<Const>> {
6309 friend class GenericSelectionExpr;
6310 // FIXME: This iterator could conceptually be a random access iterator, and
6311 // it would be nice if we could strengthen the iterator category someday.
6312 // However this iterator does not satisfy two requirements of forward
6313 // iterators:
6314 // a) reference = T& or reference = const T&
6315 // b) If It1 and It2 are both dereferenceable, then It1 == It2 if and only
6316 // if *It1 and *It2 are bound to the same objects.
6317 // An alternative design approach was discussed during review;
6318 // store an Association object inside the iterator, and return a reference
6319 // to it when dereferenced. This idea was discarded because of nasty
6320 // lifetime issues:
6321 // AssociationIterator It = ...;
6322 // const Association &Assoc = *It++; // Oops, Assoc is dangling.
6323 using BaseTy = typename AssociationIteratorTy::iterator_facade_base;
6324 using StmtPtrPtrTy =
6325 std::conditional_t<Const, const Stmt *const *, Stmt **>;
6326 using TSIPtrPtrTy = std::conditional_t<Const, const TypeSourceInfo *const *,
6327 TypeSourceInfo **>;
6328 StmtPtrPtrTy E = nullptr;
6329 TSIPtrPtrTy TSI; // Kept in sync with E.
6330 unsigned Offset = 0, SelectedOffset = 0;
6331 AssociationIteratorTy(StmtPtrPtrTy E, TSIPtrPtrTy TSI, unsigned Offset,
6332 unsigned SelectedOffset)
6333 : E(E), TSI(TSI), Offset(Offset), SelectedOffset(SelectedOffset) {}
6334
6335 public:
6336 AssociationIteratorTy() : E(nullptr), TSI(nullptr) {}
6337 typename BaseTy::reference operator*() const {
6338 return AssociationTy<Const>(cast<Expr>(*E), *TSI,
6339 Offset == SelectedOffset);
6340 }
6341 typename BaseTy::pointer operator->() const { return **this; }
6342 using BaseTy::operator++;
6343 AssociationIteratorTy &operator++() {
6344 ++E;
6345 ++TSI;
6346 ++Offset;
6347 return *this;
6348 }
6349 bool operator==(AssociationIteratorTy Other) const { return E == Other.E; }
6350 }; // class AssociationIterator
6351
6352 /// Build a non-result-dependent generic selection expression accepting an
6353 /// expression predicate.
6354 GenericSelectionExpr(const ASTContext &Context, SourceLocation GenericLoc,
6355 Expr *ControllingExpr,
6356 ArrayRef<TypeSourceInfo *> AssocTypes,
6357 ArrayRef<Expr *> AssocExprs, SourceLocation DefaultLoc,
6358 SourceLocation RParenLoc,
6359 bool ContainsUnexpandedParameterPack,
6360 unsigned ResultIndex);
6361
6362 /// Build a result-dependent generic selection expression accepting an
6363 /// expression predicate.
6364 GenericSelectionExpr(const ASTContext &Context, SourceLocation GenericLoc,
6365 Expr *ControllingExpr,
6366 ArrayRef<TypeSourceInfo *> AssocTypes,
6367 ArrayRef<Expr *> AssocExprs, SourceLocation DefaultLoc,
6368 SourceLocation RParenLoc,
6369 bool ContainsUnexpandedParameterPack);
6370
6371 /// Build a non-result-dependent generic selection expression accepting a
6372 /// type predicate.
6373 GenericSelectionExpr(const ASTContext &Context, SourceLocation GenericLoc,
6374 TypeSourceInfo *ControllingType,
6375 ArrayRef<TypeSourceInfo *> AssocTypes,
6376 ArrayRef<Expr *> AssocExprs, SourceLocation DefaultLoc,
6377 SourceLocation RParenLoc,
6378 bool ContainsUnexpandedParameterPack,
6379 unsigned ResultIndex);
6380
6381 /// Build a result-dependent generic selection expression accepting a type
6382 /// predicate.
6383 GenericSelectionExpr(const ASTContext &Context, SourceLocation GenericLoc,
6384 TypeSourceInfo *ControllingType,
6385 ArrayRef<TypeSourceInfo *> AssocTypes,
6386 ArrayRef<Expr *> AssocExprs, SourceLocation DefaultLoc,
6387 SourceLocation RParenLoc,
6388 bool ContainsUnexpandedParameterPack);
6389
6390 /// Build an empty generic selection expression for deserialization.
6391 explicit GenericSelectionExpr(EmptyShell Empty, unsigned NumAssocs);
6392
6393public:
6394 /// Create a non-result-dependent generic selection expression accepting an
6395 /// expression predicate.
6396 static GenericSelectionExpr *
6397 Create(const ASTContext &Context, SourceLocation GenericLoc,
6398 Expr *ControllingExpr, ArrayRef<TypeSourceInfo *> AssocTypes,
6399 ArrayRef<Expr *> AssocExprs, SourceLocation DefaultLoc,
6400 SourceLocation RParenLoc, bool ContainsUnexpandedParameterPack,
6401 unsigned ResultIndex);
6402
6403 /// Create a result-dependent generic selection expression accepting an
6404 /// expression predicate.
6405 static GenericSelectionExpr *
6406 Create(const ASTContext &Context, SourceLocation GenericLoc,
6407 Expr *ControllingExpr, ArrayRef<TypeSourceInfo *> AssocTypes,
6408 ArrayRef<Expr *> AssocExprs, SourceLocation DefaultLoc,
6409 SourceLocation RParenLoc, bool ContainsUnexpandedParameterPack);
6410
6411 /// Create a non-result-dependent generic selection expression accepting a
6412 /// type predicate.
6413 static GenericSelectionExpr *
6414 Create(const ASTContext &Context, SourceLocation GenericLoc,
6415 TypeSourceInfo *ControllingType, ArrayRef<TypeSourceInfo *> AssocTypes,
6416 ArrayRef<Expr *> AssocExprs, SourceLocation DefaultLoc,
6417 SourceLocation RParenLoc, bool ContainsUnexpandedParameterPack,
6418 unsigned ResultIndex);
6419
6420 /// Create a result-dependent generic selection expression accepting a type
6421 /// predicate
6422 static GenericSelectionExpr *
6423 Create(const ASTContext &Context, SourceLocation GenericLoc,
6424 TypeSourceInfo *ControllingType, ArrayRef<TypeSourceInfo *> AssocTypes,
6425 ArrayRef<Expr *> AssocExprs, SourceLocation DefaultLoc,
6426 SourceLocation RParenLoc, bool ContainsUnexpandedParameterPack);
6427
6428 /// Create an empty generic selection expression for deserialization.
6429 static GenericSelectionExpr *CreateEmpty(const ASTContext &Context,
6430 unsigned NumAssocs);
6431
6432 using Association = AssociationTy<false>;
6433 using ConstAssociation = AssociationTy<true>;
6434 using AssociationIterator = AssociationIteratorTy<false>;
6435 using ConstAssociationIterator = AssociationIteratorTy<true>;
6436 using association_range = llvm::iterator_range<AssociationIterator>;
6438 llvm::iterator_range<ConstAssociationIterator>;
6439
6440 /// The number of association expressions.
6441 unsigned getNumAssocs() const { return NumAssocs; }
6442
6443 /// The zero-based index of the result expression's generic association in
6444 /// the generic selection's association list. Defined only if the
6445 /// generic selection is not result-dependent.
6446 unsigned getResultIndex() const {
6447 assert(!isResultDependent() &&
6448 "Generic selection is result-dependent but getResultIndex called!");
6449 return ResultIndex;
6450 }
6451
6452 /// Whether this generic selection is result-dependent.
6453 bool isResultDependent() const { return ResultIndex == ResultDependentIndex; }
6454
6455 /// Whether this generic selection uses an expression as its controlling
6456 /// argument.
6457 bool isExprPredicate() const { return IsExprPredicate; }
6458 /// Whether this generic selection uses a type as its controlling argument.
6459 bool isTypePredicate() const { return !IsExprPredicate; }
6460
6461 /// Return the controlling expression of this generic selection expression.
6462 /// Only valid to call if the selection expression used an expression as its
6463 /// controlling argument.
6465 return cast<Expr>(
6466 getTrailingObjects<Stmt *>()[getIndexOfControllingExpression()]);
6467 }
6468 const Expr *getControllingExpr() const {
6469 return cast<Expr>(
6470 getTrailingObjects<Stmt *>()[getIndexOfControllingExpression()]);
6471 }
6472
6473 /// Return the controlling type of this generic selection expression. Only
6474 /// valid to call if the selection expression used a type as its controlling
6475 /// argument.
6477 return getTrailingObjects<TypeSourceInfo *>()[getIndexOfControllingType()];
6478 }
6480 return getTrailingObjects<TypeSourceInfo *>()[getIndexOfControllingType()];
6481 }
6482
6483 /// Return the result expression of this controlling expression. Defined if
6484 /// and only if the generic selection expression is not result-dependent.
6486 return cast<Expr>(
6487 getTrailingObjects<Stmt *>()[getIndexOfStartOfAssociatedExprs() +
6488 getResultIndex()]);
6489 }
6490 const Expr *getResultExpr() const {
6491 return cast<Expr>(
6492 getTrailingObjects<Stmt *>()[getIndexOfStartOfAssociatedExprs() +
6493 getResultIndex()]);
6494 }
6495
6497 return {reinterpret_cast<Expr *const *>(getTrailingObjects<Stmt *>() +
6498 getIndexOfStartOfAssociatedExprs()),
6499 NumAssocs};
6500 }
6502 return {getTrailingObjects<TypeSourceInfo *>() +
6503 getIndexOfStartOfAssociatedTypes(),
6504 NumAssocs};
6505 }
6506
6507 /// Return the Ith association expression with its TypeSourceInfo,
6508 /// bundled together in GenericSelectionExpr::(Const)Association.
6510 assert(I < getNumAssocs() &&
6511 "Out-of-range index in GenericSelectionExpr::getAssociation!");
6512 return Association(
6513 cast<Expr>(
6514 getTrailingObjects<Stmt *>()[getIndexOfStartOfAssociatedExprs() +
6515 I]),
6516 getTrailingObjects<
6517 TypeSourceInfo *>()[getIndexOfStartOfAssociatedTypes() + I],
6518 !isResultDependent() && (getResultIndex() == I));
6519 }
6521 assert(I < getNumAssocs() &&
6522 "Out-of-range index in GenericSelectionExpr::getAssociation!");
6523 return ConstAssociation(
6524 cast<Expr>(
6525 getTrailingObjects<Stmt *>()[getIndexOfStartOfAssociatedExprs() +
6526 I]),
6527 getTrailingObjects<
6528 TypeSourceInfo *>()[getIndexOfStartOfAssociatedTypes() + I],
6529 !isResultDependent() && (getResultIndex() == I));
6530 }
6531
6533 AssociationIterator Begin(getTrailingObjects<Stmt *>() +
6534 getIndexOfStartOfAssociatedExprs(),
6535 getTrailingObjects<TypeSourceInfo *>() +
6536 getIndexOfStartOfAssociatedTypes(),
6537 /*Offset=*/0, ResultIndex);
6538 AssociationIterator End(Begin.E + NumAssocs, Begin.TSI + NumAssocs,
6539 /*Offset=*/NumAssocs, ResultIndex);
6540 return llvm::make_range(Begin, End);
6541 }
6542
6544 ConstAssociationIterator Begin(getTrailingObjects<Stmt *>() +
6545 getIndexOfStartOfAssociatedExprs(),
6546 getTrailingObjects<TypeSourceInfo *>() +
6547 getIndexOfStartOfAssociatedTypes(),
6548 /*Offset=*/0, ResultIndex);
6549 ConstAssociationIterator End(Begin.E + NumAssocs, Begin.TSI + NumAssocs,
6550 /*Offset=*/NumAssocs, ResultIndex);
6551 return llvm::make_range(Begin, End);
6552 }
6553
6555 return GenericSelectionExprBits.GenericLoc;
6556 }
6557 SourceLocation getDefaultLoc() const { return DefaultLoc; }
6558 SourceLocation getRParenLoc() const { return RParenLoc; }
6561
6562 static bool classof(const Stmt *T) {
6563 return T->getStmtClass() == GenericSelectionExprClass;
6564 }
6565
6567 return child_range(getTrailingObjects<Stmt *>(
6568 numTrailingObjects(OverloadToken<Stmt *>())));
6569 }
6571 return const_child_range(getTrailingObjects<Stmt *>(
6572 numTrailingObjects(OverloadToken<Stmt *>())));
6573 }
6574};
6575
6576//===----------------------------------------------------------------------===//
6577// Clang Extensions
6578//===----------------------------------------------------------------------===//
6579
6580template <class Derived> class ElementAccessExprBase : public Expr {
6581protected:
6585
6588 ExprObjectKind OK)
6589 : Expr(SC, Ty, VK, OK), Base(Base), Accessor(&Accessor),
6590 AccessorLoc(Loc) {
6591 setDependence(computeDependence(static_cast<Derived *>(this)));
6592 }
6593
6596
6597public:
6598 const Expr *getBase() const { return cast<Expr>(Base); }
6599 Expr *getBase() { return cast<Expr>(Base); }
6600 void setBase(Expr *E) { Base = E; }
6601
6604
6607
6608 SourceLocation getBeginLoc() const LLVM_READONLY {
6609 return getBase()->getBeginLoc();
6610 }
6611 SourceLocation getEndLoc() const LLVM_READONLY { return AccessorLoc; }
6612
6615 return const_child_range(&Base, &Base + 1);
6616 }
6617};
6618
6619/// ExtVectorElementExpr - This represents access to specific elements of a
6620/// vector, and may occur on the left hand side or right hand side. For example
6621/// the following is legal: "V.xy = V.zw" if V is a 4 element extended vector.
6622///
6623/// Note that the base may have either vector or pointer to vector type, just
6624/// like a struct field reference.
6625///
6627 : public ElementAccessExprBase<ExtVectorElementExpr> {
6628public:
6634
6635 /// Build an empty vector element expression.
6637 : ElementAccessExprBase(ExtVectorElementExprClass, Empty) {}
6638
6639 /// getNumElements - Get the number of components being selected.
6640 unsigned getNumElements() const;
6641
6642 /// containsDuplicateElements - Return true if any element access is
6643 /// repeated.
6644 bool containsDuplicateElements() const;
6645
6646 /// getEncodedElementAccess - Encode the elements accessed into an llvm
6647 /// aggregate Constant of ConstantInt(s).
6649
6650 /// isArrow - Return true if the base expression is a pointer to vector,
6651 /// return false if the base expression is a vector.
6652 bool isArrow() const;
6653
6654 static bool classof(const Stmt *T) {
6655 return T->getStmtClass() == ExtVectorElementExprClass;
6656 }
6657};
6658
6659class MatrixElementExpr : public ElementAccessExprBase<MatrixElementExpr> {
6660public:
6664 MatrixElementExprClass, Ty, VK, Base, Accessor, Loc,
6665 OK_Ordinary /*TODO: Should we add a new OK_MatrixComponent?*/) {}
6666
6667 /// Build an empty matrix element expression.
6669 : ElementAccessExprBase(MatrixElementExprClass, Empty) {}
6670
6671 /// getNumElements - Get the number of components being selected.
6672 unsigned getNumElements() const;
6673
6674 /// containsDuplicateElements - Return true if any element access is
6675 /// repeated.
6676 bool containsDuplicateElements() const;
6677
6678 /// getEncodedElementAccess - Encode the elements accessed into an llvm
6679 /// aggregate Constant of ConstantInt(s).
6681
6682 static bool classof(const Stmt *T) {
6683 return T->getStmtClass() == MatrixElementExprClass;
6684 }
6685};
6686
6687/// BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
6688/// ^{ statement-body } or ^(int arg1, float arg2){ statement-body }
6689class BlockExpr : public Expr {
6690protected:
6692public:
6693 BlockExpr(BlockDecl *BD, QualType ty, bool ContainsUnexpandedParameterPack)
6694 : Expr(BlockExprClass, ty, VK_PRValue, OK_Ordinary), TheBlock(BD) {
6695 setDependence(computeDependence(this, ContainsUnexpandedParameterPack));
6696 }
6697
6698 /// Build an empty block expression.
6699 explicit BlockExpr(EmptyShell Empty) : Expr(BlockExprClass, Empty) { }
6700
6701 const BlockDecl *getBlockDecl() const { return TheBlock; }
6703 void setBlockDecl(BlockDecl *BD) { TheBlock = BD; }
6704
6705 // Convenience functions for probing the underlying BlockDecl.
6707 const Stmt *getBody() const;
6708 Stmt *getBody();
6709
6710 SourceLocation getBeginLoc() const LLVM_READONLY {
6711 return getCaretLocation();
6712 }
6713 SourceLocation getEndLoc() const LLVM_READONLY {
6714 return getBody()->getEndLoc();
6715 }
6716
6717 /// getFunctionType - Return the underlying function type for this block.
6718 const FunctionProtoType *getFunctionType() const;
6719
6720 static bool classof(const Stmt *T) {
6721 return T->getStmtClass() == BlockExprClass;
6722 }
6723
6724 // Iterators
6731};
6732
6733/// Copy initialization expr of a __block variable and a boolean flag that
6734/// indicates whether the expression can throw.
6736 BlockVarCopyInit() = default;
6738 : ExprAndFlag(CopyExpr, CanThrow) {}
6739 void setExprAndFlag(Expr *CopyExpr, bool CanThrow) {
6740 ExprAndFlag.setPointerAndInt(CopyExpr, CanThrow);
6741 }
6742 Expr *getCopyExpr() const { return ExprAndFlag.getPointer(); }
6743 bool canThrow() const { return ExprAndFlag.getInt(); }
6744 llvm::PointerIntPair<Expr *, 1, bool> ExprAndFlag;
6745};
6746
6747/// AsTypeExpr - Clang builtin function __builtin_astype [OpenCL 6.2.4.2]
6748/// This AST node provides support for reinterpreting a type to another
6749/// type of the same size.
6750class AsTypeExpr : public Expr {
6751private:
6752 Stmt *SrcExpr;
6753 SourceLocation BuiltinLoc, RParenLoc;
6754
6755 friend class ASTReader;
6756 friend class ASTStmtReader;
6757 explicit AsTypeExpr(EmptyShell Empty) : Expr(AsTypeExprClass, Empty) {}
6758
6759public:
6761 ExprObjectKind OK, SourceLocation BuiltinLoc,
6762 SourceLocation RParenLoc)
6763 : Expr(AsTypeExprClass, DstType, VK, OK), SrcExpr(SrcExpr),
6764 BuiltinLoc(BuiltinLoc), RParenLoc(RParenLoc) {
6766 }
6767
6768 /// getSrcExpr - Return the Expr to be converted.
6769 Expr *getSrcExpr() const { return cast<Expr>(SrcExpr); }
6770
6771 /// getBuiltinLoc - Return the location of the __builtin_astype token.
6772 SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
6773
6774 /// getRParenLoc - Return the location of final right parenthesis.
6775 SourceLocation getRParenLoc() const { return RParenLoc; }
6776
6777 SourceLocation getBeginLoc() const LLVM_READONLY { return BuiltinLoc; }
6778 SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
6779
6780 static bool classof(const Stmt *T) {
6781 return T->getStmtClass() == AsTypeExprClass;
6782 }
6783
6784 // Iterators
6785 child_range children() { return child_range(&SrcExpr, &SrcExpr+1); }
6787 return const_child_range(&SrcExpr, &SrcExpr + 1);
6788 }
6789};
6790
6791/// PseudoObjectExpr - An expression which accesses a pseudo-object
6792/// l-value. A pseudo-object is an abstract object, accesses to which
6793/// are translated to calls. The pseudo-object expression has a
6794/// syntactic form, which shows how the expression was actually
6795/// written in the source code, and a semantic form, which is a series
6796/// of expressions to be executed in order which detail how the
6797/// operation is actually evaluated. Optionally, one of the semantic
6798/// forms may also provide a result value for the expression.
6799///
6800/// If any of the semantic-form expressions is an OpaqueValueExpr,
6801/// that OVE is required to have a source expression, and it is bound
6802/// to the result of that source expression. Such OVEs may appear
6803/// only in subsequent semantic-form expressions and as
6804/// sub-expressions of the syntactic form.
6805///
6806/// PseudoObjectExpr should be used only when an operation can be
6807/// usefully described in terms of fairly simple rewrite rules on
6808/// objects and functions that are meant to be used by end-developers.
6809/// For example, under the Itanium ABI, dynamic casts are implemented
6810/// as a call to a runtime function called __dynamic_cast; using this
6811/// class to describe that would be inappropriate because that call is
6812/// not really part of the user-visible semantics, and instead the
6813/// cast is properly reflected in the AST and IR-generation has been
6814/// taught to generate the call as necessary. In contrast, an
6815/// Objective-C property access is semantically defined to be
6816/// equivalent to a particular message send, and this is very much
6817/// part of the user model. The name of this class encourages this
6818/// modelling design.
6819class PseudoObjectExpr final
6820 : public Expr,
6821 private llvm::TrailingObjects<PseudoObjectExpr, Expr *> {
6822 // PseudoObjectExprBits.NumSubExprs - The number of sub-expressions.
6823 // Always at least two, because the first sub-expression is the
6824 // syntactic form.
6825
6826 // PseudoObjectExprBits.ResultIndex - The index of the
6827 // sub-expression holding the result. 0 means the result is void,
6828 // which is unambiguous because it's the index of the syntactic
6829 // form. Note that this is therefore 1 higher than the value passed
6830 // in to Create, which is an index within the semantic forms.
6831 // Note also that ASTStmtWriter assumes this encoding.
6832
6833 PseudoObjectExpr(QualType type, ExprValueKind VK,
6834 Expr *syntactic, ArrayRef<Expr*> semantic,
6835 unsigned resultIndex);
6836
6837 PseudoObjectExpr(EmptyShell shell, unsigned numSemanticExprs);
6838
6839 unsigned getNumSubExprs() const {
6840 return PseudoObjectExprBits.NumSubExprs;
6841 }
6842
6843public:
6844 /// NoResult - A value for the result index indicating that there is
6845 /// no semantic result.
6846 enum : unsigned { NoResult = ~0U };
6847
6848 static PseudoObjectExpr *Create(const ASTContext &Context, Expr *syntactic,
6849 ArrayRef<Expr*> semantic,
6850 unsigned resultIndex);
6851
6852 static PseudoObjectExpr *Create(const ASTContext &Context, EmptyShell shell,
6853 unsigned numSemanticExprs);
6854
6855 /// Return the syntactic form of this expression, i.e. the
6856 /// expression it actually looks like. Likely to be expressed in
6857 /// terms of OpaqueValueExprs bound in the semantic form.
6858 Expr *getSyntacticForm() { return getTrailingObjects()[0]; }
6859 const Expr *getSyntacticForm() const { return getTrailingObjects()[0]; }
6860
6861 /// Return the index of the result-bearing expression into the semantics
6862 /// expressions, or PseudoObjectExpr::NoResult if there is none.
6863 unsigned getResultExprIndex() const {
6864 if (PseudoObjectExprBits.ResultIndex == 0) return NoResult;
6865 return PseudoObjectExprBits.ResultIndex - 1;
6866 }
6867
6868 /// Return the result-bearing expression, or null if there is none.
6870 if (PseudoObjectExprBits.ResultIndex == 0)
6871 return nullptr;
6872 return getTrailingObjects()[PseudoObjectExprBits.ResultIndex];
6873 }
6874 const Expr *getResultExpr() const {
6875 return const_cast<PseudoObjectExpr*>(this)->getResultExpr();
6876 }
6877
6878 unsigned getNumSemanticExprs() const { return getNumSubExprs() - 1; }
6879
6880 typedef Expr * const *semantics_iterator;
6881 typedef const Expr * const *const_semantics_iterator;
6882 semantics_iterator semantics_begin() { return getTrailingObjects() + 1; }
6884 return getTrailingObjects() + 1;
6885 }
6887 return getTrailingObjects() + getNumSubExprs();
6888 }
6890 return getTrailingObjects() + getNumSubExprs();
6891 }
6892
6894 return getTrailingObjects(getNumSubExprs()).drop_front();
6895 }
6897 return getTrailingObjects(getNumSubExprs()).drop_front();
6898 }
6899
6901 return getTrailingObjects(getNumSubExprs())[index + 1];
6902 }
6903 const Expr *getSemanticExpr(unsigned index) const {
6904 return const_cast<PseudoObjectExpr*>(this)->getSemanticExpr(index);
6905 }
6906
6907 SourceLocation getExprLoc() const LLVM_READONLY {
6908 return getSyntacticForm()->getExprLoc();
6909 }
6910
6911 SourceLocation getBeginLoc() const LLVM_READONLY {
6912 return getSyntacticForm()->getBeginLoc();
6913 }
6914 SourceLocation getEndLoc() const LLVM_READONLY {
6915 return getSyntacticForm()->getEndLoc();
6916 }
6917
6919 const_child_range CCR =
6920 const_cast<const PseudoObjectExpr *>(this)->children();
6921 return child_range(cast_away_const(CCR.begin()),
6922 cast_away_const(CCR.end()));
6923 }
6925 Stmt *const *cs = const_cast<Stmt *const *>(
6926 reinterpret_cast<const Stmt *const *>(getTrailingObjects()));
6927 return const_child_range(cs, cs + getNumSubExprs());
6928 }
6929
6930 static bool classof(const Stmt *T) {
6931 return T->getStmtClass() == PseudoObjectExprClass;
6932 }
6933
6935 friend class ASTStmtReader;
6936};
6937
6938/// AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*,
6939/// __atomic_load, __atomic_store, and __atomic_compare_exchange_*, for the
6940/// similarly-named C++11 instructions, and __c11 variants for <stdatomic.h>,
6941/// and corresponding __opencl_atomic_* for OpenCL 2.0.
6942/// All of these instructions take one primary pointer, at least one memory
6943/// order. The instructions for which getScopeModel returns non-null value
6944/// take one sync scope.
6945class AtomicExpr : public Expr {
6946public:
6948#define ATOMIC_BUILTIN(ID, TYPE, ATTRS) AO ## ID,
6949#include "clang/Basic/Builtins.inc"
6950 // Avoid trailing comma
6952 };
6953
6954private:
6955 /// Location of sub-expressions.
6956 /// The location of Scope sub-expression is NumSubExprs - 1, which is
6957 /// not fixed, therefore is not defined in enum.
6958 enum { PTR, ORDER, VAL1, ORDER_FAIL, VAL2, WEAK, END_EXPR };
6959 Stmt *SubExprs[END_EXPR + 1];
6960 unsigned NumSubExprs;
6961 SourceLocation BuiltinLoc, RParenLoc;
6962 AtomicOp Op;
6963
6964 friend class ASTStmtReader;
6965public:
6967 AtomicOp op, SourceLocation RP);
6968
6969 /// Determine the number of arguments the specified atomic builtin
6970 /// should have.
6971 static unsigned getNumSubExprs(AtomicOp Op);
6972
6973 /// Build an empty AtomicExpr.
6974 explicit AtomicExpr(EmptyShell Empty) : Expr(AtomicExprClass, Empty) { }
6975
6976 Expr *getPtr() const {
6977 return cast<Expr>(SubExprs[PTR]);
6978 }
6979 Expr *getOrder() const {
6980 return cast<Expr>(SubExprs[ORDER]);
6981 }
6982 Expr *getScope() const {
6983 assert(getScopeModel() && "No scope");
6984 return cast<Expr>(SubExprs[NumSubExprs - 1]);
6985 }
6986 Expr *getVal1() const {
6987 if (Op == AO__c11_atomic_init || Op == AO__opencl_atomic_init)
6988 return cast<Expr>(SubExprs[ORDER]);
6989 assert(NumSubExprs > VAL1);
6990 return cast<Expr>(SubExprs[VAL1]);
6991 }
6993 assert(NumSubExprs > ORDER_FAIL);
6994 return cast<Expr>(SubExprs[ORDER_FAIL]);
6995 }
6996 Expr *getVal2() const {
6997 if (Op == AO__atomic_exchange || Op == AO__scoped_atomic_exchange)
6998 return cast<Expr>(SubExprs[ORDER_FAIL]);
6999 assert(NumSubExprs > VAL2);
7000 return cast<Expr>(SubExprs[VAL2]);
7001 }
7002 Expr *getWeak() const {
7003 assert(NumSubExprs > WEAK);
7004 return cast<Expr>(SubExprs[WEAK]);
7005 }
7006 QualType getValueType() const;
7007
7008 AtomicOp getOp() const { return Op; }
7009 StringRef getOpAsString() const {
7010 switch (Op) {
7011#define ATOMIC_BUILTIN(ID, TYPE, ATTRS) \
7012 case AO##ID: \
7013 return #ID;
7014#include "clang/Basic/Builtins.inc"
7015 }
7016 llvm_unreachable("not an atomic operator?");
7017 }
7018 unsigned getNumSubExprs() const { return NumSubExprs; }
7019
7020 Expr **getSubExprs() { return reinterpret_cast<Expr **>(SubExprs); }
7021 const Expr * const *getSubExprs() const {
7022 return reinterpret_cast<Expr * const *>(SubExprs);
7023 }
7024
7025 bool isVolatile() const {
7027 }
7028
7029 bool isCmpXChg() const {
7030 return getOp() == AO__c11_atomic_compare_exchange_strong ||
7031 getOp() == AO__c11_atomic_compare_exchange_weak ||
7032 getOp() == AO__hip_atomic_compare_exchange_strong ||
7033 getOp() == AO__opencl_atomic_compare_exchange_strong ||
7034 getOp() == AO__opencl_atomic_compare_exchange_weak ||
7035 getOp() == AO__hip_atomic_compare_exchange_weak ||
7036 getOp() == AO__atomic_compare_exchange ||
7037 getOp() == AO__atomic_compare_exchange_n ||
7038 getOp() == AO__scoped_atomic_compare_exchange ||
7039 getOp() == AO__scoped_atomic_compare_exchange_n;
7040 }
7041
7042 bool hasVal1Operand() const {
7043 switch (getOp()) {
7044 case AO__atomic_load_n:
7045 case AO__scoped_atomic_load_n:
7046 case AO__c11_atomic_load:
7047 case AO__opencl_atomic_load:
7048 case AO__hip_atomic_load:
7049 case AO__atomic_test_and_set:
7050 case AO__atomic_clear:
7051 return false;
7052 default:
7053 return true;
7054 }
7055 }
7056
7057 bool isOpenCL() const {
7058 return getOp() >= AO__opencl_atomic_compare_exchange_strong &&
7059 getOp() <= AO__opencl_atomic_store;
7060 }
7061
7062 bool isHIP() const {
7063 return Op >= AO__hip_atomic_compare_exchange_strong &&
7064 Op <= AO__hip_atomic_store;
7065 }
7066
7067 /// Return true if atomics operations targeting allocations in private memory
7068 /// are undefined.
7070 return isOpenCL() || isHIP();
7071 }
7072
7073 SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
7074 SourceLocation getRParenLoc() const { return RParenLoc; }
7075
7076 SourceLocation getBeginLoc() const LLVM_READONLY { return BuiltinLoc; }
7077 SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
7078
7079 static bool classof(const Stmt *T) {
7080 return T->getStmtClass() == AtomicExprClass;
7081 }
7082
7083 // Iterators
7085 return child_range(SubExprs, SubExprs+NumSubExprs);
7086 }
7088 return const_child_range(SubExprs, SubExprs + NumSubExprs);
7089 }
7090
7091 /// Get atomic scope model for the atomic op code.
7092 /// \return empty atomic scope model if the atomic op code does not have
7093 /// scope operand.
7094 static std::unique_ptr<AtomicScopeModel> getScopeModel(AtomicOp Op) {
7095 // FIXME: Allow grouping of builtins to be able to only check >= and <=
7096 if (Op >= AO__opencl_atomic_compare_exchange_strong &&
7097 Op <= AO__opencl_atomic_store && Op != AO__opencl_atomic_init)
7099 if (Op >= AO__hip_atomic_compare_exchange_strong &&
7100 Op <= AO__hip_atomic_store)
7102 if (Op >= AO__scoped_atomic_add_fetch && Op <= AO__scoped_atomic_xor_fetch)
7105 }
7106
7107 /// Get atomic scope model.
7108 /// \return empty atomic scope model if this atomic expression does not have
7109 /// scope operand.
7110 std::unique_ptr<AtomicScopeModel> getScopeModel() const {
7111 return getScopeModel(getOp());
7112 }
7113};
7114
7115/// This class represents BOTH the OpenMP Array Section and OpenACC 'subarray',
7116/// with a boolean differentiator.
7117/// OpenMP 5.0 [2.1.5, Array Sections].
7118/// To specify an array section in an OpenMP construct, array subscript
7119/// expressions are extended with the following syntax:
7120/// \code
7121/// [ lower-bound : length : stride ]
7122/// [ lower-bound : length : ]
7123/// [ lower-bound : length ]
7124/// [ lower-bound : : stride ]
7125/// [ lower-bound : : ]
7126/// [ lower-bound : ]
7127/// [ : length : stride ]
7128/// [ : length : ]
7129/// [ : length ]
7130/// [ : : stride ]
7131/// [ : : ]
7132/// [ : ]
7133/// \endcode
7134/// The array section must be a subset of the original array.
7135/// Array sections are allowed on multidimensional arrays. Base language array
7136/// subscript expressions can be used to specify length-one dimensions of
7137/// multidimensional array sections.
7138/// Each of the lower-bound, length, and stride expressions if specified must be
7139/// an integral type expressions of the base language. When evaluated
7140/// they represent a set of integer values as follows:
7141/// \code
7142/// { lower-bound, lower-bound + stride, lower-bound + 2 * stride,... ,
7143/// lower-bound + ((length - 1) * stride) }
7144/// \endcode
7145/// The lower-bound and length must evaluate to non-negative integers.
7146/// The stride must evaluate to a positive integer.
7147/// When the size of the array dimension is not known, the length must be
7148/// specified explicitly.
7149/// When the stride is absent it defaults to 1.
7150/// When the length is absent it defaults to ⌈(size − lower-bound)/stride⌉,
7151/// where size is the size of the array dimension. When the lower-bound is
7152/// absent it defaults to 0.
7153///
7154///
7155/// OpenACC 3.3 [2.7.1 Data Specification in Data Clauses]
7156/// In C and C++, a subarray is an array name followed by an extended array
7157/// range specification in brackets, with start and length, such as
7158///
7159/// AA[2:n]
7160///
7161/// If the lower bound is missing, zero is used. If the length is missing and
7162/// the array has known size, the size of the array is used; otherwise the
7163/// length is required. The subarray AA[2:n] means elements AA[2], AA[3], . . .
7164/// , AA[2+n-1]. In C and C++, a two dimensional array may be declared in at
7165/// least four ways:
7166///
7167/// -Statically-sized array: float AA[100][200];
7168/// -Pointer to statically sized rows: typedef float row[200]; row* BB;
7169/// -Statically-sized array of pointers: float* CC[200];
7170/// -Pointer to pointers: float** DD;
7171///
7172/// Each dimension may be statically sized, or a pointer to dynamically
7173/// allocated memory. Each of these may be included in a data clause using
7174/// subarray notation to specify a rectangular array:
7175///
7176/// -AA[2:n][0:200]
7177/// -BB[2:n][0:m]
7178/// -CC[2:n][0:m]
7179/// -DD[2:n][0:m]
7180///
7181/// Multidimensional rectangular subarrays in C and C++ may be specified for any
7182/// array with any combination of statically-sized or dynamically-allocated
7183/// dimensions. For statically sized dimensions, all dimensions except the first
7184/// must specify the whole extent to preserve the contiguous data restriction,
7185/// discussed below. For dynamically allocated dimensions, the implementation
7186/// will allocate pointers in device memory corresponding to the pointers in
7187/// local memory and will fill in those pointers as appropriate.
7188///
7189/// In Fortran, a subarray is an array name followed by a comma-separated list
7190/// of range specifications in parentheses, with lower and upper bound
7191/// subscripts, such as
7192///
7193/// arr(1:high,low:100)
7194///
7195/// If either the lower or upper bounds are missing, the declared or allocated
7196/// bounds of the array, if known, are used. All dimensions except the last must
7197/// specify the whole extent, to preserve the contiguous data restriction,
7198/// discussed below.
7199///
7200/// Restrictions
7201///
7202/// -In Fortran, the upper bound for the last dimension of an assumed-size dummy
7203/// array must be specified.
7204///
7205/// -In C and C++, the length for dynamically allocated dimensions of an array
7206/// must be explicitly specified.
7207///
7208/// -In C and C++, modifying pointers in pointer arrays during the data
7209/// lifetime, either on the host or on the device, may result in undefined
7210/// behavior.
7211///
7212/// -If a subarray appears in a data clause, the implementation may choose to
7213/// allocate memory for only that subarray on the accelerator.
7214///
7215/// -In Fortran, array pointers may appear, but pointer association is not
7216/// preserved in device memory.
7217///
7218/// -Any array or subarray in a data clause, including Fortran array pointers,
7219/// must be a contiguous section of memory, except for dynamic multidimensional
7220/// C arrays.
7221///
7222/// -In C and C++, if a variable or array of composite type appears, all the
7223/// data members of the struct or class are allocated and copied, as
7224/// appropriate. If a composite member is a pointer type, the data addressed by
7225/// that pointer are not implicitly copied.
7226///
7227/// -In Fortran, if a variable or array of composite type appears, all the
7228/// members of that derived type are allocated and copied, as appropriate. If
7229/// any member has the allocatable or pointer attribute, the data accessed
7230/// through that member are not copied.
7231///
7232/// -If an expression is used in a subscript or subarray expression in a clause
7233/// on a data construct, the same value is used when copying data at the end of
7234/// the data region, even if the values of variables in the expression change
7235/// during the data region.
7236class ArraySectionExpr : public Expr {
7237 friend class ASTStmtReader;
7238 friend class ASTStmtWriter;
7239
7240public:
7242
7243private:
7244 enum {
7245 BASE,
7246 LOWER_BOUND,
7247 LENGTH,
7248 STRIDE,
7249 END_EXPR,
7250 OPENACC_END_EXPR = STRIDE
7251 };
7252
7253 ArraySectionType ASType = OMPArraySection;
7254 Stmt *SubExprs[END_EXPR] = {nullptr};
7255 SourceLocation ColonLocFirst;
7256 SourceLocation ColonLocSecond;
7257 SourceLocation RBracketLoc;
7258
7259public:
7260 // Constructor for OMP array sections, which include a 'stride'.
7261 ArraySectionExpr(Expr *Base, Expr *LowerBound, Expr *Length, Expr *Stride,
7263 SourceLocation ColonLocFirst, SourceLocation ColonLocSecond,
7264 SourceLocation RBracketLoc)
7265 : Expr(ArraySectionExprClass, Type, VK, OK), ASType(OMPArraySection),
7266 ColonLocFirst(ColonLocFirst), ColonLocSecond(ColonLocSecond),
7267 RBracketLoc(RBracketLoc) {
7268 setBase(Base);
7269 setLowerBound(LowerBound);
7270 setLength(Length);
7271 setStride(Stride);
7273 }
7274
7275 // Constructor for OpenACC sub-arrays, which do not permit a 'stride'.
7278 SourceLocation RBracketLoc)
7279 : Expr(ArraySectionExprClass, Type, VK, OK), ASType(OpenACCArraySection),
7280 ColonLocFirst(ColonLoc), RBracketLoc(RBracketLoc) {
7281 setBase(Base);
7282 setLowerBound(LowerBound);
7283 setLength(Length);
7285 }
7286
7287 /// Create an empty array section expression.
7289 : Expr(ArraySectionExprClass, Shell) {}
7290
7291 /// Return original type of the base expression for array section.
7292 static QualType getBaseOriginalType(const Expr *Base);
7293
7294 /// Return the effective 'element' type of this array section. As the array
7295 /// section itself returns a collection of elements (closer to its `getBase`
7296 /// type), this is only useful for figuring out the effective type of this if
7297 /// it were a normal Array subscript expr.
7298 QualType getElementType() const;
7299
7300 /// Returns the effective 'type' of the base of this array section. This
7301 /// should be the array/pointer type that this operates on. Just
7302 /// getBase->getType isn't sufficient, since it doesn't look through existing
7303 /// Array sections to figure out the actual 'base' of this.
7304 QualType getBaseType() const;
7305
7306 static bool classof(const Stmt *T) {
7307 return T->getStmtClass() == ArraySectionExprClass;
7308 }
7309
7310 bool isOMPArraySection() const { return ASType == OMPArraySection; }
7311 bool isOpenACCArraySection() const { return ASType == OpenACCArraySection; }
7312
7313 /// Get base of the array section.
7314 Expr *getBase() { return cast<Expr>(SubExprs[BASE]); }
7315 const Expr *getBase() const { return cast<Expr>(SubExprs[BASE]); }
7316
7317 /// Get lower bound of array section.
7318 Expr *getLowerBound() { return cast_or_null<Expr>(SubExprs[LOWER_BOUND]); }
7319 const Expr *getLowerBound() const {
7320 return cast_or_null<Expr>(SubExprs[LOWER_BOUND]);
7321 }
7322
7323 /// Get length of array section.
7324 Expr *getLength() { return cast_or_null<Expr>(SubExprs[LENGTH]); }
7325 const Expr *getLength() const { return cast_or_null<Expr>(SubExprs[LENGTH]); }
7326
7327 /// Get stride of array section.
7329 assert(ASType != OpenACCArraySection &&
7330 "Stride not valid in OpenACC subarrays");
7331 return cast_or_null<Expr>(SubExprs[STRIDE]);
7332 }
7333
7334 const Expr *getStride() const {
7335 assert(ASType != OpenACCArraySection &&
7336 "Stride not valid in OpenACC subarrays");
7337 return cast_or_null<Expr>(SubExprs[STRIDE]);
7338 }
7339
7340 SourceLocation getBeginLoc() const LLVM_READONLY {
7341 return getBase()->getBeginLoc();
7342 }
7343 SourceLocation getEndLoc() const LLVM_READONLY { return RBracketLoc; }
7344
7345 SourceLocation getColonLocFirst() const { return ColonLocFirst; }
7347 assert(ASType != OpenACCArraySection &&
7348 "second colon for stride not valid in OpenACC subarrays");
7349 return ColonLocSecond;
7350 }
7351 SourceLocation getRBracketLoc() const { return RBracketLoc; }
7352
7353 SourceLocation getExprLoc() const LLVM_READONLY {
7354 return getBase()->getExprLoc();
7355 }
7356
7358 return child_range(
7359 &SubExprs[BASE],
7360 &SubExprs[ASType == OMPArraySection ? END_EXPR : OPENACC_END_EXPR]);
7361 }
7362
7364 return const_child_range(
7365 &SubExprs[BASE],
7366 &SubExprs[ASType == OMPArraySection ? END_EXPR : OPENACC_END_EXPR]);
7367 }
7368
7369private:
7370 /// Set base of the array section.
7371 void setBase(Expr *E) { SubExprs[BASE] = E; }
7372
7373 /// Set lower bound of the array section.
7374 void setLowerBound(Expr *E) { SubExprs[LOWER_BOUND] = E; }
7375
7376 /// Set length of the array section.
7377 void setLength(Expr *E) { SubExprs[LENGTH] = E; }
7378
7379 /// Set length of the array section.
7380 void setStride(Expr *E) {
7381 assert(ASType != OpenACCArraySection &&
7382 "Stride not valid in OpenACC subarrays");
7383 SubExprs[STRIDE] = E;
7384 }
7385
7386 void setColonLocFirst(SourceLocation L) { ColonLocFirst = L; }
7387
7388 void setColonLocSecond(SourceLocation L) {
7389 assert(ASType != OpenACCArraySection &&
7390 "second colon for stride not valid in OpenACC subarrays");
7391 ColonLocSecond = L;
7392 }
7393 void setRBracketLoc(SourceLocation L) { RBracketLoc = L; }
7394};
7395
7396/// This class represents temporary values used to represent inout and out
7397/// arguments in HLSL. From the callee perspective these parameters are more or
7398/// less __restrict__ T&. They are guaranteed to not alias any memory. inout
7399/// parameters are initialized by the caller, and out parameters are references
7400/// to uninitialized memory.
7401///
7402/// In the caller, the argument expression creates a temporary in local memory
7403/// and the address of the temporary is passed into the callee. There may be
7404/// implicit conversion sequences to initialize the temporary, and on expiration
7405/// of the temporary an inverse conversion sequence is applied as a write-back
7406/// conversion to the source l-value.
7407///
7408/// This AST node has three sub-expressions:
7409/// - An OpaqueValueExpr with a source that is the argument lvalue expression.
7410/// - An OpaqueValueExpr with a source that is an implicit conversion
7411/// sequence from the source lvalue to the argument type.
7412/// - An expression that assigns the second expression into the first,
7413/// performing any necessary conversions.
7414class HLSLOutArgExpr : public Expr {
7415 friend class ASTStmtReader;
7416
7417 enum {
7418 BaseLValue,
7419 CastedTemporary,
7420 WritebackCast,
7421 NumSubExprs,
7422 };
7423
7424 Stmt *SubExprs[NumSubExprs];
7425 bool IsInOut;
7426
7428 Expr *WB, bool IsInOut)
7429 : Expr(HLSLOutArgExprClass, Ty, VK_LValue, OK_Ordinary),
7430 IsInOut(IsInOut) {
7431 SubExprs[BaseLValue] = B;
7432 SubExprs[CastedTemporary] = OpV;
7433 SubExprs[WritebackCast] = WB;
7434 assert(!Ty->isDependentType() && "HLSLOutArgExpr given a dependent type!");
7435 }
7436
7437 explicit HLSLOutArgExpr(EmptyShell Shell)
7438 : Expr(HLSLOutArgExprClass, Shell) {}
7439
7440public:
7441 static HLSLOutArgExpr *Create(const ASTContext &C, QualType Ty,
7442 OpaqueValueExpr *Base, OpaqueValueExpr *OpV,
7443 Expr *WB, bool IsInOut);
7444 static HLSLOutArgExpr *CreateEmpty(const ASTContext &Ctx);
7445
7447 return cast<OpaqueValueExpr>(SubExprs[BaseLValue]);
7448 }
7450 return cast<OpaqueValueExpr>(SubExprs[BaseLValue]);
7451 }
7452
7453 /// Return the l-value expression that was written as the argument
7454 /// in source. Everything else here is implicitly generated.
7455 const Expr *getArgLValue() const {
7457 }
7459
7460 const Expr *getWritebackCast() const {
7461 return cast<Expr>(SubExprs[WritebackCast]);
7462 }
7463 Expr *getWritebackCast() { return cast<Expr>(SubExprs[WritebackCast]); }
7464
7466 return cast<OpaqueValueExpr>(SubExprs[CastedTemporary]);
7467 }
7469 return cast<OpaqueValueExpr>(SubExprs[CastedTemporary]);
7470 }
7471
7472 /// returns true if the parameter is inout and false if the parameter is out.
7473 bool isInOut() const { return IsInOut; }
7474
7475 SourceLocation getBeginLoc() const LLVM_READONLY {
7476 return SubExprs[BaseLValue]->getBeginLoc();
7477 }
7478
7479 SourceLocation getEndLoc() const LLVM_READONLY {
7480 return SubExprs[BaseLValue]->getEndLoc();
7481 }
7482
7483 static bool classof(const Stmt *T) {
7484 return T->getStmtClass() == HLSLOutArgExprClass;
7485 }
7486
7487 // Iterators
7489 return child_range(&SubExprs[BaseLValue], &SubExprs[NumSubExprs]);
7490 }
7491};
7492
7493/// Frontend produces RecoveryExprs on semantic errors that prevent creating
7494/// other well-formed expressions. E.g. when type-checking of a binary operator
7495/// fails, we cannot produce a BinaryOperator expression. Instead, we can choose
7496/// to produce a recovery expression storing left and right operands.
7497///
7498/// RecoveryExpr does not have any semantic meaning in C++, it is only useful to
7499/// preserve expressions in AST that would otherwise be dropped. It captures
7500/// subexpressions of some expression that we could not construct and source
7501/// range covered by the expression.
7502///
7503/// By default, RecoveryExpr uses dependence-bits to take advantage of existing
7504/// machinery to deal with dependent code in C++, e.g. RecoveryExpr is preserved
7505/// in `decltype(<broken-expr>)` as part of the `DependentDecltypeType`. In
7506/// addition to that, clang does not report most errors on dependent
7507/// expressions, so we get rid of bogus errors for free. However, note that
7508/// unlike other dependent expressions, RecoveryExpr can be produced in
7509/// non-template contexts.
7510///
7511/// We will preserve the type in RecoveryExpr when the type is known, e.g.
7512/// preserving the return type for a broken non-overloaded function call, a
7513/// overloaded call where all candidates have the same return type. In this
7514/// case, the expression is not type-dependent (unless the known type is itself
7515/// dependent)
7516///
7517/// One can also reliably suppress all bogus errors on expressions containing
7518/// recovery expressions by examining results of Expr::containsErrors().
7519class RecoveryExpr final : public Expr,
7520 private llvm::TrailingObjects<RecoveryExpr, Expr *> {
7521public:
7522 static RecoveryExpr *Create(ASTContext &Ctx, QualType T,
7523 SourceLocation BeginLoc, SourceLocation EndLoc,
7524 ArrayRef<Expr *> SubExprs);
7525 static RecoveryExpr *CreateEmpty(ASTContext &Ctx, unsigned NumSubExprs);
7526
7527 ArrayRef<Expr *> subExpressions() { return getTrailingObjects(NumExprs); }
7528
7530 return const_cast<RecoveryExpr *>(this)->subExpressions();
7531 }
7532
7534 Stmt **B = reinterpret_cast<Stmt **>(getTrailingObjects());
7535 return child_range(B, B + NumExprs);
7536 }
7537
7538 SourceLocation getBeginLoc() const { return BeginLoc; }
7539 SourceLocation getEndLoc() const { return EndLoc; }
7540
7541 static bool classof(const Stmt *T) {
7542 return T->getStmtClass() == RecoveryExprClass;
7543 }
7544
7545private:
7547 SourceLocation EndLoc, ArrayRef<Expr *> SubExprs);
7548 RecoveryExpr(EmptyShell Empty, unsigned NumSubExprs)
7549 : Expr(RecoveryExprClass, Empty), NumExprs(NumSubExprs) {}
7550
7551 size_t numTrailingObjects(OverloadToken<Stmt *>) const { return NumExprs; }
7552
7553 SourceLocation BeginLoc, EndLoc;
7554 unsigned NumExprs;
7555 friend TrailingObjects;
7556 friend class ASTStmtReader;
7557 friend class ASTStmtWriter;
7558};
7559
7560/// Insertion operator for diagnostics. This allows sending
7561/// Expr into a diagnostic with <<.
7563 const Expr *E) {
7564 DB.AddTaggedVal(reinterpret_cast<uint64_t>(E), DiagnosticsEngine::ak_expr);
7565 return DB;
7566}
7567
7568/// Walk @p E through parens, implicit casts, unary &/*, array subscripts and
7569/// comma operators to find the head of a struct-field access -- typically a
7570/// MemberExpr, or an LValueToRValue ImplicitCastExpr over a pointer-typed
7571/// field. Returns nullptr for shapes we don't handle (multiple subscripts,
7572/// non-comma binary ops, or '&fam' on an array lvalue which designates the
7573/// array-as-a-whole rather than an element pointer).
7574///
7575/// If @p OutArrayIndex / @p OutArrayElementTy are non-null, they receive the
7576/// index expression and base array type for forms like '&p->fam[idx]'.
7577///
7578/// Shared by CGBuiltin's __builtin_*_object_size lowering and the AST
7579/// constant evaluator so they recognize the same 'counted_by' access shapes.
7580const Expr *findStructFieldAccess(const Expr *E,
7581 const Expr **OutArrayIndex = nullptr,
7582 QualType *OutArrayElementTy = nullptr);
7583
7584} // end namespace clang
7585
7586#endif // LLVM_CLANG_AST_EXPR_H
#define V(N, I)
#define PTR(CLASS)
Definition AttrVisitor.h:27
Defines enumerations for traits support.
static bool CanThrow(Expr *E, ASTContext &Ctx)
Definition CFG.cpp:2852
clang::CharUnits operator*(clang::CharUnits::QuantityType Scale, const clang::CharUnits &CU)
Definition CharUnits.h:225
Defines the clang::LangOptions interface.
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
*collection of selector each with an associated kind and an ordered *collection of selectors A selector has a kind
Expr * getExpr()
Get 'expr' part of the associated expression/statement.
Provides definitions for the atomic synchronization scopes.
C Language Family Type Representation.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:223
a trap message and trap category.
llvm::APFloat getValue(const llvm::fltSemantics &Semantics) const
void setValue(const ASTContext &C, const llvm::APFloat &Val)
unsigned getBitWidth() const
void setValue(const ASTContext &C, const llvm::APInt &Val)
llvm::APInt getValue() const
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition APValue.h:122
@ None
There is no such object (it's outside its lifetime).
Definition APValue.h:129
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:223
std::reverse_iterator< iterator > reverse_iterator
Definition ASTVector.h:89
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition ASTVector.h:88
const Stmt ** const_iterator
Definition ASTVector.h:86
AbstractConditionalOperator(StmtClass SC, EmptyShell Empty)
Definition Expr.h:4374
SourceLocation getColonLoc() const
Definition Expr.h:4392
Expr * getCond() const
getCond - Return the expression representing the condition for the ?
Definition Expr.h:4542
static bool classof(const Stmt *T)
Definition Expr.h:4394
AbstractConditionalOperator(StmtClass SC, QualType T, ExprValueKind VK, ExprObjectKind OK, SourceLocation qloc, SourceLocation cloc)
Definition Expr.h:4369
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression representing the value of the expression if the condition eval...
Definition Expr.h:4548
SourceLocation getQuestionLoc() const
Definition Expr.h:4391
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression representing the value of the expression if the condition eva...
Definition Expr.h:4554
SourceLocation getAmpAmpLoc() const
Definition Expr.h:4576
static bool classof(const Stmt *T)
Definition Expr.h:4587
void setLabel(LabelDecl *L)
Definition Expr.h:4585
child_range children()
Definition Expr.h:4592
void setLabelLoc(SourceLocation L)
Definition Expr.h:4579
AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelDecl *L, QualType t)
Definition Expr.h:4565
void setAmpAmpLoc(SourceLocation L)
Definition Expr.h:4577
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:4582
AddrLabelExpr(EmptyShell Empty)
Build an empty address of a label expression.
Definition Expr.h:4573
SourceLocation getLabelLoc() const
Definition Expr.h:4578
const_child_range children() const
Definition Expr.h:4595
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:4581
LabelDecl * getLabel() const
Definition Expr.h:4584
const_child_range children() const
Definition Expr.h:6058
ArrayInitIndexExpr(QualType T)
Definition Expr.h:6043
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:6052
friend class ASTReader
Definition Expr.h:6062
static bool classof(const Stmt *S)
Definition Expr.h:6048
child_range children()
Definition Expr.h:6055
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:6053
friend class ASTStmtReader
Definition Expr.h:6063
child_range children()
Definition Expr.h:6023
ArrayInitLoopExpr(QualType T, Expr *CommonInit, Expr *ElementInit)
Definition Expr.h:5992
const_child_range children() const
Definition Expr.h:6026
llvm::APInt getArraySize() const
Definition Expr.h:6007
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:6019
static bool classof(const Stmt *S)
Definition Expr.h:6012
friend class ASTReader
Definition Expr.h:6030
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:6016
OpaqueValueExpr * getCommonExpr() const
Get the common subexpression shared by all initializations (the source array).
Definition Expr.h:6000
Expr * getSubExpr() const
Get the initializer to use for each array element.
Definition Expr.h:6005
friend class ASTStmtWriter
Definition Expr.h:6032
friend class ASTStmtReader
Definition Expr.h:6031
const Expr * getStride() const
Definition Expr.h:7334
QualType getElementType() const
Return the effective 'element' type of this array section.
Definition Expr.cpp:5434
SourceLocation getRBracketLoc() const
Definition Expr.h:7351
const_child_range children() const
Definition Expr.h:7363
Expr * getBase()
Get base of the array section.
Definition Expr.h:7314
static bool classof(const Stmt *T)
Definition Expr.h:7306
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:7343
Expr * getLength()
Get length of array section.
Definition Expr.h:7324
static QualType getBaseOriginalType(const Expr *Base)
Return original type of the base expression for array section.
Definition Expr.cpp:5406
SourceLocation getExprLoc() const LLVM_READONLY
Definition Expr.h:7353
const Expr * getLowerBound() const
Definition Expr.h:7319
bool isOMPArraySection() const
Definition Expr.h:7310
Expr * getStride()
Get stride of array section.
Definition Expr.h:7328
const Expr * getBase() const
Definition Expr.h:7315
ArraySectionExpr(Expr *Base, Expr *LowerBound, Expr *Length, QualType Type, ExprValueKind VK, ExprObjectKind OK, SourceLocation ColonLoc, SourceLocation RBracketLoc)
Definition Expr.h:7276
const Expr * getLength() const
Definition Expr.h:7325
ArraySectionExpr(EmptyShell Shell)
Create an empty array section expression.
Definition Expr.h:7288
friend class ASTStmtWriter
Definition Expr.h:7238
ArraySectionExpr(Expr *Base, Expr *LowerBound, Expr *Length, Expr *Stride, QualType Type, ExprValueKind VK, ExprObjectKind OK, SourceLocation ColonLocFirst, SourceLocation ColonLocSecond, SourceLocation RBracketLoc)
Definition Expr.h:7261
SourceLocation getColonLocSecond() const
Definition Expr.h:7346
Expr * getLowerBound()
Get lower bound of array section.
Definition Expr.h:7318
QualType getBaseType() const
Returns the effective 'type' of the base of this array section.
Definition Expr.cpp:5452
child_range children()
Definition Expr.h:7357
friend class ASTStmtReader
Definition Expr.h:7237
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:7340
bool isOpenACCArraySection() const
Definition Expr.h:7311
SourceLocation getColonLocFirst() const
Definition Expr.h:7345
ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t, ExprValueKind VK, ExprObjectKind OK, SourceLocation rbracketloc)
Definition Expr.h:2739
SourceLocation getExprLoc() const LLVM_READONLY
Definition Expr.h:2787
const Expr * getLHS() const
Definition Expr.h:2762
const_child_range children() const
Definition Expr.h:2799
const Expr * getBase() const
Definition Expr.h:2770
SourceLocation getRBracketLoc() const
Definition Expr.h:2780
const Expr * getRHS() const
Definition Expr.h:2766
Expr * getLHS()
An array access can be written A[4] or 4[A] (both are equivalent).
Definition Expr.h:2761
void setRHS(Expr *E)
Definition Expr.h:2767
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:2775
const Expr * getIdx() const
Definition Expr.h:2773
SourceLocation getEndLoc() const
Definition Expr.h:2778
void setRBracketLoc(SourceLocation L)
Definition Expr.h:2783
child_range children()
Definition Expr.h:2796
static bool classof(const Stmt *T)
Definition Expr.h:2791
void setLHS(Expr *E)
Definition Expr.h:2763
ArraySubscriptExpr(EmptyShell Shell)
Create an empty array subscript expression.
Definition Expr.h:2749
Expr * getSrcExpr() const
getSrcExpr - Return the Expr to be converted.
Definition Expr.h:6769
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:6778
AsTypeExpr(Expr *SrcExpr, QualType DstType, ExprValueKind VK, ExprObjectKind OK, SourceLocation BuiltinLoc, SourceLocation RParenLoc)
Definition Expr.h:6760
SourceLocation getBuiltinLoc() const
getBuiltinLoc - Return the location of the __builtin_astype token.
Definition Expr.h:6772
const_child_range children() const
Definition Expr.h:6786
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:6777
friend class ASTReader
Definition Expr.h:6755
SourceLocation getRParenLoc() const
getRParenLoc - Return the location of final right parenthesis.
Definition Expr.h:6775
static bool classof(const Stmt *T)
Definition Expr.h:6780
friend class ASTStmtReader
Definition Expr.h:6756
child_range children()
Definition Expr.h:6785
Expr ** getSubExprs()
Definition Expr.h:7020
static std::unique_ptr< AtomicScopeModel > getScopeModel(AtomicOp Op)
Get atomic scope model for the atomic op code.
Definition Expr.h:7094
Expr * getVal2() const
Definition Expr.h:6996
SourceLocation getRParenLoc() const
Definition Expr.h:7074
Expr * getOrder() const
Definition Expr.h:6979
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:7077
QualType getValueType() const
Definition Expr.cpp:5399
Expr * getScope() const
Definition Expr.h:6982
bool isCmpXChg() const
Definition Expr.h:7029
bool isHIP() const
Definition Expr.h:7062
AtomicOp getOp() const
Definition Expr.h:7008
bool isOpenCL() const
Definition Expr.h:7057
AtomicExpr(EmptyShell Empty)
Build an empty AtomicExpr.
Definition Expr.h:6974
Expr * getVal1() const
Definition Expr.h:6986
child_range children()
Definition Expr.h:7084
StringRef getOpAsString() const
Definition Expr.h:7009
bool threadPrivateMemoryAtomicsAreUndefined() const
Return true if atomics operations targeting allocations in private memory are undefined.
Definition Expr.h:7069
const Expr *const * getSubExprs() const
Definition Expr.h:7021
Expr * getPtr() const
Definition Expr.h:6976
std::unique_ptr< AtomicScopeModel > getScopeModel() const
Get atomic scope model.
Definition Expr.h:7110
Expr * getWeak() const
Definition Expr.h:7002
const_child_range children() const
Definition Expr.h:7087
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:7076
AtomicExpr(SourceLocation BLoc, ArrayRef< Expr * > args, QualType t, AtomicOp op, SourceLocation RP)
Definition Expr.cpp:5272
friend class ASTStmtReader
Definition Expr.h:6964
SourceLocation getBuiltinLoc() const
Definition Expr.h:7073
Expr * getOrderFail() const
Definition Expr.h:6992
bool hasVal1Operand() const
Definition Expr.h:7042
unsigned getNumSubExprs() const
Definition Expr.h:7018
static bool classof(const Stmt *T)
Definition Expr.h:7079
bool isVolatile() const
Definition Expr.h:7025
static std::unique_ptr< AtomicScopeModel > create(AtomicScopeModelKind K)
Create an atomic scope model by AtomicScopeModelKind.
Definition SyncScope.h:299
static bool classof(const Stmt *T)
Definition Expr.h:4529
BinaryConditionalOperator(Expr *common, OpaqueValueExpr *opaqueValue, Expr *cond, Expr *lhs, Expr *rhs, SourceLocation qloc, SourceLocation cloc, QualType t, ExprValueKind VK, ExprObjectKind OK)
Definition Expr.h:4477
const_child_range children() const
Definition Expr.h:4537
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:4522
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression which will be evaluated if the condition evaluates to false; ...
Definition Expr.h:4518
BinaryConditionalOperator(EmptyShell Empty)
Build an empty conditional operator.
Definition Expr.h:4493
OpaqueValueExpr * getOpaqueValue() const
getOpaqueValue - Return the opaque value placeholder.
Definition Expr.h:4502
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:4525
Expr * getCond() const
getCond - Return the condition expression; this is defined in terms of the opaque value.
Definition Expr.h:4506
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression which will be evaluated if the condition evaluates to true; th...
Definition Expr.h:4511
Expr * getCommon() const
getCommon - Return the common expression, written to the left of the condition.
Definition Expr.h:4499
A builtin binary operation expression such as "x + y" or "x <= y".
Definition Expr.h:4049
static bool isLogicalOp(Opcode Opc)
Definition Expr.h:4182
void setLHS(Expr *E)
Definition Expr.h:4100
Expr * getLHS() const
Definition Expr.h:4099
child_range children()
Definition Expr.h:4224
BinaryOperator(EmptyShell Empty)
Construct an empty binary operator.
Definition Expr.h:4078
static bool isRelationalOp(Opcode Opc)
Definition Expr.h:4143
static OverloadedOperatorKind getOverloadedOperator(Opcode Opc)
Retrieve the overloaded operator kind that corresponds to the given binary opcode.
Definition Expr.cpp:2189
const FPOptionsOverride * getTrailingFPFeatures() const
Definition Expr.h:4065
const_child_range children() const
Definition Expr.h:4227
static bool isComparisonOp(Opcode Opc)
Definition Expr.h:4149
void setHasStoredFPFeatures(bool B)
Set and fetch the bit that shows whether FPFeatures needs to be allocated in Trailing Storage.
Definition Expr.h:4233
void setOperatorLoc(SourceLocation L)
Definition Expr.h:4092
static bool isShiftOp(Opcode Opc)
Definition Expr.h:4137
bool isComparisonOp() const
Definition Expr.h:4150
FPOptionsOverride getStoredFPFeaturesOrDefault() const
Get the store FPOptionsOverride or default if not stored.
Definition Expr.h:4256
StringRef getOpcodeStr() const
Definition Expr.h:4115
static bool isCommaOp(Opcode Opc)
Definition Expr.h:4152
static Opcode getOpForCompoundAssignment(Opcode Opc)
Definition Expr.h:4196
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:4104
FPOptionsOverride * getTrailingFPFeatures()
Return a pointer to the trailing FPOptions.
Definition Expr.h:4060
bool isRelationalOp() const
Definition Expr.h:4144
void setRHS(Expr *E)
Definition Expr.h:4102
SourceLocation getOperatorLoc() const
Definition Expr.h:4091
bool isPtrMemOp() const
Definition Expr.h:4129
bool isFEnvAccessOn(const LangOptions &LO) const
Get the FENV_ACCESS status of this operator.
Definition Expr.h:4283
bool hasStoredFPFeatures() const
Definition Expr.h:4234
bool isCompoundAssignmentOp() const
Definition Expr.h:4193
static Opcode negateComparisonOp(Opcode Opc)
Definition Expr.h:4155
bool isLogicalOp() const
Definition Expr.h:4183
bool isMultiplicativeOp() const
Definition Expr.h:4134
SourceLocation getExprLoc() const
Definition Expr.h:4090
static Opcode reverseComparisonOp(Opcode Opc)
Definition Expr.h:4168
static bool isShiftAssignOp(Opcode Opc)
Definition Expr.h:4204
bool isFPContractableWithinStatement(const LangOptions &LO) const
Get the FP contractibility status of this operator.
Definition Expr.h:4277
bool isShiftOp() const
Definition Expr.h:4138
Expr * getRHS() const
Definition Expr.h:4101
static unsigned sizeOfTrailingObjects(bool HasFPFeatures)
Return the size in bytes needed for the trailing objects.
Definition Expr.h:4300
bool isEqualityOp() const
Definition Expr.h:4147
BinaryOperator(StmtClass SC, EmptyShell Empty)
Construct an empty BinaryOperator, SC is CompoundAssignOperator.
Definition Expr.h:4294
void setExcludedOverflowPattern(bool B)
Set and get the bit that informs arithmetic overflow sanitizers whether or not they should exclude ce...
Definition Expr.h:4238
bool isBitwiseOp() const
Definition Expr.h:4141
static BinaryOperator * CreateEmpty(const ASTContext &C, bool hasFPFeatures)
Definition Expr.cpp:5100
FPOptionsOverride getStoredFPFeatures() const
Get FPFeatures from trailing storage.
Definition Expr.h:4246
static bool classof(const Stmt *S)
Definition Expr.h:4218
bool isAdditiveOp() const
Definition Expr.h:4136
static bool isAdditiveOp(Opcode Opc)
Definition Expr.h:4135
static bool isPtrMemOp(Opcode Opc)
predicates to categorize the respective opcodes.
Definition Expr.h:4126
static bool isAssignmentOp(Opcode Opc)
Definition Expr.h:4185
static bool isCompoundAssignmentOp(Opcode Opc)
Definition Expr.h:4190
bool isShiftAssignOp() const
Definition Expr.h:4207
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:4107
FPOptions getFPFeaturesInEffect(const LangOptions &LO) const
Get the FP features status of this operator.
Definition Expr.h:4262
static bool isNullPointerArithmeticExtension(ASTContext &Ctx, Opcode Opc, const Expr *LHS, const Expr *RHS)
Return true if a binary operator using the specified opcode and operands would match the 'p = (i8*)nu...
Definition Expr.cpp:2214
Opcode getOpcode() const
Definition Expr.h:4094
void setStoredFPFeatures(FPOptionsOverride F)
Set FPFeatures in trailing storage, used only by Serialization.
Definition Expr.h:4251
FPOptionsOverride getFPFeatures() const
Definition Expr.h:4269
bool isCommaOp() const
Definition Expr.h:4153
bool isAssignmentOp() const
Definition Expr.h:4188
static Opcode getOverloadedOpcode(OverloadedOperatorKind OO)
Retrieve the binary opcode that corresponds to the given overloaded operator.
Definition Expr.cpp:2151
size_t offsetOfTrailingStorage() const
Definition Expr.h:4356
static bool isEqualityOp(Opcode Opc)
Definition Expr.h:4146
bool hasExcludedOverflowPattern() const
Definition Expr.h:4241
void setOpcode(Opcode Opc)
Definition Expr.h:4097
static bool isBitwiseOp(Opcode Opc)
Definition Expr.h:4140
static bool isMultiplicativeOp(Opcode Opc)
Definition Expr.h:4131
BinaryOperator(const ASTContext &Ctx, Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, ExprValueKind VK, ExprObjectKind OK, SourceLocation opLoc, FPOptionsOverride FPFeatures)
Build a binary operator, assuming that appropriate storage has been allocated for the trailing object...
Definition Expr.cpp:5063
BinaryOperatorKind Opcode
Definition Expr.h:4054
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition Decl.h:4806
BlockExpr(EmptyShell Empty)
Build an empty block expression.
Definition Expr.h:6699
SourceLocation getCaretLocation() const
Definition Expr.cpp:2549
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:6710
BlockDecl * TheBlock
Definition Expr.h:6691
child_range children()
Definition Expr.h:6725
BlockDecl * getBlockDecl()
Definition Expr.h:6702
const Stmt * getBody() const
Definition Expr.cpp:2552
BlockExpr(BlockDecl *BD, QualType ty, bool ContainsUnexpandedParameterPack)
Definition Expr.h:6693
const_child_range children() const
Definition Expr.h:6728
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:6713
void setBlockDecl(BlockDecl *BD)
Definition Expr.h:6703
static bool classof(const Stmt *T)
Definition Expr.h:6720
const FunctionProtoType * getFunctionType() const
getFunctionType - Return the underlying function type for this block.
Definition Expr.cpp:2543
const BlockDecl * getBlockDecl() const
Definition Expr.h:6701
This class is used for builtin types like 'int'.
Definition TypeBase.h:3241
static bool isPlaceholderTypeKind(Kind K)
Determines whether the given kind corresponds to a placeholder type.
Definition TypeBase.h:3326
SourceLocation getRParenLoc() const
Definition Expr.h:4015
static CStyleCastExpr * CreateEmpty(const ASTContext &Context, unsigned PathSize, bool HasFPFeatures)
Definition Expr.cpp:2131
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:4018
friend class CastExpr
Definition Expr.h:4028
void setRParenLoc(SourceLocation L)
Definition Expr.h:4016
static bool classof(const Stmt *T)
Definition Expr.h:4023
friend TrailingObjects
Definition Expr.h:4027
SourceLocation getLParenLoc() const
Definition Expr.h:4012
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:4019
void setLParenLoc(SourceLocation L)
Definition Expr.h:4013
Represents a base class of a C++ class.
Definition DeclCXX.h:146
Represents a call to a member function that may be written either with member call syntax (e....
Definition ExprCXX.h:182
A call to an overloaded operator written using operator syntax.
Definition ExprCXX.h:84
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition Expr.h:2954
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
Definition Expr.h:3158
bool hasStoredFPFeatures() const
Definition Expr.h:3113
const FPOptionsOverride * getTrailingFPFeatures() const
Definition Expr.h:3065
bool usesMemberSyntax() const
Definition Expr.h:3115
std::optional< llvm::APInt > evaluateBytesReturnedByAllocSizeCall(const ASTContext &Ctx) const
Evaluates the total size in bytes allocated by calling a function decorated with alloc_size.
Definition Expr.cpp:3613
static unsigned sizeOfTrailingObjects(unsigned NumPreArgs, unsigned NumArgs, bool HasFPFeatures)
Return the size in bytes needed for the trailing objects.
Definition Expr.h:3037
static constexpr ADLCallKind NotADL
Definition Expr.h:3020
bool usesADL() const
Definition Expr.h:3111
const Stmt * getPreArg(unsigned I) const
Definition Expr.h:3047
SourceLocation getBeginLoc() const
Definition Expr.h:3288
void setRParenLoc(SourceLocation L)
Definition Expr.h:3286
const_arg_iterator arg_begin() const
Definition Expr.h:3216
static bool classof(const Stmt *T)
Definition Expr.h:3351
llvm::iterator_range< const_arg_iterator > const_arg_range
Definition Expr.h:3204
void setCoroElideSafe(bool V=true)
Definition Expr.h:3129
const Expr *const * getArgs() const
Definition Expr.h:3152
void setArg(unsigned Arg, Expr *ArgExpr)
setArg - Set the specified argument.
Definition Expr.h:3171
ConstExprIterator const_arg_iterator
Definition Expr.h:3202
ExprIterator arg_iterator
Definition Expr.h:3201
child_range children()
Definition Expr.h:3357
std::pair< const NamedDecl *, const WarnUnusedResultAttr * > getUnusedResultAttr(const ASTContext &Ctx) const
Returns the WarnUnusedResultAttr that is declared on the callee or its return type declaration,...
Definition Expr.h:3276
void setADLCallKind(ADLCallKind V=UsesADL)
Definition Expr.h:3108
const AllocSizeAttr * getCalleeAllocSizeAttr() const
Try to get the alloc_size attribute of the callee. May return null.
Definition Expr.cpp:3604
llvm::iterator_range< arg_iterator > arg_range
Definition Expr.h:3203
const_arg_range arguments() const
Definition Expr.h:3207
unsigned getBuiltinCallee() const
getBuiltinCallee - If this is a call to a builtin, return the builtin ID of the callee.
Definition Expr.cpp:1598
arg_iterator arg_begin()
Definition Expr.h:3211
FPOptionsOverride getStoredFPFeaturesOrDefault() const
Get the store FPOptionsOverride or default if not stored.
Definition Expr.h:3241
FPOptionsOverride getStoredFPFeatures() const
Get FPOptionsOverride from trailing storage.
Definition Expr.h:3230
arg_iterator arg_end()
Definition Expr.h:3214
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return null.
Definition Expr.h:3137
static CallExpr * CreateEmpty(const ASTContext &Ctx, unsigned NumArgs, bool HasFPFeatures, EmptyShell Empty)
Create an empty call expression, for deserialization.
Definition Expr.cpp:1541
bool isCallToStdMove() const
Definition Expr.cpp:3654
void setUsesMemberSyntax(bool V=true)
Definition Expr.h:3118
void setPreArg(unsigned I, Stmt *PreArg)
Definition Expr.h:3051
ADLCallKind getADLCallKind() const
Definition Expr.h:3105
Expr * getCallee()
Definition Expr.h:3101
FPOptionsOverride getFPFeatures() const
Definition Expr.h:3253
static constexpr unsigned OffsetToTrailingObjects
Definition Expr.h:2991
void markDependentForPostponedNameLookup()
Used by Sema to implement MSVC-compatible delayed name lookup.
Definition Expr.h:3336
const Expr * getCallee() const
Definition Expr.h:3102
const Decl * getCalleeDecl() const
Definition Expr.h:3132
void computeDependence()
Compute and set dependence bits.
Definition Expr.h:3177
void setStoredFPFeatures(FPOptionsOverride F)
Set FPOptionsOverride in trailing storage. Used only by Serialization.
Definition Expr.h:3235
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
Definition Expr.h:3145
FPOptions getFPFeaturesInEffect(const LangOptions &LO) const
Get the FP features status of this operator.
Definition Expr.h:3247
bool isCoroElideSafe() const
Definition Expr.h:3128
Expr ** getArgs()
Retrieve the call arguments.
Definition Expr.h:3148
const_child_range children() const
Definition Expr.h:3362
CallExpr(StmtClass SC, Expr *Fn, ArrayRef< Expr * > PreArgs, ArrayRef< Expr * > Args, QualType Ty, ExprValueKind VK, SourceLocation RParenLoc, FPOptionsOverride FPFeatures, unsigned MinNumArgs, ADLCallKind UsesADL)
Build a call expression, assuming that appropriate storage has been allocated for the trailing object...
Definition Expr.cpp:1479
arg_range arguments()
Definition Expr.h:3206
static constexpr unsigned sizeToAllocateForCallExprSubclass(unsigned SizeOfTrailingObjects)
Definition Expr.h:2994
SourceLocation getEndLoc() const
Definition Expr.h:3307
SourceLocation getRParenLoc() const
Definition Expr.h:3285
static constexpr ADLCallKind UsesADL
Definition Expr.h:3021
bool isBuiltinAssumeFalse(const ASTContext &Ctx) const
Return true if this is a call to __assume() or __builtin_assume() with a non-value-dependent constant...
Definition Expr.cpp:3592
const_arg_iterator arg_end() const
Definition Expr.h:3219
const FunctionDecl * getDirectCallee() const
Definition Expr.h:3140
Stmt * getPreArg(unsigned I)
Definition Expr.h:3043
friend class ASTStmtReader
Definition Expr.h:3310
FPOptionsOverride * getTrailingFPFeatures()
Return a pointer to the trailing FPOptions.
Definition Expr.h:3059
Decl * getCalleeDecl()
Definition Expr.h:3131
QualType getCallReturnType(const ASTContext &Ctx) const
getCallReturnType - Get the return type of the call expr.
Definition Expr.cpp:1609
bool isUnevaluatedBuiltinCall(const ASTContext &Ctx) const
Returns true if this is a call to a builtin which does not evaluate side-effects within its arguments...
Definition Expr.cpp:1603
void setNumArgsUnsafe(unsigned NewNumArgs)
Bluntly set a new number of arguments without doing any checks whatsoever.
Definition Expr.h:3199
void setCallee(Expr *F)
Definition Expr.h:3103
unsigned getNumPreArgs() const
Definition Expr.h:3056
ArrayRef< Stmt * > getRawSubExprs() const
This method provides fast access to all the subexpressions of a CallExpr without going through the sl...
Definition Expr.h:3225
bool hasUnusedResultAttr(const ASTContext &Ctx) const
Returns true if this call expression should warn on unused results.
Definition Expr.h:3281
void shrinkNumArgs(unsigned NewNumArgs)
Reduce the number of arguments in this call expression.
Definition Expr.h:3190
const Expr * getArg(unsigned Arg) const
Definition Expr.h:3162
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition Expr.h:3687
FPOptionsOverride * getTrailingFPFeatures()
Return a pointer to the trailing FPOptions.
Definition Expr.cpp:2061
path_iterator path_begin()
Definition Expr.h:3757
unsigned path_size() const
Definition Expr.h:3756
NamedDecl * getConversionFunction() const
If this cast applies a user-defined conversion, retrieve the conversion function that it invokes.
Definition Expr.cpp:2010
const Expr * getSubExprAsWritten() const
Definition Expr.h:3745
Expr * getSubExprAsWritten()
Retrieve the cast subexpression as it was written in the source code, looking through any implicit ca...
Definition Expr.cpp:1988
CastKind getCastKind() const
Definition Expr.h:3731
void setCastKind(CastKind K)
Definition Expr.h:3732
llvm::iterator_range< path_iterator > path()
Path through the class hierarchy taken by casts between base and derived classes (see implementation ...
Definition Expr.h:3774
const FieldDecl * getTargetUnionField() const
Definition Expr.h:3781
CastExpr(StmtClass SC, EmptyShell Empty, unsigned BasePathSize, bool HasFPFeatures)
Construct an empty cast.
Definition Expr.h:3713
static bool classof(const Stmt *T)
Definition Expr.h:3831
llvm::iterator_range< path_const_iterator > path() const
Definition Expr.h:3777
bool hasStoredFPFeatures() const
Definition Expr.h:3786
bool changesVolatileQualification() const
Return.
Definition Expr.h:3821
static const FieldDecl * getTargetFieldForToUnionCast(QualType unionType, QualType opType)
Definition Expr.cpp:2042
FPOptionsOverride getStoredFPFeatures() const
Get FPOptionsOverride from trailing storage.
Definition Expr.h:3789
CastExpr(StmtClass SC, QualType ty, ExprValueKind VK, const CastKind kind, Expr *op, unsigned BasePathSize, bool HasFPFeatures)
Definition Expr.h:3700
const Expr * getSubExpr() const
Definition Expr.h:3738
path_iterator path_end()
Definition Expr.h:3758
const_child_range children() const
Definition Expr.h:3838
const FPOptionsOverride * getTrailingFPFeatures() const
Definition Expr.h:3726
CXXBaseSpecifier ** path_iterator
Definition Expr.h:3753
path_const_iterator path_end() const
Definition Expr.h:3760
const char * getCastKindName() const
Definition Expr.h:3735
child_range children()
Definition Expr.h:3837
friend class ASTStmtReader
Definition Expr.h:3697
void setSubExpr(Expr *E)
Definition Expr.h:3739
path_const_iterator path_begin() const
Definition Expr.h:3759
const CXXBaseSpecifier *const * path_const_iterator
Definition Expr.h:3754
bool path_empty() const
Definition Expr.h:3755
FPOptionsOverride getFPFeatures() const
Definition Expr.h:3807
FPOptionsOverride getStoredFPFeaturesOrDefault() const
Get the store FPOptionsOverride or default if not stored.
Definition Expr.h:3795
Expr * getSubExpr()
Definition Expr.h:3737
FPOptions getFPFeaturesInEffect(const LangOptions &LO) const
Get the FP features status of this operation.
Definition Expr.h:3801
void setValue(unsigned Val)
Definition Expr.h:1646
SourceLocation getLocation() const
Definition Expr.h:1632
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:1638
void setLocation(SourceLocation Location)
Definition Expr.h:1642
static bool classof(const Stmt *T)
Definition Expr.h:1648
static void print(unsigned val, CharacterLiteralKind Kind, raw_ostream &OS)
Definition Expr.cpp:1026
unsigned getValue() const
Definition Expr.h:1640
child_range children()
Definition Expr.h:1655
void setKind(CharacterLiteralKind kind)
Definition Expr.h:1643
const_child_range children() const
Definition Expr.h:1658
CharacterLiteralKind getKind() const
Definition Expr.h:1633
CharacterLiteral(EmptyShell Empty)
Construct an empty character literal.
Definition Expr.h:1630
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:1637
CharacterLiteral(unsigned value, CharacterLiteralKind kind, QualType type, SourceLocation l)
Definition Expr.h:1621
void setRParenLoc(SourceLocation L)
Definition Expr.h:4910
void setIsConditionTrue(bool isTrue)
Definition Expr.h:4887
SourceLocation getBuiltinLoc() const
Definition Expr.h:4906
Expr * getLHS() const
Definition Expr.h:4901
Expr * getChosenSubExpr() const
getChosenSubExpr - Return the subexpression chosen according to the condition.
Definition Expr.h:4895
bool isConditionDependent() const
Definition Expr.h:4889
void setBuiltinLoc(SourceLocation L)
Definition Expr.h:4907
bool isConditionTrue() const
isConditionTrue - Return whether the condition is true (i.e.
Definition Expr.h:4882
ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, QualType t, ExprValueKind VK, ExprObjectKind OK, SourceLocation RP, bool condIsTrue)
Definition Expr.h:4865
void setRHS(Expr *E)
Definition Expr.h:4904
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:4913
child_range children()
Definition Expr.h:4920
Expr * getRHS() const
Definition Expr.h:4903
SourceLocation getRParenLoc() const
Definition Expr.h:4909
ChooseExpr(EmptyShell Empty)
Build an empty __builtin_choose_expr.
Definition Expr.h:4878
const_child_range children() const
Definition Expr.h:4923
Expr * getCond() const
Definition Expr.h:4899
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:4912
void setCond(Expr *E)
Definition Expr.h:4900
void setLHS(Expr *E)
Definition Expr.h:4902
static bool classof(const Stmt *T)
Definition Expr.h:4915
CompoundAssignOperator - For compound assignments (e.g.
Definition Expr.h:4311
void setComputationResultType(QualType T)
Definition Expr.h:4349
static CompoundAssignOperator * CreateEmpty(const ASTContext &C, bool hasFPFeatures)
Definition Expr.cpp:5122
CompoundAssignOperator(const ASTContext &C, Expr *lhs, Expr *rhs, Opcode opc, QualType ResType, ExprValueKind VK, ExprObjectKind OK, SourceLocation OpLoc, FPOptionsOverride FPFeatures, QualType CompLHSType, QualType CompResultType)
Definition Expr.h:4321
QualType getComputationLHSType() const
Definition Expr.h:4345
void setComputationLHSType(QualType T)
Definition Expr.h:4346
static bool classof(const Stmt *S)
Definition Expr.h:4351
QualType getComputationResultType() const
Definition Expr.h:4348
void setFileScope(bool FS)
Definition Expr.h:3649
const_child_range children() const
Definition Expr.h:3678
void setTypeSourceInfo(TypeSourceInfo *tinfo)
Definition Expr.h:3657
bool hasStaticStorage() const
Definition Expr.h:3661
SourceLocation getLParenLoc() const
Definition Expr.h:3651
child_range children()
Definition Expr.h:3677
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:3665
APValue & getStaticValue() const
Definition Expr.cpp:5715
CompoundLiteralExpr(EmptyShell Empty)
Construct an empty compound literal.
Definition Expr.h:3641
void setLParenLoc(SourceLocation L)
Definition Expr.h:3652
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:3670
APValue & getOrCreateStaticValue(ASTContext &Ctx) const
Definition Expr.cpp:5706
bool isFileScope() const
Definition Expr.h:3648
static bool classof(const Stmt *T)
Definition Expr.h:3672
const Expr * getInitializer() const
Definition Expr.h:3644
TypeSourceInfo * getTypeSourceInfo() const
Definition Expr.h:3654
void setInitializer(Expr *E)
Definition Expr.h:3646
CompoundLiteralExpr(SourceLocation lparenloc, TypeSourceInfo *tinfo, QualType T, ExprValueKind VK, Expr *init, bool fileScope)
Definition Expr.h:3632
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition Stmt.h:1749
ConditionalOperator - The ?
Definition Expr.h:4402
const_child_range children() const
Definition Expr.h:4454
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression representing the value of the expression if the condition eva...
Definition Expr.h:4434
Expr * getLHS() const
Definition Expr.h:4436
static bool classof(const Stmt *T)
Definition Expr.h:4446
ConditionalOperator(Expr *cond, SourceLocation QLoc, Expr *lhs, SourceLocation CLoc, Expr *rhs, QualType t, ExprValueKind VK, ExprObjectKind OK)
Definition Expr.h:4408
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:4439
Expr * getCond() const
getCond - Return the expression representing the condition for the ?
Definition Expr.h:4425
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression representing the value of the expression if the condition eval...
Definition Expr.h:4429
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:4442
child_range children()
Definition Expr.h:4451
Expr * getRHS() const
Definition Expr.h:4437
friend class ASTStmtReader
Definition Expr.h:4406
ConditionalOperator(EmptyShell Empty)
Build an empty conditional operator.
Definition Expr.h:4420
APValue getAPValueResult() const
Definition Expr.cpp:419
static ConstantResultStorageKind getStorageKind(const APValue &Value)
Definition Expr.cpp:308
child_range children()
Definition Expr.h:1174
void MoveIntoResult(APValue &Value, const ASTContext &Context)
Definition Expr.cpp:384
llvm::APSInt getResultAsAPSInt() const
Definition Expr.cpp:407
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:1143
ConstantResultStorageKind getResultStorageKind() const
Definition Expr.h:1162
void SetResult(APValue Value, const ASTContext &Context)
Definition Expr.h:1154
APValue::ValueKind getResultAPValueKind() const
Definition Expr.h:1159
static bool classof(const Stmt *T)
Definition Expr.h:1150
bool hasAPValueResult() const
Definition Expr.h:1168
friend class ASTStmtWriter
Definition Expr.h:1099
const_child_range children() const
Definition Expr.h:1175
friend class ASTStmtReader
Definition Expr.h:1098
bool isImmediateInvocation() const
Definition Expr.h:1165
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:1146
static ConstantExpr * CreateEmpty(const ASTContext &Context, ConstantResultStorageKind StorageKind)
Definition Expr.cpp:373
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Definition Expr.h:4730
FPOptionsOverride getStoredFPFeaturesOrDefault() const
Get the store FPOptionsOverride or default if not stored.
Definition Expr.h:4798
SourceLocation getRParenLoc() const
getRParenLoc - Return the location of final right parenthesis.
Definition Expr.h:4834
const_child_range children() const
Definition Expr.h:4845
FPOptions getFPFeaturesInEffect(const LangOptions &LO) const
Get the FP features status of this operator.
Definition Expr.h:4807
bool isFPContractableWithinStatement(const LangOptions &LO) const
Get the FP contractibility status of this operator.
Definition Expr.h:4783
friend class ASTReader
Definition Expr.h:4737
static ConvertVectorExpr * CreateEmpty(const ASTContext &C, bool hasFPFeatures)
Definition Expr.cpp:5688
static bool classof(const Stmt *T)
Definition Expr.h:4839
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:4837
child_range children()
Definition Expr.h:4844
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:4836
SourceLocation getBuiltinLoc() const
getBuiltinLoc - Return the location of the __builtin_convertvector token.
Definition Expr.h:4831
FPOptionsOverride getStoredFPFeatures() const
Get FPFeatures from trailing storage.
Definition Expr.h:4793
TypeSourceInfo * getTypeSourceInfo() const
getTypeSourceInfo - Return the destination type.
Definition Expr.h:4823
void setStoredFPFeatures(FPOptionsOverride F)
Set FPFeatures in trailing storage, used by Serialization & ASTImporter.
Definition Expr.h:4803
bool hasStoredFPFeatures() const
Is FPFeatures in Trailing Storage?
Definition Expr.h:4788
friend class ASTStmtReader
Definition Expr.h:4738
void setTypeSourceInfo(TypeSourceInfo *ti)
Definition Expr.h:4826
Expr * getSrcExpr() const
getSrcExpr - Return the Expr to be converted.
Definition Expr.h:4820
FPOptionsOverride getFPOptionsOverride() const
Definition Expr.h:4813
A POD class for pairing a NamedDecl* with an access specifier.
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition DeclBase.h:1466
unsigned getNumTemplateArgs() const
Retrieve the number of template arguments provided as part of this template-id.
Definition Expr.h:1456
NamedDecl * getFoundDecl()
Get the NamedDecl through which this reference occurred.
Definition Expr.h:1392
bool hasExplicitTemplateArgs() const
Determines whether this declaration reference was followed by an explicit template argument list.
Definition Expr.h:1436
NestedNameSpecifier getQualifier() const
If the name was qualified, retrieves the nested-name-specifier that precedes the name.
Definition Expr.h:1382
void setIsImmediateEscalating(bool Set)
Definition Expr.h:1493
const_child_range children() const
Definition Expr.h:1516
bool refersToEnclosingVariableOrCapture() const
Does this DeclRefExpr refer to an enclosing local or a captured variable?
Definition Expr.h:1485
void setDecl(ValueDecl *NewD)
Definition Expr.cpp:550
bool hasTemplateKWAndArgsInfo() const
Definition Expr.h:1402
const NamedDecl * getFoundDecl() const
Get the NamedDecl through which this reference occurred.
Definition Expr.h:1398
static DeclRefExpr * CreateEmpty(const ASTContext &Context, bool HasQualifier, bool HasFoundDecl, bool HasTemplateKWAndArgsInfo, unsigned NumTemplateArgs)
Construct an empty declaration reference expression.
Definition Expr.cpp:535
void setLocation(SourceLocation L)
Definition Expr.h:1358
void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const
Copies the template arguments (if present) into the given structure.
Definition Expr.h:1440
DeclarationNameInfo getNameInfo() const
Definition Expr.h:1353
void setHadMultipleCandidates(bool V=true)
Sets the flag telling whether this expression refers to a function that was resolved from an overload...
Definition Expr.h:1474
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition Expr.h:1408
bool isCapturedByCopyInLambdaWithExplicitObjectParameter() const
Definition Expr.h:1497
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition Expr.h:1416
bool hasQualifier() const
Determine whether this declaration reference was preceded by a C++ nested-name-specifier,...
Definition Expr.h:1370
NestedNameSpecifierLoc getQualifierLoc() const
If the name was qualified, retrieves the nested-name-specifier that precedes the name,...
Definition Expr.h:1374
ValueDecl * getDecl()
Definition Expr.h:1349
child_range children()
Definition Expr.h:1512
const ValueDecl * getDecl() const
Definition Expr.h:1350
const TemplateArgumentLoc * getTemplateArgs() const
Retrieve the template arguments provided as part of this template-id.
Definition Expr.h:1448
friend class ASTStmtWriter
Definition Expr.h:1283
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition Expr.h:1462
static bool classof(const Stmt *T)
Definition Expr.h:1507
NonOdrUseReason isNonOdrUse() const
Is this expression a non-odr-use reference, and if so, why?
Definition Expr.h:1479
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.cpp:557
bool hadMultipleCandidates() const
Returns true if this expression refers to a function that was resolved from an overloaded set having ...
Definition Expr.h:1468
friend class ASTStmtReader
Definition Expr.h:1282
void setCapturedByCopyInLambdaWithExplicitObjectParameter(bool Set, const ASTContext &Context)
Definition Expr.h:1501
SourceLocation getBeginLoc() const
Definition Expr.h:1360
bool hasTemplateKeyword() const
Determines whether the name in this declaration reference was preceded by the template keyword.
Definition Expr.h:1432
SourceLocation getLocation() const
Definition Expr.h:1357
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition Expr.h:1424
bool isImmediateEscalating() const
Definition Expr.h:1489
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
DeclarationNameLoc - Additional source/type location info for a declaration name.
Represents a single C99 designator.
Definition Expr.h:5611
SourceRange getSourceRange() const LLVM_READONLY
Definition Expr.h:5783
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:5773
static Designator CreateArrayRangeDesignator(unsigned Index, SourceLocation LBracketLoc, SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
Creates a GNU array-range designator.
Definition Expr.h:5738
struct FieldDesignatorInfo FieldInfo
A field designator, e.g., ".x".
Definition Expr.h:5673
static Designator CreateFieldDesignator(const IdentifierInfo *FieldName, SourceLocation DotLoc, SourceLocation FieldLoc)
Creates a field designator.
Definition Expr.h:5692
struct ArrayOrRangeDesignatorInfo ArrayOrRangeInfo
An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
Definition Expr.h:5676
void setFieldDecl(FieldDecl *FD)
Definition Expr.h:5709
static Designator CreateArrayDesignator(unsigned Index, SourceLocation LBracketLoc, SourceLocation RBracketLoc)
Creates an array designator.
Definition Expr.h:5728
FieldDecl * getFieldDecl() const
Definition Expr.h:5702
SourceLocation getFieldLoc() const
Definition Expr.h:5719
SourceLocation getRBracketLoc() const
Definition Expr.h:5767
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:5779
const IdentifierInfo * getFieldName() const
Definition Expr.cpp:4799
SourceLocation getEllipsisLoc() const
Definition Expr.h:5761
SourceLocation getDotLoc() const
Definition Expr.h:5714
SourceLocation getLBracketLoc() const
Definition Expr.h:5755
Represents a C99 designated initializer expression.
Definition Expr.h:5568
bool isDirectInit() const
Whether this designated initializer should result in direct-initialization of the designated subobjec...
Definition Expr.h:5828
static DesignatedInitExpr * CreateEmpty(const ASTContext &C, unsigned NumIndexExprs)
Definition Expr.cpp:4853
Expr * getArrayRangeEnd(const Designator &D) const
Definition Expr.cpp:4908
void setInit(Expr *init)
Definition Expr.h:5840
const_child_range children() const
Definition Expr.h:5877
const Designator * getDesignator(unsigned Idx) const
Definition Expr.h:5810
Expr * getSubExpr(unsigned Idx) const
Definition Expr.h:5850
SourceRange getDesignatorsSourceRange() const
Definition Expr.cpp:4869
void setSubExpr(unsigned Idx, Expr *E)
Definition Expr.h:5854
bool usesGNUSyntax() const
Determines whether this designated initializer used the deprecated GNU syntax for designated initiali...
Definition Expr.h:5832
Expr * getArrayRangeStart(const Designator &D) const
Definition Expr.cpp:4903
void ExpandDesignator(const ASTContext &C, unsigned Idx, const Designator *First, const Designator *Last)
Replaces the designator at index Idx with the series of designators in [First, Last).
Definition Expr.cpp:4915
MutableArrayRef< Designator > designators()
Definition Expr.h:5801
void setGNUSyntax(bool GNU)
Definition Expr.h:5833
child_range children()
Definition Expr.h:5873
void setEqualOrColonLoc(SourceLocation L)
Definition Expr.h:5824
Expr * getArrayIndex(const Designator &D) const
Definition Expr.cpp:4898
Designator * getDesignator(unsigned Idx)
Definition Expr.h:5809
ArrayRef< Designator > designators() const
Definition Expr.h:5805
Expr * getInit() const
Retrieve the initializer value.
Definition Expr.h:5836
unsigned size() const
Returns the number of designators in this initializer.
Definition Expr.h:5798
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.cpp:4877
void setDesignators(const ASTContext &C, const Designator *Desigs, unsigned NumDesigs)
Definition Expr.cpp:4860
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.cpp:4894
SourceLocation getEqualOrColonLoc() const
Retrieve the location of the '=' that precedes the initializer value itself, if present.
Definition Expr.h:5823
unsigned getNumSubExprs() const
Retrieve the total number of subexpressions in this designated initializer expression,...
Definition Expr.h:5848
static bool classof(const Stmt *T)
Definition Expr.h:5868
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.cpp:4958
DesignatedInitUpdateExpr(EmptyShell Empty)
Definition Expr.h:5940
DesignatedInitUpdateExpr(const ASTContext &C, SourceLocation lBraceLoc, Expr *baseExprs, SourceLocation rBraceLoc)
Definition Expr.cpp:4941
static bool classof(const Stmt *T)
Definition Expr.h:5946
void setBase(Expr *Base)
Definition Expr.h:5951
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.cpp:4962
const_child_range children() const
Definition Expr.h:5963
void setUpdater(Expr *Updater)
Definition Expr.h:5956
InitListExpr * getUpdater() const
Definition Expr.h:5953
Designator - A designator in a C99 designated initializer.
Definition Designator.h:38
child_range children()
Definition Expr.h:6613
IdentifierInfo & getAccessor() const
Definition Expr.h:6602
void setAccessorLoc(SourceLocation L)
Definition Expr.h:6606
SourceLocation AccessorLoc
Definition Expr.h:6584
void setAccessor(IdentifierInfo *II)
Definition Expr.h:6603
const Expr * getBase() const
Definition Expr.h:6598
const_child_range children() const
Definition Expr.h:6614
SourceLocation getAccessorLoc() const
Definition Expr.h:6605
IdentifierInfo * Accessor
Definition Expr.h:6583
void setBase(Expr *E)
Definition Expr.h:6600
ElementAccessExprBase(StmtClass SC, EmptyShell Empty)
Definition Expr.h:6594
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:6611
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:6608
ElementAccessExprBase(StmtClass SC, QualType Ty, ExprValueKind VK, Expr *Base, IdentifierInfo &Accessor, SourceLocation Loc, ExprObjectKind OK)
Definition Expr.h:6586
BaseTy::pointer operator->() const
Definition Expr.h:5207
ChildElementIter & operator++()
Definition Expr.h:5209
BaseTy::reference operator*() const
Definition Expr.h:5195
bool operator==(ChildElementIter Other) const
Definition Expr.h:5220
unsigned getStartingElementPos() const
Definition Expr.h:5167
ChildElementIter< false > begin()
Definition Expr.h:5252
bool doForEachDataElement(Call &&C, unsigned &StartingIndexInArray, Targs &&...Fargs) const
Definition Expr.h:5259
llvm::iterator_range< ChildElementIter< false > > fake_child_range
Definition Expr.h:5226
SourceLocation getEndLoc() const
Definition Expr.h:5161
ChildElementIter< true > begin() const
Definition Expr.h:5254
StringLiteral * getDataStringLiteral() const
Definition Expr.h:5163
const_fake_child_range underlying_data_elements() const
Definition Expr.h:5234
EmbedExpr(EmptyShell Empty)
Definition Expr.h:5157
child_range children()
Definition Expr.h:5240
EmbedDataStorage * getData() const
Definition Expr.h:5165
EmbedExpr(const ASTContext &Ctx, SourceLocation Loc, EmbedDataStorage *Data, unsigned Begin, unsigned NumOfElements)
Definition Expr.cpp:2403
StringRef getFileName() const
Definition Expr.h:5164
fake_child_range underlying_data_elements()
Definition Expr.h:5229
SourceLocation getBeginLoc() const
Definition Expr.h:5160
SourceLocation getLocation() const
Definition Expr.h:5159
static bool classof(const Stmt *T)
Definition Expr.h:5248
llvm::iterator_range< ChildElementIter< true > > const_fake_child_range
Definition Expr.h:5227
friend class ASTStmtReader
Definition Expr.h:5271
const_child_range children() const
Definition Expr.h:5244
size_t getDataElementCount() const
Definition Expr.h:5168
An instance of this object exists for each enum constant that is defined.
Definition Decl.h:3557
TypeSourceInfo * getTypeInfoAsWritten() const
getTypeInfoAsWritten - Returns the type source info for the type that this expression is casting to.
Definition Expr.h:3961
ExplicitCastExpr(StmtClass SC, QualType exprTy, ExprValueKind VK, CastKind kind, Expr *op, unsigned PathSize, bool HasFPFeatures, TypeSourceInfo *writtenTy)
Definition Expr.h:3945
void setTypeInfoAsWritten(TypeSourceInfo *writtenTy)
Definition Expr.h:3962
static bool classof(const Stmt *T)
Definition Expr.h:3968
ExplicitCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize, bool HasFPFeatures)
Construct an empty explicit cast.
Definition Expr.h:3954
QualType getTypeAsWritten() const
getTypeAsWritten - Returns the type that this expression is casting to, as written in the source code...
Definition Expr.h:3966
The return type of classify().
Definition Expr.h:339
bool isLValue() const
Definition Expr.h:390
bool isPRValue() const
Definition Expr.h:393
bool isXValue() const
Definition Expr.h:391
ModifiableType
The results of modification testing.
Definition Expr.h:358
ModifiableType getModifiable() const
Definition Expr.h:386
bool isGLValue() const
Definition Expr.h:392
Kinds getKind() const
Definition Expr.h:385
Kinds
The various classification results. Most of these mean prvalue.
Definition Expr.h:342
static Classification makeSimpleLValue()
Create a simple, modifiable lvalue.
Definition Expr.h:398
bool isRValue() const
Definition Expr.h:394
bool isModifiable() const
Definition Expr.h:395
This represents one expression.
Definition Expr.h:112
LValueClassification
Definition Expr.h:289
@ LV_DuplicateMatrixComponents
Definition Expr.h:294
@ LV_ArrayTemporary
Definition Expr.h:300
@ LV_DuplicateVectorComponents
Definition Expr.h:293
@ LV_ClassTemporary
Definition Expr.h:299
@ LV_InvalidMessageExpression
Definition Expr.h:296
@ LV_NotObjectType
Definition Expr.h:291
@ LV_MemberFunction
Definition Expr.h:297
@ LV_InvalidExpression
Definition Expr.h:295
@ LV_IncompleteVoidType
Definition Expr.h:292
@ LV_Valid
Definition Expr.h:290
@ LV_SubObjCPropertySetting
Definition Expr.h:298
Classification ClassifyModifiable(ASTContext &Ctx, SourceLocation &Loc) const
ClassifyModifiable - Classify this expression according to the C++11 expression taxonomy,...
Definition Expr.h:427
Expr(StmtClass SC, QualType T, ExprValueKind VK, ExprObjectKind OK)
Definition Expr.h:123
Expr(StmtClass SC, EmptyShell)
Construct an empty expression.
Definition Expr.h:133
bool EvaluateAsInt(EvalResult &Result, const ASTContext &Ctx, SideEffectsKind AllowSideEffects=SE_NoSideEffects, bool InConstantContext=false) const
EvaluateAsInt - Return true if this is a constant which we can fold and convert to an integer,...
EnumConstantDecl * getEnumConstantDecl()
If this expression refers to an enum constant, retrieve its declaration.
Definition Expr.cpp:4289
static bool isPotentialConstantExpr(const FunctionDecl *FD, SmallVectorImpl< PartialDiagnosticAt > &Diags)
isPotentialConstantExpr - Return true if this function's definition might be usable in a constant exp...
bool isReadIfDiscardedInCPlusPlus11() const
Determine whether an lvalue-to-rvalue conversion should implicitly be applied to this expression if i...
Definition Expr.cpp:2576
bool isXValue() const
Definition Expr.h:286
bool isIntegerConstantExpr(const ASTContext &Ctx) const
static bool isPotentialConstantExprUnevaluated(Expr *E, const FunctionDecl *FD, SmallVectorImpl< PartialDiagnosticAt > &Diags)
isPotentialConstantExprUnevaluated - Return true if this expression might be usable in a constant exp...
bool isGLValue() const
Definition Expr.h:287
Expr * IgnoreParenNoopCasts(const ASTContext &Ctx) LLVM_READONLY
Skip past any parentheses and casts which do not change the value (including ptr->int casts of the sa...
Definition Expr.cpp:3128
isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx, SourceLocation *Loc=nullptr) const
isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type, does not have an incomplet...
SideEffectsKind
Definition Expr.h:682
@ SE_AllowSideEffects
Allow any unmodeled side effect.
Definition Expr.h:686
@ SE_NoSideEffects
Strictly evaluate the expression.
Definition Expr.h:683
@ SE_AllowUndefinedBehavior
Allow UB that we can give a value, but not arbitrary unmodeled side effects.
Definition Expr.h:684
static bool classof(const Stmt *T)
Definition Expr.h:1042
static QualType findBoundMemberType(const Expr *expr)
Given an expression of bound-member type, find the type of the member.
Definition Expr.cpp:3057
Expr & operator=(const Expr &)=delete
static std::pair< const NamedDecl *, const WarnUnusedResultAttr * > getUnusedResultAttrImpl(const Decl *Callee, QualType ReturnType)
Returns the WarnUnusedResultAttr that is declared on the callee or its return type declaration,...
Definition Expr.cpp:1642
bool EvaluateCharRangeAsString(std::string &Result, const Expr *SizeExpression, const Expr *PtrExpression, ASTContext &Ctx, EvalResult &Status) const
bool isImplicitCXXThis() const
Whether this expression is an implicit reference to 'this' in C++.
Definition Expr.cpp:3306
const Expr * IgnoreParenNoopCasts(const ASTContext &Ctx) const
Definition Expr.h:979
llvm::APSInt EvaluateKnownConstIntCheckOverflow(const ASTContext &Ctx, SmallVectorImpl< PartialDiagnosticAt > *Diag=nullptr) const
Expr * IgnoreParenCasts() LLVM_READONLY
Skip past any parentheses and casts which might surround this expression until reaching a fixed point...
Definition Expr.cpp:3106
void setType(QualType t)
Definition Expr.h:145
bool isUnusedResultAWarning(const Expr *&WarnExpr, SourceLocation &Loc, SourceRange &R1, SourceRange &R2, ASTContext &Ctx) const
isUnusedResultAWarning - Return true if this immediate expression should be warned about if the resul...
Definition Expr.cpp:2642
LValueClassification ClassifyLValue(ASTContext &Ctx) const
Reasons why an expression might not be an l-value.
bool isValueDependent() const
Determines whether the value of this expression depends on.
Definition Expr.h:177
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
Definition Expr.h:447
bool refersToVectorElement() const
Returns whether this expression refers to a vector element.
Definition Expr.cpp:4296
bool isTypeDependent() const
Determines whether the type of this expression depends on.
Definition Expr.h:194
llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx) const
EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded integer.
bool containsUnexpandedParameterPack() const
Whether this expression contains an unexpanded parameter pack (for C++11 variadic templates).
Definition Expr.h:241
Expr * IgnoreParenLValueCasts() LLVM_READONLY
Skip past any parentheses and lvalue casts which might surround this expression until reaching a fixe...
Definition Expr.cpp:3118
FPOptions getFPFeaturesInEffect(const LangOptions &LO) const
Returns the set of floating point options that apply to this expression.
Definition Expr.cpp:4002
const CXXRecordDecl * getBestDynamicClassType() const
For an expression of class type or pointer to class type, return the most derived class decl the expr...
Definition Expr.cpp:70
Expr * IgnoreParenImpCasts() LLVM_READONLY
Skip past any parentheses and implicit casts which might surround this expression until reaching a fi...
Definition Expr.cpp:3101
Expr * IgnoreImplicit() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point.
Definition Expr.cpp:3089
Expr * IgnoreConversionOperatorSingleStep() LLVM_READONLY
Skip conversion operators.
Definition Expr.cpp:3110
bool containsErrors() const
Whether this expression contains subexpressions which had errors.
Definition Expr.h:246
bool EvaluateAsFloat(llvm::APFloat &Result, const ASTContext &Ctx, SideEffectsKind AllowSideEffects=SE_NoSideEffects, bool InConstantContext=false) const
EvaluateAsFloat - Return true if this is a constant which we can fold and convert to a floating point...
bool isObjCSelfExpr() const
Check if this expression is the ObjC 'self' implicit parameter.
Definition Expr.cpp:4224
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
Definition Expr.cpp:3097
bool isFlexibleArrayMemberLike(const ASTContext &Context, LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel, bool IgnoreTemplateOrMacroSubstitution=false) const
Check whether this array fits the idiom of a flexible array member, depending on the value of -fstric...
Definition Expr.cpp:212
bool hasPlaceholderType(BuiltinType::Kind K) const
Returns whether this expression has a specific placeholder type.
Definition Expr.h:531
bool EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx, bool InConstantContext=false) const
EvaluateAsLValue - Evaluate an expression to see if we can fold it to an lvalue with link time known ...
bool EvaluateAsInitializer(const ASTContext &Ctx, const VarDecl *VD, EvalResult &Result, bool IsConstantInitializer) const
EvaluateAsInitializer - Evaluate an expression as if it were the initializer of the given declaration...
bool EvaluateAsFixedPoint(EvalResult &Result, const ASTContext &Ctx, SideEffectsKind AllowSideEffects=SE_NoSideEffects, bool InConstantContext=false) const
EvaluateAsFixedPoint - Return true if this is a constant which we can fold and convert to a fixed poi...
bool isEvaluatable(const ASTContext &Ctx, SideEffectsKind AllowSideEffects=SE_NoSideEffects) const
isEvaluatable - Call EvaluateAsRValue to see if this expression can be constant folded without side-e...
Expr * IgnoreParenBaseCasts() LLVM_READONLY
Skip past any parentheses and derived-to-base casts until reaching a fixed point.
Definition Expr.cpp:3123
bool isConstantInitializer(ASTContext &Ctx, bool ForRef=false, const Expr **Culprit=nullptr) const
Returns true if this expression can be emitted to IR as a constant, and thus can be used as a constan...
Definition Expr.cpp:3358
bool isPRValue() const
Definition Expr.h:285
bool isLValue() const
isLValue - True if this expression is an "l-value" according to the rules of the current language.
Definition Expr.h:284
static bool hasAnyTypeDependentArguments(ArrayRef< Expr * > Exprs)
hasAnyTypeDependentArguments - Determines if any of the expressions in Exprs is type-dependent.
Definition Expr.cpp:3350
FieldDecl * getSourceBitField()
If this expression refers to a bit-field, retrieve the declaration of that bit-field.
Definition Expr.cpp:4242
NullPointerConstantValueDependence
Enumeration used to describe how isNullPointerConstant() should cope with value-dependent expressions...
Definition Expr.h:836
@ NPC_ValueDependentIsNull
Specifies that a value-dependent expression of integral or dependent type should be considered a null...
Definition Expr.h:842
@ NPC_NeverValueDependent
Specifies that the expression should never be value-dependent.
Definition Expr.h:838
@ NPC_ValueDependentIsNotNull
Specifies that a value-dependent expression should be considered to never be a null pointer constant.
Definition Expr.h:846
Expr * IgnoreUnlessSpelledInSource()
Skip past any invisible AST nodes which might surround this statement, such as ExprWithCleanups or Im...
Definition Expr.cpp:3154
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
Definition Expr.h:454
bool EvaluateAsRValue(EvalResult &Result, const ASTContext &Ctx, bool InConstantContext=false) const
EvaluateAsRValue - Return true if this is a constant which we can fold to an rvalue using any crazy t...
Expr * IgnoreCasts() LLVM_READONLY
Skip past any casts which might surround this expression until reaching a fixed point.
Definition Expr.cpp:3085
Decl * getReferencedDeclOfCallee()
Definition Expr.cpp:1552
Expr * IgnoreImplicitAsWritten() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point.
Definition Expr.cpp:3093
std::optional< uint64_t > tryEvaluateStrLen(const ASTContext &Ctx) const
If the current Expr is a pointer, this will try to statically determine the strlen of the string poin...
bool HasSideEffects(const ASTContext &Ctx, bool IncludePossibleEffects=true) const
HasSideEffects - This routine returns true for all those expressions which have any effect other than...
Definition Expr.cpp:3700
bool EvaluateAsConstantExpr(EvalResult &Result, const ASTContext &Ctx, ConstantExprKind Kind=ConstantExprKind::Normal) const
Evaluate an expression that is required to be a constant expression.
bool isInstantiationDependent() const
Whether this expression is instantiation-dependent, meaning that it depends in some way on.
Definition Expr.h:223
const Expr * getBestDynamicClassTypeExpr() const
Get the inner expression that determines the best dynamic class.
Definition Expr.cpp:45
const Expr * IgnoreUnlessSpelledInSource() const
Definition Expr.h:873
std::optional< llvm::APSInt > getIntegerConstantExpr(const ASTContext &Ctx, bool AllowRelaxedEval=false) const
isIntegerConstantExpr - Return the value if this expression is a valid integer constant expression.
std::optional< std::string > tryEvaluateString(ASTContext &Ctx) const
If the current Expr can be evaluated to a pointer to a null-terminated constant string,...
Expr * IgnoreImpCasts() LLVM_READONLY
Skip past any implicit casts which might surround this expression until reaching a fixed point.
Definition Expr.cpp:3081
NullPointerConstantKind
Enumeration used to describe the kind of Null pointer constant returned from isNullPointerConstant().
Definition Expr.h:813
@ NPCK_ZeroExpression
Expression is a Null pointer constant built from a zero integer expression that is not a simple,...
Definition Expr.h:822
@ NPCK_ZeroLiteral
Expression is a Null pointer constant built from a literal zero.
Definition Expr.h:825
@ NPCK_CXX11_nullptr
Expression is a C++11 nullptr.
Definition Expr.h:828
@ NPCK_GNUNull
Expression is a GNU-style __null constant.
Definition Expr.h:831
@ NPCK_NotNull
Expression is not a Null pointer constant.
Definition Expr.h:815
bool EvaluateAsBooleanCondition(bool &Result, const ASTContext &Ctx, bool InConstantContext=false) const
EvaluateAsBooleanCondition - Return true if this is a constant which we can fold and convert to a boo...
bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const
Determine whether the result of this expression is a temporary object of the given class type.
Definition Expr.cpp:3264
NullPointerConstantKind isNullPointerConstant(ASTContext &Ctx, NullPointerConstantValueDependence NPC) const
isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to a Null pointer constant.
Definition Expr.cpp:4081
QualType getEnumCoercedType(const ASTContext &Ctx) const
If this expression is an enumeration constant, return the enumeration type under which said constant ...
Definition Expr.cpp:272
bool isBoundMemberFunction(ASTContext &Ctx) const
Returns true if this expression is a bound member function.
Definition Expr.cpp:3051
Expr()=delete
ConstantExprKind
Definition Expr.h:760
@ ClassTemplateArgument
A class template argument. Such a value is used for code generation.
Definition Expr.h:768
@ Normal
An integer constant expression (an array bound, enumerator, case value, bit-field width,...
Definition Expr.h:763
@ ImmediateInvocation
An immediate invocation.
Definition Expr.h:772
@ NonClassTemplateArgument
A non-class template argument.
Definition Expr.h:766
std::optional< uint64_t > tryEvaluateObjectSize(const ASTContext &Ctx, unsigned Type) const
If the current Expr is a pointer, this will try to statically determine the number of bytes available...
void setValueKind(ExprValueKind Cat)
setValueKind - Set the value kind produced by this expression.
Definition Expr.h:464
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition Expr.cpp:283
const FieldDecl * getSourceBitField() const
Definition Expr.h:497
static bool isSameComparisonOperand(const Expr *E1, const Expr *E2)
Checks that the two Expr's will refer to the same value as a comparison operand.
Definition Expr.cpp:4333
void setObjectKind(ExprObjectKind Cat)
setObjectKind - Set the object kind produced by this expression.
Definition Expr.h:467
friend class ASTImporter
Definition Expr.h:140
bool refersToMatrixElement() const
Returns whether this expression refers to a matrix element.
Definition Expr.h:517
bool refersToBitField() const
Returns true if this expression is a gl-value that potentially refers to a bit-field.
Definition Expr.h:479
bool isDefaultArgument() const
Determine whether this expression is a default function argument.
Definition Expr.cpp:3225
isModifiableLvalueResult
Definition Expr.h:305
@ MLV_DuplicateVectorComponents
Definition Expr.h:309
@ MLV_LValueCast
Definition Expr.h:312
@ MLV_InvalidMessageExpression
Definition Expr.h:321
@ MLV_DuplicateMatrixComponents
Definition Expr.h:310
@ MLV_ConstQualifiedField
Definition Expr.h:315
@ MLV_InvalidExpression
Definition Expr.h:311
@ MLV_IncompleteType
Definition Expr.h:313
@ MLV_Valid
Definition Expr.h:306
@ MLV_ConstQualified
Definition Expr.h:314
@ MLV_NoSetterProperty
Definition Expr.h:318
@ MLV_ArrayTemporary
Definition Expr.h:323
@ MLV_SubObjCPropertySetting
Definition Expr.h:320
@ MLV_ConstAddrSpace
Definition Expr.h:316
@ MLV_MemberFunction
Definition Expr.h:319
@ MLV_NotObjectType
Definition Expr.h:307
@ MLV_ArrayType
Definition Expr.h:317
@ MLV_ClassTemporary
Definition Expr.h:322
@ MLV_IncompleteVoidType
Definition Expr.h:308
Classification Classify(ASTContext &Ctx) const
Classify - Classify this expression according to the C++11 expression taxonomy.
Definition Expr.h:415
QualType getType() const
Definition Expr.h:144
const Decl * getReferencedDeclOfCallee() const
Definition Expr.h:502
bool hasNonTrivialCall(const ASTContext &Ctx) const
Determine whether this expression involves a call to any function that is not trivial.
Definition Expr.cpp:4069
bool isOrdinaryOrBitFieldObject() const
Definition Expr.h:458
bool hasPlaceholderType() const
Returns whether this expression has a placeholder type.
Definition Expr.h:526
bool refersToGlobalRegisterVar() const
Returns whether this expression refers to a global register variable.
Definition Expr.cpp:4321
friend class ASTStmtReader
Definition Expr.h:141
bool isCXX98IntegralConstantExpr(const ASTContext &Ctx) const
isCXX98IntegralConstantExpr - Return true if this expression is an integral constant expression in C+...
const ValueDecl * getAsBuiltinConstantDeclRef(const ASTContext &Context) const
If this expression is an unambiguous reference to a single declaration, in the style of __builtin_fun...
Definition Expr.cpp:232
bool isOBJCGCCandidate(ASTContext &Ctx) const
isOBJCGCCandidate - Return true if this expression may be used in a read/ write barrier.
Definition Expr.cpp:3012
static ExprValueKind getValueKindForType(QualType T)
getValueKindForType - Given a formal return or parameter type, give its value kind.
Definition Expr.h:437
bool EvaluateWithSubstitution(APValue &Value, ASTContext &Ctx, const FunctionDecl *Callee, ArrayRef< const Expr * > Args, const Expr *This=nullptr) const
EvaluateWithSubstitution - Evaluate an expression as if from the context of a call to the given funct...
const Expr * skipRValueSubobjectAdjustments() const
Definition Expr.h:1031
bool isKnownToHaveBooleanValue(bool Semantic=true) const
isKnownToHaveBooleanValue - Return true if this is an integer expression that is known to return 0 or...
Definition Expr.cpp:138
bool isCXX11ConstantExpr(const ASTContext &Ctx, APValue *Result=nullptr, bool AllowRelaxedEval=false) const
isCXX11ConstantExpr - Return true if this expression is a constant expression in C++11.
void setDependence(ExprDependence Deps)
Each concrete expr subclass is expected to compute its dependence and call this in the constructor.
Definition Expr.h:137
Expr(const Expr &)=delete
Expr(Expr &&)=delete
void EvaluateForOverflow(const ASTContext &Ctx) const
ExprDependence getDependence() const
Definition Expr.h:164
Expr & operator=(Expr &&)=delete
const EnumConstantDecl * getEnumConstantDecl() const
Definition Expr.h:493
const ObjCPropertyRefExpr * getObjCProperty() const
If this expression is an l-value for an Objective C property, find the underlying property reference ...
Definition Expr.cpp:4205
ExtVectorElementExpr(QualType Ty, ExprValueKind VK, Expr *Base, IdentifierInfo &Accessor, SourceLocation Loc)
Definition Expr.h:6629
ExtVectorElementExpr(EmptyShell Empty)
Build an empty vector element expression.
Definition Expr.h:6636
bool containsDuplicateElements() const
containsDuplicateElements - Return true if any element access is repeated.
Definition Expr.cpp:4467
bool isArrow() const
isArrow - Return true if the base expression is a pointer to vector, return false if the base express...
Definition Expr.cpp:4449
void getEncodedElementAccess(SmallVectorImpl< uint32_t > &Elts) const
getEncodedElementAccess - Encode the elements accessed into an llvm aggregate Constant of ConstantInt...
Definition Expr.cpp:4562
static bool classof(const Stmt *T)
Definition Expr.h:6654
unsigned getNumElements() const
getNumElements - Get the number of components being selected.
Definition Expr.cpp:4453
Represents difference between two FPOptions values.
FPOptions applyOverrides(FPOptions Base)
bool requiresTrailingStorage() const
static FPOptions defaultWithoutTrailingStorage(const LangOptions &LO)
Return the default value of FPOptions that's used when trailing storage isn't required.
bool allowFPContractWithinStatement() const
Represents a member of a struct/union/class.
Definition Decl.h:3294
SourceLocation getLocation() const
Retrieve the location of the literal.
Definition Expr.h:1592
std::string getValueAsString(unsigned Radix) const
Definition Expr.cpp:1016
unsigned getScale() const
Definition Expr.h:1596
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:1588
const_child_range children() const
Definition Expr.h:1609
void setLocation(SourceLocation Location)
Definition Expr.h:1594
llvm::APInt getValue() const
Returns an internal integer representation of the literal.
Definition Expr.h:1586
static bool classof(const Stmt *T)
Definition Expr.h:1599
void setScale(unsigned S)
Definition Expr.h:1597
static FixedPointLiteral * CreateFromRawInt(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l, unsigned Scale)
Definition Expr.cpp:1003
child_range children()
Definition Expr.h:1606
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:1589
SourceLocation getLocation() const
Definition Expr.h:1718
llvm::APFloatBase::Semantics getRawSemantics() const
Get a raw enumeration value representing the floating-point semantics of this literal (32-bit IEEE,...
Definition Expr.h:1687
child_range children()
Definition Expr.h:1729
const llvm::fltSemantics & getSemantics() const
Return the APFloat semantics this literal uses.
Definition Expr.h:1699
void setValue(const ASTContext &C, const llvm::APFloat &Val)
Definition Expr.h:1680
const_child_range children() const
Definition Expr.h:1732
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:1721
void setRawSemantics(llvm::APFloatBase::Semantics Sem)
Set the raw enumeration value representing the floating-point semantics of this literal (32-bit IEEE,...
Definition Expr.h:1694
double getValueAsApproximateDouble() const
getValueAsApproximateDouble - This returns the value as an inaccurate double.
Definition Expr.cpp:1095
llvm::APFloat getValue() const
Definition Expr.h:1677
void setExact(bool E)
Definition Expr.h:1711
static bool classof(const Stmt *T)
Definition Expr.h:1724
void setLocation(SourceLocation L)
Definition Expr.h:1719
bool isExact() const
Definition Expr.h:1710
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:1722
void setSemantics(const llvm::fltSemantics &Sem)
Set the APFloat semantics this literal uses.
Definition Expr.h:1706
Expr * getSubExpr()
Definition Expr.h:1074
FullExpr(StmtClass SC, EmptyShell Empty)
Definition Expr.h:1070
void setSubExpr(Expr *E)
As with any mutator of the AST, be very careful when modifying an existing AST to preserve its invari...
Definition Expr.h:1078
Stmt * SubExpr
Definition Expr.h:1062
static bool classof(const Stmt *T)
Definition Expr.h:1080
FullExpr(StmtClass SC, Expr *subexpr)
Definition Expr.h:1064
const Expr * getSubExpr() const
Definition Expr.h:1073
Represents a function declaration or definition.
Definition Decl.h:2058
Represents a prototype with parameter type info, e.g.
Definition TypeBase.h:5421
SourceLocation getTokenLocation() const
getTokenLocation - The location of the __null token.
Definition Expr.h:4948
static bool classof(const Stmt *T)
Definition Expr.h:4954
child_range children()
Definition Expr.h:4959
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:4951
const_child_range children() const
Definition Expr.h:4962
GNUNullExpr(QualType Ty, SourceLocation Loc)
Definition Expr.h:4939
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:4952
GNUNullExpr(EmptyShell Empty)
Build an empty GNU __null expression.
Definition Expr.h:4945
void setTokenLocation(SourceLocation L)
Definition Expr.h:4949
SourceLocation getBeginLoc() const
Definition Expr.h:6559
AssociationTy< false > Association
Definition Expr.h:6432
TypeSourceInfo * getControllingType()
Return the controlling type of this generic selection expression.
Definition Expr.h:6476
static bool classof(const Stmt *T)
Definition Expr.h:6562
const Expr * getControllingExpr() const
Definition Expr.h:6468
unsigned getNumAssocs() const
The number of association expressions.
Definition Expr.h:6441
const_association_range associations() const
Definition Expr.h:6543
AssociationIteratorTy< true > ConstAssociationIterator
Definition Expr.h:6435
SourceLocation getEndLoc() const
Definition Expr.h:6560
ArrayRef< Expr * > getAssocExprs() const
Definition Expr.h:6496
bool isExprPredicate() const
Whether this generic selection uses an expression as its controlling argument.
Definition Expr.h:6457
ConstAssociation getAssociation(unsigned I) const
Definition Expr.h:6520
association_range associations()
Definition Expr.h:6532
AssociationTy< true > ConstAssociation
Definition Expr.h:6433
SourceLocation getGenericLoc() const
Definition Expr.h:6554
SourceLocation getRParenLoc() const
Definition Expr.h:6558
unsigned getResultIndex() const
The zero-based index of the result expression's generic association in the generic selection's associ...
Definition Expr.h:6446
Expr * getResultExpr()
Return the result expression of this controlling expression.
Definition Expr.h:6485
AssociationIteratorTy< false > AssociationIterator
Definition Expr.h:6434
SourceLocation getDefaultLoc() const
Definition Expr.h:6557
llvm::iterator_range< AssociationIterator > association_range
Definition Expr.h:6436
const Expr * getResultExpr() const
Definition Expr.h:6490
bool isResultDependent() const
Whether this generic selection is result-dependent.
Definition Expr.h:6453
child_range children()
Definition Expr.h:6566
friend class ASTStmtWriter
Definition Expr.h:6201
const_child_range children() const
Definition Expr.h:6570
Association getAssociation(unsigned I)
Return the Ith association expression with its TypeSourceInfo, bundled together in GenericSelectionEx...
Definition Expr.h:6509
friend class ASTStmtReader
Definition Expr.h:6200
bool isTypePredicate() const
Whether this generic selection uses a type as its controlling argument.
Definition Expr.h:6459
const TypeSourceInfo * getControllingType() const
Definition Expr.h:6479
llvm::iterator_range< ConstAssociationIterator > const_association_range
Definition Expr.h:6437
static GenericSelectionExpr * CreateEmpty(const ASTContext &Context, unsigned NumAssocs)
Create an empty generic selection expression for deserialization.
Definition Expr.cpp:4787
Expr * getControllingExpr()
Return the controlling expression of this generic selection expression.
Definition Expr.h:6464
ArrayRef< TypeSourceInfo * > getAssocTypeSourceInfos() const
Definition Expr.h:6501
This class represents temporary values used to represent inout and out arguments in HLSL.
Definition Expr.h:7414
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:7479
const OpaqueValueExpr * getCastedTemporary() const
Definition Expr.h:7465
const OpaqueValueExpr * getOpaqueArgLValue() const
Definition Expr.h:7446
Expr * getWritebackCast()
Definition Expr.h:7463
bool isInOut() const
returns true if the parameter is inout and false if the parameter is out.
Definition Expr.h:7473
static HLSLOutArgExpr * CreateEmpty(const ASTContext &Ctx)
Definition Expr.cpp:5674
static bool classof(const Stmt *T)
Definition Expr.h:7483
Expr * getArgLValue()
Definition Expr.h:7458
child_range children()
Definition Expr.h:7488
OpaqueValueExpr * getCastedTemporary()
Definition Expr.h:7468
const Expr * getWritebackCast() const
Definition Expr.h:7460
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:7475
const Expr * getArgLValue() const
Return the l-value expression that was written as the argument in source.
Definition Expr.h:7455
OpaqueValueExpr * getOpaqueArgLValue()
Definition Expr.h:7449
friend class ASTStmtReader
Definition Expr.h:7415
One of these records is kept for each identifier that is lexed.
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:1761
ImaginaryLiteral(Expr *val, QualType Ty)
Definition Expr.h:1745
const Expr * getSubExpr() const
Definition Expr.h:1754
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:1758
ImaginaryLiteral(EmptyShell Empty)
Build an empty imaginary literal.
Definition Expr.h:1751
child_range children()
Definition Expr.h:1768
static bool classof(const Stmt *T)
Definition Expr.h:1763
const_child_range children() const
Definition Expr.h:1769
void setSubExpr(Expr *E)
Definition Expr.h:1756
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition Expr.h:3864
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:3911
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:3908
static ImplicitCastExpr * CreateEmpty(const ASTContext &Context, unsigned PathSize, bool HasFPFeatures)
Definition Expr.cpp:2104
ImplicitCastExpr(OnStack_t _, QualType ty, CastKind kind, Expr *op, ExprValueKind VK, FPOptionsOverride FPO)
Definition Expr.h:3887
bool isPartOfExplicitCast() const
Definition Expr.h:3895
friend class CastExpr
Definition Expr.h:3920
static bool classof(const Stmt *T)
Definition Expr.h:3915
void setIsPartOfExplicitCast(bool PartOfExplicitCast)
Definition Expr.h:3896
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:6090
static bool classof(const Stmt *T)
Definition Expr.h:6085
child_range children()
Definition Expr.h:6093
ImplicitValueInitExpr(EmptyShell Empty)
Construct an empty implicit value initialization.
Definition Expr.h:6082
const_child_range children() const
Definition Expr.h:6096
ImplicitValueInitExpr(QualType ty)
Definition Expr.h:6076
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:6089
Describes an C or C++ initializer list.
Definition Expr.h:5319
const_reverse_iterator rend() const
Definition Expr.h:5540
bool hasArrayFiller() const
Return true if this is an array initializer and its array "filler" has been set.
Definition Expr.h:5432
void setSyntacticForm(InitListExpr *Init)
Definition Expr.h:5493
InitExprsTy::reverse_iterator reverse_iterator
Definition Expr.h:5530
InitExprsTy::const_reverse_iterator const_reverse_iterator
Definition Expr.h:5531
void markError()
Mark the semantic form of the InitListExpr as error when the semantic analysis fails.
Definition Expr.h:5394
bool hasDesignatedInit() const
Determine whether this initializer list contains a designated initializer.
Definition Expr.h:5435
bool isTransparent() const
Is this a transparent initializer list (that is, an InitListExpr that is purely syntactic,...
Definition Expr.cpp:2473
void resizeInits(const ASTContext &Context, unsigned NumInits)
Specify the number of initializers.
Definition Expr.cpp:2433
bool isStringLiteralInit() const
Is this an initializer for an array of characters, initialized by a string literal or an @encode?
Definition Expr.cpp:2459
FieldDecl * getInitializedFieldInUnion()
If this initializes a union, specifies which field in the union to initialize.
Definition Expr.h:5446
unsigned getNumInits() const
Definition Expr.h:5352
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.cpp:2507
bool isSemanticForm() const
Definition Expr.h:5482
void setInit(unsigned Init, Expr *expr)
Definition Expr.h:5384
const_iterator begin() const
Definition Expr.h:5534
reverse_iterator rbegin()
Definition Expr.h:5537
const_reverse_iterator rbegin() const
Definition Expr.h:5538
InitExprsTy::const_iterator const_iterator
Definition Expr.h:5529
Expr *const * getInits() const
Retrieve the set of initializers.
Definition Expr.h:5368
SourceLocation getLBraceLoc() const
Definition Expr.h:5477
Expr * updateInit(const ASTContext &C, unsigned Init, Expr *expr)
Updates the initializer at index Init with the new expression expr, and returns the old expression at...
Definition Expr.cpp:2437
void setArrayFiller(Expr *filler)
Definition Expr.cpp:2449
InitListExpr * getSyntacticForm() const
Definition Expr.h:5489
static bool classof(const Stmt *T)
Definition Expr.h:5510
bool hadArrayRangeDesignator() const
Definition Expr.h:5500
Expr * getArrayFiller()
If this initializer list initializes an array with more elements than there are initializers in the l...
Definition Expr.h:5422
iterator end()
Definition Expr.h:5535
bool isExplicit() const
Definition Expr.h:5462
iterator begin()
Definition Expr.h:5533
unsigned getNumInitsWithEmbedExpanded() const
getNumInits but if the list has an EmbedExpr inside includes full length of embedded data.
Definition Expr.h:5356
SourceLocation getRBraceLoc() const
Definition Expr.h:5479
InitListExpr * getSemanticForm() const
Definition Expr.h:5483
const FieldDecl * getInitializedFieldInUnion() const
Definition Expr.h:5449
InitListExpr(const ASTContext &C, SourceLocation lbraceloc, ArrayRef< Expr * > initExprs, SourceLocation rbraceloc, bool isExplicit)
Definition Expr.cpp:2415
friend class ASTStmtWriter
Definition Expr.h:5543
const Expr * getInit(unsigned Init) const
Definition Expr.h:5374
InitListExpr(EmptyShell Empty)
Build an empty initializer list.
Definition Expr.h:5347
void setLBraceLoc(SourceLocation Loc)
Definition Expr.h:5478
const Expr * getArrayFiller() const
Definition Expr.h:5425
const_child_range children() const
Definition Expr.h:5521
bool isIdiomaticZeroInitializer(const LangOptions &LangOpts) const
Is this the zero initializer {0} in a language which considers it idiomatic?
Definition Expr.cpp:2496
reverse_iterator rend()
Definition Expr.h:5539
friend class ASTStmtReader
Definition Expr.h:5542
const_iterator end() const
Definition Expr.h:5536
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.cpp:2525
void setInitializedFieldInUnion(FieldDecl *FD)
Definition Expr.h:5452
bool isSyntacticForm() const
Definition Expr.h:5486
void setRBraceLoc(SourceLocation Loc)
Definition Expr.h:5480
ArrayRef< Expr * > inits() const
Definition Expr.h:5372
InitExprsTy::iterator iterator
Definition Expr.h:5528
void sawArrayRangeDesignator(bool ARD=true)
Definition Expr.h:5503
Expr ** getInits()
Retrieve the set of initializers.
Definition Expr.h:5365
Expr * getInit(unsigned Init)
Definition Expr.h:5379
child_range children()
Definition Expr.h:5515
void reserveInits(const ASTContext &C, unsigned NumInits)
Reserve space for some number of initializers.
Definition Expr.cpp:2428
void setLocation(SourceLocation Location)
Definition Expr.h:1549
child_range children()
Definition Expr.h:1556
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:1544
static bool classof(const Stmt *T)
Definition Expr.h:1551
SourceLocation getLocation() const
Retrieve the location of the literal.
Definition Expr.h:1547
const_child_range children() const
Definition Expr.h:1559
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:1543
Represents the declaration of a label.
Definition Decl.h:524
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition ExprCXX.h:4919
MatrixElementExpr(QualType Ty, ExprValueKind VK, Expr *Base, IdentifierInfo &Accessor, SourceLocation Loc)
Definition Expr.h:6661
bool containsDuplicateElements() const
containsDuplicateElements - Return true if any element access is repeated.
Definition Expr.cpp:4543
void getEncodedElementAccess(SmallVectorImpl< uint32_t > &Elts) const
getEncodedElementAccess - Encode the elements accessed into an llvm aggregate Constant of ConstantInt...
Definition Expr.cpp:4594
unsigned getNumElements() const
getNumElements - Get the number of components being selected.
Definition Expr.cpp:4459
static bool classof(const Stmt *T)
Definition Expr.h:6682
MatrixElementExpr(EmptyShell Empty)
Build an empty matrix element expression.
Definition Expr.h:6668
MatrixSingleSubscriptExpr(Expr *Base, Expr *RowIdx, QualType T, SourceLocation RBracketLoc)
matrix[row]
Definition Expr.h:2817
SourceLocation getRBracketLoc() const
Definition Expr.h:2850
const Expr * getRowIdx() const
Definition Expr.h:2837
const_child_range children() const
Definition Expr.h:2865
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:2840
void setRBracketLoc(SourceLocation L)
Definition Expr.h:2853
MatrixSingleSubscriptExpr(EmptyShell Shell)
Create an empty matrix single-subscript expression.
Definition Expr.h:2829
SourceLocation getExprLoc() const LLVM_READONLY
Definition Expr.h:2846
const Expr * getBase() const
Definition Expr.h:2833
static bool classof(const Stmt *T)
Definition Expr.h:2857
SourceLocation getEndLoc() const
Definition Expr.h:2844
void setColumnIdx(Expr *E)
Definition Expr.h:2916
SourceLocation getEndLoc() const
Definition Expr.h:2922
void setBase(Expr *E)
Definition Expr.h:2904
const Expr * getBase() const
Definition Expr.h:2903
const_child_range children() const
Definition Expr.h:2943
SourceLocation getRBracketLoc() const
Definition Expr.h:2928
SourceLocation getExprLoc() const LLVM_READONLY
Definition Expr.h:2924
MatrixSubscriptExpr(Expr *Base, Expr *RowIdx, Expr *ColumnIdx, QualType T, SourceLocation RBracketLoc)
Definition Expr.h:2881
const Expr * getRowIdx() const
Definition Expr.h:2907
void setRowIdx(Expr *E)
Definition Expr.h:2908
bool isIncomplete() const
Definition Expr.h:2896
MatrixSubscriptExpr(EmptyShell Shell)
Create an empty matrix subscript expression.
Definition Expr.h:2893
static bool classof(const Stmt *T)
Definition Expr.h:2935
child_range children()
Definition Expr.h:2940
const Expr * getColumnIdx() const
Definition Expr.h:2911
void setRBracketLoc(SourceLocation L)
Definition Expr.h:2931
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:2918
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition Expr.h:3375
static MemberExpr * CreateEmpty(const ASTContext &Context, bool HasQualifier, bool HasFoundDecl, bool HasTemplateKWAndArgsInfo, unsigned NumTemplateArgs)
Definition Expr.cpp:1780
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition Expr.h:3547
void setMemberDecl(ValueDecl *D)
Definition Expr.cpp:1795
SourceLocation getMemberLoc() const
getMemberLoc - Return the location of the "member", in X->F, it is the location of 'F'.
Definition Expr.h:3564
void setMemberLoc(SourceLocation L)
Definition Expr.h:3565
void setHadMultipleCandidates(bool V=true)
Sets the flag telling whether this expression refers to a method that was resolved from an overloaded...
Definition Expr.h:3585
SourceLocation getOperatorLoc() const
Definition Expr.h:3557
void setArrow(bool A)
Definition Expr.h:3560
child_range children()
Definition Expr.h:3608
NestedNameSpecifier getQualifier() const
If the member name was qualified, retrieves the nested-name-specifier that precedes the member name.
Definition Expr.h:3486
static bool classof(const Stmt *T)
Definition Expr.h:3603
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding the member name, if any.
Definition Expr.h:3492
NestedNameSpecifierLoc getQualifierLoc() const
If the member name was qualified, retrieves the nested-name-specifier that precedes the member name,...
Definition Expr.h:3477
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
Definition Expr.h:3458
const_child_range children() const
Definition Expr.h:3609
bool hasExplicitTemplateArgs() const
Determines whether the member name was followed by an explicit template argument list.
Definition Expr.h:3519
friend class ASTReader
Definition Expr.h:3376
NonOdrUseReason isNonOdrUse() const
Is this expression a non-odr-use reference, and if so, why?
Definition Expr.h:3599
bool hasQualifier() const
Determines whether this member expression actually had a C++ nested-name-specifier prior to the name ...
Definition Expr.h:3472
void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const
Copies the template arguments (if present) into the given structure.
Definition Expr.h:3523
bool isImplicitAccess() const
Determine whether the base of this explicit is implicit.
Definition Expr.h:3573
const TemplateArgumentLoc * getTemplateArgs() const
Retrieve the template arguments provided as part of this template-id.
Definition Expr.h:3531
bool performsVirtualDispatch(const LangOptions &LO) const
Returns true if virtual dispatch is performed.
Definition Expr.h:3593
Expr * getBase() const
Definition Expr.h:3452
unsigned getNumTemplateArgs() const
Retrieve the number of template arguments provided as part of this template-id.
Definition Expr.h:3540
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition Expr.h:3508
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.cpp:1816
void setBase(Expr *E)
Definition Expr.h:3451
friend class ASTStmtWriter
Definition Expr.h:3378
static MemberExpr * CreateImplicit(const ASTContext &C, Expr *Base, bool IsArrow, ValueDecl *MemberDecl, QualType T, ExprValueKind VK, ExprObjectKind OK)
Create an implicit MemberExpr, with no location, qualifier, template arguments, and so on.
Definition Expr.h:3436
bool hadMultipleCandidates() const
Returns true if this member expression refers to a method that was resolved from an overloaded set ha...
Definition Expr.h:3579
bool hasTemplateKeyword() const
Determines whether the member name was preceded by the template keyword.
Definition Expr.h:3515
friend class ASTStmtReader
Definition Expr.h:3377
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.cpp:1802
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition Expr.h:3500
DeclarationNameInfo getMemberNameInfo() const
Retrieve the member declaration name info.
Definition Expr.h:3552
bool isArrow() const
Definition Expr.h:3559
SourceLocation getExprLoc() const LLVM_READONLY
Definition Expr.h:3570
DeclAccessPair getFoundDecl() const
Retrieves the declaration found by lookup.
Definition Expr.h:3462
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition TypeBase.h:3767
This represents a decl that may have a name.
Definition Decl.h:274
A C++ nested-name-specifier augmented with source location information.
NestedNameSpecifier getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
SourceLocation getBeginLoc() const
Retrieve the location of the beginning of this nested-name-specifier.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
static bool classof(const Stmt *T)
Definition Expr.h:5904
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:5909
child_range children()
Definition Expr.h:5912
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:5908
NoInitExpr(QualType ty)
Definition Expr.h:5896
NoInitExpr(EmptyShell Empty)
Definition Expr.h:5901
const_child_range children() const
Definition Expr.h:5915
ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC property.
Definition ExprObjC.h:650
const Expr * getIndexExpr(unsigned Idx) const
Definition Expr.h:2601
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:2613
void setOperatorLoc(SourceLocation L)
Definition Expr.h:2572
static OffsetOfExpr * CreateEmpty(const ASTContext &C, unsigned NumComps, unsigned NumExprs)
Definition Expr.cpp:1674
Expr * getIndexExpr(unsigned Idx)
Definition Expr.h:2597
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:2614
static bool classof(const Stmt *T)
Definition Expr.h:2616
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition Expr.h:2571
const OffsetOfNode & getComponent(unsigned Idx) const
Definition Expr.h:2585
void setIndexExpr(unsigned Idx, Expr *E)
Definition Expr.h:2605
TypeSourceInfo * getTypeSourceInfo() const
Definition Expr.h:2578
void setTypeSourceInfo(TypeSourceInfo *tsi)
Definition Expr.h:2581
const_child_range children() const
Definition Expr.h:2625
child_range children()
Definition Expr.h:2621
void setComponent(unsigned Idx, OffsetOfNode ON)
Definition Expr.h:2589
unsigned getNumExpressions() const
Definition Expr.h:2609
SourceLocation getRParenLoc() const
Return the location of the right parentheses.
Definition Expr.h:2575
void setRParenLoc(SourceLocation R)
Definition Expr.h:2576
friend TrailingObjects
Definition Expr.h:2630
unsigned getNumComponents() const
Definition Expr.h:2593
Helper class for OffsetOfExpr.
Definition Expr.h:2432
const IdentifierInfo * getFieldName() const
For a field or identifier offsetof node, returns the name of the field.
Definition Expr.cpp:1696
unsigned getArrayExprIndex() const
For an array element node, returns the index into the array of expressions.
Definition Expr.h:2490
FieldDecl * getField() const
For a field offsetof node, returns the field.
Definition Expr.h:2496
OffsetOfNode(const CXXBaseSpecifier *Base)
Create an offsetof node that refers into a C++ base class.
Definition Expr.h:2482
OffsetOfNode(SourceLocation LBracketLoc, unsigned Index, SourceLocation RBracketLoc)
Create an offsetof node that refers to an array element.
Definition Expr.h:2466
SourceRange getSourceRange() const LLVM_READONLY
Retrieve the source range that covers this offsetof node.
Definition Expr.h:2517
Kind
The kind of offsetof node we have.
Definition Expr.h:2435
@ Array
An index into an array.
Definition Expr.h:2437
@ Identifier
A field in a dependent type, known only by its name.
Definition Expr.h:2441
@ Field
A field.
Definition Expr.h:2439
@ Base
An implicit indirection through a C++ base class, when the field found is in a base class.
Definition Expr.h:2444
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:2518
Kind getKind() const
Determine what kind of offsetof node this is.
Definition Expr.h:2486
OffsetOfNode(SourceLocation DotLoc, FieldDecl *Field, SourceLocation NameLoc)
Create an offsetof node that refers to a field.
Definition Expr.h:2471
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:2519
CXXBaseSpecifier * getBase() const
For a base class node, returns the base specifier.
Definition Expr.h:2506
OffsetOfNode(SourceLocation DotLoc, const IdentifierInfo *Name, SourceLocation NameLoc)
Create an offsetof node that refers to an identifier.
Definition Expr.h:2476
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition Expr.h:1189
static const OpaqueValueExpr * findInCopyConstruct(const Expr *expr)
Given an expression which invokes a copy constructor — i.e.
Definition Expr.cpp:5177
OpaqueValueExpr(EmptyShell Empty)
Definition Expr.h:1207
OpaqueValueExpr(SourceLocation Loc, QualType T, ExprValueKind VK, ExprObjectKind OK=OK_Ordinary, Expr *SourceExpr=nullptr)
Definition Expr.h:1194
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:1213
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:1216
static bool classof(const Stmt *T)
Definition Expr.h:1249
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Definition Expr.h:1239
SourceLocation getLocation() const
Retrieve the location of this expression.
Definition Expr.h:1211
friend class ASTStmtReader
Definition Expr.h:1190
const_child_range children() const
Definition Expr.h:1227
child_range children()
Definition Expr.h:1223
SourceLocation getExprLoc() const LLVM_READONLY
Definition Expr.h:1219
bool isUnique() const
Definition Expr.h:1247
void setIsUnique(bool V)
Definition Expr.h:1241
static OpenACCAsteriskSizeExpr * CreateEmpty(const ASTContext &C)
Definition Expr.cpp:5684
SourceLocation getEndLoc() const
Definition Expr.h:2117
SourceLocation getLocation() const
Definition Expr.h:2118
const_child_range children() const
Definition Expr.h:2128
SourceLocation getBeginLoc() const
Definition Expr.h:2116
static bool classof(const Stmt *T)
Definition Expr.h:2120
ParenExpr(SourceLocation l, SourceLocation r, Expr *val)
Definition Expr.h:2198
SourceLocation getLParen() const
Get the location of the left parentheses '('.
Definition Expr.h:2218
Expr * getSubExpr()
Definition Expr.h:2211
static bool classof(const Stmt *T)
Definition Expr.h:2225
ParenExpr(EmptyShell Empty)
Construct an empty parenthesized expression.
Definition Expr.h:2207
void setLParen(SourceLocation Loc)
Definition Expr.h:2219
void setIsProducedByFoldExpansion(bool ProducedByFoldExpansion=true)
Definition Expr.h:2238
const_child_range children() const
Definition Expr.h:2231
void setRParen(SourceLocation Loc)
Definition Expr.h:2223
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:2214
child_range children()
Definition Expr.h:2230
const Expr * getSubExpr() const
Definition Expr.h:2210
bool isProducedByFoldExpansion() const
Definition Expr.h:2235
SourceLocation getRParen() const
Get the location of the right parentheses ')'.
Definition Expr.h:2222
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:2215
void setSubExpr(Expr *E)
Definition Expr.h:2212
Expr *const * getExprs() const
Definition Expr.h:6140
static ParenListExpr * CreateEmpty(const ASTContext &Ctx, unsigned NumExprs)
Create an empty paren list.
Definition Expr.cpp:4989
SourceLocation getBeginLoc() const
Definition Expr.h:6148
Expr * getExpr(unsigned Init)
Definition Expr.h:6129
ArrayRef< Expr * > exprs() const
Definition Expr.h:6144
const Expr * getExpr(unsigned Init) const
Definition Expr.h:6134
const_child_range children() const
Definition Expr.h:6159
Expr ** getExprs()
Definition Expr.h:6138
SourceLocation getEndLoc() const
Definition Expr.h:6149
unsigned getNumExprs() const
Return the number of expressions in this paren list.
Definition Expr.h:6127
SourceLocation getLParenLoc() const
Definition Expr.h:6146
friend class ASTStmtReader
Definition Expr.h:6104
SourceLocation getRParenLoc() const
Definition Expr.h:6147
static bool classof(const Stmt *T)
Definition Expr.h:6151
child_range children()
Definition Expr.h:6156
Represents a parameter to a function.
Definition Decl.h:1819
SourceLocation getBeginLoc() const
Definition Expr.h:2081
void setLocation(SourceLocation L)
Definition Expr.h:2058
static bool classof(const Stmt *T)
Definition Expr.h:2084
SourceLocation getEndLoc() const
Definition Expr.h:2082
const StringLiteral * getFunctionName() const
Definition Expr.h:2066
StringRef getIdentKindName() const
Definition Expr.h:2073
static PredefinedExpr * CreateEmpty(const ASTContext &Ctx, bool HasFunctionName)
Create an empty PredefinedExpr.
Definition Expr.cpp:648
bool isTransparent() const
Definition Expr.h:2055
static std::string ComputeName(PredefinedIdentKind IK, const Decl *CurrentDecl, bool ForceElaboratedPrinting=false)
Definition Expr.cpp:679
const_child_range children() const
Definition Expr.h:2093
child_range children()
Definition Expr.h:2089
PredefinedIdentKind getIdentKind() const
Definition Expr.h:2051
SourceLocation getLocation() const
Definition Expr.h:2057
friend class ASTStmtReader
Definition Expr.h:2017
StringLiteral * getFunctionName()
Definition Expr.h:2060
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Definition Expr.h:6821
const Expr * getResultExpr() const
Definition Expr.h:6874
const_semantics_iterator semantics_begin() const
Definition Expr.h:6883
semantics_iterator semantics_end()
Definition Expr.h:6886
SourceLocation getExprLoc() const LLVM_READONLY
Definition Expr.h:6907
unsigned getResultExprIndex() const
Return the index of the result-bearing expression into the semantics expressions, or PseudoObjectExpr...
Definition Expr.h:6863
semantics_iterator semantics_begin()
Definition Expr.h:6882
const Expr *const * const_semantics_iterator
Definition Expr.h:6881
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:6911
Expr *const * semantics_iterator
Definition Expr.h:6880
const_semantics_iterator semantics_end() const
Definition Expr.h:6889
const Expr * getSyntacticForm() const
Definition Expr.h:6859
static bool classof(const Stmt *T)
Definition Expr.h:6930
const Expr * getSemanticExpr(unsigned index) const
Definition Expr.h:6903
Expr * getResultExpr()
Return the result-bearing expression, or null if there is none.
Definition Expr.h:6869
child_range children()
Definition Expr.h:6918
ArrayRef< Expr * > semantics()
Definition Expr.h:6893
ArrayRef< const Expr * > semantics() const
Definition Expr.h:6896
unsigned getNumSemanticExprs() const
Definition Expr.h:6878
friend class ASTStmtReader
Definition Expr.h:6935
Expr * getSemanticExpr(unsigned index)
Definition Expr.h:6900
Expr * getSyntacticForm()
Return the syntactic form of this expression, i.e.
Definition Expr.h:6858
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:6914
const_child_range children() const
Definition Expr.h:6924
A (possibly-)qualified type.
Definition TypeBase.h:938
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
Definition TypeBase.h:8588
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition TypeBase.h:1005
Represents a struct/union/class.
Definition Decl.h:4459
Frontend produces RecoveryExprs on semantic errors that prevent creating other well-formed expression...
Definition Expr.h:7520
ArrayRef< const Expr * > subExpressions() const
Definition Expr.h:7529
ArrayRef< Expr * > subExpressions()
Definition Expr.h:7527
SourceLocation getEndLoc() const
Definition Expr.h:7539
static bool classof(const Stmt *T)
Definition Expr.h:7541
child_range children()
Definition Expr.h:7533
friend class ASTStmtWriter
Definition Expr.h:7557
friend class ASTStmtReader
Definition Expr.h:7556
SourceLocation getBeginLoc() const
Definition Expr.h:7538
static RecoveryExpr * CreateEmpty(ASTContext &Ctx, unsigned NumSubExprs)
Definition Expr.cpp:5483
Base for LValueReferenceType and RValueReferenceType.
Definition TypeBase.h:3687
static bool classof(const Stmt *T)
Definition Expr.h:2170
const_child_range children() const
Definition Expr.h:2179
SourceLocation getLocation() const
Definition Expr.h:2166
const TypeSourceInfo * getTypeSourceInfo() const
Definition Expr.h:2156
SourceLocation getLParenLocation() const
Definition Expr.h:2167
TypeSourceInfo * getTypeSourceInfo()
Definition Expr.h:2154
std::string ComputeName(ASTContext &Context) const
Definition Expr.cpp:593
SourceLocation getBeginLoc() const
Definition Expr.h:2164
SourceLocation getRParenLocation() const
Definition Expr.h:2168
SourceLocation getEndLoc() const
Definition Expr.h:2165
static SYCLUniqueStableNameExpr * CreateEmpty(const ASTContext &Ctx)
Definition Expr.cpp:588
ShuffleVectorExpr(EmptyShell Empty)
Build an empty vector-shuffle expression.
Definition Expr.h:4668
llvm::APSInt getShuffleMaskIdx(unsigned N) const
Definition Expr.h:4706
void setExprs(const ASTContext &C, ArrayRef< Expr * > Exprs)
Definition Expr.cpp:4617
Expr ** getSubExprs()
Retrieve the array of expressions.
Definition Expr.h:4690
const_child_range children() const
Definition Expr.h:4719
child_range children()
Definition Expr.h:4715
ShuffleVectorExpr(const ASTContext &C, ArrayRef< Expr * > args, QualType Type, SourceLocation BLoc, SourceLocation RP)
Definition Expr.cpp:4604
SourceLocation getBuiltinLoc() const
Definition Expr.h:4671
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:4678
void setRParenLoc(SourceLocation L)
Definition Expr.h:4675
const Expr * getExpr(unsigned Index) const
Definition Expr.h:4698
unsigned getNumSubExprs() const
getNumSubExprs - Return the size of the SubExprs array.
Definition Expr.h:4687
static bool classof(const Stmt *T)
Definition Expr.h:4680
SourceLocation getRParenLoc() const
Definition Expr.h:4674
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:4677
Expr * getExpr(unsigned Index)
getExpr - Return the Expr at the specified index.
Definition Expr.h:4693
void setBuiltinLoc(SourceLocation L)
Definition Expr.h:4672
SourceLocExpr(EmptyShell Empty)
Build an empty call expression.
Definition Expr.h:5047
SourceLocation getBeginLoc() const
Definition Expr.h:5082
APValue EvaluateInContext(const ASTContext &Ctx, const Expr *DefaultExpr) const
Return the result of evaluating this SourceLocExpr in the specified (and possibly null) default argum...
Definition Expr.cpp:2291
bool isIntType() const
Definition Expr.h:5061
static bool classof(const Stmt *T)
Definition Expr.h:5093
child_range children()
Definition Expr.h:5085
SourceLocExpr(const ASTContext &Ctx, SourceLocIdentKind Type, QualType ResultTy, SourceLocation BLoc, SourceLocation RParenLoc, DeclContext *Context)
Definition Expr.cpp:2258
SourceLocation getLocation() const
Definition Expr.h:5081
const DeclContext * getParentContext() const
If the SourceLocExpr has been resolved return the subexpression representing the resolved value.
Definition Expr.h:5078
SourceLocation getEndLoc() const
Definition Expr.h:5083
DeclContext * getParentContext()
Definition Expr.h:5079
StringRef getBuiltinStr() const
Return a string representing the name of the specific builtin function.
Definition Expr.cpp:2271
const_child_range children() const
Definition Expr.h:5089
static bool MayBeDependent(SourceLocIdentKind Kind)
Definition Expr.h:5097
SourceLocIdentKind getIdentKind() const
Definition Expr.h:5057
friend class ASTStmtReader
Definition Expr.h:5109
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
This class handles loading and caching of source files into memory.
A trivial tuple used to represent a source range.
const CompoundStmt * getSubStmt() const
Definition Expr.h:4624
void setRParenLoc(SourceLocation L)
Definition Expr.h:4633
const_child_range children() const
Definition Expr.h:4643
child_range children()
Definition Expr.h:4642
CompoundStmt * getSubStmt()
Definition Expr.h:4623
static bool classof(const Stmt *T)
Definition Expr.h:4637
StmtExpr(CompoundStmt *SubStmt, QualType T, SourceLocation LParenLoc, SourceLocation RParenLoc, unsigned TemplateDepth)
Definition Expr.h:4610
StmtExpr(EmptyShell Empty)
Build an empty statement expression.
Definition Expr.h:4621
void setLParenLoc(SourceLocation L)
Definition Expr.h:4631
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:4628
unsigned getTemplateDepth() const
Definition Expr.h:4635
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:4627
SourceLocation getRParenLoc() const
Definition Expr.h:4632
void setSubStmt(CompoundStmt *S)
Definition Expr.h:4625
SourceLocation getLParenLoc() const
Definition Expr.h:4630
Stmt - This represents one statement.
Definition Stmt.h:85
SourceLocation getEndLoc() const LLVM_READONLY
Definition Stmt.cpp:367
UnaryExprOrTypeTraitExprBitfields UnaryExprOrTypeTraitExprBits
Definition Stmt.h:1360
GenericSelectionExprBitfields GenericSelectionExprBits
Definition Stmt.h:1368
InitListExprBitfields InitListExprBits
Definition Stmt.h:1366
ParenListExprBitfields ParenListExprBits
Definition Stmt.h:1367
ArrayOrMatrixSubscriptExprBitfields ArrayOrMatrixSubscriptExprBits
Definition Stmt.h:1361
ParenExprBitfields ParenExprBits
Definition Stmt.h:1371
StmtIterator child_iterator
Child Iterators: All subclasses must implement 'children' to permit easy iteration over the substatem...
Definition Stmt.h:1588
CallExprBitfields CallExprBits
Definition Stmt.h:1362
ShuffleVectorExprBitfields ShuffleVectorExprBits
Definition Stmt.h:1372
FloatingLiteralBitfields FloatingLiteralBits
Definition Stmt.h:1356
child_iterator child_begin()
Definition Stmt.h:1600
StmtClass getStmtClass() const
Definition Stmt.h:1502
CharacterLiteralBitfields CharacterLiteralBits
Definition Stmt.h:1358
UnaryOperatorBitfields UnaryOperatorBits
Definition Stmt.h:1359
ConstCastIterator< Expr > ConstExprIterator
Definition Stmt.h:1476
SourceLocExprBitfields SourceLocExprBits
Definition Stmt.h:1370
Stmt(StmtClass SC, EmptyShell)
Construct an empty statement.
Definition Stmt.h:1484
ChooseExprBitfields ChooseExprBits
Definition Stmt.h:1376
ConstantExprBitfields ConstantExprBits
Definition Stmt.h:1353
llvm::iterator_range< child_iterator > child_range
Definition Stmt.h:1591
StmtExprBitfields StmtExprBits
Definition Stmt.h:1375
StringLiteralBitfields StringLiteralBits
Definition Stmt.h:1357
OpaqueValueExprBitfields OpaqueValueExprBits
Definition Stmt.h:1416
CastExprBitfields CastExprBits
Definition Stmt.h:1364
MemberExprBitfields MemberExprBits
Definition Stmt.h:1363
DeclRefExprBitfields DeclRefExprBits
Definition Stmt.h:1355
ConstStmtIterator const_child_iterator
Definition Stmt.h:1589
PredefinedExprBitfields PredefinedExprBits
Definition Stmt.h:1354
ConvertVectorExprBitfields ConvertVectorExprBits
Definition Stmt.h:1417
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.cpp:355
BinaryOperatorBitfields BinaryOperatorBits
Definition Stmt.h:1365
PseudoObjectExprBitfields PseudoObjectExprBits
Definition Stmt.h:1369
ExprBitfields ExprBits
Definition Stmt.h:1352
llvm::iterator_range< const_child_iterator > const_child_range
Definition Stmt.h:1592
CastIterator< Expr > ExprIterator
Definition Stmt.h:1475
The streaming interface shared between DiagnosticBuilder and PartialDiagnostic.
void AddTaggedVal(uint64_t V, DiagnosticsEngine::ArgumentKind Kind) const
StringLiteral - This represents a string literal expression, e.g.
Definition Expr.h:1810
const_child_range children() const
Definition Expr.h:1995
SourceLocation getStrTokenLoc(unsigned TokNum) const
Get one of the string literal token.
Definition Expr.h:1956
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:1984
bool containsNonAscii() const
Definition Expr.h:1935
bool isUTF8() const
Definition Expr.h:1929
bool isWide() const
Definition Expr.h:1928
bool containsNonAsciiOrNull() const
Definition Expr.h:1942
bool isPascal() const
Definition Expr.h:1933
unsigned getLength() const
Definition Expr.h:1920
static bool classof(const Stmt *T)
Definition Expr.h:1987
tokloc_iterator tokloc_begin() const
Definition Expr.h:1976
tokloc_iterator tokloc_end() const
Definition Expr.h:1980
child_range children()
Definition Expr.h:1992
StringLiteralKind getKind() const
Definition Expr.h:1923
SourceLocation getLocationOfByte(unsigned ByteNo, const SourceManager &SM, const LangOptions &Features, const TargetInfo &Target, unsigned *StartToken=nullptr, unsigned *StartTokenByteOffset=nullptr) const
getLocationOfByte - Return a source location that points to the specified byte of this string literal...
Definition Expr.cpp:1332
StringRef getBytes() const
Allow access to clients that need the byte representation, such as ASTWriterStmt::VisitStringLiteral(...
Definition Expr.h:1886
uint32_t getCodeUnit(size_t i) const
Definition Expr.h:1893
bool isUnevaluated() const
Definition Expr.h:1932
void outputString(raw_ostream &OS) const
Definition Expr.cpp:1215
bool isUTF32() const
Definition Expr.h:1931
int64_t getCodeUnitS(size_t I, uint64_t BitWidth) const
Definition Expr.h:1907
unsigned getByteLength() const
Definition Expr.h:1919
StringRef getString() const
Definition Expr.h:1878
friend class ASTStmtReader
Definition Expr.h:1811
bool isUTF16() const
Definition Expr.h:1930
static StringLiteral * CreateEmpty(const ASTContext &Ctx, unsigned NumConcatenated, unsigned Length, unsigned CharByteWidth)
Construct an empty string literal.
Definition Expr.cpp:1204
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:1985
const SourceLocation * tokloc_iterator
Definition Expr.h:1974
unsigned getNumConcatenated() const
getNumConcatenated - Get the number of string literal tokens that were concatenated in translation ph...
Definition Expr.h:1951
bool isOrdinary() const
Definition Expr.h:1927
unsigned getCharByteWidth() const
Definition Expr.h:1921
Exposes information about the current target.
Definition TargetInfo.h:227
A convenient class for passing around template argument information.
Location wrapper for a TemplateArgument.
A container of type source information.
Definition TypeBase.h:8475
QualType getType() const
Return the type wrapped by this type source info.
Definition TypeBase.h:8486
The base class of the type hierarchy.
Definition TypeBase.h:1879
bool isPlaceholderType() const
Test for a type which does not represent an actual type-system type but is instead used as a placehol...
Definition TypeBase.h:9089
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
Definition TypeBase.h:9157
bool isReferenceType() const
Definition TypeBase.h:8765
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition Type.cpp:789
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition TypeBase.h:2859
SourceLocation getRParenLoc() const
Definition Expr.h:2712
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:2716
void setKind(UnaryExprOrTypeTrait K)
Definition Expr.h:2671
QualType getArgumentType() const
Definition Expr.h:2679
void setOperatorLoc(SourceLocation L)
Definition Expr.h:2710
SourceLocation getOperatorLoc() const
Definition Expr.h:2709
const Expr * getArgumentExpr() const
Definition Expr.h:2690
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:2715
void setRParenLoc(SourceLocation L)
Definition Expr.h:2713
static bool classof(const Stmt *T)
Definition Expr.h:2718
QualType getTypeOfArgument() const
Gets the argument type, or the type of the argument expression, whichever is appropriate.
Definition Expr.h:2705
UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, TypeSourceInfo *TInfo, QualType resultType, SourceLocation op, SourceLocation rp)
Definition Expr.h:2644
TypeSourceInfo * getArgumentTypeInfo() const
Definition Expr.h:2682
UnaryExprOrTypeTraitExpr(EmptyShell Empty)
Construct an empty sizeof/alignof expression.
Definition Expr.h:2665
UnaryExprOrTypeTrait getKind() const
Definition Expr.h:2668
void setArgument(TypeSourceInfo *TInfo)
Definition Expr.h:2698
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition Expr.h:2255
static bool classof(const Stmt *T)
Definition Expr.h:2381
static bool isPostfix(Opcode Op)
isPostfix - Return true if this is a postfix operation, like x++.
Definition Expr.h:2325
bool isDecrementOp() const
Definition Expr.h:2347
void setSubExpr(Expr *E)
Definition Expr.h:2297
SourceLocation getExprLoc() const
Definition Expr.h:2379
bool isPostfix() const
Definition Expr.h:2335
bool isFEnvAccessOn(const LangOptions &LO) const
Get the FENV_ACCESS status of this operator.
Definition Expr.h:2320
bool isPrefix() const
Definition Expr.h:2334
void setOperatorLoc(SourceLocation L)
Definition Expr.h:2301
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition Expr.h:2300
Expr * getSubExpr() const
Definition Expr.h:2296
friend class ASTReader
Definition Expr.h:2424
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:2376
bool isArithmeticOp() const
Definition Expr.h:2359
void setCanOverflow(bool C)
Definition Expr.h:2310
UnaryOperator(bool HasFPFeatures, EmptyShell Empty)
Build an empty unary operator.
Definition Expr.h:2277
Opcode getOpcode() const
Definition Expr.h:2291
friend class ASTNodeImporter
Definition Expr.h:2423
bool hasStoredFPFeatures() const
Is FPFeatures in Trailing Storage?
Definition Expr.h:2392
static OverloadedOperatorKind getOverloadedOperator(Opcode Opc)
Retrieve the overloaded operator kind that corresponds to the given unary opcode.
Definition Expr.cpp:1436
void setOpcode(Opcode Opc)
Definition Expr.h:2294
child_range children()
Definition Expr.h:2386
static bool isIncrementOp(Opcode Op)
Definition Expr.h:2337
static bool isIncrementDecrementOp(Opcode Op)
Definition Expr.h:2351
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:2373
static bool isDecrementOp(Opcode Op)
Definition Expr.h:2344
FPOptionsOverride getStoredFPFeaturesOrDefault() const
Get the store FPOptionsOverride or default if not stored.
Definition Expr.h:2400
FPOptionsOverride getStoredFPFeatures() const
Get FPFeatures from trailing storage.
Definition Expr.h:2395
bool isFPContractableWithinStatement(const LangOptions &LO) const
Get the FP contractibility status of this operator.
Definition Expr.h:2314
static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix)
Retrieve the unary opcode that corresponds to the given overloaded operator.
Definition Expr.cpp:1421
FPOptions getFPFeaturesInEffect(const LangOptions &LO) const
Get the FP features status of this operator.
Definition Expr.h:2411
friend class ASTStmtWriter
Definition Expr.h:2426
void setStoredFPFeatures(FPOptionsOverride F)
Set FPFeatures in trailing storage, used by Serialization & ASTImporter.
Definition Expr.h:2406
UnaryOperatorKind Opcode
Definition Expr.h:2269
UnaryOperator(const ASTContext &Ctx, Expr *input, Opcode opc, QualType type, ExprValueKind VK, ExprObjectKind OK, SourceLocation l, bool CanOverflow, FPOptionsOverride FPFeatures)
Definition Expr.cpp:5151
FPOptionsOverride getFPOptionsOverride() const
Definition Expr.h:2416
friend class ASTStmtReader
Definition Expr.h:2425
static UnaryOperator * CreateEmpty(const ASTContext &C, bool hasFPFeatures)
Definition Expr.cpp:5144
static bool isPrefix(Opcode Op)
isPrefix - Return true if this is a prefix operation, like –x.
Definition Expr.h:2330
friend TrailingObjects
Definition Expr.h:2422
static StringRef getOpcodeStr(Opcode Op)
getOpcodeStr - Turn an Opcode enum value into the punctuation char it corresponds to,...
Definition Expr.cpp:1412
static bool isArithmeticOp(Opcode Op)
Definition Expr.h:2356
bool isIncrementDecrementOp() const
Definition Expr.h:2352
bool isIncrementOp() const
Definition Expr.h:2340
const_child_range children() const
Definition Expr.h:2387
bool canOverflow() const
Returns true if the unary operator can cause an overflow.
Definition Expr.h:2309
void setVarargABI(VarArgKind Kind)
Definition Expr.h:4993
void setRParenLoc(SourceLocation L)
Definition Expr.h:5008
TypeSourceInfo * getWrittenTypeInfo() const
Definition Expr.h:5001
child_range children()
Definition Expr.h:5018
SourceLocation getBuiltinLoc() const
Definition Expr.h:5004
SourceLocation getRParenLoc() const
Definition Expr.h:5007
bool isZOSABI() const
Returns whether this is really a z/OS ABI va_arg expression.
Definition Expr.h:4999
VAArgExpr(EmptyShell Empty)
Create an empty __builtin_va_arg expression.
Definition Expr.h:4985
Expr * getSubExpr()
Definition Expr.h:4989
bool isMicrosoftABI() const
Returns whether this is really a Win64 ABI va_arg expression.
Definition Expr.h:4996
void setSubExpr(Expr *E)
Definition Expr.h:4990
static bool classof(const Stmt *T)
Definition Expr.h:5013
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:5010
VAArgExpr(SourceLocation BLoc, Expr *e, TypeSourceInfo *TInfo, SourceLocation RPLoc, QualType t, VarArgKind VaKind)
Definition Expr.h:4977
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:5011
void setBuiltinLoc(SourceLocation L)
Definition Expr.h:5005
VarArgKind getVarargABI() const
Definition Expr.h:4992
void setWrittenTypeInfo(TypeSourceInfo *TI)
Definition Expr.h:5002
const_child_range children() const
Definition Expr.h:5019
const Expr * getSubExpr() const
Definition Expr.h:4988
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition Decl.h:712
Represents a statement that could possibly have a value and type.
Definition Stmt.h:2136
Stmt(StmtClass SC, EmptyShell)
Construct an empty statement.
Definition Stmt.h:1484
Represents a variable declaration or definition.
Definition Decl.h:932
Definition SPIR.cpp:47
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const internal::VariadicDynCastAllOfMatcher< Stmt, Expr > expr
Matches expressions.
bool Const(InterpState &S, const T &Arg)
Definition Interp.h:1594
Top level wrappers for InstallAPI frontend operations.
LLVM_READNONE bool isASCII(char c)
Returns true if a byte is an ASCII character.
Definition CharInfo.h:41
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
ConstantResultStorageKind
Describes the kind of result that can be tail-allocated.
Definition Expr.h:1087
bool isa(CodeGen::Address addr)
Definition Address.h:330
const Expr * findStructFieldAccess(const Expr *E, const Expr **OutArrayIndex=nullptr, QualType *OutArrayElementTy=nullptr)
Walk E through parens, implicit casts, unary &/*, array subscripts and comma operators to find the he...
Definition Expr.cpp:5771
ExprDependenceScope::ExprDependence ExprDependence
StmtIterator cast_away_const(const ConstStmtIterator &RHS)
ExprObjectKind
A further classification of the kind of object referenced by an l-value or x-value.
Definition Specifiers.h:150
@ OK_VectorComponent
A vector component is an element or range of elements of a vector.
Definition Specifiers.h:158
@ OK_Ordinary
An ordinary object is located at an address in memory.
Definition Specifiers.h:152
@ OK_BitField
A bitfield object is a bitfield on a C or C++ record.
Definition Specifiers.h:155
@ OK_MatrixComponent
A matrix component is a single element or range of elements of a matrix.
Definition Specifiers.h:170
Expr::ConstantExprKind ConstantExprKind
Definition Expr.h:1053
ExprDependence computeDependence(FullExpr *E)
@ 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',...
@ Result
The result type of a method or function.
Definition TypeBase.h:906
const FunctionProtoType * T
@ Type
The name was classified as a type.
Definition Sema.h:559
CastKind
CastKind - The kind of operation required for a conversion.
std::pair< SourceLocation, PartialDiagnostic > PartialDiagnosticAt
A partial diagnostic along with the source location where this diagnostic occurs.
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
Definition Specifiers.h:133
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
Definition Specifiers.h:136
@ VK_XValue
An x-value expression is a reference to an object with independent storage but which can be "moved",...
Definition Specifiers.h:145
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
Definition Specifiers.h:140
SmallVector< CXXBaseSpecifier *, 4 > CXXCastPath
A simple array of base specifiers.
Definition ASTContext.h:147
StringLiteralKind
Definition Expr.h:1774
const StreamingDiagnostic & operator<<(const StreamingDiagnostic &DB, const ConceptReference *C)
Insertion operator for diagnostics.
U cast(CodeGen::Address addr)
Definition Address.h:327
@ None
The alignment was not explicit in code.
Definition ASTContext.h:176
SourceLocIdentKind
Definition Expr.h:5024
@ Other
Other implicit parameter.
Definition Decl.h:1774
PredefinedIdentKind
Definition Expr.h:2000
@ PrettyFunctionNoVirtual
The same as PrettyFunction, except that the 'virtual' keyword is omitted for virtual member functions...
Definition Expr.h:2010
CharacterLiteralKind
Definition Expr.h:1614
NonOdrUseReason
The reason why a DeclRefExpr does not constitute an odr-use.
Definition Specifiers.h:174
@ NOUR_None
This is an odr-use.
Definition Specifiers.h:176
unsigned long uint64_t
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
__packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 __packed_splat4 uint16_t
__packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 __packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 uint32_t
#define true
Definition stdbool.h:25
BlockVarCopyInit(Expr *CopyExpr, bool CanThrow)
Definition Expr.h:6737
Expr * getCopyExpr() const
Definition Expr.h:6742
llvm::PointerIntPair< Expr *, 1, bool > ExprAndFlag
Definition Expr.h:6744
bool canThrow() const
Definition Expr.h:6743
void setExprAndFlag(Expr *CopyExpr, bool CanThrow)
Definition Expr.h:6739
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
Stores data related to a single embed directive.
Definition Expr.h:5113
StringLiteral * BinaryData
Definition Expr.h:5114
size_t getDataElementCount() const
Definition Expr.h:5118
EvalResult is a struct with detailed info about an evaluated expression.
Definition Expr.h:657
APValue Val
Val - This is the value the expression can be folded to.
Definition Expr.h:659
bool isGlobalLValue() const
Return true if the evaluated lvalue expression is global.
bool hasSideEffects() const
Return true if the evaluated expression has side effects.
Definition Expr.h:651
SmallVectorImpl< PartialDiagnosticAt > * Diag
Diag - If this is non-null, it will be filled in with a stack of notes indicating why evaluation fail...
Definition Expr.h:641
bool DiagEmitted
Whether any diagnostic has been emitted.
Definition Expr.h:625
bool HasUndefinedBehavior
Whether the evaluation hit undefined behavior.
Definition Expr.h:621
bool HasSideEffects
Whether the evaluated expression has side effects.
Definition Expr.h:616
SmallVectorImpl< PartialDiagnosticAt > * ExtendedDiag
Location where we spot ptr to int cast or null subobject while evaluating constant expression in MS c...
Definition Expr.h:645
A placeholder type used to construct an empty shell of a type, that will be filled in later (e....
Definition Stmt.h:1442
const CastExpr * BasePath
Definition Expr.h:76
const CXXRecordDecl * DerivedClass
Definition Expr.h:77
const MemberPointerType * MPT
Definition Expr.h:81
const FieldDecl * Field
Definition Expr.h:87
SubobjectAdjustment(const MemberPointerType *MPT, Expr *RHS)
Definition Expr.h:102
SubobjectAdjustment(const FieldDecl *Field)
Definition Expr.h:98
SubobjectAdjustment(const CastExpr *BasePath, const CXXRecordDecl *DerivedClass)
Definition Expr.h:91
struct DTB DerivedToBase
Definition Expr.h:86
enum clang::SubobjectAdjustment::@253221166153022235222106274120241151060023135167 Kind