clang  16.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 
16 #include "clang/AST/APValue.h"
17 #include "clang/AST/ASTVector.h"
19 #include "clang/AST/Decl.h"
23 #include "clang/AST/Stmt.h"
24 #include "clang/AST/TemplateBase.h"
25 #include "clang/AST/Type.h"
26 #include "clang/Basic/CharInfo.h"
28 #include "clang/Basic/SyncScope.h"
29 #include "clang/Basic/TypeTraits.h"
30 #include "llvm/ADT/APFloat.h"
31 #include "llvm/ADT/APSInt.h"
32 #include "llvm/ADT/SmallVector.h"
33 #include "llvm/ADT/StringRef.h"
34 #include "llvm/ADT/iterator.h"
35 #include "llvm/ADT/iterator_range.h"
36 #include "llvm/Support/AtomicOrdering.h"
37 #include "llvm/Support/Compiler.h"
38 #include "llvm/Support/TrailingObjects.h"
39 
40 namespace clang {
41  class APValue;
42  class ASTContext;
43  class BlockDecl;
44  class CXXBaseSpecifier;
45  class CXXMemberCallExpr;
46  class CXXOperatorCallExpr;
47  class CastExpr;
48  class Decl;
49  class IdentifierInfo;
50  class MaterializeTemporaryExpr;
51  class NamedDecl;
52  class ObjCPropertyRefExpr;
53  class OpaqueValueExpr;
54  class ParmVarDecl;
55  class StringLiteral;
56  class TargetInfo;
57  class ValueDecl;
58 
59 /// A simple array of base specifiers.
61 
62 /// An adjustment to be made to the temporary created when emitting a
63 /// reference binding, which accesses a particular subobject of that temporary.
65  enum {
69  } Kind;
70 
71  struct DTB {
74  };
75 
76  struct P {
79  };
80 
81  union {
84  struct P Ptr;
85  };
86 
87  SubobjectAdjustment(const CastExpr *BasePath,
88  const CXXRecordDecl *DerivedClass)
90  DerivedToBase.BasePath = BasePath;
91  DerivedToBase.DerivedClass = DerivedClass;
92  }
93 
96  this->Field = Field;
97  }
98 
101  this->Ptr.MPT = MPT;
102  this->Ptr.RHS = RHS;
103  }
104 };
105 
106 /// This represents one expression. Note that Expr's are subclasses of Stmt.
107 /// This allows an expression to be transparently used any place a Stmt is
108 /// required.
109 class Expr : public ValueStmt {
110  QualType TR;
111 
112 public:
113  Expr() = delete;
114  Expr(const Expr&) = delete;
115  Expr(Expr &&) = delete;
116  Expr &operator=(const Expr&) = delete;
117  Expr &operator=(Expr&&) = delete;
118 
119 protected:
121  : ValueStmt(SC) {
122  ExprBits.Dependent = 0;
123  ExprBits.ValueKind = VK;
124  ExprBits.ObjectKind = OK;
125  assert(ExprBits.ObjectKind == OK && "truncated kind");
126  setType(T);
127  }
128 
129  /// Construct an empty expression.
130  explicit Expr(StmtClass SC, EmptyShell) : ValueStmt(SC) { }
131 
132  /// Each concrete expr subclass is expected to compute its dependence and call
133  /// this in the constructor.
135  ExprBits.Dependent = static_cast<unsigned>(Deps);
136  }
137  friend class ASTImporter; // Sets dependence dircetly.
138  friend class ASTStmtReader; // Sets dependence dircetly.
139 
140 public:
141  QualType getType() const { return TR; }
142  void setType(QualType t) {
143  // In C++, the type of an expression is always adjusted so that it
144  // will not have reference type (C++ [expr]p6). Use
145  // QualType::getNonReferenceType() to retrieve the non-reference
146  // type. Additionally, inspect Expr::isLvalue to determine whether
147  // an expression that is adjusted in this manner should be
148  // considered an lvalue.
149  assert((t.isNull() || !t->isReferenceType()) &&
150  "Expressions can't have reference type");
151 
152  TR = t;
153  }
154 
156  return static_cast<ExprDependence>(ExprBits.Dependent);
157  }
158 
159  /// Determines whether the value of this expression depends on
160  /// - a template parameter (C++ [temp.dep.constexpr])
161  /// - or an error, whose resolution is unknown
162  ///
163  /// For example, the array bound of "Chars" in the following example is
164  /// value-dependent.
165  /// @code
166  /// template<int Size, char (&Chars)[Size]> struct meta_string;
167  /// @endcode
168  bool isValueDependent() const {
169  return static_cast<bool>(getDependence() & ExprDependence::Value);
170  }
171 
172  /// Determines whether the type of this expression depends on
173  /// - a template paramter (C++ [temp.dep.expr], which means that its type
174  /// could change from one template instantiation to the next)
175  /// - or an error
176  ///
177  /// For example, the expressions "x" and "x + y" are type-dependent in
178  /// the following code, but "y" is not type-dependent:
179  /// @code
180  /// template<typename T>
181  /// void add(T x, int y) {
182  /// x + y;
183  /// }
184  /// @endcode
185  bool isTypeDependent() const {
186  return static_cast<bool>(getDependence() & ExprDependence::Type);
187  }
188 
189  /// Whether this expression is instantiation-dependent, meaning that
190  /// it depends in some way on
191  /// - a template parameter (even if neither its type nor (constant) value
192  /// can change due to the template instantiation)
193  /// - or an error
194  ///
195  /// In the following example, the expression \c sizeof(sizeof(T() + T())) is
196  /// instantiation-dependent (since it involves a template parameter \c T), but
197  /// is neither type- nor value-dependent, since the type of the inner
198  /// \c sizeof is known (\c std::size_t) and therefore the size of the outer
199  /// \c sizeof is known.
200  ///
201  /// \code
202  /// template<typename T>
203  /// void f(T x, T y) {
204  /// sizeof(sizeof(T() + T());
205  /// }
206  /// \endcode
207  ///
208  /// \code
209  /// void func(int) {
210  /// func(); // the expression is instantiation-dependent, because it depends
211  /// // on an error.
212  /// }
213  /// \endcode
215  return static_cast<bool>(getDependence() & ExprDependence::Instantiation);
216  }
217 
218  /// Whether this expression contains an unexpanded parameter
219  /// pack (for C++11 variadic templates).
220  ///
221  /// Given the following function template:
222  ///
223  /// \code
224  /// template<typename F, typename ...Types>
225  /// void forward(const F &f, Types &&...args) {
226  /// f(static_cast<Types&&>(args)...);
227  /// }
228  /// \endcode
229  ///
230  /// The expressions \c args and \c static_cast<Types&&>(args) both
231  /// contain parameter packs.
233  return static_cast<bool>(getDependence() & ExprDependence::UnexpandedPack);
234  }
235 
236  /// Whether this expression contains subexpressions which had errors, e.g. a
237  /// TypoExpr.
238  bool containsErrors() const {
239  return static_cast<bool>(getDependence() & ExprDependence::Error);
240  }
241 
242  /// getExprLoc - Return the preferred location for the arrow when diagnosing
243  /// a problem with a generic expression.
244  SourceLocation getExprLoc() const LLVM_READONLY;
245 
246  /// Determine whether an lvalue-to-rvalue conversion should implicitly be
247  /// applied to this expression if it appears as a discarded-value expression
248  /// in C++11 onwards. This applies to certain forms of volatile glvalues.
249  bool isReadIfDiscardedInCPlusPlus11() const;
250 
251  /// isUnusedResultAWarning - Return true if this immediate expression should
252  /// be warned about if the result is unused. If so, fill in expr, location,
253  /// and ranges with expr to warn on and source locations/ranges appropriate
254  /// for a warning.
255  bool isUnusedResultAWarning(const Expr *&WarnExpr, SourceLocation &Loc,
256  SourceRange &R1, SourceRange &R2,
257  ASTContext &Ctx) const;
258 
259  /// isLValue - True if this expression is an "l-value" according to
260  /// the rules of the current language. C and C++ give somewhat
261  /// different rules for this concept, but in general, the result of
262  /// an l-value expression identifies a specific object whereas the
263  /// result of an r-value expression is a value detached from any
264  /// specific storage.
265  ///
266  /// C++11 divides the concept of "r-value" into pure r-values
267  /// ("pr-values") and so-called expiring values ("x-values"), which
268  /// identify specific objects that can be safely cannibalized for
269  /// their resources.
270  bool isLValue() const { return getValueKind() == VK_LValue; }
271  bool isPRValue() const { return getValueKind() == VK_PRValue; }
272  bool isXValue() const { return getValueKind() == VK_XValue; }
273  bool isGLValue() const { return getValueKind() != VK_PRValue; }
274 
286  };
287  /// Reasons why an expression might not be an l-value.
289 
296  MLV_LValueCast, // Specialized form of MLV_InvalidExpression.
308  };
309  /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type,
310  /// does not have an incomplete type, does not have a const-qualified type,
311  /// and if it is a structure or union, does not have any member (including,
312  /// recursively, any member or element of all contained aggregates or unions)
313  /// with a const-qualified type.
314  ///
315  /// \param Loc [in,out] - A source location which *may* be filled
316  /// in with the location of the expression making this a
317  /// non-modifiable lvalue, if specified.
319  isModifiableLvalue(ASTContext &Ctx, SourceLocation *Loc = nullptr) const;
320 
321  /// The return type of classify(). Represents the C++11 expression
322  /// taxonomy.
324  public:
325  /// The various classification results. Most of these mean prvalue.
326  enum Kinds {
329  CL_Function, // Functions cannot be lvalues in C.
330  CL_Void, // Void cannot be an lvalue in C.
331  CL_AddressableVoid, // Void expression whose address can be taken in C.
332  CL_DuplicateVectorComponents, // A vector shuffle with dupes.
333  CL_MemberFunction, // An expression referring to a member function
335  CL_ClassTemporary, // A temporary of class type, or subobject thereof.
336  CL_ArrayTemporary, // A temporary of array type.
337  CL_ObjCMessageRValue, // ObjC message is an rvalue
338  CL_PRValue // A prvalue for any other reason, of any other type
339  };
340  /// The results of modification testing.
342  CM_Untested, // testModifiable was false.
344  CM_RValue, // Not modifiable because it's an rvalue
345  CM_Function, // Not modifiable because it's a function; C++ only
346  CM_LValueCast, // Same as CM_RValue, but indicates GCC cast-as-lvalue ext
347  CM_NoSetterProperty,// Implicit assignment to ObjC property without setter
353  };
354 
355  private:
356  friend class Expr;
357 
358  unsigned short Kind;
359  unsigned short Modifiable;
360 
361  explicit Classification(Kinds k, ModifiableType m)
362  : Kind(k), Modifiable(m)
363  {}
364 
365  public:
367 
368  Kinds getKind() const { return static_cast<Kinds>(Kind); }
370  assert(Modifiable != CM_Untested && "Did not test for modifiability.");
371  return static_cast<ModifiableType>(Modifiable);
372  }
373  bool isLValue() const { return Kind == CL_LValue; }
374  bool isXValue() const { return Kind == CL_XValue; }
375  bool isGLValue() const { return Kind <= CL_XValue; }
376  bool isPRValue() const { return Kind >= CL_Function; }
377  bool isRValue() const { return Kind >= CL_XValue; }
378  bool isModifiable() const { return getModifiable() == CM_Modifiable; }
379 
380  /// Create a simple, modifiably lvalue
383  }
384 
385  };
386  /// Classify - Classify this expression according to the C++11
387  /// expression taxonomy.
388  ///
389  /// C++11 defines ([basic.lval]) a new taxonomy of expressions to replace the
390  /// old lvalue vs rvalue. This function determines the type of expression this
391  /// is. There are three expression types:
392  /// - lvalues are classical lvalues as in C++03.
393  /// - prvalues are equivalent to rvalues in C++03.
394  /// - xvalues are expressions yielding unnamed rvalue references, e.g. a
395  /// function returning an rvalue reference.
396  /// lvalues and xvalues are collectively referred to as glvalues, while
397  /// prvalues and xvalues together form rvalues.
399  return ClassifyImpl(Ctx, nullptr);
400  }
401 
402  /// ClassifyModifiable - Classify this expression according to the
403  /// C++11 expression taxonomy, and see if it is valid on the left side
404  /// of an assignment.
405  ///
406  /// This function extends classify in that it also tests whether the
407  /// expression is modifiable (C99 6.3.2.1p1).
408  /// \param Loc A source location that might be filled with a relevant location
409  /// if the expression is not modifiable.
411  return ClassifyImpl(Ctx, &Loc);
412  }
413 
414  /// Returns the set of floating point options that apply to this expression.
415  /// Only meaningful for operations on floating point values.
417 
418  /// getValueKindForType - Given a formal return or parameter type,
419  /// give its value kind.
421  if (const ReferenceType *RT = T->getAs<ReferenceType>())
422  return (isa<LValueReferenceType>(RT)
423  ? VK_LValue
424  : (RT->getPointeeType()->isFunctionType()
425  ? VK_LValue : VK_XValue));
426  return VK_PRValue;
427  }
428 
429  /// getValueKind - The value kind that this expression produces.
431  return static_cast<ExprValueKind>(ExprBits.ValueKind);
432  }
433 
434  /// getObjectKind - The object kind that this expression produces.
435  /// Object kinds are meaningful only for expressions that yield an
436  /// l-value or x-value.
438  return static_cast<ExprObjectKind>(ExprBits.ObjectKind);
439  }
440 
443  return (OK == OK_Ordinary || OK == OK_BitField);
444  }
445 
446  /// setValueKind - Set the value kind produced by this expression.
447  void setValueKind(ExprValueKind Cat) { ExprBits.ValueKind = Cat; }
448 
449  /// setObjectKind - Set the object kind produced by this expression.
450  void setObjectKind(ExprObjectKind Cat) { ExprBits.ObjectKind = Cat; }
451 
452 private:
453  Classification ClassifyImpl(ASTContext &Ctx, SourceLocation *Loc) const;
454 
455 public:
456 
457  /// Returns true if this expression is a gl-value that
458  /// potentially refers to a bit-field.
459  ///
460  /// In C++, whether a gl-value refers to a bitfield is essentially
461  /// an aspect of the value-kind type system.
462  bool refersToBitField() const { return getObjectKind() == OK_BitField; }
463 
464  /// If this expression refers to a bit-field, retrieve the
465  /// declaration of that bit-field.
466  ///
467  /// Note that this returns a non-null pointer in subtly different
468  /// places than refersToBitField returns true. In particular, this can
469  /// return a non-null pointer even for r-values loaded from
470  /// bit-fields, but it will return null for a conditional bit-field.
472 
473  const FieldDecl *getSourceBitField() const {
474  return const_cast<Expr*>(this)->getSourceBitField();
475  }
476 
479  return const_cast<Expr*>(this)->getReferencedDeclOfCallee();
480  }
481 
482  /// If this expression is an l-value for an Objective C
483  /// property, find the underlying property reference expression.
484  const ObjCPropertyRefExpr *getObjCProperty() const;
485 
486  /// Check if this expression is the ObjC 'self' implicit parameter.
487  bool isObjCSelfExpr() const;
488 
489  /// Returns whether this expression refers to a vector element.
490  bool refersToVectorElement() const;
491 
492  /// Returns whether this expression refers to a matrix element.
493  bool refersToMatrixElement() const {
494  return getObjectKind() == OK_MatrixComponent;
495  }
496 
497  /// Returns whether this expression refers to a global register
498  /// variable.
499  bool refersToGlobalRegisterVar() const;
500 
501  /// Returns whether this expression has a placeholder type.
502  bool hasPlaceholderType() const {
503  return getType()->isPlaceholderType();
504  }
505 
506  /// Returns whether this expression has a specific placeholder type.
509  if (const BuiltinType *BT = dyn_cast<BuiltinType>(getType()))
510  return BT->getKind() == K;
511  return false;
512  }
513 
514  /// isKnownToHaveBooleanValue - Return true if this is an integer expression
515  /// that is known to return 0 or 1. This happens for _Bool/bool expressions
516  /// but also int expressions which are produced by things like comparisons in
517  /// C.
518  ///
519  /// \param Semantic If true, only return true for expressions that are known
520  /// to be semantically boolean, which might not be true even for expressions
521  /// that are known to evaluate to 0/1. For instance, reading an unsigned
522  /// bit-field with width '1' will evaluate to 0/1, but doesn't necessarily
523  /// semantically correspond to a bool.
524  bool isKnownToHaveBooleanValue(bool Semantic = true) const;
525 
526  /// Check whether this array fits the idiom of a flexible array member,
527  /// depending on the value of -fstrict-flex-array.
528  /// When IgnoreTemplateOrMacroSubstitution is set, it doesn't consider sizes
529  /// resulting from the substitution of a macro or a template as special sizes.
531  ASTContext &Context, unsigned StrictFlexArraysLevel,
532  bool IgnoreTemplateOrMacroSubstitution = false) const;
533 
534  /// isIntegerConstantExpr - Return the value if this expression is a valid
535  /// integer constant expression. If not a valid i-c-e, return None and fill
536  /// in Loc (if specified) with the location of the invalid expression.
537  ///
538  /// Note: This does not perform the implicit conversions required by C++11
539  /// [expr.const]p5.
541  SourceLocation *Loc = nullptr,
542  bool isEvaluated = true) const;
543  bool isIntegerConstantExpr(const ASTContext &Ctx,
544  SourceLocation *Loc = nullptr) const;
545 
546  /// isCXX98IntegralConstantExpr - Return true if this expression is an
547  /// integral constant expression in C++98. Can only be used in C++.
548  bool isCXX98IntegralConstantExpr(const ASTContext &Ctx) const;
549 
550  /// isCXX11ConstantExpr - Return true if this expression is a constant
551  /// expression in C++11. Can only be used in C++.
552  ///
553  /// Note: This does not perform the implicit conversions required by C++11
554  /// [expr.const]p5.
555  bool isCXX11ConstantExpr(const ASTContext &Ctx, APValue *Result = nullptr,
556  SourceLocation *Loc = nullptr) const;
557 
558  /// isPotentialConstantExpr - Return true if this function's definition
559  /// might be usable in a constant expression in C++11, if it were marked
560  /// constexpr. Return false if the function can never produce a constant
561  /// expression, along with diagnostics describing why not.
562  static bool isPotentialConstantExpr(const FunctionDecl *FD,
564  PartialDiagnosticAt> &Diags);
565 
566  /// isPotentialConstantExprUnevaluted - Return true if this expression might
567  /// be usable in a constant expression in C++11 in an unevaluated context, if
568  /// it were in function FD marked constexpr. Return false if the function can
569  /// never produce a constant expression, along with diagnostics describing
570  /// why not.
572  const FunctionDecl *FD,
574  PartialDiagnosticAt> &Diags);
575 
576  /// isConstantInitializer - Returns true if this expression can be emitted to
577  /// IR as a constant, and thus can be used as a constant initializer in C.
578  /// If this expression is not constant and Culprit is non-null,
579  /// it is used to store the address of first non constant expr.
580  bool isConstantInitializer(ASTContext &Ctx, bool ForRef,
581  const Expr **Culprit = nullptr) const;
582 
583  /// If this expression is an unambiguous reference to a single declaration,
584  /// in the style of __builtin_function_start, return that declaration. Note
585  /// that this may return a non-static member function or field in C++ if this
586  /// expression is a member pointer constant.
587  const ValueDecl *getAsBuiltinConstantDeclRef(const ASTContext &Context) const;
588 
589  /// EvalStatus is a struct with detailed info about an evaluation in progress.
590  struct EvalStatus {
591  /// Whether the evaluated expression has side effects.
592  /// For example, (f() && 0) can be folded, but it still has side effects.
594 
595  /// Whether the evaluation hit undefined behavior.
596  /// For example, 1.0 / 0.0 can be folded to Inf, but has undefined behavior.
597  /// Likewise, INT_MAX + 1 can be folded to INT_MIN, but has UB.
599 
600  /// Diag - If this is non-null, it will be filled in with a stack of notes
601  /// indicating why evaluation failed (or why it failed to produce a constant
602  /// expression).
603  /// If the expression is unfoldable, the notes will indicate why it's not
604  /// foldable. If the expression is foldable, but not a constant expression,
605  /// the notes will describes why it isn't a constant expression. If the
606  /// expression *is* a constant expression, no notes will be produced.
608 
611 
612  // hasSideEffects - Return true if the evaluated expression has
613  // side effects.
614  bool hasSideEffects() const {
615  return HasSideEffects;
616  }
617  };
618 
619  /// EvalResult is a struct with detailed info about an evaluated expression.
621  /// Val - This is the value the expression can be folded to.
623 
624  // isGlobalLValue - Return true if the evaluated lvalue expression
625  // is global.
626  bool isGlobalLValue() const;
627  };
628 
629  /// EvaluateAsRValue - Return true if this is a constant which we can fold to
630  /// an rvalue using any crazy technique (that has nothing to do with language
631  /// standards) that we want to, even if the expression has side-effects. If
632  /// this function returns true, it returns the folded constant in Result. If
633  /// the expression is a glvalue, an lvalue-to-rvalue conversion will be
634  /// applied.
635  bool EvaluateAsRValue(EvalResult &Result, const ASTContext &Ctx,
636  bool InConstantContext = false) const;
637 
638  /// EvaluateAsBooleanCondition - Return true if this is a constant
639  /// which we can fold and convert to a boolean condition using
640  /// any crazy technique that we want to, even if the expression has
641  /// side-effects.
642  bool EvaluateAsBooleanCondition(bool &Result, const ASTContext &Ctx,
643  bool InConstantContext = false) const;
644 
646  SE_NoSideEffects, ///< Strictly evaluate the expression.
647  SE_AllowUndefinedBehavior, ///< Allow UB that we can give a value, but not
648  ///< arbitrary unmodeled side effects.
649  SE_AllowSideEffects ///< Allow any unmodeled side effect.
650  };
651 
652  /// EvaluateAsInt - Return true if this is a constant which we can fold and
653  /// convert to an integer, using any crazy technique that we want to.
654  bool EvaluateAsInt(EvalResult &Result, const ASTContext &Ctx,
655  SideEffectsKind AllowSideEffects = SE_NoSideEffects,
656  bool InConstantContext = false) const;
657 
658  /// EvaluateAsFloat - Return true if this is a constant which we can fold and
659  /// convert to a floating point value, using any crazy technique that we
660  /// want to.
661  bool EvaluateAsFloat(llvm::APFloat &Result, const ASTContext &Ctx,
662  SideEffectsKind AllowSideEffects = SE_NoSideEffects,
663  bool InConstantContext = false) const;
664 
665  /// EvaluateAsFloat - Return true if this is a constant which we can fold and
666  /// convert to a fixed point value.
667  bool EvaluateAsFixedPoint(EvalResult &Result, const ASTContext &Ctx,
668  SideEffectsKind AllowSideEffects = SE_NoSideEffects,
669  bool InConstantContext = false) const;
670 
671  /// isEvaluatable - Call EvaluateAsRValue to see if this expression can be
672  /// constant folded without side-effects, but discard the result.
673  bool isEvaluatable(const ASTContext &Ctx,
674  SideEffectsKind AllowSideEffects = SE_NoSideEffects) const;
675 
676  /// HasSideEffects - This routine returns true for all those expressions
677  /// which have any effect other than producing a value. Example is a function
678  /// call, volatile variable read, or throwing an exception. If
679  /// IncludePossibleEffects is false, this call treats certain expressions with
680  /// potential side effects (such as function call-like expressions,
681  /// instantiation-dependent expressions, or invocations from a macro) as not
682  /// having side effects.
683  bool HasSideEffects(const ASTContext &Ctx,
684  bool IncludePossibleEffects = true) const;
685 
686  /// Determine whether this expression involves a call to any function
687  /// that is not trivial.
688  bool hasNonTrivialCall(const ASTContext &Ctx) const;
689 
690  /// EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded
691  /// integer. This must be called on an expression that constant folds to an
692  /// integer.
694  const ASTContext &Ctx,
695  SmallVectorImpl<PartialDiagnosticAt> *Diag = nullptr) const;
696 
698  const ASTContext &Ctx,
699  SmallVectorImpl<PartialDiagnosticAt> *Diag = nullptr) const;
700 
701  void EvaluateForOverflow(const ASTContext &Ctx) const;
702 
703  /// EvaluateAsLValue - Evaluate an expression to see if we can fold it to an
704  /// lvalue with link time known address, with no side-effects.
705  bool EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx,
706  bool InConstantContext = false) const;
707 
708  /// EvaluateAsInitializer - Evaluate an expression as if it were the
709  /// initializer of the given declaration. Returns true if the initializer
710  /// can be folded to a constant, and produces any relevant notes. In C++11,
711  /// notes will be produced if the expression is not a constant expression.
712  bool EvaluateAsInitializer(APValue &Result, const ASTContext &Ctx,
713  const VarDecl *VD,
715  bool IsConstantInitializer) const;
716 
717  /// EvaluateWithSubstitution - Evaluate an expression as if from the context
718  /// of a call to the given function with the given arguments, inside an
719  /// unevaluated context. Returns true if the expression could be folded to a
720  /// constant.
722  const FunctionDecl *Callee,
724  const Expr *This = nullptr) const;
725 
726  enum class ConstantExprKind {
727  /// An integer constant expression (an array bound, enumerator, case value,
728  /// bit-field width, or similar) or similar.
729  Normal,
730  /// A non-class template argument. Such a value is only used for mangling,
731  /// not for code generation, so can refer to dllimported functions.
733  /// A class template argument. Such a value is used for code generation.
735  /// An immediate invocation. The destruction of the end result of this
736  /// evaluation is not part of the evaluation, but all other temporaries
737  /// are destroyed.
739  };
740 
741  /// Evaluate an expression that is required to be a constant expression. Does
742  /// not check the syntactic constraints for C and C++98 constant expressions.
744  EvalResult &Result, const ASTContext &Ctx,
746 
747  /// If the current Expr is a pointer, this will try to statically
748  /// determine the number of bytes available where the pointer is pointing.
749  /// Returns true if all of the above holds and we were able to figure out the
750  /// size, false otherwise.
751  ///
752  /// \param Type - How to evaluate the size of the Expr, as defined by the
753  /// "type" parameter of __builtin_object_size
754  bool tryEvaluateObjectSize(uint64_t &Result, ASTContext &Ctx,
755  unsigned Type) const;
756 
757  /// If the current Expr is a pointer, this will try to statically
758  /// determine the strlen of the string pointed to.
759  /// Returns true if all of the above holds and we were able to figure out the
760  /// strlen, false otherwise.
761  bool tryEvaluateStrLen(uint64_t &Result, ASTContext &Ctx) const;
762 
763  /// Enumeration used to describe the kind of Null pointer constant
764  /// returned from \c isNullPointerConstant().
766  /// Expression is not a Null pointer constant.
768 
769  /// Expression is a Null pointer constant built from a zero integer
770  /// expression that is not a simple, possibly parenthesized, zero literal.
771  /// C++ Core Issue 903 will classify these expressions as "not pointers"
772  /// once it is adopted.
773  /// http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#903
775 
776  /// Expression is a Null pointer constant built from a literal zero.
778 
779  /// Expression is a C++11 nullptr.
781 
782  /// Expression is a GNU-style __null constant.
784  };
785 
786  /// Enumeration used to describe how \c isNullPointerConstant()
787  /// should cope with value-dependent expressions.
789  /// Specifies that the expression should never be value-dependent.
791 
792  /// Specifies that a value-dependent expression of integral or
793  /// dependent type should be considered a null pointer constant.
795 
796  /// Specifies that a value-dependent expression should be considered
797  /// to never be a null pointer constant.
799  };
800 
801  /// isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to
802  /// a Null pointer constant. The return value can further distinguish the
803  /// kind of NULL pointer constant that was detected.
805  ASTContext &Ctx,
807 
808  /// isOBJCGCCandidate - Return true if this expression may be used in a read/
809  /// write barrier.
810  bool isOBJCGCCandidate(ASTContext &Ctx) const;
811 
812  /// Returns true if this expression is a bound member function.
813  bool isBoundMemberFunction(ASTContext &Ctx) const;
814 
815  /// Given an expression of bound-member type, find the type
816  /// of the member. Returns null if this is an *overloaded* bound
817  /// member expression.
818  static QualType findBoundMemberType(const Expr *expr);
819 
820  /// Skip past any invisble AST nodes which might surround this
821  /// statement, such as ExprWithCleanups or ImplicitCastExpr nodes,
822  /// but also injected CXXMemberExpr and CXXConstructExpr which represent
823  /// implicit conversions.
826  return const_cast<Expr *>(this)->IgnoreUnlessSpelledInSource();
827  }
828 
829  /// Skip past any implicit casts which might surround this expression until
830  /// reaching a fixed point. Skips:
831  /// * ImplicitCastExpr
832  /// * FullExpr
833  Expr *IgnoreImpCasts() LLVM_READONLY;
834  const Expr *IgnoreImpCasts() const {
835  return const_cast<Expr *>(this)->IgnoreImpCasts();
836  }
837 
838  /// Skip past any casts which might surround this expression until reaching
839  /// a fixed point. Skips:
840  /// * CastExpr
841  /// * FullExpr
842  /// * MaterializeTemporaryExpr
843  /// * SubstNonTypeTemplateParmExpr
844  Expr *IgnoreCasts() LLVM_READONLY;
845  const Expr *IgnoreCasts() const {
846  return const_cast<Expr *>(this)->IgnoreCasts();
847  }
848 
849  /// Skip past any implicit AST nodes which might surround this expression
850  /// until reaching a fixed point. Skips:
851  /// * What IgnoreImpCasts() skips
852  /// * MaterializeTemporaryExpr
853  /// * CXXBindTemporaryExpr
854  Expr *IgnoreImplicit() LLVM_READONLY;
855  const Expr *IgnoreImplicit() const {
856  return const_cast<Expr *>(this)->IgnoreImplicit();
857  }
858 
859  /// Skip past any implicit AST nodes which might surround this expression
860  /// until reaching a fixed point. Same as IgnoreImplicit, except that it
861  /// also skips over implicit calls to constructors and conversion functions.
862  ///
863  /// FIXME: Should IgnoreImplicit do this?
864  Expr *IgnoreImplicitAsWritten() LLVM_READONLY;
865  const Expr *IgnoreImplicitAsWritten() const {
866  return const_cast<Expr *>(this)->IgnoreImplicitAsWritten();
867  }
868 
869  /// Skip past any parentheses which might surround this expression until
870  /// reaching a fixed point. Skips:
871  /// * ParenExpr
872  /// * UnaryOperator if `UO_Extension`
873  /// * GenericSelectionExpr if `!isResultDependent()`
874  /// * ChooseExpr if `!isConditionDependent()`
875  /// * ConstantExpr
876  Expr *IgnoreParens() LLVM_READONLY;
877  const Expr *IgnoreParens() const {
878  return const_cast<Expr *>(this)->IgnoreParens();
879  }
880 
881  /// Skip past any parentheses and implicit casts which might surround this
882  /// expression until reaching a fixed point.
883  /// FIXME: IgnoreParenImpCasts really ought to be equivalent to
884  /// IgnoreParens() + IgnoreImpCasts() until reaching a fixed point. However
885  /// this is currently not the case. Instead IgnoreParenImpCasts() skips:
886  /// * What IgnoreParens() skips
887  /// * What IgnoreImpCasts() skips
888  /// * MaterializeTemporaryExpr
889  /// * SubstNonTypeTemplateParmExpr
890  Expr *IgnoreParenImpCasts() LLVM_READONLY;
891  const Expr *IgnoreParenImpCasts() const {
892  return const_cast<Expr *>(this)->IgnoreParenImpCasts();
893  }
894 
895  /// Skip past any parentheses and casts which might surround this expression
896  /// until reaching a fixed point. Skips:
897  /// * What IgnoreParens() skips
898  /// * What IgnoreCasts() skips
899  Expr *IgnoreParenCasts() LLVM_READONLY;
900  const Expr *IgnoreParenCasts() const {
901  return const_cast<Expr *>(this)->IgnoreParenCasts();
902  }
903 
904  /// Skip conversion operators. If this Expr is a call to a conversion
905  /// operator, return the argument.
906  Expr *IgnoreConversionOperatorSingleStep() LLVM_READONLY;
908  return const_cast<Expr *>(this)->IgnoreConversionOperatorSingleStep();
909  }
910 
911  /// Skip past any parentheses and lvalue casts which might surround this
912  /// expression until reaching a fixed point. Skips:
913  /// * What IgnoreParens() skips
914  /// * What IgnoreCasts() skips, except that only lvalue-to-rvalue
915  /// casts are skipped
916  /// FIXME: This is intended purely as a temporary workaround for code
917  /// that hasn't yet been rewritten to do the right thing about those
918  /// casts, and may disappear along with the last internal use.
919  Expr *IgnoreParenLValueCasts() LLVM_READONLY;
920  const Expr *IgnoreParenLValueCasts() const {
921  return const_cast<Expr *>(this)->IgnoreParenLValueCasts();
922  }
923 
924  /// Skip past any parenthese and casts which do not change the value
925  /// (including ptr->int casts of the same size) until reaching a fixed point.
926  /// Skips:
927  /// * What IgnoreParens() skips
928  /// * CastExpr which do not change the value
929  /// * SubstNonTypeTemplateParmExpr
930  Expr *IgnoreParenNoopCasts(const ASTContext &Ctx) LLVM_READONLY;
931  const Expr *IgnoreParenNoopCasts(const ASTContext &Ctx) const {
932  return const_cast<Expr *>(this)->IgnoreParenNoopCasts(Ctx);
933  }
934 
935  /// Skip past any parentheses and derived-to-base casts until reaching a
936  /// fixed point. Skips:
937  /// * What IgnoreParens() skips
938  /// * CastExpr which represent a derived-to-base cast (CK_DerivedToBase,
939  /// CK_UncheckedDerivedToBase and CK_NoOp)
940  Expr *IgnoreParenBaseCasts() LLVM_READONLY;
941  const Expr *IgnoreParenBaseCasts() const {
942  return const_cast<Expr *>(this)->IgnoreParenBaseCasts();
943  }
944 
945  /// Determine whether this expression is a default function argument.
946  ///
947  /// Default arguments are implicitly generated in the abstract syntax tree
948  /// by semantic analysis for function calls, object constructions, etc. in
949  /// C++. Default arguments are represented by \c CXXDefaultArgExpr nodes;
950  /// this routine also looks through any implicit casts to determine whether
951  /// the expression is a default argument.
952  bool isDefaultArgument() const;
953 
954  /// Determine whether the result of this expression is a
955  /// temporary object of the given class type.
956  bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const;
957 
958  /// Whether this expression is an implicit reference to 'this' in C++.
959  bool isImplicitCXXThis() const;
960 
962 
963  /// For an expression of class type or pointer to class type,
964  /// return the most derived class decl the expression is known to refer to.
965  ///
966  /// If this expression is a cast, this method looks through it to find the
967  /// most derived decl that can be inferred from the expression.
968  /// This is valid because derived-to-base conversions have undefined
969  /// behavior if the object isn't dynamically of the derived type.
970  const CXXRecordDecl *getBestDynamicClassType() const;
971 
972  /// Get the inner expression that determines the best dynamic class.
973  /// If this is a prvalue, we guarantee that it is of the most-derived type
974  /// for the object itself.
975  const Expr *getBestDynamicClassTypeExpr() const;
976 
977  /// Walk outwards from an expression we want to bind a reference to and
978  /// find the expression whose lifetime needs to be extended. Record
979  /// the LHSs of comma expressions and adjustments needed along the path.
982  SmallVectorImpl<SubobjectAdjustment> &Adjustments) const;
986  return skipRValueSubobjectAdjustments(CommaLHSs, Adjustments);
987  }
988 
989  /// Checks that the two Expr's will refer to the same value as a comparison
990  /// operand. The caller must ensure that the values referenced by the Expr's
991  /// are not modified between E1 and E2 or the result my be invalid.
992  static bool isSameComparisonOperand(const Expr* E1, const Expr* E2);
993 
994  static bool classof(const Stmt *T) {
995  return T->getStmtClass() >= firstExprConstant &&
996  T->getStmtClass() <= lastExprConstant;
997  }
998 };
999 // PointerLikeTypeTraits is specialized so it can be used with a forward-decl of
1000 // Expr. Verify that we got it right.
1002  llvm::detail::ConstantLog2<alignof(Expr)>::value,
1003  "PointerLikeTypeTraits<Expr*> assumes too much alignment.");
1004 
1006 
1007 //===----------------------------------------------------------------------===//
1008 // Wrapper Expressions.
1009 //===----------------------------------------------------------------------===//
1010 
1011 /// FullExpr - Represents a "full-expression" node.
1012 class FullExpr : public Expr {
1013 protected:
1015 
1016  FullExpr(StmtClass SC, Expr *subexpr)
1017  : Expr(SC, subexpr->getType(), subexpr->getValueKind(),
1018  subexpr->getObjectKind()),
1019  SubExpr(subexpr) {
1021  }
1023  : Expr(SC, Empty) {}
1024 public:
1025  const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
1026  Expr *getSubExpr() { return cast<Expr>(SubExpr); }
1027 
1028  /// As with any mutator of the AST, be very careful when modifying an
1029  /// existing AST to preserve its invariants.
1030  void setSubExpr(Expr *E) { SubExpr = E; }
1031 
1032  static bool classof(const Stmt *T) {
1033  return T->getStmtClass() >= firstFullExprConstant &&
1034  T->getStmtClass() <= lastFullExprConstant;
1035  }
1036 };
1037 
1038 /// ConstantExpr - An expression that occurs in a constant context and
1039 /// optionally the result of evaluating the expression.
1040 class ConstantExpr final
1041  : public FullExpr,
1042  private llvm::TrailingObjects<ConstantExpr, APValue, uint64_t> {
1043  static_assert(std::is_same<uint64_t, llvm::APInt::WordType>::value,
1044  "ConstantExpr assumes that llvm::APInt::WordType is uint64_t "
1045  "for tail-allocated storage");
1046  friend TrailingObjects;
1047  friend class ASTStmtReader;
1048  friend class ASTStmtWriter;
1049 
1050 public:
1051  /// Describes the kind of result that can be tail-allocated.
1053 
1054 private:
1055  size_t numTrailingObjects(OverloadToken<APValue>) const {
1056  return ConstantExprBits.ResultKind == ConstantExpr::RSK_APValue;
1057  }
1058  size_t numTrailingObjects(OverloadToken<uint64_t>) const {
1059  return ConstantExprBits.ResultKind == ConstantExpr::RSK_Int64;
1060  }
1061 
1062  uint64_t &Int64Result() {
1063  assert(ConstantExprBits.ResultKind == ConstantExpr::RSK_Int64 &&
1064  "invalid accessor");
1065  return *getTrailingObjects<uint64_t>();
1066  }
1067  const uint64_t &Int64Result() const {
1068  return const_cast<ConstantExpr *>(this)->Int64Result();
1069  }
1070  APValue &APValueResult() {
1071  assert(ConstantExprBits.ResultKind == ConstantExpr::RSK_APValue &&
1072  "invalid accessor");
1073  return *getTrailingObjects<APValue>();
1074  }
1075  APValue &APValueResult() const {
1076  return const_cast<ConstantExpr *>(this)->APValueResult();
1077  }
1078 
1079  ConstantExpr(Expr *SubExpr, ResultStorageKind StorageKind,
1080  bool IsImmediateInvocation);
1081  ConstantExpr(EmptyShell Empty, ResultStorageKind StorageKind);
1082 
1083 public:
1084  static ConstantExpr *Create(const ASTContext &Context, Expr *E,
1085  const APValue &Result);
1086  static ConstantExpr *Create(const ASTContext &Context, Expr *E,
1087  ResultStorageKind Storage = RSK_None,
1088  bool IsImmediateInvocation = false);
1089  static ConstantExpr *CreateEmpty(const ASTContext &Context,
1090  ResultStorageKind StorageKind);
1091 
1092  static ResultStorageKind getStorageKind(const APValue &Value);
1093  static ResultStorageKind getStorageKind(const Type *T,
1094  const ASTContext &Context);
1095 
1096  SourceLocation getBeginLoc() const LLVM_READONLY {
1097  return SubExpr->getBeginLoc();
1098  }
1099  SourceLocation getEndLoc() const LLVM_READONLY {
1100  return SubExpr->getEndLoc();
1101  }
1102 
1103  static bool classof(const Stmt *T) {
1104  return T->getStmtClass() == ConstantExprClass;
1105  }
1106 
1107  void SetResult(APValue Value, const ASTContext &Context) {
1108  MoveIntoResult(Value, Context);
1109  }
1110  void MoveIntoResult(APValue &Value, const ASTContext &Context);
1111 
1113  return static_cast<APValue::ValueKind>(ConstantExprBits.APValueKind);
1114  }
1116  return static_cast<ResultStorageKind>(ConstantExprBits.ResultKind);
1117  }
1118  bool isImmediateInvocation() const {
1119  return ConstantExprBits.IsImmediateInvocation;
1120  }
1121  bool hasAPValueResult() const {
1122  return ConstantExprBits.APValueKind != APValue::None;
1123  }
1124  APValue getAPValueResult() const;
1125  APValue &getResultAsAPValue() const { return APValueResult(); }
1127  // Iterators
1130  return const_child_range(&SubExpr, &SubExpr + 1);
1131  }
1132 };
1133 
1134 //===----------------------------------------------------------------------===//
1135 // Primary Expressions.
1136 //===----------------------------------------------------------------------===//
1137 
1138 /// OpaqueValueExpr - An expression referring to an opaque object of a
1139 /// fixed type and value class. These don't correspond to concrete
1140 /// syntax; instead they're used to express operations (usually copy
1141 /// operations) on values whose source is generally obvious from
1142 /// context.
1143 class OpaqueValueExpr : public Expr {
1144  friend class ASTStmtReader;
1145  Expr *SourceExpr;
1146 
1147 public:
1149  ExprObjectKind OK = OK_Ordinary, Expr *SourceExpr = nullptr)
1150  : Expr(OpaqueValueExprClass, T, VK, OK), SourceExpr(SourceExpr) {
1151  setIsUnique(false);
1152  OpaqueValueExprBits.Loc = Loc;
1154  }
1155 
1156  /// Given an expression which invokes a copy constructor --- i.e. a
1157  /// CXXConstructExpr, possibly wrapped in an ExprWithCleanups ---
1158  /// find the OpaqueValueExpr that's the source of the construction.
1159  static const OpaqueValueExpr *findInCopyConstruct(const Expr *expr);
1160 
1161  explicit OpaqueValueExpr(EmptyShell Empty)
1162  : Expr(OpaqueValueExprClass, Empty) {}
1163 
1164  /// Retrieve the location of this expression.
1166 
1167  SourceLocation getBeginLoc() const LLVM_READONLY {
1168  return SourceExpr ? SourceExpr->getBeginLoc() : getLocation();
1169  }
1170  SourceLocation getEndLoc() const LLVM_READONLY {
1171  return SourceExpr ? SourceExpr->getEndLoc() : getLocation();
1172  }
1173  SourceLocation getExprLoc() const LLVM_READONLY {
1174  return SourceExpr ? SourceExpr->getExprLoc() : getLocation();
1175  }
1176 
1179  }
1180 
1183  }
1184 
1185  /// The source expression of an opaque value expression is the
1186  /// expression which originally generated the value. This is
1187  /// provided as a convenience for analyses that don't wish to
1188  /// precisely model the execution behavior of the program.
1189  ///
1190  /// The source expression is typically set when building the
1191  /// expression which binds the opaque value expression in the first
1192  /// place.
1193  Expr *getSourceExpr() const { return SourceExpr; }
1194 
1195  void setIsUnique(bool V) {
1196  assert((!V || SourceExpr) &&
1197  "unique OVEs are expected to have source expressions");
1198  OpaqueValueExprBits.IsUnique = V;
1199  }
1200 
1201  bool isUnique() const { return OpaqueValueExprBits.IsUnique; }
1202 
1203  static bool classof(const Stmt *T) {
1204  return T->getStmtClass() == OpaqueValueExprClass;
1205  }
1206 };
1207 
1208 /// A reference to a declared variable, function, enum, etc.
1209 /// [C99 6.5.1p2]
1210 ///
1211 /// This encodes all the information about how a declaration is referenced
1212 /// within an expression.
1213 ///
1214 /// There are several optional constructs attached to DeclRefExprs only when
1215 /// they apply in order to conserve memory. These are laid out past the end of
1216 /// the object, and flags in the DeclRefExprBitfield track whether they exist:
1217 ///
1218 /// DeclRefExprBits.HasQualifier:
1219 /// Specifies when this declaration reference expression has a C++
1220 /// nested-name-specifier.
1221 /// DeclRefExprBits.HasFoundDecl:
1222 /// Specifies when this declaration reference expression has a record of
1223 /// a NamedDecl (different from the referenced ValueDecl) which was found
1224 /// during name lookup and/or overload resolution.
1225 /// DeclRefExprBits.HasTemplateKWAndArgsInfo:
1226 /// Specifies when this declaration reference expression has an explicit
1227 /// C++ template keyword and/or template argument list.
1228 /// DeclRefExprBits.RefersToEnclosingVariableOrCapture
1229 /// Specifies when this declaration reference expression (validly)
1230 /// refers to an enclosed local or a captured variable.
1231 class DeclRefExpr final
1232  : public Expr,
1233  private llvm::TrailingObjects<DeclRefExpr, NestedNameSpecifierLoc,
1234  NamedDecl *, ASTTemplateKWAndArgsInfo,
1235  TemplateArgumentLoc> {
1236  friend class ASTStmtReader;
1237  friend class ASTStmtWriter;
1238  friend TrailingObjects;
1239 
1240  /// The declaration that we are referencing.
1241  ValueDecl *D;
1242 
1243  /// Provides source/type location info for the declaration name
1244  /// embedded in D.
1245  DeclarationNameLoc DNLoc;
1246 
1247  size_t numTrailingObjects(OverloadToken<NestedNameSpecifierLoc>) const {
1248  return hasQualifier();
1249  }
1250 
1251  size_t numTrailingObjects(OverloadToken<NamedDecl *>) const {
1252  return hasFoundDecl();
1253  }
1254 
1255  size_t numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
1256  return hasTemplateKWAndArgsInfo();
1257  }
1258 
1259  /// Test whether there is a distinct FoundDecl attached to the end of
1260  /// this DRE.
1261  bool hasFoundDecl() const { return DeclRefExprBits.HasFoundDecl; }
1262 
1263  DeclRefExpr(const ASTContext &Ctx, NestedNameSpecifierLoc QualifierLoc,
1264  SourceLocation TemplateKWLoc, ValueDecl *D,
1265  bool RefersToEnlosingVariableOrCapture,
1266  const DeclarationNameInfo &NameInfo, NamedDecl *FoundD,
1267  const TemplateArgumentListInfo *TemplateArgs, QualType T,
1268  ExprValueKind VK, NonOdrUseReason NOUR);
1269 
1270  /// Construct an empty declaration reference expression.
1271  explicit DeclRefExpr(EmptyShell Empty) : Expr(DeclRefExprClass, Empty) {}
1272 
1273 public:
1274  DeclRefExpr(const ASTContext &Ctx, ValueDecl *D,
1275  bool RefersToEnclosingVariableOrCapture, QualType T,
1276  ExprValueKind VK, SourceLocation L,
1277  const DeclarationNameLoc &LocInfo = DeclarationNameLoc(),
1278  NonOdrUseReason NOUR = NOUR_None);
1279 
1280  static DeclRefExpr *
1281  Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc,
1282  SourceLocation TemplateKWLoc, ValueDecl *D,
1283  bool RefersToEnclosingVariableOrCapture, SourceLocation NameLoc,
1284  QualType T, ExprValueKind VK, NamedDecl *FoundD = nullptr,
1285  const TemplateArgumentListInfo *TemplateArgs = nullptr,
1286  NonOdrUseReason NOUR = NOUR_None);
1287 
1288  static DeclRefExpr *
1289  Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc,
1290  SourceLocation TemplateKWLoc, ValueDecl *D,
1291  bool RefersToEnclosingVariableOrCapture,
1292  const DeclarationNameInfo &NameInfo, QualType T, ExprValueKind VK,
1293  NamedDecl *FoundD = nullptr,
1294  const TemplateArgumentListInfo *TemplateArgs = nullptr,
1295  NonOdrUseReason NOUR = NOUR_None);
1296 
1297  /// Construct an empty declaration reference expression.
1298  static DeclRefExpr *CreateEmpty(const ASTContext &Context, bool HasQualifier,
1299  bool HasFoundDecl,
1300  bool HasTemplateKWAndArgsInfo,
1301  unsigned NumTemplateArgs);
1302 
1303  ValueDecl *getDecl() { return D; }
1304  const ValueDecl *getDecl() const { return D; }
1305  void setDecl(ValueDecl *NewD);
1306 
1308  return DeclarationNameInfo(getDecl()->getDeclName(), getLocation(), DNLoc);
1309  }
1310 
1313  SourceLocation getBeginLoc() const LLVM_READONLY;
1314  SourceLocation getEndLoc() const LLVM_READONLY;
1315 
1316  /// Determine whether this declaration reference was preceded by a
1317  /// C++ nested-name-specifier, e.g., \c N::foo.
1318  bool hasQualifier() const { return DeclRefExprBits.HasQualifier; }
1319 
1320  /// If the name was qualified, retrieves the nested-name-specifier
1321  /// that precedes the name, with source-location information.
1323  if (!hasQualifier())
1324  return NestedNameSpecifierLoc();
1325  return *getTrailingObjects<NestedNameSpecifierLoc>();
1326  }
1327 
1328  /// If the name was qualified, retrieves the nested-name-specifier
1329  /// that precedes the name. Otherwise, returns NULL.
1332  }
1333 
1334  /// Get the NamedDecl through which this reference occurred.
1335  ///
1336  /// This Decl may be different from the ValueDecl actually referred to in the
1337  /// presence of using declarations, etc. It always returns non-NULL, and may
1338  /// simple return the ValueDecl when appropriate.
1339 
1341  return hasFoundDecl() ? *getTrailingObjects<NamedDecl *>() : D;
1342  }
1343 
1344  /// Get the NamedDecl through which this reference occurred.
1345  /// See non-const variant.
1346  const NamedDecl *getFoundDecl() const {
1347  return hasFoundDecl() ? *getTrailingObjects<NamedDecl *>() : D;
1348  }
1349 
1351  return DeclRefExprBits.HasTemplateKWAndArgsInfo;
1352  }
1353 
1354  /// Retrieve the location of the template keyword preceding
1355  /// this name, if any.
1357  if (!hasTemplateKWAndArgsInfo())
1358  return SourceLocation();
1359  return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->TemplateKWLoc;
1360  }
1361 
1362  /// Retrieve the location of the left angle bracket starting the
1363  /// explicit template argument list following the name, if any.
1365  if (!hasTemplateKWAndArgsInfo())
1366  return SourceLocation();
1367  return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->LAngleLoc;
1368  }
1369 
1370  /// Retrieve the location of the right angle bracket ending the
1371  /// explicit template argument list following the name, if any.
1373  if (!hasTemplateKWAndArgsInfo())
1374  return SourceLocation();
1375  return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->RAngleLoc;
1376  }
1377 
1378  /// Determines whether the name in this declaration reference
1379  /// was preceded by the template keyword.
1380  bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
1381 
1382  /// Determines whether this declaration reference was followed by an
1383  /// explicit template argument list.
1384  bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
1385 
1386  /// Copies the template arguments (if present) into the given
1387  /// structure.
1390  getTrailingObjects<ASTTemplateKWAndArgsInfo>()->copyInto(
1391  getTrailingObjects<TemplateArgumentLoc>(), List);
1392  }
1393 
1394  /// Retrieve the template arguments provided as part of this
1395  /// template-id.
1397  if (!hasExplicitTemplateArgs())
1398  return nullptr;
1399  return getTrailingObjects<TemplateArgumentLoc>();
1400  }
1401 
1402  /// Retrieve the number of template arguments provided as part of this
1403  /// template-id.
1404  unsigned getNumTemplateArgs() const {
1405  if (!hasExplicitTemplateArgs())
1406  return 0;
1407  return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs;
1408  }
1409 
1411  return {getTemplateArgs(), getNumTemplateArgs()};
1412  }
1413 
1414  /// Returns true if this expression refers to a function that
1415  /// was resolved from an overloaded set having size greater than 1.
1416  bool hadMultipleCandidates() const {
1417  return DeclRefExprBits.HadMultipleCandidates;
1418  }
1419  /// Sets the flag telling whether this expression refers to
1420  /// a function that was resolved from an overloaded set having size
1421  /// greater than 1.
1422  void setHadMultipleCandidates(bool V = true) {
1423  DeclRefExprBits.HadMultipleCandidates = V;
1424  }
1425 
1426  /// Is this expression a non-odr-use reference, and if so, why?
1428  return static_cast<NonOdrUseReason>(DeclRefExprBits.NonOdrUseReason);
1429  }
1430 
1431  /// Does this DeclRefExpr refer to an enclosing local or a captured
1432  /// variable?
1434  return DeclRefExprBits.RefersToEnclosingVariableOrCapture;
1435  }
1436 
1437  static bool classof(const Stmt *T) {
1438  return T->getStmtClass() == DeclRefExprClass;
1439  }
1440 
1441  // Iterators
1444  }
1445 
1448  }
1449 };
1450 
1451 /// Used by IntegerLiteral/FloatingLiteral to store the numeric without
1452 /// leaking memory.
1453 ///
1454 /// For large floats/integers, APFloat/APInt will allocate memory from the heap
1455 /// to represent these numbers. Unfortunately, when we use a BumpPtrAllocator
1456 /// to allocate IntegerLiteral/FloatingLiteral nodes the memory associated with
1457 /// the APFloat/APInt values will never get freed. APNumericStorage uses
1458 /// ASTContext's allocator for memory allocation.
1460  union {
1461  uint64_t VAL; ///< Used to store the <= 64 bits integer value.
1462  uint64_t *pVal; ///< Used to store the >64 bits integer value.
1463  };
1464  unsigned BitWidth;
1465 
1466  bool hasAllocation() const { return llvm::APInt::getNumWords(BitWidth) > 1; }
1467 
1468  APNumericStorage(const APNumericStorage &) = delete;
1469  void operator=(const APNumericStorage &) = delete;
1470 
1471 protected:
1472  APNumericStorage() : VAL(0), BitWidth(0) { }
1473 
1475  unsigned NumWords = llvm::APInt::getNumWords(BitWidth);
1476  if (NumWords > 1)
1477  return llvm::APInt(BitWidth, NumWords, pVal);
1478  else
1479  return llvm::APInt(BitWidth, VAL);
1480  }
1481  void setIntValue(const ASTContext &C, const llvm::APInt &Val);
1482 };
1483 
1485 public:
1486  llvm::APInt getValue() const { return getIntValue(); }
1487  void setValue(const ASTContext &C, const llvm::APInt &Val) {
1488  setIntValue(C, Val);
1489  }
1490 };
1491 
1493 public:
1494  llvm::APFloat getValue(const llvm::fltSemantics &Semantics) const {
1495  return llvm::APFloat(Semantics, getIntValue());
1496  }
1497  void setValue(const ASTContext &C, const llvm::APFloat &Val) {
1498  setIntValue(C, Val.bitcastToAPInt());
1499  }
1500 };
1501 
1502 class IntegerLiteral : public Expr, public APIntStorage {
1503  SourceLocation Loc;
1504 
1505  /// Construct an empty integer literal.
1506  explicit IntegerLiteral(EmptyShell Empty)
1507  : Expr(IntegerLiteralClass, Empty) { }
1508 
1509 public:
1510  // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy,
1511  // or UnsignedLongLongTy
1512  IntegerLiteral(const ASTContext &C, const llvm::APInt &V, QualType type,
1513  SourceLocation l);
1514 
1515  /// Returns a new integer literal with value 'V' and type 'type'.
1516  /// \param type - either IntTy, LongTy, LongLongTy, UnsignedIntTy,
1517  /// UnsignedLongTy, or UnsignedLongLongTy which should match the size of V
1518  /// \param V - the value that the returned integer literal contains.
1519  static IntegerLiteral *Create(const ASTContext &C, const llvm::APInt &V,
1521  /// Returns a new empty integer literal.
1522  static IntegerLiteral *Create(const ASTContext &C, EmptyShell Empty);
1523 
1524  SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
1525  SourceLocation getEndLoc() const LLVM_READONLY { return Loc; }
1526 
1527  /// Retrieve the location of the literal.
1528  SourceLocation getLocation() const { return Loc; }
1529 
1530  void setLocation(SourceLocation Location) { Loc = Location; }
1531 
1532  static bool classof(const Stmt *T) {
1533  return T->getStmtClass() == IntegerLiteralClass;
1534  }
1535 
1536  // Iterators
1539  }
1542  }
1543 };
1544 
1545 class FixedPointLiteral : public Expr, public APIntStorage {
1546  SourceLocation Loc;
1547  unsigned Scale;
1548 
1549  /// \brief Construct an empty fixed-point literal.
1550  explicit FixedPointLiteral(EmptyShell Empty)
1551  : Expr(FixedPointLiteralClass, Empty) {}
1552 
1553  public:
1555  SourceLocation l, unsigned Scale);
1556 
1557  // Store the int as is without any bit shifting.
1559  const llvm::APInt &V,
1561  unsigned Scale);
1562 
1563  /// Returns an empty fixed-point literal.
1564  static FixedPointLiteral *Create(const ASTContext &C, EmptyShell Empty);
1565 
1566  SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
1567  SourceLocation getEndLoc() const LLVM_READONLY { return Loc; }
1568 
1569  /// \brief Retrieve the location of the literal.
1570  SourceLocation getLocation() const { return Loc; }
1571 
1572  void setLocation(SourceLocation Location) { Loc = Location; }
1573 
1574  unsigned getScale() const { return Scale; }
1575  void setScale(unsigned S) { Scale = S; }
1576 
1577  static bool classof(const Stmt *T) {
1578  return T->getStmtClass() == FixedPointLiteralClass;
1579  }
1580 
1581  std::string getValueAsString(unsigned Radix) const;
1582 
1583  // Iterators
1586  }
1589  }
1590 };
1591 
1592 class CharacterLiteral : public Expr {
1593 public:
1600  };
1601 
1602 private:
1603  unsigned Value;
1604  SourceLocation Loc;
1605 public:
1606  // type should be IntTy
1608  SourceLocation l)
1609  : Expr(CharacterLiteralClass, type, VK_PRValue, OK_Ordinary),
1610  Value(value), Loc(l) {
1611  CharacterLiteralBits.Kind = kind;
1613  }
1614 
1615  /// Construct an empty character literal.
1616  CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { }
1617 
1618  SourceLocation getLocation() const { return Loc; }
1620  return static_cast<CharacterKind>(CharacterLiteralBits.Kind);
1621  }
1622 
1623  SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
1624  SourceLocation getEndLoc() const LLVM_READONLY { return Loc; }
1625 
1626  unsigned getValue() const { return Value; }
1627 
1628  void setLocation(SourceLocation Location) { Loc = Location; }
1630  void setValue(unsigned Val) { Value = Val; }
1631 
1632  static bool classof(const Stmt *T) {
1633  return T->getStmtClass() == CharacterLiteralClass;
1634  }
1635 
1636  static void print(unsigned val, CharacterKind Kind, raw_ostream &OS);
1637 
1638  // Iterators
1641  }
1644  }
1645 };
1646 
1647 class FloatingLiteral : public Expr, private APFloatStorage {
1648  SourceLocation Loc;
1649 
1650  FloatingLiteral(const ASTContext &C, const llvm::APFloat &V, bool isexact,
1652 
1653  /// Construct an empty floating-point literal.
1654  explicit FloatingLiteral(const ASTContext &C, EmptyShell Empty);
1655 
1656 public:
1657  static FloatingLiteral *Create(const ASTContext &C, const llvm::APFloat &V,
1658  bool isexact, QualType Type, SourceLocation L);
1659  static FloatingLiteral *Create(const ASTContext &C, EmptyShell Empty);
1660 
1661  llvm::APFloat getValue() const {
1663  }
1664  void setValue(const ASTContext &C, const llvm::APFloat &Val) {
1665  assert(&getSemantics() == &Val.getSemantics() && "Inconsistent semantics");
1666  APFloatStorage::setValue(C, Val);
1667  }
1668 
1669  /// Get a raw enumeration value representing the floating-point semantics of
1670  /// this literal (32-bit IEEE, x87, ...), suitable for serialisation.
1671  llvm::APFloatBase::Semantics getRawSemantics() const {
1672  return static_cast<llvm::APFloatBase::Semantics>(
1673  FloatingLiteralBits.Semantics);
1674  }
1675 
1676  /// Set the raw enumeration value representing the floating-point semantics of
1677  /// this literal (32-bit IEEE, x87, ...), suitable for serialisation.
1678  void setRawSemantics(llvm::APFloatBase::Semantics Sem) {
1679  FloatingLiteralBits.Semantics = Sem;
1680  }
1681 
1682  /// Return the APFloat semantics this literal uses.
1683  const llvm::fltSemantics &getSemantics() const {
1684  return llvm::APFloatBase::EnumToSemantics(
1685  static_cast<llvm::APFloatBase::Semantics>(
1686  FloatingLiteralBits.Semantics));
1687  }
1688 
1689  /// Set the APFloat semantics this literal uses.
1690  void setSemantics(const llvm::fltSemantics &Sem) {
1691  FloatingLiteralBits.Semantics = llvm::APFloatBase::SemanticsToEnum(Sem);
1692  }
1693 
1694  bool isExact() const { return FloatingLiteralBits.IsExact; }
1695  void setExact(bool E) { FloatingLiteralBits.IsExact = E; }
1696 
1697  /// getValueAsApproximateDouble - This returns the value as an inaccurate
1698  /// double. Note that this may cause loss of precision, but is useful for
1699  /// debugging dumps, etc.
1700  double getValueAsApproximateDouble() const;
1701 
1702  SourceLocation getLocation() const { return Loc; }
1703  void setLocation(SourceLocation L) { Loc = L; }
1704 
1705  SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
1706  SourceLocation getEndLoc() const LLVM_READONLY { return Loc; }
1707 
1708  static bool classof(const Stmt *T) {
1709  return T->getStmtClass() == FloatingLiteralClass;
1710  }
1711 
1712  // Iterators
1715  }
1718  }
1719 };
1720 
1721 /// ImaginaryLiteral - We support imaginary integer and floating point literals,
1722 /// like "1.0i". We represent these as a wrapper around FloatingLiteral and
1723 /// IntegerLiteral classes. Instances of this class always have a Complex type
1724 /// whose element type matches the subexpression.
1725 ///
1726 class ImaginaryLiteral : public Expr {
1727  Stmt *Val;
1728 public:
1730  : Expr(ImaginaryLiteralClass, Ty, VK_PRValue, OK_Ordinary), Val(val) {
1732  }
1733 
1734  /// Build an empty imaginary literal.
1736  : Expr(ImaginaryLiteralClass, Empty) { }
1737 
1738  const Expr *getSubExpr() const { return cast<Expr>(Val); }
1739  Expr *getSubExpr() { return cast<Expr>(Val); }
1740  void setSubExpr(Expr *E) { Val = E; }
1741 
1742  SourceLocation getBeginLoc() const LLVM_READONLY {
1743  return Val->getBeginLoc();
1744  }
1745  SourceLocation getEndLoc() const LLVM_READONLY { return Val->getEndLoc(); }
1746 
1747  static bool classof(const Stmt *T) {
1748  return T->getStmtClass() == ImaginaryLiteralClass;
1749  }
1750 
1751  // Iterators
1752  child_range children() { return child_range(&Val, &Val+1); }
1754  return const_child_range(&Val, &Val + 1);
1755  }
1756 };
1757 
1758 /// StringLiteral - This represents a string literal expression, e.g. "foo"
1759 /// or L"bar" (wide strings). The actual string data can be obtained with
1760 /// getBytes() and is NOT null-terminated. The length of the string data is
1761 /// determined by calling getByteLength().
1762 ///
1763 /// The C type for a string is always a ConstantArrayType. In C++, the char
1764 /// type is const qualified, in C it is not.
1765 ///
1766 /// Note that strings in C can be formed by concatenation of multiple string
1767 /// literal pptokens in translation phase #6. This keeps track of the locations
1768 /// of each of these pieces.
1769 ///
1770 /// Strings in C can also be truncated and extended by assigning into arrays,
1771 /// e.g. with constructs like:
1772 /// char X[2] = "foobar";
1773 /// In this case, getByteLength() will return 6, but the string literal will
1774 /// have type "char[2]".
1775 class StringLiteral final
1776  : public Expr,
1777  private llvm::TrailingObjects<StringLiteral, unsigned, SourceLocation,
1778  char> {
1779  friend class ASTStmtReader;
1780  friend TrailingObjects;
1781 
1782  /// StringLiteral is followed by several trailing objects. They are in order:
1783  ///
1784  /// * A single unsigned storing the length in characters of this string. The
1785  /// length in bytes is this length times the width of a single character.
1786  /// Always present and stored as a trailing objects because storing it in
1787  /// StringLiteral would increase the size of StringLiteral by sizeof(void *)
1788  /// due to alignment requirements. If you add some data to StringLiteral,
1789  /// consider moving it inside StringLiteral.
1790  ///
1791  /// * An array of getNumConcatenated() SourceLocation, one for each of the
1792  /// token this string is made of.
1793  ///
1794  /// * An array of getByteLength() char used to store the string data.
1795 
1796 public:
1798 
1799 private:
1800  unsigned numTrailingObjects(OverloadToken<unsigned>) const { return 1; }
1801  unsigned numTrailingObjects(OverloadToken<SourceLocation>) const {
1802  return getNumConcatenated();
1803  }
1804 
1805  unsigned numTrailingObjects(OverloadToken<char>) const {
1806  return getByteLength();
1807  }
1808 
1809  char *getStrDataAsChar() { return getTrailingObjects<char>(); }
1810  const char *getStrDataAsChar() const { return getTrailingObjects<char>(); }
1811 
1812  const uint16_t *getStrDataAsUInt16() const {
1813  return reinterpret_cast<const uint16_t *>(getTrailingObjects<char>());
1814  }
1815 
1816  const uint32_t *getStrDataAsUInt32() const {
1817  return reinterpret_cast<const uint32_t *>(getTrailingObjects<char>());
1818  }
1819 
1820  /// Build a string literal.
1821  StringLiteral(const ASTContext &Ctx, StringRef Str, StringKind Kind,
1822  bool Pascal, QualType Ty, const SourceLocation *Loc,
1823  unsigned NumConcatenated);
1824 
1825  /// Build an empty string literal.
1826  StringLiteral(EmptyShell Empty, unsigned NumConcatenated, unsigned Length,
1827  unsigned CharByteWidth);
1828 
1829  /// Map a target and string kind to the appropriate character width.
1830  static unsigned mapCharByteWidth(TargetInfo const &Target, StringKind SK);
1831 
1832  /// Set one of the string literal token.
1833  void setStrTokenLoc(unsigned TokNum, SourceLocation L) {
1834  assert(TokNum < getNumConcatenated() && "Invalid tok number");
1835  getTrailingObjects<SourceLocation>()[TokNum] = L;
1836  }
1837 
1838 public:
1839  /// This is the "fully general" constructor that allows representation of
1840  /// strings formed from multiple concatenated tokens.
1841  static StringLiteral *Create(const ASTContext &Ctx, StringRef Str,
1842  StringKind Kind, bool Pascal, QualType Ty,
1843  const SourceLocation *Loc,
1844  unsigned NumConcatenated);
1845 
1846  /// Simple constructor for string literals made from one token.
1847  static StringLiteral *Create(const ASTContext &Ctx, StringRef Str,
1848  StringKind Kind, bool Pascal, QualType Ty,
1849  SourceLocation Loc) {
1850  return Create(Ctx, Str, Kind, Pascal, Ty, &Loc, 1);
1851  }
1852 
1853  /// Construct an empty string literal.
1854  static StringLiteral *CreateEmpty(const ASTContext &Ctx,
1855  unsigned NumConcatenated, unsigned Length,
1856  unsigned CharByteWidth);
1857 
1858  StringRef getString() const {
1859  assert(getCharByteWidth() == 1 &&
1860  "This function is used in places that assume strings use char");
1861  return StringRef(getStrDataAsChar(), getByteLength());
1862  }
1863 
1864  /// Allow access to clients that need the byte representation, such as
1865  /// ASTWriterStmt::VisitStringLiteral().
1866  StringRef getBytes() const {
1867  // FIXME: StringRef may not be the right type to use as a result for this.
1868  return StringRef(getStrDataAsChar(), getByteLength());
1869  }
1870 
1871  void outputString(raw_ostream &OS) const;
1872 
1873  uint32_t getCodeUnit(size_t i) const {
1874  assert(i < getLength() && "out of bounds access");
1875  switch (getCharByteWidth()) {
1876  case 1:
1877  return static_cast<unsigned char>(getStrDataAsChar()[i]);
1878  case 2:
1879  return getStrDataAsUInt16()[i];
1880  case 4:
1881  return getStrDataAsUInt32()[i];
1882  }
1883  llvm_unreachable("Unsupported character width!");
1884  }
1885 
1886  unsigned getByteLength() const { return getCharByteWidth() * getLength(); }
1887  unsigned getLength() const { return *getTrailingObjects<unsigned>(); }
1888  unsigned getCharByteWidth() const { return StringLiteralBits.CharByteWidth; }
1889 
1891  return static_cast<StringKind>(StringLiteralBits.Kind);
1892  }
1893 
1894  bool isOrdinary() const { return getKind() == Ordinary; }
1895  bool isWide() const { return getKind() == Wide; }
1896  bool isUTF8() const { return getKind() == UTF8; }
1897  bool isUTF16() const { return getKind() == UTF16; }
1898  bool isUTF32() const { return getKind() == UTF32; }
1899  bool isPascal() const { return StringLiteralBits.IsPascal; }
1900 
1901  bool containsNonAscii() const {
1902  for (auto c : getString())
1903  if (!isASCII(c))
1904  return true;
1905  return false;
1906  }
1907 
1908  bool containsNonAsciiOrNull() const {
1909  for (auto c : getString())
1910  if (!isASCII(c) || !c)
1911  return true;
1912  return false;
1913  }
1914 
1915  /// getNumConcatenated - Get the number of string literal tokens that were
1916  /// concatenated in translation phase #6 to form this string literal.
1917  unsigned getNumConcatenated() const {
1918  return StringLiteralBits.NumConcatenated;
1919  }
1920 
1921  /// Get one of the string literal token.
1922  SourceLocation getStrTokenLoc(unsigned TokNum) const {
1923  assert(TokNum < getNumConcatenated() && "Invalid tok number");
1924  return getTrailingObjects<SourceLocation>()[TokNum];
1925  }
1926 
1927  /// getLocationOfByte - Return a source location that points to the specified
1928  /// byte of this string literal.
1929  ///
1930  /// Strings are amazingly complex. They can be formed from multiple tokens
1931  /// and can have escape sequences in them in addition to the usual trigraph
1932  /// and escaped newline business. This routine handles this complexity.
1933  ///
1935  getLocationOfByte(unsigned ByteNo, const SourceManager &SM,
1936  const LangOptions &Features, const TargetInfo &Target,
1937  unsigned *StartToken = nullptr,
1938  unsigned *StartTokenByteOffset = nullptr) const;
1939 
1941 
1943  return getTrailingObjects<SourceLocation>();
1944  }
1945 
1947  return getTrailingObjects<SourceLocation>() + getNumConcatenated();
1948  }
1949 
1950  SourceLocation getBeginLoc() const LLVM_READONLY { return *tokloc_begin(); }
1951  SourceLocation getEndLoc() const LLVM_READONLY { return *(tokloc_end() - 1); }
1952 
1953  static bool classof(const Stmt *T) {
1954  return T->getStmtClass() == StringLiteralClass;
1955  }
1956 
1957  // Iterators
1960  }
1963  }
1964 };
1965 
1966 /// [C99 6.4.2.2] - A predefined identifier such as __func__.
1967 class PredefinedExpr final
1968  : public Expr,
1969  private llvm::TrailingObjects<PredefinedExpr, Stmt *> {
1970  friend class ASTStmtReader;
1971  friend TrailingObjects;
1972 
1973  // PredefinedExpr is optionally followed by a single trailing
1974  // "Stmt *" for the predefined identifier. It is present if and only if
1975  // hasFunctionName() is true and is always a "StringLiteral *".
1976 
1977 public:
1978  enum IdentKind {
1981  LFunction, // Same as Function, but as wide string.
1984  LFuncSig, // Same as FuncSig, but as as wide string
1986  /// The same as PrettyFunction, except that the
1987  /// 'virtual' keyword is omitted for virtual member functions.
1989  };
1990 
1991 private:
1993  StringLiteral *SL);
1994 
1995  explicit PredefinedExpr(EmptyShell Empty, bool HasFunctionName);
1996 
1997  /// True if this PredefinedExpr has storage for a function name.
1998  bool hasFunctionName() const { return PredefinedExprBits.HasFunctionName; }
1999 
2000  void setFunctionName(StringLiteral *SL) {
2001  assert(hasFunctionName() &&
2002  "This PredefinedExpr has no storage for a function name!");
2003  *getTrailingObjects<Stmt *>() = SL;
2004  }
2005 
2006 public:
2007  /// Create a PredefinedExpr.
2008  static PredefinedExpr *Create(const ASTContext &Ctx, SourceLocation L,
2009  QualType FNTy, IdentKind IK, StringLiteral *SL);
2010 
2011  /// Create an empty PredefinedExpr.
2012  static PredefinedExpr *CreateEmpty(const ASTContext &Ctx,
2013  bool HasFunctionName);
2014 
2016  return static_cast<IdentKind>(PredefinedExprBits.Kind);
2017  }
2018 
2021 
2023  return hasFunctionName()
2024  ? static_cast<StringLiteral *>(*getTrailingObjects<Stmt *>())
2025  : nullptr;
2026  }
2027 
2029  return hasFunctionName()
2030  ? static_cast<StringLiteral *>(*getTrailingObjects<Stmt *>())
2031  : nullptr;
2032  }
2033 
2034  static StringRef getIdentKindName(IdentKind IK);
2035  StringRef getIdentKindName() const {
2036  return getIdentKindName(getIdentKind());
2037  }
2038 
2039  static std::string ComputeName(IdentKind IK, const Decl *CurrentDecl);
2040 
2042  SourceLocation getEndLoc() const { return getLocation(); }
2043 
2044  static bool classof(const Stmt *T) {
2045  return T->getStmtClass() == PredefinedExprClass;
2046  }
2047 
2048  // Iterators
2050  return child_range(getTrailingObjects<Stmt *>(),
2051  getTrailingObjects<Stmt *>() + hasFunctionName());
2052  }
2053 
2055  return const_child_range(getTrailingObjects<Stmt *>(),
2056  getTrailingObjects<Stmt *>() + hasFunctionName());
2057  }
2058 };
2059 
2060 // This represents a use of the __builtin_sycl_unique_stable_name, which takes a
2061 // type-id, and at CodeGen time emits a unique string representation of the
2062 // type in a way that permits us to properly encode information about the SYCL
2063 // kernels.
2064 class SYCLUniqueStableNameExpr final : public Expr {
2065  friend class ASTStmtReader;
2066  SourceLocation OpLoc, LParen, RParen;
2068 
2069  SYCLUniqueStableNameExpr(EmptyShell Empty, QualType ResultTy);
2071  SourceLocation RParen, QualType ResultTy,
2072  TypeSourceInfo *TSI);
2073 
2074  void setTypeSourceInfo(TypeSourceInfo *Ty) { TypeInfo = Ty; }
2075 
2076  void setLocation(SourceLocation L) { OpLoc = L; }
2077  void setLParenLocation(SourceLocation L) { LParen = L; }
2078  void setRParenLocation(SourceLocation L) { RParen = L; }
2079 
2080 public:
2082 
2083  const TypeSourceInfo *getTypeSourceInfo() const { return TypeInfo; }
2084 
2085  static SYCLUniqueStableNameExpr *
2086  Create(const ASTContext &Ctx, SourceLocation OpLoc, SourceLocation LParen,
2087  SourceLocation RParen, TypeSourceInfo *TSI);
2088 
2089  static SYCLUniqueStableNameExpr *CreateEmpty(const ASTContext &Ctx);
2090 
2092  SourceLocation getEndLoc() const { return RParen; }
2093  SourceLocation getLocation() const { return OpLoc; }
2094  SourceLocation getLParenLocation() const { return LParen; }
2095  SourceLocation getRParenLocation() const { return RParen; }
2096 
2097  static bool classof(const Stmt *T) {
2098  return T->getStmtClass() == SYCLUniqueStableNameExprClass;
2099  }
2100 
2101  // Iterators
2104  }
2105 
2108  }
2109 
2110  // Convenience function to generate the name of the currently stored type.
2111  std::string ComputeName(ASTContext &Context) const;
2112 
2113  // Get the generated name of the type. Note that this only works after all
2114  // kernels have been instantiated.
2115  static std::string ComputeName(ASTContext &Context, QualType Ty);
2116 };
2117 
2118 /// ParenExpr - This represents a parethesized expression, e.g. "(1)". This
2119 /// AST node is only formed if full location information is requested.
2120 class ParenExpr : public Expr {
2121  SourceLocation L, R;
2122  Stmt *Val;
2123 public:
2125  : Expr(ParenExprClass, val->getType(), val->getValueKind(),
2126  val->getObjectKind()),
2127  L(l), R(r), Val(val) {
2129  }
2130 
2131  /// Construct an empty parenthesized expression.
2132  explicit ParenExpr(EmptyShell Empty)
2133  : Expr(ParenExprClass, Empty) { }
2134 
2135  const Expr *getSubExpr() const { return cast<Expr>(Val); }
2136  Expr *getSubExpr() { return cast<Expr>(Val); }
2137  void setSubExpr(Expr *E) { Val = E; }
2138 
2139  SourceLocation getBeginLoc() const LLVM_READONLY { return L; }
2140  SourceLocation getEndLoc() const LLVM_READONLY { return R; }
2141 
2142  /// Get the location of the left parentheses '('.
2143  SourceLocation getLParen() const { return L; }
2144  void setLParen(SourceLocation Loc) { L = Loc; }
2145 
2146  /// Get the location of the right parentheses ')'.
2147  SourceLocation getRParen() const { return R; }
2148  void setRParen(SourceLocation Loc) { R = Loc; }
2149 
2150  static bool classof(const Stmt *T) {
2151  return T->getStmtClass() == ParenExprClass;
2152  }
2153 
2154  // Iterators
2155  child_range children() { return child_range(&Val, &Val+1); }
2157  return const_child_range(&Val, &Val + 1);
2158  }
2159 };
2160 
2161 /// UnaryOperator - This represents the unary-expression's (except sizeof and
2162 /// alignof), the postinc/postdec operators from postfix-expression, and various
2163 /// extensions.
2164 ///
2165 /// Notes on various nodes:
2166 ///
2167 /// Real/Imag - These return the real/imag part of a complex operand. If
2168 /// applied to a non-complex value, the former returns its operand and the
2169 /// later returns zero in the type of the operand.
2170 ///
2171 class UnaryOperator final
2172  : public Expr,
2173  private llvm::TrailingObjects<UnaryOperator, FPOptionsOverride> {
2174  Stmt *Val;
2175 
2176  size_t numTrailingObjects(OverloadToken<FPOptionsOverride>) const {
2177  return UnaryOperatorBits.HasFPFeatures ? 1 : 0;
2178  }
2179 
2180  FPOptionsOverride &getTrailingFPFeatures() {
2181  assert(UnaryOperatorBits.HasFPFeatures);
2182  return *getTrailingObjects<FPOptionsOverride>();
2183  }
2184 
2185  const FPOptionsOverride &getTrailingFPFeatures() const {
2186  assert(UnaryOperatorBits.HasFPFeatures);
2187  return *getTrailingObjects<FPOptionsOverride>();
2188  }
2189 
2190 public:
2192 
2193 protected:
2194  UnaryOperator(const ASTContext &Ctx, Expr *input, Opcode opc, QualType type,
2196  bool CanOverflow, FPOptionsOverride FPFeatures);
2197 
2198  /// Build an empty unary operator.
2199  explicit UnaryOperator(bool HasFPFeatures, EmptyShell Empty)
2200  : Expr(UnaryOperatorClass, Empty) {
2201  UnaryOperatorBits.Opc = UO_AddrOf;
2202  UnaryOperatorBits.HasFPFeatures = HasFPFeatures;
2203  }
2204 
2205 public:
2206  static UnaryOperator *CreateEmpty(const ASTContext &C, bool hasFPFeatures);
2207 
2208  static UnaryOperator *Create(const ASTContext &C, Expr *input, Opcode opc,
2211  bool CanOverflow, FPOptionsOverride FPFeatures);
2212 
2213  Opcode getOpcode() const {
2214  return static_cast<Opcode>(UnaryOperatorBits.Opc);
2215  }
2216  void setOpcode(Opcode Opc) { UnaryOperatorBits.Opc = Opc; }
2217 
2218  Expr *getSubExpr() const { return cast<Expr>(Val); }
2219  void setSubExpr(Expr *E) { Val = E; }
2220 
2221  /// getOperatorLoc - Return the location of the operator.
2224 
2225  /// Returns true if the unary operator can cause an overflow. For instance,
2226  /// signed int i = INT_MAX; i++;
2227  /// signed char c = CHAR_MAX; c++;
2228  /// Due to integer promotions, c++ is promoted to an int before the postfix
2229  /// increment, and the result is an int that cannot overflow. However, i++
2230  /// can overflow.
2231  bool canOverflow() const { return UnaryOperatorBits.CanOverflow; }
2232  void setCanOverflow(bool C) { UnaryOperatorBits.CanOverflow = C; }
2233 
2234  // Get the FP contractability status of this operator. Only meaningful for
2235  // operations on floating point types.
2238  }
2239 
2240  // Get the FENV_ACCESS status of this operator. Only meaningful for
2241  // operations on floating point types.
2242  bool isFEnvAccessOn(const LangOptions &LO) const {
2243  return getFPFeaturesInEffect(LO).getAllowFEnvAccess();
2244  }
2245 
2246  /// isPostfix - Return true if this is a postfix operation, like x++.
2247  static bool isPostfix(Opcode Op) {
2248  return Op == UO_PostInc || Op == UO_PostDec;
2249  }
2250 
2251  /// isPrefix - Return true if this is a prefix operation, like --x.
2252  static bool isPrefix(Opcode Op) {
2253  return Op == UO_PreInc || Op == UO_PreDec;
2254  }
2255 
2256  bool isPrefix() const { return isPrefix(getOpcode()); }
2257  bool isPostfix() const { return isPostfix(getOpcode()); }
2258 
2259  static bool isIncrementOp(Opcode Op) {
2260  return Op == UO_PreInc || Op == UO_PostInc;
2261  }
2262  bool isIncrementOp() const {
2263  return isIncrementOp(getOpcode());
2264  }
2265 
2266  static bool isDecrementOp(Opcode Op) {
2267  return Op == UO_PreDec || Op == UO_PostDec;
2268  }
2269  bool isDecrementOp() const {
2270  return isDecrementOp(getOpcode());
2271  }
2272 
2273  static bool isIncrementDecrementOp(Opcode Op) { return Op <= UO_PreDec; }
2274  bool isIncrementDecrementOp() const {
2276  }
2277 
2278  static bool isArithmeticOp(Opcode Op) {
2279  return Op >= UO_Plus && Op <= UO_LNot;
2280  }
2281  bool isArithmeticOp() const { return isArithmeticOp(getOpcode()); }
2282 
2283  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
2284  /// corresponds to, e.g. "sizeof" or "[pre]++"
2285  static StringRef getOpcodeStr(Opcode Op);
2286 
2287  /// Retrieve the unary opcode that corresponds to the given
2288  /// overloaded operator.
2289  static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix);
2290 
2291  /// Retrieve the overloaded operator kind that corresponds to
2292  /// the given unary opcode.
2294 
2295  SourceLocation getBeginLoc() const LLVM_READONLY {
2296  return isPostfix() ? Val->getBeginLoc() : getOperatorLoc();
2297  }
2298  SourceLocation getEndLoc() const LLVM_READONLY {
2299  return isPostfix() ? getOperatorLoc() : Val->getEndLoc();
2300  }
2302 
2303  static bool classof(const Stmt *T) {
2304  return T->getStmtClass() == UnaryOperatorClass;
2305  }
2306 
2307  // Iterators
2308  child_range children() { return child_range(&Val, &Val+1); }
2310  return const_child_range(&Val, &Val + 1);
2311  }
2312 
2313  /// Is FPFeatures in Trailing Storage?
2314  bool hasStoredFPFeatures() const { return UnaryOperatorBits.HasFPFeatures; }
2315 
2316  /// Get FPFeatures from trailing storage.
2318  return getTrailingFPFeatures();
2319  }
2320 
2321 protected:
2322  /// Set FPFeatures in trailing storage, used only by Serialization
2323  void setStoredFPFeatures(FPOptionsOverride F) { getTrailingFPFeatures() = F; }
2324 
2325 public:
2326  // Get the FP features status of this operator. Only meaningful for
2327  // operations on floating point types.
2329  if (UnaryOperatorBits.HasFPFeatures)
2330  return getStoredFPFeatures().applyOverrides(LO);
2332  }
2334  if (UnaryOperatorBits.HasFPFeatures)
2335  return getStoredFPFeatures();
2336  return FPOptionsOverride();
2337  }
2338 
2340  friend class ASTReader;
2341  friend class ASTStmtReader;
2342  friend class ASTStmtWriter;
2343 };
2344 
2345 /// Helper class for OffsetOfExpr.
2346 
2347 // __builtin_offsetof(type, identifier(.identifier|[expr])*)
2349 public:
2350  /// The kind of offsetof node we have.
2351  enum Kind {
2352  /// An index into an array.
2353  Array = 0x00,
2354  /// A field.
2355  Field = 0x01,
2356  /// A field in a dependent type, known only by its name.
2357  Identifier = 0x02,
2358  /// An implicit indirection through a C++ base class, when the
2359  /// field found is in a base class.
2360  Base = 0x03
2361  };
2362 
2363 private:
2364  enum { MaskBits = 2, Mask = 0x03 };
2365 
2366  /// The source range that covers this part of the designator.
2367  SourceRange Range;
2368 
2369  /// The data describing the designator, which comes in three
2370  /// different forms, depending on the lower two bits.
2371  /// - An unsigned index into the array of Expr*'s stored after this node
2372  /// in memory, for [constant-expression] designators.
2373  /// - A FieldDecl*, for references to a known field.
2374  /// - An IdentifierInfo*, for references to a field with a given name
2375  /// when the class type is dependent.
2376  /// - A CXXBaseSpecifier*, for references that look at a field in a
2377  /// base class.
2378  uintptr_t Data;
2379 
2380 public:
2381  /// Create an offsetof node that refers to an array element.
2382  OffsetOfNode(SourceLocation LBracketLoc, unsigned Index,
2383  SourceLocation RBracketLoc)
2384  : Range(LBracketLoc, RBracketLoc), Data((Index << 2) | Array) {}
2385 
2386  /// Create an offsetof node that refers to a field.
2388  : Range(DotLoc.isValid() ? DotLoc : NameLoc, NameLoc),
2389  Data(reinterpret_cast<uintptr_t>(Field) | OffsetOfNode::Field) {}
2390 
2391  /// Create an offsetof node that refers to an identifier.
2393  SourceLocation NameLoc)
2394  : Range(DotLoc.isValid() ? DotLoc : NameLoc, NameLoc),
2395  Data(reinterpret_cast<uintptr_t>(Name) | Identifier) {}
2396 
2397  /// Create an offsetof node that refers into a C++ base class.
2399  : Data(reinterpret_cast<uintptr_t>(Base) | OffsetOfNode::Base) {}
2400 
2401  /// Determine what kind of offsetof node this is.
2402  Kind getKind() const { return static_cast<Kind>(Data & Mask); }
2403 
2404  /// For an array element node, returns the index into the array
2405  /// of expressions.
2406  unsigned getArrayExprIndex() const {
2407  assert(getKind() == Array);
2408  return Data >> 2;
2409  }
2410 
2411  /// For a field offsetof node, returns the field.
2412  FieldDecl *getField() const {
2413  assert(getKind() == Field);
2414  return reinterpret_cast<FieldDecl *>(Data & ~(uintptr_t)Mask);
2415  }
2416 
2417  /// For a field or identifier offsetof node, returns the name of
2418  /// the field.
2419  IdentifierInfo *getFieldName() const;
2420 
2421  /// For a base class node, returns the base specifier.
2423  assert(getKind() == Base);
2424  return reinterpret_cast<CXXBaseSpecifier *>(Data & ~(uintptr_t)Mask);
2425  }
2426 
2427  /// Retrieve the source range that covers this offsetof node.
2428  ///
2429  /// For an array element node, the source range contains the locations of
2430  /// the square brackets. For a field or identifier node, the source range
2431  /// contains the location of the period (if there is one) and the
2432  /// identifier.
2433  SourceRange getSourceRange() const LLVM_READONLY { return Range; }
2434  SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); }
2435  SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); }
2436 };
2437 
2438 /// OffsetOfExpr - [C99 7.17] - This represents an expression of the form
2439 /// offsetof(record-type, member-designator). For example, given:
2440 /// @code
2441 /// struct S {
2442 /// float f;
2443 /// double d;
2444 /// };
2445 /// struct T {
2446 /// int i;
2447 /// struct S s[10];
2448 /// };
2449 /// @endcode
2450 /// we can represent and evaluate the expression @c offsetof(struct T, s[2].d).
2451 
2452 class OffsetOfExpr final
2453  : public Expr,
2454  private llvm::TrailingObjects<OffsetOfExpr, OffsetOfNode, Expr *> {
2455  SourceLocation OperatorLoc, RParenLoc;
2456  // Base type;
2457  TypeSourceInfo *TSInfo;
2458  // Number of sub-components (i.e. instances of OffsetOfNode).
2459  unsigned NumComps;
2460  // Number of sub-expressions (i.e. array subscript expressions).
2461  unsigned NumExprs;
2462 
2463  size_t numTrailingObjects(OverloadToken<OffsetOfNode>) const {
2464  return NumComps;
2465  }
2466 
2468  SourceLocation OperatorLoc, TypeSourceInfo *tsi,
2470  SourceLocation RParenLoc);
2471 
2472  explicit OffsetOfExpr(unsigned numComps, unsigned numExprs)
2473  : Expr(OffsetOfExprClass, EmptyShell()),
2474  TSInfo(nullptr), NumComps(numComps), NumExprs(numExprs) {}
2475 
2476 public:
2477 
2478  static OffsetOfExpr *Create(const ASTContext &C, QualType type,
2479  SourceLocation OperatorLoc, TypeSourceInfo *tsi,
2480  ArrayRef<OffsetOfNode> comps,
2481  ArrayRef<Expr*> exprs, SourceLocation RParenLoc);
2482 
2483  static OffsetOfExpr *CreateEmpty(const ASTContext &C,
2484  unsigned NumComps, unsigned NumExprs);
2485 
2486  /// getOperatorLoc - Return the location of the operator.
2487  SourceLocation getOperatorLoc() const { return OperatorLoc; }
2488  void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
2489 
2490  /// Return the location of the right parentheses.
2491  SourceLocation getRParenLoc() const { return RParenLoc; }
2492  void setRParenLoc(SourceLocation R) { RParenLoc = R; }
2493 
2495  return TSInfo;
2496  }
2498  TSInfo = tsi;
2499  }
2500 
2501  const OffsetOfNode &getComponent(unsigned Idx) const {
2502  assert(Idx < NumComps && "Subscript out of range");
2503  return getTrailingObjects<OffsetOfNode>()[Idx];
2504  }
2505 
2506  void setComponent(unsigned Idx, OffsetOfNode ON) {
2507  assert(Idx < NumComps && "Subscript out of range");
2508  getTrailingObjects<OffsetOfNode>()[Idx] = ON;
2509  }
2510 
2511  unsigned getNumComponents() const {
2512  return NumComps;
2513  }
2514 
2515  Expr* getIndexExpr(unsigned Idx) {
2516  assert(Idx < NumExprs && "Subscript out of range");
2517  return getTrailingObjects<Expr *>()[Idx];
2518  }
2519 
2520  const Expr *getIndexExpr(unsigned Idx) const {
2521  assert(Idx < NumExprs && "Subscript out of range");
2522  return getTrailingObjects<Expr *>()[Idx];
2523  }
2524 
2525  void setIndexExpr(unsigned Idx, Expr* E) {
2526  assert(Idx < NumComps && "Subscript out of range");
2527  getTrailingObjects<Expr *>()[Idx] = E;
2528  }
2529 
2530  unsigned getNumExpressions() const {
2531  return NumExprs;
2532  }
2533 
2534  SourceLocation getBeginLoc() const LLVM_READONLY { return OperatorLoc; }
2535  SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
2536 
2537  static bool classof(const Stmt *T) {
2538  return T->getStmtClass() == OffsetOfExprClass;
2539  }
2540 
2541  // Iterators
2543  Stmt **begin = reinterpret_cast<Stmt **>(getTrailingObjects<Expr *>());
2544  return child_range(begin, begin + NumExprs);
2545  }
2547  Stmt *const *begin =
2548  reinterpret_cast<Stmt *const *>(getTrailingObjects<Expr *>());
2549  return const_child_range(begin, begin + NumExprs);
2550  }
2552 };
2553 
2554 /// UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated)
2555 /// expression operand. Used for sizeof/alignof (C99 6.5.3.4) and
2556 /// vec_step (OpenCL 1.1 6.11.12).
2558  union {
2561  } Argument;
2562  SourceLocation OpLoc, RParenLoc;
2563 
2564 public:
2566  QualType resultType, SourceLocation op,
2567  SourceLocation rp)
2568  : Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_PRValue,
2569  OK_Ordinary),
2570  OpLoc(op), RParenLoc(rp) {
2571  assert(ExprKind <= UETT_Last && "invalid enum value!");
2572  UnaryExprOrTypeTraitExprBits.Kind = ExprKind;
2573  assert(static_cast<unsigned>(ExprKind) ==
2575  "UnaryExprOrTypeTraitExprBits.Kind overflow!");
2576  UnaryExprOrTypeTraitExprBits.IsType = true;
2577  Argument.Ty = TInfo;
2579  }
2580 
2582  QualType resultType, SourceLocation op,
2583  SourceLocation rp);
2584 
2585  /// Construct an empty sizeof/alignof expression.
2587  : Expr(UnaryExprOrTypeTraitExprClass, Empty) { }
2588 
2590  return static_cast<UnaryExprOrTypeTrait>(UnaryExprOrTypeTraitExprBits.Kind);
2591  }
2593  assert(K <= UETT_Last && "invalid enum value!");
2595  assert(static_cast<unsigned>(K) == UnaryExprOrTypeTraitExprBits.Kind &&
2596  "UnaryExprOrTypeTraitExprBits.Kind overflow!");
2597  }
2598 
2599  bool isArgumentType() const { return UnaryExprOrTypeTraitExprBits.IsType; }
2601  return getArgumentTypeInfo()->getType();
2602  }
2604  assert(isArgumentType() && "calling getArgumentType() when arg is expr");
2605  return Argument.Ty;
2606  }
2608  assert(!isArgumentType() && "calling getArgumentExpr() when arg is type");
2609  return static_cast<Expr*>(Argument.Ex);
2610  }
2611  const Expr *getArgumentExpr() const {
2612  return const_cast<UnaryExprOrTypeTraitExpr*>(this)->getArgumentExpr();
2613  }
2614 
2615  void setArgument(Expr *E) {
2616  Argument.Ex = E;
2617  UnaryExprOrTypeTraitExprBits.IsType = false;
2618  }
2620  Argument.Ty = TInfo;
2621  UnaryExprOrTypeTraitExprBits.IsType = true;
2622  }
2623 
2624  /// Gets the argument type, or the type of the argument expression, whichever
2625  /// is appropriate.
2628  }
2629 
2630  SourceLocation getOperatorLoc() const { return OpLoc; }
2631  void setOperatorLoc(SourceLocation L) { OpLoc = L; }
2632 
2633  SourceLocation getRParenLoc() const { return RParenLoc; }
2634  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2635 
2636  SourceLocation getBeginLoc() const LLVM_READONLY { return OpLoc; }
2637  SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
2638 
2639  static bool classof(const Stmt *T) {
2640  return T->getStmtClass() == UnaryExprOrTypeTraitExprClass;
2641  }
2642 
2643  // Iterators
2645  const_child_range children() const;
2646 };
2647 
2648 //===----------------------------------------------------------------------===//
2649 // Postfix Operators.
2650 //===----------------------------------------------------------------------===//
2651 
2652 /// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
2653 class ArraySubscriptExpr : public Expr {
2654  enum { LHS, RHS, END_EXPR };
2655  Stmt *SubExprs[END_EXPR];
2656 
2657  bool lhsIsBase() const { return getRHS()->getType()->isIntegerType(); }
2658 
2659 public:
2661  ExprObjectKind OK, SourceLocation rbracketloc)
2662  : Expr(ArraySubscriptExprClass, t, VK, OK) {
2663  SubExprs[LHS] = lhs;
2664  SubExprs[RHS] = rhs;
2665  ArrayOrMatrixSubscriptExprBits.RBracketLoc = rbracketloc;
2667  }
2668 
2669  /// Create an empty array subscript expression.
2671  : Expr(ArraySubscriptExprClass, Shell) { }
2672 
2673  /// An array access can be written A[4] or 4[A] (both are equivalent).
2674  /// - getBase() and getIdx() always present the normalized view: A[4].
2675  /// In this case getBase() returns "A" and getIdx() returns "4".
2676  /// - getLHS() and getRHS() present the syntactic view. e.g. for
2677  /// 4[A] getLHS() returns "4".
2678  /// Note: Because vector element access is also written A[4] we must
2679  /// predicate the format conversion in getBase and getIdx only on the
2680  /// the type of the RHS, as it is possible for the LHS to be a vector of
2681  /// integer type
2682  Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); }
2683  const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
2684  void setLHS(Expr *E) { SubExprs[LHS] = E; }
2685 
2686  Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); }
2687  const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
2688  void setRHS(Expr *E) { SubExprs[RHS] = E; }
2689 
2690  Expr *getBase() { return lhsIsBase() ? getLHS() : getRHS(); }
2691  const Expr *getBase() const { return lhsIsBase() ? getLHS() : getRHS(); }
2692 
2693  Expr *getIdx() { return lhsIsBase() ? getRHS() : getLHS(); }
2694  const Expr *getIdx() const { return lhsIsBase() ? getRHS() : getLHS(); }
2695 
2696  SourceLocation getBeginLoc() const LLVM_READONLY {
2697  return getLHS()->getBeginLoc();
2698  }
2700 
2702  return ArrayOrMatrixSubscriptExprBits.RBracketLoc;
2703  }
2705  ArrayOrMatrixSubscriptExprBits.RBracketLoc = L;
2706  }
2707 
2708  SourceLocation getExprLoc() const LLVM_READONLY {
2709  return getBase()->getExprLoc();
2710  }
2711 
2712  static bool classof(const Stmt *T) {
2713  return T->getStmtClass() == ArraySubscriptExprClass;
2714  }
2715 
2716  // Iterators
2718  return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
2719  }
2721  return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
2722  }
2723 };
2724 
2725 /// MatrixSubscriptExpr - Matrix subscript expression for the MatrixType
2726 /// extension.
2727 /// MatrixSubscriptExpr can be either incomplete (only Base and RowIdx are set
2728 /// so far, the type is IncompleteMatrixIdx) or complete (Base, RowIdx and
2729 /// ColumnIdx refer to valid expressions). Incomplete matrix expressions only
2730 /// exist during the initial construction of the AST.
2731 class MatrixSubscriptExpr : public Expr {
2732  enum { BASE, ROW_IDX, COLUMN_IDX, END_EXPR };
2733  Stmt *SubExprs[END_EXPR];
2734 
2735 public:
2736  MatrixSubscriptExpr(Expr *Base, Expr *RowIdx, Expr *ColumnIdx, QualType T,
2737  SourceLocation RBracketLoc)
2738  : Expr(MatrixSubscriptExprClass, T, Base->getValueKind(),
2740  SubExprs[BASE] = Base;
2741  SubExprs[ROW_IDX] = RowIdx;
2742  SubExprs[COLUMN_IDX] = ColumnIdx;
2743  ArrayOrMatrixSubscriptExprBits.RBracketLoc = RBracketLoc;
2745  }
2746 
2747  /// Create an empty matrix subscript expression.
2749  : Expr(MatrixSubscriptExprClass, Shell) {}
2750 
2751  bool isIncomplete() const {
2752  bool IsIncomplete = hasPlaceholderType(BuiltinType::IncompleteMatrixIdx);
2753  assert((SubExprs[COLUMN_IDX] || IsIncomplete) &&
2754  "expressions without column index must be marked as incomplete");
2755  return IsIncomplete;
2756  }
2757  Expr *getBase() { return cast<Expr>(SubExprs[BASE]); }
2758  const Expr *getBase() const { return cast<Expr>(SubExprs[BASE]); }
2759  void setBase(Expr *E) { SubExprs[BASE] = E; }
2760 
2761  Expr *getRowIdx() { return cast<Expr>(SubExprs[ROW_IDX]); }
2762  const Expr *getRowIdx() const { return cast<Expr>(SubExprs[ROW_IDX]); }
2763  void setRowIdx(Expr *E) { SubExprs[ROW_IDX] = E; }
2764 
2765  Expr *getColumnIdx() { return cast_or_null<Expr>(SubExprs[COLUMN_IDX]); }
2766  const Expr *getColumnIdx() const {
2767  assert(!isIncomplete() &&
2768  "cannot get the column index of an incomplete expression");
2769  return cast<Expr>(SubExprs[COLUMN_IDX]);
2770  }
2771  void setColumnIdx(Expr *E) { SubExprs[COLUMN_IDX] = E; }
2772 
2773  SourceLocation getBeginLoc() const LLVM_READONLY {
2774  return getBase()->getBeginLoc();
2775  }
2776 
2778 
2779  SourceLocation getExprLoc() const LLVM_READONLY {
2780  return getBase()->getExprLoc();
2781  }
2782 
2784  return ArrayOrMatrixSubscriptExprBits.RBracketLoc;
2785  }
2787  ArrayOrMatrixSubscriptExprBits.RBracketLoc = L;
2788  }
2789 
2790  static bool classof(const Stmt *T) {
2791  return T->getStmtClass() == MatrixSubscriptExprClass;
2792  }
2793 
2794  // Iterators
2796  return child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
2797  }
2799  return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
2800  }
2801 };
2802 
2803 /// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
2804 /// CallExpr itself represents a normal function call, e.g., "f(x, 2)",
2805 /// while its subclasses may represent alternative syntax that (semantically)
2806 /// results in a function call. For example, CXXOperatorCallExpr is
2807 /// a subclass for overloaded operator calls that use operator syntax, e.g.,
2808 /// "str1 + str2" to resolve to a function call.
2809 class CallExpr : public Expr {
2810  enum { FN = 0, PREARGS_START = 1 };
2811 
2812  /// The number of arguments in the call expression.
2813  unsigned NumArgs;
2814 
2815  /// The location of the right parenthese. This has a different meaning for
2816  /// the derived classes of CallExpr.
2817  SourceLocation RParenLoc;
2818 
2819  // CallExpr store some data in trailing objects. However since CallExpr
2820  // is used a base of other expression classes we cannot use
2821  // llvm::TrailingObjects. Instead we manually perform the pointer arithmetic
2822  // and casts.
2823  //
2824  // The trailing objects are in order:
2825  //
2826  // * A single "Stmt *" for the callee expression.
2827  //
2828  // * An array of getNumPreArgs() "Stmt *" for the pre-argument expressions.
2829  //
2830  // * An array of getNumArgs() "Stmt *" for the argument expressions.
2831  //
2832  // * An optional of type FPOptionsOverride.
2833  //
2834  // Note that we store the offset in bytes from the this pointer to the start
2835  // of the trailing objects. It would be perfectly possible to compute it
2836  // based on the dynamic kind of the CallExpr. However 1.) we have plenty of
2837  // space in the bit-fields of Stmt. 2.) It was benchmarked to be faster to
2838  // compute this once and then load the offset from the bit-fields of Stmt,
2839  // instead of re-computing the offset each time the trailing objects are
2840  // accessed.
2841 
2842  /// Return a pointer to the start of the trailing array of "Stmt *".
2843  Stmt **getTrailingStmts() {
2844  return reinterpret_cast<Stmt **>(reinterpret_cast<char *>(this) +
2845  CallExprBits.OffsetToTrailingObjects);
2846  }
2847  Stmt *const *getTrailingStmts() const {
2848  return const_cast<CallExpr *>(this)->getTrailingStmts();
2849  }
2850 
2851  /// Map a statement class to the appropriate offset in bytes from the
2852  /// this pointer to the trailing objects.
2853  static unsigned offsetToTrailingObjects(StmtClass SC);
2854 
2855  unsigned getSizeOfTrailingStmts() const {
2856  return (1 + getNumPreArgs() + getNumArgs()) * sizeof(Stmt *);
2857  }
2858 
2859  size_t getOffsetOfTrailingFPFeatures() const {
2860  assert(hasStoredFPFeatures());
2861  return CallExprBits.OffsetToTrailingObjects + getSizeOfTrailingStmts();
2862  }
2863 
2864 public:
2865  enum class ADLCallKind : bool { NotADL, UsesADL };
2868 
2869 protected:
2870  /// Build a call expression, assuming that appropriate storage has been
2871  /// allocated for the trailing objects.
2872  CallExpr(StmtClass SC, Expr *Fn, ArrayRef<Expr *> PreArgs,
2874  SourceLocation RParenLoc, FPOptionsOverride FPFeatures,
2875  unsigned MinNumArgs, ADLCallKind UsesADL);
2876 
2877  /// Build an empty call expression, for deserialization.
2878  CallExpr(StmtClass SC, unsigned NumPreArgs, unsigned NumArgs,
2879  bool hasFPFeatures, EmptyShell Empty);
2880 
2881  /// Return the size in bytes needed for the trailing objects.
2882  /// Used by the derived classes to allocate the right amount of storage.
2883  static unsigned sizeOfTrailingObjects(unsigned NumPreArgs, unsigned NumArgs,
2884  bool HasFPFeatures) {
2885  return (1 + NumPreArgs + NumArgs) * sizeof(Stmt *) +
2886  HasFPFeatures * sizeof(FPOptionsOverride);
2887  }
2888 
2889  Stmt *getPreArg(unsigned I) {
2890  assert(I < getNumPreArgs() && "Prearg access out of range!");
2891  return getTrailingStmts()[PREARGS_START + I];
2892  }
2893  const Stmt *getPreArg(unsigned I) const {
2894  assert(I < getNumPreArgs() && "Prearg access out of range!");
2895  return getTrailingStmts()[PREARGS_START + I];
2896  }
2897  void setPreArg(unsigned I, Stmt *PreArg) {
2898  assert(I < getNumPreArgs() && "Prearg access out of range!");
2899  getTrailingStmts()[PREARGS_START + I] = PreArg;
2900  }
2901 
2902  unsigned getNumPreArgs() const { return CallExprBits.NumPreArgs; }
2903 
2904  /// Return a pointer to the trailing FPOptions
2906  assert(hasStoredFPFeatures());
2907  return reinterpret_cast<FPOptionsOverride *>(
2908  reinterpret_cast<char *>(this) + CallExprBits.OffsetToTrailingObjects +
2909  getSizeOfTrailingStmts());
2910  }
2912  assert(hasStoredFPFeatures());
2913  return reinterpret_cast<const FPOptionsOverride *>(
2914  reinterpret_cast<const char *>(this) +
2915  CallExprBits.OffsetToTrailingObjects + getSizeOfTrailingStmts());
2916  }
2917 
2918 public:
2919  /// Create a call expression.
2920  /// \param Fn The callee expression,
2921  /// \param Args The argument array,
2922  /// \param Ty The type of the call expression (which is *not* the return
2923  /// type in general),
2924  /// \param VK The value kind of the call expression (lvalue, rvalue, ...),
2925  /// \param RParenLoc The location of the right parenthesis in the call
2926  /// expression.
2927  /// \param FPFeatures Floating-point features associated with the call,
2928  /// \param MinNumArgs Specifies the minimum number of arguments. The actual
2929  /// number of arguments will be the greater of Args.size()
2930  /// and MinNumArgs. This is used in a few places to allocate
2931  /// enough storage for the default arguments.
2932  /// \param UsesADL Specifies whether the callee was found through
2933  /// argument-dependent lookup.
2934  ///
2935  /// Note that you can use CreateTemporary if you need a temporary call
2936  /// expression on the stack.
2937  static CallExpr *Create(const ASTContext &Ctx, Expr *Fn,
2939  SourceLocation RParenLoc,
2940  FPOptionsOverride FPFeatures, unsigned MinNumArgs = 0,
2942 
2943  /// Create a temporary call expression with no arguments in the memory
2944  /// pointed to by Mem. Mem must points to at least sizeof(CallExpr)
2945  /// + sizeof(Stmt *) bytes of storage, aligned to alignof(CallExpr):
2946  ///
2947  /// \code{.cpp}
2948  /// alignas(CallExpr) char Buffer[sizeof(CallExpr) + sizeof(Stmt *)];
2949  /// CallExpr *TheCall = CallExpr::CreateTemporary(Buffer, etc);
2950  /// \endcode
2951  static CallExpr *CreateTemporary(void *Mem, Expr *Fn, QualType Ty,
2952  ExprValueKind VK, SourceLocation RParenLoc,
2954 
2955  /// Create an empty call expression, for deserialization.
2956  static CallExpr *CreateEmpty(const ASTContext &Ctx, unsigned NumArgs,
2957  bool HasFPFeatures, EmptyShell Empty);
2958 
2959  Expr *getCallee() { return cast<Expr>(getTrailingStmts()[FN]); }
2960  const Expr *getCallee() const { return cast<Expr>(getTrailingStmts()[FN]); }
2961  void setCallee(Expr *F) { getTrailingStmts()[FN] = F; }
2962 
2964  return static_cast<ADLCallKind>(CallExprBits.UsesADL);
2965  }
2967  CallExprBits.UsesADL = static_cast<bool>(V);
2968  }
2969  bool usesADL() const { return getADLCallKind() == UsesADL; }
2970 
2971  bool hasStoredFPFeatures() const { return CallExprBits.HasFPFeatures; }
2972 
2974  const Decl *getCalleeDecl() const {
2976  }
2977 
2978  /// If the callee is a FunctionDecl, return it. Otherwise return null.
2980  return dyn_cast_or_null<FunctionDecl>(getCalleeDecl());
2981  }
2983  return dyn_cast_or_null<FunctionDecl>(getCalleeDecl());
2984  }
2985 
2986  /// getNumArgs - Return the number of actual arguments to this call.
2987  unsigned getNumArgs() const { return NumArgs; }
2988 
2989  /// Retrieve the call arguments.
2991  return reinterpret_cast<Expr **>(getTrailingStmts() + PREARGS_START +
2992  getNumPreArgs());
2993  }
2994  const Expr *const *getArgs() const {
2995  return reinterpret_cast<const Expr *const *>(
2996  getTrailingStmts() + PREARGS_START + getNumPreArgs());
2997  }
2998 
2999  /// getArg - Return the specified argument.
3000  Expr *getArg(unsigned Arg) {
3001  assert(Arg < getNumArgs() && "Arg access out of range!");
3002  return getArgs()[Arg];
3003  }
3004  const Expr *getArg(unsigned Arg) const {
3005  assert(Arg < getNumArgs() && "Arg access out of range!");
3006  return getArgs()[Arg];
3007  }
3008 
3009  /// setArg - Set the specified argument.
3010  /// ! the dependence bits might be stale after calling this setter, it is
3011  /// *caller*'s responsibility to recompute them by calling
3012  /// computeDependence().
3013  void setArg(unsigned Arg, Expr *ArgExpr) {
3014  assert(Arg < getNumArgs() && "Arg access out of range!");
3015  getArgs()[Arg] = ArgExpr;
3016  }
3017 
3018  /// Compute and set dependence bits.
3021  this, llvm::makeArrayRef(
3022  reinterpret_cast<Expr **>(getTrailingStmts() + PREARGS_START),
3023  getNumPreArgs())));
3024  }
3025 
3026  /// Reduce the number of arguments in this call expression. This is used for
3027  /// example during error recovery to drop extra arguments. There is no way
3028  /// to perform the opposite because: 1.) We don't track how much storage
3029  /// we have for the argument array 2.) This would potentially require growing
3030  /// the argument array, something we cannot support since the arguments are
3031  /// stored in a trailing array.
3032  void shrinkNumArgs(unsigned NewNumArgs) {
3033  assert((NewNumArgs <= getNumArgs()) &&
3034  "shrinkNumArgs cannot increase the number of arguments!");
3035  NumArgs = NewNumArgs;
3036  }
3037 
3038  /// Bluntly set a new number of arguments without doing any checks whatsoever.
3039  /// Only used during construction of a CallExpr in a few places in Sema.
3040  /// FIXME: Find a way to remove it.
3041  void setNumArgsUnsafe(unsigned NewNumArgs) { NumArgs = NewNumArgs; }
3042 
3045  typedef llvm::iterator_range<arg_iterator> arg_range;
3046  typedef llvm::iterator_range<const_arg_iterator> const_arg_range;
3047 
3050  return const_arg_range(arg_begin(), arg_end());
3051  }
3052 
3054  return getTrailingStmts() + PREARGS_START + getNumPreArgs();
3055  }
3057 
3059  return getTrailingStmts() + PREARGS_START + getNumPreArgs();
3060  }
3062 
3063  /// This method provides fast access to all the subexpressions of
3064  /// a CallExpr without going through the slower virtual child_iterator
3065  /// interface. This provides efficient reverse iteration of the
3066  /// subexpressions. This is currently used for CFG construction.
3068  return llvm::makeArrayRef(getTrailingStmts(),
3069  PREARGS_START + getNumPreArgs() + getNumArgs());
3070  }
3071 
3072  /// Get FPOptionsOverride from trailing storage.
3074  assert(hasStoredFPFeatures());
3075  return *getTrailingFPFeatures();
3076  }
3077  /// Set FPOptionsOverride in trailing storage. Used only by Serialization.
3079  assert(hasStoredFPFeatures());
3080  *getTrailingFPFeatures() = F;
3081  }
3082 
3083  // Get the FP features status of this operator. Only meaningful for
3084  // operations on floating point types.
3086  if (hasStoredFPFeatures())
3087  return getStoredFPFeatures().applyOverrides(LO);
3089  }
3090 
3092  if (hasStoredFPFeatures())
3093  return getStoredFPFeatures();
3094  return FPOptionsOverride();
3095  }
3096 
3097  /// getBuiltinCallee - If this is a call to a builtin, return the builtin ID
3098  /// of the callee. If not, return 0.
3099  unsigned getBuiltinCallee() const;
3100 
3101  /// Returns \c true if this is a call to a builtin which does not
3102  /// evaluate side-effects within its arguments.
3103  bool isUnevaluatedBuiltinCall(const ASTContext &Ctx) const;
3104 
3105  /// getCallReturnType - Get the return type of the call expr. This is not
3106  /// always the type of the expr itself, if the return type is a reference
3107  /// type.
3108  QualType getCallReturnType(const ASTContext &Ctx) const;
3109 
3110  /// Returns the WarnUnusedResultAttr that is either declared on the called
3111  /// function, or its return type declaration.
3112  const Attr *getUnusedResultAttr(const ASTContext &Ctx) const;
3113 
3114  /// Returns true if this call expression should warn on unused results.
3115  bool hasUnusedResultAttr(const ASTContext &Ctx) const {
3116  return getUnusedResultAttr(Ctx) != nullptr;
3117  }
3118 
3119  SourceLocation getRParenLoc() const { return RParenLoc; }
3120  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
3121 
3122  SourceLocation getBeginLoc() const LLVM_READONLY;
3123  SourceLocation getEndLoc() const LLVM_READONLY;
3124 
3125  /// Return true if this is a call to __assume() or __builtin_assume() with
3126  /// a non-value-dependent constant parameter evaluating as false.
3127  bool isBuiltinAssumeFalse(const ASTContext &Ctx) const;
3128 
3129  /// Used by Sema to implement MSVC-compatible delayed name lookup.
3130  /// (Usually Exprs themselves should set dependence).
3132  setDependence(getDependence() | ExprDependence::TypeValueInstantiation);
3133  }
3134 
3135  bool isCallToStdMove() const;
3136 
3137  static bool classof(const Stmt *T) {
3138  return T->getStmtClass() >= firstCallExprConstant &&
3139  T->getStmtClass() <= lastCallExprConstant;
3140  }
3141 
3142  // Iterators
3144  return child_range(getTrailingStmts(), getTrailingStmts() + PREARGS_START +
3145  getNumPreArgs() + getNumArgs());
3146  }
3147 
3149  return const_child_range(getTrailingStmts(),
3150  getTrailingStmts() + PREARGS_START +
3151  getNumPreArgs() + getNumArgs());
3152  }
3153 };
3154 
3155 /// Extra data stored in some MemberExpr objects.
3157  /// The nested-name-specifier that qualifies the name, including
3158  /// source-location information.
3160 
3161  /// The DeclAccessPair through which the MemberDecl was found due to
3162  /// name qualifiers.
3164 };
3165 
3166 /// MemberExpr - [C99 6.5.2.3] Structure and Union Members. X->F and X.F.
3167 ///
3168 class MemberExpr final
3169  : public Expr,
3170  private llvm::TrailingObjects<MemberExpr, MemberExprNameQualifier,
3171  ASTTemplateKWAndArgsInfo,
3172  TemplateArgumentLoc> {
3173  friend class ASTReader;
3174  friend class ASTStmtReader;
3175  friend class ASTStmtWriter;
3176  friend TrailingObjects;
3177 
3178  /// Base - the expression for the base pointer or structure references. In
3179  /// X.F, this is "X".
3180  Stmt *Base;
3181 
3182  /// MemberDecl - This is the decl being referenced by the field/member name.
3183  /// In X.F, this is the decl referenced by F.
3184  ValueDecl *MemberDecl;
3185 
3186  /// MemberDNLoc - Provides source/type location info for the
3187  /// declaration name embedded in MemberDecl.
3188  DeclarationNameLoc MemberDNLoc;
3189 
3190  /// MemberLoc - This is the location of the member name.
3191  SourceLocation MemberLoc;
3192 
3193  size_t numTrailingObjects(OverloadToken<MemberExprNameQualifier>) const {
3194  return hasQualifierOrFoundDecl();
3195  }
3196 
3197  size_t numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
3198  return hasTemplateKWAndArgsInfo();
3199  }
3200 
3201  bool hasQualifierOrFoundDecl() const {
3202  return MemberExprBits.HasQualifierOrFoundDecl;
3203  }
3204 
3205  bool hasTemplateKWAndArgsInfo() const {
3206  return MemberExprBits.HasTemplateKWAndArgsInfo;
3207  }
3208 
3209  MemberExpr(Expr *Base, bool IsArrow, SourceLocation OperatorLoc,
3210  ValueDecl *MemberDecl, const DeclarationNameInfo &NameInfo,
3211  QualType T, ExprValueKind VK, ExprObjectKind OK,
3212  NonOdrUseReason NOUR);
3213  MemberExpr(EmptyShell Empty)
3214  : Expr(MemberExprClass, Empty), Base(), MemberDecl() {}
3215 
3216 public:
3217  static MemberExpr *Create(const ASTContext &C, Expr *Base, bool IsArrow,
3218  SourceLocation OperatorLoc,
3219  NestedNameSpecifierLoc QualifierLoc,
3220  SourceLocation TemplateKWLoc, ValueDecl *MemberDecl,
3221  DeclAccessPair FoundDecl,
3222  DeclarationNameInfo MemberNameInfo,
3223  const TemplateArgumentListInfo *TemplateArgs,
3224  QualType T, ExprValueKind VK, ExprObjectKind OK,
3225  NonOdrUseReason NOUR);
3226 
3227  /// Create an implicit MemberExpr, with no location, qualifier, template
3228  /// arguments, and so on. Suitable only for non-static member access.
3230  bool IsArrow, ValueDecl *MemberDecl,
3231  QualType T, ExprValueKind VK,
3232  ExprObjectKind OK) {
3233  return Create(C, Base, IsArrow, SourceLocation(), NestedNameSpecifierLoc(),
3234  SourceLocation(), MemberDecl,
3235  DeclAccessPair::make(MemberDecl, MemberDecl->getAccess()),
3236  DeclarationNameInfo(), nullptr, T, VK, OK, NOUR_None);
3237  }
3238 
3239  static MemberExpr *CreateEmpty(const ASTContext &Context, bool HasQualifier,
3240  bool HasFoundDecl,
3241  bool HasTemplateKWAndArgsInfo,
3242  unsigned NumTemplateArgs);
3243 
3244  void setBase(Expr *E) { Base = E; }
3245  Expr *getBase() const { return cast<Expr>(Base); }
3246 
3247  /// Retrieve the member declaration to which this expression refers.
3248  ///
3249  /// The returned declaration will be a FieldDecl or (in C++) a VarDecl (for
3250  /// static data members), a CXXMethodDecl, or an EnumConstantDecl.
3251  ValueDecl *getMemberDecl() const { return MemberDecl; }
3252  void setMemberDecl(ValueDecl *D);
3253 
3254  /// Retrieves the declaration found by lookup.
3256  if (!hasQualifierOrFoundDecl())
3258  getMemberDecl()->getAccess());
3259  return getTrailingObjects<MemberExprNameQualifier>()->FoundDecl;
3260  }
3261 
3262  /// Determines whether this member expression actually had
3263  /// a C++ nested-name-specifier prior to the name of the member, e.g.,
3264  /// x->Base::foo.
3265  bool hasQualifier() const { return getQualifier() != nullptr; }
3266 
3267  /// If the member name was qualified, retrieves the
3268  /// nested-name-specifier that precedes the member name, with source-location
3269  /// information.
3271  if (!hasQualifierOrFoundDecl())
3272  return NestedNameSpecifierLoc();
3273  return getTrailingObjects<MemberExprNameQualifier>()->QualifierLoc;
3274  }
3275 
3276  /// If the member name was qualified, retrieves the
3277  /// nested-name-specifier that precedes the member name. Otherwise, returns
3278  /// NULL.
3281  }
3282 
3283  /// Retrieve the location of the template keyword preceding
3284  /// the member name, if any.
3286  if (!hasTemplateKWAndArgsInfo())
3287  return SourceLocation();
3288  return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->TemplateKWLoc;
3289  }
3290 
3291  /// Retrieve the location of the left angle bracket starting the
3292  /// explicit template argument list following the member name, if any.
3294  if (!hasTemplateKWAndArgsInfo())
3295  return SourceLocation();
3296  return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->LAngleLoc;
3297  }
3298 
3299  /// Retrieve the location of the right angle bracket ending the
3300  /// explicit template argument list following the member name, if any.
3302  if (!hasTemplateKWAndArgsInfo())
3303  return SourceLocation();
3304  return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->RAngleLoc;
3305  }
3306 
3307  /// Determines whether the member name was preceded by the template keyword.
3308  bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
3309 
3310  /// Determines whether the member name was followed by an
3311  /// explicit template argument list.
3312  bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
3313 
3314  /// Copies the template arguments (if present) into the given
3315  /// structure.
3318  getTrailingObjects<ASTTemplateKWAndArgsInfo>()->copyInto(
3319  getTrailingObjects<TemplateArgumentLoc>(), List);
3320  }
3321 
3322  /// Retrieve the template arguments provided as part of this
3323  /// template-id.
3325  if (!hasExplicitTemplateArgs())
3326  return nullptr;
3327 
3328  return getTrailingObjects<TemplateArgumentLoc>();
3329  }
3330 
3331  /// Retrieve the number of template arguments provided as part of this
3332  /// template-id.
3333  unsigned getNumTemplateArgs() const {
3334  if (!hasExplicitTemplateArgs())
3335  return 0;
3336 
3337  return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs;
3338  }
3339 
3341  return {getTemplateArgs(), getNumTemplateArgs()};
3342  }
3343 
3344  /// Retrieve the member declaration name info.
3346  return DeclarationNameInfo(MemberDecl->getDeclName(),
3347  MemberLoc, MemberDNLoc);
3348  }
3349 
3350  SourceLocation getOperatorLoc() const { return MemberExprBits.OperatorLoc; }
3351 
3352  bool isArrow() const { return MemberExprBits.IsArrow; }
3353  void setArrow(bool A) { MemberExprBits.IsArrow = A; }
3354 
3355  /// getMemberLoc - Return the location of the "member", in X->F, it is the
3356  /// location of 'F'.
3357  SourceLocation getMemberLoc() const { return MemberLoc; }
3358  void setMemberLoc(SourceLocation L) { MemberLoc = L; }
3359 
3360  SourceLocation getBeginLoc() const LLVM_READONLY;
3361  SourceLocation getEndLoc() const LLVM_READONLY;
3362 
3363  SourceLocation getExprLoc() const LLVM_READONLY { return MemberLoc; }
3364 
3365  /// Determine whether the base of this explicit is implicit.
3366  bool isImplicitAccess() const {
3367  return getBase() && getBase()->isImplicitCXXThis();
3368  }
3369 
3370  /// Returns true if this member expression refers to a method that
3371  /// was resolved from an overloaded set having size greater than 1.
3372  bool hadMultipleCandidates() const {
3373  return MemberExprBits.HadMultipleCandidates;
3374  }
3375  /// Sets the flag telling whether this expression refers to
3376  /// a method that was resolved from an overloaded set having size
3377  /// greater than 1.
3378  void setHadMultipleCandidates(bool V = true) {
3379  MemberExprBits.HadMultipleCandidates = V;
3380  }
3381 
3382  /// Returns true if virtual dispatch is performed.
3383  /// If the member access is fully qualified, (i.e. X::f()), virtual
3384  /// dispatching is not performed. In -fapple-kext mode qualified
3385  /// calls to virtual method will still go through the vtable.
3386  bool performsVirtualDispatch(const LangOptions &LO) const {
3387  return LO.AppleKext || !hasQualifier();
3388  }
3389 
3390  /// Is this expression a non-odr-use reference, and if so, why?
3391  /// This is only meaningful if the named member is a static member.
3393  return static_cast<NonOdrUseReason>(MemberExprBits.NonOdrUseReason);
3394  }
3395 
3396  static bool classof(const Stmt *T) {
3397  return T->getStmtClass() == MemberExprClass;
3398  }
3399 
3400  // Iterators
3403  return const_child_range(&Base, &Base + 1);
3404  }
3405 };
3406 
3407 /// CompoundLiteralExpr - [C99 6.5.2.5]
3408 ///
3409 class CompoundLiteralExpr : public Expr {
3410  /// LParenLoc - If non-null, this is the location of the left paren in a
3411  /// compound literal like "(int){4}". This can be null if this is a
3412  /// synthesized compound expression.
3413  SourceLocation LParenLoc;
3414 
3415  /// The type as written. This can be an incomplete array type, in
3416  /// which case the actual expression type will be different.
3417  /// The int part of the pair stores whether this expr is file scope.
3418  llvm::PointerIntPair<TypeSourceInfo *, 1, bool> TInfoAndScope;
3419  Stmt *Init;
3420 public:
3422  QualType T, ExprValueKind VK, Expr *init, bool fileScope)
3423  : Expr(CompoundLiteralExprClass, T, VK, OK_Ordinary),
3424  LParenLoc(lparenloc), TInfoAndScope(tinfo, fileScope), Init(init) {
3426  }
3427 
3428  /// Construct an empty compound literal.
3430  : Expr(CompoundLiteralExprClass, Empty) { }
3431 
3432  const Expr *getInitializer() const { return cast<Expr>(Init); }
3433  Expr *getInitializer() { return cast<Expr>(Init); }
3434  void setInitializer(Expr *E) { Init = E; }
3435 
3436  bool isFileScope() const { return TInfoAndScope.getInt(); }
3437  void setFileScope(bool FS) { TInfoAndScope.setInt(FS); }
3438 
3439  SourceLocation getLParenLoc() const { return LParenLoc; }
3440  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
3441 
3443  return TInfoAndScope.getPointer();
3444  }
3446  TInfoAndScope.setPointer(tinfo);
3447  }
3448 
3449  SourceLocation getBeginLoc() const LLVM_READONLY {
3450  // FIXME: Init should never be null.
3451  if (!Init)
3452  return SourceLocation();
3453  if (LParenLoc.isInvalid())
3454  return Init->getBeginLoc();
3455  return LParenLoc;
3456  }
3457  SourceLocation getEndLoc() const LLVM_READONLY {
3458  // FIXME: Init should never be null.
3459  if (!Init)
3460  return SourceLocation();
3461  return Init->getEndLoc();
3462  }
3463 
3464  static bool classof(const Stmt *T) {
3465  return T->getStmtClass() == CompoundLiteralExprClass;
3466  }
3467 
3468  // Iterators
3469  child_range children() { return child_range(&Init, &Init+1); }
3471  return const_child_range(&Init, &Init + 1);
3472  }
3473 };
3474 
3475 /// CastExpr - Base class for type casts, including both implicit
3476 /// casts (ImplicitCastExpr) and explicit casts that have some
3477 /// representation in the source code (ExplicitCastExpr's derived
3478 /// classes).
3479 class CastExpr : public Expr {
3480  Stmt *Op;
3481 
3482  bool CastConsistency() const;
3483 
3484  const CXXBaseSpecifier * const *path_buffer() const {
3485  return const_cast<CastExpr*>(this)->path_buffer();
3486  }
3487  CXXBaseSpecifier **path_buffer();
3488 
3489  friend class ASTStmtReader;
3490 
3491 protected:
3493  Expr *op, unsigned BasePathSize, bool HasFPFeatures)
3494  : Expr(SC, ty, VK, OK_Ordinary), Op(op) {
3495  CastExprBits.Kind = kind;
3496  CastExprBits.PartOfExplicitCast = false;
3497  CastExprBits.BasePathSize = BasePathSize;
3498  assert((CastExprBits.BasePathSize == BasePathSize) &&
3499  "BasePathSize overflow!");
3500  assert(CastConsistency());
3501  CastExprBits.HasFPFeatures = HasFPFeatures;
3502  }
3503 
3504  /// Construct an empty cast.
3505  CastExpr(StmtClass SC, EmptyShell Empty, unsigned BasePathSize,
3506  bool HasFPFeatures)
3507  : Expr(SC, Empty) {
3508  CastExprBits.PartOfExplicitCast = false;
3509  CastExprBits.BasePathSize = BasePathSize;
3510  CastExprBits.HasFPFeatures = HasFPFeatures;
3511  assert((CastExprBits.BasePathSize == BasePathSize) &&
3512  "BasePathSize overflow!");
3513  }
3514 
3515  /// Return a pointer to the trailing FPOptions.
3516  /// \pre hasStoredFPFeatures() == true
3519  return const_cast<CastExpr *>(this)->getTrailingFPFeatures();
3520  }
3521 
3522 public:
3523  CastKind getCastKind() const { return (CastKind) CastExprBits.Kind; }
3524  void setCastKind(CastKind K) { CastExprBits.Kind = K; }
3525 
3526  static const char *getCastKindName(CastKind CK);
3527  const char *getCastKindName() const { return getCastKindName(getCastKind()); }
3528 
3529  Expr *getSubExpr() { return cast<Expr>(Op); }
3530  const Expr *getSubExpr() const { return cast<Expr>(Op); }
3531  void setSubExpr(Expr *E) { Op = E; }
3532 
3533  /// Retrieve the cast subexpression as it was written in the source
3534  /// code, looking through any implicit casts or other intermediate nodes
3535  /// introduced by semantic analysis.
3537  const Expr *getSubExprAsWritten() const {
3538  return const_cast<CastExpr *>(this)->getSubExprAsWritten();
3539  }
3540 
3541  /// If this cast applies a user-defined conversion, retrieve the conversion
3542  /// function that it invokes.
3544 
3546  typedef const CXXBaseSpecifier *const *path_const_iterator;
3547  bool path_empty() const { return path_size() == 0; }
3548  unsigned path_size() const { return CastExprBits.BasePathSize; }
3549  path_iterator path_begin() { return path_buffer(); }
3550  path_iterator path_end() { return path_buffer() + path_size(); }
3551  path_const_iterator path_begin() const { return path_buffer(); }
3552  path_const_iterator path_end() const { return path_buffer() + path_size(); }
3553 
3554  llvm::iterator_range<path_iterator> path() {
3555  return llvm::make_range(path_begin(), path_end());
3556  }
3557  llvm::iterator_range<path_const_iterator> path() const {
3558  return llvm::make_range(path_begin(), path_end());
3559  }
3560 
3562  assert(getCastKind() == CK_ToUnion);
3564  }
3565 
3566  bool hasStoredFPFeatures() const { return CastExprBits.HasFPFeatures; }
3567 
3568  /// Get FPOptionsOverride from trailing storage.
3570  assert(hasStoredFPFeatures());
3571  return *getTrailingFPFeatures();
3572  }
3573 
3574  // Get the FP features status of this operation. Only meaningful for
3575  // operations on floating point types.
3577  if (hasStoredFPFeatures())
3578  return getStoredFPFeatures().applyOverrides(LO);
3580  }
3581 
3583  if (hasStoredFPFeatures())
3584  return getStoredFPFeatures();
3585  return FPOptionsOverride();
3586  }
3587 
3588  static const FieldDecl *getTargetFieldForToUnionCast(QualType unionType,
3589  QualType opType);
3590  static const FieldDecl *getTargetFieldForToUnionCast(const RecordDecl *RD,
3591  QualType opType);
3592 
3593  static bool classof(const Stmt *T) {
3594  return T->getStmtClass() >= firstCastExprConstant &&
3595  T->getStmtClass() <= lastCastExprConstant;
3596  }
3597 
3598  // Iterators
3599  child_range children() { return child_range(&Op, &Op+1); }
3600  const_child_range children() const { return const_child_range(&Op, &Op + 1); }
3601 };
3602 
3603 /// ImplicitCastExpr - Allows us to explicitly represent implicit type
3604 /// conversions, which have no direct representation in the original
3605 /// source code. For example: converting T[]->T*, void f()->void
3606 /// (*f)(), float->double, short->int, etc.
3607 ///
3608 /// In C, implicit casts always produce rvalues. However, in C++, an
3609 /// implicit cast whose result is being bound to a reference will be
3610 /// an lvalue or xvalue. For example:
3611 ///
3612 /// @code
3613 /// class Base { };
3614 /// class Derived : public Base { };
3615 /// Derived &&ref();
3616 /// void f(Derived d) {
3617 /// Base& b = d; // initializer is an ImplicitCastExpr
3618 /// // to an lvalue of type Base
3619 /// Base&& r = ref(); // initializer is an ImplicitCastExpr
3620 /// // to an xvalue of type Base
3621 /// }
3622 /// @endcode
3623 class ImplicitCastExpr final
3624  : public CastExpr,
3625  private llvm::TrailingObjects<ImplicitCastExpr, CXXBaseSpecifier *,
3626  FPOptionsOverride> {
3627 
3629  unsigned BasePathLength, FPOptionsOverride FPO,
3630  ExprValueKind VK)
3631  : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, BasePathLength,
3632  FPO.requiresTrailingStorage()) {
3634  if (hasStoredFPFeatures())
3635  *getTrailingFPFeatures() = FPO;
3636  }
3637 
3638  /// Construct an empty implicit cast.
3639  explicit ImplicitCastExpr(EmptyShell Shell, unsigned PathSize,
3640  bool HasFPFeatures)
3641  : CastExpr(ImplicitCastExprClass, Shell, PathSize, HasFPFeatures) {}
3642 
3643  unsigned numTrailingObjects(OverloadToken<CXXBaseSpecifier *>) const {
3644  return path_size();
3645  }
3646 
3647 public:
3648  enum OnStack_t { OnStack };
3651  : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, 0,
3652  FPO.requiresTrailingStorage()) {
3653  if (hasStoredFPFeatures())
3654  *getTrailingFPFeatures() = FPO;
3655  }
3656 
3657  bool isPartOfExplicitCast() const { return CastExprBits.PartOfExplicitCast; }
3658  void setIsPartOfExplicitCast(bool PartOfExplicitCast) {
3659  CastExprBits.PartOfExplicitCast = PartOfExplicitCast;
3660  }
3661 
3662  static ImplicitCastExpr *Create(const ASTContext &Context, QualType T,
3663  CastKind Kind, Expr *Operand,
3664  const CXXCastPath *BasePath,
3665  ExprValueKind Cat, FPOptionsOverride FPO);
3666 
3667  static ImplicitCastExpr *CreateEmpty(const ASTContext &Context,
3668  unsigned PathSize, bool HasFPFeatures);
3669 
3670  SourceLocation getBeginLoc() const LLVM_READONLY {
3671  return getSubExpr()->getBeginLoc();
3672  }
3673  SourceLocation getEndLoc() const LLVM_READONLY {
3674  return getSubExpr()->getEndLoc();
3675  }
3676 
3677  static bool classof(const Stmt *T) {
3678  return T->getStmtClass() == ImplicitCastExprClass;
3679  }
3680 
3682  friend class CastExpr;
3683 };
3684 
3685 /// ExplicitCastExpr - An explicit cast written in the source
3686 /// code.
3687 ///
3688 /// This class is effectively an abstract class, because it provides
3689 /// the basic representation of an explicitly-written cast without
3690 /// specifying which kind of cast (C cast, functional cast, static
3691 /// cast, etc.) was written; specific derived classes represent the
3692 /// particular style of cast and its location information.
3693 ///
3694 /// Unlike implicit casts, explicit cast nodes have two different
3695 /// types: the type that was written into the source code, and the
3696 /// actual type of the expression as determined by semantic
3697 /// analysis. These types may differ slightly. For example, in C++ one
3698 /// can cast to a reference type, which indicates that the resulting
3699 /// expression will be an lvalue or xvalue. The reference type, however,
3700 /// will not be used as the type of the expression.
3701 class ExplicitCastExpr : public CastExpr {
3702  /// TInfo - Source type info for the (written) type
3703  /// this expression is casting to.
3704  TypeSourceInfo *TInfo;
3705 
3706 protected:
3708  CastKind kind, Expr *op, unsigned PathSize,
3709  bool HasFPFeatures, TypeSourceInfo *writtenTy)
3710  : CastExpr(SC, exprTy, VK, kind, op, PathSize, HasFPFeatures),
3711  TInfo(writtenTy) {
3713  }
3714 
3715  /// Construct an empty explicit cast.
3716  ExplicitCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize,
3717  bool HasFPFeatures)
3718  : CastExpr(SC, Shell, PathSize, HasFPFeatures) {}
3719 
3720 public:
3721  /// getTypeInfoAsWritten - Returns the type source info for the type
3722  /// that this expression is casting to.
3723  TypeSourceInfo *getTypeInfoAsWritten() const { return TInfo; }
3724  void setTypeInfoAsWritten(TypeSourceInfo *writtenTy) { TInfo = writtenTy; }
3725 
3726  /// getTypeAsWritten - Returns the type that this expression is
3727  /// casting to, as written in the source code.
3728  QualType getTypeAsWritten() const { return TInfo->getType(); }
3729 
3730  static bool classof(const Stmt *T) {
3731  return T->getStmtClass() >= firstExplicitCastExprConstant &&
3732  T->getStmtClass() <= lastExplicitCastExprConstant;
3733  }
3734 };
3735 
3736 /// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style
3737 /// cast in C++ (C++ [expr.cast]), which uses the syntax
3738 /// (Type)expr. For example: @c (int)f.
3739 class CStyleCastExpr final
3740  : public ExplicitCastExpr,
3741  private llvm::TrailingObjects<CStyleCastExpr, CXXBaseSpecifier *,
3742  FPOptionsOverride> {
3743  SourceLocation LPLoc; // the location of the left paren
3744  SourceLocation RPLoc; // the location of the right paren
3745 
3747  unsigned PathSize, FPOptionsOverride FPO,
3748  TypeSourceInfo *writtenTy, SourceLocation l, SourceLocation r)
3749  : ExplicitCastExpr(CStyleCastExprClass, exprTy, vk, kind, op, PathSize,
3750  FPO.requiresTrailingStorage(), writtenTy),
3751  LPLoc(l), RPLoc(r) {
3752  if (hasStoredFPFeatures())
3753  *getTrailingFPFeatures() = FPO;
3754  }
3755 
3756  /// Construct an empty C-style explicit cast.
3757  explicit CStyleCastExpr(EmptyShell Shell, unsigned PathSize,
3758  bool HasFPFeatures)
3759  : ExplicitCastExpr(CStyleCastExprClass, Shell, PathSize, HasFPFeatures) {}
3760 
3761  unsigned numTrailingObjects(OverloadToken<CXXBaseSpecifier *>) const {
3762  return path_size();
3763  }
3764 
3765 public:
3766  static CStyleCastExpr *
3767  Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind K,
3768  Expr *Op, const CXXCastPath *BasePath, FPOptionsOverride FPO,
3769  TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation R);
3770 
3771  static CStyleCastExpr *CreateEmpty(const ASTContext &Context,
3772  unsigned PathSize, bool HasFPFeatures);
3773 
3774  SourceLocation getLParenLoc() const { return LPLoc; }
3775  void setLParenLoc(SourceLocation L) { LPLoc = L; }
3776 
3777  SourceLocation getRParenLoc() const { return RPLoc; }
3778  void setRParenLoc(SourceLocation L) { RPLoc = L; }
3779 
3780  SourceLocation getBeginLoc() const LLVM_READONLY { return LPLoc; }
3781  SourceLocation getEndLoc() const LLVM_READONLY {
3782  return getSubExpr()->getEndLoc();
3783  }
3784 
3785  static bool classof(const Stmt *T) {
3786  return T->getStmtClass() == CStyleCastExprClass;
3787  }
3788 
3790  friend class CastExpr;
3791 };
3792 
3793 /// A builtin binary operation expression such as "x + y" or "x <= y".
3794 ///
3795 /// This expression node kind describes a builtin binary operation,
3796 /// such as "x + y" for integer values "x" and "y". The operands will
3797 /// already have been converted to appropriate types (e.g., by
3798 /// performing promotions or conversions).
3799 ///
3800 /// In C++, where operators may be overloaded, a different kind of
3801 /// expression node (CXXOperatorCallExpr) is used to express the
3802 /// invocation of an overloaded operator with operator syntax. Within
3803 /// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is
3804 /// used to store an expression "x + y" depends on the subexpressions
3805 /// for x and y. If neither x or y is type-dependent, and the "+"
3806 /// operator resolves to a built-in operation, BinaryOperator will be
3807 /// used to express the computation (x and y may still be
3808 /// value-dependent). If either x or y is type-dependent, or if the
3809 /// "+" resolves to an overloaded operator, CXXOperatorCallExpr will
3810 /// be used to express the computation.
3811 class BinaryOperator : public Expr {
3812  enum { LHS, RHS, END_EXPR };
3813  Stmt *SubExprs[END_EXPR];
3814 
3815 public:
3817 
3818 protected:
3819  size_t offsetOfTrailingStorage() const;
3820 
3821  /// Return a pointer to the trailing FPOptions
3823  assert(BinaryOperatorBits.HasFPFeatures);
3824  return reinterpret_cast<FPOptionsOverride *>(
3825  reinterpret_cast<char *>(this) + offsetOfTrailingStorage());
3826  }
3828  assert(BinaryOperatorBits.HasFPFeatures);
3829  return reinterpret_cast<const FPOptionsOverride *>(
3830  reinterpret_cast<const char *>(this) + offsetOfTrailingStorage());
3831  }
3832 
3833  /// Build a binary operator, assuming that appropriate storage has been
3834  /// allocated for the trailing objects when needed.
3835  BinaryOperator(const ASTContext &Ctx, Expr *lhs, Expr *rhs, Opcode opc,
3836  QualType ResTy, ExprValueKind VK, ExprObjectKind OK,
3837  SourceLocation opLoc, FPOptionsOverride FPFeatures);
3838 
3839  /// Construct an empty binary operator.
3840  explicit BinaryOperator(EmptyShell Empty) : Expr(BinaryOperatorClass, Empty) {
3841  BinaryOperatorBits.Opc = BO_Comma;
3842  }
3843 
3844 public:
3845  static BinaryOperator *CreateEmpty(const ASTContext &C, bool hasFPFeatures);
3846 
3847  static BinaryOperator *Create(const ASTContext &C, Expr *lhs, Expr *rhs,
3848  Opcode opc, QualType ResTy, ExprValueKind VK,
3849  ExprObjectKind OK, SourceLocation opLoc,
3850  FPOptionsOverride FPFeatures);
3854 
3855  Opcode getOpcode() const {
3856  return static_cast<Opcode>(BinaryOperatorBits.Opc);
3857  }
3858  void setOpcode(Opcode Opc) { BinaryOperatorBits.Opc = Opc; }
3859 
3860  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
3861  void setLHS(Expr *E) { SubExprs[LHS] = E; }
3862  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
3863  void setRHS(Expr *E) { SubExprs[RHS] = E; }
3864 
3865  SourceLocation getBeginLoc() const LLVM_READONLY {
3866  return getLHS()->getBeginLoc();
3867  }
3868  SourceLocation getEndLoc() const LLVM_READONLY {
3869  return getRHS()->getEndLoc();
3870  }
3871 
3872  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
3873  /// corresponds to, e.g. "<<=".
3874  static StringRef getOpcodeStr(Opcode Op);
3875 
3876  StringRef getOpcodeStr() const { return getOpcodeStr(getOpcode()); }
3877 
3878  /// Retrieve the binary opcode that corresponds to the given
3879  /// overloaded operator.
3881 
3882  /// Retrieve the overloaded operator kind that corresponds to
3883  /// the given binary opcode.
3885 
3886  /// predicates to categorize the respective opcodes.
3887  static bool isPtrMemOp(Opcode Opc) {
3888  return Opc == BO_PtrMemD || Opc == BO_PtrMemI;
3889  }
3890  bool isPtrMemOp() const { return isPtrMemOp(getOpcode()); }
3891 
3892  static bool isMultiplicativeOp(Opcode Opc) {
3893  return Opc >= BO_Mul && Opc <= BO_Rem;
3894  }
3896  static bool isAdditiveOp(Opcode Opc) { return Opc == BO_Add || Opc==BO_Sub; }
3897  bool isAdditiveOp() const { return isAdditiveOp(getOpcode()); }
3898  static bool isShiftOp(Opcode Opc) { return Opc == BO_Shl || Opc == BO_Shr; }
3899  bool isShiftOp() const { return isShiftOp(getOpcode()); }
3900 
3901  static bool isBitwiseOp(Opcode Opc) { return Opc >= BO_And && Opc <= BO_Or; }
3902  bool isBitwiseOp() const { return isBitwiseOp(getOpcode()); }
3903 
3904  static bool isRelationalOp(Opcode Opc) { return Opc >= BO_LT && Opc<=BO_GE; }
3905  bool isRelationalOp() const { return isRelationalOp(getOpcode()); }
3906 
3907  static bool isEqualityOp(Opcode Opc) { return Opc == BO_EQ || Opc == BO_NE; }
3908  bool isEqualityOp() const { return isEqualityOp(getOpcode()); }
3909 
3910  static bool isComparisonOp(Opcode Opc) { return Opc >= BO_Cmp && Opc<=BO_NE; }
3911  bool isComparisonOp() const { return isComparisonOp(getOpcode()); }
3912 
3913  static bool isCommaOp(Opcode Opc) { return Opc == BO_Comma; }
3914  bool isCommaOp() const { return isCommaOp(getOpcode()); }
3915 
3917  switch (Opc) {
3918  default:
3919  llvm_unreachable("Not a comparison operator.");
3920  case BO_LT: return BO_GE;
3921  case BO_GT: return BO_LE;
3922  case BO_LE: return BO_GT;
3923  case BO_GE: return BO_LT;
3924  case BO_EQ: return BO_NE;
3925  case BO_NE: return BO_EQ;
3926  }
3927  }
3928 
3930  switch (Opc) {
3931  default:
3932  llvm_unreachable("Not a comparison operator.");
3933  case BO_LT: return BO_GT;
3934  case BO_GT: return BO_LT;
3935  case BO_LE: return BO_GE;
3936  case BO_GE: return BO_LE;
3937  case BO_EQ:
3938  case BO_NE:
3939  return Opc;
3940  }
3941  }
3942 
3943  static bool isLogicalOp(Opcode Opc) { return Opc == BO_LAnd || Opc==BO_LOr; }
3944  bool isLogicalOp() const { return isLogicalOp(getOpcode()); }
3945 
3946  static bool isAssignmentOp(Opcode Opc) {
3947  return Opc >= BO_Assign && Opc <= BO_OrAssign;
3948  }
3949  bool isAssignmentOp() const { return isAssignmentOp(getOpcode()); }
3950 
3951  static bool isCompoundAssignmentOp(Opcode Opc) {
3952  return Opc > BO_Assign && Opc <= BO_OrAssign;
3953  }
3954  bool isCompoundAssignmentOp() const {
3956  }
3958  assert(isCompoundAssignmentOp(Opc));
3959  if (Opc >= BO_AndAssign)
3960  return Opcode(unsigned(Opc) - BO_AndAssign + BO_And);
3961  else
3962  return Opcode(unsigned(Opc) - BO_MulAssign + BO_Mul);
3963  }
3964 
3965  static bool isShiftAssignOp(Opcode Opc) {
3966  return Opc == BO_ShlAssign || Opc == BO_ShrAssign;
3967  }
3968  bool isShiftAssignOp() const {
3969  return isShiftAssignOp(getOpcode());
3970  }
3971 
3972  // Return true if a binary operator using the specified opcode and operands
3973  // would match the 'p = (i8*)nullptr + n' idiom for casting a pointer-sized
3974  // integer to a pointer.
3975  static bool isNullPointerArithmeticExtension(ASTContext &Ctx, Opcode Opc,
3976  Expr *LHS, Expr *RHS);
3977 
3978  static bool classof(const Stmt *S) {
3979  return S->getStmtClass() >= firstBinaryOperatorConstant &&
3980  S->getStmtClass() <= lastBinaryOperatorConstant;
3981  }
3982 
3983  // Iterators
3985  return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
3986  }
3988  return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
3989  }
3990 
3991  /// Set and fetch the bit that shows whether FPFeatures needs to be
3992  /// allocated in Trailing Storage
3993  void setHasStoredFPFeatures(bool B) { BinaryOperatorBits.HasFPFeatures = B; }
3994  bool hasStoredFPFeatures() const { return BinaryOperatorBits.HasFPFeatures; }
3995 
3996  /// Get FPFeatures from trailing storage
3998  assert(hasStoredFPFeatures());
3999  return *getTrailingFPFeatures();
4000  }
4001  /// Set FPFeatures in trailing storage, used only by Serialization
4003  assert(BinaryOperatorBits.HasFPFeatures);
4004  *getTrailingFPFeatures() = F;
4005  }
4006 
4007  // Get the FP features status of this operator. Only meaningful for
4008  // operations on floating point types.
4010  if (BinaryOperatorBits.HasFPFeatures)
4011  return getStoredFPFeatures().applyOverrides(LO);
4013  }
4014 
4015  // This is used in ASTImporter
4017  if (BinaryOperatorBits.HasFPFeatures)
4018  return getStoredFPFeatures();
4019  return FPOptionsOverride();
4020  }
4021 
4022  // Get the FP contractability status of this operator. Only meaningful for
4023  // operations on floating point types.
4026  }
4027 
4028  // Get the FENV_ACCESS status of this operator. Only meaningful for
4029  // operations on floating point types.
4030  bool isFEnvAccessOn(const LangOptions &LO) const {
4031  return getFPFeaturesInEffect(LO).getAllowFEnvAccess();
4032  }
4033 
4034 protected:
4035  BinaryOperator(const ASTContext &Ctx, Expr *lhs, Expr *rhs, Opcode opc,
4036  QualType ResTy, ExprValueKind VK, ExprObjectKind OK,
4037  SourceLocation opLoc, FPOptionsOverride FPFeatures,
4038  bool dead2);
4039 
4040  /// Construct an empty BinaryOperator, SC is CompoundAssignOperator.
4041  BinaryOperator(StmtClass SC, EmptyShell Empty) : Expr(SC, Empty) {
4042  BinaryOperatorBits.Opc = BO_MulAssign;
4043  }
4044 
4045  /// Return the size in bytes needed for the trailing objects.
4046  /// Used to allocate the right amount of storage.
4047  static unsigned sizeOfTrailingObjects(bool HasFPFeatures) {
4048  return HasFPFeatures * sizeof(FPOptionsOverride);
4049  }
4050 };
4051 
4052 /// CompoundAssignOperator - For compound assignments (e.g. +=), we keep
4053 /// track of the type the operation is performed in. Due to the semantics of
4054 /// these operators, the operands are promoted, the arithmetic performed, an
4055 /// implicit conversion back to the result type done, then the assignment takes
4056 /// place. This captures the intermediate type which the computation is done
4057 /// in.
4059  QualType ComputationLHSType;
4060  QualType ComputationResultType;
4061 
4062  /// Construct an empty CompoundAssignOperator.
4063  explicit CompoundAssignOperator(const ASTContext &C, EmptyShell Empty,
4064  bool hasFPFeatures)
4065  : BinaryOperator(CompoundAssignOperatorClass, Empty) {}
4066 
4067 protected:
4068  CompoundAssignOperator(const ASTContext &C, Expr *lhs, Expr *rhs, Opcode opc,
4069  QualType ResType, ExprValueKind VK, ExprObjectKind OK,
4070  SourceLocation OpLoc, FPOptionsOverride FPFeatures,
4071  QualType CompLHSType, QualType CompResultType)
4072  : BinaryOperator(C, lhs, rhs, opc, ResType, VK, OK, OpLoc, FPFeatures,
4073  true),
4074  ComputationLHSType(CompLHSType), ComputationResultType(CompResultType) {
4075  assert(isCompoundAssignmentOp() &&
4076  "Only should be used for compound assignments");
4077  }
4078 
4079 public:
4081  bool hasFPFeatures);
4082 
4083  static CompoundAssignOperator *
4084  Create(const ASTContext &C, Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
4086  FPOptionsOverride FPFeatures, QualType CompLHSType = QualType(),
4087  QualType CompResultType = QualType());
4088 
4089  // The two computation types are the type the LHS is converted
4090  // to for the computation and the type of the result; the two are
4091  // distinct in a few cases (specifically, int+=ptr and ptr-=ptr).
4092  QualType getComputationLHSType() const { return ComputationLHSType; }
4093  void setComputationLHSType(QualType T) { ComputationLHSType = T; }
4094 
4095  QualType getComputationResultType() const { return ComputationResultType; }
4096  void setComputationResultType(QualType T) { ComputationResultType = T; }
4097 
4098  static bool classof(const Stmt *S) {
4099  return S->getStmtClass() == CompoundAssignOperatorClass;
4100  }
4101 };
4102 
4104  assert(BinaryOperatorBits.HasFPFeatures);
4105  return isa<CompoundAssignOperator>(this) ? sizeof(CompoundAssignOperator)
4106  : sizeof(BinaryOperator);
4107 }
4108 
4109 /// AbstractConditionalOperator - An abstract base class for
4110 /// ConditionalOperator and BinaryConditionalOperator.
4112  SourceLocation QuestionLoc, ColonLoc;
4113  friend class ASTStmtReader;
4114 
4115 protected:
4117  ExprObjectKind OK, SourceLocation qloc,
4118  SourceLocation cloc)
4119  : Expr(SC, T, VK, OK), QuestionLoc(qloc), ColonLoc(cloc) {}
4120 
4122  : Expr(SC, Empty) { }
4123 
4124 public:
4125  // getCond - Return the expression representing the condition for
4126  // the ?: operator.
4127  Expr *getCond() const;
4128 
4129  // getTrueExpr - Return the subexpression representing the value of
4130  // the expression if the condition evaluates to true.
4131  Expr *getTrueExpr() const;
4132 
4133  // getFalseExpr - Return the subexpression representing the value of
4134  // the expression if the condition evaluates to false. This is
4135  // the same as getRHS.
4136  Expr *getFalseExpr() const;
4137 
4138  SourceLocation getQuestionLoc() const { return QuestionLoc; }
4139  SourceLocation getColonLoc() const { return ColonLoc; }
4140 
4141  static bool classof(const Stmt *T) {
4142  return T->getStmtClass() == ConditionalOperatorClass ||
4143  T->getStmtClass() == BinaryConditionalOperatorClass;
4144  }
4145 };
4146 
4147 /// ConditionalOperator - The ?: ternary operator. The GNU "missing
4148 /// middle" extension is a BinaryConditionalOperator.
4150  enum { COND, LHS, RHS, END_EXPR };
4151  Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
4152 
4153  friend class ASTStmtReader;
4154 public:
4156  SourceLocation CLoc, Expr *rhs, QualType t,
4158  : AbstractConditionalOperator(ConditionalOperatorClass, t, VK, OK, QLoc,
4159  CLoc) {
4160  SubExprs[COND] = cond;
4161  SubExprs[LHS] = lhs;
4162  SubExprs[RHS] = rhs;
4164  }
4165 
4166  /// Build an empty conditional operator.
4168  : AbstractConditionalOperator(ConditionalOperatorClass, Empty) { }
4169 
4170  // getCond - Return the expression representing the condition for
4171  // the ?: operator.
4172  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
4173 
4174  // getTrueExpr - Return the subexpression representing the value of
4175  // the expression if the condition evaluates to true.
4176  Expr *getTrueExpr() const { return cast<Expr>(SubExprs[LHS]); }
4177 
4178  // getFalseExpr - Return the subexpression representing the value of
4179  // the expression if the condition evaluates to false. This is
4180  // the same as getRHS.
4181  Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); }
4182 
4183  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
4184  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
4185 
4186  SourceLocation getBeginLoc() const LLVM_READONLY {
4187  return getCond()->getBeginLoc();
4188  }
4189  SourceLocation getEndLoc() const LLVM_READONLY {
4190  return getRHS()->getEndLoc();
4191  }
4192 
4193  static bool classof(const Stmt *T) {
4194  return T->getStmtClass() == ConditionalOperatorClass;
4195  }
4196 
4197  // Iterators
4199  return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
4200  }
4202  return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
4203  }
4204 };
4205 
4206 /// BinaryConditionalOperator - The GNU extension to the conditional
4207 /// operator which allows the middle operand to be omitted.
4208 ///
4209 /// This is a different expression kind on the assumption that almost
4210 /// every client ends up needing to know that these are different.
4212  enum { COMMON, COND, LHS, RHS, NUM_SUBEXPRS };
4213 
4214  /// - the common condition/left-hand-side expression, which will be
4215  /// evaluated as the opaque value
4216  /// - the condition, expressed in terms of the opaque value
4217  /// - the left-hand-side, expressed in terms of the opaque value
4218  /// - the right-hand-side
4219  Stmt *SubExprs[NUM_SUBEXPRS];
4220  OpaqueValueExpr *OpaqueValue;
4221 
4222  friend class ASTStmtReader;
4223 public:
4225  Expr *cond, Expr *lhs, Expr *rhs,
4226  SourceLocation qloc, SourceLocation cloc,
4228  : AbstractConditionalOperator(BinaryConditionalOperatorClass, t, VK, OK,
4229  qloc, cloc),
4230  OpaqueValue(opaqueValue) {
4231  SubExprs[COMMON] = common;
4232  SubExprs[COND] = cond;
4233  SubExprs[LHS] = lhs;
4234  SubExprs[RHS] = rhs;
4235  assert(OpaqueValue->getSourceExpr() == common && "Wrong opaque value");
4237  }
4238 
4239  /// Build an empty conditional operator.
4241  : AbstractConditionalOperator(BinaryConditionalOperatorClass, Empty) { }
4242 
4243  /// getCommon - Return the common expression, written to the
4244  /// left of the condition. The opaque value will be bound to the
4245  /// result of this expression.
4246  Expr *getCommon() const { return cast<Expr>(SubExprs[COMMON]); }
4247 
4248  /// getOpaqueValue - Return the opaque value placeholder.
4249  OpaqueValueExpr *getOpaqueValue() const { return OpaqueValue; }
4250 
4251  /// getCond - Return the condition expression; this is defined
4252  /// in terms of the opaque value.
4253  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
4254 
4255  /// getTrueExpr - Return the subexpression which will be
4256  /// evaluated if the condition evaluates to true; this is defined
4257  /// in terms of the opaque value.
4258  Expr *getTrueExpr() const {
4259  return cast<Expr>(SubExprs[LHS]);
4260  }
4261 
4262  /// getFalseExpr - Return the subexpression which will be
4263  /// evaluated if the condnition evaluates to false; this is
4264  /// defined in terms of the opaque value.
4265  Expr *getFalseExpr() const {
4266  return cast<Expr>(SubExprs[RHS]);
4267  }
4268 
4269  SourceLocation getBeginLoc() const LLVM_READONLY {
4270  return getCommon()->getBeginLoc();
4271  }
4272  SourceLocation getEndLoc() const LLVM_READONLY {
4273  return getFalseExpr()->getEndLoc();
4274  }
4275 
4276  static bool classof(const Stmt *T) {
4277  return T->getStmtClass() == BinaryConditionalOperatorClass;
4278  }
4279 
4280  // Iterators
4282  return child_range(SubExprs, SubExprs + NUM_SUBEXPRS);
4283  }
4285  return const_child_range(SubExprs, SubExprs + NUM_SUBEXPRS);
4286  }
4287 };
4288 
4290  if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this))
4291  return co->getCond();
4292  return cast<BinaryConditionalOperator>(this)->getCond();
4293 }
4294 
4296  if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this))
4297  return co->getTrueExpr();
4298  return cast<BinaryConditionalOperator>(this)->getTrueExpr();
4299 }
4300 
4302  if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this))
4303  return co->getFalseExpr();
4304  return cast<BinaryConditionalOperator>(this)->getFalseExpr();
4305 }
4306 
4307 /// AddrLabelExpr - The GNU address of label extension, representing &&label.
4308 class AddrLabelExpr : public Expr {
4309  SourceLocation AmpAmpLoc, LabelLoc;
4310  LabelDecl *Label;
4311 public:
4313  QualType t)
4314  : Expr(AddrLabelExprClass, t, VK_PRValue, OK_Ordinary), AmpAmpLoc(AALoc),
4315  LabelLoc(LLoc), Label(L) {
4317  }
4318 
4319  /// Build an empty address of a label expression.
4320  explicit AddrLabelExpr(EmptyShell Empty)
4321  : Expr(AddrLabelExprClass, Empty) { }
4322 
4323  SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; }
4324  void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; }
4325  SourceLocation getLabelLoc() const { return LabelLoc; }
4326  void setLabelLoc(SourceLocation L) { LabelLoc = L; }
4327 
4328  SourceLocation getBeginLoc() const LLVM_READONLY { return AmpAmpLoc; }
4329  SourceLocation getEndLoc() const LLVM_READONLY { return LabelLoc; }
4330 
4331  LabelDecl *getLabel() const { return Label; }
4332  void setLabel(LabelDecl *L) { Label = L; }
4333 
4334  static bool classof(const Stmt *T) {
4335  return T->getStmtClass() == AddrLabelExprClass;
4336  }
4337 
4338  // Iterators
4341  }
4344  }
4345 };
4346 
4347 /// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
4348 /// The StmtExpr contains a single CompoundStmt node, which it evaluates and
4349 /// takes the value of the last subexpression.
4350 ///
4351 /// A StmtExpr is always an r-value; values "returned" out of a
4352 /// StmtExpr will be copied.
4353 class StmtExpr : public Expr {
4354  Stmt *SubStmt;
4355  SourceLocation LParenLoc, RParenLoc;
4356 public:
4358  SourceLocation RParenLoc, unsigned TemplateDepth)
4359  : Expr(StmtExprClass, T, VK_PRValue, OK_Ordinary), SubStmt(SubStmt),
4360  LParenLoc(LParenLoc), RParenLoc(RParenLoc) {
4361  setDependence(computeDependence(this, TemplateDepth));
4362  // FIXME: A templated statement expression should have an associated
4363  // DeclContext so that nested declarations always have a dependent context.
4364  StmtExprBits.TemplateDepth = TemplateDepth;
4365  }
4366 
4367  /// Build an empty statement expression.
4368  explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { }
4369 
4370  CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); }
4371  const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); }
4372  void setSubStmt(CompoundStmt *S) { SubStmt = S; }
4373 
4374  SourceLocation getBeginLoc() const LLVM_READONLY { return LParenLoc; }
4375  SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
4376 
4377  SourceLocation getLParenLoc() const { return LParenLoc; }
4378  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
4379  SourceLocation getRParenLoc() const { return RParenLoc; }
4380  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
4381 
4382  unsigned getTemplateDepth() const { return StmtExprBits.TemplateDepth; }
4383 
4384  static bool classof(const Stmt *T) {
4385  return T->getStmtClass() == StmtExprClass;
4386  }
4387 
4388  // Iterators
4389  child_range children() { return child_range(&SubStmt, &SubStmt+1); }
4391  return const_child_range(&SubStmt, &SubStmt + 1);
4392  }
4393 };
4394 
4395 /// ShuffleVectorExpr - clang-specific builtin-in function
4396 /// __builtin_shufflevector.
4397 /// This AST node represents a operator that does a constant
4398 /// shuffle, similar to LLVM's shufflevector instruction. It takes
4399 /// two vectors and a variable number of constant indices,
4400 /// and returns the appropriately shuffled vector.
4401 class ShuffleVectorExpr : public Expr {
4402  SourceLocation BuiltinLoc, RParenLoc;
4403 
4404  // SubExprs - the list of values passed to the __builtin_shufflevector
4405  // function. The first two are vectors, and the rest are constant
4406  // indices. The number of values in this list is always
4407  // 2+the number of indices in the vector type.
4408  Stmt **SubExprs;
4409  unsigned NumExprs;
4410 
4411 public:
4413  SourceLocation BLoc, SourceLocation RP);
4414 
4415  /// Build an empty vector-shuffle expression.
4417  : Expr(ShuffleVectorExprClass, Empty), SubExprs(nullptr) { }
4418 
4419  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
4420  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
4421 
4422  SourceLocation getRParenLoc() const { return RParenLoc; }
4423  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
4424 
4425  SourceLocation getBeginLoc() const LLVM_READONLY { return BuiltinLoc; }
4426  SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
4427 
4428  static bool classof(const Stmt *T) {
4429  return T->getStmtClass() == ShuffleVectorExprClass;
4430  }
4431 
4432  /// getNumSubExprs - Return the size of the SubExprs array. This includes the
4433  /// constant expression, the actual arguments passed in, and the function
4434  /// pointers.
4435  unsigned getNumSubExprs() const { return NumExprs; }
4436 
4437  /// Retrieve the array of expressions.
4438  Expr **getSubExprs() { return reinterpret_cast<Expr **>(SubExprs); }
4439 
4440  /// getExpr - Return the Expr at the specified index.
4441  Expr *getExpr(unsigned Index) {
4442  assert((Index < NumExprs) && "Arg access out of range!");
4443  return cast<Expr>(SubExprs[Index]);
4444  }
4445  const Expr *getExpr(unsigned Index) const {
4446  assert((Index < NumExprs) && "Arg access out of range!");
4447  return cast<Expr>(SubExprs[Index]);
4448  }
4449 
4450  void setExprs(const ASTContext &C, ArrayRef<Expr *> Exprs);
4451 
4452  llvm::APSInt getShuffleMaskIdx(const ASTContext &Ctx, unsigned N) const {
4453  assert((N < NumExprs - 2) && "Shuffle idx out of range!");
4454  return getExpr(N+2)->EvaluateKnownConstInt(Ctx);
4455  }
4456 
4457  // Iterators
4459  return child_range(&SubExprs[0], &SubExprs[0]+NumExprs);
4460  }
4462  return const_child_range(&SubExprs[0], &SubExprs[0] + NumExprs);
4463  }
4464 };
4465 
4466 /// ConvertVectorExpr - Clang builtin function __builtin_convertvector
4467 /// This AST node provides support for converting a vector type to another
4468 /// vector type of the same arity.
4469 class ConvertVectorExpr : public Expr {
4470 private:
4471  Stmt *SrcExpr;
4472  TypeSourceInfo *TInfo;
4473  SourceLocation BuiltinLoc, RParenLoc;
4474 
4475  friend class ASTReader;
4476  friend class ASTStmtReader;
4477  explicit ConvertVectorExpr(EmptyShell Empty) : Expr(ConvertVectorExprClass, Empty) {}
4478 
4479 public:
4482  SourceLocation BuiltinLoc, SourceLocation RParenLoc)
4483  : Expr(ConvertVectorExprClass, DstType, VK, OK), SrcExpr(SrcExpr),
4484  TInfo(TI), BuiltinLoc(BuiltinLoc), RParenLoc(RParenLoc) {
4486  }
4487 
4488  /// getSrcExpr - Return the Expr to be converted.
4489  Expr *getSrcExpr() const { return cast<Expr>(SrcExpr); }
4490 
4491  /// getTypeSourceInfo - Return the destination type.
4493  return TInfo;
4494  }
4496  TInfo = ti;
4497  }
4498 
4499  /// getBuiltinLoc - Return the location of the __builtin_convertvector token.
4500  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
4501 
4502  /// getRParenLoc - Return the location of final right parenthesis.
4503  SourceLocation getRParenLoc() const { return RParenLoc; }
4504 
4505  SourceLocation getBeginLoc() const LLVM_READONLY { return BuiltinLoc; }
4506  SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
4507 
4508  static bool classof(const Stmt *T) {
4509  return T->getStmtClass() == ConvertVectorExprClass;
4510  }
4511 
4512  // Iterators
4513  child_range children() { return child_range(&SrcExpr, &SrcExpr+1); }
4515  return const_child_range(&SrcExpr, &SrcExpr + 1);
4516  }
4517 };
4518 
4519 /// ChooseExpr - GNU builtin-in function __builtin_choose_expr.
4520 /// This AST node is similar to the conditional operator (?:) in C, with
4521 /// the following exceptions:
4522 /// - the test expression must be a integer constant expression.
4523 /// - the expression returned acts like the chosen subexpression in every
4524 /// visible way: the type is the same as that of the chosen subexpression,
4525 /// and all predicates (whether it's an l-value, whether it's an integer
4526 /// constant expression, etc.) return the same result as for the chosen
4527 /// sub-expression.
4528 class ChooseExpr : public Expr {
4529  enum { COND, LHS, RHS, END_EXPR };
4530  Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
4531  SourceLocation BuiltinLoc, RParenLoc;
4532  bool CondIsTrue;
4533 public:
4534  ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, QualType t,
4536  bool condIsTrue)
4537  : Expr(ChooseExprClass, t, VK, OK), BuiltinLoc(BLoc), RParenLoc(RP),
4538  CondIsTrue(condIsTrue) {
4539  SubExprs[COND] = cond;
4540  SubExprs[LHS] = lhs;
4541  SubExprs[RHS] = rhs;
4542 
4544  }
4545 
4546  /// Build an empty __builtin_choose_expr.
4547  explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { }
4548 
4549  /// isConditionTrue - Return whether the condition is true (i.e. not
4550  /// equal to zero).
4551  bool isConditionTrue() const {
4552  assert(!isConditionDependent() &&
4553  "Dependent condition isn't true or false");
4554  return CondIsTrue;
4555  }
4556  void setIsConditionTrue(bool isTrue) { CondIsTrue = isTrue; }
4557 
4558  bool isConditionDependent() const {
4559  return getCond()->isTypeDependent() || getCond()->isValueDependent();
4560  }
4561 
4562  /// getChosenSubExpr - Return the subexpression chosen according to the
4563  /// condition.
4565  return isConditionTrue() ?