clang 19.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.
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, modifiably 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 /// Enumeration used to describe the kind of Null pointer constant
791 /// returned from \c isNullPointerConstant().
793 /// Expression is not a Null pointer constant.
795
796 /// Expression is a Null pointer constant built from a zero integer
797 /// expression that is not a simple, possibly parenthesized, zero literal.
798 /// C++ Core Issue 903 will classify these expressions as "not pointers"
799 /// once it is adopted.
800 /// http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#903
802
803 /// Expression is a Null pointer constant built from a literal zero.
805
806 /// Expression is a C++11 nullptr.
808
809 /// Expression is a GNU-style __null constant.
811 };
812
813 /// Enumeration used to describe how \c isNullPointerConstant()
814 /// should cope with value-dependent expressions.
816 /// Specifies that the expression should never be value-dependent.
818
819 /// Specifies that a value-dependent expression of integral or
820 /// dependent type should be considered a null pointer constant.
822
823 /// Specifies that a value-dependent expression should be considered
824 /// to never be a null pointer constant.
826 };
827
828 /// isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to
829 /// a Null pointer constant. The return value can further distinguish the
830 /// kind of NULL pointer constant that was detected.
832 ASTContext &Ctx,
834
835 /// isOBJCGCCandidate - Return true if this expression may be used in a read/
836 /// write barrier.
837 bool isOBJCGCCandidate(ASTContext &Ctx) const;
838
839 /// Returns true if this expression is a bound member function.
840 bool isBoundMemberFunction(ASTContext &Ctx) const;
841
842 /// Given an expression of bound-member type, find the type
843 /// of the member. Returns null if this is an *overloaded* bound
844 /// member expression.
845 static QualType findBoundMemberType(const Expr *expr);
846
847 /// Skip past any invisible AST nodes which might surround this
848 /// statement, such as ExprWithCleanups or ImplicitCastExpr nodes,
849 /// but also injected CXXMemberExpr and CXXConstructExpr which represent
850 /// implicit conversions.
853 return const_cast<Expr *>(this)->IgnoreUnlessSpelledInSource();
854 }
855
856 /// Skip past any implicit casts which might surround this expression until
857 /// reaching a fixed point. Skips:
858 /// * ImplicitCastExpr
859 /// * FullExpr
860 Expr *IgnoreImpCasts() LLVM_READONLY;
861 const Expr *IgnoreImpCasts() const {
862 return const_cast<Expr *>(this)->IgnoreImpCasts();
863 }
864
865 /// Skip past any casts which might surround this expression until reaching
866 /// a fixed point. Skips:
867 /// * CastExpr
868 /// * FullExpr
869 /// * MaterializeTemporaryExpr
870 /// * SubstNonTypeTemplateParmExpr
871 Expr *IgnoreCasts() LLVM_READONLY;
872 const Expr *IgnoreCasts() const {
873 return const_cast<Expr *>(this)->IgnoreCasts();
874 }
875
876 /// Skip past any implicit AST nodes which might surround this expression
877 /// until reaching a fixed point. Skips:
878 /// * What IgnoreImpCasts() skips
879 /// * MaterializeTemporaryExpr
880 /// * CXXBindTemporaryExpr
881 Expr *IgnoreImplicit() LLVM_READONLY;
882 const Expr *IgnoreImplicit() const {
883 return const_cast<Expr *>(this)->IgnoreImplicit();
884 }
885
886 /// Skip past any implicit AST nodes which might surround this expression
887 /// until reaching a fixed point. Same as IgnoreImplicit, except that it
888 /// also skips over implicit calls to constructors and conversion functions.
889 ///
890 /// FIXME: Should IgnoreImplicit do this?
891 Expr *IgnoreImplicitAsWritten() LLVM_READONLY;
893 return const_cast<Expr *>(this)->IgnoreImplicitAsWritten();
894 }
895
896 /// Skip past any parentheses which might surround this expression until
897 /// reaching a fixed point. Skips:
898 /// * ParenExpr
899 /// * UnaryOperator if `UO_Extension`
900 /// * GenericSelectionExpr if `!isResultDependent()`
901 /// * ChooseExpr if `!isConditionDependent()`
902 /// * ConstantExpr
903 Expr *IgnoreParens() LLVM_READONLY;
904 const Expr *IgnoreParens() const {
905 return const_cast<Expr *>(this)->IgnoreParens();
906 }
907
908 /// Skip past any parentheses and implicit casts which might surround this
909 /// expression until reaching a fixed point.
910 /// FIXME: IgnoreParenImpCasts really ought to be equivalent to
911 /// IgnoreParens() + IgnoreImpCasts() until reaching a fixed point. However
912 /// this is currently not the case. Instead IgnoreParenImpCasts() skips:
913 /// * What IgnoreParens() skips
914 /// * What IgnoreImpCasts() skips
915 /// * MaterializeTemporaryExpr
916 /// * SubstNonTypeTemplateParmExpr
917 Expr *IgnoreParenImpCasts() LLVM_READONLY;
918 const Expr *IgnoreParenImpCasts() const {
919 return const_cast<Expr *>(this)->IgnoreParenImpCasts();
920 }
921
922 /// Skip past any parentheses and casts which might surround this expression
923 /// until reaching a fixed point. Skips:
924 /// * What IgnoreParens() skips
925 /// * What IgnoreCasts() skips
926 Expr *IgnoreParenCasts() LLVM_READONLY;
927 const Expr *IgnoreParenCasts() const {
928 return const_cast<Expr *>(this)->IgnoreParenCasts();
929 }
930
931 /// Skip conversion operators. If this Expr is a call to a conversion
932 /// operator, return the argument.
935 return const_cast<Expr *>(this)->IgnoreConversionOperatorSingleStep();
936 }
937
938 /// Skip past any parentheses and lvalue casts which might surround this
939 /// expression until reaching a fixed point. Skips:
940 /// * What IgnoreParens() skips
941 /// * What IgnoreCasts() skips, except that only lvalue-to-rvalue
942 /// casts are skipped
943 /// FIXME: This is intended purely as a temporary workaround for code
944 /// that hasn't yet been rewritten to do the right thing about those
945 /// casts, and may disappear along with the last internal use.
946 Expr *IgnoreParenLValueCasts() LLVM_READONLY;
948 return const_cast<Expr *>(this)->IgnoreParenLValueCasts();
949 }
950
951 /// Skip past any parentheses and casts which do not change the value
952 /// (including ptr->int casts of the same size) until reaching a fixed point.
953 /// Skips:
954 /// * What IgnoreParens() skips
955 /// * CastExpr which do not change the value
956 /// * SubstNonTypeTemplateParmExpr
957 Expr *IgnoreParenNoopCasts(const ASTContext &Ctx) LLVM_READONLY;
958 const Expr *IgnoreParenNoopCasts(const ASTContext &Ctx) const {
959 return const_cast<Expr *>(this)->IgnoreParenNoopCasts(Ctx);
960 }
961
962 /// Skip past any parentheses and derived-to-base casts until reaching a
963 /// fixed point. Skips:
964 /// * What IgnoreParens() skips
965 /// * CastExpr which represent a derived-to-base cast (CK_DerivedToBase,
966 /// CK_UncheckedDerivedToBase and CK_NoOp)
967 Expr *IgnoreParenBaseCasts() LLVM_READONLY;
968 const Expr *IgnoreParenBaseCasts() const {
969 return const_cast<Expr *>(this)->IgnoreParenBaseCasts();
970 }
971
972 /// Determine whether this expression is a default function argument.
973 ///
974 /// Default arguments are implicitly generated in the abstract syntax tree
975 /// by semantic analysis for function calls, object constructions, etc. in
976 /// C++. Default arguments are represented by \c CXXDefaultArgExpr nodes;
977 /// this routine also looks through any implicit casts to determine whether
978 /// the expression is a default argument.
979 bool isDefaultArgument() const;
980
981 /// Determine whether the result of this expression is a
982 /// temporary object of the given class type.
983 bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const;
984
985 /// Whether this expression is an implicit reference to 'this' in C++.
986 bool isImplicitCXXThis() const;
987
989
990 /// For an expression of class type or pointer to class type,
991 /// return the most derived class decl the expression is known to refer to.
992 ///
993 /// If this expression is a cast, this method looks through it to find the
994 /// most derived decl that can be inferred from the expression.
995 /// This is valid because derived-to-base conversions have undefined
996 /// behavior if the object isn't dynamically of the derived type.
998
999 /// Get the inner expression that determines the best dynamic class.
1000 /// If this is a prvalue, we guarantee that it is of the most-derived type
1001 /// for the object itself.
1002 const Expr *getBestDynamicClassTypeExpr() const;
1003
1004 /// Walk outwards from an expression we want to bind a reference to and
1005 /// find the expression whose lifetime needs to be extended. Record
1006 /// the LHSs of comma expressions and adjustments needed along the path.
1009 SmallVectorImpl<SubobjectAdjustment> &Adjustments) const;
1013 return skipRValueSubobjectAdjustments(CommaLHSs, Adjustments);
1014 }
1015
1016 /// Checks that the two Expr's will refer to the same value as a comparison
1017 /// operand. The caller must ensure that the values referenced by the Expr's
1018 /// are not modified between E1 and E2 or the result my be invalid.
1019 static bool isSameComparisonOperand(const Expr* E1, const Expr* E2);
1020
1021 static bool classof(const Stmt *T) {
1022 return T->getStmtClass() >= firstExprConstant &&
1023 T->getStmtClass() <= lastExprConstant;
1024 }
1025};
1026// PointerLikeTypeTraits is specialized so it can be used with a forward-decl of
1027// Expr. Verify that we got it right.
1029 llvm::detail::ConstantLog2<alignof(Expr)>::value,
1030 "PointerLikeTypeTraits<Expr*> assumes too much alignment.");
1031
1033
1034//===----------------------------------------------------------------------===//
1035// Wrapper Expressions.
1036//===----------------------------------------------------------------------===//
1037
1038/// FullExpr - Represents a "full-expression" node.
1039class FullExpr : public Expr {
1040protected:
1042
1044 : Expr(SC, subexpr->getType(), subexpr->getValueKind(),
1045 subexpr->getObjectKind()),
1046 SubExpr(subexpr) {
1048 }
1050 : Expr(SC, Empty) {}
1051public:
1052 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
1053 Expr *getSubExpr() { return cast<Expr>(SubExpr); }
1054
1055 /// As with any mutator of the AST, be very careful when modifying an
1056 /// existing AST to preserve its invariants.
1057 void setSubExpr(Expr *E) { SubExpr = E; }
1058
1059 static bool classof(const Stmt *T) {
1060 return T->getStmtClass() >= firstFullExprConstant &&
1061 T->getStmtClass() <= lastFullExprConstant;
1062 }
1063};
1064
1065/// Describes the kind of result that can be tail-allocated.
1067
1068/// ConstantExpr - An expression that occurs in a constant context and
1069/// optionally the result of evaluating the expression.
1070class ConstantExpr final
1071 : public FullExpr,
1072 private llvm::TrailingObjects<ConstantExpr, APValue, uint64_t> {
1073 static_assert(std::is_same<uint64_t, llvm::APInt::WordType>::value,
1074 "ConstantExpr assumes that llvm::APInt::WordType is uint64_t "
1075 "for tail-allocated storage");
1076 friend TrailingObjects;
1077 friend class ASTStmtReader;
1078 friend class ASTStmtWriter;
1079
1080 size_t numTrailingObjects(OverloadToken<APValue>) const {
1082 }
1083 size_t numTrailingObjects(OverloadToken<uint64_t>) const {
1085 }
1086
1087 uint64_t &Int64Result() {
1089 "invalid accessor");
1090 return *getTrailingObjects<uint64_t>();
1091 }
1092 const uint64_t &Int64Result() const {
1093 return const_cast<ConstantExpr *>(this)->Int64Result();
1094 }
1095 APValue &APValueResult() {
1097 "invalid accessor");
1098 return *getTrailingObjects<APValue>();
1099 }
1100 APValue &APValueResult() const {
1101 return const_cast<ConstantExpr *>(this)->APValueResult();
1102 }
1103
1104 ConstantExpr(Expr *SubExpr, ConstantResultStorageKind StorageKind,
1105 bool IsImmediateInvocation);
1106 ConstantExpr(EmptyShell Empty, ConstantResultStorageKind StorageKind);
1107
1108public:
1109 static ConstantExpr *Create(const ASTContext &Context, Expr *E,
1110 const APValue &Result);
1111 static ConstantExpr *
1112 Create(const ASTContext &Context, Expr *E,
1114 bool IsImmediateInvocation = false);
1115 static ConstantExpr *CreateEmpty(const ASTContext &Context,
1116 ConstantResultStorageKind StorageKind);
1117
1118 static ConstantResultStorageKind getStorageKind(const APValue &Value);
1120 const ASTContext &Context);
1121
1122 SourceLocation getBeginLoc() const LLVM_READONLY {
1123 return SubExpr->getBeginLoc();
1124 }
1125 SourceLocation getEndLoc() const LLVM_READONLY {
1126 return SubExpr->getEndLoc();
1127 }
1128
1129 static bool classof(const Stmt *T) {
1130 return T->getStmtClass() == ConstantExprClass;
1131 }
1132
1133 void SetResult(APValue Value, const ASTContext &Context) {
1134 MoveIntoResult(Value, Context);
1135 }
1136 void MoveIntoResult(APValue &Value, const ASTContext &Context);
1137
1139 return static_cast<APValue::ValueKind>(ConstantExprBits.APValueKind);
1140 }
1142 return static_cast<ConstantResultStorageKind>(ConstantExprBits.ResultKind);
1143 }
1145 return ConstantExprBits.IsImmediateInvocation;
1146 }
1147 bool hasAPValueResult() const {
1148 return ConstantExprBits.APValueKind != APValue::None;
1149 }
1150 APValue getAPValueResult() const;
1151 llvm::APSInt getResultAsAPSInt() const;
1152 // Iterators
1155 return const_child_range(&SubExpr, &SubExpr + 1);
1156 }
1157};
1158
1159//===----------------------------------------------------------------------===//
1160// Primary Expressions.
1161//===----------------------------------------------------------------------===//
1162
1163/// OpaqueValueExpr - An expression referring to an opaque object of a
1164/// fixed type and value class. These don't correspond to concrete
1165/// syntax; instead they're used to express operations (usually copy
1166/// operations) on values whose source is generally obvious from
1167/// context.
1168class OpaqueValueExpr : public Expr {
1169 friend class ASTStmtReader;
1170 Expr *SourceExpr;
1171
1172public:
1174 ExprObjectKind OK = OK_Ordinary, Expr *SourceExpr = nullptr)
1175 : Expr(OpaqueValueExprClass, T, VK, OK), SourceExpr(SourceExpr) {
1176 setIsUnique(false);
1177 OpaqueValueExprBits.Loc = Loc;
1179 }
1180
1181 /// Given an expression which invokes a copy constructor --- i.e. a
1182 /// CXXConstructExpr, possibly wrapped in an ExprWithCleanups ---
1183 /// find the OpaqueValueExpr that's the source of the construction.
1184 static const OpaqueValueExpr *findInCopyConstruct(const Expr *expr);
1185
1187 : Expr(OpaqueValueExprClass, Empty) {}
1188
1189 /// Retrieve the location of this expression.
1191
1192 SourceLocation getBeginLoc() const LLVM_READONLY {
1193 return SourceExpr ? SourceExpr->getBeginLoc() : getLocation();
1194 }
1195 SourceLocation getEndLoc() const LLVM_READONLY {
1196 return SourceExpr ? SourceExpr->getEndLoc() : getLocation();
1197 }
1198 SourceLocation getExprLoc() const LLVM_READONLY {
1199 return SourceExpr ? SourceExpr->getExprLoc() : getLocation();
1200 }
1201
1204 }
1205
1208 }
1209
1210 /// The source expression of an opaque value expression is the
1211 /// expression which originally generated the value. This is
1212 /// provided as a convenience for analyses that don't wish to
1213 /// precisely model the execution behavior of the program.
1214 ///
1215 /// The source expression is typically set when building the
1216 /// expression which binds the opaque value expression in the first
1217 /// place.
1218 Expr *getSourceExpr() const { return SourceExpr; }
1219
1220 void setIsUnique(bool V) {
1221 assert((!V || SourceExpr) &&
1222 "unique OVEs are expected to have source expressions");
1223 OpaqueValueExprBits.IsUnique = V;
1224 }
1225
1226 bool isUnique() const { return OpaqueValueExprBits.IsUnique; }
1227
1228 static bool classof(const Stmt *T) {
1229 return T->getStmtClass() == OpaqueValueExprClass;
1230 }
1231};
1232
1233/// A reference to a declared variable, function, enum, etc.
1234/// [C99 6.5.1p2]
1235///
1236/// This encodes all the information about how a declaration is referenced
1237/// within an expression.
1238///
1239/// There are several optional constructs attached to DeclRefExprs only when
1240/// they apply in order to conserve memory. These are laid out past the end of
1241/// the object, and flags in the DeclRefExprBitfield track whether they exist:
1242///
1243/// DeclRefExprBits.HasQualifier:
1244/// Specifies when this declaration reference expression has a C++
1245/// nested-name-specifier.
1246/// DeclRefExprBits.HasFoundDecl:
1247/// Specifies when this declaration reference expression has a record of
1248/// a NamedDecl (different from the referenced ValueDecl) which was found
1249/// during name lookup and/or overload resolution.
1250/// DeclRefExprBits.HasTemplateKWAndArgsInfo:
1251/// Specifies when this declaration reference expression has an explicit
1252/// C++ template keyword and/or template argument list.
1253/// DeclRefExprBits.RefersToEnclosingVariableOrCapture
1254/// Specifies when this declaration reference expression (validly)
1255/// refers to an enclosed local or a captured variable.
1256class DeclRefExpr final
1257 : public Expr,
1258 private llvm::TrailingObjects<DeclRefExpr, NestedNameSpecifierLoc,
1259 NamedDecl *, ASTTemplateKWAndArgsInfo,
1260 TemplateArgumentLoc> {
1261 friend class ASTStmtReader;
1262 friend class ASTStmtWriter;
1263 friend TrailingObjects;
1264
1265 /// The declaration that we are referencing.
1266 ValueDecl *D;
1267
1268 /// Provides source/type location info for the declaration name
1269 /// embedded in D.
1270 DeclarationNameLoc DNLoc;
1271
1272 size_t numTrailingObjects(OverloadToken<NestedNameSpecifierLoc>) const {
1273 return hasQualifier();
1274 }
1275
1276 size_t numTrailingObjects(OverloadToken<NamedDecl *>) const {
1277 return hasFoundDecl();
1278 }
1279
1280 size_t numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
1281 return hasTemplateKWAndArgsInfo();
1282 }
1283
1284 /// Test whether there is a distinct FoundDecl attached to the end of
1285 /// this DRE.
1286 bool hasFoundDecl() const { return DeclRefExprBits.HasFoundDecl; }
1287
1288 DeclRefExpr(const ASTContext &Ctx, NestedNameSpecifierLoc QualifierLoc,
1289 SourceLocation TemplateKWLoc, ValueDecl *D,
1290 bool RefersToEnlosingVariableOrCapture,
1291 const DeclarationNameInfo &NameInfo, NamedDecl *FoundD,
1292 const TemplateArgumentListInfo *TemplateArgs, QualType T,
1294
1295 /// Construct an empty declaration reference expression.
1296 explicit DeclRefExpr(EmptyShell Empty) : Expr(DeclRefExprClass, Empty) {}
1297
1298public:
1299 DeclRefExpr(const ASTContext &Ctx, ValueDecl *D,
1300 bool RefersToEnclosingVariableOrCapture, QualType T,
1301 ExprValueKind VK, SourceLocation L,
1302 const DeclarationNameLoc &LocInfo = DeclarationNameLoc(),
1303 NonOdrUseReason NOUR = NOUR_None);
1304
1305 static DeclRefExpr *
1306 Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc,
1307 SourceLocation TemplateKWLoc, ValueDecl *D,
1308 bool RefersToEnclosingVariableOrCapture, SourceLocation NameLoc,
1309 QualType T, ExprValueKind VK, NamedDecl *FoundD = nullptr,
1310 const TemplateArgumentListInfo *TemplateArgs = nullptr,
1311 NonOdrUseReason NOUR = NOUR_None);
1312
1313 static DeclRefExpr *
1314 Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc,
1315 SourceLocation TemplateKWLoc, ValueDecl *D,
1316 bool RefersToEnclosingVariableOrCapture,
1317 const DeclarationNameInfo &NameInfo, QualType T, ExprValueKind VK,
1318 NamedDecl *FoundD = nullptr,
1319 const TemplateArgumentListInfo *TemplateArgs = nullptr,
1320 NonOdrUseReason NOUR = NOUR_None);
1321
1322 /// Construct an empty declaration reference expression.
1323 static DeclRefExpr *CreateEmpty(const ASTContext &Context, bool HasQualifier,
1324 bool HasFoundDecl,
1325 bool HasTemplateKWAndArgsInfo,
1326 unsigned NumTemplateArgs);
1327
1328 ValueDecl *getDecl() { return D; }
1329 const ValueDecl *getDecl() const { return D; }
1330 void setDecl(ValueDecl *NewD);
1331
1333 return DeclarationNameInfo(getDecl()->getDeclName(), getLocation(), DNLoc);
1334 }
1335
1338 SourceLocation getBeginLoc() const LLVM_READONLY;
1339 SourceLocation getEndLoc() const LLVM_READONLY;
1340
1341 /// Determine whether this declaration reference was preceded by a
1342 /// C++ nested-name-specifier, e.g., \c N::foo.
1343 bool hasQualifier() const { return DeclRefExprBits.HasQualifier; }
1344
1345 /// If the name was qualified, retrieves the nested-name-specifier
1346 /// that precedes the name, with source-location information.
1348 if (!hasQualifier())
1349 return NestedNameSpecifierLoc();
1350 return *getTrailingObjects<NestedNameSpecifierLoc>();
1351 }
1352
1353 /// If the name was qualified, retrieves the nested-name-specifier
1354 /// that precedes the name. Otherwise, returns NULL.
1357 }
1358
1359 /// Get the NamedDecl through which this reference occurred.
1360 ///
1361 /// This Decl may be different from the ValueDecl actually referred to in the
1362 /// presence of using declarations, etc. It always returns non-NULL, and may
1363 /// simple return the ValueDecl when appropriate.
1364
1366 return hasFoundDecl() ? *getTrailingObjects<NamedDecl *>() : D;
1367 }
1368
1369 /// Get the NamedDecl through which this reference occurred.
1370 /// See non-const variant.
1371 const NamedDecl *getFoundDecl() const {
1372 return hasFoundDecl() ? *getTrailingObjects<NamedDecl *>() : D;
1373 }
1374
1376 return DeclRefExprBits.HasTemplateKWAndArgsInfo;
1377 }
1378
1379 /// Retrieve the location of the template keyword preceding
1380 /// this name, if any.
1383 return SourceLocation();
1384 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->TemplateKWLoc;
1385 }
1386
1387 /// Retrieve the location of the left angle bracket starting the
1388 /// explicit template argument list following the name, if any.
1391 return SourceLocation();
1392 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->LAngleLoc;
1393 }
1394
1395 /// Retrieve the location of the right angle bracket ending the
1396 /// explicit template argument list following the name, if any.
1399 return SourceLocation();
1400 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->RAngleLoc;
1401 }
1402
1403 /// Determines whether the name in this declaration reference
1404 /// was preceded by the template keyword.
1406
1407 /// Determines whether this declaration reference was followed by an
1408 /// explicit template argument list.
1409 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
1410
1411 /// Copies the template arguments (if present) into the given
1412 /// structure.
1415 getTrailingObjects<ASTTemplateKWAndArgsInfo>()->copyInto(
1416 getTrailingObjects<TemplateArgumentLoc>(), List);
1417 }
1418
1419 /// Retrieve the template arguments provided as part of this
1420 /// template-id.
1423 return nullptr;
1424 return getTrailingObjects<TemplateArgumentLoc>();
1425 }
1426
1427 /// Retrieve the number of template arguments provided as part of this
1428 /// template-id.
1429 unsigned getNumTemplateArgs() const {
1431 return 0;
1432 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs;
1433 }
1434
1436 return {getTemplateArgs(), getNumTemplateArgs()};
1437 }
1438
1439 /// Returns true if this expression refers to a function that
1440 /// was resolved from an overloaded set having size greater than 1.
1442 return DeclRefExprBits.HadMultipleCandidates;
1443 }
1444 /// Sets the flag telling whether this expression refers to
1445 /// a function that was resolved from an overloaded set having size
1446 /// greater than 1.
1447 void setHadMultipleCandidates(bool V = true) {
1448 DeclRefExprBits.HadMultipleCandidates = V;
1449 }
1450
1451 /// Is this expression a non-odr-use reference, and if so, why?
1453 return static_cast<NonOdrUseReason>(DeclRefExprBits.NonOdrUseReason);
1454 }
1455
1456 /// Does this DeclRefExpr refer to an enclosing local or a captured
1457 /// variable?
1459 return DeclRefExprBits.RefersToEnclosingVariableOrCapture;
1460 }
1461
1463 return DeclRefExprBits.IsImmediateEscalating;
1464 }
1465
1467 DeclRefExprBits.IsImmediateEscalating = Set;
1468 }
1469
1471 return DeclRefExprBits.CapturedByCopyInLambdaWithExplicitObjectParameter;
1472 }
1473
1475 bool Set, const ASTContext &Context) {
1476 DeclRefExprBits.CapturedByCopyInLambdaWithExplicitObjectParameter = Set;
1477 setDependence(computeDependence(this, Context));
1478 }
1479
1480 static bool classof(const Stmt *T) {
1481 return T->getStmtClass() == DeclRefExprClass;
1482 }
1483
1484 // Iterators
1487 }
1488
1491 }
1492};
1493
1494class IntegerLiteral : public Expr, public APIntStorage {
1495 SourceLocation Loc;
1496
1497 /// Construct an empty integer literal.
1498 explicit IntegerLiteral(EmptyShell Empty)
1499 : Expr(IntegerLiteralClass, Empty) { }
1500
1501public:
1502 // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy,
1503 // or UnsignedLongLongTy
1504 IntegerLiteral(const ASTContext &C, const llvm::APInt &V, QualType type,
1505 SourceLocation l);
1506
1507 /// Returns a new integer literal with value 'V' and type 'type'.
1508 /// \param type - either IntTy, LongTy, LongLongTy, UnsignedIntTy,
1509 /// UnsignedLongTy, or UnsignedLongLongTy which should match the size of V
1510 /// \param V - the value that the returned integer literal contains.
1511 static IntegerLiteral *Create(const ASTContext &C, const llvm::APInt &V,
1513 /// Returns a new empty integer literal.
1514 static IntegerLiteral *Create(const ASTContext &C, EmptyShell Empty);
1515
1516 SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
1517 SourceLocation getEndLoc() const LLVM_READONLY { return Loc; }
1518
1519 /// Retrieve the location of the literal.
1520 SourceLocation getLocation() const { return Loc; }
1521
1522 void setLocation(SourceLocation Location) { Loc = Location; }
1523
1524 static bool classof(const Stmt *T) {
1525 return T->getStmtClass() == IntegerLiteralClass;
1526 }
1527
1528 // Iterators
1531 }
1534 }
1535};
1536
1537class FixedPointLiteral : public Expr, public APIntStorage {
1538 SourceLocation Loc;
1539 unsigned Scale;
1540
1541 /// \brief Construct an empty fixed-point literal.
1542 explicit FixedPointLiteral(EmptyShell Empty)
1543 : Expr(FixedPointLiteralClass, Empty) {}
1544
1545 public:
1546 FixedPointLiteral(const ASTContext &C, const llvm::APInt &V, QualType type,
1547 SourceLocation l, unsigned Scale);
1548
1549 // Store the int as is without any bit shifting.
1551 const llvm::APInt &V,
1553 unsigned Scale);
1554
1555 /// Returns an empty fixed-point literal.
1556 static FixedPointLiteral *Create(const ASTContext &C, EmptyShell Empty);
1557
1558 SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
1559 SourceLocation getEndLoc() const LLVM_READONLY { return Loc; }
1560
1561 /// \brief Retrieve the location of the literal.
1562 SourceLocation getLocation() const { return Loc; }
1563
1564 void setLocation(SourceLocation Location) { Loc = Location; }
1565
1566 unsigned getScale() const { return Scale; }
1567 void setScale(unsigned S) { Scale = S; }
1568
1569 static bool classof(const Stmt *T) {
1570 return T->getStmtClass() == FixedPointLiteralClass;
1571 }
1572
1573 std::string getValueAsString(unsigned Radix) const;
1574
1575 // Iterators
1578 }
1581 }
1582};
1583
1585
1586class CharacterLiteral : public Expr {
1587 unsigned Value;
1588 SourceLocation Loc;
1589public:
1590 // type should be IntTy
1593 : Expr(CharacterLiteralClass, type, VK_PRValue, OK_Ordinary),
1594 Value(value), Loc(l) {
1595 CharacterLiteralBits.Kind = llvm::to_underlying(kind);
1596 setDependence(ExprDependence::None);
1597 }
1598
1599 /// Construct an empty character literal.
1600 CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { }
1601
1602 SourceLocation getLocation() const { return Loc; }
1604 return static_cast<CharacterLiteralKind>(CharacterLiteralBits.Kind);
1605 }
1606
1607 SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
1608 SourceLocation getEndLoc() const LLVM_READONLY { return Loc; }
1609
1610 unsigned getValue() const { return Value; }
1611
1612 void setLocation(SourceLocation Location) { Loc = Location; }
1614 CharacterLiteralBits.Kind = llvm::to_underlying(kind);
1615 }
1616 void setValue(unsigned Val) { Value = Val; }
1617
1618 static bool classof(const Stmt *T) {
1619 return T->getStmtClass() == CharacterLiteralClass;
1620 }
1621
1622 static void print(unsigned val, CharacterLiteralKind Kind, raw_ostream &OS);
1623
1624 // Iterators
1627 }
1630 }
1631};
1632
1633class FloatingLiteral : public Expr, private APFloatStorage {
1634 SourceLocation Loc;
1635
1636 FloatingLiteral(const ASTContext &C, const llvm::APFloat &V, bool isexact,
1638
1639 /// Construct an empty floating-point literal.
1640 explicit FloatingLiteral(const ASTContext &C, EmptyShell Empty);
1641
1642public:
1643 static FloatingLiteral *Create(const ASTContext &C, const llvm::APFloat &V,
1644 bool isexact, QualType Type, SourceLocation L);
1645 static FloatingLiteral *Create(const ASTContext &C, EmptyShell Empty);
1646
1647 llvm::APFloat getValue() const {
1649 }
1650 void setValue(const ASTContext &C, const llvm::APFloat &Val) {
1651 assert(&getSemantics() == &Val.getSemantics() && "Inconsistent semantics");
1653 }
1654
1655 /// Get a raw enumeration value representing the floating-point semantics of
1656 /// this literal (32-bit IEEE, x87, ...), suitable for serialisation.
1657 llvm::APFloatBase::Semantics getRawSemantics() const {
1658 return static_cast<llvm::APFloatBase::Semantics>(
1659 FloatingLiteralBits.Semantics);
1660 }
1661
1662 /// Set the raw enumeration value representing the floating-point semantics of
1663 /// this literal (32-bit IEEE, x87, ...), suitable for serialisation.
1664 void setRawSemantics(llvm::APFloatBase::Semantics Sem) {
1665 FloatingLiteralBits.Semantics = Sem;
1666 }
1667
1668 /// Return the APFloat semantics this literal uses.
1669 const llvm::fltSemantics &getSemantics() const {
1670 return llvm::APFloatBase::EnumToSemantics(
1671 static_cast<llvm::APFloatBase::Semantics>(
1672 FloatingLiteralBits.Semantics));
1673 }
1674
1675 /// Set the APFloat semantics this literal uses.
1676 void setSemantics(const llvm::fltSemantics &Sem) {
1677 FloatingLiteralBits.Semantics = llvm::APFloatBase::SemanticsToEnum(Sem);
1678 }
1679
1680 bool isExact() const { return FloatingLiteralBits.IsExact; }
1681 void setExact(bool E) { FloatingLiteralBits.IsExact = E; }
1682
1683 /// getValueAsApproximateDouble - This returns the value as an inaccurate
1684 /// double. Note that this may cause loss of precision, but is useful for
1685 /// debugging dumps, etc.
1686 double getValueAsApproximateDouble() const;
1687
1688 SourceLocation getLocation() const { return Loc; }
1689 void setLocation(SourceLocation L) { Loc = L; }
1690
1691 SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
1692 SourceLocation getEndLoc() const LLVM_READONLY { return Loc; }
1693
1694 static bool classof(const Stmt *T) {
1695 return T->getStmtClass() == FloatingLiteralClass;
1696 }
1697
1698 // Iterators
1701 }
1704 }
1705};
1706
1707/// ImaginaryLiteral - We support imaginary integer and floating point literals,
1708/// like "1.0i". We represent these as a wrapper around FloatingLiteral and
1709/// IntegerLiteral classes. Instances of this class always have a Complex type
1710/// whose element type matches the subexpression.
1711///
1712class ImaginaryLiteral : public Expr {
1713 Stmt *Val;
1714public:
1716 : Expr(ImaginaryLiteralClass, Ty, VK_PRValue, OK_Ordinary), Val(val) {
1717 setDependence(ExprDependence::None);
1718 }
1719
1720 /// Build an empty imaginary literal.
1722 : Expr(ImaginaryLiteralClass, Empty) { }
1723
1724 const Expr *getSubExpr() const { return cast<Expr>(Val); }
1725 Expr *getSubExpr() { return cast<Expr>(Val); }
1726 void setSubExpr(Expr *E) { Val = E; }
1727
1728 SourceLocation getBeginLoc() const LLVM_READONLY {
1729 return Val->getBeginLoc();
1730 }
1731 SourceLocation getEndLoc() const LLVM_READONLY { return Val->getEndLoc(); }
1732
1733 static bool classof(const Stmt *T) {
1734 return T->getStmtClass() == ImaginaryLiteralClass;
1735 }
1736
1737 // Iterators
1738 child_range children() { return child_range(&Val, &Val+1); }
1740 return const_child_range(&Val, &Val + 1);
1741 }
1742};
1743
1745 Ordinary,
1746 Wide,
1747 UTF8,
1748 UTF16,
1749 UTF32,
1751};
1752
1753/// StringLiteral - This represents a string literal expression, e.g. "foo"
1754/// or L"bar" (wide strings). The actual string data can be obtained with
1755/// getBytes() and is NOT null-terminated. The length of the string data is
1756/// determined by calling getByteLength().
1757///
1758/// The C type for a string is always a ConstantArrayType. In C++, the char
1759/// type is const qualified, in C it is not.
1760///
1761/// Note that strings in C can be formed by concatenation of multiple string
1762/// literal pptokens in translation phase #6. This keeps track of the locations
1763/// of each of these pieces.
1764///
1765/// Strings in C can also be truncated and extended by assigning into arrays,
1766/// e.g. with constructs like:
1767/// char X[2] = "foobar";
1768/// In this case, getByteLength() will return 6, but the string literal will
1769/// have type "char[2]".
1770class StringLiteral final
1771 : public Expr,
1772 private llvm::TrailingObjects<StringLiteral, unsigned, SourceLocation,
1773 char> {
1774 friend class ASTStmtReader;
1775 friend TrailingObjects;
1776
1777 /// StringLiteral is followed by several trailing objects. They are in order:
1778 ///
1779 /// * A single unsigned storing the length in characters of this string. The
1780 /// length in bytes is this length times the width of a single character.
1781 /// Always present and stored as a trailing objects because storing it in
1782 /// StringLiteral would increase the size of StringLiteral by sizeof(void *)
1783 /// due to alignment requirements. If you add some data to StringLiteral,
1784 /// consider moving it inside StringLiteral.
1785 ///
1786 /// * An array of getNumConcatenated() SourceLocation, one for each of the
1787 /// token this string is made of.
1788 ///
1789 /// * An array of getByteLength() char used to store the string data.
1790
1791 unsigned numTrailingObjects(OverloadToken<unsigned>) const { return 1; }
1792 unsigned numTrailingObjects(OverloadToken<SourceLocation>) const {
1793 return getNumConcatenated();
1794 }
1795
1796 unsigned numTrailingObjects(OverloadToken<char>) const {
1797 return getByteLength();
1798 }
1799
1800 char *getStrDataAsChar() { return getTrailingObjects<char>(); }
1801 const char *getStrDataAsChar() const { return getTrailingObjects<char>(); }
1802
1803 const uint16_t *getStrDataAsUInt16() const {
1804 return reinterpret_cast<const uint16_t *>(getTrailingObjects<char>());
1805 }
1806
1807 const uint32_t *getStrDataAsUInt32() const {
1808 return reinterpret_cast<const uint32_t *>(getTrailingObjects<char>());
1809 }
1810
1811 /// Build a string literal.
1812 StringLiteral(const ASTContext &Ctx, StringRef Str, StringLiteralKind Kind,
1813 bool Pascal, QualType Ty, const SourceLocation *Loc,
1814 unsigned NumConcatenated);
1815
1816 /// Build an empty string literal.
1817 StringLiteral(EmptyShell Empty, unsigned NumConcatenated, unsigned Length,
1818 unsigned CharByteWidth);
1819
1820 /// Map a target and string kind to the appropriate character width.
1821 static unsigned mapCharByteWidth(TargetInfo const &Target,
1823
1824 /// Set one of the string literal token.
1825 void setStrTokenLoc(unsigned TokNum, SourceLocation L) {
1826 assert(TokNum < getNumConcatenated() && "Invalid tok number");
1827 getTrailingObjects<SourceLocation>()[TokNum] = L;
1828 }
1829
1830public:
1831 /// This is the "fully general" constructor that allows representation of
1832 /// strings formed from multiple concatenated tokens.
1833 static StringLiteral *Create(const ASTContext &Ctx, StringRef Str,
1834 StringLiteralKind Kind, bool Pascal, QualType Ty,
1835 const SourceLocation *Loc,
1836 unsigned NumConcatenated);
1837
1838 /// Simple constructor for string literals made from one token.
1839 static StringLiteral *Create(const ASTContext &Ctx, StringRef Str,
1840 StringLiteralKind Kind, bool Pascal, QualType Ty,
1841 SourceLocation Loc) {
1842 return Create(Ctx, Str, Kind, Pascal, Ty, &Loc, 1);
1843 }
1844
1845 /// Construct an empty string literal.
1846 static StringLiteral *CreateEmpty(const ASTContext &Ctx,
1847 unsigned NumConcatenated, unsigned Length,
1848 unsigned CharByteWidth);
1849
1850 StringRef getString() const {
1851 assert((isUnevaluated() || getCharByteWidth() == 1) &&
1852 "This function is used in places that assume strings use char");
1853 return StringRef(getStrDataAsChar(), getByteLength());
1854 }
1855
1856 /// Allow access to clients that need the byte representation, such as
1857 /// ASTWriterStmt::VisitStringLiteral().
1858 StringRef getBytes() const {
1859 // FIXME: StringRef may not be the right type to use as a result for this.
1860 return StringRef(getStrDataAsChar(), getByteLength());
1861 }
1862
1863 void outputString(raw_ostream &OS) const;
1864
1865 uint32_t getCodeUnit(size_t i) const {
1866 assert(i < getLength() && "out of bounds access");
1867 switch (getCharByteWidth()) {
1868 case 1:
1869 return static_cast<unsigned char>(getStrDataAsChar()[i]);
1870 case 2:
1871 return getStrDataAsUInt16()[i];
1872 case 4:
1873 return getStrDataAsUInt32()[i];
1874 }
1875 llvm_unreachable("Unsupported character width!");
1876 }
1877
1878 // Get code unit but preserve sign info.
1879 int64_t getCodeUnitS(size_t I, uint64_t BitWidth) const {
1880 int64_t V = getCodeUnit(I);
1881 if (isOrdinary() || isWide()) {
1882 unsigned Width = getCharByteWidth() * BitWidth;
1883 llvm::APInt AInt(Width, (uint64_t)V);
1884 V = AInt.getSExtValue();
1885 }
1886 return V;
1887 }
1888
1889 unsigned getByteLength() const { return getCharByteWidth() * getLength(); }
1890 unsigned getLength() const { return *getTrailingObjects<unsigned>(); }
1891 unsigned getCharByteWidth() const { return StringLiteralBits.CharByteWidth; }
1892
1894 return static_cast<StringLiteralKind>(StringLiteralBits.Kind);
1895 }
1896
1897 bool isOrdinary() const { return getKind() == StringLiteralKind::Ordinary; }
1898 bool isWide() const { return getKind() == StringLiteralKind::Wide; }
1899 bool isUTF8() const { return getKind() == StringLiteralKind::UTF8; }
1900 bool isUTF16() const { return getKind() == StringLiteralKind::UTF16; }
1901 bool isUTF32() const { return getKind() == StringLiteralKind::UTF32; }
1903 bool isPascal() const { return StringLiteralBits.IsPascal; }
1904
1905 bool containsNonAscii() const {
1906 for (auto c : getString())
1907 if (!isASCII(c))
1908 return true;
1909 return false;
1910 }
1911
1913 for (auto c : getString())
1914 if (!isASCII(c) || !c)
1915 return true;
1916 return false;
1917 }
1918
1919 /// getNumConcatenated - Get the number of string literal tokens that were
1920 /// concatenated in translation phase #6 to form this string literal.
1921 unsigned getNumConcatenated() const {
1922 return StringLiteralBits.NumConcatenated;
1923 }
1924
1925 /// Get one of the string literal token.
1926 SourceLocation getStrTokenLoc(unsigned TokNum) const {
1927 assert(TokNum < getNumConcatenated() && "Invalid tok number");
1928 return getTrailingObjects<SourceLocation>()[TokNum];
1929 }
1930
1931 /// getLocationOfByte - Return a source location that points to the specified
1932 /// byte of this string literal.
1933 ///
1934 /// Strings are amazingly complex. They can be formed from multiple tokens
1935 /// and can have escape sequences in them in addition to the usual trigraph
1936 /// and escaped newline business. This routine handles this complexity.
1937 ///
1939 getLocationOfByte(unsigned ByteNo, const SourceManager &SM,
1940 const LangOptions &Features, const TargetInfo &Target,
1941 unsigned *StartToken = nullptr,
1942 unsigned *StartTokenByteOffset = nullptr) const;
1943
1945
1947 return getTrailingObjects<SourceLocation>();
1948 }
1949
1951 return getTrailingObjects<SourceLocation>() + getNumConcatenated();
1952 }
1953
1954 SourceLocation getBeginLoc() const LLVM_READONLY { return *tokloc_begin(); }
1955 SourceLocation getEndLoc() const LLVM_READONLY { return *(tokloc_end() - 1); }
1956
1957 static bool classof(const Stmt *T) {
1958 return T->getStmtClass() == StringLiteralClass;
1959 }
1960
1961 // Iterators
1964 }
1967 }
1968};
1969
1971 Func,
1972 Function,
1973 LFunction, // Same as Function, but as wide string.
1974 FuncDName,
1975 FuncSig,
1976 LFuncSig, // Same as FuncSig, but as wide string
1978 /// The same as PrettyFunction, except that the
1979 /// 'virtual' keyword is omitted for virtual member functions.
1981};
1982
1983/// [C99 6.4.2.2] - A predefined identifier such as __func__.
1985 : public Expr,
1986 private llvm::TrailingObjects<PredefinedExpr, Stmt *> {
1987 friend class ASTStmtReader;
1988 friend TrailingObjects;
1989
1990 // PredefinedExpr is optionally followed by a single trailing
1991 // "Stmt *" for the predefined identifier. It is present if and only if
1992 // hasFunctionName() is true and is always a "StringLiteral *".
1993
1995 bool IsTransparent, StringLiteral *SL);
1996
1997 explicit PredefinedExpr(EmptyShell Empty, bool HasFunctionName);
1998
1999 /// True if this PredefinedExpr has storage for a function name.
2000 bool hasFunctionName() const { return PredefinedExprBits.HasFunctionName; }
2001
2002 void setFunctionName(StringLiteral *SL) {
2003 assert(hasFunctionName() &&
2004 "This PredefinedExpr has no storage for a function name!");
2005 *getTrailingObjects<Stmt *>() = SL;
2006 }
2007
2008public:
2009 /// Create a PredefinedExpr.
2010 ///
2011 /// If IsTransparent, the PredefinedExpr is transparently handled as a
2012 /// StringLiteral.
2013 static PredefinedExpr *Create(const ASTContext &Ctx, SourceLocation L,
2014 QualType FNTy, PredefinedIdentKind IK,
2015 bool IsTransparent, StringLiteral *SL);
2016
2017 /// Create an empty PredefinedExpr.
2018 static PredefinedExpr *CreateEmpty(const ASTContext &Ctx,
2019 bool HasFunctionName);
2020
2022 return static_cast<PredefinedIdentKind>(PredefinedExprBits.Kind);
2023 }
2024
2025 bool isTransparent() const { return PredefinedExprBits.IsTransparent; }
2026
2029
2031 return hasFunctionName()
2032 ? static_cast<StringLiteral *>(*getTrailingObjects<Stmt *>())
2033 : nullptr;
2034 }
2035
2037 return hasFunctionName()
2038 ? static_cast<StringLiteral *>(*getTrailingObjects<Stmt *>())
2039 : nullptr;
2040 }
2041
2042 static StringRef getIdentKindName(PredefinedIdentKind IK);
2043 StringRef getIdentKindName() const {
2045 }
2046
2047 static std::string ComputeName(PredefinedIdentKind IK,
2048 const Decl *CurrentDecl);
2049
2052
2053 static bool classof(const Stmt *T) {
2054 return T->getStmtClass() == PredefinedExprClass;
2055 }
2056
2057 // Iterators
2059 return child_range(getTrailingObjects<Stmt *>(),
2060 getTrailingObjects<Stmt *>() + hasFunctionName());
2061 }
2062
2064 return const_child_range(getTrailingObjects<Stmt *>(),
2065 getTrailingObjects<Stmt *>() + hasFunctionName());
2066 }
2067};
2068
2069// This represents a use of the __builtin_sycl_unique_stable_name, which takes a
2070// type-id, and at CodeGen time emits a unique string representation of the
2071// type in a way that permits us to properly encode information about the SYCL
2072// kernels.
2073class SYCLUniqueStableNameExpr final : public Expr {
2074 friend class ASTStmtReader;
2075 SourceLocation OpLoc, LParen, RParen;
2077
2080 SourceLocation RParen, QualType ResultTy,
2081 TypeSourceInfo *TSI);
2082
2083 void setTypeSourceInfo(TypeSourceInfo *Ty) { TypeInfo = Ty; }
2084
2085 void setLocation(SourceLocation L) { OpLoc = L; }
2086 void setLParenLocation(SourceLocation L) { LParen = L; }
2087 void setRParenLocation(SourceLocation L) { RParen = L; }
2088
2089public:
2091
2092 const TypeSourceInfo *getTypeSourceInfo() const { return TypeInfo; }
2093
2095 Create(const ASTContext &Ctx, SourceLocation OpLoc, SourceLocation LParen,
2096 SourceLocation RParen, TypeSourceInfo *TSI);
2097
2099
2101 SourceLocation getEndLoc() const { return RParen; }
2102 SourceLocation getLocation() const { return OpLoc; }
2103 SourceLocation getLParenLocation() const { return LParen; }
2104 SourceLocation getRParenLocation() const { return RParen; }
2105
2106 static bool classof(const Stmt *T) {
2107 return T->getStmtClass() == SYCLUniqueStableNameExprClass;
2108 }
2109
2110 // Iterators
2113 }
2114
2117 }
2118
2119 // Convenience function to generate the name of the currently stored type.
2120 std::string ComputeName(ASTContext &Context) const;
2121
2122 // Get the generated name of the type. Note that this only works after all
2123 // kernels have been instantiated.
2124 static std::string ComputeName(ASTContext &Context, QualType Ty);
2125};
2126
2127/// ParenExpr - This represents a parethesized expression, e.g. "(1)". This
2128/// AST node is only formed if full location information is requested.
2129class ParenExpr : public Expr {
2130 SourceLocation L, R;
2131 Stmt *Val;
2132public:
2134 : Expr(ParenExprClass, val->getType(), val->getValueKind(),
2135 val->getObjectKind()),
2136 L(l), R(r), Val(val) {
2138 }
2139
2140 /// Construct an empty parenthesized expression.
2141 explicit ParenExpr(EmptyShell Empty)
2142 : Expr(ParenExprClass, Empty) { }
2143
2144 const Expr *getSubExpr() const { return cast<Expr>(Val); }
2145 Expr *getSubExpr() { return cast<Expr>(Val); }
2146 void setSubExpr(Expr *E) { Val = E; }
2147
2148 SourceLocation getBeginLoc() const LLVM_READONLY { return L; }
2149 SourceLocation getEndLoc() const LLVM_READONLY { return R; }
2150
2151 /// Get the location of the left parentheses '('.
2152 SourceLocation getLParen() const { return L; }
2153 void setLParen(SourceLocation Loc) { L = Loc; }
2154
2155 /// Get the location of the right parentheses ')'.
2156 SourceLocation getRParen() const { return R; }
2157 void setRParen(SourceLocation Loc) { R = Loc; }
2158
2159 static bool classof(const Stmt *T) {
2160 return T->getStmtClass() == ParenExprClass;
2161 }
2162
2163 // Iterators
2164 child_range children() { return child_range(&Val, &Val+1); }
2166 return const_child_range(&Val, &Val + 1);
2167 }
2168};
2169
2170/// UnaryOperator - This represents the unary-expression's (except sizeof and
2171/// alignof), the postinc/postdec operators from postfix-expression, and various
2172/// extensions.
2173///
2174/// Notes on various nodes:
2175///
2176/// Real/Imag - These return the real/imag part of a complex operand. If
2177/// applied to a non-complex value, the former returns its operand and the
2178/// later returns zero in the type of the operand.
2179///
2180class UnaryOperator final
2181 : public Expr,
2182 private llvm::TrailingObjects<UnaryOperator, FPOptionsOverride> {
2183 Stmt *Val;
2184
2185 size_t numTrailingObjects(OverloadToken<FPOptionsOverride>) const {
2186 return UnaryOperatorBits.HasFPFeatures ? 1 : 0;
2187 }
2188
2189 FPOptionsOverride &getTrailingFPFeatures() {
2190 assert(UnaryOperatorBits.HasFPFeatures);
2191 return *getTrailingObjects<FPOptionsOverride>();
2192 }
2193
2194 const FPOptionsOverride &getTrailingFPFeatures() const {
2195 assert(UnaryOperatorBits.HasFPFeatures);
2196 return *getTrailingObjects<FPOptionsOverride>();
2197 }
2198
2199public:
2201
2202protected:
2203 UnaryOperator(const ASTContext &Ctx, Expr *input, Opcode opc, QualType type,
2205 bool CanOverflow, FPOptionsOverride FPFeatures);
2206
2207 /// Build an empty unary operator.
2208 explicit UnaryOperator(bool HasFPFeatures, EmptyShell Empty)
2209 : Expr(UnaryOperatorClass, Empty) {
2210 UnaryOperatorBits.Opc = UO_AddrOf;
2211 UnaryOperatorBits.HasFPFeatures = HasFPFeatures;
2212 }
2213
2214public:
2215 static UnaryOperator *CreateEmpty(const ASTContext &C, bool hasFPFeatures);
2216
2217 static UnaryOperator *Create(const ASTContext &C, Expr *input, Opcode opc,
2220 bool CanOverflow, FPOptionsOverride FPFeatures);
2221
2223 return static_cast<Opcode>(UnaryOperatorBits.Opc);
2224 }
2225 void setOpcode(Opcode Opc) { UnaryOperatorBits.Opc = Opc; }
2226
2227 Expr *getSubExpr() const { return cast<Expr>(Val); }
2228 void setSubExpr(Expr *E) { Val = E; }
2229
2230 /// getOperatorLoc - Return the location of the operator.
2233
2234 /// Returns true if the unary operator can cause an overflow. For instance,
2235 /// signed int i = INT_MAX; i++;
2236 /// signed char c = CHAR_MAX; c++;
2237 /// Due to integer promotions, c++ is promoted to an int before the postfix
2238 /// increment, and the result is an int that cannot overflow. However, i++
2239 /// can overflow.
2240 bool canOverflow() const { return UnaryOperatorBits.CanOverflow; }
2241 void setCanOverflow(bool C) { UnaryOperatorBits.CanOverflow = C; }
2242
2243 /// Get the FP contractability status of this operator. Only meaningful for
2244 /// operations on floating point types.
2247 }
2248
2249 /// Get the FENV_ACCESS status of this operator. Only meaningful for
2250 /// operations on floating point types.
2251 bool isFEnvAccessOn(const LangOptions &LO) const {
2252 return getFPFeaturesInEffect(LO).getAllowFEnvAccess();
2253 }
2254
2255 /// isPostfix - Return true if this is a postfix operation, like x++.
2256 static bool isPostfix(Opcode Op) {
2257 return Op == UO_PostInc || Op == UO_PostDec;
2258 }
2259
2260 /// isPrefix - Return true if this is a prefix operation, like --x.
2261 static bool isPrefix(Opcode Op) {
2262 return Op == UO_PreInc || Op == UO_PreDec;
2263 }
2264
2265 bool isPrefix() const { return isPrefix(getOpcode()); }
2266 bool isPostfix() const { return isPostfix(getOpcode()); }
2267
2268 static bool isIncrementOp(Opcode Op) {
2269 return Op == UO_PreInc || Op == UO_PostInc;
2270 }
2271 bool isIncrementOp() const {
2272 return isIncrementOp(getOpcode());
2273 }
2274
2275 static bool isDecrementOp(Opcode Op) {
2276 return Op == UO_PreDec || Op == UO_PostDec;
2277 }
2278 bool isDecrementOp() const {
2279 return isDecrementOp(getOpcode());
2280 }
2281
2282 static bool isIncrementDecrementOp(Opcode Op) { return Op <= UO_PreDec; }
2285 }
2286
2287 static bool isArithmeticOp(Opcode Op) {
2288 return Op >= UO_Plus && Op <= UO_LNot;
2289 }
2290 bool isArithmeticOp() const { return isArithmeticOp(getOpcode()); }
2291
2292 /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
2293 /// corresponds to, e.g. "sizeof" or "[pre]++"
2294 static StringRef getOpcodeStr(Opcode Op);
2295
2296 /// Retrieve the unary opcode that corresponds to the given
2297 /// overloaded operator.
2298 static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix);
2299
2300 /// Retrieve the overloaded operator kind that corresponds to
2301 /// the given unary opcode.
2303
2304 SourceLocation getBeginLoc() const LLVM_READONLY {
2305 return isPostfix() ? Val->getBeginLoc() : getOperatorLoc();
2306 }
2307 SourceLocation getEndLoc() const LLVM_READONLY {
2308 return isPostfix() ? getOperatorLoc() : Val->getEndLoc();
2309 }
2311
2312 static bool classof(const Stmt *T) {
2313 return T->getStmtClass() == UnaryOperatorClass;
2314 }
2315
2316 // Iterators
2317 child_range children() { return child_range(&Val, &Val+1); }
2319 return const_child_range(&Val, &Val + 1);
2320 }
2321
2322 /// Is FPFeatures in Trailing Storage?
2323 bool hasStoredFPFeatures() const { return UnaryOperatorBits.HasFPFeatures; }
2324
2325 /// Get FPFeatures from trailing storage.
2327 return getTrailingFPFeatures();
2328 }
2329
2330protected:
2331 /// Set FPFeatures in trailing storage, used by Serialization & ASTImporter.
2332 void setStoredFPFeatures(FPOptionsOverride F) { getTrailingFPFeatures() = F; }
2333
2334public:
2335 /// Get the FP features status of this operator. Only meaningful for
2336 /// operations on floating point types.
2338 if (UnaryOperatorBits.HasFPFeatures)
2341 }
2343 if (UnaryOperatorBits.HasFPFeatures)
2344 return getStoredFPFeatures();
2345 return FPOptionsOverride();
2346 }
2347
2349 friend class ASTNodeImporter;
2350 friend class ASTReader;
2351 friend class ASTStmtReader;
2352 friend class ASTStmtWriter;
2353};
2354
2355/// Helper class for OffsetOfExpr.
2356
2357// __builtin_offsetof(type, identifier(.identifier|[expr])*)
2359public:
2360 /// The kind of offsetof node we have.
2361 enum Kind {
2362 /// An index into an array.
2363 Array = 0x00,
2364 /// A field.
2365 Field = 0x01,
2366 /// A field in a dependent type, known only by its name.
2368 /// An implicit indirection through a C++ base class, when the
2369 /// field found is in a base class.
2370 Base = 0x03
2372
2373private:
2374 enum { MaskBits = 2, Mask = 0x03 };
2375
2376 /// The source range that covers this part of the designator.
2377 SourceRange Range;
2378
2379 /// The data describing the designator, which comes in three
2380 /// different forms, depending on the lower two bits.
2381 /// - An unsigned index into the array of Expr*'s stored after this node
2382 /// in memory, for [constant-expression] designators.
2383 /// - A FieldDecl*, for references to a known field.
2384 /// - An IdentifierInfo*, for references to a field with a given name
2385 /// when the class type is dependent.
2386 /// - A CXXBaseSpecifier*, for references that look at a field in a
2387 /// base class.
2388 uintptr_t Data;
2389
2390public:
2391 /// Create an offsetof node that refers to an array element.
2392 OffsetOfNode(SourceLocation LBracketLoc, unsigned Index,
2393 SourceLocation RBracketLoc)
2394 : Range(LBracketLoc, RBracketLoc), Data((Index << 2) | Array) {}
2395
2396 /// Create an offsetof node that refers to a field.
2398 : Range(DotLoc.isValid() ? DotLoc : NameLoc, NameLoc),
2399 Data(reinterpret_cast<uintptr_t>(Field) | OffsetOfNode::Field) {}
2400
2401 /// Create an offsetof node that refers to an identifier.
2403 SourceLocation NameLoc)
2404 : Range(DotLoc.isValid() ? DotLoc : NameLoc, NameLoc),
2405 Data(reinterpret_cast<uintptr_t>(Name) | Identifier) {}
2406
2407 /// Create an offsetof node that refers into a C++ base class.
2409 : Data(reinterpret_cast<uintptr_t>(Base) | OffsetOfNode::Base) {}
2410
2411 /// Determine what kind of offsetof node this is.
2412 Kind getKind() const { return static_cast<Kind>(Data & Mask); }
2413
2414 /// For an array element node, returns the index into the array
2415 /// of expressions.
2416 unsigned getArrayExprIndex() const {
2417 assert(getKind() == Array);
2418 return Data >> 2;
2419 }
2420
2421 /// For a field offsetof node, returns the field.
2423 assert(getKind() == Field);
2424 return reinterpret_cast<FieldDecl *>(Data & ~(uintptr_t)Mask);
2425 }
2426
2427 /// For a field or identifier offsetof node, returns the name of
2428 /// the field.
2430
2431 /// For a base class node, returns the base specifier.
2433 assert(getKind() == Base);
2434 return reinterpret_cast<CXXBaseSpecifier *>(Data & ~(uintptr_t)Mask);
2435 }
2436
2437 /// Retrieve the source range that covers this offsetof node.
2438 ///
2439 /// For an array element node, the source range contains the locations of
2440 /// the square brackets. For a field or identifier node, the source range
2441 /// contains the location of the period (if there is one) and the
2442 /// identifier.
2443 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
2444 SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); }
2445 SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); }
2446};
2447
2448/// OffsetOfExpr - [C99 7.17] - This represents an expression of the form
2449/// offsetof(record-type, member-designator). For example, given:
2450/// @code
2451/// struct S {
2452/// float f;
2453/// double d;
2454/// };
2455/// struct T {
2456/// int i;
2457/// struct S s[10];
2458/// };
2459/// @endcode
2460/// we can represent and evaluate the expression @c offsetof(struct T, s[2].d).
2461
2462class OffsetOfExpr final
2463 : public Expr,
2464 private llvm::TrailingObjects<OffsetOfExpr, OffsetOfNode, Expr *> {
2465 SourceLocation OperatorLoc, RParenLoc;
2466 // Base type;
2467 TypeSourceInfo *TSInfo;
2468 // Number of sub-components (i.e. instances of OffsetOfNode).
2469 unsigned NumComps;
2470 // Number of sub-expressions (i.e. array subscript expressions).
2471 unsigned NumExprs;
2472
2473 size_t numTrailingObjects(OverloadToken<OffsetOfNode>) const {
2474 return NumComps;
2475 }
2476
2478 SourceLocation OperatorLoc, TypeSourceInfo *tsi,
2480 SourceLocation RParenLoc);
2481
2482 explicit OffsetOfExpr(unsigned numComps, unsigned numExprs)
2483 : Expr(OffsetOfExprClass, EmptyShell()),
2484 TSInfo(nullptr), NumComps(numComps), NumExprs(numExprs) {}
2485
2486public:
2487
2488 static OffsetOfExpr *Create(const ASTContext &C, QualType type,
2489 SourceLocation OperatorLoc, TypeSourceInfo *tsi,
2491 ArrayRef<Expr*> exprs, SourceLocation RParenLoc);
2492
2493 static OffsetOfExpr *CreateEmpty(const ASTContext &C,
2494 unsigned NumComps, unsigned NumExprs);
2495
2496 /// getOperatorLoc - Return the location of the operator.
2497 SourceLocation getOperatorLoc() const { return OperatorLoc; }
2498 void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
2499
2500 /// Return the location of the right parentheses.
2501 SourceLocation getRParenLoc() const { return RParenLoc; }
2502 void setRParenLoc(SourceLocation R) { RParenLoc = R; }
2503
2505 return TSInfo;
2506 }
2508 TSInfo = tsi;
2509 }
2510
2511 const OffsetOfNode &getComponent(unsigned Idx) const {
2512 assert(Idx < NumComps && "Subscript out of range");
2513 return getTrailingObjects<OffsetOfNode>()[Idx];
2514 }
2515
2516 void setComponent(unsigned Idx, OffsetOfNode ON) {
2517 assert(Idx < NumComps && "Subscript out of range");
2518 getTrailingObjects<OffsetOfNode>()[Idx] = ON;
2519 }
2520
2521 unsigned getNumComponents() const {
2522 return NumComps;
2523 }
2524
2525 Expr* getIndexExpr(unsigned Idx) {
2526 assert(Idx < NumExprs && "Subscript out of range");
2527 return getTrailingObjects<Expr *>()[Idx];
2528 }
2529
2530 const Expr *getIndexExpr(unsigned Idx) const {
2531 assert(Idx < NumExprs && "Subscript out of range");
2532 return getTrailingObjects<Expr *>()[Idx];
2533 }
2534
2535 void setIndexExpr(unsigned Idx, Expr* E) {
2536 assert(Idx < NumComps && "Subscript out of range");
2537 getTrailingObjects<Expr *>()[Idx] = E;
2538 }
2539
2540 unsigned getNumExpressions() const {
2541 return NumExprs;
2542 }
2543
2544 SourceLocation getBeginLoc() const LLVM_READONLY { return OperatorLoc; }
2545 SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
2546
2547 static bool classof(const Stmt *T) {
2548 return T->getStmtClass() == OffsetOfExprClass;
2549 }
2550
2551 // Iterators
2553 Stmt **begin = reinterpret_cast<Stmt **>(getTrailingObjects<Expr *>());
2554 return child_range(begin, begin + NumExprs);
2555 }
2557 Stmt *const *begin =
2558 reinterpret_cast<Stmt *const *>(getTrailingObjects<Expr *>());
2559 return const_child_range(begin, begin + NumExprs);
2560 }
2562};
2563
2564/// UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated)
2565/// expression operand. Used for sizeof/alignof (C99 6.5.3.4) and
2566/// vec_step (OpenCL 1.1 6.11.12).
2568 union {
2571 } Argument;
2572 SourceLocation OpLoc, RParenLoc;
2573
2574public:
2576 QualType resultType, SourceLocation op,
2577 SourceLocation rp)
2578 : Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_PRValue,
2579 OK_Ordinary),
2580 OpLoc(op), RParenLoc(rp) {
2581 assert(ExprKind <= UETT_Last && "invalid enum value!");
2582 UnaryExprOrTypeTraitExprBits.Kind = ExprKind;
2583 assert(static_cast<unsigned>(ExprKind) ==
2585 "UnaryExprOrTypeTraitExprBits.Kind overflow!");
2586 UnaryExprOrTypeTraitExprBits.IsType = true;
2587 Argument.Ty = TInfo;
2589 }
2590
2592 QualType resultType, SourceLocation op,
2593 SourceLocation rp);
2594
2595 /// Construct an empty sizeof/alignof expression.
2597 : Expr(UnaryExprOrTypeTraitExprClass, Empty) { }
2598
2600 return static_cast<UnaryExprOrTypeTrait>(UnaryExprOrTypeTraitExprBits.Kind);
2601 }
2603 assert(K <= UETT_Last && "invalid enum value!");
2605 assert(static_cast<unsigned>(K) == UnaryExprOrTypeTraitExprBits.Kind &&
2606 "UnaryExprOrTypeTraitExprBits.Kind overflow!");
2607 }
2608
2609 bool isArgumentType() const { return UnaryExprOrTypeTraitExprBits.IsType; }
2611 return getArgumentTypeInfo()->getType();
2612 }
2614 assert(isArgumentType() && "calling getArgumentType() when arg is expr");
2615 return Argument.Ty;
2616 }
2618 assert(!isArgumentType() && "calling getArgumentExpr() when arg is type");
2619 return static_cast<Expr*>(Argument.Ex);
2620 }
2621 const Expr *getArgumentExpr() const {
2622 return const_cast<UnaryExprOrTypeTraitExpr*>(this)->getArgumentExpr();
2623 }
2624
2626 Argument.Ex = E;
2627 UnaryExprOrTypeTraitExprBits.IsType = false;
2628 }
2630 Argument.Ty = TInfo;
2631 UnaryExprOrTypeTraitExprBits.IsType = true;
2632 }
2633
2634 /// Gets the argument type, or the type of the argument expression, whichever
2635 /// is appropriate.
2638 }
2639
2640 SourceLocation getOperatorLoc() const { return OpLoc; }
2641 void setOperatorLoc(SourceLocation L) { OpLoc = L; }
2642
2643 SourceLocation getRParenLoc() const { return RParenLoc; }
2644 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2645
2646 SourceLocation getBeginLoc() const LLVM_READONLY { return OpLoc; }
2647 SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
2648
2649 static bool classof(const Stmt *T) {
2650 return T->getStmtClass() == UnaryExprOrTypeTraitExprClass;
2651 }
2652
2653 // Iterators
2656};
2657
2658//===----------------------------------------------------------------------===//
2659// Postfix Operators.
2660//===----------------------------------------------------------------------===//
2661
2662/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
2663class ArraySubscriptExpr : public Expr {
2664 enum { LHS, RHS, END_EXPR };
2665 Stmt *SubExprs[END_EXPR];
2666
2667 bool lhsIsBase() const { return getRHS()->getType()->isIntegerType(); }
2668
2669public:
2671 ExprObjectKind OK, SourceLocation rbracketloc)
2672 : Expr(ArraySubscriptExprClass, t, VK, OK) {
2673 SubExprs[LHS] = lhs;
2674 SubExprs[RHS] = rhs;
2675 ArrayOrMatrixSubscriptExprBits.RBracketLoc = rbracketloc;
2677 }
2678
2679 /// Create an empty array subscript expression.
2681 : Expr(ArraySubscriptExprClass, Shell) { }
2682
2683 /// An array access can be written A[4] or 4[A] (both are equivalent).
2684 /// - getBase() and getIdx() always present the normalized view: A[4].
2685 /// In this case getBase() returns "A" and getIdx() returns "4".
2686 /// - getLHS() and getRHS() present the syntactic view. e.g. for
2687 /// 4[A] getLHS() returns "4".
2688 /// Note: Because vector element access is also written A[4] we must
2689 /// predicate the format conversion in getBase and getIdx only on the
2690 /// the type of the RHS, as it is possible for the LHS to be a vector of
2691 /// integer type
2692 Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); }
2693 const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
2694 void setLHS(Expr *E) { SubExprs[LHS] = E; }
2695
2696 Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); }
2697 const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
2698 void setRHS(Expr *E) { SubExprs[RHS] = E; }
2699
2700 Expr *getBase() { return lhsIsBase() ? getLHS() : getRHS(); }
2701 const Expr *getBase() const { return lhsIsBase() ? getLHS() : getRHS(); }
2702
2703 Expr *getIdx() { return lhsIsBase() ? getRHS() : getLHS(); }
2704 const Expr *getIdx() const { return lhsIsBase() ? getRHS() : getLHS(); }
2705
2706 SourceLocation getBeginLoc() const LLVM_READONLY {
2707 return getLHS()->getBeginLoc();
2708 }
2710
2712 return ArrayOrMatrixSubscriptExprBits.RBracketLoc;
2713 }
2715 ArrayOrMatrixSubscriptExprBits.RBracketLoc = L;
2716 }
2717
2718 SourceLocation getExprLoc() const LLVM_READONLY {
2719 return getBase()->getExprLoc();
2720 }
2721
2722 static bool classof(const Stmt *T) {
2723 return T->getStmtClass() == ArraySubscriptExprClass;
2724 }
2725
2726 // Iterators
2728 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
2729 }
2731 return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
2732 }
2733};
2734
2735/// MatrixSubscriptExpr - Matrix subscript expression for the MatrixType
2736/// extension.
2737/// MatrixSubscriptExpr can be either incomplete (only Base and RowIdx are set
2738/// so far, the type is IncompleteMatrixIdx) or complete (Base, RowIdx and
2739/// ColumnIdx refer to valid expressions). Incomplete matrix expressions only
2740/// exist during the initial construction of the AST.
2742 enum { BASE, ROW_IDX, COLUMN_IDX, END_EXPR };
2743 Stmt *SubExprs[END_EXPR];
2744
2745public:
2746 MatrixSubscriptExpr(Expr *Base, Expr *RowIdx, Expr *ColumnIdx, QualType T,
2747 SourceLocation RBracketLoc)
2748 : Expr(MatrixSubscriptExprClass, T, Base->getValueKind(),
2750 SubExprs[BASE] = Base;
2751 SubExprs[ROW_IDX] = RowIdx;
2752 SubExprs[COLUMN_IDX] = ColumnIdx;
2753 ArrayOrMatrixSubscriptExprBits.RBracketLoc = RBracketLoc;
2755 }
2756
2757 /// Create an empty matrix subscript expression.
2759 : Expr(MatrixSubscriptExprClass, Shell) {}
2760
2761 bool isIncomplete() const {
2762 bool IsIncomplete = hasPlaceholderType(BuiltinType::IncompleteMatrixIdx);
2763 assert((SubExprs[COLUMN_IDX] || IsIncomplete) &&
2764 "expressions without column index must be marked as incomplete");
2765 return IsIncomplete;
2766 }
2767 Expr *getBase() { return cast<Expr>(SubExprs[BASE]); }
2768 const Expr *getBase() const { return cast<Expr>(SubExprs[BASE]); }
2769 void setBase(Expr *E) { SubExprs[BASE] = E; }
2770
2771 Expr *getRowIdx() { return cast<Expr>(SubExprs[ROW_IDX]); }
2772 const Expr *getRowIdx() const { return cast<Expr>(SubExprs[ROW_IDX]); }
2773 void setRowIdx(Expr *E) { SubExprs[ROW_IDX] = E; }
2774
2775 Expr *getColumnIdx() { return cast_or_null<Expr>(SubExprs[COLUMN_IDX]); }
2776 const Expr *getColumnIdx() const {
2777 assert(!isIncomplete() &&
2778 "cannot get the column index of an incomplete expression");
2779 return cast<Expr>(SubExprs[COLUMN_IDX]);
2780 }
2781 void setColumnIdx(Expr *E) { SubExprs[COLUMN_IDX] = E; }
2782
2783 SourceLocation getBeginLoc() const LLVM_READONLY {
2784 return getBase()->getBeginLoc();
2785 }
2786
2788
2789 SourceLocation getExprLoc() const LLVM_READONLY {
2790 return getBase()->getExprLoc();
2791 }
2792
2794 return ArrayOrMatrixSubscriptExprBits.RBracketLoc;
2795 }
2797 ArrayOrMatrixSubscriptExprBits.RBracketLoc = L;
2798 }
2799
2800 static bool classof(const Stmt *T) {
2801 return T->getStmtClass() == MatrixSubscriptExprClass;
2802 }
2803
2804 // Iterators
2806 return child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
2807 }
2809 return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
2810 }
2811};
2812
2813/// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
2814/// CallExpr itself represents a normal function call, e.g., "f(x, 2)",
2815/// while its subclasses may represent alternative syntax that (semantically)
2816/// results in a function call. For example, CXXOperatorCallExpr is
2817/// a subclass for overloaded operator calls that use operator syntax, e.g.,
2818/// "str1 + str2" to resolve to a function call.
2819class CallExpr : public Expr {
2820 enum { FN = 0, PREARGS_START = 1 };
2821
2822 /// The number of arguments in the call expression.
2823 unsigned NumArgs;
2824
2825 /// The location of the right parentheses. This has a different meaning for
2826 /// the derived classes of CallExpr.
2827 SourceLocation RParenLoc;
2828
2829 // CallExpr store some data in trailing objects. However since CallExpr
2830 // is used a base of other expression classes we cannot use
2831 // llvm::TrailingObjects. Instead we manually perform the pointer arithmetic
2832 // and casts.
2833 //
2834 // The trailing objects are in order:
2835 //
2836 // * A single "Stmt *" for the callee expression.
2837 //
2838 // * An array of getNumPreArgs() "Stmt *" for the pre-argument expressions.
2839 //
2840 // * An array of getNumArgs() "Stmt *" for the argument expressions.
2841 //
2842 // * An optional of type FPOptionsOverride.
2843 //
2844 // Note that we store the offset in bytes from the this pointer to the start
2845 // of the trailing objects. It would be perfectly possible to compute it
2846 // based on the dynamic kind of the CallExpr. However 1.) we have plenty of
2847 // space in the bit-fields of Stmt. 2.) It was benchmarked to be faster to
2848 // compute this once and then load the offset from the bit-fields of Stmt,
2849 // instead of re-computing the offset each time the trailing objects are
2850 // accessed.
2851
2852 /// Return a pointer to the start of the trailing array of "Stmt *".
2853 Stmt **getTrailingStmts() {
2854 return reinterpret_cast<Stmt **>(reinterpret_cast<char *>(this) +
2855 CallExprBits.OffsetToTrailingObjects);
2856 }
2857 Stmt *const *getTrailingStmts() const {
2858 return const_cast<CallExpr *>(this)->getTrailingStmts();
2859 }
2860
2861 /// Map a statement class to the appropriate offset in bytes from the
2862 /// this pointer to the trailing objects.
2863 static unsigned offsetToTrailingObjects(StmtClass SC);
2864
2865 unsigned getSizeOfTrailingStmts() const {
2866 return (1 + getNumPreArgs() + getNumArgs()) * sizeof(Stmt *);
2867 }
2868
2869 size_t getOffsetOfTrailingFPFeatures() const {
2870 assert(hasStoredFPFeatures());
2871 return CallExprBits.OffsetToTrailingObjects + getSizeOfTrailingStmts();
2872 }
2873
2874public:
2875 enum class ADLCallKind : bool { NotADL, UsesADL };
2878
2879protected:
2880 /// Build a call expression, assuming that appropriate storage has been
2881 /// allocated for the trailing objects.
2882 CallExpr(StmtClass SC, Expr *Fn, ArrayRef<Expr *> PreArgs,
2884 SourceLocation RParenLoc, FPOptionsOverride FPFeatures,
2885 unsigned MinNumArgs, ADLCallKind UsesADL);
2886
2887 /// Build an empty call expression, for deserialization.
2888 CallExpr(StmtClass SC, unsigned NumPreArgs, unsigned NumArgs,
2889 bool hasFPFeatures, EmptyShell Empty);
2890
2891 /// Return the size in bytes needed for the trailing objects.
2892 /// Used by the derived classes to allocate the right amount of storage.
2893 static unsigned sizeOfTrailingObjects(unsigned NumPreArgs, unsigned NumArgs,
2894 bool HasFPFeatures) {
2895 return (1 + NumPreArgs + NumArgs) * sizeof(Stmt *) +
2896 HasFPFeatures * sizeof(FPOptionsOverride);
2897 }
2898
2899 Stmt *getPreArg(unsigned I) {
2900 assert(I < getNumPreArgs() && "Prearg access out of range!");
2901 return getTrailingStmts()[PREARGS_START + I];
2902 }
2903 const Stmt *getPreArg(unsigned I) const {
2904 assert(I < getNumPreArgs() && "Prearg access out of range!");
2905 return getTrailingStmts()[PREARGS_START + I];
2906 }
2907 void setPreArg(unsigned I, Stmt *PreArg) {
2908 assert(I < getNumPreArgs() && "Prearg access out of range!");
2909 getTrailingStmts()[PREARGS_START + I] = PreArg;
2910 }
2911
2912 unsigned getNumPreArgs() const { return CallExprBits.NumPreArgs; }
2913
2914 /// Return a pointer to the trailing FPOptions
2916 assert(hasStoredFPFeatures());
2917 return reinterpret_cast<FPOptionsOverride *>(
2918 reinterpret_cast<char *>(this) + CallExprBits.OffsetToTrailingObjects +
2919 getSizeOfTrailingStmts());
2920 }
2922 assert(hasStoredFPFeatures());
2923 return reinterpret_cast<const FPOptionsOverride *>(
2924 reinterpret_cast<const char *>(this) +
2925 CallExprBits.OffsetToTrailingObjects + getSizeOfTrailingStmts());
2926 }
2927
2928public:
2929 /// Create a call expression.
2930 /// \param Fn The callee expression,
2931 /// \param Args The argument array,
2932 /// \param Ty The type of the call expression (which is *not* the return
2933 /// type in general),
2934 /// \param VK The value kind of the call expression (lvalue, rvalue, ...),
2935 /// \param RParenLoc The location of the right parenthesis in the call
2936 /// expression.
2937 /// \param FPFeatures Floating-point features associated with the call,
2938 /// \param MinNumArgs Specifies the minimum number of arguments. The actual
2939 /// number of arguments will be the greater of Args.size()
2940 /// and MinNumArgs. This is used in a few places to allocate
2941 /// enough storage for the default arguments.
2942 /// \param UsesADL Specifies whether the callee was found through
2943 /// argument-dependent lookup.
2944 ///
2945 /// Note that you can use CreateTemporary if you need a temporary call
2946 /// expression on the stack.
2947 static CallExpr *Create(const ASTContext &Ctx, Expr *Fn,
2949 SourceLocation RParenLoc,
2950 FPOptionsOverride FPFeatures, unsigned MinNumArgs = 0,
2952
2953 /// Create a temporary call expression with no arguments in the memory
2954 /// pointed to by Mem. Mem must points to at least sizeof(CallExpr)
2955 /// + sizeof(Stmt *) bytes of storage, aligned to alignof(CallExpr):
2956 ///
2957 /// \code{.cpp}
2958 /// alignas(CallExpr) char Buffer[sizeof(CallExpr) + sizeof(Stmt *)];
2959 /// CallExpr *TheCall = CallExpr::CreateTemporary(Buffer, etc);
2960 /// \endcode
2961 static CallExpr *CreateTemporary(void *Mem, Expr *Fn, QualType Ty,
2962 ExprValueKind VK, SourceLocation RParenLoc,
2964
2965 /// Create an empty call expression, for deserialization.
2966 static CallExpr *CreateEmpty(const ASTContext &Ctx, unsigned NumArgs,
2967 bool HasFPFeatures, EmptyShell Empty);
2968
2969 Expr *getCallee() { return cast<Expr>(getTrailingStmts()[FN]); }
2970 const Expr *getCallee() const { return cast<Expr>(getTrailingStmts()[FN]); }
2971 void setCallee(Expr *F) { getTrailingStmts()[FN] = F; }
2972
2974 return static_cast<ADLCallKind>(CallExprBits.UsesADL);
2975 }
2977 CallExprBits.UsesADL = static_cast<bool>(V);
2978 }
2979 bool usesADL() const { return getADLCallKind() == UsesADL; }
2980
2981 bool hasStoredFPFeatures() const { return CallExprBits.HasFPFeatures; }
2982
2984 const Decl *getCalleeDecl() const {
2986 }
2987
2988 /// If the callee is a FunctionDecl, return it. Otherwise return null.
2990 return dyn_cast_or_null<FunctionDecl>(getCalleeDecl());
2991 }
2993 return dyn_cast_or_null<FunctionDecl>(getCalleeDecl());
2994 }
2995
2996 /// getNumArgs - Return the number of actual arguments to this call.
2997 unsigned getNumArgs() const { return NumArgs; }
2998
2999 /// Retrieve the call arguments.
3001 return reinterpret_cast<Expr **>(getTrailingStmts() + PREARGS_START +
3002 getNumPreArgs());
3003 }
3004 const Expr *const *getArgs() const {
3005 return reinterpret_cast<const Expr *const *>(
3006 getTrailingStmts() + PREARGS_START + getNumPreArgs());
3007 }
3008
3009 /// getArg - Return the specified argument.
3010 Expr *getArg(unsigned Arg) {
3011 assert(Arg < getNumArgs() && "Arg access out of range!");
3012 return getArgs()[Arg];
3013 }
3014 const Expr *getArg(unsigned Arg) const {
3015 assert(Arg < getNumArgs() && "Arg access out of range!");
3016 return getArgs()[Arg];
3017 }
3018
3019 /// setArg - Set the specified argument.
3020 /// ! the dependence bits might be stale after calling this setter, it is
3021 /// *caller*'s responsibility to recompute them by calling
3022 /// computeDependence().
3023 void setArg(unsigned Arg, Expr *ArgExpr) {
3024 assert(Arg < getNumArgs() && "Arg access out of range!");
3025 getArgs()[Arg] = ArgExpr;
3026 }
3027
3028 /// Compute and set dependence bits.
3031 this, llvm::ArrayRef(
3032 reinterpret_cast<Expr **>(getTrailingStmts() + PREARGS_START),
3033 getNumPreArgs())));
3034 }
3035
3036 /// Reduce the number of arguments in this call expression. This is used for
3037 /// example during error recovery to drop extra arguments. There is no way
3038 /// to perform the opposite because: 1.) We don't track how much storage
3039 /// we have for the argument array 2.) This would potentially require growing
3040 /// the argument array, something we cannot support since the arguments are
3041 /// stored in a trailing array.
3042 void shrinkNumArgs(unsigned NewNumArgs) {
3043 assert((NewNumArgs <= getNumArgs()) &&
3044 "shrinkNumArgs cannot increase the number of arguments!");
3045 NumArgs = NewNumArgs;
3046 }
3047
3048 /// Bluntly set a new number of arguments without doing any checks whatsoever.
3049 /// Only used during construction of a CallExpr in a few places in Sema.
3050 /// FIXME: Find a way to remove it.
3051 void setNumArgsUnsafe(unsigned NewNumArgs) { NumArgs = NewNumArgs; }
3052
3055 typedef llvm::iterator_range<arg_iterator> arg_range;
3056 typedef llvm::iterator_range<const_arg_iterator> const_arg_range;
3057
3060 return const_arg_range(arg_begin(), arg_end());
3061 }
3062
3064 return getTrailingStmts() + PREARGS_START + getNumPreArgs();
3065 }
3067
3069 return getTrailingStmts() + PREARGS_START + getNumPreArgs();
3070 }
3072
3073 /// This method provides fast access to all the subexpressions of
3074 /// a CallExpr without going through the slower virtual child_iterator
3075 /// interface. This provides efficient reverse iteration of the
3076 /// subexpressions. This is currently used for CFG construction.
3078 return llvm::ArrayRef(getTrailingStmts(),
3079 PREARGS_START + getNumPreArgs() + getNumArgs());
3080 }
3081
3082 /// Get FPOptionsOverride from trailing storage.
3084 assert(hasStoredFPFeatures());
3085 return *getTrailingFPFeatures();
3086 }
3087 /// Set FPOptionsOverride in trailing storage. Used only by Serialization.
3089 assert(hasStoredFPFeatures());
3090 *getTrailingFPFeatures() = F;
3091 }
3092
3093 /// Get the FP features status of this operator. Only meaningful for
3094 /// operations on floating point types.
3096 if (hasStoredFPFeatures())
3099 }
3100
3102 if (hasStoredFPFeatures())
3103 return getStoredFPFeatures();
3104 return FPOptionsOverride();
3105 }
3106
3107 /// getBuiltinCallee - If this is a call to a builtin, return the builtin ID
3108 /// of the callee. If not, return 0.
3109 unsigned getBuiltinCallee() const;
3110
3111 /// Returns \c true if this is a call to a builtin which does not
3112 /// evaluate side-effects within its arguments.
3113 bool isUnevaluatedBuiltinCall(const ASTContext &Ctx) const;
3114
3115 /// getCallReturnType - Get the return type of the call expr. This is not
3116 /// always the type of the expr itself, if the return type is a reference
3117 /// type.
3118 QualType getCallReturnType(const ASTContext &Ctx) const;
3119
3120 /// Returns the WarnUnusedResultAttr that is either declared on the called
3121 /// function, or its return type declaration.
3122 const Attr *getUnusedResultAttr(const ASTContext &Ctx) const;
3123
3124 /// Returns true if this call expression should warn on unused results.
3125 bool hasUnusedResultAttr(const ASTContext &Ctx) const {
3126 return getUnusedResultAttr(Ctx) != nullptr;
3127 }
3128
3129 SourceLocation getRParenLoc() const { return RParenLoc; }
3130 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
3131
3132 SourceLocation getBeginLoc() const LLVM_READONLY;
3133 SourceLocation getEndLoc() const LLVM_READONLY;
3134
3135 /// Return true if this is a call to __assume() or __builtin_assume() with
3136 /// a non-value-dependent constant parameter evaluating as false.
3137 bool isBuiltinAssumeFalse(const ASTContext &Ctx) const;
3138
3139 /// Used by Sema to implement MSVC-compatible delayed name lookup.
3140 /// (Usually Exprs themselves should set dependence).
3142 setDependence(getDependence() | ExprDependence::TypeValueInstantiation);
3143 }
3144
3145 bool isCallToStdMove() const;
3146
3147 static bool classof(const Stmt *T) {
3148 return T->getStmtClass() >= firstCallExprConstant &&
3149 T->getStmtClass() <= lastCallExprConstant;
3150 }
3151
3152 // Iterators
3154 return child_range(getTrailingStmts(), getTrailingStmts() + PREARGS_START +
3156 }
3157
3159 return const_child_range(getTrailingStmts(),
3160 getTrailingStmts() + PREARGS_START +
3162 }
3163};
3164
3165/// Extra data stored in some MemberExpr objects.
3167 /// The nested-name-specifier that qualifies the name, including
3168 /// source-location information.
3170
3171 /// The DeclAccessPair through which the MemberDecl was found due to
3172 /// name qualifiers.
3174};
3175
3176/// MemberExpr - [C99 6.5.2.3] Structure and Union Members. X->F and X.F.
3177///
3178class MemberExpr final
3179 : public Expr,
3180 private llvm::TrailingObjects<MemberExpr, MemberExprNameQualifier,
3181 ASTTemplateKWAndArgsInfo,
3182 TemplateArgumentLoc> {
3183 friend class ASTReader;
3184 friend class ASTStmtReader;
3185 friend class ASTStmtWriter;
3186 friend TrailingObjects;
3187
3188 /// Base - the expression for the base pointer or structure references. In
3189 /// X.F, this is "X".
3190 Stmt *Base;
3191
3192 /// MemberDecl - This is the decl being referenced by the field/member name.
3193 /// In X.F, this is the decl referenced by F.
3194 ValueDecl *MemberDecl;
3195
3196 /// MemberDNLoc - Provides source/type location info for the
3197 /// declaration name embedded in MemberDecl.
3198 DeclarationNameLoc MemberDNLoc;
3199
3200 /// MemberLoc - This is the location of the member name.
3201 SourceLocation MemberLoc;
3202
3203 size_t numTrailingObjects(OverloadToken<MemberExprNameQualifier>) const {
3204 return hasQualifierOrFoundDecl();
3205 }
3206
3207 size_t numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
3208 return hasTemplateKWAndArgsInfo();
3209 }
3210
3211 bool hasQualifierOrFoundDecl() const {
3212 return MemberExprBits.HasQualifierOrFoundDecl;
3213 }
3214
3215 bool hasTemplateKWAndArgsInfo() const {
3216 return MemberExprBits.HasTemplateKWAndArgsInfo;
3217 }
3218
3219 MemberExpr(Expr *Base, bool IsArrow, SourceLocation OperatorLoc,
3220 ValueDecl *MemberDecl, const DeclarationNameInfo &NameInfo,
3221 QualType T, ExprValueKind VK, ExprObjectKind OK,
3222 NonOdrUseReason NOUR);
3223 MemberExpr(EmptyShell Empty)
3224 : Expr(MemberExprClass, Empty), Base(), MemberDecl() {}
3225
3226public:
3227 static MemberExpr *Create(const ASTContext &C, Expr *Base, bool IsArrow,
3228 SourceLocation OperatorLoc,
3229 NestedNameSpecifierLoc QualifierLoc,
3230 SourceLocation TemplateKWLoc, ValueDecl *MemberDecl,
3231 DeclAccessPair FoundDecl,
3232 DeclarationNameInfo MemberNameInfo,
3233 const TemplateArgumentListInfo *TemplateArgs,
3234 QualType T, ExprValueKind VK, ExprObjectKind OK,
3235 NonOdrUseReason NOUR);
3236
3237 /// Create an implicit MemberExpr, with no location, qualifier, template
3238 /// arguments, and so on. Suitable only for non-static member access.
3240 bool IsArrow, ValueDecl *MemberDecl,
3241 QualType T, ExprValueKind VK,
3242 ExprObjectKind OK) {
3243 return Create(C, Base, IsArrow, SourceLocation(), NestedNameSpecifierLoc(),
3244 SourceLocation(), MemberDecl,
3245 DeclAccessPair::make(MemberDecl, MemberDecl->getAccess()),
3246 DeclarationNameInfo(), nullptr, T, VK, OK, NOUR_None);
3247 }
3248
3249 static MemberExpr *CreateEmpty(const ASTContext &Context, bool HasQualifier,
3250 bool HasFoundDecl,
3251 bool HasTemplateKWAndArgsInfo,
3252 unsigned NumTemplateArgs);
3253
3254 void setBase(Expr *E) { Base = E; }
3255 Expr *getBase() const { return cast<Expr>(Base); }
3256
3257 /// Retrieve the member declaration to which this expression refers.
3258 ///
3259 /// The returned declaration will be a FieldDecl or (in C++) a VarDecl (for
3260 /// static data members), a CXXMethodDecl, or an EnumConstantDecl.
3261 ValueDecl *getMemberDecl() const { return MemberDecl; }
3262 void setMemberDecl(ValueDecl *D);
3263
3264 /// Retrieves the declaration found by lookup.
3266 if (!hasQualifierOrFoundDecl())
3268 getMemberDecl()->getAccess());
3269 return getTrailingObjects<MemberExprNameQualifier>()->FoundDecl;
3270 }
3271
3272 /// Determines whether this member expression actually had
3273 /// a C++ nested-name-specifier prior to the name of the member, e.g.,
3274 /// x->Base::foo.
3275 bool hasQualifier() const { return getQualifier() != nullptr; }
3276
3277 /// If the member name was qualified, retrieves the
3278 /// nested-name-specifier that precedes the member name, with source-location
3279 /// information.
3281 if (!hasQualifierOrFoundDecl())
3282 return NestedNameSpecifierLoc();
3283 return getTrailingObjects<MemberExprNameQualifier>()->QualifierLoc;
3284 }
3285
3286 /// If the member name was qualified, retrieves the
3287 /// nested-name-specifier that precedes the member name. Otherwise, returns
3288 /// NULL.
3291 }
3292
3293 /// Retrieve the location of the template keyword preceding
3294 /// the member name, if any.
3296 if (!hasTemplateKWAndArgsInfo())
3297 return SourceLocation();
3298 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->TemplateKWLoc;
3299 }
3300
3301 /// Retrieve the location of the left angle bracket starting the
3302 /// explicit template argument list following the member name, if any.
3304 if (!hasTemplateKWAndArgsInfo())
3305 return SourceLocation();
3306 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->LAngleLoc;
3307 }
3308
3309 /// Retrieve the location of the right angle bracket ending the
3310 /// explicit template argument list following the member name, if any.
3312 if (!hasTemplateKWAndArgsInfo())
3313 return SourceLocation();
3314 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->RAngleLoc;
3315 }
3316
3317 /// Determines whether the member name was preceded by the template keyword.
3319
3320 /// Determines whether the member name was followed by an
3321 /// explicit template argument list.
3322 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
3323
3324 /// Copies the template arguments (if present) into the given
3325 /// structure.
3328 getTrailingObjects<ASTTemplateKWAndArgsInfo>()->copyInto(
3329 getTrailingObjects<TemplateArgumentLoc>(), List);
3330 }
3331
3332 /// Retrieve the template arguments provided as part of this
3333 /// template-id.
3336 return nullptr;
3337
3338 return getTrailingObjects<TemplateArgumentLoc>();
3339 }
3340
3341 /// Retrieve the number of template arguments provided as part of this
3342 /// template-id.
3343 unsigned getNumTemplateArgs() const {
3345 return 0;
3346
3347 return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs;
3348 }
3349
3351 return {getTemplateArgs(), getNumTemplateArgs()};
3352 }
3353
3354 /// Retrieve the member declaration name info.
3356 return DeclarationNameInfo(MemberDecl->getDeclName(),
3357 MemberLoc, MemberDNLoc);
3358 }
3359
3360 SourceLocation getOperatorLoc() const { return MemberExprBits.OperatorLoc; }
3361
3362 bool isArrow() const { return MemberExprBits.IsArrow; }
3363 void setArrow(bool A) { MemberExprBits.IsArrow = A; }
3364
3365 /// getMemberLoc - Return the location of the "member", in X->F, it is the
3366 /// location of 'F'.
3367 SourceLocation getMemberLoc() const { return MemberLoc; }
3368 void setMemberLoc(SourceLocation L) { MemberLoc = L; }
3369
3370 SourceLocation getBeginLoc() const LLVM_READONLY;
3371 SourceLocation getEndLoc() const LLVM_READONLY;
3372
3373 SourceLocation getExprLoc() const LLVM_READONLY { return MemberLoc; }
3374
3375 /// Determine whether the base of this explicit is implicit.
3376 bool isImplicitAccess() const {
3377 return getBase() && getBase()->isImplicitCXXThis();
3378 }
3379
3380 /// Returns true if this member expression refers to a method that
3381 /// was resolved from an overloaded set having size greater than 1.
3383 return MemberExprBits.HadMultipleCandidates;
3384 }
3385 /// Sets the flag telling whether this expression refers to
3386 /// a method that was resolved from an overloaded set having size
3387 /// greater than 1.
3388 void setHadMultipleCandidates(bool V = true) {
3389 MemberExprBits.HadMultipleCandidates = V;
3390 }
3391
3392 /// Returns true if virtual dispatch is performed.
3393 /// If the member access is fully qualified, (i.e. X::f()), virtual
3394 /// dispatching is not performed. In -fapple-kext mode qualified
3395 /// calls to virtual method will still go through the vtable.
3396 bool performsVirtualDispatch(const LangOptions &LO) const {
3397 return LO.AppleKext || !hasQualifier();
3398 }
3399
3400 /// Is this expression a non-odr-use reference, and if so, why?
3401 /// This is only meaningful if the named member is a static member.
3403 return static_cast<NonOdrUseReason>(MemberExprBits.NonOdrUseReason);
3404 }
3405
3406 static bool classof(const Stmt *T) {
3407 return T->getStmtClass() == MemberExprClass;
3408 }
3409
3410 // Iterators
3413 return const_child_range(&Base, &Base + 1);
3414 }
3415};
3416
3417/// CompoundLiteralExpr - [C99 6.5.2.5]
3418///
3420 /// LParenLoc - If non-null, this is the location of the left paren in a
3421 /// compound literal like "(int){4}". This can be null if this is a
3422 /// synthesized compound expression.
3423 SourceLocation LParenLoc;
3424
3425 /// The type as written. This can be an incomplete array type, in
3426 /// which case the actual expression type will be different.
3427 /// The int part of the pair stores whether this expr is file scope.
3428 llvm::PointerIntPair<TypeSourceInfo *, 1, bool> TInfoAndScope;
3429 Stmt *Init;
3430public:
3432 QualType T, ExprValueKind VK, Expr *init, bool fileScope)
3433 : Expr(CompoundLiteralExprClass, T, VK, OK_Ordinary),
3434 LParenLoc(lparenloc), TInfoAndScope(tinfo, fileScope), Init(init) {
3436 }
3437
3438 /// Construct an empty compound literal.
3440 : Expr(CompoundLiteralExprClass, Empty) { }
3441
3442 const Expr *getInitializer() const { return cast<Expr>(Init); }
3443 Expr *getInitializer() { return cast<Expr>(Init); }
3444 void setInitializer(Expr *E) { Init = E; }
3445
3446 bool isFileScope() const { return TInfoAndScope.getInt(); }
3447 void setFileScope(bool FS) { TInfoAndScope.setInt(FS); }
3448
3449 SourceLocation getLParenLoc() const { return LParenLoc; }
3450 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
3451
3453 return TInfoAndScope.getPointer();
3454 }
3456 TInfoAndScope.setPointer(tinfo);
3457 }
3458
3459 SourceLocation getBeginLoc() const LLVM_READONLY {
3460 // FIXME: Init should never be null.
3461 if (!Init)
3462 return SourceLocation();
3463 if (LParenLoc.isInvalid())
3464 return Init->getBeginLoc();
3465 return LParenLoc;
3466 }
3467 SourceLocation getEndLoc() const LLVM_READONLY {
3468 // FIXME: Init should never be null.
3469 if (!Init)
3470 return SourceLocation();
3471 return Init->getEndLoc();
3472 }
3473
3474 static bool classof(const Stmt *T) {
3475 return T->getStmtClass() == CompoundLiteralExprClass;
3476 }
3477
3478 // Iterators
3479 child_range children() { return child_range(&Init, &Init+1); }
3481 return const_child_range(&Init, &Init + 1);
3482 }
3483};
3484
3485/// CastExpr - Base class for type casts, including both implicit
3486/// casts (ImplicitCastExpr) and explicit casts that have some
3487/// representation in the source code (ExplicitCastExpr's derived
3488/// classes).
3489class CastExpr : public Expr {
3490 Stmt *Op;
3491
3492 bool CastConsistency() const;
3493
3494 const CXXBaseSpecifier * const *path_buffer() const {
3495 return const_cast<CastExpr*>(this)->path_buffer();
3496 }
3497 CXXBaseSpecifier **path_buffer();
3498
3499 friend class ASTStmtReader;
3500
3501protected:
3503 Expr *op, unsigned BasePathSize, bool HasFPFeatures)
3504 : Expr(SC, ty, VK, OK_Ordinary), Op(op) {
3505 CastExprBits.Kind = kind;
3506 CastExprBits.PartOfExplicitCast = false;
3507 CastExprBits.BasePathSize = BasePathSize;
3508 assert((CastExprBits.BasePathSize == BasePathSize) &&
3509 "BasePathSize overflow!");
3510 assert(CastConsistency());
3511 CastExprBits.HasFPFeatures = HasFPFeatures;
3512 }
3513
3514 /// Construct an empty cast.
3515 CastExpr(StmtClass SC, EmptyShell Empty, unsigned BasePathSize,
3516 bool HasFPFeatures)
3517 : Expr(SC, Empty) {
3518 CastExprBits.PartOfExplicitCast = false;
3519 CastExprBits.BasePathSize = BasePathSize;
3520 CastExprBits.HasFPFeatures = HasFPFeatures;
3521 assert((CastExprBits.BasePathSize == BasePathSize) &&
3522 "BasePathSize overflow!");
3523 }
3524
3525 /// Return a pointer to the trailing FPOptions.
3526 /// \pre hasStoredFPFeatures() == true
3529 return const_cast<CastExpr *>(this)->getTrailingFPFeatures();
3530 }
3531
3532public:
3533 CastKind getCastKind() const { return (CastKind) CastExprBits.Kind; }
3534 void setCastKind(CastKind K) { CastExprBits.Kind = K; }
3535
3536 static const char *getCastKindName(CastKind CK);
3537 const char *getCastKindName() const { return getCastKindName(getCastKind()); }
3538
3539 Expr *getSubExpr() { return cast<Expr>(Op); }
3540 const Expr *getSubExpr() const { return cast<Expr>(Op); }
3541 void setSubExpr(Expr *E) { Op = E; }
3542
3543 /// Retrieve the cast subexpression as it was written in the source
3544 /// code, looking through any implicit casts or other intermediate nodes
3545 /// introduced by semantic analysis.
3547 const Expr *getSubExprAsWritten() const {
3548 return const_cast<CastExpr *>(this)->getSubExprAsWritten();
3549 }
3550
3551 /// If this cast applies a user-defined conversion, retrieve the conversion
3552 /// function that it invokes.
3554
3557 bool path_empty() const { return path_size() == 0; }
3558 unsigned path_size() const { return CastExprBits.BasePathSize; }
3559 path_iterator path_begin() { return path_buffer(); }
3560 path_iterator path_end() { return path_buffer() + path_size(); }
3561 path_const_iterator path_begin() const { return path_buffer(); }
3562 path_const_iterator path_end() const { return path_buffer() + path_size(); }
3563
3564 llvm::iterator_range<path_iterator> path() {
3565 return llvm::make_range(path_begin(), path_end());
3566 }
3567 llvm::iterator_range<path_const_iterator> path() const {
3568 return llvm::make_range(path_begin(), path_end());
3569 }
3570
3572 assert(getCastKind() == CK_ToUnion);
3574 }
3575
3576 bool hasStoredFPFeatures() const { return CastExprBits.HasFPFeatures; }
3577
3578 /// Get FPOptionsOverride from trailing storage.
3580 assert(hasStoredFPFeatures());
3581 return *getTrailingFPFeatures();
3582 }
3583
3584 /// Get the FP features status of this operation. Only meaningful for
3585 /// operations on floating point types.
3587 if (hasStoredFPFeatures())
3590 }
3591
3593 if (hasStoredFPFeatures())
3594 return getStoredFPFeatures();
3595 return FPOptionsOverride();
3596 }
3597
3598 /// Return
3599 // True : if this conversion changes the volatile-ness of a gl-value.
3600 // Qualification conversions on gl-values currently use CK_NoOp, but
3601 // it's important to recognize volatile-changing conversions in
3602 // clients code generation that normally eagerly peephole loads. Note
3603 // that the query is answering for this specific node; Sema may
3604 // produce multiple cast nodes for any particular conversion sequence.
3605 // False : Otherwise.
3607 return (isGLValue() && (getType().isVolatileQualified() !=
3608 getSubExpr()->getType().isVolatileQualified()));
3609 }
3610
3611 static const FieldDecl *getTargetFieldForToUnionCast(QualType unionType,
3612 QualType opType);
3613 static const FieldDecl *getTargetFieldForToUnionCast(const RecordDecl *RD,
3614 QualType opType);
3615
3616 static bool classof(const Stmt *T) {
3617 return T->getStmtClass() >= firstCastExprConstant &&
3618 T->getStmtClass() <= lastCastExprConstant;
3619 }
3620
3621 // Iterators
3622 child_range children() { return child_range(&Op, &Op+1); }
3623 const_child_range children() const { return const_child_range(&Op, &Op + 1); }
3624};
3625
3626/// ImplicitCastExpr - Allows us to explicitly represent implicit type
3627/// conversions, which have no direct representation in the original
3628/// source code. For example: converting T[]->T*, void f()->void
3629/// (*f)(), float->double, short->int, etc.
3630///
3631/// In C, implicit casts always produce rvalues. However, in C++, an
3632/// implicit cast whose result is being bound to a reference will be
3633/// an lvalue or xvalue. For example:
3634///
3635/// @code
3636/// class Base { };
3637/// class Derived : public Base { };
3638/// Derived &&ref();
3639/// void f(Derived d) {
3640/// Base& b = d; // initializer is an ImplicitCastExpr
3641/// // to an lvalue of type Base
3642/// Base&& r = ref(); // initializer is an ImplicitCastExpr
3643/// // to an xvalue of type Base
3644/// }
3645/// @endcode
3647 : public CastExpr,
3648 private llvm::TrailingObjects<ImplicitCastExpr, CXXBaseSpecifier *,
3649 FPOptionsOverride> {
3650
3651 ImplicitCastExpr(QualType ty, CastKind kind, Expr *op,
3652 unsigned BasePathLength, FPOptionsOverride FPO,
3653 ExprValueKind VK)
3654 : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, BasePathLength,
3657 if (hasStoredFPFeatures())
3658 *getTrailingFPFeatures() = FPO;
3659 }
3660
3661 /// Construct an empty implicit cast.
3662 explicit ImplicitCastExpr(EmptyShell Shell, unsigned PathSize,
3663 bool HasFPFeatures)
3664 : CastExpr(ImplicitCastExprClass, Shell, PathSize, HasFPFeatures) {}
3665
3666 unsigned numTrailingObjects(OverloadToken<CXXBaseSpecifier *>) const {
3667 return path_size();
3668 }
3669
3670public:
3674 : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, 0,
3675 FPO.requiresTrailingStorage()) {
3676 if (hasStoredFPFeatures())
3677 *getTrailingFPFeatures() = FPO;
3678 }
3679
3680 bool isPartOfExplicitCast() const { return CastExprBits.PartOfExplicitCast; }
3681 void setIsPartOfExplicitCast(bool PartOfExplicitCast) {
3682 CastExprBits.PartOfExplicitCast = PartOfExplicitCast;
3683 }
3684
3685 static ImplicitCastExpr *Create(const ASTContext &Context, QualType T,
3686 CastKind Kind, Expr *Operand,
3687 const CXXCastPath *BasePath,
3689
3690 static ImplicitCastExpr *CreateEmpty(const ASTContext &Context,
3691 unsigned PathSize, bool HasFPFeatures);
3692
3693 SourceLocation getBeginLoc() const LLVM_READONLY {
3694 return getSubExpr()->getBeginLoc();
3695 }
3696 SourceLocation getEndLoc() const LLVM_READONLY {
3697 return getSubExpr()->getEndLoc();
3698 }
3699
3700 static bool classof(const Stmt *T) {
3701 return T->getStmtClass() == ImplicitCastExprClass;
3702 }
3703
3705 friend class CastExpr;
3706};
3707
3708/// ExplicitCastExpr - An explicit cast written in the source
3709/// code.
3710///
3711/// This class is effectively an abstract class, because it provides
3712/// the basic representation of an explicitly-written cast without
3713/// specifying which kind of cast (C cast, functional cast, static
3714/// cast, etc.) was written; specific derived classes represent the
3715/// particular style of cast and its location information.
3716///
3717/// Unlike implicit casts, explicit cast nodes have two different
3718/// types: the type that was written into the source code, and the
3719/// actual type of the expression as determined by semantic
3720/// analysis. These types may differ slightly. For example, in C++ one
3721/// can cast to a reference type, which indicates that the resulting
3722/// expression will be an lvalue or xvalue. The reference type, however,
3723/// will not be used as the type of the expression.
3725 /// TInfo - Source type info for the (written) type
3726 /// this expression is casting to.
3727 TypeSourceInfo *TInfo;
3728
3729protected:
3731 CastKind kind, Expr *op, unsigned PathSize,
3732 bool HasFPFeatures, TypeSourceInfo *writtenTy)
3733 : CastExpr(SC, exprTy, VK, kind, op, PathSize, HasFPFeatures),
3734 TInfo(writtenTy) {
3736 }
3737
3738 /// Construct an empty explicit cast.
3739 ExplicitCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize,
3740 bool HasFPFeatures)
3741 : CastExpr(SC, Shell, PathSize, HasFPFeatures) {}
3742
3743public:
3744 /// getTypeInfoAsWritten - Returns the type source info for the type
3745 /// that this expression is casting to.
3746 TypeSourceInfo *getTypeInfoAsWritten() const { return TInfo; }
3747 void setTypeInfoAsWritten(TypeSourceInfo *writtenTy) { TInfo = writtenTy; }
3748
3749 /// getTypeAsWritten - Returns the type that this expression is
3750 /// casting to, as written in the source code.
3751 QualType getTypeAsWritten() const { return TInfo->getType(); }
3752
3753 static bool classof(const Stmt *T) {
3754 return T->getStmtClass() >= firstExplicitCastExprConstant &&
3755 T->getStmtClass() <= lastExplicitCastExprConstant;
3756 }
3757};
3758
3759/// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style
3760/// cast in C++ (C++ [expr.cast]), which uses the syntax
3761/// (Type)expr. For example: @c (int)f.
3763 : public ExplicitCastExpr,
3764 private llvm::TrailingObjects<CStyleCastExpr, CXXBaseSpecifier *,
3765 FPOptionsOverride> {
3766 SourceLocation LPLoc; // the location of the left paren
3767 SourceLocation RPLoc; // the location of the right paren
3768
3769 CStyleCastExpr(QualType exprTy, ExprValueKind vk, CastKind kind, Expr *op,
3770 unsigned PathSize, FPOptionsOverride FPO,
3772 : ExplicitCastExpr(CStyleCastExprClass, exprTy, vk, kind, op, PathSize,
3773 FPO.requiresTrailingStorage(), writtenTy),
3774 LPLoc(l), RPLoc(r) {
3775 if (hasStoredFPFeatures())
3776 *getTrailingFPFeatures() = FPO;
3777 }
3778
3779 /// Construct an empty C-style explicit cast.
3780 explicit CStyleCastExpr(EmptyShell Shell, unsigned PathSize,
3781 bool HasFPFeatures)
3782 : ExplicitCastExpr(CStyleCastExprClass, Shell, PathSize, HasFPFeatures) {}
3783
3784 unsigned numTrailingObjects(OverloadToken<CXXBaseSpecifier *>) const {
3785 return path_size();
3786 }
3787
3788public:
3789 static CStyleCastExpr *
3790 Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind K,
3791 Expr *Op, const CXXCastPath *BasePath, FPOptionsOverride FPO,
3793
3794 static CStyleCastExpr *CreateEmpty(const ASTContext &Context,
3795 unsigned PathSize, bool HasFPFeatures);
3796
3797 SourceLocation getLParenLoc() const { return LPLoc; }
3798 void setLParenLoc(SourceLocation L) { LPLoc = L; }
3799
3800 SourceLocation getRParenLoc() const { return RPLoc; }
3801 void setRParenLoc(SourceLocation L) { RPLoc = L; }
3802
3803 SourceLocation getBeginLoc() const LLVM_READONLY { return LPLoc; }
3804 SourceLocation getEndLoc() const LLVM_READONLY {
3805 return getSubExpr()->getEndLoc();
3806 }
3807
3808 static bool classof(const Stmt *T) {
3809 return T->getStmtClass() == CStyleCastExprClass;
3810 }
3811
3813 friend class CastExpr;
3814};
3815
3816/// A builtin binary operation expression such as "x + y" or "x <= y".
3817///
3818/// This expression node kind describes a builtin binary operation,
3819/// such as "x + y" for integer values "x" and "y". The operands will
3820/// already have been converted to appropriate types (e.g., by
3821/// performing promotions or conversions).
3822///
3823/// In C++, where operators may be overloaded, a different kind of
3824/// expression node (CXXOperatorCallExpr) is used to express the
3825/// invocation of an overloaded operator with operator syntax. Within
3826/// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is
3827/// used to store an expression "x + y" depends on the subexpressions
3828/// for x and y. If neither x or y is type-dependent, and the "+"
3829/// operator resolves to a built-in operation, BinaryOperator will be
3830/// used to express the computation (x and y may still be
3831/// value-dependent). If either x or y is type-dependent, or if the
3832/// "+" resolves to an overloaded operator, CXXOperatorCallExpr will
3833/// be used to express the computation.
3834class BinaryOperator : public Expr {
3835 enum { LHS, RHS, END_EXPR };
3836 Stmt *SubExprs[END_EXPR];
3837
3838public:
3840
3841protected:
3842 size_t offsetOfTrailingStorage() const;
3843
3844 /// Return a pointer to the trailing FPOptions
3846 assert(BinaryOperatorBits.HasFPFeatures);
3847 return reinterpret_cast<FPOptionsOverride *>(
3848 reinterpret_cast<char *>(this) + offsetOfTrailingStorage());
3849 }
3851 assert(BinaryOperatorBits.HasFPFeatures);
3852 return reinterpret_cast<const FPOptionsOverride *>(
3853 reinterpret_cast<const char *>(this) + offsetOfTrailingStorage());
3854 }
3855
3856 /// Build a binary operator, assuming that appropriate storage has been
3857 /// allocated for the trailing objects when needed.
3858 BinaryOperator(const ASTContext &Ctx, Expr *lhs, Expr *rhs, Opcode opc,
3860 SourceLocation opLoc, FPOptionsOverride FPFeatures);
3861
3862 /// Construct an empty binary operator.
3863 explicit BinaryOperator(EmptyShell Empty) : Expr(BinaryOperatorClass, Empty) {
3864 BinaryOperatorBits.Opc = BO_Comma;
3865 }
3866
3867public:
3868 static BinaryOperator *CreateEmpty(const ASTContext &C, bool hasFPFeatures);
3869
3870 static BinaryOperator *Create(const ASTContext &C, Expr *lhs, Expr *rhs,
3871 Opcode opc, QualType ResTy, ExprValueKind VK,
3873 FPOptionsOverride FPFeatures);
3877
3879 return static_cast<Opcode>(BinaryOperatorBits.Opc);
3880 }
3881 void setOpcode(Opcode Opc) { BinaryOperatorBits.Opc = Opc; }
3882
3883 Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
3884 void setLHS(Expr *E) { SubExprs[LHS] = E; }
3885 Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
3886 void setRHS(Expr *E) { SubExprs[RHS] = E; }
3887
3888 SourceLocation getBeginLoc() const LLVM_READONLY {
3889 return getLHS()->getBeginLoc();
3890 }
3891 SourceLocation getEndLoc() const LLVM_READONLY {
3892 return getRHS()->getEndLoc();
3893 }
3894
3895 /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
3896 /// corresponds to, e.g. "<<=".
3897 static StringRef getOpcodeStr(Opcode Op);
3898
3899 StringRef getOpcodeStr() const { return getOpcodeStr(getOpcode()); }
3900
3901 /// Retrieve the binary opcode that corresponds to the given
3902 /// overloaded operator.
3904
3905 /// Retrieve the overloaded operator kind that corresponds to
3906 /// the given binary opcode.
3908
3909 /// predicates to categorize the respective opcodes.
3910 static bool isPtrMemOp(Opcode Opc) {
3911 return Opc == BO_PtrMemD || Opc == BO_PtrMemI;
3912 }
3913 bool isPtrMemOp() const { return isPtrMemOp(getOpcode()); }
3914
3915 static bool isMultiplicativeOp(Opcode Opc) {
3916 return Opc >= BO_Mul && Opc <= BO_Rem;
3917 }
3919 static bool isAdditiveOp(Opcode Opc) { return Opc == BO_Add || Opc==BO_Sub; }
3920 bool isAdditiveOp() const { return isAdditiveOp(getOpcode()); }
3921 static bool isShiftOp(Opcode Opc) { return Opc == BO_Shl || Opc == BO_Shr; }
3922 bool isShiftOp() const { return isShiftOp(getOpcode()); }
3923
3924 static bool isBitwiseOp(Opcode Opc) { return Opc >= BO_And && Opc <= BO_Or; }
3925 bool isBitwiseOp() const { return isBitwiseOp(getOpcode()); }
3926
3927 static bool isRelationalOp(Opcode Opc) { return Opc >= BO_LT && Opc<=BO_GE; }
3928 bool isRelationalOp() const { return isRelationalOp(getOpcode()); }
3929
3930 static bool isEqualityOp(Opcode Opc) { return Opc == BO_EQ || Opc == BO_NE; }
3931 bool isEqualityOp() const { return isEqualityOp(getOpcode()); }
3932
3933 static bool isComparisonOp(Opcode Opc) { return Opc >= BO_Cmp && Opc<=BO_NE; }
3934 bool isComparisonOp() const { return isComparisonOp(getOpcode()); }
3935
3936 static bool isCommaOp(Opcode Opc) { return Opc == BO_Comma; }
3937 bool isCommaOp() const { return isCommaOp(getOpcode()); }
3938
3940 switch (Opc) {
3941 default:
3942 llvm_unreachable("Not a comparison operator.");
3943 case BO_LT: return BO_GE;
3944 case BO_GT: return BO_LE;
3945 case BO_LE: return BO_GT;
3946 case BO_GE: return BO_LT;
3947 case BO_EQ: return BO_NE;
3948 case BO_NE: return BO_EQ;
3949 }
3950 }
3951
3953 switch (Opc) {
3954 default:
3955 llvm_unreachable("Not a comparison operator.");
3956 case BO_LT: return BO_GT;
3957 case BO_GT: return BO_LT;
3958 case BO_LE: return BO_GE;
3959 case BO_GE: return BO_LE;
3960 case BO_EQ:
3961 case BO_NE:
3962 return Opc;
3963 }
3964 }
3965
3966 static bool isLogicalOp(Opcode Opc) { return Opc == BO_LAnd || Opc==BO_LOr; }
3967 bool isLogicalOp() const { return isLogicalOp(getOpcode()); }
3968
3969 static bool isAssignmentOp(Opcode Opc) {
3970 return Opc >= BO_Assign && Opc <= BO_OrAssign;
3971 }
3972 bool isAssignmentOp() const { return isAssignmentOp(getOpcode()); }
3973
3975 return Opc > BO_Assign && Opc <= BO_OrAssign;
3976 }
3979 }
3981 assert(isCompoundAssignmentOp(Opc));
3982 if (Opc >= BO_AndAssign)
3983 return Opcode(unsigned(Opc) - BO_AndAssign + BO_And);
3984 else
3985 return Opcode(unsigned(Opc) - BO_MulAssign + BO_Mul);
3986 }
3987
3988 static bool isShiftAssignOp(Opcode Opc) {
3989 return Opc == BO_ShlAssign || Opc == BO_ShrAssign;
3990 }
3991 bool isShiftAssignOp() const {
3992 return isShiftAssignOp(getOpcode());
3993 }
3994
3995 /// Return true if a binary operator using the specified opcode and operands
3996 /// would match the 'p = (i8*)nullptr + n' idiom for casting a pointer-sized
3997 /// integer to a pointer.
3999 const Expr *LHS,
4000 const Expr *RHS);
4001
4002 static bool classof(const Stmt *S) {
4003 return S->getStmtClass() >= firstBinaryOperatorConstant &&
4004 S->getStmtClass() <= lastBinaryOperatorConstant;
4005 }
4006
4007 // Iterators
4009 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
4010 }
4012 return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
4013 }
4014
4015 /// Set and fetch the bit that shows whether FPFeatures needs to be
4016 /// allocated in Trailing Storage
4017 void setHasStoredFPFeatures(bool B) { BinaryOperatorBits.HasFPFeatures = B; }
4018 bool hasStoredFPFeatures() const { return BinaryOperatorBits.HasFPFeatures; }
4019
4020 /// Get FPFeatures from trailing storage
4022 assert(hasStoredFPFeatures());
4023 return *getTrailingFPFeatures();
4024 }
4025 /// Set FPFeatures in trailing storage, used only by Serialization
4027 assert(BinaryOperatorBits.HasFPFeatures);
4028 *getTrailingFPFeatures() = F;
4029 }
4030
4031 /// Get the FP features status of this operator. Only meaningful for
4032 /// operations on floating point types.
4034 if (BinaryOperatorBits.HasFPFeatures)
4037 }
4038
4039 // This is used in ASTImporter
4041 if (BinaryOperatorBits.HasFPFeatures)
4042 return getStoredFPFeatures();
4043 return FPOptionsOverride();
4044 }
4045
4046 /// Get the FP contractability status of this operator. Only meaningful for
4047 /// operations on floating point types.
4050 }
4051
4052 /// Get the FENV_ACCESS status of this operator. Only meaningful for
4053 /// operations on floating point types.
4054 bool isFEnvAccessOn(const LangOptions &LO) const {
4055 return getFPFeaturesInEffect(LO).getAllowFEnvAccess();
4056 }
4057
4058protected:
4059 BinaryOperator(const ASTContext &Ctx, Expr *lhs, Expr *rhs, Opcode opc,
4061 SourceLocation opLoc, FPOptionsOverride FPFeatures,
4062 bool dead2);
4063
4064 /// Construct an empty BinaryOperator, SC is CompoundAssignOperator.
4065 BinaryOperator(StmtClass SC, EmptyShell Empty) : Expr(SC, Empty) {
4066 BinaryOperatorBits.Opc = BO_MulAssign;
4067 }
4068
4069 /// Return the size in bytes needed for the trailing objects.
4070 /// Used to allocate the right amount of storage.
4071 static unsigned sizeOfTrailingObjects(bool HasFPFeatures) {
4072 return HasFPFeatures * sizeof(FPOptionsOverride);
4073 }
4074};
4075
4076/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep
4077/// track of the type the operation is performed in. Due to the semantics of
4078/// these operators, the operands are promoted, the arithmetic performed, an
4079/// implicit conversion back to the result type done, then the assignment takes
4080/// place. This captures the intermediate type which the computation is done
4081/// in.
4083 QualType ComputationLHSType;
4084 QualType ComputationResultType;
4085
4086 /// Construct an empty CompoundAssignOperator.
4087 explicit CompoundAssignOperator(const ASTContext &C, EmptyShell Empty,
4088 bool hasFPFeatures)
4089 : BinaryOperator(CompoundAssignOperatorClass, Empty) {}
4090
4091protected:
4093 QualType ResType, ExprValueKind VK, ExprObjectKind OK,
4094 SourceLocation OpLoc, FPOptionsOverride FPFeatures,
4095 QualType CompLHSType, QualType CompResultType)
4096 : BinaryOperator(C, lhs, rhs, opc, ResType, VK, OK, OpLoc, FPFeatures,
4097 true),
4098 ComputationLHSType(CompLHSType), ComputationResultType(CompResultType) {
4099 assert(isCompoundAssignmentOp() &&
4100 "Only should be used for compound assignments");
4101 }
4102
4103public:
4105 bool hasFPFeatures);
4106
4107 static CompoundAssignOperator *
4108 Create(const ASTContext &C, Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
4110 FPOptionsOverride FPFeatures, QualType CompLHSType = QualType(),
4111 QualType CompResultType = QualType());
4112
4113 // The two computation types are the type the LHS is converted
4114 // to for the computation and the type of the result; the two are
4115 // distinct in a few cases (specifically, int+=ptr and ptr-=ptr).
4116 QualType getComputationLHSType() const { return ComputationLHSType; }
4117 void setComputationLHSType(QualType T) { ComputationLHSType = T; }
4118
4119 QualType getComputationResultType() const { return ComputationResultType; }
4120 void setComputationResultType(QualType T) { ComputationResultType = T; }
4121
4122 static bool classof(const Stmt *S) {
4123 return S->getStmtClass() == CompoundAssignOperatorClass;
4124 }
4125};
4126
4128 assert(BinaryOperatorBits.HasFPFeatures);
4129 return isa<CompoundAssignOperator>(this) ? sizeof(CompoundAssignOperator)
4130 : sizeof(BinaryOperator);
4131}
4132
4133/// AbstractConditionalOperator - An abstract base class for
4134/// ConditionalOperator and BinaryConditionalOperator.
4136 SourceLocation QuestionLoc, ColonLoc;
4137 friend class ASTStmtReader;
4138
4139protected:
4142 SourceLocation cloc)
4143 : Expr(SC, T, VK, OK), QuestionLoc(qloc), ColonLoc(cloc) {}
4144
4146 : Expr(SC, Empty) { }
4147
4148public:
4149 /// getCond - Return the expression representing the condition for
4150 /// the ?: operator.
4151 Expr *getCond() const;
4152
4153 /// getTrueExpr - Return the subexpression representing the value of
4154 /// the expression if the condition evaluates to true.
4155 Expr *getTrueExpr() const;
4156
4157 /// getFalseExpr - Return the subexpression representing the value of
4158 /// the expression if the condition evaluates to false. This is
4159 /// the same as getRHS.
4160 Expr *getFalseExpr() const;
4161
4162 SourceLocation getQuestionLoc() const { return QuestionLoc; }
4163 SourceLocation getColonLoc() const { return ColonLoc; }
4164
4165 static bool classof(const Stmt *T) {
4166 return T->getStmtClass() == ConditionalOperatorClass ||
4167 T->getStmtClass() == BinaryConditionalOperatorClass;
4168 }
4169};
4170
4171/// ConditionalOperator - The ?: ternary operator. The GNU "missing
4172/// middle" extension is a BinaryConditionalOperator.
4174 enum { COND, LHS, RHS, END_EXPR };
4175 Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
4176
4177 friend class ASTStmtReader;
4178public:
4180 SourceLocation CLoc, Expr *rhs, QualType t,
4182 : AbstractConditionalOperator(ConditionalOperatorClass, t, VK, OK, QLoc,
4183 CLoc) {
4184 SubExprs[COND] = cond;
4185 SubExprs[LHS] = lhs;
4186 SubExprs[RHS] = rhs;
4188 }
4189
4190 /// Build an empty conditional operator.
4192 : AbstractConditionalOperator(ConditionalOperatorClass, Empty) { }
4193
4194 /// getCond - Return the expression representing the condition for
4195 /// the ?: operator.
4196 Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
4197
4198 /// getTrueExpr - Return the subexpression representing the value of
4199 /// the expression if the condition evaluates to true.
4200 Expr *getTrueExpr() const { return cast<Expr>(SubExprs[LHS]); }
4201
4202 /// getFalseExpr - Return the subexpression representing the value of
4203 /// the expression if the condition evaluates to false. This is
4204 /// the same as getRHS.
4205 Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); }
4206
4207 Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
4208 Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
4209
4210 SourceLocation getBeginLoc() const LLVM_READONLY {
4211 return getCond()->getBeginLoc();
4212 }
4213 SourceLocation getEndLoc() const LLVM_READONLY {
4214 return getRHS()->getEndLoc();
4215 }
4216
4217 static bool classof(const Stmt *T) {
4218 return T->getStmtClass() == ConditionalOperatorClass;
4219 }
4220
4221 // Iterators
4223 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
4224 }
4226 return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
4227 }
4228};
4229
4230/// BinaryConditionalOperator - The GNU extension to the conditional
4231/// operator which allows the middle operand to be omitted.
4232///
4233/// This is a different expression kind on the assumption that almost
4234/// every client ends up needing to know that these are different.
4236 enum { COMMON, COND, LHS, RHS, NUM_SUBEXPRS };
4237
4238 /// - the common condition/left-hand-side expression, which will be
4239 /// evaluated as the opaque value
4240 /// - the condition, expressed in terms of the opaque value
4241 /// - the left-hand-side, expressed in terms of the opaque value
4242 /// - the right-hand-side
4243 Stmt *SubExprs[NUM_SUBEXPRS];
4244 OpaqueValueExpr *OpaqueValue;
4245
4246 friend class ASTStmtReader;
4247public:
4249 Expr *cond, Expr *lhs, Expr *rhs,
4250 SourceLocation qloc, SourceLocation cloc,
4252 : AbstractConditionalOperator(BinaryConditionalOperatorClass, t, VK, OK,
4253 qloc, cloc),
4254 OpaqueValue(opaqueValue) {
4255 SubExprs[COMMON] = common;
4256 SubExprs[COND] = cond;
4257 SubExprs[LHS] = lhs;
4258 SubExprs[RHS] = rhs;
4259 assert(OpaqueValue->getSourceExpr() == common && "Wrong opaque value");
4261 }
4262
4263 /// Build an empty conditional operator.
4265 : AbstractConditionalOperator(BinaryConditionalOperatorClass, Empty) { }
4266
4267 /// getCommon - Return the common expression, written to the
4268 /// left of the condition. The opaque value will be bound to the
4269 /// result of this expression.
4270 Expr *getCommon() const { return cast<Expr>(SubExprs[COMMON]); }
4271
4272 /// getOpaqueValue - Return the opaque value placeholder.
4273 OpaqueValueExpr *getOpaqueValue() const { return OpaqueValue; }
4274
4275 /// getCond - Return the condition expression; this is defined
4276 /// in terms of the opaque value.
4277 Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
4278
4279 /// getTrueExpr - Return the subexpression which will be
4280 /// evaluated if the condition evaluates to true; this is defined
4281 /// in terms of the opaque value.
4283 return cast<Expr>(SubExprs[LHS]);
4284 }
4285
4286 /// getFalseExpr - Return the subexpression which will be
4287 /// evaluated if the condnition evaluates to false; this is
4288 /// defined in terms of the opaque value.
4290 return cast<Expr>(SubExprs[RHS]);
4291 }
4292
4293 SourceLocation getBeginLoc() const LLVM_READONLY {
4294 return getCommon()->getBeginLoc();
4295 }
4296 SourceLocation getEndLoc() const LLVM_READONLY {
4297 return getFalseExpr()->getEndLoc();
4298 }
4299
4300 static bool classof(const Stmt *T) {
4301 return T->getStmtClass() == BinaryConditionalOperatorClass;
4302 }
4303
4304 // Iterators
4306 return child_range(SubExprs, SubExprs + NUM_SUBEXPRS);
4307 }
4309 return const_child_range(SubExprs, SubExprs + NUM_SUBEXPRS);
4310 }
4311};
4312
4314 if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this))
4315 return co->getCond();
4316 return cast<BinaryConditionalOperator>(this)->getCond();
4317}
4318
4320 if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this))
4321 return co->getTrueExpr();
4322 return cast<BinaryConditionalOperator>(this)->getTrueExpr();
4323}
4324
4326 if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this))
4327 return co->getFalseExpr();
4328 return cast<BinaryConditionalOperator>(this)->getFalseExpr();
4329}
4330
4331/// AddrLabelExpr - The GNU address of label extension, representing &&label.
4332class AddrLabelExpr : public Expr {
4333 SourceLocation AmpAmpLoc, LabelLoc;
4334 LabelDecl *Label;
4335public:
4337 QualType t)
4338 : Expr(AddrLabelExprClass, t, VK_PRValue, OK_Ordinary), AmpAmpLoc(AALoc),
4339 LabelLoc(LLoc), Label(L) {
4340 setDependence(ExprDependence::None);
4341 }
4342
4343 /// Build an empty address of a label expression.
4345 : Expr(AddrLabelExprClass, Empty) { }
4346
4347 SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; }
4348 void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; }
4349 SourceLocation getLabelLoc() const { return LabelLoc; }
4350 void setLabelLoc(SourceLocation L) { LabelLoc = L; }
4351
4352 SourceLocation getBeginLoc() const LLVM_READONLY { return AmpAmpLoc; }
4353 SourceLocation getEndLoc() const LLVM_READONLY { return LabelLoc; }
4354
4355 LabelDecl *getLabel() const { return Label; }
4356 void setLabel(LabelDecl *L) { Label = L; }
4357
4358 static bool classof(const Stmt *T) {
4359 return T->getStmtClass() == AddrLabelExprClass;
4360 }
4361
4362 // Iterators
4365 }
4368 }
4369};
4370
4371/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
4372/// The StmtExpr contains a single CompoundStmt node, which it evaluates and
4373/// takes the value of the last subexpression.
4374///
4375/// A StmtExpr is always an r-value; values "returned" out of a
4376/// StmtExpr will be copied.
4377class StmtExpr : public Expr {
4378 Stmt *SubStmt;
4379 SourceLocation LParenLoc, RParenLoc;
4380public:
4382 SourceLocation RParenLoc, unsigned TemplateDepth)
4383 : Expr(StmtExprClass, T, VK_PRValue, OK_Ordinary), SubStmt(SubStmt),
4384 LParenLoc(LParenLoc), RParenLoc(RParenLoc) {
4385 setDependence(computeDependence(this, TemplateDepth));
4386 // FIXME: A templated statement expression should have an associated
4387 // DeclContext so that nested declarations always have a dependent context.
4388 StmtExprBits.TemplateDepth = TemplateDepth;
4389 }
4390
4391 /// Build an empty statement expression.
4392 explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { }
4393
4394 CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); }
4395 const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); }
4396 void setSubStmt(CompoundStmt *S) { SubStmt = S; }
4397
4398 SourceLocation getBeginLoc() const LLVM_READONLY { return LParenLoc; }
4399 SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
4400
4401 SourceLocation getLParenLoc() const { return LParenLoc; }
4402 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
4403 SourceLocation getRParenLoc() const { return RParenLoc; }
4404 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
4405
4406 unsigned getTemplateDepth() const { return StmtExprBits.TemplateDepth; }
4407
4408 static bool classof(const Stmt *T) {
4409 return T->getStmtClass() == StmtExprClass;
4410 }
4411
4412 // Iterators
4413 child_range children() { return child_range(&SubStmt, &SubStmt+1); }
4415 return const_child_range(&SubStmt, &SubStmt + 1);
4416 }
4417};
4418
4419/// ShuffleVectorExpr - clang-specific builtin-in function
4420/// __builtin_shufflevector.
4421/// This AST node represents a operator that does a constant
4422/// shuffle, similar to LLVM's shufflevector instruction. It takes
4423/// two vectors and a variable number of constant indices,
4424/// and returns the appropriately shuffled vector.
4425class ShuffleVectorExpr : public Expr {
4426 SourceLocation BuiltinLoc, RParenLoc;
4427
4428 // SubExprs - the list of values passed to the __builtin_shufflevector
4429 // function. The first two are vectors, and the rest are constant
4430 // indices. The number of values in this list is always
4431 // 2+the number of indices in the vector type.
4432 Stmt **SubExprs;
4433 unsigned NumExprs;
4434
4435public:
4438
4439 /// Build an empty vector-shuffle expression.
4441 : Expr(ShuffleVectorExprClass, Empty), SubExprs(nullptr) { }
4442
4443 SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
4444 void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
4445
4446 SourceLocation getRParenLoc() const { return RParenLoc; }
4447 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
4448
4449 SourceLocation getBeginLoc() const LLVM_READONLY { return BuiltinLoc; }
4450 SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
4451
4452 static bool classof(const Stmt *T) {
4453 return T->getStmtClass() == ShuffleVectorExprClass;
4454 }
4455
4456 /// getNumSubExprs - Return the size of the SubExprs array. This includes the
4457 /// constant expression, the actual arguments passed in, and the function
4458 /// pointers.
4459 unsigned getNumSubExprs() const { return NumExprs; }
4460
4461 /// Retrieve the array of expressions.
4462 Expr **getSubExprs() { return reinterpret_cast<Expr **>(SubExprs); }
4463
4464 /// getExpr - Return the Expr at the specified index.
4465 Expr *getExpr(unsigned Index) {
4466 assert((Index < NumExprs) && "Arg access out of range!");
4467 return cast<Expr>(SubExprs[Index]);
4468 }
4469 const Expr *getExpr(unsigned Index) const {
4470 assert((Index < NumExprs) && "Arg access out of range!");
4471 return cast<Expr>(SubExprs[Index]);
4472 }
4473
4474 void setExprs(const ASTContext &C, ArrayRef<Expr *> Exprs);
4475
4476 llvm::APSInt getShuffleMaskIdx(const ASTContext &Ctx, unsigned N) const {
4477 assert((N < NumExprs - 2) && "Shuffle idx out of range!");
4478 return getExpr(N+2)->EvaluateKnownConstInt(Ctx);
4479 }
4480
4481 // Iterators
4483 return child_range(&SubExprs[0], &SubExprs[0]+NumExprs);
4484 }
4486 return const_child_range(&SubExprs[0], &SubExprs[0] + NumExprs);
4487 }
4488};
4489
4490/// ConvertVectorExpr - Clang builtin function __builtin_convertvector
4491/// This AST node provides support for converting a vector type to another
4492/// vector type of the same arity.
4493class ConvertVectorExpr : public Expr {
4494private:
4495 Stmt *SrcExpr;
4496 TypeSourceInfo *TInfo;
4497 SourceLocation BuiltinLoc, RParenLoc;
4498
4499 friend class ASTReader;
4500 friend class ASTStmtReader;
4501 explicit ConvertVectorExpr(EmptyShell Empty) : Expr(ConvertVectorExprClass, Empty) {}
4502
4503public:
4506 SourceLocation BuiltinLoc, SourceLocation RParenLoc)
4507 : Expr(ConvertVectorExprClass, DstType, VK, OK), SrcExpr(SrcExpr),
4508 TInfo(TI), BuiltinLoc(BuiltinLoc), RParenLoc(RParenLoc) {
4510 }
4511
4512 /// getSrcExpr - Return the Expr to be converted.
4513 Expr *getSrcExpr() const { return cast<Expr>(SrcExpr); }
4514
4515 /// getTypeSourceInfo - Return the destination type.
4517 return TInfo;
4518 }
4520 TInfo = ti;
4521 }
4522
4523 /// getBuiltinLoc - Return the location of the __builtin_convertvector token.
4524 SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
4525
4526 /// getRParenLoc - Return the location of final right parenthesis.
4527 SourceLocation getRParenLoc() const { return RParenLoc; }
4528
4529 SourceLocation getBeginLoc() const LLVM_READONLY { return BuiltinLoc; }
4530 SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
4531
4532 static bool classof(const Stmt *T) {
4533 return T->getStmtClass() == ConvertVectorExprClass;
4534 }
4535
4536 // Iterators
4537 child_range children() { return child_range(&SrcExpr, &SrcExpr+1); }
4539 return const_child_range(&SrcExpr, &SrcExpr + 1);
4540 }
4541};
4542
4543/// ChooseExpr - GNU builtin-in function __builtin_choose_expr.
4544/// This AST node is similar to the conditional operator (?:) in C, with
4545/// the following exceptions:
4546/// - the test expression must be a integer constant expression.
4547/// - the expression returned acts like the chosen subexpression in every
4548/// visible way: the type is the same as that of the chosen subexpression,
4549/// and all predicates (whether it's an l-value, whether it's an integer
4550/// constant expression, etc.) return the same result as for the chosen
4551/// sub-expression.
4552class ChooseExpr : public Expr {
4553 enum { COND, LHS, RHS, END_EXPR };
4554 Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
4555 SourceLocation BuiltinLoc, RParenLoc;
4556 bool CondIsTrue;
4557public:
4558 ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, QualType t,
4560 bool condIsTrue)
4561 : Expr(ChooseExprClass, t, VK, OK), BuiltinLoc(BLoc), RParenLoc(RP),
4562 CondIsTrue(condIsTrue) {
4563 SubExprs[COND] = cond;
4564 SubExprs[LHS] = lhs;
4565 SubExprs[RHS] = rhs;
4566
4568 }
4569
4570 /// Build an empty __builtin_choose_expr.
4571 explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { }
4572
4573 /// isConditionTrue - Return whether the condition is true (i.e. not
4574 /// equal to zero).
4575 bool isConditionTrue() const {
4576 assert(!isConditionDependent() &&
4577 "Dependent condition isn't true or false");
4578 return CondIsTrue;
4579 }
4580 void setIsConditionTrue(bool isTrue) { CondIsTrue = isTrue; }
4581
4583 return getCond()->isTypeDependent() || getCond()->isValueDependent();
4584 }
4585
4586 /// getChosenSubExpr - Return the subexpression chosen according to the
4587 /// condition.
4589 return isConditionTrue() ? getLHS() : getRHS();
4590 }
4591
4592 Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
4593 void setCond(Expr *E) { SubExprs[COND] = E; }
4594 Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
4595 void setLHS(Expr *E) { SubExprs[LHS] = E; }
4596 Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
4597 void setRHS(Expr *E) { SubExprs[RHS] = E; }
4598
4599 SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
4600 void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
4601
4602 SourceLocation getRParenLoc() const { return RParenLoc; }
4603 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
4604
4605 SourceLocation getBeginLoc() const LLVM_READONLY { return BuiltinLoc; }
4606 SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
4607
4608 static bool classof(const Stmt *T) {
4609 return T->getStmtClass() == ChooseExprClass;
4610 }
4611
4612 // Iterators
4614 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
4615 }
4617 return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
4618 }
4619};
4620
4621/// GNUNullExpr - Implements the GNU __null extension, which is a name
4622/// for a null pointer constant that has integral type (e.g., int or
4623/// long) and is the same size and alignment as a pointer. The __null
4624/// extension is typically only used by system headers, which define
4625/// NULL as __null in C++ rather than using 0 (which is an integer
4626/// that may not match the size of a pointer).
4627class GNUNullExpr : public Expr {
4628 /// TokenLoc - The location of the __null keyword.
4629 SourceLocation TokenLoc;
4630
4631public:
4633 : Expr(GNUNullExprClass, Ty, VK_PRValue, OK_Ordinary), TokenLoc(Loc) {
4634 setDependence(ExprDependence::None);
4635 }
4636
4637 /// Build an empty GNU __null expression.
4638 explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { }
4639
4640 /// getTokenLocation - The location of the __null token.
4641 SourceLocation getTokenLocation() const { return TokenLoc; }
4642 void setTokenLocation(SourceLocation L) { TokenLoc = L; }
4643
4644 SourceLocation getBeginLoc() const LLVM_READONLY { return TokenLoc; }
4645 SourceLocation getEndLoc() const LLVM_READONLY { return TokenLoc; }
4646
4647 static bool classof(const Stmt *T) {
4648 return T->getStmtClass() == GNUNullExprClass;
4649 }
4650
4651 // Iterators
4654 }
4657 }
4658};
4659
4660/// Represents a call to the builtin function \c __builtin_va_arg.
4661class VAArgExpr : public Expr {
4662 Stmt *Val;
4663 llvm::PointerIntPair<TypeSourceInfo *, 1, bool> TInfo;
4664 SourceLocation BuiltinLoc, RParenLoc;
4665public:
4667 SourceLocation RPLoc, QualType t, bool IsMS)
4668 : Expr(VAArgExprClass, t, VK_PRValue, OK_Ordinary), Val(e),
4669 TInfo(TInfo, IsMS), BuiltinLoc(BLoc), RParenLoc(RPLoc) {
4671 }
4672
4673 /// Create an empty __builtin_va_arg expression.
4674 explicit VAArgExpr(EmptyShell Empty)
4675 : Expr(VAArgExprClass, Empty), Val(nullptr), TInfo(nullptr, false) {}
4676
4677 const Expr *getSubExpr() const { return cast<Expr>(Val); }
4678 Expr *getSubExpr() { return cast<Expr>(Val); }
4679 void setSubExpr(Expr *E) { Val = E; }
4680
4681 /// Returns whether this is really a Win64 ABI va_arg expression.
4682 bool isMicrosoftABI() const { return TInfo.getInt(); }
4683 void setIsMicrosoftABI(bool IsMS) { TInfo.setInt(IsMS); }
4684
4685 TypeSourceInfo *getWrittenTypeInfo() const { return TInfo.getPointer(); }
4686 void setWrittenTypeInfo(TypeSourceInfo *TI) { TInfo.setPointer(TI); }
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() == VAArgExprClass;
4699 }
4700
4701 // Iterators
4702 child_range children() { return child_range(&Val, &Val+1); }
4704 return const_child_range(&Val, &Val + 1);
4705 }
4706};
4707
4709 Function,
4710 FuncSig,
4711 File,
4712 FileName,
4713 Line,
4714 Column,
4716};
4717
4718/// Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(),
4719/// __builtin_FUNCTION(), __builtin_FUNCSIG(), __builtin_FILE(),
4720/// __builtin_FILE_NAME() or __builtin_source_location().
4721class SourceLocExpr final : public Expr {
4722 SourceLocation BuiltinLoc, RParenLoc;
4723 DeclContext *ParentContext;
4724
4725public:
4727 QualType ResultTy, SourceLocation BLoc,
4728 SourceLocation RParenLoc, DeclContext *Context);
4729
4730 /// Build an empty call expression.
4731 explicit SourceLocExpr(EmptyShell Empty) : Expr(SourceLocExprClass, Empty) {}
4732
4733 /// Return the result of evaluating this SourceLocExpr in the specified
4734 /// (and possibly null) default argument or initialization context.
4736 const Expr *DefaultExpr) const;
4737
4738 /// Return a string representing the name of the specific builtin function.
4739 StringRef getBuiltinStr() const;
4740
4742 return static_cast<SourceLocIdentKind>(SourceLocExprBits.Kind);
4743 }
4744
4745 bool isIntType() const {
4746 switch (getIdentKind()) {
4752 return false;
4755 return true;
4756 }
4757 llvm_unreachable("unknown source location expression kind");
4758 }
4759
4760 /// If the SourceLocExpr has been resolved return the subexpression
4761 /// representing the resolved value. Otherwise return null.
4762 const DeclContext *getParentContext() const { return ParentContext; }
4763 DeclContext *getParentContext() { return ParentContext; }
4764
4765 SourceLocation getLocation() const { return BuiltinLoc; }
4766 SourceLocation getBeginLoc() const { return BuiltinLoc; }
4767 SourceLocation getEndLoc() const { return RParenLoc; }
4768
4771 }
4772
4775 }
4776
4777 static bool classof(const Stmt *T) {
4778 return T->getStmtClass() == SourceLocExprClass;
4779 }
4780
4782 switch (Kind) {
4786 return true;
4787 default:
4788 return false;
4789 }
4790 }
4791
4792private:
4793 friend class ASTStmtReader;
4794};
4795
4796/// Describes an C or C++ initializer list.
4797///
4798/// InitListExpr describes an initializer list, which can be used to
4799/// initialize objects of different types, including
4800/// struct/class/union types, arrays, and vectors. For example:
4801///
4802/// @code
4803/// struct foo x = { 1, { 2, 3 } };
4804/// @endcode
4805///
4806/// Prior to semantic analysis, an initializer list will represent the
4807/// initializer list as written by the user, but will have the
4808/// placeholder type "void". This initializer list is called the
4809/// syntactic form of the initializer, and may contain C99 designated
4810/// initializers (represented as DesignatedInitExprs), initializations
4811/// of subobject members without explicit braces, and so on. Clients
4812/// interested in the original syntax of the initializer list should
4813/// use the syntactic form of the initializer list.
4814///
4815/// After semantic analysis, the initializer list will represent the
4816/// semantic form of the initializer, where the initializations of all
4817/// subobjects are made explicit with nested InitListExpr nodes and
4818/// C99 designators have been eliminated by placing the designated
4819/// initializations into the subobject they initialize. Additionally,
4820/// any "holes" in the initialization, where no initializer has been
4821/// specified for a particular subobject, will be replaced with
4822/// implicitly-generated ImplicitValueInitExpr expressions that
4823/// value-initialize the subobjects. Note, however, that the
4824/// initializer lists may still have fewer initializers than there are
4825/// elements to initialize within the object.
4826///
4827/// After semantic analysis has completed, given an initializer list,
4828/// method isSemanticForm() returns true if and only if this is the
4829/// semantic form of the initializer list (note: the same AST node
4830/// may at the same time be the syntactic form).
4831/// Given the semantic form of the initializer list, one can retrieve
4832/// the syntactic form of that initializer list (when different)
4833/// using method getSyntacticForm(); the method returns null if applied
4834/// to a initializer list which is already in syntactic form.
4835/// Similarly, given the syntactic form (i.e., an initializer list such
4836/// that isSemanticForm() returns false), one can retrieve the semantic
4837/// form using method getSemanticForm().
4838/// Since many initializer lists have the same syntactic and semantic forms,
4839/// getSyntacticForm() may return NULL, indicating that the current
4840/// semantic initializer list also serves as its syntactic form.
4841class InitListExpr : public Expr {
4842 // FIXME: Eliminate this vector in favor of ASTContext allocation
4844 InitExprsTy InitExprs;
4845 SourceLocation LBraceLoc, RBraceLoc;
4846
4847 /// The alternative form of the initializer list (if it exists).
4848 /// The int part of the pair stores whether this initializer list is
4849 /// in semantic form. If not null, the pointer points to:
4850 /// - the syntactic form, if this is in semantic form;
4851 /// - the semantic form, if this is in syntactic form.
4852 llvm::PointerIntPair<InitListExpr *, 1, bool> AltForm;
4853
4854 /// Either:
4855 /// If this initializer list initializes an array with more elements than
4856 /// there are initializers in the list, specifies an expression to be used
4857 /// for value initialization of the rest of the elements.
4858 /// Or
4859 /// If this initializer list initializes a union, specifies which
4860 /// field within the union will be initialized.
4861 llvm::PointerUnion<Expr *, FieldDecl *> ArrayFillerOrUnionFieldInit;
4862
4863public:
4864 InitListExpr(const ASTContext &C, SourceLocation lbraceloc,
4865 ArrayRef<Expr*> initExprs, SourceLocation rbraceloc);
4866
4867 /// Build an empty initializer list.
4868 explicit InitListExpr(EmptyShell Empty)
4869 : Expr(InitListExprClass, Empty), AltForm(nullptr, true) { }
4870
4871 unsigned getNumInits() const { return InitExprs.size(); }
4872
4873 /// Retrieve the set of initializers.
4874 Expr **getInits() { return reinterpret_cast<Expr **>(InitExprs.data()); }
4875
4876 /// Retrieve the set of initializers.
4877 Expr * const *getInits() const {
4878 return reinterpret_cast<Expr * const *>(InitExprs.data());
4879 }
4880
4882
4884 return llvm::ArrayRef(getInits(), getNumInits());
4885 }
4886
4887 const Expr *getInit(unsigned Init) const {
4888 assert(Init < getNumInits() && "Initializer access out of range!");
4889 return cast_or_null<Expr>(InitExprs[Init]);
4890 }
4891
4892 Expr *getInit(unsigned Init) {
4893 assert(Init < getNumInits() && "Initializer access out of range!");
4894 return cast_or_null<Expr>(InitExprs[Init]);
4895 }
4896
4897 void setInit(unsigned Init, Expr *expr) {
4898 assert(Init < getNumInits() && "Initializer access out of range!");
4899 InitExprs[Init] = expr;
4900
4901 if (expr)
4902 setDependence(getDependence() | expr->getDependence());
4903 }
4904
4905 /// Mark the semantic form of the InitListExpr as error when the semantic
4906 /// analysis fails.
4907 void markError() {
4908 assert(isSemanticForm());
4909 setDependence(getDependence() | ExprDependence::ErrorDependent);
4910 }
4911
4912 /// Reserve space for some number of initializers.
4913 void reserveInits(const ASTContext &C, unsigned NumInits);
4914
4915 /// Specify the number of initializers
4916 ///
4917 /// If there are more than @p NumInits initializers, the remaining
4918 /// initializers will be destroyed. If there are fewer than @p
4919 /// NumInits initializers, NULL expressions will be added for the
4920 /// unknown initializers.
4921 void resizeInits(const ASTContext &Context, unsigned NumInits);
4922
4923 /// Updates the initializer at index @p Init with the new
4924 /// expression @p expr, and returns the old expression at that
4925 /// location.
4926 ///
4927 /// When @p Init is out of range for this initializer list, the
4928 /// initializer list will be extended with NULL expressions to
4929 /// accommodate the new entry.
4930 Expr *updateInit(const ASTContext &C, unsigned Init, Expr *expr);
4931
4932 /// If this initializer list initializes an array with more elements
4933 /// than there are initializers in the list, specifies an expression to be
4934 /// used for value initialization of the rest of the elements.
4936 return ArrayFillerOrUnionFieldInit.dyn_cast<Expr *>();
4937 }
4938 const Expr *getArrayFiller() const {
4939 return const_cast<InitListExpr *>(this)->getArrayFiller();
4940 }
4941 void setArrayFiller(Expr *filler);
4942
4943 /// Return true if this is an array initializer and its array "filler"
4944 /// has been set.
4945 bool hasArrayFiller() const { return getArrayFiller(); }
4946
4947 /// Determine whether this initializer list contains a designated initializer.
4948 bool hasDesignatedInit() const {
4949 return std::any_of(begin(), end(), [](const Stmt *S) {
4950 return isa<DesignatedInitExpr>(S);
4951 });
4952 }
4953
4954 /// If this initializes a union, specifies which field in the
4955 /// union to initialize.
4956 ///
4957 /// Typically, this field is the first named field within the
4958 /// union. However, a designated initializer can specify the
4959 /// initialization of a different field within the union.
4961 return ArrayFillerOrUnionFieldInit.dyn_cast<FieldDecl *>();
4962 }
4964 return const_cast<InitListExpr *>(this)->getInitializedFieldInUnion();
4965 }
4967 assert((FD == nullptr
4968 || getInitializedFieldInUnion() == nullptr
4969 || getInitializedFieldInUnion() == FD)
4970 && "Only one field of a union may be initialized at a time!");
4971 ArrayFillerOrUnionFieldInit = FD;
4972 }
4973
4974 // Explicit InitListExpr's originate from source code (and have valid source
4975 // locations). Implicit InitListExpr's are created by the semantic analyzer.
4976 // FIXME: This is wrong; InitListExprs created by semantic analysis have
4977 // valid source locations too!
4978 bool isExplicit() const {
4979 return LBraceLoc.isValid() && RBraceLoc.isValid();
4980 }
4981
4982 /// Is this an initializer for an array of characters, initialized by a string
4983 /// literal or an @encode?
4984 bool isStringLiteralInit() const;
4985
4986 /// Is this a transparent initializer list (that is, an InitListExpr that is
4987 /// purely syntactic, and whose semantics are that of the sole contained
4988 /// initializer)?
4989 bool isTransparent() const;
4990
4991 /// Is this the zero initializer {0} in a language which considers it
4992 /// idiomatic?
4993 bool isIdiomaticZeroInitializer(const LangOptions &LangOpts) const;
4994
4995 SourceLocation getLBraceLoc() const { return LBraceLoc; }
4996 void setLBraceLoc(SourceLocation Loc) { LBraceLoc = Loc; }
4997 SourceLocation getRBraceLoc() const { return RBraceLoc; }
4998 void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; }
4999
5000 bool isSemanticForm() const { return AltForm.getInt(); }
5002 return isSemanticForm() ? nullptr : AltForm.getPointer();
5003 }
5004 bool isSyntacticForm() const {
5005 return !AltForm.getInt() || !AltForm.getPointer();
5006 }
5008 return isSemanticForm() ? AltForm.getPointer() : nullptr;
5009 }
5010
5012 AltForm.setPointer(Init);
5013 AltForm.setInt(true);
5014 Init->AltForm.setPointer(this);
5015 Init->AltForm.setInt(false);
5016 }
5017
5019 return InitListExprBits.HadArrayRangeDesignator != 0;
5020 }
5021 void sawArrayRangeDesignator(bool ARD = true) {
5022 InitListExprBits.HadArrayRangeDesignator = ARD;
5023 }
5024
5025 SourceLocation getBeginLoc() const LLVM_READONLY;
5026 SourceLocation getEndLoc() const LLVM_READONLY;
5027
5028 static bool classof(const Stmt *T) {
5029 return T->getStmtClass() == InitListExprClass;
5030 }
5031
5032 // Iterators
5034 const_child_range CCR = const_cast<const InitListExpr *>(this)->children();
5035 return child_range(cast_away_const(CCR.begin()),
5036 cast_away_const(CCR.end()));
5037 }
5038
5040 // FIXME: This does not include the array filler expression.
5041 if (InitExprs.empty())
5043 return const_child_range(&InitExprs[0], &InitExprs[0] + InitExprs.size());
5044 }
5045
5050
5051 iterator begin() { return InitExprs.begin(); }
5052 const_iterator begin() const { return InitExprs.begin(); }
5053 iterator end() { return InitExprs.end(); }
5054 const_iterator end() const { return InitExprs.end(); }
5055 reverse_iterator rbegin() { return InitExprs.rbegin(); }
5056 const_reverse_iterator rbegin() const { return InitExprs.rbegin(); }
5057 reverse_iterator rend() { return InitExprs.rend(); }
5058 const_reverse_iterator rend() const { return InitExprs.rend(); }
5059
5060 friend class ASTStmtReader;
5061 friend class ASTStmtWriter;
5062};
5063
5064/// Represents a C99 designated initializer expression.
5065///
5066/// A designated initializer expression (C99 6.7.8) contains one or
5067/// more designators (which can be field designators, array
5068/// designators, or GNU array-range designators) followed by an
5069/// expression that initializes the field or element(s) that the
5070/// designators refer to. For example, given:
5071///
5072/// @code
5073/// struct point {
5074/// double x;
5075/// double y;
5076/// };
5077/// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 };
5078/// @endcode
5079///
5080/// The InitListExpr contains three DesignatedInitExprs, the first of
5081/// which covers @c [2].y=1.0. This DesignatedInitExpr will have two
5082/// designators, one array designator for @c [2] followed by one field
5083/// designator for @c .y. The initialization expression will be 1.0.
5085 : public Expr,
5086 private llvm::TrailingObjects<DesignatedInitExpr, Stmt *> {
5087public:
5088 /// Forward declaration of the Designator class.
5089 class Designator;
5090
5091private:
5092 /// The location of the '=' or ':' prior to the actual initializer
5093 /// expression.
5094 SourceLocation EqualOrColonLoc;
5095
5096 /// Whether this designated initializer used the GNU deprecated
5097 /// syntax rather than the C99 '=' syntax.
5098 LLVM_PREFERRED_TYPE(bool)
5099 unsigned GNUSyntax : 1;
5100
5101 /// The number of designators in this initializer expression.
5102 unsigned NumDesignators : 15;
5103
5104 /// The number of subexpressions of this initializer expression,
5105 /// which contains both the initializer and any additional
5106 /// expressions used by array and array-range designators.
5107 unsigned NumSubExprs : 16;
5108
5109 /// The designators in this designated initialization
5110 /// expression.
5111 Designator *Designators;
5112
5114 llvm::ArrayRef<Designator> Designators,
5115 SourceLocation EqualOrColonLoc, bool GNUSyntax,
5116 ArrayRef<Expr *> IndexExprs, Expr *Init);
5117
5118 explicit DesignatedInitExpr(unsigned NumSubExprs)
5119 : Expr(DesignatedInitExprClass, EmptyShell()),
5120 NumDesignators(0), NumSubExprs(NumSubExprs), Designators(nullptr) { }
5121
5122public:
5123 /// Represents a single C99 designator.
5124 ///
5125 /// @todo This class is infuriatingly similar to clang::Designator,
5126 /// but minor differences (storing indices vs. storing pointers)
5127 /// keep us from reusing it. Try harder, later, to rectify these
5128 /// differences.
5130 /// A field designator, e.g., ".x".
5131 struct FieldDesignatorInfo {
5132 /// Refers to the field that is being initialized. The low bit
5133 /// of this field determines whether this is actually a pointer
5134 /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When
5135 /// initially constructed, a field designator will store an
5136 /// IdentifierInfo*. After semantic analysis has resolved that
5137 /// name, the field designator will instead store a FieldDecl*.
5138 uintptr_t NameOrField;
5139
5140 /// The location of the '.' in the designated initializer.
5141 SourceLocation DotLoc;
5142
5143 /// The location of the field name in the designated initializer.
5144 SourceLocation FieldLoc;
5145
5146 FieldDesignatorInfo(const IdentifierInfo *II, SourceLocation DotLoc,
5147 SourceLocation FieldLoc)
5148 : NameOrField(reinterpret_cast<uintptr_t>(II) | 0x1), DotLoc(DotLoc),
5149 FieldLoc(FieldLoc) {}
5150 };
5151
5152 /// An array or GNU array-range designator, e.g., "[9]" or "[10...15]".
5153 struct ArrayOrRangeDesignatorInfo {
5154 /// Location of the first index expression within the designated
5155 /// initializer expression's list of subexpressions.
5156 unsigned Index;
5157
5158 /// The location of the '[' starting the array range designator.
5159 SourceLocation LBracketLoc;
5160
5161 /// The location of the ellipsis separating the start and end
5162 /// indices. Only valid for GNU array-range designators.
5163 SourceLocation EllipsisLoc;
5164
5165 /// The location of the ']' terminating the array range designator.
5166 SourceLocation RBracketLoc;
5167
5168 ArrayOrRangeDesignatorInfo(unsigned Index, SourceLocation LBracketLoc,
5169 SourceLocation RBracketLoc)
5170 : Index(Index), LBracketLoc(LBracketLoc), RBracketLoc(RBracketLoc) {}
5171
5172 ArrayOrRangeDesignatorInfo(unsigned Index,
5173 SourceLocation LBracketLoc,
5174 SourceLocation EllipsisLoc,
5175 SourceLocation RBracketLoc)
5176 : Index(Index), LBracketLoc(LBracketLoc), EllipsisLoc(EllipsisLoc),
5177 RBracketLoc(RBracketLoc) {}
5178 };
5179
5180 /// The kind of designator this describes.
5181 enum DesignatorKind {
5182 FieldDesignator,
5183 ArrayDesignator,
5184 ArrayRangeDesignator
5185 };
5186
5187 DesignatorKind Kind;
5188
5189 union {
5190 /// A field designator, e.g., ".x".
5191 struct FieldDesignatorInfo FieldInfo;
5192
5193 /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
5194 struct ArrayOrRangeDesignatorInfo ArrayOrRangeInfo;
5195 };
5196
5197 Designator(DesignatorKind Kind) : Kind(Kind) {}
5198
5199 public:
5201
5202 bool isFieldDesignator() const { return Kind == FieldDesignator; }
5203 bool isArrayDesignator() const { return Kind == ArrayDesignator; }
5204 bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; }
5205
5206 //===------------------------------------------------------------------===//
5207 // FieldDesignatorInfo
5208
5209 /// Creates a field designator.
5211 SourceLocation DotLoc,
5212 SourceLocation FieldLoc) {
5213 Designator D(FieldDesignator);
5214 new (&D.FieldInfo) FieldDesignatorInfo(FieldName, DotLoc, FieldLoc);
5215 return D;
5216 }
5217
5218 const IdentifierInfo *getFieldName() const;
5219
5221 assert(isFieldDesignator() && "Only valid on a field designator");
5222 if (FieldInfo.NameOrField & 0x01)
5223 return nullptr;
5224 return reinterpret_cast<FieldDecl *>(FieldInfo.NameOrField);
5225 }
5226
5228 assert(isFieldDesignator() && "Only valid on a field designator");
5229 FieldInfo.NameOrField = reinterpret_cast<uintptr_t>(FD);
5230 }
5231
5233 assert(isFieldDesignator() && "Only valid on a field designator");
5234 return FieldInfo.DotLoc;
5235 }
5236
5238 assert(isFieldDesignator() && "Only valid on a field designator");
5239 return FieldInfo.FieldLoc;
5240 }
5241
5242 //===------------------------------------------------------------------===//
5243 // ArrayOrRangeDesignator
5244
5245 /// Creates an array designator.
5246 static Designator CreateArrayDesignator(unsigned Index,
5247 SourceLocation LBracketLoc,
5248 SourceLocation RBracketLoc) {
5249 Designator D(ArrayDesignator);
5250 new (&D.ArrayOrRangeInfo) ArrayOrRangeDesignatorInfo(Index, LBracketLoc,
5251 RBracketLoc);
5252 return D;
5253 }
5254
5255 /// Creates a GNU array-range designator.
5257 SourceLocation LBracketLoc,
5258 SourceLocation EllipsisLoc,
5259 SourceLocation RBracketLoc) {
5260 Designator D(ArrayRangeDesignator);
5261 new (&D.ArrayOrRangeInfo) ArrayOrRangeDesignatorInfo(Index, LBracketLoc,
5262 EllipsisLoc,
5263 RBracketLoc);
5264 return D;
5265 }
5266
5267 unsigned getArrayIndex() const {
5268 assert((isArrayDesignator() || isArrayRangeDesignator()) &&
5269 "Only valid on an array or array-range designator");
5270 return ArrayOrRangeInfo.Index;
5271 }
5272
5274 assert((isArrayDesignator() || isArrayRangeDesignator()) &&
5275 "Only valid on an array or array-range designator");
5276 return ArrayOrRangeInfo.LBracketLoc;
5277 }
5278
5280 assert(isArrayRangeDesignator() &&
5281 "Only valid on an array-range designator");
5282 return ArrayOrRangeInfo.EllipsisLoc;
5283 }
5284
5286 assert((isArrayDesignator() || isArrayRangeDesignator()) &&
5287 "Only valid on an array or array-range designator");
5288 return ArrayOrRangeInfo.RBracketLoc;
5289 }
5290
5291 SourceLocation getBeginLoc() const LLVM_READONLY {
5292 if (isFieldDesignator())
5293 return getDotLoc().isInvalid() ? getFieldLoc() : getDotLoc();
5294 return getLBracketLoc();
5295 }
5296
5297 SourceLocation getEndLoc() const LLVM_READONLY {
5299 }
5300
5301 SourceRange getSourceRange() const LLVM_READONLY {
5302 return SourceRange(getBeginLoc(), getEndLoc());
5303 }
5304 };
5305
5306 static DesignatedInitExpr *Create(const ASTContext &C,
5307 llvm::ArrayRef<Designator> Designators,
5308 ArrayRef<Expr*> IndexExprs,
5309 SourceLocation EqualOrColonLoc,
5310 bool GNUSyntax, Expr *Init);
5311
5313 unsigned NumIndexExprs);
5314
5315 /// Returns the number of designators in this initializer.
5316 unsigned size() const { return NumDesignators; }
5317
5318 // Iterator access to the designators.
5320 return {Designators, NumDesignators};
5321 }
5322
5324 return {Designators, NumDesignators};
5325 }
5326
5327 Designator *getDesignator(unsigned Idx) { return &designators()[Idx]; }
5328 const Designator *getDesignator(unsigned Idx) const {
5329 return &designators()[Idx];
5330 }
5331
5332 void setDesignators(const ASTContext &C, const Designator *Desigs,
5333 unsigned NumDesigs);
5334
5335 Expr *getArrayIndex(const Designator &D) const;
5336 Expr *getArrayRangeStart(const Designator &D) const;
5337 Expr *getArrayRangeEnd(const Designator &D) const;
5338
5339 /// Retrieve the location of the '=' that precedes the
5340 /// initializer value itself, if present.
5341 SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; }
5342 void setEqualOrColonLoc(SourceLocation L) { EqualOrColonLoc = L; }
5343
5344 /// Whether this designated initializer should result in direct-initialization
5345 /// of the designated subobject (eg, '{.foo{1, 2, 3}}').
5346 bool isDirectInit() const { return EqualOrColonLoc.isInvalid(); }
5347
5348 /// Determines whether this designated initializer used the
5349 /// deprecated GNU syntax for designated initializers.
5350 bool usesGNUSyntax() const { return GNUSyntax; }
5351 void setGNUSyntax(bool GNU) { GNUSyntax = GNU; }
5352
5353 /// Retrieve the initializer value.
5354 Expr *getInit() const {
5355 return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin());
5356 }
5357
5358 void setInit(Expr *init) {
5359 *child_begin() = init;
5360 }
5361
5362 /// Retrieve the total number of subexpressions in this
5363 /// designated initializer expression, including the actual
5364 /// initialized value and any expressions that occur within array
5365 /// and array-range designators.
5366 unsigned getNumSubExprs() const { return NumSubExprs; }
5367
5368 Expr *getSubExpr(unsigned Idx) const {
5369 assert(Idx < NumSubExprs && "Subscript out of range");
5370 return cast<Expr>(getTrailingObjects<Stmt *>()[Idx]);
5371 }
5372
5373 void setSubExpr(unsigned Idx, Expr *E) {
5374 assert(Idx < NumSubExprs && "Subscript out of range");
5375 getTrailingObjects<Stmt *>()[Idx] = E;
5376 }
5377
5378 /// Replaces the designator at index @p Idx with the series
5379 /// of designators in [First, Last).
5380 void ExpandDesignator(const ASTContext &C, unsigned Idx,
5381 const Designator *First, const Designator *Last);
5382
5384
5385 SourceLocation getBeginLoc() const LLVM_READONLY;
5386 SourceLocation getEndLoc() const LLVM_READONLY;
5387
5388 static bool classof(const Stmt *T) {
5389 return T->getStmtClass() == DesignatedInitExprClass;
5390 }
5391
5392 // Iterators
5394 Stmt **begin = getTrailingObjects<Stmt *>();
5395 return child_range(begin, begin + NumSubExprs);
5396 }
5398 Stmt * const *begin = getTrailingObjects<Stmt *>();
5399 return const_child_range(begin, begin + NumSubExprs);
5400 }
5401
5403};
5404
5405/// Represents a place-holder for an object not to be initialized by
5406/// anything.
5407///
5408/// This only makes sense when it appears as part of an updater of a
5409/// DesignatedInitUpdateExpr (see below). The base expression of a DIUE
5410/// initializes a big object, and the NoInitExpr's mark the spots within the
5411/// big object not to be overwritten by the updater.
5412///
5413/// \see DesignatedInitUpdateExpr
5414class NoInitExpr : public Expr {
5415public:
5417 : Expr(NoInitExprClass, ty, VK_PRValue, OK_Ordinary) {
5419 }
5420
5421 explicit NoInitExpr(EmptyShell Empty)
5422 : Expr(NoInitExprClass, Empty) { }
5423
5424 static bool classof(const Stmt *T) {
5425 return T->getStmtClass() == NoInitExprClass;
5426 }
5427
5428 SourceLocation getBeginLoc() const LLVM_READONLY { return SourceLocation(); }
5429 SourceLocation getEndLoc() const LLVM_READONLY { return SourceLocation(); }
5430
5431 // Iterators
5434 }
5437 }
5438};
5439
5440// In cases like:
5441// struct Q { int a, b, c; };
5442// Q *getQ();
5443// void foo() {
5444// struct A { Q q; } a = { *getQ(), .q.b = 3 };
5445// }
5446//
5447// We will have an InitListExpr for a, with type A, and then a
5448// DesignatedInitUpdateExpr for "a.q" with type Q. The "base" for this DIUE
5449// is the call expression *getQ(); the "updater" for the DIUE is ".q.b = 3"
5450//
5452 // BaseAndUpdaterExprs[0] is the base expression;
5453 // BaseAndUpdaterExprs[1] is an InitListExpr overwriting part of the base.
5454 Stmt *BaseAndUpdaterExprs[2];
5455
5456public:
5458 Expr *baseExprs, SourceLocation rBraceLoc);
5459
5461 : Expr(DesignatedInitUpdateExprClass, Empty) { }
5462
5463 SourceLocation getBeginLoc() const LLVM_READONLY;
5464 SourceLocation getEndLoc() const LLVM_READONLY;
5465
5466 static bool classof(const Stmt *T) {
5467 return T->getStmtClass() == DesignatedInitUpdateExprClass;
5468 }
5469
5470 Expr *getBase() const { return cast<Expr>(BaseAndUpdaterExprs[0]); }
5471 void setBase(Expr *Base) { BaseAndUpdaterExprs[0] = Base; }
5472
5474 return cast<InitListExpr>(BaseAndUpdaterExprs[1]);
5475 }
5476 void setUpdater(Expr *Updater) { BaseAndUpdaterExprs[1] = Updater; }
5477
5478 // Iterators
5479 // children = the base and the updater
5481 return child_range(&BaseAndUpdaterExprs[0], &BaseAndUpdaterExprs[0] + 2);
5482 }
5484 return const_child_range(&BaseAndUpdaterExprs[0],
5485 &BaseAndUpdaterExprs[0] + 2);
5486 }
5487};
5488
5489/// Represents a loop initializing the elements of an array.
5490///
5491/// The need to initialize the elements of an array occurs in a number of
5492/// contexts:
5493///
5494/// * in the implicit copy/move constructor for a class with an array member
5495/// * when a lambda-expression captures an array by value
5496/// * when a decomposition declaration decomposes an array
5497///
5498/// There are two subexpressions: a common expression (the source array)
5499/// that is evaluated once up-front, and a per-element initializer that
5500/// runs once for each array element.
5501///
5502/// Within the per-element initializer, the common expression may be referenced
5503/// via an OpaqueValueExpr, and the current index may be obtained via an
5504/// ArrayInitIndexExpr.
5505class ArrayInitLoopExpr : public Expr {
5506 Stmt *SubExprs[2];
5507
5508 explicit ArrayInitLoopExpr(EmptyShell Empty)
5509 : Expr(ArrayInitLoopExprClass, Empty), SubExprs{} {}
5510
5511public:
5512 explicit ArrayInitLoopExpr(QualType T, Expr *CommonInit, Expr *ElementInit)
5513 : Expr(ArrayInitLoopExprClass, T, VK_PRValue, OK_Ordinary),
5514 SubExprs{CommonInit, ElementInit} {
5516 }
5517
5518 /// Get the common subexpression shared by all initializations (the source
5519 /// array).
5521 return cast<OpaqueValueExpr>(SubExprs[0]);
5522 }
5523
5524 /// Get the initializer to use for each array element.
5525 Expr *getSubExpr() const { return cast<Expr>(SubExprs[1]); }
5526
5527 llvm::APInt getArraySize() const {
5528 return cast<ConstantArrayType>(getType()->castAsArrayTypeUnsafe())
5529 ->getSize();
5530 }
5531
5532 static bool classof(const Stmt *S) {
5533 return S->getStmtClass() == ArrayInitLoopExprClass;
5534 }
5535
5536 SourceLocation getBeginLoc() const LLVM_READONLY {
5537 return getCommonExpr()->getBeginLoc();
5538 }
5539 SourceLocation getEndLoc() const LLVM_READONLY {
5540 return getCommonExpr()->getEndLoc();
5541 }
5542
5544 return child_range(SubExprs, SubExprs + 2);
5545 }
5547 return const_child_range(SubExprs, SubExprs + 2);
5548 }
5549
5550 friend class ASTReader;
5551 friend class ASTStmtReader;
5552 friend class ASTStmtWriter;
5553};
5554
5555/// Represents the index of the current element of an array being
5556/// initialized by an ArrayInitLoopExpr. This can only appear within the
5557/// subexpression of an ArrayInitLoopExpr.
5558class ArrayInitIndexExpr : public Expr {
5559 explicit ArrayInitIndexExpr(EmptyShell Empty)
5560 : Expr(ArrayInitIndexExprClass, Empty) {}
5561
5562public:
5564 : Expr(ArrayInitIndexExprClass, T, VK_PRValue, OK_Ordinary) {
5565 setDependence(ExprDependence::None);
5566 }
5567
5568 static bool classof(const Stmt *S) {
5569 return S->getStmtClass() == ArrayInitIndexExprClass;
5570 }
5571
5572 SourceLocation getBeginLoc() const LLVM_READONLY { return SourceLocation(); }
5573 SourceLocation getEndLoc() const LLVM_READONLY { return SourceLocation(); }
5574
5577 }
5580 }
5581
5582 friend class ASTReader;
5583 friend class ASTStmtReader;
5584};
5585
5586/// Represents an implicitly-generated value initialization of
5587/// an object of a given type.
5588///
5589/// Implicit value initializations occur within semantic initializer
5590/// list expressions (InitListExpr) as placeholders for subobject
5591/// initializations not explicitly specified by the user.
5592///
5593/// \see InitListExpr
5595public:
5597 : Expr(ImplicitValueInitExprClass, ty, VK_PRValue, OK_Ordinary) {
5599 }
5600
5601 /// Construct an empty implicit value initialization.
5603 : Expr(ImplicitValueInitExprClass, Empty) { }
5604
5605 static bool classof(const Stmt *T) {
5606 return T->getStmtClass() == ImplicitValueInitExprClass;
5607 }
5608
5609 SourceLocation getBeginLoc() const LLVM_READONLY { return SourceLocation(); }
5610 SourceLocation getEndLoc() const LLVM_READONLY { return SourceLocation(); }
5611
5612 // Iterators
5615 }
5618 }
5619};
5620
5621class ParenListExpr final
5622 : public Expr,
5623 private llvm::TrailingObjects<ParenListExpr, Stmt *> {
5624 friend class ASTStmtReader;
5625 friend TrailingObjects;
5626
5627 /// The location of the left and right parentheses.
5628 SourceLocation LParenLoc, RParenLoc;
5629
5630 /// Build a paren list.
5632 SourceLocation RParenLoc);
5633
5634 /// Build an empty paren list.
5635 ParenListExpr(EmptyShell Empty, unsigned NumExprs);
5636
5637public:
5638 /// Create a paren list.
5639 static ParenListExpr *Create(const ASTContext &Ctx, SourceLocation LParenLoc,
5640 ArrayRef<Expr *> Exprs,
5641 SourceLocation RParenLoc);
5642
5643 /// Create an empty paren list.
5644 static ParenListExpr *CreateEmpty(const ASTContext &Ctx, unsigned NumExprs);
5645
5646 /// Return the number of expressions in this paren list.
5647 unsigned getNumExprs() const { return ParenListExprBits.NumExprs; }
5648
5649 Expr *getExpr(unsigned Init) {
5650 assert(Init < getNumExprs() && "Initializer access out of range!");
5651 return getExprs()[Init];
5652 }
5653
5654 const Expr *getExpr(unsigned Init) const {
5655 return const_cast<ParenListExpr *>(this)->getExpr(Init);
5656 }
5657
5659 return reinterpret_cast<Expr **>(getTrailingObjects<Stmt *>());
5660 }
5661
5663
5664 SourceLocation getLParenLoc() const { return LParenLoc; }
5665 SourceLocation getRParenLoc() const { return RParenLoc; }
5668
5669 static bool classof(const Stmt *T) {
5670 return T->getStmtClass() == ParenListExprClass;
5671 }
5672
5673 // Iterators
5675 return child_range(getTrailingObjects<Stmt *>(),
5676 getTrailingObjects<Stmt *>() + getNumExprs());
5677 }
5679 return const_child_range(getTrailingObjects<Stmt *>(),
5680 getTrailingObjects<Stmt *>() + getNumExprs());
5681 }
5682};
5683
5684/// Represents a C11 generic selection.
5685///
5686/// A generic selection (C11 6.5.1.1) contains an unevaluated controlling
5687/// expression, followed by one or more generic associations. Each generic
5688/// association specifies a type name and an expression, or "default" and an
5689/// expression (in which case it is known as a default generic association).
5690/// The type and value of the generic selection are identical to those of its
5691/// result expression, which is defined as the expression in the generic
5692/// association with a type name that is compatible with the type of the
5693/// controlling expression, or the expression in the default generic association
5694/// if no types are compatible. For example:
5695///
5696/// @code
5697/// _Generic(X, double: 1, float: 2, default: 3)
5698/// @endcode
5699///
5700/// The above expression evaluates to 1 if 1.0 is substituted for X, 2 if 1.0f
5701/// or 3 if "hello".
5702///
5703/// As an extension, generic selections are allowed in C++, where the following
5704/// additional semantics apply:
5705///
5706/// Any generic selection whose controlling expression is type-dependent or
5707/// which names a dependent type in its association list is result-dependent,
5708/// which means that the choice of result expression is dependent.
5709/// Result-dependent generic associations are both type- and value-dependent.
5710///
5711/// We also allow an extended form in both C and C++ where the controlling
5712/// predicate for the selection expression is a type rather than an expression.
5713/// This type argument form does not perform any conversions for the
5714/// controlling type, which makes it suitable for use with qualified type
5715/// associations, which is not possible with the expression form.
5717 : public Expr,
5718 private llvm::TrailingObjects<GenericSelectionExpr, Stmt *,
5719 TypeSourceInfo *> {
5720 friend class ASTStmtReader;
5721 friend class ASTStmtWriter;
5722 friend TrailingObjects;
5723
5724 /// The number of association expressions and the index of the result
5725 /// expression in the case where the generic selection expression is not
5726 /// result-dependent. The result index is equal to ResultDependentIndex
5727 /// if and only if the generic selection expression is result-dependent.
5728 unsigned NumAssocs : 15;
5729 unsigned ResultIndex : 15; // NB: ResultDependentIndex is tied to this width.
5730 LLVM_PREFERRED_TYPE(bool)
5731 unsigned IsExprPredicate : 1;
5732 enum : unsigned {
5733 ResultDependentIndex = 0x7FFF
5734 };
5735
5736 unsigned getIndexOfControllingExpression() const {
5737 // If controlled by an expression, the first offset into the Stmt *
5738 // trailing array is the controlling expression, the associated expressions
5739 // follow this.
5740 assert(isExprPredicate() && "Asking for the controlling expression of a "
5741 "selection expr predicated by a type");
5742 return 0;
5743 }
5744
5745 unsigned getIndexOfControllingType() const {
5746 // If controlled by a type, the first offset into the TypeSourceInfo *
5747 // trailing array is the controlling type, the associated types follow this.
5748 assert(isTypePredicate() && "Asking for the controlling type of a "
5749 "selection expr predicated by an expression");
5750 return 0;
5751 }
5752
5753 unsigned getIndexOfStartOfAssociatedExprs() const {
5754 // If the predicate is a type, then the associated expressions are the only
5755 // Stmt * in the trailing array, otherwise we need to offset past the
5756 // predicate expression.
5757 return (int)isExprPredicate();
5758 }
5759
5760 unsigned getIndexOfStartOfAssociatedTypes() const {
5761 // If the predicate is a type, then the associated types follow it in the
5762 // trailing array. Otherwise, the associated types are the only
5763 // TypeSourceInfo * in the trailing array.
5764 return (int)isTypePredicate();
5765 }
5766
5767
5768 /// The location of the "default" and of the right parenthesis.
5769 SourceLocation DefaultLoc, RParenLoc;
5770
5771 // GenericSelectionExpr is followed by several trailing objects.
5772 // They are (in order):
5773 //
5774 // * A single Stmt * for the controlling expression or a TypeSourceInfo * for
5775 // the controlling type, depending on the result of isTypePredicate() or
5776 // isExprPredicate().
5777 // * An array of getNumAssocs() Stmt * for the association expressions.
5778 // * An array of getNumAssocs() TypeSourceInfo *, one for each of the
5779 // association expressions.
5780 unsigned numTrailingObjects(OverloadToken<Stmt *>) const {
5781 // Add one to account for the controlling expression; the remainder
5782 // are the associated expressions.
5783 return getNumAssocs() + (int)isExprPredicate();
5784 }
5785
5786 unsigned numTrailingObjects(OverloadToken<TypeSourceInfo *>) const {
5787 // Add one to account for the controlling type predicate, the remainder
5788 // are the associated types.
5789 return getNumAssocs() + (int)isTypePredicate();
5790 }
5791
5792 template <bool Const> class AssociationIteratorTy;
5793 /// Bundle together an association expression and its TypeSourceInfo.
5794 /// The Const template parameter is for the const and non-const versions
5795 /// of AssociationTy.
5796 template <bool Const> class AssociationTy {
5797 friend class GenericSelectionExpr;
5798 template <bool OtherConst> friend class AssociationIteratorTy;
5799 using ExprPtrTy = std::conditional_t<Const, const Expr *, Expr *>;
5800 using TSIPtrTy =
5801 std::conditional_t<Const, const TypeSourceInfo *, TypeSourceInfo *>;
5802 ExprPtrTy E;
5803 TSIPtrTy TSI;
5804 bool Selected;
5805 AssociationTy(ExprPtrTy E, TSIPtrTy TSI, bool Selected)
5806 : E(E), TSI(TSI), Selected(Selected) {}
5807
5808 public:
5809 ExprPtrTy getAssociationExpr() const { return E; }
5810 TSIPtrTy getTypeSourceInfo() const { return TSI; }
5811 QualType getType() const { return TSI ? TSI->getType() : QualType(); }
5812 bool isSelected() const { return Selected; }
5813 AssociationTy *operator->() { return this; }
5814 const AssociationTy *operator->() const { return this; }
5815 }; // class AssociationTy
5816
5817 /// Iterator over const and non-const Association objects. The Association
5818 /// objects are created on the fly when the iterator is dereferenced.
5819 /// This abstract over how exactly the association expressions and the
5820 /// corresponding TypeSourceInfo * are stored.
5821 template <bool Const>
5822 class AssociationIteratorTy
5823 : public llvm::iterator_facade_base<
5824 AssociationIteratorTy<Const>, std::input_iterator_tag,
5825 AssociationTy<Const>, std::ptrdiff_t, AssociationTy<Const>,
5826 AssociationTy<Const>> {
5827 friend class GenericSelectionExpr;
5828 // FIXME: This iterator could conceptually be a random access iterator, and
5829 // it would be nice if we could strengthen the iterator category someday.
5830 // However this iterator does not satisfy two requirements of forward
5831 // iterators:
5832 // a) reference = T& or reference = const T&
5833 // b) If It1 and It2 are both dereferenceable, then It1 == It2 if and only
5834 // if *It1 and *It2 are bound to the same objects.
5835 // An alternative design approach was discussed during review;
5836 // store an Association object inside the iterator, and return a reference
5837 // to it when dereferenced. This idea was discarded beacuse of nasty
5838 // lifetime issues:
5839 // AssociationIterator It = ...;
5840 // const Association &Assoc = *It++; // Oops, Assoc is dangling.
5841 using BaseTy = typename AssociationIteratorTy::iterator_facade_base;
5842 using StmtPtrPtrTy =
5843 std::conditional_t<Const, const Stmt *const *, Stmt **>;
5844 using TSIPtrPtrTy = std::conditional_t<Const, const TypeSourceInfo *const *,
5845 TypeSourceInfo **>;
5846 StmtPtrPtrTy E = nullptr;
5847 TSIPtrPtrTy TSI; // Kept in sync with E.
5848 unsigned Offset = 0, SelectedOffset = 0;
5849 AssociationIteratorTy(StmtPtrPtrTy E, TSIPtrPtrTy TSI, unsigned Offset,
5850 unsigned SelectedOffset)
5851 : E(E), TSI(TSI), Offset(Offset), SelectedOffset(SelectedOffset) {}
5852
5853 public:
5854 AssociationIteratorTy() : E(nullptr), TSI(nullptr) {}
5855 typename BaseTy::reference operator*() const {
5856 return AssociationTy<Const>(cast<Expr>(*E), *TSI,
5857 Offset == SelectedOffset);
5858 }
5859 typename BaseTy::pointer operator->() const { return **this; }
5860 using BaseTy::operator++;
5861 AssociationIteratorTy &operator++() {
5862 ++E;
5863 ++TSI;
5864 ++Offset;
5865 return *this;
5866 }
5867 bool operator==(AssociationIteratorTy Other) const { return E == Other.E; }
5868 }; // class AssociationIterator
5869
5870 /// Build a non-result-dependent generic selection expression accepting an
5871 /// expression predicate.
5872 GenericSelectionExpr(const ASTContext &Context, SourceLocation GenericLoc,
5873 Expr *ControllingExpr,
5874 ArrayRef<TypeSourceInfo *> AssocTypes,
5875 ArrayRef<Expr *> AssocExprs, SourceLocation DefaultLoc,
5876 SourceLocation RParenLoc,
5877 bool ContainsUnexpandedParameterPack,
5878 unsigned ResultIndex);
5879
5880 /// Build a result-dependent generic selection expression accepting an
5881 /// expression predicate.
5882 GenericSelectionExpr(const ASTContext &Context, SourceLocation GenericLoc,
5883 Expr *ControllingExpr,
5884 ArrayRef<TypeSourceInfo *> AssocTypes,
5885 ArrayRef<Expr *> AssocExprs, SourceLocation DefaultLoc,
5886 SourceLocation RParenLoc,
5887 bool ContainsUnexpandedParameterPack);
5888
5889 /// Build a non-result-dependent generic selection expression accepting a
5890 /// type predicate.
5891 GenericSelectionExpr(const ASTContext &Context, SourceLocation GenericLoc,
5892 TypeSourceInfo *ControllingType,
5893 ArrayRef<TypeSourceInfo *> AssocTypes,
5894 ArrayRef<Expr *> AssocExprs, SourceLocation DefaultLoc,
5895 SourceLocation RParenLoc,
5896 bool ContainsUnexpandedParameterPack,
5897 unsigned ResultIndex);
5898
5899 /// Build a result-dependent generic selection expression accepting a type
5900 /// predicate.
5901 GenericSelectionExpr(const ASTContext &Context, SourceLocation GenericLoc,
5902 TypeSourceInfo *ControllingType,
5903 ArrayRef<TypeSourceInfo *> AssocTypes,
5904 ArrayRef<Expr *> AssocExprs, SourceLocation DefaultLoc,
5905 SourceLocation RParenLoc,
5906 bool ContainsUnexpandedParameterPack);
5907
5908 /// Build an empty generic selection expression for deserialization.
5909 explicit GenericSelectionExpr(EmptyShell Empty, unsigned NumAssocs);
5910
5911public:
5912 /// Create a non-result-dependent generic selection expression accepting an
5913 /// expression predicate.
5914 static GenericSelectionExpr *
5915 Create(const ASTContext &Context, SourceLocation GenericLoc,
5916 Expr *ControllingExpr, ArrayRef<TypeSourceInfo *> AssocTypes,
5917 ArrayRef<Expr *> AssocExprs, SourceLocation DefaultLoc,
5918 SourceLocation RParenLoc, bool ContainsUnexpandedParameterPack,
5919 unsigned ResultIndex);
5920
5921 /// Create a result-dependent generic selection expression accepting an
5922 /// expression predicate.
5923 static GenericSelectionExpr *
5924 Create(const ASTContext &Context, SourceLocation GenericLoc,
5925 Expr *ControllingExpr, ArrayRef<TypeSourceInfo *> AssocTypes,
5926 ArrayRef<Expr *> AssocExprs, SourceLocation DefaultLoc,
5927 SourceLocation RParenLoc, bool ContainsUnexpandedParameterPack);
5928
5929 /// Create a non-result-dependent generic selection expression accepting a
5930 /// type predicate.
5931 static GenericSelectionExpr *
5932 Create(const ASTContext &Context, SourceLocation GenericLoc,
5933 TypeSourceInfo *ControllingType, ArrayRef<TypeSourceInfo *> AssocTypes,
5934 ArrayRef<Expr *> AssocExprs, SourceLocation DefaultLoc,
5935 SourceLocation RParenLoc, bool ContainsUnexpandedParameterPack,
5936 unsigned ResultIndex);
5937
5938 /// Create a result-dependent generic selection expression accepting a type
5939 /// predicate
5940 static GenericSelectionExpr *
5941 Create(const ASTContext &Context, SourceLocation GenericLoc,
5942 TypeSourceInfo *ControllingType, ArrayRef<TypeSourceInfo *> AssocTypes,
5943 ArrayRef<Expr *> AssocExprs, SourceLocation DefaultLoc,
5944 SourceLocation RParenLoc, bool ContainsUnexpandedParameterPack);
5945
5946 /// Create an empty generic selection expression for deserialization.
5947 static GenericSelectionExpr *CreateEmpty(const ASTContext &Context,
5948 unsigned NumAssocs);
5949
5950 using Association = AssociationTy<false>;
5951 using ConstAssociation = AssociationTy<true>;
5952 using AssociationIterator = AssociationIteratorTy<false>;
5953 using ConstAssociationIterator = AssociationIteratorTy<true>;
5954 using association_range = llvm::iterator_range<AssociationIterator>;
5956 llvm::iterator_range<ConstAssociationIterator>;
5957
5958 /// The number of association expressions.
5959 unsigned getNumAssocs() const { return NumAssocs; }
5960
5961 /// The zero-based index of the result expression's generic association in
5962 /// the generic selection's association list. Defined only if the
5963 /// generic selection is not result-dependent.
5964 unsigned getResultIndex() const {
5965 assert(!isResultDependent() &&
5966 "Generic selection is result-dependent but getResultIndex called!");
5967 return ResultIndex;
5968 }
5969
5970 /// Whether this generic selection is result-dependent.
5971 bool isResultDependent() const { return ResultIndex == ResultDependentIndex; }
5972
5973 /// Whether this generic selection uses an expression as its controlling
5974 /// argument.
5975 bool isExprPredicate() const { return IsExprPredicate; }
5976 /// Whether this generic selection uses a type as its controlling argument.
5977 bool isTypePredicate() const { return !IsExprPredicate; }
5978
5979 /// Return the controlling expression of this generic selection expression.
5980 /// Only valid to call if the selection expression used an expression as its
5981 /// controlling argument.
5983 return cast<Expr>(
5984 getTrailingObjects<Stmt *>()[getIndexOfControllingExpression()]);
5985 }
5986 const Expr *getControllingExpr() const {
5987 return cast<Expr>(
5988 getTrailingObjects<Stmt *>()[getIndexOfControllingExpression()]);
5989 }
5990
5991 /// Return the controlling type of this generic selection expression. Only
5992 /// valid to call if the selection expression used a type as its controlling
5993 /// argument.
5995 return getTrailingObjects<TypeSourceInfo *>()[getIndexOfControllingType()];
5996 }
5998 return getTrailingObjects<TypeSourceInfo *>()[getIndexOfControllingType()];
5999 }
6000
6001 /// Return the result expression of this controlling expression. Defined if
6002 /// and only if the generic selection expression is not result-dependent.
6004 return cast<Expr>(
6005 getTrailingObjects<Stmt *>()[getIndexOfStartOfAssociatedExprs() +
6006 getResultIndex()]);
6007 }
6008 const Expr *getResultExpr() const {
6009 return cast<Expr>(
6010 getTrailingObjects<Stmt *>()[getIndexOfStartOfAssociatedExprs() +
6011 getResultIndex()]);
6012 }
6013
6015 return {reinterpret_cast<Expr *const *>(getTrailingObjects<Stmt *>() +
6016 getIndexOfStartOfAssociatedExprs()),
6017 NumAssocs};
6018 }
6020 return {getTrailingObjects<TypeSourceInfo *>() +
6021 getIndexOfStartOfAssociatedTypes(),
6022 NumAssocs};
6023 }
6024
6025 /// Return the Ith association expression with its TypeSourceInfo,
6026 /// bundled together in GenericSelectionExpr::(Const)Association.
6028 assert(I < getNumAssocs() &&
6029 "Out-of-range index in GenericSelectionExpr::getAssociation!");
6030 return Association(
6031 cast<Expr>(
6032 getTrailingObjects<Stmt *>()[getIndexOfStartOfAssociatedExprs() +
6033 I]),
6034 getTrailingObjects<
6035 TypeSourceInfo *>()[getIndexOfStartOfAssociatedTypes() + I],
6036 !isResultDependent() && (getResultIndex() == I));
6037 }
6039 assert(I < getNumAssocs() &&
6040 "Out-of-range index in GenericSelectionExpr::getAssociation!");
6041 return ConstAssociation(
6042 cast<Expr>(
6043 getTrailingObjects<Stmt *>()[getIndexOfStartOfAssociatedExprs() +
6044 I]),
6045 getTrailingObjects<
6046 TypeSourceInfo *>()[getIndexOfStartOfAssociatedTypes() + I],
6047 !isResultDependent() && (getResultIndex() == I));
6048 }
6049
6051 AssociationIterator Begin(getTrailingObjects<Stmt *>() +
6052 getIndexOfStartOfAssociatedExprs(),
6053 getTrailingObjects<TypeSourceInfo *>() +
6054 getIndexOfStartOfAssociatedTypes(),
6055 /*Offset=*/0, ResultIndex);
6056 AssociationIterator End(Begin.E + NumAssocs, Begin.TSI + NumAssocs,
6057 /*Offset=*/NumAssocs, ResultIndex);
6058 return llvm::make_range(Begin, End);
6059 }
6060
6062 ConstAssociationIterator Begin(getTrailingObjects<Stmt *>() +
6063 getIndexOfStartOfAssociatedExprs(),
6064 getTrailingObjects<TypeSourceInfo *>() +
6065 getIndexOfStartOfAssociatedTypes(),
6066 /*Offset=*/0, ResultIndex);
6067 ConstAssociationIterator End(Begin.E + NumAssocs, Begin.TSI + NumAssocs,
6068 /*Offset=*/NumAssocs, ResultIndex);
6069 return llvm::make_range(Begin, End);
6070 }
6071
6073 return GenericSelectionExprBits.GenericLoc;
6074 }
6075 SourceLocation getDefaultLoc() const { return DefaultLoc; }
6076 SourceLocation getRParenLoc() const { return RParenLoc; }
6079
6080 static bool classof(const Stmt *T) {
6081 return T->getStmtClass() == GenericSelectionExprClass;
6082 }
6083
6085 return child_range(getTrailingObjects<Stmt *>(),
6086 getTrailingObjects<Stmt *>() +
6087 numTrailingObjects(OverloadToken<Stmt *>()));
6088 }
6090 return const_child_range(getTrailingObjects<Stmt *>(),
6091 getTrailingObjects<Stmt *>() +
6092 numTrailingObjects(OverloadToken<Stmt *>()));
6093 }
6094};
6095
6096//===----------------------------------------------------------------------===//
6097// Clang Extensions
6098//===----------------------------------------------------------------------===//
6099
6100/// ExtVectorElementExpr - This represents access to specific elements of a
6101/// vector, and may occur on the left hand side or right hand side. For example
6102/// the following is legal: "V.xy = V.zw" if V is a 4 element extended vector.
6103///
6104/// Note that the base may have either vector or pointer to vector type, just
6105/// like a struct field reference.
6106///
6108 Stmt *Base;
6109 IdentifierInfo *Accessor;
6110 SourceLocation AccessorLoc;
6111public:
6113 IdentifierInfo &accessor, SourceLocation loc)
6114 : Expr(ExtVectorElementExprClass, ty, VK,
6116 Base(base), Accessor(&accessor), AccessorLoc(loc) {
6118 }
6119
6120 /// Build an empty vector element expression.
6122 : Expr(ExtVectorElementExprClass, Empty) { }
6123
6124 const Expr *getBase() const { return cast<Expr>(Base); }
6125 Expr *getBase() { return cast<Expr>(Base); }
6126 void setBase(Expr *E) { Base = E; }
6127
6128 IdentifierInfo &getAccessor() const { return *Accessor; }
6129 void setAccessor(IdentifierInfo *II) { Accessor = II; }
6130
6131 SourceLocation getAccessorLoc() const { return AccessorLoc; }
6132 void setAccessorLoc(SourceLocation L) { AccessorLoc = L; }
6133
6134 /// getNumElements - Get the number of components being selected.
6135 unsigned getNumElements() const;
6136
6137 /// containsDuplicateElements - Return true if any element access is
6138 /// repeated.
6139 bool containsDuplicateElements() const;
6140
6141 /// getEncodedElementAccess - Encode the elements accessed into an llvm
6142 /// aggregate Constant of ConstantInt(s).
6144
6145 SourceLocation getBeginLoc() const LLVM_READONLY {
6146 return getBase()->getBeginLoc();
6147 }
6148 SourceLocation getEndLoc() const LLVM_READONLY { return AccessorLoc; }
6149
6150 /// isArrow - Return true if the base expression is a pointer to vector,
6151 /// return false if the base expression is a vector.
6152 bool isArrow() const;
6153
6154 static bool classof(const Stmt *T) {
6155 return T->getStmtClass() == ExtVectorElementExprClass;
6156 }
6157
6158 // Iterators
6161 return const_child_range(&Base, &Base + 1);
6162 }
6163};
6164
6165/// BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
6166/// ^{ statement-body } or ^(int arg1, float arg2){ statement-body }
6167class BlockExpr : public Expr {
6168protected:
6170public:
6172 : Expr(BlockExprClass, ty, VK_PRValue, OK_Ordinary), TheBlock(BD) {
6174 }
6175
6176 /// Build an empty block expression.
6177 explicit BlockExpr(EmptyShell Empty) : Expr(BlockExprClass, Empty) { }
6178
6179 const BlockDecl *getBlockDecl() const { return TheBlock; }
6181 void setBlockDecl(BlockDecl *BD) { TheBlock = BD; }
6182
6183 // Convenience functions for probing the underlying BlockDecl.
6185 const Stmt *getBody() const;
6186 Stmt *getBody();
6187
6188 SourceLocation getBeginLoc() const LLVM_READONLY {
6189 return getCaretLocation();
6190 }
6191 SourceLocation getEndLoc() const LLVM_READONLY {
6192 return getBody()->getEndLoc();
6193 }
6194
6195 /// getFunctionType - Return the underlying function type for this block.
6196 const FunctionProtoType *getFunctionType() const;
6197
6198 static bool classof(const Stmt *T) {
6199 return T->getStmtClass() == BlockExprClass;
6200 }
6201
6202 // Iterators
6205 }
6208 }
6209};
6210
6211/// Copy initialization expr of a __block variable and a boolean flag that
6212/// indicates whether the expression can throw.
6214 BlockVarCopyInit() = default;
6216 : ExprAndFlag(CopyExpr, CanThrow) {}
6217 void setExprAndFlag(Expr *CopyExpr, bool CanThrow) {
6218 ExprAndFlag.setPointerAndInt(CopyExpr, CanThrow);
6219 }
6220 Expr *getCopyExpr() const { return ExprAndFlag.getPointer(); }
6221 bool canThrow() const { return ExprAndFlag.getInt(); }
6222 llvm::PointerIntPair<Expr *, 1, bool> ExprAndFlag;
6223};
6224
6225/// AsTypeExpr - Clang builtin function __builtin_astype [OpenCL 6.2.4.2]
6226/// This AST node provides support for reinterpreting a type to another
6227/// type of the same size.
6228class AsTypeExpr : public Expr {
6229private:
6230 Stmt *SrcExpr;
6231 SourceLocation BuiltinLoc, RParenLoc;
6232
6233 friend class ASTReader;
6234 friend class ASTStmtReader;
6235 explicit AsTypeExpr(EmptyShell Empty) : Expr(AsTypeExprClass, Empty) {}
6236
6237public:
6238 AsTypeExpr(Expr *SrcExpr, QualType DstType, ExprValueKind VK,
6239 ExprObjectKind OK, SourceLocation BuiltinLoc,
6240 SourceLocation RParenLoc)
6241 : Expr(AsTypeExprClass, DstType, VK, OK), SrcExpr(SrcExpr),
6242 BuiltinLoc(BuiltinLoc), RParenLoc(RParenLoc) {
6244 }
6245
6246 /// getSrcExpr - Return the Expr to be converted.
6247 Expr *getSrcExpr() const { return cast<Expr>(SrcExpr); }
6248
6249 /// getBuiltinLoc - Return the location of the __builtin_astype token.
6250 SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
6251
6252 /// getRParenLoc - Return the location of final right parenthesis.
6253 SourceLocation getRParenLoc() const { return RParenLoc; }
6254
6255 SourceLocation getBeginLoc() const LLVM_READONLY { return BuiltinLoc; }
6256 SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
6257
6258 static bool classof(const Stmt *T) {
6259 return T->getStmtClass() == AsTypeExprClass;
6260 }
6261
6262 // Iterators
6263 child_range children() { return child_range(&SrcExpr, &SrcExpr+1); }
6265 return const_child_range(&SrcExpr, &SrcExpr + 1);
6266 }
6267};
6268
6269/// PseudoObjectExpr - An expression which accesses a pseudo-object
6270/// l-value. A pseudo-object is an abstract object, accesses to which
6271/// are translated to calls. The pseudo-object expression has a
6272/// syntactic form, which shows how the expression was actually
6273/// written in the source code, and a semantic form, which is a series
6274/// of expressions to be executed in order which detail how the
6275/// operation is actually evaluated. Optionally, one of the semantic
6276/// forms may also provide a result value for the expression.
6277///
6278/// If any of the semantic-form expressions is an OpaqueValueExpr,
6279/// that OVE is required to have a source expression, and it is bound
6280/// to the result of that source expression. Such OVEs may appear
6281/// only in subsequent semantic-form expressions and as
6282/// sub-expressions of the syntactic form.
6283///
6284/// PseudoObjectExpr should be used only when an operation can be
6285/// usefully described in terms of fairly simple rewrite rules on
6286/// objects and functions that are meant to be used by end-developers.
6287/// For example, under the Itanium ABI, dynamic casts are implemented
6288/// as a call to a runtime function called __dynamic_cast; using this
6289/// class to describe that would be inappropriate because that call is
6290/// not really part of the user-visible semantics, and instead the
6291/// cast is properly reflected in the AST and IR-generation has been
6292/// taught to generate the call as necessary. In contrast, an
6293/// Objective-C property access is semantically defined to be
6294/// equivalent to a particular message send, and this is very much
6295/// part of the user model. The name of this class encourages this
6296/// modelling design.
6298 : public Expr,
6299 private llvm::TrailingObjects<PseudoObjectExpr, Expr *> {
6300 // PseudoObjectExprBits.NumSubExprs - The number of sub-expressions.
6301 // Always at least two, because the first sub-expression is the
6302 // syntactic form.
6303
6304 // PseudoObjectExprBits.ResultIndex - The index of the
6305 // sub-expression holding the result. 0 means the result is void,
6306 // which is unambiguous because it's the index of the syntactic
6307 // form. Note that this is therefore 1 higher than the value passed
6308 // in to Create, which is an index within the semantic forms.
6309 // Note also that ASTStmtWriter assumes this encoding.
6310
6311 Expr **getSubExprsBuffer() { return getTrailingObjects<Expr *>(); }
6312 const Expr * const *getSubExprsBuffer() const {
6313 return getTrailingObjects<Expr *>();
6314 }
6315
6317 Expr *syntactic, ArrayRef<Expr*> semantic,
6318 unsigned resultIndex);
6319
6320 PseudoObjectExpr(EmptyShell shell, unsigned numSemanticExprs);
6321
6322 unsigned getNumSubExprs() const {
6323 return PseudoObjectExprBits.NumSubExprs;
6324 }
6325
6326public:
6327 /// NoResult - A value for the result index indicating that there is
6328 /// no semantic result.
6329 enum : unsigned { NoResult = ~0U };
6330
6331 static PseudoObjectExpr *Create(const ASTContext &Context, Expr *syntactic,
6332 ArrayRef<Expr*> semantic,
6333 unsigned resultIndex);
6334
6335 static PseudoObjectExpr *Create(const ASTContext &Context, EmptyShell shell,
6336 unsigned numSemanticExprs);
6337
6338 /// Return the syntactic form of this expression, i.e. the
6339 /// expression it actually looks like. Likely to be expressed in
6340 /// terms of OpaqueValueExprs bound in the semantic form.
6341 Expr *getSyntacticForm() { return getSubExprsBuffer()[0]; }
6342 const Expr *getSyntacticForm() const { return getSubExprsBuffer()[0]; }
6343
6344 /// Return the index of the result-bearing expression into the semantics
6345 /// expressions, or PseudoObjectExpr::NoResult if there is none.
6346 unsigned getResultExprIndex() const {
6347 if (PseudoObjectExprBits.ResultIndex == 0) return NoResult;
6348 return PseudoObjectExprBits.ResultIndex - 1;
6349 }
6350
6351 /// Return the result-bearing expression, or null if there is none.
6353 if (PseudoObjectExprBits.ResultIndex == 0)
6354 return nullptr;
6355 return getSubExprsBuffer()[PseudoObjectExprBits.ResultIndex];
6356 }
6357 const Expr *getResultExpr() const {
6358 return const_cast<PseudoObjectExpr*>(this)->getResultExpr();
6359 }
6360
6361 unsigned getNumSemanticExprs() const { return getNumSubExprs() - 1; }
6362
6363 typedef Expr * const *semantics_iterator;
6364 typedef const Expr * const *const_semantics_iterator;
6366 return getSubExprsBuffer() + 1;
6367 }
6369 return getSubExprsBuffer() + 1;
6370 }
6372 return getSubExprsBuffer() + getNumSubExprs();
6373 }
6375 return getSubExprsBuffer() + getNumSubExprs();
6376 }
6377
6380 }
6383 }
6384
6385 Expr *getSemanticExpr(unsigned index) {
6386 assert(index + 1 < getNumSubExprs());
6387 return getSubExprsBuffer()[index + 1];
6388 }
6389 const Expr *getSemanticExpr(unsigned index) const {
6390 return const_cast<PseudoObjectExpr*>(this)->getSemanticExpr(index);
6391 }
6392
6393 SourceLocation getExprLoc() const LLVM_READONLY {
6394 return getSyntacticForm()->getExprLoc();
6395 }
6396
6397 SourceLocation getBeginLoc() const LLVM_READONLY {
6398 return getSyntacticForm()->getBeginLoc();
6399 }
6400 SourceLocation getEndLoc() const LLVM_READONLY {
6401 return getSyntacticForm()->getEndLoc();
6402 }
6403
6405 const_child_range CCR =
6406 const_cast<const PseudoObjectExpr *>(this)->children();
6407 return child_range(cast_away_const(CCR.begin()),
6408 cast_away_const(CCR.end()));
6409 }
6411 Stmt *const *cs = const_cast<Stmt *const *>(
6412 reinterpret_cast<const Stmt *const *>(getSubExprsBuffer()));
6413 return const_child_range(cs, cs + getNumSubExprs());
6414 }
6415
6416 static bool classof(const Stmt *T) {
6417 return T->getStmtClass() == PseudoObjectExprClass;
6418 }
6419
6421 friend class ASTStmtReader;
6422};
6423
6424/// AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*,
6425/// __atomic_load, __atomic_store, and __atomic_compare_exchange_*, for the
6426/// similarly-named C++11 instructions, and __c11 variants for <stdatomic.h>,
6427/// and corresponding __opencl_atomic_* for OpenCL 2.0.
6428/// All of these instructions take one primary pointer, at least one memory
6429/// order. The instructions for which getScopeModel returns non-null value
6430/// take one synch scope.
6431class AtomicExpr : public Expr {
6432public:
6434#define BUILTIN(ID, TYPE, ATTRS)
6435#define ATOMIC_BUILTIN(ID, TYPE, ATTRS) AO ## ID,
6436#include "clang/Basic/Builtins.inc"
6437 // Avoid trailing comma
6438 BI_First = 0
6440
6441private:
6442 /// Location of sub-expressions.
6443 /// The location of Scope sub-expression is NumSubExprs - 1, which is
6444 /// not fixed, therefore is not defined in enum.
6445 enum { PTR, ORDER, VAL1, ORDER_FAIL, VAL2, WEAK, END_EXPR };
6446 Stmt *SubExprs[END_EXPR + 1];
6447 unsigned NumSubExprs;
6448 SourceLocation BuiltinLoc, RParenLoc;
6449 AtomicOp Op;
6450
6451 friend class ASTStmtReader;
6452public:
6454 AtomicOp op, SourceLocation RP);
6455
6456 /// Determine the number of arguments the specified atomic builtin
6457 /// should have.
6458 static unsigned getNumSubExprs(AtomicOp Op);
6459
6460 /// Build an empty AtomicExpr.
6461 explicit AtomicExpr(EmptyShell Empty) : Expr(AtomicExprClass, Empty) { }
6462
6463 Expr *getPtr() const {
6464 return cast<Expr>(SubExprs[PTR]);
6465 }
6466 Expr *getOrder() const {
6467 return cast<Expr>(SubExprs[ORDER]);
6468 }
6469 Expr *getScope() const {
6470 assert(getScopeModel() && "No scope");
6471 return cast<Expr>(SubExprs[NumSubExprs - 1]);
6472 }
6473 Expr *getVal1() const {
6474 if (Op == AO__c11_atomic_init || Op == AO__opencl_atomic_init)
6475 return cast<Expr>(SubExprs[ORDER]);
6476 assert(NumSubExprs > VAL1);
6477 return cast<Expr>(SubExprs[VAL1]);
6478 }
6480 assert(NumSubExprs > ORDER_FAIL);
6481 return cast<Expr>(SubExprs[ORDER_FAIL]);
6482 }
6483 Expr *getVal2() const {
6484 if (Op == AO__atomic_exchange || Op == AO__scoped_atomic_exchange)
6485 return cast<Expr>(SubExprs[ORDER_FAIL]);
6486 assert(NumSubExprs > VAL2);
6487 return cast<Expr>(SubExprs[VAL2]);
6488 }
6489 Expr *getWeak() const {
6490 assert(NumSubExprs > WEAK);
6491 return cast<Expr>(SubExprs[WEAK]);
6492 }
6493 QualType getValueType() const;
6494
6495 AtomicOp getOp() const { return Op; }
6496 StringRef getOpAsString() const {
6497 switch (Op) {
6498#define BUILTIN(ID, TYPE, ATTRS)
6499#define ATOMIC_BUILTIN(ID, TYPE, ATTRS) \
6500 case AO##ID: \
6501 return #ID;
6502#include "clang/Basic/Builtins.inc"
6503 }
6504 llvm_unreachable("not an atomic operator?");
6505 }
6506 unsigned getNumSubExprs() const { return NumSubExprs; }
6507
6508 Expr **getSubExprs() { return reinterpret_cast<Expr **>(SubExprs); }
6509 const Expr * const *getSubExprs() const {
6510 return reinterpret_cast<Expr * const *>(SubExprs);
6511 }
6512
6513 bool isVolatile() const {
6515 }
6516
6517 bool isCmpXChg() const {
6518 return getOp() == AO__c11_atomic_compare_exchange_strong ||
6519 getOp() == AO__c11_atomic_compare_exchange_weak ||
6520 getOp() == AO__hip_atomic_compare_exchange_strong ||
6521 getOp() == AO__opencl_atomic_compare_exchange_strong ||
6522 getOp() == AO__opencl_atomic_compare_exchange_weak ||
6523 getOp() == AO__hip_atomic_compare_exchange_weak ||
6524 getOp() == AO__atomic_compare_exchange ||
6525 getOp() == AO__atomic_compare_exchange_n ||
6526 getOp() == AO__scoped_atomic_compare_exchange ||
6527 getOp() == AO__scoped_atomic_compare_exchange_n;
6528 }
6529
6530 bool isOpenCL() const {
6531 return getOp() >= AO__opencl_atomic_compare_exchange_strong &&
6532 getOp() <= AO__opencl_atomic_store;
6533 }
6534
6535 SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
6536 SourceLocation getRParenLoc() const { return RParenLoc; }
6537
6538 SourceLocation getBeginLoc() const LLVM_READONLY { return BuiltinLoc; }
6539 SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
6540
6541 static bool classof(const Stmt *T) {
6542 return T->getStmtClass() == AtomicExprClass;
6543 }
6544
6545 // Iterators
6547 return child_range(SubExprs, SubExprs+NumSubExprs);
6548 }
6550 return const_child_range(SubExprs, SubExprs + NumSubExprs);
6551 }
6552
6553 /// Get atomic scope model for the atomic op code.
6554 /// \return empty atomic scope model if the atomic op code does not have
6555 /// scope operand.
6556 static std::unique_ptr<AtomicScopeModel> getScopeModel(AtomicOp Op) {
6557 // FIXME: Allow grouping of builtins to be able to only check >= and <=
6558 if (Op >= AO__opencl_atomic_compare_exchange_strong &&
6559 Op <= AO__opencl_atomic_store && Op != AO__opencl_atomic_init)
6561 if (Op >= AO__hip_atomic_compare_exchange_strong &&
6562 Op <= AO__hip_atomic_store)
6564 if (Op >= AO__scoped_atomic_add_fetch && Op <= AO__scoped_atomic_xor_fetch)
6567 }
6568
6569 /// Get atomic scope model.
6570 /// \return empty atomic scope model if this atomic expression does not have
6571 /// scope operand.
6572 std::unique_ptr<AtomicScopeModel> getScopeModel() const {
6573 return getScopeModel(getOp());
6574 }
6575};
6576
6577/// TypoExpr - Internal placeholder for expressions where typo correction
6578/// still needs to be performed and/or an error diagnostic emitted.
6579class TypoExpr : public Expr {
6580 // The location for the typo name.
6581 SourceLocation TypoLoc;
6582
6583public:
6585 : Expr(TypoExprClass, T, VK_LValue, OK_Ordinary), TypoLoc(TypoLoc) {
6586 assert(T->isDependentType() && "TypoExpr given a non-dependent type");
6587 setDependence(ExprDependence::TypeValueInstantiation |
6588 ExprDependence::Error);
6589 }
6590
6593 }
6596 }
6597
6598 SourceLocation getBeginLoc() const LLVM_READONLY { return TypoLoc; }
6599 SourceLocation getEndLoc() const LLVM_READONLY { return TypoLoc; }
6600
6601 static bool classof(const Stmt *T) {
6602 return T->getStmtClass() == TypoExprClass;
6603 }
6604
6605};
6606
6607/// Frontend produces RecoveryExprs on semantic errors that prevent creating
6608/// other well-formed expressions. E.g. when type-checking of a binary operator
6609/// fails, we cannot produce a BinaryOperator expression. Instead, we can choose
6610/// to produce a recovery expression storing left and right operands.
6611///
6612/// RecoveryExpr does not have any semantic meaning in C++, it is only useful to
6613/// preserve expressions in AST that would otherwise be dropped. It captures
6614/// subexpressions of some expression that we could not construct and source
6615/// range covered by the expression.
6616///
6617/// By default, RecoveryExpr uses dependence-bits to take advantage of existing
6618/// machinery to deal with dependent code in C++, e.g. RecoveryExpr is preserved
6619/// in `decltype(<broken-expr>)` as part of the `DependentDecltypeType`. In
6620/// addition to that, clang does not report most errors on dependent
6621/// expressions, so we get rid of bogus errors for free. However, note that
6622/// unlike other dependent expressions, RecoveryExpr can be produced in
6623/// non-template contexts.
6624///
6625/// We will preserve the type in RecoveryExpr when the type is known, e.g.
6626/// preserving the return type for a broken non-overloaded function call, a
6627/// overloaded call where all candidates have the same return type. In this
6628/// case, the expression is not type-dependent (unless the known type is itself
6629/// dependent)
6630///
6631/// One can also reliably suppress all bogus errors on expressions containing
6632/// recovery expressions by examining results of Expr::containsErrors().
6633class RecoveryExpr final : public Expr,
6634 private llvm::TrailingObjects<RecoveryExpr, Expr *> {
6635public:
6636 static RecoveryExpr *Create(ASTContext &Ctx, QualType T,
6637 SourceLocation BeginLoc, SourceLocation EndLoc,
6638 ArrayRef<Expr *> SubExprs);
6639 static RecoveryExpr *CreateEmpty(ASTContext &Ctx, unsigned NumSubExprs);
6640
6642 auto *B = getTrailingObjects<Expr *>();
6643 return llvm::ArrayRef(B, B + NumExprs);
6644 }
6645
6647 return const_cast<RecoveryExpr *>(this)->subExpressions();
6648 }
6649
6651 Stmt **B = reinterpret_cast<Stmt **>(getTrailingObjects<Expr *>());
6652 return child_range(B, B + NumExprs);
6653 }
6654
6655 SourceLocation getBeginLoc() const { return BeginLoc; }
6656 SourceLocation getEndLoc() const { return EndLoc; }
6657
6658 static bool classof(const Stmt *T) {
6659 return T->getStmtClass() == RecoveryExprClass;
6660 }
6661
6662private:
6664 SourceLocation EndLoc, ArrayRef<Expr *> SubExprs);
6665 RecoveryExpr(EmptyShell Empty, unsigned NumSubExprs)
6666 : Expr(RecoveryExprClass, Empty), NumExprs(NumSubExprs) {}
6667
6668 size_t numTrailingObjects(OverloadToken<Stmt *>) const { return NumExprs; }
6669
6670 SourceLocation BeginLoc, EndLoc;
6671 unsigned NumExprs;
6672 friend TrailingObjects;
6673 friend class ASTStmtReader;
6674 friend class ASTStmtWriter;
6675};
6676
6677} // end namespace clang
6678
6679#endif // LLVM_CLANG_AST_EXPR_H
#define V(N, I)
Definition: ASTContext.h:3259
MatchType Type
#define PTR(CLASS)
Definition: AttrVisitor.h:27
#define SM(sm)
Definition: Cuda.cpp:82
static bool CanThrow(Expr *E, ASTContext &Ctx)
Definition: CFG.cpp:2679
clang::CharUnits operator*(clang::CharUnits::QuantityType Scale, const clang::CharUnits &CU)
Definition: CharUnits.h:225
Defines the clang::LangOptions interface.
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
llvm::MachO::Target Target
Definition: MachO.h:40
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)
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:182
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:366
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:4135
AbstractConditionalOperator(StmtClass SC, EmptyShell Empty)
Definition: Expr.h:4145
SourceLocation getColonLoc() const
Definition: Expr.h:4163
Expr * getCond() const
getCond - Return the expression representing the condition for the ?: operator.
Definition: Expr.h:4313
static bool classof(const Stmt *T)
Definition: Expr.h:4165
AbstractConditionalOperator(StmtClass SC, QualType T, ExprValueKind VK, ExprObjectKind OK, SourceLocation qloc, SourceLocation cloc)
Definition: Expr.h:4140
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression representing the value of the expression if the condition eval...
Definition: Expr.h:4319
SourceLocation getQuestionLoc() const
Definition: Expr.h:4162
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression representing the value of the expression if the condition eva...
Definition: Expr.h:4325
AddrLabelExpr - The GNU address of label extension, representing &&label.
Definition: Expr.h:4332
SourceLocation getAmpAmpLoc() const
Definition: Expr.h:4347
static bool classof(const Stmt *T)
Definition: Expr.h:4358
void setLabel(LabelDecl *L)
Definition: Expr.h:4356
child_range children()
Definition: Expr.h:4363
void setLabelLoc(SourceLocation L)
Definition: Expr.h:4350
AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelDecl *L, QualType t)
Definition: Expr.h:4336
void setAmpAmpLoc(SourceLocation L)
Definition: Expr.h:4348
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:4353
AddrLabelExpr(EmptyShell Empty)
Build an empty address of a label expression.
Definition: Expr.h:4344
SourceLocation getLabelLoc() const
Definition: Expr.h:4349
const_child_range children() const
Definition: Expr.h:4366
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:4352
LabelDecl * getLabel() const
Definition: Expr.h:4355
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
Definition: Expr.h:5558
const_child_range children() const
Definition: Expr.h:5578
ArrayInitIndexExpr(QualType T)
Definition: Expr.h:5563
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:5572
static bool classof(const Stmt *S)
Definition: Expr.h:5568
child_range children()
Definition: Expr.h:5575
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:5573
Represents a loop initializing the elements of an array.
Definition: Expr.h:5505
child_range children()
Definition: Expr.h:5543
ArrayInitLoopExpr(QualType T, Expr *CommonInit, Expr *ElementInit)
Definition: Expr.h:5512
const_child_range children() const
Definition: Expr.h:5546
llvm::APInt getArraySize() const
Definition: Expr.h:5527
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:5539
static bool classof(const Stmt *S)
Definition: Expr.h:5532
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:5536
OpaqueValueExpr * getCommonExpr() const
Get the common subexpression shared by all initializations (the source array).
Definition: Expr.h:5520
Expr * getSubExpr() const
Get the initializer to use for each array element.
Definition: Expr.h:5525
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition: Expr.h:2663
ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t, ExprValueKind VK, ExprObjectKind OK, SourceLocation rbracketloc)
Definition: Expr.h:2670
SourceLocation getExprLoc() const LLVM_READONLY
Definition: Expr.h:2718
const Expr * getLHS() const
Definition: Expr.h:2693
const_child_range children() const
Definition: Expr.h:2730
const Expr * getBase() const
Definition: Expr.h:2701
SourceLocation getRBracketLoc() const
Definition: Expr.h:2711
const Expr * getRHS() const
Definition: Expr.h:2697
Expr * getLHS()
An array access can be written A[4] or 4[A] (both are equivalent).
Definition: Expr.h:2692
void setRHS(Expr *E)
Definition: Expr.h:2698
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:2706
const Expr * getIdx() const
Definition: Expr.h:2704
SourceLocation getEndLoc() const
Definition: Expr.h:2709
void setRBracketLoc(SourceLocation L)
Definition: Expr.h:2714
child_range children()
Definition: Expr.h:2727
static bool classof(const Stmt *T)
Definition: Expr.h:2722
void setLHS(Expr *E)
Definition: Expr.h:2694
ArraySubscriptExpr(EmptyShell Shell)
Create an empty array subscript expression.
Definition: Expr.h:2680
AsTypeExpr - Clang builtin function __builtin_astype [OpenCL 6.2.4.2] This AST node provides support ...
Definition: Expr.h:6228
Expr * getSrcExpr() const
getSrcExpr - Return the Expr to be converted.
Definition: Expr.h:6247
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:6256
AsTypeExpr(Expr *SrcExpr, QualType DstType, ExprValueKind VK, ExprObjectKind OK, SourceLocation BuiltinLoc, SourceLocation RParenLoc)
Definition: Expr.h:6238
SourceLocation getBuiltinLoc() const
getBuiltinLoc - Return the location of the __builtin_astype token.
Definition: Expr.h:6250
const_child_range children() const
Definition: Expr.h:6264
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:6255
SourceLocation getRParenLoc() const
getRParenLoc - Return the location of final right parenthesis.
Definition: Expr.h:6253
static bool classof(const Stmt *T)
Definition: Expr.h:6258
child_range children()
Definition: Expr.h:6263
AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, __atomic_load,...
Definition: Expr.h:6431
Expr ** getSubExprs()
Definition: Expr.h:6508
static std::unique_ptr< AtomicScopeModel > getScopeModel(AtomicOp Op)
Get atomic scope model for the atomic op code.
Definition: Expr.h:6556
Expr * getVal2() const
Definition: Expr.h:6483
SourceLocation getRParenLoc() const
Definition: Expr.h:6536
Expr * getOrder() const
Definition: Expr.h:6466
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:6539
QualType getValueType() const
Definition: Expr.cpp:5042
Expr * getScope() const
Definition: Expr.h:6469
bool isCmpXChg() const
Definition: Expr.h:6517
AtomicOp getOp() const
Definition: Expr.h:6495
bool isOpenCL() const
Definition: Expr.h:6530
AtomicExpr(EmptyShell Empty)
Build an empty AtomicExpr.
Definition: Expr.h:6461
Expr * getVal1() const
Definition: Expr.h:6473
child_range children()
Definition: Expr.h:6546
StringRef getOpAsString() const
Definition: Expr.h:6496
const Expr *const * getSubExprs() const
Definition: Expr.h:6509
Expr * getPtr() const
Definition: Expr.h:6463
std::unique_ptr< AtomicScopeModel > getScopeModel() const
Get atomic scope model.
Definition: Expr.h:6572
Expr * getWeak() const
Definition: Expr.h:6489
const_child_range children() const
Definition: Expr.h:6549
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:6538
SourceLocation getBuiltinLoc() const
Definition: Expr.h:6535
Expr * getOrderFail() const
Definition: Expr.h:6479
unsigned getNumSubExprs() const
Definition: Expr.h:6506
static bool classof(const Stmt *T)
Definition: Expr.h:6541
bool isVolatile() const
Definition: Expr.h:6513
static std::unique_ptr< AtomicScopeModel > create(AtomicScopeModelKind K)
Create an atomic scope model by AtomicScopeModelKind.
Definition: SyncScope.h:274
Attr - This represents one attribute.
Definition: Attr.h:42
BinaryConditionalOperator - The GNU extension to the conditional operator which allows the middle ope...
Definition: Expr.h:4235
static bool classof(const Stmt *T)
Definition: Expr.h:4300
BinaryConditionalOperator(Expr *common, OpaqueValueExpr *opaqueValue, Expr *cond, Expr *lhs, Expr *rhs, SourceLocation qloc, SourceLocation cloc, QualType t, ExprValueKind VK, ExprObjectKind OK)
Definition: Expr.h:4248
const_child_range children() const
Definition: Expr.h:4308
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:4293
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression which will be evaluated if the condnition evaluates to false;...
Definition: Expr.h:4289
BinaryConditionalOperator(EmptyShell Empty)
Build an empty conditional operator.
Definition: Expr.h:4264
OpaqueValueExpr * getOpaqueValue() const
getOpaqueValue - Return the opaque value placeholder.
Definition: Expr.h:4273
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:4296
Expr * getCond() const
getCond - Return the condition expression; this is defined in terms of the opaque value.
Definition: Expr.h:4277
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression which will be evaluated if the condition evaluates to true; th...
Definition: Expr.h:4282
Expr * getCommon() const
getCommon - Return the common expression, written to the left of the condition.
Definition: Expr.h:4270
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:3834
static bool isLogicalOp(Opcode Opc)
Definition: Expr.h:3966
void setLHS(Expr *E)
Definition: Expr.h:3884
Expr * getLHS() const
Definition: Expr.h:3883
child_range children()
Definition: Expr.h:4008
BinaryOperator(EmptyShell Empty)
Construct an empty binary operator.
Definition: Expr.h:3863
static bool isRelationalOp(Opcode Opc)
Definition: Expr.h:3927
static OverloadedOperatorKind getOverloadedOperator(Opcode Opc)
Retrieve the overloaded operator kind that corresponds to the given binary opcode.
Definition: Expr.cpp:2167
const FPOptionsOverride * getTrailingFPFeatures() const
Definition: Expr.h:3850
const_child_range children() const
Definition: Expr.h:4011
static bool isComparisonOp(Opcode Opc)
Definition: Expr.h:3933
void setHasStoredFPFeatures(bool B)
Set and fetch the bit that shows whether FPFeatures needs to be allocated in Trailing Storage.
Definition: Expr.h:4017
void setOperatorLoc(SourceLocation L)
Definition: Expr.h:3876
static bool isShiftOp(Opcode Opc)
Definition: Expr.h:3921
bool isComparisonOp() const
Definition: Expr.h:3934
StringRef getOpcodeStr() const
Definition: Expr.h:3899
static bool isCommaOp(Opcode Opc)
Definition: Expr.h:3936
static Opcode getOpForCompoundAssignment(Opcode Opc)
Definition: Expr.h:3980
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:3888
FPOptionsOverride * getTrailingFPFeatures()
Return a pointer to the trailing FPOptions.
Definition: Expr.h:3845
bool isRelationalOp() const
Definition: Expr.h:3928
void setRHS(Expr *E)
Definition: Expr.h:3886
SourceLocation getOperatorLoc() const
Definition: Expr.h:3875
bool isPtrMemOp() const
Definition: Expr.h:3913
bool isFEnvAccessOn(const LangOptions &LO) const
Get the FENV_ACCESS status of this operator.
Definition: Expr.h:4054
bool hasStoredFPFeatures() const
Definition: Expr.h:4018
bool isCompoundAssignmentOp() const
Definition: Expr.h:3977
static Opcode negateComparisonOp(Opcode Opc)
Definition: Expr.h:3939
bool isLogicalOp() const
Definition: Expr.h:3967
bool isMultiplicativeOp() const
Definition: Expr.h:3918
SourceLocation getExprLoc() const
Definition: Expr.h:3874
static Opcode reverseComparisonOp(Opcode Opc)
Definition: Expr.h:3952
static bool isShiftAssignOp(Opcode Opc)
Definition: Expr.h:3988
bool isFPContractableWithinStatement(const LangOptions &LO) const
Get the FP contractability status of this operator.
Definition: Expr.h:4048
bool isShiftOp() const
Definition: Expr.h:3922
Expr * getRHS() const
Definition: Expr.h:3885
static unsigned sizeOfTrailingObjects(bool HasFPFeatures)
Return the size in bytes needed for the trailing objects.
Definition: Expr.h:4071
bool isEqualityOp() const
Definition: Expr.h:3931
BinaryOperator(StmtClass SC, EmptyShell Empty)
Construct an empty BinaryOperator, SC is CompoundAssignOperator.
Definition: Expr.h:4065
bool isBitwiseOp() const
Definition: Expr.h:3925
static BinaryOperator * CreateEmpty(const ASTContext &C, bool hasFPFeatures)
Definition: Expr.cpp:4759
FPOptionsOverride getStoredFPFeatures() const
Get FPFeatures from trailing storage.
Definition: Expr.h:4021
static bool classof(const Stmt *S)
Definition: Expr.h:4002
bool isAdditiveOp() const
Definition: Expr.h:3920
static bool isAdditiveOp(Opcode Opc)
Definition: Expr.h:3919
static bool isPtrMemOp(Opcode Opc)
predicates to categorize the respective opcodes.
Definition: Expr.h:3910
static bool isAssignmentOp(Opcode Opc)
Definition: Expr.h:3969
static bool isCompoundAssignmentOp(Opcode Opc)
Definition: Expr.h:3974
bool isShiftAssignOp() const
Definition: Expr.h:3991
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:3891
FPOptions getFPFeaturesInEffect(const LangOptions &LO) const
Get the FP features status of this operator.
Definition: Expr.h:4033
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:2192
Opcode getOpcode() const
Definition: Expr.h:3878
void setStoredFPFeatures(FPOptionsOverride F)
Set FPFeatures in trailing storage, used only by Serialization.
Definition: Expr.h:4026
FPOptionsOverride getFPFeatures() const
Definition: Expr.h:4040
bool isCommaOp() const
Definition: Expr.h:3937
bool isAssignmentOp() const
Definition: Expr.h:3972
static Opcode getOverloadedOpcode(OverloadedOperatorKind OO)
Retrieve the binary opcode that corresponds to the given overloaded operator.
Definition: Expr.cpp:2129
size_t offsetOfTrailingStorage() const
Definition: Expr.h:4127
static bool isEqualityOp(Opcode Opc)
Definition: Expr.h:3930
void setOpcode(Opcode Opc)
Definition: Expr.h:3881
static bool isBitwiseOp(Opcode Opc)
Definition: Expr.h:3924
static bool isMultiplicativeOp(Opcode Opc)
Definition: Expr.h:3915
BinaryOperatorKind Opcode
Definition: Expr.h:3839
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition: Decl.h:4459
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
Definition: Expr.h:6167
BlockExpr(EmptyShell Empty)
Build an empty block expression.
Definition: Expr.h:6177
SourceLocation getCaretLocation() const
Definition: Expr.cpp:2494
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:6188
BlockDecl * TheBlock
Definition: Expr.h:6169
child_range children()
Definition: Expr.h:6203
BlockDecl * getBlockDecl()
Definition: Expr.h:6180
const Stmt * getBody() const
Definition: Expr.cpp:2497
const_child_range children() const
Definition: Expr.h:6206
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:6191
void setBlockDecl(BlockDecl *BD)
Definition: Expr.h:6181
static bool classof(const Stmt *T)
Definition: Expr.h:6198
const FunctionProtoType * getFunctionType() const
getFunctionType - Return the underlying function type for this block.
Definition: Expr.cpp:2488
BlockExpr(BlockDecl *BD, QualType ty)
Definition: Expr.h:6171
const BlockDecl * getBlockDecl() const
Definition: Expr.h:6179
This class is used for builtin types like 'int'.
Definition: Type.h:2740
static bool isPlaceholderTypeKind(Kind K)
Determines whether the given kind corresponds to a placeholder type.
Definition: Type.h:2816
CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style cast in C++ (C++ [expr....
Definition: Expr.h:3765
SourceLocation getRParenLoc() const
Definition: Expr.h:3800
static CStyleCastExpr * CreateEmpty(const ASTContext &Context, unsigned PathSize, bool HasFPFeatures)
Definition: Expr.cpp:2109
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:3803
void setRParenLoc(SourceLocation L)
Definition: Expr.h:3801
static bool classof(const Stmt *T)
Definition: Expr.h:3808
friend TrailingObjects
Definition: Expr.h:3812
SourceLocation getLParenLoc() const
Definition: Expr.h:3797
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:3804
void setLParenLoc(SourceLocation L)
Definition: Expr.h:3798
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:2819
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
Definition: Expr.h:3010
bool hasStoredFPFeatures() const
Definition: Expr.h:2981
const FPOptionsOverride * getTrailingFPFeatures() const
Definition: Expr.h:2921
static unsigned sizeOfTrailingObjects(unsigned NumPreArgs, unsigned NumArgs, bool HasFPFeatures)
Return the size in bytes needed for the trailing objects.
Definition: Expr.h:2893
static constexpr ADLCallKind NotADL
Definition: Expr.h:2876
bool usesADL() const
Definition: Expr.h:2979
const Stmt * getPreArg(unsigned I) const
Definition: Expr.h:2903
void setRParenLoc(SourceLocation L)
Definition: Expr.h:3130
const_arg_iterator arg_begin() const
Definition: Expr.h:3068
static bool classof(const Stmt *T)
Definition: Expr.h:3147
llvm::iterator_range< const_arg_iterator > const_arg_range
Definition: Expr.h:3056
const Expr *const * getArgs() const
Definition: Expr.h:3004
void setArg(unsigned Arg, Expr *ArgExpr)
setArg - Set the specified argument.
Definition: Expr.h:3023
ConstExprIterator const_arg_iterator
Definition: Expr.h:3054
ExprIterator arg_iterator
Definition: Expr.h:3053
child_range children()
Definition: Expr.h:3153
void setADLCallKind(ADLCallKind V=UsesADL)
Definition: Expr.h:2976
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.cpp:1618
llvm::iterator_range< arg_iterator > arg_range
Definition: Expr.h:3055
const_arg_range arguments() const
Definition: Expr.h:3059
unsigned getBuiltinCallee() const
getBuiltinCallee - If this is a call to a builtin, return the builtin ID of the callee.
Definition: Expr.cpp:1559
arg_iterator arg_begin()
Definition: Expr.h:3063
FPOptionsOverride getStoredFPFeatures() const
Get FPOptionsOverride from trailing storage.
Definition: Expr.h:3083
arg_iterator arg_end()
Definition: Expr.h:3066
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return null.
Definition: Expr.h:2989
static CallExpr * CreateEmpty(const ASTContext &Ctx, unsigned NumArgs, bool HasFPFeatures, EmptyShell Empty)
Create an empty call expression, for deserialization.
Definition: Expr.cpp:1498
bool isCallToStdMove() const
Definition: Expr.cpp:3496
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.cpp:1627
void setPreArg(unsigned I, Stmt *PreArg)
Definition: Expr.h:2907
ADLCallKind getADLCallKind() const
Definition: Expr.h:2973
Expr * getCallee()
Definition: Expr.h:2969
FPOptionsOverride getFPFeatures() const
Definition: Expr.h:3101
void markDependentForPostponedNameLookup()
Used by Sema to implement MSVC-compatible delayed name lookup.
Definition: Expr.h:3141
const Expr * getCallee() const
Definition: Expr.h:2970
ArrayRef< Stmt * > getRawSubExprs()
This method provides fast access to all the subexpressions of a CallExpr without going through the sl...
Definition: Expr.h:3077
const Decl * getCalleeDecl() const
Definition: Expr.h:2984
void computeDependence()
Compute and set dependence bits.
Definition: Expr.h:3029
void setStoredFPFeatures(FPOptionsOverride F)
Set FPOptionsOverride in trailing storage. Used only by Serialization.
Definition: Expr.h:3088
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
Definition: Expr.h:2997
FPOptions getFPFeaturesInEffect(const LangOptions &LO) const
Get the FP features status of this operator.
Definition: Expr.h:3095
Expr ** getArgs()
Retrieve the call arguments.
Definition: Expr.h:3000
const_child_range children() const
Definition: Expr.h:3158
arg_range arguments()
Definition: Expr.h:3058
SourceLocation getRParenLoc() const
Definition: Expr.h:3129
static constexpr ADLCallKind UsesADL
Definition: Expr.h:2877
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:1488
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:3484
const_arg_iterator arg_end() const
Definition: Expr.h:3071
const FunctionDecl * getDirectCallee() const
Definition: Expr.h:2992
Stmt * getPreArg(unsigned I)
Definition: Expr.h:2899
FPOptionsOverride * getTrailingFPFeatures()
Return a pointer to the trailing FPOptions.
Definition: Expr.h:2915
Decl * getCalleeDecl()
Definition: Expr.h:2983
QualType getCallReturnType(const ASTContext &Ctx) const
getCallReturnType - Get the return type of the call expr.
Definition: Expr.cpp:1570
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:1600
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:1564
void setNumArgsUnsafe(unsigned NewNumArgs)
Bluntly set a new number of arguments without doing any checks whatsoever.
Definition: Expr.h:3051
void setCallee(Expr *F)
Definition: Expr.h:2971
unsigned getNumPreArgs() const
Definition: Expr.h:2912
bool hasUnusedResultAttr(const ASTContext &Ctx) const
Returns true if this call expression should warn on unused results.
Definition: Expr.h:3125
void shrinkNumArgs(unsigned NewNumArgs)
Reduce the number of arguments in this call expression.
Definition: Expr.h:3042
const Expr * getArg(unsigned Arg) const
Definition: Expr.h:3014
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition: Expr.h:3489
FPOptionsOverride * getTrailingFPFeatures()
Return a pointer to the trailing FPOptions.
Definition: Expr.cpp:2040
path_iterator path_begin()
Definition: Expr.h:3559
unsigned path_size() const
Definition: Expr.h:3558
NamedDecl * getConversionFunction() const
If this cast applies a user-defined conversion, retrieve the conversion function that it invokes.
Definition: Expr.cpp:1989
const Expr * getSubExprAsWritten() const
Definition: Expr.h:3547
Expr * getSubExprAsWritten()
Retrieve the cast subexpression as it was written in the source code, looking through any implicit ca...
Definition: Expr.cpp:1967
CastKind getCastKind() const
Definition: Expr.h:3533
void setCastKind(CastKind K)
Definition: Expr.h:3534
llvm::iterator_range< path_iterator > path()
Definition: Expr.h:3564
const FieldDecl * getTargetUnionField() const
Definition: Expr.h:3571
CastExpr(StmtClass SC, EmptyShell Empty, unsigned BasePathSize, bool HasFPFeatures)
Construct an empty cast.
Definition: Expr.h:3515
static bool classof(const Stmt *T)
Definition: Expr.h:3616
llvm::iterator_range< path_const_iterator > path() const
Definition: Expr.h:3567
bool hasStoredFPFeatures() const
Definition: Expr.h:3576
bool changesVolatileQualification() const
Return.
Definition: Expr.h:3606
static const FieldDecl * getTargetFieldForToUnionCast(QualType unionType, QualType opType)
Definition: Expr.cpp:2020
FPOptionsOverride getStoredFPFeatures() const
Get FPOptionsOverride from trailing storage.
Definition: Expr.h:3579
CastExpr(StmtClass SC, QualType ty, ExprValueKind VK, const CastKind kind, Expr *op, unsigned BasePathSize, bool HasFPFeatures)
Definition: Expr.h:3502
const Expr * getSubExpr() const
Definition: Expr.h:3540
path_iterator path_end()
Definition: Expr.h:3560
const_child_range children() const
Definition: Expr.h:3623
const FPOptionsOverride * getTrailingFPFeatures() const
Definition: Expr.h:3528
CXXBaseSpecifier ** path_iterator
Definition: Expr.h:3555
path_const_iterator path_end() const
Definition: Expr.h:3562
const char * getCastKindName() const
Definition: Expr.h:3537
child_range children()
Definition: Expr.h:3622
void setSubExpr(Expr *E)
Definition: Expr.h:3541
path_const_iterator path_begin() const
Definition: Expr.h:3561
const CXXBaseSpecifier *const * path_const_iterator
Definition: Expr.h:3556
bool path_empty() const
Definition: Expr.h:3557
FPOptionsOverride getFPFeatures() const
Definition: Expr.h:3592
Expr * getSubExpr()
Definition: Expr.h:3539
FPOptions getFPFeaturesInEffect(const LangOptions &LO) const
Get the FP features status of this operation.
Definition: Expr.h:3586
void setValue(unsigned Val)
Definition: Expr.h:1616
SourceLocation getLocation() const
Definition: Expr.h:1602
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:1608
void setLocation(SourceLocation Location)
Definition: Expr.h:1612
static bool classof(const Stmt *T)
Definition: Expr.h:1618
static void print(unsigned val, CharacterLiteralKind Kind, raw_ostream &OS)
Definition: Expr.cpp:1002
unsigned getValue() const
Definition: Expr.h:1610
child_range children()
Definition: Expr.h:1625
void setKind(CharacterLiteralKind kind)
Definition: Expr.h:1613
const_child_range children() const
Definition: Expr.h:1628
CharacterLiteralKind getKind() const
Definition: Expr.h:1603
CharacterLiteral(EmptyShell Empty)
Construct an empty character literal.
Definition: Expr.h:1600
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:1607
CharacterLiteral(unsigned value, CharacterLiteralKind kind, QualType type, SourceLocation l)
Definition: Expr.h:1591
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
Definition: Expr.h:4552
void setRParenLoc(SourceLocation L)
Definition: Expr.h:4603
void setIsConditionTrue(bool isTrue)
Definition: Expr.h:4580
SourceLocation getBuiltinLoc() const
Definition: Expr.h:4599
Expr * getLHS() const
Definition: Expr.h:4594
Expr * getChosenSubExpr() const
getChosenSubExpr - Return the subexpression chosen according to the condition.
Definition: Expr.h:4588
bool isConditionDependent() const
Definition: Expr.h:4582
void setBuiltinLoc(SourceLocation L)
Definition: Expr.h:4600
bool isConditionTrue() const
isConditionTrue - Return whether the condition is true (i.e.
Definition: Expr.h:4575
ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, QualType t, ExprValueKind VK, ExprObjectKind OK, SourceLocation RP, bool condIsTrue)
Definition: Expr.h:4558
void setRHS(Expr *E)
Definition: Expr.h:4597
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:4606
child_range children()
Definition: Expr.h:4613
Expr * getRHS() const
Definition: Expr.h:4596
SourceLocation getRParenLoc() const
Definition: Expr.h:4602
ChooseExpr(EmptyShell Empty)
Build an empty __builtin_choose_expr.
Definition: Expr.h:4571
const_child_range children() const
Definition: Expr.h:4616
Expr * getCond() const
Definition: Expr.h:4592
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:4605
void setCond(Expr *E)
Definition: Expr.h:4593
void setLHS(Expr *E)
Definition: Expr.h:4595
static bool classof(const Stmt *T)
Definition: Expr.h:4608
CompoundAssignOperator - For compound assignments (e.g.
Definition: Expr.h:4082
void setComputationResultType(QualType T)
Definition: Expr.h:4120
static CompoundAssignOperator * CreateEmpty(const ASTContext &C, bool hasFPFeatures)
Definition: Expr.cpp:4781
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:4092
QualType getComputationLHSType() const
Definition: Expr.h:4116
void setComputationLHSType(QualType T)
Definition: Expr.h:4117
static bool classof(const Stmt *S)
Definition: Expr.h:4122
QualType getComputationResultType() const
Definition: Expr.h:4119
CompoundLiteralExpr - [C99 6.5.2.5].
Definition: Expr.h:3419
void setFileScope(bool FS)
Definition: Expr.h:3447
const_child_range children() const
Definition: Expr.h:3480
void setTypeSourceInfo(TypeSourceInfo *tinfo)
Definition: Expr.h:3455
SourceLocation getLParenLoc() const
Definition: Expr.h:3449
child_range children()
Definition: Expr.h:3479
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:3459
CompoundLiteralExpr(EmptyShell Empty)
Construct an empty compound literal.
Definition: Expr.h:3439
void setLParenLoc(SourceLocation L)
Definition: Expr.h:3450
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:3467
bool isFileScope() const
Definition: Expr.h:3446
static bool classof(const Stmt *T)
Definition: Expr.h:3474
const Expr * getInitializer() const
Definition: Expr.h:3442
TypeSourceInfo * getTypeSourceInfo() const
Definition: Expr.h:3452
void setInitializer(Expr *E)
Definition: Expr.h:3444
CompoundLiteralExpr(SourceLocation lparenloc, TypeSourceInfo *tinfo, QualType T, ExprValueKind VK, Expr *init, bool fileScope)
Definition: Expr.h:3431
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:1604
ConditionalOperator - The ?: ternary operator.
Definition: Expr.h:4173
const_child_range children() const
Definition: Expr.h:4225
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression representing the value of the expression if the condition eva...
Definition: Expr.h:4205
Expr * getLHS() const
Definition: Expr.h:4207
static bool classof(const Stmt *T)
Definition: Expr.h:4217
ConditionalOperator(Expr *cond, SourceLocation QLoc, Expr *lhs, SourceLocation CLoc, Expr *rhs, QualType t, ExprValueKind VK, ExprObjectKind OK)
Definition: Expr.h:4179
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:4210
Expr * getCond() const
getCond - Return the expression representing the condition for the ?: operator.
Definition: Expr.h:4196
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression representing the value of the expression if the condition eval...
Definition: Expr.h:4200
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:4213
child_range children()
Definition: Expr.h:4222
Expr * getRHS() const
Definition: Expr.h:4208
ConditionalOperator(EmptyShell Empty)
Build an empty conditional operator.
Definition: Expr.h:4191
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
Definition: Expr.h:1072
APValue getAPValueResult() const
Definition: Expr.cpp:413
static ConstantResultStorageKind getStorageKind(const APValue &Value)
Definition: Expr.cpp:302
child_range children()
Definition: Expr.h:1153
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:1122
ConstantResultStorageKind getResultStorageKind() const
Definition: Expr.h:1141
void SetResult(APValue Value, const ASTContext &Context)
Definition: Expr.h:1133
APValue::ValueKind getResultAPValueKind() const
Definition: Expr.h:1138
static bool classof(const Stmt *T)
Definition: Expr.h:1129
bool hasAPValueResult() const
Definition: Expr.h:1147
const_child_range children() const
Definition: Expr.h:1154
bool isImmediateInvocation() const
Definition: Expr.h:1144
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:1125
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:4493
SourceLocation getRParenLoc() const
getRParenLoc - Return the location of final right parenthesis.
Definition: Expr.h:4527
const_child_range children() const
Definition: Expr.h:4538
ConvertVectorExpr(Expr *SrcExpr, TypeSourceInfo *TI, QualType DstType, ExprValueKind VK, ExprObjectKind OK, SourceLocation BuiltinLoc, SourceLocation RParenLoc)
Definition: Expr.h:4504
static bool classof(const Stmt *T)
Definition: Expr.h:4532
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:4530
child_range children()
Definition: Expr.h:4537
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:4529
SourceLocation getBuiltinLoc() const
getBuiltinLoc - Return the location of the __builtin_convertvector token.
Definition: Expr.h:4524
TypeSourceInfo * getTypeSourceInfo() const
getTypeSourceInfo - Return the destination type.
Definition: Expr.h:4516
void setTypeSourceInfo(TypeSourceInfo *ti)
Definition: Expr.h:4519
Expr * getSrcExpr() const
getSrcExpr - Return the Expr to be converted.
Definition: Expr.h:4513
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:1446
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1260
unsigned getNumTemplateArgs() const
Retrieve the number of template arguments provided as part of this template-id.
Definition: Expr.h:1429
NamedDecl * getFoundDecl()
Get the NamedDecl through which this reference occurred.
Definition: Expr.h:1365
bool hasExplicitTemplateArgs() const
Determines whether this declaration reference was followed by an explicit template argument list.
Definition: Expr.h:1409
void setIsImmediateEscalating(bool Set)
Definition: Expr.h:1466
const_child_range children() const
Definition: Expr.h:1489
bool refersToEnclosingVariableOrCapture() const
Does this DeclRefExpr refer to an enclosing local or a captured variable?
Definition: Expr.h:1458
void setDecl(ValueDecl *NewD)
Definition: Expr.cpp:544
bool hasTemplateKWAndArgsInfo() const
Definition: Expr.h:1375
const NamedDecl * getFoundDecl() const
Get the NamedDecl through which this reference occurred.
Definition: Expr.h:1371
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:1337
void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const
Copies the template arguments (if present) into the given structure.
Definition: Expr.h:1413
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.cpp:551
DeclarationNameInfo getNameInfo() const
Definition: Expr.h:1332
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:1447
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition: Expr.h:1381
bool isCapturedByCopyInLambdaWithExplicitObjectParameter() const
Definition: Expr.h:1470
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition: Expr.h:1389
bool hasQualifier() const
Determine whether this declaration reference was preceded by a C++ nested-name-specifier,...
Definition: Expr.h:1343
NestedNameSpecifierLoc getQualifierLoc() const
If the name was qualified, retrieves the nested-name-specifier that precedes the name,...
Definition: Expr.h:1347
ValueDecl * getDecl()
Definition: Expr.h:1328
child_range children()
Definition: Expr.h:1485
const ValueDecl * getDecl() const
Definition: Expr.h:1329
const TemplateArgumentLoc * getTemplateArgs() const
Retrieve the template arguments provided as part of this template-id.
Definition: Expr.h:1421
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition: Expr.h:1435
static bool classof(const Stmt *T)
Definition: Expr.h:1480
NonOdrUseReason isNonOdrUse() const
Is this expression a non-odr-use reference, and if so, why?
Definition: Expr.h:1452
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:1441
void setCapturedByCopyInLambdaWithExplicitObjectParameter(bool Set, const ASTContext &Context)
Definition: Expr.h:1474
bool hasTemplateKeyword() const
Determines whether the name in this declaration reference was preceded by the template keyword.
Definition: Expr.h:1405
SourceLocation getLocation() const
Definition: Expr.h:1336
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition: Expr.h:1397
NestedNameSpecifier * getQualifier() const
If the name was qualified, retrieves the nested-name-specifier that precedes the name.
Definition: Expr.h:1355
bool isImmediateEscalating() const
Definition: Expr.h:1462
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:85
AccessSpecifier getAccess() const
Definition: DeclBase.h:512
DeclarationNameLoc - Additional source/type location info for a declaration name.
Represents a single C99 designator.
Definition: Expr.h:5129
unsigned getArrayIndex() const
Definition: Expr.h:5267
SourceRange getSourceRange() const LLVM_READONLY
Definition: Expr.h:5301
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:5291
static Designator CreateArrayRangeDesignator(unsigned Index, SourceLocation LBracketLoc, SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
Creates a GNU array-range designator.
Definition: Expr.h:5256
struct FieldDesignatorInfo FieldInfo
A field designator, e.g., ".x".
Definition: Expr.h:5191
static Designator CreateFieldDesignator(const IdentifierInfo *FieldName, SourceLocation DotLoc, SourceLocation FieldLoc)
Creates a field designator.
Definition: Expr.h:5210
struct ArrayOrRangeDesignatorInfo ArrayOrRangeInfo
An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
Definition: Expr.h:5194
void setFieldDecl(FieldDecl *FD)
Definition: Expr.h:5227
static Designator CreateArrayDesignator(unsigned Index, SourceLocation LBracketLoc, SourceLocation RBracketLoc)
Creates an array designator.
Definition: Expr.h:5246
FieldDecl * getFieldDecl() const
Definition: Expr.h:5220
SourceLocation getFieldLoc() const
Definition: Expr.h:5237
SourceLocation getRBracketLoc() const
Definition: Expr.h:5285
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:5297
const IdentifierInfo * getFieldName() const
Definition: Expr.cpp:4526
SourceLocation getEllipsisLoc() const
Definition: Expr.h:5279
SourceLocation getDotLoc() const
Definition: Expr.h:5232
SourceLocation getLBracketLoc() const
Definition: Expr.h:5273
Represents a C99 designated initializer expression.
Definition: Expr.h:5086
bool isDirectInit() const
Whether this designated initializer should result in direct-initialization of the designated subobjec...
Definition: Expr.h:5346
static DesignatedInitExpr * CreateEmpty(const ASTContext &C, unsigned NumIndexExprs)
Definition: Expr.cpp:4580
Expr * getArrayRangeEnd(const Designator &D) const
Definition: Expr.cpp:4635
void setInit(Expr *init)
Definition: Expr.h:5358
const_child_range children() const
Definition: Expr.h:5397
const Designator * getDesignator(unsigned Idx) const
Definition: Expr.h:5328
Expr * getSubExpr(unsigned Idx) const
Definition: Expr.h:5368
SourceRange getDesignatorsSourceRange() const
Definition: Expr.cpp:4596
llvm::MutableArrayRef< Designator > designators()
Definition: Expr.h:5319
void setSubExpr(unsigned Idx, Expr *E)
Definition: Expr.h:5373
bool usesGNUSyntax() const
Determines whether this designated initializer used the deprecated GNU syntax for designated initiali...
Definition: Expr.h:5350
Expr * getArrayRangeStart(const Designator &D) const
Definition: Expr.cpp:4630
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:4642
void setGNUSyntax(bool GNU)
Definition: Expr.h:5351
child_range children()
Definition: Expr.h:5393
void setEqualOrColonLoc(SourceLocation L)
Definition: Expr.h:5342
Expr * getArrayIndex(const Designator &D) const
Definition: Expr.cpp:4625
Designator * getDesignator(unsigned Idx)
Definition: Expr.h:5327
Expr * getInit() const
Retrieve the initializer value.
Definition: Expr.h:5354
unsigned size() const
Returns the number of designators in this initializer.
Definition: Expr.h:5316
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.cpp:4604
void setDesignators(const ASTContext &C, const Designator *Desigs, unsigned NumDesigs)
Definition: Expr.cpp:4587
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.cpp:4621
SourceLocation getEqualOrColonLoc() const
Retrieve the location of the '=' that precedes the initializer value itself, if present.
Definition: Expr.h:5341
unsigned getNumSubExprs() const
Retrieve the total number of subexpressions in this designated initializer expression,...
Definition: Expr.h:5366
static bool classof(const Stmt *T)
Definition: Expr.h:5388
llvm::ArrayRef< Designator > designators() const
Definition: Expr.h:5323
Expr * getBase() const
Definition: Expr.h:5470
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.cpp:4685
DesignatedInitUpdateExpr(EmptyShell Empty)
Definition: Expr.h:5460
static bool classof(const Stmt *T)
Definition: Expr.h:5466
void setBase(Expr *Base)
Definition: Expr.h:5471
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.cpp:4689
const_child_range children() const
Definition: Expr.h:5483
void setUpdater(Expr *Updater)
Definition: Expr.h:5476
InitListExpr * getUpdater() const
Definition: Expr.h:5473
Designator - A designator in a C99 designated initializer.
Definition: Designator.h:38
An instance of this object exists for each enum constant that is defined.
Definition: Decl.h:3265
ExplicitCastExpr - An explicit cast written in the source code.
Definition: Expr.h:3724
TypeSourceInfo * getTypeInfoAsWritten() const
getTypeInfoAsWritten - Returns the type source info for the type that this expression is casting to.
Definition: Expr.h:3746
ExplicitCastExpr(StmtClass SC, QualType exprTy, ExprValueKind VK, CastKind kind, Expr *op, unsigned PathSize, bool HasFPFeatures, TypeSourceInfo *writtenTy)
Definition: Expr.h:3730
void setTypeInfoAsWritten(TypeSourceInfo *writtenTy)
Definition: Expr.h:3747
static bool classof(const Stmt *T)
Definition: Expr.h:3753
ExplicitCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize, bool HasFPFeatures)
Construct an empty explicit cast.
Definition: Expr.h:3739
QualType getTypeAsWritten() const
getTypeAsWritten - Returns the type that this expression is casting to, as written in the source code...
Definition: Expr.h:3751
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, modifiably 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:4112
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:2509
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:3072
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:1021
static QualType findBoundMemberType(const Expr *expr)
Given an expression of bound-member type, find the type of the member.
Definition: Expr.cpp:3001
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:3221
const Expr * IgnoreParenNoopCasts(const ASTContext &Ctx) const
Definition: Expr.h:958
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:3050
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:2575
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:4119
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:3062
FPOptions getFPFeaturesInEffect(const LangOptions &LO) const
Returns the set of floating point options that apply to this expression.
Definition: Expr.cpp:3832
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:3045
Expr * IgnoreImplicit() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point.
Definition: Expr.cpp:3033
Expr * IgnoreConversionOperatorSingleStep() LLVM_READONLY
Skip conversion operators.
Definition: Expr.cpp:3054
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:4047
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
Definition: Expr.cpp:3041
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:3067
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:3265
FieldDecl * getSourceBitField()
If this expression refers to a bit-field, retrieve the declaration of that bit-field.
Definition: Expr.cpp:4065
NullPointerConstantValueDependence
Enumeration used to describe how isNullPointerConstant() should cope with value-dependent expressions...
Definition: Expr.h:815
@ NPC_ValueDependentIsNull
Specifies that a value-dependent expression of integral or dependent type should be considered a null...
Definition: Expr.h:821
@ NPC_NeverValueDependent
Specifies that the expression should never be value-dependent.
Definition: Expr.h:817
@ NPC_ValueDependentIsNotNull
Specifies that a value-dependent expression should be considered to never be a null pointer constant.
Definition: Expr.h:825
Expr * IgnoreUnlessSpelledInSource()
Skip past any invisible AST nodes which might surround this statement, such as ExprWithCleanups or Im...
Definition: Expr.cpp:3098
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:3029
Decl * getReferencedDeclOfCallee()
Definition: Expr.cpp:1525
Expr * IgnoreImplicitAsWritten() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point.
Definition: Expr.cpp:3037
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:3542
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:852
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:3025
NullPointerConstantKind
Enumeration used to describe the kind of Null pointer constant returned from isNullPointerConstant().
Definition: Expr.h:792
@ NPCK_ZeroExpression
Expression is a Null pointer constant built from a zero integer expression that is not a simple,...
Definition: Expr.h:801
@ NPCK_ZeroLiteral
Expression is a Null pointer constant built from a literal zero.
Definition: Expr.h:804
@ NPCK_CXX11_nullptr
Expression is a C++11 nullptr.
Definition: Expr.h:807
@ NPCK_GNUNull
Expression is a GNU-style __null constant.
Definition: Expr.h:810
@ NPCK_NotNull
Expression is not a Null pointer constant.
Definition: Expr.h:794
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:3179
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:3904
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:2995
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:3273
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:4156
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:3140
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:3892
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:4144
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:2956
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:1010
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:4028
ExtVectorElementExpr - This represents access to specific elements of a vector, and may occur on the ...
Definition: Expr.h:6107
ExtVectorElementExpr(EmptyShell Empty)
Build an empty vector element expression.
Definition: Expr.h:6121
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:6145
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:6148
bool containsDuplicateElements() const
containsDuplicateElements - Return true if any element access is repeated.
Definition: Expr.cpp:4275
void setAccessor(IdentifierInfo *II)
Definition: Expr.h:6129
bool isArrow() const
isArrow - Return true if the base expression is a pointer to vector, return false if the base express...
Definition: Expr.cpp:4264
child_range children()
Definition: Expr.h:6159
void setBase(Expr *E)
Definition: Expr.h:6126
SourceLocation getAccessorLoc() const
Definition: Expr.h:6131
void getEncodedElementAccess(SmallVectorImpl< uint32_t > &Elts) const
getEncodedElementAccess - Encode the elements accessed into an llvm aggregate Constant of ConstantInt...
Definition: Expr.cpp:4296
const Expr * getBase() const
Definition: Expr.h:6124
static bool classof(const Stmt *T)
Definition: Expr.h:6154
void setAccessorLoc(SourceLocation L)
Definition: Expr.h:6132
unsigned getNumElements() const
getNumElements - Get the number of components being selected.
Definition: Expr.cpp:4268
ExtVectorElementExpr(QualType ty, ExprValueKind VK, Expr *base, IdentifierInfo &accessor, SourceLocation loc)
Definition: Expr.h:6112
IdentifierInfo & getAccessor() const
Definition: Expr.h:6128
const_child_range children() const
Definition: Expr.h:6160
Represents difference between two FPOptions values.
Definition: LangOptions.h:870
FPOptions applyOverrides(FPOptions Base)
Definition: LangOptions.h:938
bool requiresTrailingStorage() const
Definition: LangOptions.h:896
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:786
Represents a member of a struct/union/class.
Definition: Decl.h:3025
SourceLocation getLocation() const
Retrieve the location of the literal.
Definition: Expr.h:1562
std::string getValueAsString(unsigned Radix) const
Definition: Expr.cpp:992
unsigned getScale() const
Definition: Expr.h:1566
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:1558
const_child_range children() const
Definition: Expr.h:1579
void setLocation(SourceLocation Location)
Definition: Expr.h:1564
static bool classof(const Stmt *T)
Definition: Expr.h:1569
void setScale(unsigned S)
Definition: Expr.h:1567
static FixedPointLiteral * CreateFromRawInt(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l, unsigned Scale)
Definition: Expr.cpp:979
child_range children()
Definition: Expr.h:1576
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:1559
SourceLocation getLocation() const
Definition: Expr.h:1688
llvm::APFloatBase::Semantics getRawSemantics() const
Get a raw enumeration value representing the floating-point semantics of this literal (32-bit IEEE,...
Definition: Expr.h:1657
child_range children()
Definition: Expr.h:1699
const llvm::fltSemantics & getSemantics() const
Return the APFloat semantics this literal uses.
Definition: Expr.h:1669
void setValue(const ASTContext &C, const llvm::APFloat &Val)
Definition: Expr.h:1650
const_child_range children() const
Definition: Expr.h:1702
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:1691
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:1664
double getValueAsApproximateDouble() const
getValueAsApproximateDouble - This returns the value as an inaccurate double.
Definition: Expr.cpp:1071
llvm::APFloat getValue() const
Definition: Expr.h:1647
void setExact(bool E)
Definition: Expr.h:1681
static bool classof(const Stmt *T)
Definition: Expr.h:1694
void setLocation(SourceLocation L)
Definition: Expr.h:1689
bool isExact() const
Definition: Expr.h:1680
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:1692
void setSemantics(const llvm::fltSemantics &Sem)
Set the APFloat semantics this literal uses.
Definition: Expr.h:1676
FullExpr - Represents a "full-expression" node.
Definition: Expr.h:1039
Expr * getSubExpr()
Definition: Expr.h:1053
FullExpr(StmtClass SC, EmptyShell Empty)
Definition: Expr.h:1049
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:1057
Stmt * SubExpr
Definition: Expr.h:1041
static bool classof(const Stmt *T)
Definition: Expr.h:1059
FullExpr(StmtClass SC, Expr *subexpr)
Definition: Expr.h:1043
const Expr * getSubExpr() const
Definition: Expr.h:1052
Represents a function declaration or definition.
Definition: Decl.h:1959
Represents a prototype with parameter type info, e.g.
Definition: Type.h:4199
GNUNullExpr - Implements the GNU __null extension, which is a name for a null pointer constant that h...
Definition: Expr.h:4627
SourceLocation getTokenLocation() const
getTokenLocation - The location of the __null token.
Definition: Expr.h:4641
static bool classof(const Stmt *T)
Definition: Expr.h:4647
child_range children()
Definition: Expr.h:4652
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:4644
const_child_range children() const
Definition: Expr.h:4655
GNUNullExpr(QualType Ty, SourceLocation Loc)
Definition: Expr.h:4632
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:4645
GNUNullExpr(EmptyShell Empty)
Build an empty GNU __null expression.
Definition: Expr.h:4638
void setTokenLocation(SourceLocation L)
Definition: Expr.h:4642
Represents a C11 generic selection.
Definition: Expr.h:5719
llvm::iterator_range< ConstAssociationIterator > const_association_range
Definition: Expr.h:5956
SourceLocation getBeginLoc() const
Definition: Expr.h:6077
AssociationTy< false > Association
Definition: Expr.h:5950
TypeSourceInfo * getControllingType()
Return the controlling type of this generic selection expression.
Definition: Expr.h:5994
static bool classof(const Stmt *T)
Definition: Expr.h:6080
const Expr * getControllingExpr() const
Definition: Expr.h:5986
unsigned getNumAssocs() const
The number of association expressions.
Definition: Expr.h:5959
const_association_range associations() const
Definition: Expr.h:6061
AssociationIteratorTy< true > ConstAssociationIterator
Definition: Expr.h:5953
SourceLocation getEndLoc() const
Definition: Expr.h:6078
ArrayRef< Expr * > getAssocExprs() const
Definition: Expr.h:6014
bool isExprPredicate() const
Whether this generic selection uses an expression as its controlling argument.
Definition: Expr.h:5975
ConstAssociation getAssociation(unsigned I) const
Definition: Expr.h:6038
association_range associations()
Definition: Expr.h:6050
AssociationTy< true > ConstAssociation
Definition: Expr.h:5951
SourceLocation getGenericLoc() const
Definition: Expr.h:6072
SourceLocation getRParenLoc() const
Definition: Expr.h:6076
unsigned getResultIndex() const
The zero-based index of the result expression's generic association in the generic selection's associ...
Definition: Expr.h:5964
Expr * getResultExpr()
Return the result expression of this controlling expression.
Definition: Expr.h:6003
AssociationIteratorTy< false > AssociationIterator
Definition: Expr.h:5952
SourceLocation getDefaultLoc() const
Definition: Expr.h:6075
llvm::iterator_range< AssociationIterator > association_range
Definition: Expr.h:5954
const Expr * getResultExpr() const
Definition: Expr.h:6008
bool isResultDependent() const
Whether this generic selection is result-dependent.
Definition: Expr.h:5971
child_range children()
Definition: Expr.h:6084
const_child_range children() const
Definition: Expr.h:6089
Association getAssociation(unsigned I)
Return the Ith association expression with its TypeSourceInfo, bundled together in GenericSelectionEx...
Definition: Expr.h:6027
bool isTypePredicate() const
Whether this generic selection uses a type as its controlling argument.
Definition: Expr.h:5977
const TypeSourceInfo * getControllingType() const
Definition: Expr.h:5997
static GenericSelectionExpr * CreateEmpty(const ASTContext &Context, unsigned NumAssocs)
Create an empty generic selection expression for deserialization.
Definition: Expr.cpp:4514
Expr * getControllingExpr()
Return the controlling expression of this generic selection expression.
Definition: Expr.h:5982
ArrayRef< TypeSourceInfo * > getAssocTypeSourceInfos() const
Definition: Expr.h:6019
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:1712
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:1731
ImaginaryLiteral(Expr *val, QualType Ty)
Definition: Expr.h:1715
const Expr * getSubExpr() const
Definition: Expr.h:1724
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:1728
Expr * getSubExpr()
Definition: Expr.h:1725
ImaginaryLiteral(EmptyShell Empty)
Build an empty imaginary literal.
Definition: Expr.h:1721
child_range children()
Definition: Expr.h:1738
static bool classof(const Stmt *T)
Definition: Expr.h:1733
const_child_range children() const
Definition: Expr.h:1739
void setSubExpr(Expr *E)
Definition: Expr.h:1726
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition: Expr.h:3649
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:3696
friend TrailingObjects
Definition: Expr.h:3704
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:3693
static ImplicitCastExpr * CreateEmpty(const ASTContext &Context, unsigned PathSize, bool HasFPFeatures)
Definition: Expr.cpp:2082
ImplicitCastExpr(OnStack_t _, QualType ty, CastKind kind, Expr *op, ExprValueKind VK, FPOptionsOverride FPO)
Definition: Expr.h:3672
bool isPartOfExplicitCast() const
Definition: Expr.h:3680
friend class CastExpr
Definition: Expr.h:3705
static bool classof(const Stmt *T)
Definition: Expr.h:3700
void setIsPartOfExplicitCast(bool PartOfExplicitCast)
Definition: Expr.h:3681
Represents an implicitly-generated value initialization of an object of a given type.
Definition: Expr.h:5594
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:5610
static bool classof(const Stmt *T)
Definition: Expr.h:5605
child_range children()
Definition: Expr.h:5613
ImplicitValueInitExpr(EmptyShell Empty)
Construct an empty implicit value initialization.
Definition: Expr.h:5602
const_child_range children() const
Definition: Expr.h:5616
ImplicitValueInitExpr(QualType ty)
Definition: Expr.h:5596
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:5609
Describes an C or C++ initializer list.
Definition: Expr.h:4841
const_reverse_iterator rend() const
Definition: Expr.h:5058
bool hasArrayFiller() const
Return true if this is an array initializer and its array "filler" has been set.
Definition: Expr.h:4945
void setSyntacticForm(InitListExpr *Init)
Definition: Expr.h:5011
InitExprsTy::reverse_iterator reverse_iterator
Definition: Expr.h:5048
InitExprsTy::const_reverse_iterator const_reverse_iterator
Definition: Expr.h:5049
void markError()
Mark the semantic form of the InitListExpr as error when the semantic analysis fails.
Definition: Expr.h:4907
bool hasDesignatedInit() const
Determine whether this initializer list contains a designated initializer.
Definition: Expr.h:4948
bool isTransparent() const
Is this a transparent initializer list (that is, an InitListExpr that is purely syntactic,...
Definition: Expr.cpp:2418
void resizeInits(const ASTContext &Context, unsigned NumInits)
Specify the number of initializers.
Definition: Expr.cpp:2378
bool isStringLiteralInit() const
Is this an initializer for an array of characters, initialized by a string literal or an @encode?
Definition: Expr.cpp:2404
FieldDecl * getInitializedFieldInUnion()
If this initializes a union, specifies which field in the union to initialize.
Definition: Expr.h:4960
unsigned getNumInits() const
Definition: Expr.h:4871
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.cpp:2452
bool isSemanticForm() const
Definition: Expr.h:5000
void setInit(unsigned Init, Expr *expr)
Definition: Expr.h:4897
const_iterator begin() const
Definition: Expr.h:5052
reverse_iterator rbegin()
Definition: Expr.h:5055
const_reverse_iterator rbegin() const
Definition: Expr.h:5056
InitExprsTy::const_iterator const_iterator
Definition: Expr.h:5047
Expr *const * getInits() const
Retrieve the set of initializers.
Definition: Expr.h:4877
SourceLocation getLBraceLoc() const
Definition: Expr.h:4995
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:2382
void setArrayFiller(Expr *filler)
Definition: Expr.cpp:2394
InitListExpr * getSyntacticForm() const
Definition: Expr.h:5007
static bool classof(const Stmt *T)
Definition: Expr.h:5028
bool hadArrayRangeDesignator() const
Definition: Expr.h:5018
Expr * getArrayFiller()
If this initializer list initializes an array with more elements than there are initializers in the l...
Definition: Expr.h:4935
iterator end()
Definition: Expr.h:5053
bool isExplicit() const
Definition: Expr.h:4978
iterator begin()
Definition: Expr.h:5051
SourceLocation getRBraceLoc() const
Definition: Expr.h:4997
InitListExpr * getSemanticForm() const
Definition: Expr.h:5001
const FieldDecl * getInitializedFieldInUnion() const
Definition: Expr.h:4963
const Expr * getInit(unsigned Init) const
Definition: Expr.h:4887
InitListExpr(EmptyShell Empty)
Build an empty initializer list.
Definition: Expr.h:4868
void setLBraceLoc(SourceLocation Loc)
Definition: Expr.h:4996
const Expr * getArrayFiller() const
Definition: Expr.h:4938
const_child_range children() const
Definition: Expr.h:5039
bool isIdiomaticZeroInitializer(const LangOptions &LangOpts) const
Is this the zero initializer {0} in a language which considers it idiomatic?
Definition: Expr.cpp:2441
reverse_iterator rend()
Definition: Expr.h:5057
const_iterator end() const
Definition: Expr.h:5054
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.cpp:2470
void setInitializedFieldInUnion(FieldDecl *FD)
Definition: Expr.h:4966
bool isSyntacticForm() const
Definition: Expr.h:5004
ArrayRef< Expr * > inits()
Definition: Expr.h:4881
void setRBraceLoc(SourceLocation Loc)
Definition: Expr.h:4998
ArrayRef< Expr * > inits() const
Definition: Expr.h:4883
InitExprsTy::iterator iterator
Definition: Expr.h:5046
void sawArrayRangeDesignator(bool ARD=true)
Definition: Expr.h:5021
Expr ** getInits()
Retrieve the set of initializers.
Definition: Expr.h:4874
Expr * getInit(unsigned Init)
Definition: Expr.h:4892
child_range children()
Definition: Expr.h:5033
void reserveInits(const ASTContext &C, unsigned NumInits)
Reserve space for some number of initializers.
Definition: Expr.cpp:2373
void setLocation(SourceLocation Location)
Definition: Expr.h:1522
child_range children()
Definition: Expr.h:1529
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:1517
static bool classof(const Stmt *T)
Definition: Expr.h:1524
SourceLocation getLocation() const
Retrieve the location of the literal.
Definition: Expr.h:1520
const_child_range children() const
Definition: Expr.h:1532
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:1516
Represents the declaration of a label.
Definition: Decl.h:499
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:418
MatrixSubscriptExpr - Matrix subscript expression for the MatrixType extension.
Definition: Expr.h:2741
void setColumnIdx(Expr *E)
Definition: Expr.h:2781
SourceLocation getEndLoc() const
Definition: Expr.h:2787
void setBase(Expr *E)
Definition: Expr.h:2769
const Expr * getBase() const
Definition: Expr.h:2768
const_child_range children() const
Definition: Expr.h:2808
SourceLocation getRBracketLoc() const
Definition: Expr.h:2793
SourceLocation getExprLoc() const LLVM_READONLY
Definition: Expr.h:2789
MatrixSubscriptExpr(Expr *Base, Expr *RowIdx, Expr *ColumnIdx, QualType T, SourceLocation RBracketLoc)
Definition: Expr.h:2746
const Expr * getRowIdx() const
Definition: Expr.h:2772
void setRowIdx(Expr *E)
Definition: Expr.h:2773
bool isIncomplete() const
Definition: Expr.h:2761
MatrixSubscriptExpr(EmptyShell Shell)
Create an empty matrix subscript expression.
Definition: Expr.h:2758
static bool classof(const Stmt *T)
Definition: Expr.h:2800
child_range children()
Definition: Expr.h:2805
const Expr * getColumnIdx() const
Definition: Expr.h:2776
void setRBracketLoc(SourceLocation L)
Definition: Expr.h:2796
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:2783
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition: Expr.h:3182
static MemberExpr * CreateEmpty(const ASTContext &Context, bool HasQualifier, bool HasFoundDecl, bool HasTemplateKWAndArgsInfo, unsigned NumTemplateArgs)
Definition: Expr.cpp:1762
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition: Expr.h:3350
void setMemberDecl(ValueDecl *D)
Definition: Expr.cpp:1778
SourceLocation getMemberLoc() const
getMemberLoc - Return the location of the "member", in X->F, it is the location of 'F'.
Definition: Expr.h:3367
void setMemberLoc(SourceLocation L)
Definition: Expr.h:3368
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:3388
SourceLocation getOperatorLoc() const
Definition: Expr.h:3360
void setArrow(bool A)
Definition: Expr.h:3363
child_range children()
Definition: Expr.h:3411
static bool classof(const Stmt *T)
Definition: Expr.h:3406
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding the member name, if any.
Definition: Expr.h:3295
NestedNameSpecifierLoc getQualifierLoc() const
If the member name was qualified, retrieves the nested-name-specifier that precedes the member name,...
Definition: Expr.h:3280
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
Definition: Expr.h:3261
const_child_range children() const
Definition: Expr.h:3412
bool hasExplicitTemplateArgs() const
Determines whether the member name was followed by an explicit template argument list.
Definition: Expr.h:3322
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:3402
bool hasQualifier() const
Determines whether this member expression actually had a C++ nested-name-specifier prior to the name ...
Definition: Expr.h:3275
void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const
Copies the template arguments (if present) into the given structure.
Definition: Expr.h:3326
bool isImplicitAccess() const
Determine whether the base of this explicit is implicit.
Definition: Expr.h:3376
const TemplateArgumentLoc * getTemplateArgs() const
Retrieve the template arguments provided as part of this template-id.
Definition: Expr.h:3334
bool performsVirtualDispatch(const LangOptions &LO) const
Returns true if virtual dispatch is performed.
Definition: Expr.h:3396
Expr * getBase() const
Definition: Expr.h:3255
unsigned getNumTemplateArgs() const
Retrieve the number of template arguments provided as part of this template-id.
Definition: Expr.h:3343
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition: Expr.h:3311
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.cpp:1799
void setBase(Expr *E)
Definition: Expr.h:3254
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:3239
NestedNameSpecifier * getQualifier() const
If the member name was qualified, retrieves the nested-name-specifier that precedes the member name.
Definition: Expr.h:3289
bool hadMultipleCandidates() const
Returns true if this member expression refers to a method that was resolved from an overloaded set ha...
Definition: Expr.h:3382
bool hasTemplateKeyword() const
Determines whether the member name was preceded by the template keyword.
Definition: Expr.h:3318
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.cpp:1785
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition: Expr.h:3303
DeclarationNameInfo getMemberNameInfo() const
Retrieve the member declaration name info.
Definition: Expr.h:3355
bool isArrow() const
Definition: Expr.h:3362
SourceLocation getExprLoc() const LLVM_READONLY
Definition: Expr.h:3373
DeclAccessPair getFoundDecl() const
Retrieves the declaration found by lookup.
Definition: Expr.h:3265
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition: Type.h:3089
This represents a decl that may have a name.
Definition: Decl.h:249
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition: Decl.h:315
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:5414
static bool classof(const Stmt *T)
Definition: Expr.h:5424
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:5429
child_range children()
Definition: Expr.h:5432
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:5428
NoInitExpr(QualType ty)
Definition: Expr.h:5416
NoInitExpr(EmptyShell Empty)
Definition: Expr.h:5421
const_child_range children() const
Definition: Expr.h:5435
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:2464
const Expr * getIndexExpr(unsigned Idx) const
Definition: Expr.h:2530
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:2544
void setOperatorLoc(SourceLocation L)
Definition: Expr.h:2498
static OffsetOfExpr * CreateEmpty(const ASTContext &C, unsigned NumComps, unsigned NumExprs)
Definition: Expr.cpp:1650
Expr * getIndexExpr(unsigned Idx)
Definition: Expr.h:2525
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:2545
static bool classof(const Stmt *T)
Definition: Expr.h:2547
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition: Expr.h:2497
const OffsetOfNode & getComponent(unsigned Idx) const
Definition: Expr.h:2511
void setIndexExpr(unsigned Idx, Expr *E)
Definition: Expr.h:2535
TypeSourceInfo * getTypeSourceInfo() const
Definition: Expr.h:2504
void setTypeSourceInfo(TypeSourceInfo *tsi)
Definition: Expr.h:2507
const_child_range children() const
Definition: Expr.h:2556
child_range children()
Definition: Expr.h:2552
void setComponent(unsigned Idx, OffsetOfNode ON)
Definition: Expr.h:2516
unsigned getNumExpressions() const
Definition: Expr.h:2540
SourceLocation getRParenLoc() const
Return the location of the right parentheses.
Definition: Expr.h:2501
void setRParenLoc(SourceLocation R)
Definition: Expr.h:2502
friend TrailingObjects
Definition: Expr.h:2561
unsigned getNumComponents() const
Definition: Expr.h:2521
Helper class for OffsetOfExpr.
Definition: Expr.h:2358
OffsetOfNode(SourceLocation DotLoc, IdentifierInfo *Name, SourceLocation NameLoc)
Create an offsetof node that refers to an identifier.
Definition: Expr.h:2402
unsigned getArrayExprIndex() const
For an array element node, returns the index into the array of expressions.
Definition: Expr.h:2416
FieldDecl * getField() const
For a field offsetof node, returns the field.
Definition: Expr.h:2422
OffsetOfNode(const CXXBaseSpecifier *Base)
Create an offsetof node that refers into a C++ base class.
Definition: Expr.h:2408
OffsetOfNode(SourceLocation LBracketLoc, unsigned Index, SourceLocation RBracketLoc)
Create an offsetof node that refers to an array element.
Definition: Expr.h:2392
IdentifierInfo * getFieldName() const
For a field or identifier offsetof node, returns the name of the field.
Definition: Expr.cpp:1672
SourceRange getSourceRange() const LLVM_READONLY
Retrieve the source range that covers this offsetof node.
Definition: Expr.h:2443
Kind
The kind of offsetof node we have.
Definition: Expr.h:2361
@ Array
An index into an array.
Definition: Expr.h:2363
@ Identifier
A field in a dependent type, known only by its name.
Definition: Expr.h:2367
@ Field
A field.
Definition: Expr.h:2365
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:2444
Kind getKind() const
Determine what kind of offsetof node this is.
Definition: Expr.h:2412
OffsetOfNode(SourceLocation DotLoc, FieldDecl *Field, SourceLocation NameLoc)
Create an offsetof node that refers to a field.
Definition: Expr.h:2397
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:2445
CXXBaseSpecifier * getBase() const
For a base class node, returns the base specifier.
Definition: Expr.h:2432
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition: Expr.h:1168
static const OpaqueValueExpr * findInCopyConstruct(const Expr *expr)
Given an expression which invokes a copy constructor — i.e.
Definition: Expr.cpp:4836
OpaqueValueExpr(EmptyShell Empty)
Definition: Expr.h:1186
OpaqueValueExpr(SourceLocation Loc, QualType T, ExprValueKind VK, ExprObjectKind OK=OK_Ordinary, Expr *SourceExpr=nullptr)
Definition: Expr.h:1173
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:1192
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:1195
static bool classof(const Stmt *T)
Definition: Expr.h:1228
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Definition: Expr.h:1218
SourceLocation getLocation() const
Retrieve the location of this expression.
Definition: Expr.h:1190
const_child_range children() const
Definition: Expr.h:1206
child_range children()
Definition: Expr.h:1202
SourceLocation getExprLoc() const LLVM_READONLY
Definition: Expr.h:1198
bool isUnique() const
Definition: Expr.h:1226
void setIsUnique(bool V)
Definition: Expr.h:1220
ParenExpr - This represents a parethesized expression, e.g.
Definition: Expr.h:2129
ParenExpr(SourceLocation l, SourceLocation r, Expr *val)
Definition: Expr.h:2133
SourceLocation getLParen() const
Get the location of the left parentheses '('.
Definition: Expr.h:2152
Expr * getSubExpr()
Definition: Expr.h:2145
static bool classof(const Stmt *T)
Definition: Expr.h:2159
ParenExpr(EmptyShell Empty)
Construct an empty parenthesized expression.
Definition: Expr.h:2141
void setLParen(SourceLocation Loc)
Definition: Expr.h:2153
const_child_range children() const
Definition: Expr.h:2165
void setRParen(SourceLocation Loc)
Definition: Expr.h:2157
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:2148
child_range children()
Definition: Expr.h:2164
const Expr * getSubExpr() const
Definition: Expr.h:2144
SourceLocation getRParen() const
Get the location of the right parentheses ')'.
Definition: Expr.h:2156
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:2149
void setSubExpr(Expr *E)
Definition: Expr.h:2146
static ParenListExpr * CreateEmpty(const ASTContext &Ctx, unsigned NumExprs)
Create an empty paren list.
Definition: Expr.cpp:4718
ArrayRef< Expr * > exprs()
Definition: Expr.h:5662
SourceLocation getBeginLoc() const
Definition: Expr.h:5666
Expr * getExpr(unsigned Init)
Definition: Expr.h:5649
const Expr * getExpr(unsigned Init) const
Definition: Expr.h:5654
const_child_range children() const
Definition: Expr.h:5678
Expr ** getExprs()
Definition: Expr.h:5658
SourceLocation getEndLoc() const
Definition: Expr.h:5667
unsigned getNumExprs() const
Return the number of expressions in this paren list.
Definition: Expr.h:5647
SourceLocation getLParenLoc() const
Definition: Expr.h:5664
SourceLocation getRParenLoc() const
Definition: Expr.h:5665
static bool classof(const Stmt *T)
Definition: Expr.h:5669
child_range children()
Definition: Expr.h:5674
[C99 6.4.2.2] - A predefined identifier such as func.
Definition: Expr.h:1986
SourceLocation getBeginLoc() const
Definition: Expr.h:2050
static std::string ComputeName(PredefinedIdentKind IK, const Decl *CurrentDecl)
Definition: Expr.cpp:678
void setLocation(SourceLocation L)
Definition: Expr.h:2028
static bool classof(const Stmt *T)
Definition: Expr.h:2053
SourceLocation getEndLoc() const
Definition: Expr.h:2051
const StringLiteral * getFunctionName() const
Definition: Expr.h:2036
StringRef getIdentKindName() const
Definition: Expr.h:2043
static PredefinedExpr * CreateEmpty(const ASTContext &Ctx, bool HasFunctionName)
Create an empty PredefinedExpr.
Definition: Expr.cpp:647
bool isTransparent() const
Definition: Expr.h:2025
const_child_range children() const
Definition: Expr.h:2063
child_range children()
Definition: Expr.h:2058
PredefinedIdentKind getIdentKind() const
Definition: Expr.h:2021
SourceLocation getLocation() const
Definition: Expr.h:2027
StringLiteral * getFunctionName()
Definition: Expr.h:2030
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Definition: Expr.h:6299
friend TrailingObjects
Definition: Expr.h:6420
const Expr * getResultExpr() const
Definition: Expr.h:6357
const_semantics_iterator semantics_begin() const
Definition: Expr.h:6368
semantics_iterator semantics_end()
Definition: Expr.h:6371
SourceLocation getExprLoc() const LLVM_READONLY
Definition: Expr.h:6393
unsigned getResultExprIndex() const
Return the index of the result-bearing expression into the semantics expressions, or PseudoObjectExpr...
Definition: Expr.h:6346
semantics_iterator semantics_begin()
Definition: Expr.h:6365
const Expr *const * const_semantics_iterator
Definition: Expr.h:6364
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:6397
Expr *const * semantics_iterator
Definition: Expr.h:6363
const_semantics_iterator semantics_end() const
Definition: Expr.h:6374
const Expr * getSyntacticForm() const
Definition: Expr.h:6342
static bool classof(const Stmt *T)
Definition: Expr.h:6416
const Expr * getSemanticExpr(unsigned index) const
Definition: Expr.h:6389
Expr * getResultExpr()
Return the result-bearing expression, or null if there is none.
Definition: Expr.h:6352
child_range children()
Definition: Expr.h:6404
ArrayRef< Expr * > semantics()
Definition: Expr.h:6378
ArrayRef< const Expr * > semantics() const
Definition: Expr.h:6381
unsigned getNumSemanticExprs() const
Definition: Expr.h:6361
Expr * getSemanticExpr(unsigned index)
Definition: Expr.h:6385
Expr * getSyntacticForm()
Return the syntactic form of this expression, i.e.
Definition: Expr.h:6341
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:6400
const_child_range children() const
Definition: Expr.h:6410
A (possibly-)qualified type.
Definition: Type.h:737
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
Definition: Type.h:6985
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:804
Represents a struct/union/class.
Definition: Decl.h:4133
Frontend produces RecoveryExprs on semantic errors that prevent creating other well-formed expression...
Definition: Expr.h:6634
ArrayRef< const Expr * > subExpressions() const
Definition: Expr.h:6646
ArrayRef< Expr * > subExpressions()
Definition: Expr.h:6641
SourceLocation getEndLoc() const
Definition: Expr.h:6656
static bool classof(const Stmt *T)
Definition: Expr.h:6658
child_range children()
Definition: Expr.h:6650
SourceLocation getBeginLoc() const
Definition: Expr.h:6655
static RecoveryExpr * CreateEmpty(ASTContext &Ctx, unsigned NumSubExprs)
Definition: Expr.cpp:5099
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:3009
static bool classof(const Stmt *T)
Definition: Expr.h:2106
const_child_range children() const
Definition: Expr.h:2115
SourceLocation getLocation() const
Definition: Expr.h:2102
const TypeSourceInfo * getTypeSourceInfo() const
Definition: Expr.h:2092
SourceLocation getLParenLocation() const
Definition: Expr.h:2103
TypeSourceInfo * getTypeSourceInfo()
Definition: Expr.h:2090
std::string ComputeName(ASTContext &Context) const
Definition: Expr.cpp:592
SourceLocation getBeginLoc() const
Definition: Expr.h:2100
SourceLocation getRParenLocation() const
Definition: Expr.h:2104
SourceLocation getEndLoc() const
Definition: Expr.h:2101
static SYCLUniqueStableNameExpr * CreateEmpty(const ASTContext &Ctx)
Definition: Expr.cpp:587
ShuffleVectorExpr - clang-specific builtin-in function __builtin_shufflevector.
Definition: Expr.h:4425
ShuffleVectorExpr(EmptyShell Empty)
Build an empty vector-shuffle expression.
Definition: Expr.h:4440
void setExprs(const ASTContext &C, ArrayRef< Expr * > Exprs)
Definition: Expr.cpp:4340
llvm::APSInt getShuffleMaskIdx(const ASTContext &Ctx, unsigned N) const
Definition: Expr.h:4476
Expr ** getSubExprs()
Retrieve the array of expressions.
Definition: Expr.h:4462
const_child_range children() const
Definition: Expr.h:4485
child_range children()
Definition: Expr.h:4482
SourceLocation getBuiltinLoc() const
Definition: Expr.h:4443
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:4450
void setRParenLoc(SourceLocation L)
Definition: Expr.h:4447
const Expr * getExpr(unsigned Index) const
Definition: Expr.h:4469
unsigned getNumSubExprs() const
getNumSubExprs - Return the size of the SubExprs array.
Definition: Expr.h:4459
static bool classof(const Stmt *T)
Definition: Expr.h:4452
SourceLocation getRParenLoc() const
Definition: Expr.h:4446
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:4449
Expr * getExpr(unsigned Index)
getExpr - Return the Expr at the specified index.
Definition: Expr.h:4465
void setBuiltinLoc(SourceLocation L)
Definition: Expr.h:4444
Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(), __builtin_FUNCTION(),...
Definition: Expr.h:4721
SourceLocExpr(EmptyShell Empty)
Build an empty call expression.
Definition: Expr.h:4731
SourceLocation getBeginLoc() const
Definition: Expr.h:4766
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:2259
bool isIntType() const
Definition: Expr.h:4745
static bool classof(const Stmt *T)
Definition: Expr.h:4777
child_range children()
Definition: Expr.h:4769
SourceLocation getLocation() const
Definition: Expr.h:4765
const DeclContext * getParentContext() const
If the SourceLocExpr has been resolved return the subexpression representing the resolved value.
Definition: Expr.h:4762
SourceLocation getEndLoc() const
Definition: Expr.h:4767
DeclContext * getParentContext()
Definition: Expr.h:4763
StringRef getBuiltinStr() const
Return a string representing the name of the specific builtin function.
Definition: Expr.cpp:2239
const_child_range children() const
Definition: Expr.h:4773
static bool MayBeDependent(SourceLocIdentKind Kind)
Definition: Expr.h:4781
SourceLocIdentKind getIdentKind() const
Definition: Expr.h:4741
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:4377
const CompoundStmt * getSubStmt() const
Definition: Expr.h:4395
void setRParenLoc(SourceLocation L)
Definition: Expr.h:4404
const_child_range children() const
Definition: Expr.h:4414
child_range children()
Definition: Expr.h:4413
CompoundStmt * getSubStmt()
Definition: Expr.h:4394
static bool classof(const Stmt *T)
Definition: Expr.h:4408
StmtExpr(CompoundStmt *SubStmt, QualType T, SourceLocation LParenLoc, SourceLocation RParenLoc, unsigned TemplateDepth)
Definition: Expr.h:4381
StmtExpr(EmptyShell Empty)
Build an empty statement expression.
Definition: Expr.h:4392
void setLParenLoc(SourceLocation L)
Definition: Expr.h:4402
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:4399
unsigned getTemplateDepth() const
Definition: Expr.h:4406
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:4398
SourceLocation getRParenLoc() const
Definition: Expr.h:4403
void setSubStmt(CompoundStmt *S)
Definition: Expr.h:4396
SourceLocation getLParenLoc() const
Definition: Expr.h:4401
Stmt - This represents one statement.
Definition: Stmt.h:84
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Stmt.cpp:350
StmtClass
Definition: Stmt.h:86
UnaryExprOrTypeTraitExprBitfields UnaryExprOrTypeTraitExprBits
Definition: Stmt.h:1223
GenericSelectionExprBitfields GenericSelectionExprBits
Definition: Stmt.h:1231
InitListExprBitfields InitListExprBits
Definition: Stmt.h:1229
ParenListExprBitfields ParenListExprBits
Definition: Stmt.h:1230
ArrayOrMatrixSubscriptExprBitfields ArrayOrMatrixSubscriptExprBits
Definition: Stmt.h:1224
StmtIterator child_iterator
Child Iterators: All subclasses must implement 'children' to permit easy iteration over the substatem...
Definition: Stmt.h:1442
CallExprBitfields CallExprBits
Definition: Stmt.h:1225
FloatingLiteralBitfields FloatingLiteralBits
Definition: Stmt.h:1219
child_iterator child_begin()
Definition: Stmt.h:1455
StmtClass getStmtClass() const
Definition: Stmt.h:1356
CharacterLiteralBitfields CharacterLiteralBits
Definition: Stmt.h:1221
UnaryOperatorBitfields UnaryOperatorBits
Definition: Stmt.h:1222
SourceLocExprBitfields SourceLocExprBits
Definition: Stmt.h:1233
ConstantExprBitfields ConstantExprBits
Definition: Stmt.h:1216
llvm::iterator_range< child_iterator > child_range
Definition: Stmt.h:1445
StmtExprBitfields StmtExprBits
Definition: Stmt.h:1236
StringLiteralBitfields StringLiteralBits
Definition: Stmt.h:1220
OpaqueValueExprBitfields OpaqueValueExprBits
Definition: Stmt.h:1271
CastExprBitfields CastExprBits
Definition: Stmt.h:1227
MemberExprBitfields MemberExprBits
Definition: Stmt.h:1226
DeclRefExprBitfields DeclRefExprBits
Definition: Stmt.h:1218
ConstStmtIterator const_child_iterator
Definition: Stmt.h:1443
PredefinedExprBitfields PredefinedExprBits
Definition: Stmt.h:1217
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.cpp:338
BinaryOperatorBitfields BinaryOperatorBits
Definition: Stmt.h:1228
PseudoObjectExprBitfields PseudoObjectExprBits
Definition: Stmt.h:1232
ExprBitfields ExprBits
Definition: Stmt.h:1215
llvm::iterator_range< const_child_iterator > const_child_range
Definition: Stmt.h:1446
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1773
const_child_range children() const
Definition: Expr.h:1965
SourceLocation getStrTokenLoc(unsigned TokNum) const
Get one of the string literal token.
Definition: Expr.h:1926
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:1954
bool containsNonAscii() const
Definition: Expr.h:1905
bool isUTF8() const
Definition: Expr.h:1899
bool isWide() const
Definition: Expr.h:1898
bool containsNonAsciiOrNull() const
Definition: Expr.h:1912
bool isPascal() const
Definition: Expr.h:1903
unsigned getLength() const
Definition: Expr.h:1890
static bool classof(const Stmt *T)
Definition: Expr.h:1957
tokloc_iterator tokloc_begin() const
Definition: Expr.h:1946
tokloc_iterator tokloc_end() const
Definition: Expr.h:1950
child_range children()
Definition: Expr.h:1962
StringLiteralKind getKind() const
Definition: Expr.h:1893
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:1309
StringRef getBytes() const
Allow access to clients that need the byte representation, such as ASTWriterStmt::VisitStringLiteral(...
Definition: Expr.h:1858
uint32_t getCodeUnit(size_t i) const
Definition: Expr.h:1865
bool isUnevaluated() const
Definition: Expr.h:1902
void outputString(raw_ostream &OS) const
Definition: Expr.cpp:1193
bool isUTF32() const
Definition: Expr.h:1901
int64_t getCodeUnitS(size_t I, uint64_t BitWidth) const
Definition: Expr.h:1879
unsigned getByteLength() const
Definition: Expr.h:1889
StringRef getString() const
Definition: Expr.h:1850
bool isUTF16() const
Definition: Expr.h:1900
static StringLiteral * CreateEmpty(const ASTContext &Ctx, unsigned NumConcatenated, unsigned Length, unsigned CharByteWidth)
Construct an empty string literal.
Definition: Expr.cpp:1182
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:1955
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:1839
const SourceLocation * tokloc_iterator
Definition: Expr.h:1944
unsigned getNumConcatenated() const
getNumConcatenated - Get the number of string literal tokens that were concatenated in translation ph...
Definition: Expr.h:1921
bool isOrdinary() const
Definition: Expr.h:1897
unsigned getCharByteWidth() const
Definition: Expr.h:1891
Exposes information about the current target.
Definition: TargetInfo.h:213
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:6873
QualType getType() const
Return the type wrapped by this type source info.
Definition: Type.h:6884
The base class of the type hierarchy.
Definition: Type.h:1606
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:7419
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
Definition: Type.h:7479
bool isReferenceType() const
Definition: Type.h:7166
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:651
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:2420
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:7657
TypoExpr - Internal placeholder for expressions where typo correction still needs to be performed and...
Definition: Expr.h:6579
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:6599
child_range children()
Definition: Expr.h:6591
const_child_range children() const
Definition: Expr.h:6594
static bool classof(const Stmt *T)
Definition: Expr.h:6601
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:6598
TypoExpr(QualType T, SourceLocation TypoLoc)
Definition: Expr.h:6584
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
Definition: Expr.h:2567
SourceLocation getRParenLoc() const
Definition: Expr.h:2643
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:2647
void setKind(UnaryExprOrTypeTrait K)
Definition: Expr.h:2602
QualType getArgumentType() const
Definition: Expr.h:2610
void setOperatorLoc(SourceLocation L)
Definition: Expr.h:2641
SourceLocation getOperatorLoc() const
Definition: Expr.h:2640
const Expr * getArgumentExpr() const
Definition: Expr.h:2621
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:2646
TypeSourceInfo * Ty
Definition: Expr.h:2569
void setRParenLoc(SourceLocation L)
Definition: Expr.h:2644
static bool classof(const Stmt *T)
Definition: Expr.h:2649
QualType getTypeOfArgument() const
Gets the argument type, or the type of the argument expression, whichever is appropriate.
Definition: Expr.h:2636
bool isArgumentType() const
Definition: Expr.h:2609
void setArgument(Expr *E)
Definition: Expr.h:2625
UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, TypeSourceInfo *TInfo, QualType resultType, SourceLocation op, SourceLocation rp)
Definition: Expr.h:2575
TypeSourceInfo * getArgumentTypeInfo() const
Definition: Expr.h:2613
UnaryExprOrTypeTraitExpr(EmptyShell Empty)
Construct an empty sizeof/alignof expression.
Definition: Expr.h:2596
UnaryExprOrTypeTrait getKind() const
Definition: Expr.h:2599
void setArgument(TypeSourceInfo *TInfo)
Definition: Expr.h:2629
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition: Expr.h:2182
static bool classof(const Stmt *T)
Definition: Expr.h:2312
static bool isPostfix(Opcode Op)
isPostfix - Return true if this is a postfix operation, like x++.
Definition: Expr.h:2256
bool isDecrementOp() const
Definition: Expr.h:2278
void setSubExpr(Expr *E)
Definition: Expr.h:2228
SourceLocation getExprLoc() const
Definition: Expr.h:2310
bool isPostfix() const
Definition: Expr.h:2266
bool isFEnvAccessOn(const LangOptions &LO) const
Get the FENV_ACCESS status of this operator.
Definition: Expr.h:2251
bool isPrefix() const
Definition: Expr.h:2265
void setOperatorLoc(SourceLocation L)
Definition: Expr.h:2232
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition: Expr.h:2231
Expr * getSubExpr() const
Definition: Expr.h:2227
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:2307
bool isArithmeticOp() const
Definition: Expr.h:2290
void setCanOverflow(bool C)
Definition: Expr.h:2241
UnaryOperator(bool HasFPFeatures, EmptyShell Empty)
Build an empty unary operator.
Definition: Expr.h:2208
Opcode getOpcode() const
Definition: Expr.h:2222
bool hasStoredFPFeatures() const
Is FPFeatures in Trailing Storage?
Definition: Expr.h:2323
static OverloadedOperatorKind getOverloadedOperator(Opcode Opc)
Retrieve the overloaded operator kind that corresponds to the given unary opcode.
Definition: Expr.cpp:1409
void setOpcode(Opcode Opc)
Definition: Expr.h:2225
child_range children()
Definition: Expr.h:2317
static bool isIncrementOp(Opcode Op)
Definition: Expr.h:2268
static bool isIncrementDecrementOp(Opcode Op)
Definition: Expr.h:2282
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:2304
static bool isDecrementOp(Opcode Op)
Definition: Expr.h:2275
FPOptionsOverride getStoredFPFeatures() const
Get FPFeatures from trailing storage.
Definition: Expr.h:2326
bool isFPContractableWithinStatement(const LangOptions &LO) const
Get the FP contractability status of this operator.
Definition: Expr.h:2245
static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix)
Retrieve the unary opcode that corresponds to the given overloaded operator.
Definition: Expr.cpp:1394
FPOptions getFPFeaturesInEffect(const LangOptions &LO) const
Get the FP features status of this operator.
Definition: Expr.h:2337
void setStoredFPFeatures(FPOptionsOverride F)
Set FPFeatures in trailing storage, used by Serialization & ASTImporter.
Definition: Expr.h:2332
UnaryOperatorKind Opcode
Definition: Expr.h:2200
FPOptionsOverride getFPOptionsOverride() const
Definition: Expr.h:2342
static UnaryOperator * CreateEmpty(const ASTContext &C, bool hasFPFeatures)
Definition: Expr.cpp:4803
static bool isPrefix(Opcode Op)
isPrefix - Return true if this is a prefix operation, like –x.
Definition: Expr.h:2261
friend TrailingObjects
Definition: Expr.h:2348
static StringRef getOpcodeStr(Opcode Op)
getOpcodeStr - Turn an Opcode enum value into the punctuation char it corresponds to,...
Definition: Expr.cpp:1385
static bool isArithmeticOp(Opcode Op)
Definition: Expr.h:2287
bool isIncrementDecrementOp() const
Definition: Expr.h:2283
bool isIncrementOp() const
Definition: Expr.h:2271
const_child_range children() const
Definition: Expr.h:2318
bool canOverflow() const
Returns true if the unary operator can cause an overflow.
Definition: Expr.h:2240
Represents a call to the builtin function __builtin_va_arg.
Definition: Expr.h:4661
VAArgExpr(SourceLocation BLoc, Expr *e, TypeSourceInfo *TInfo, SourceLocation RPLoc, QualType t, bool IsMS)
Definition: Expr.h:4666
void setRParenLoc(SourceLocation L)
Definition: Expr.h:4692
TypeSourceInfo * getWrittenTypeInfo() const
Definition: Expr.h:4685
child_range children()
Definition: Expr.h:4702
SourceLocation getBuiltinLoc() const
Definition: Expr.h:4688
SourceLocation getRParenLoc() const
Definition: Expr.h:4691
VAArgExpr(EmptyShell Empty)
Create an empty __builtin_va_arg expression.
Definition: Expr.h:4674
Expr * getSubExpr()
Definition: Expr.h:4678
bool isMicrosoftABI() const
Returns whether this is really a Win64 ABI va_arg expression.
Definition: Expr.h:4682
void setIsMicrosoftABI(bool IsMS)
Definition: Expr.h:4683
void setSubExpr(Expr *E)
Definition: Expr.h:4679
static bool classof(const Stmt *T)
Definition: Expr.h:4697
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:4694
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:4695
void setBuiltinLoc(SourceLocation L)
Definition: Expr.h:4689
void setWrittenTypeInfo(TypeSourceInfo *TI)
Definition: Expr.h:4686
const_child_range children() const
Definition: Expr.h:4703
const Expr * getSubExpr() const
Definition: Expr.h:4677
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:706
Represents a statement that could possibly have a value and type.
Definition: Stmt.h:2010
Represents a variable declaration or definition.
Definition: Decl.h:918
@ 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:928
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:42
@ Create
'copyin' clause, allowed on Compute and Combined constructs, plus 'data', 'enter data',...
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:1066
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:146
@ OK_VectorComponent
A vector component is an element or range of elements on a vector.
Definition: Specifiers.h:154
@ OK_Ordinary
An ordinary object is located at an address in memory.
Definition: Specifiers.h:148
@ OK_BitField
A bitfield object is a bitfield on a C or C++ record.
Definition: Specifiers.h:151
@ OK_MatrixComponent
A matrix component is a single element of a matrix.
Definition: Specifiers.h:166
BinaryOperatorKind
ExprDependence computeDependence(FullExpr *E)
bool operator==(const CallGraphNode::CallRecord &LHS, const CallGraphNode::CallRecord &RHS)
Definition: CallGraph.h:207
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:129
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
Definition: Specifiers.h:132
@ VK_XValue
An x-value expression is a reference to an object with independent storage but which can be "moved",...
Definition: Specifiers.h:141
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
Definition: Specifiers.h:136
SmallVector< CXXBaseSpecifier *, 4 > CXXCastPath
A simple array of base specifiers.
Definition: Expr.h:62
StringLiteralKind
Definition: Expr.h:1744
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:4708
@ Other
Other implicit parameter.
PredefinedIdentKind
Definition: Expr.h:1970
@ PrettyFunctionNoVirtual
The same as PrettyFunction, except that the 'virtual' keyword is omitted for virtual member functions...
CharacterLiteralKind
Definition: Expr.h:1584
NonOdrUseReason
The reason why a DeclRefExpr does not constitute an odr-use.
Definition: Specifiers.h:170
@ NOUR_None
This is an odr-use.
Definition: Specifiers.h:172
unsigned long uint64_t
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
#define true
Definition: stdbool.h:21
#define false
Definition: stdbool.h:22
Copy initialization expr of a __block variable and a boolean flag that indicates whether the expressi...
Definition: Expr.h:6213
BlockVarCopyInit(Expr *CopyExpr, bool CanThrow)
Definition: Expr.h:6215
Expr * getCopyExpr() const
Definition: Expr.h:6220
llvm::PointerIntPair< Expr *, 1, bool > ExprAndFlag
Definition: Expr.h:6222
bool canThrow() const
Definition: Expr.h:6221
void setExprAndFlag(Expr *CopyExpr, bool CanThrow)
Definition: Expr.h:6217
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
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
Extra data stored in some MemberExpr objects.
Definition: Expr.h:3166
DeclAccessPair FoundDecl
The DeclAccessPair through which the MemberDecl was found due to name qualifiers.
Definition: Expr.h:3173
NestedNameSpecifierLoc QualifierLoc
The nested-name-specifier that qualifies the name, including source-location information.
Definition: Expr.h:3169
Iterator for iterating over Stmt * arrays that contain only T *.
Definition: Stmt.h:1314
A placeholder type used to construct an empty shell of a type, that will be filled in later (e....
Definition: Stmt.h:1296
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
SubobjectAdjustment(const CastExpr *BasePath, const CXXRecordDecl *DerivedClass)
Definition: Expr.h:89
struct DTB DerivedToBase
Definition: Expr.h:84
enum clang::SubobjectAdjustment::@50 Kind