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