clang  8.0.0svn
Expr.h
Go to the documentation of this file.
1 //===--- Expr.h - Classes for representing expressions ----------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the Expr interface and subclasses.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_AST_EXPR_H
15 #define LLVM_CLANG_AST_EXPR_H
16 
17 #include "clang/AST/APValue.h"
18 #include "clang/AST/ASTVector.h"
19 #include "clang/AST/Decl.h"
22 #include "clang/AST/Stmt.h"
23 #include "clang/AST/TemplateBase.h"
24 #include "clang/AST/Type.h"
25 #include "clang/Basic/CharInfo.h"
27 #include "clang/Basic/SyncScope.h"
28 #include "clang/Basic/TypeTraits.h"
29 #include "llvm/ADT/APFloat.h"
30 #include "llvm/ADT/APSInt.h"
31 #include "llvm/ADT/SmallVector.h"
32 #include "llvm/ADT/StringRef.h"
33 #include "llvm/Support/AtomicOrdering.h"
34 #include "llvm/Support/Compiler.h"
35 
36 namespace clang {
37  class APValue;
38  class ASTContext;
39  class BlockDecl;
40  class CXXBaseSpecifier;
41  class CXXMemberCallExpr;
42  class CXXOperatorCallExpr;
43  class CastExpr;
44  class Decl;
45  class IdentifierInfo;
46  class MaterializeTemporaryExpr;
47  class NamedDecl;
48  class ObjCPropertyRefExpr;
49  class OpaqueValueExpr;
50  class ParmVarDecl;
51  class StringLiteral;
52  class TargetInfo;
53  class ValueDecl;
54 
55 /// A simple array of base specifiers.
57 
58 /// An adjustment to be made to the temporary created when emitting a
59 /// reference binding, which accesses a particular subobject of that temporary.
61  enum {
65  } Kind;
66 
67  struct DTB {
70  };
71 
72  struct P {
75  };
76 
77  union {
80  struct P Ptr;
81  };
82 
85  : Kind(DerivedToBaseAdjustment) {
88  }
89 
91  : Kind(FieldAdjustment) {
92  this->Field = Field;
93  }
94 
96  : Kind(MemberPointerAdjustment) {
97  this->Ptr.MPT = MPT;
98  this->Ptr.RHS = RHS;
99  }
100 };
101 
102 /// Expr - This represents one expression. Note that Expr's are subclasses of
103 /// Stmt. This allows an expression to be transparently used any place a Stmt
104 /// is required.
105 ///
106 class Expr : public Stmt {
107  QualType TR;
108 
109 protected:
111  bool TD, bool VD, bool ID, bool ContainsUnexpandedParameterPack)
112  : Stmt(SC)
113  {
114  ExprBits.TypeDependent = TD;
115  ExprBits.ValueDependent = VD;
116  ExprBits.InstantiationDependent = ID;
117  ExprBits.ValueKind = VK;
118  ExprBits.ObjectKind = OK;
119  assert(ExprBits.ObjectKind == OK && "truncated kind");
120  ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack;
121  setType(T);
122  }
123 
124  /// Construct an empty expression.
125  explicit Expr(StmtClass SC, EmptyShell) : Stmt(SC) { }
126 
127 public:
128  QualType getType() const { return TR; }
129  void setType(QualType t) {
130  // In C++, the type of an expression is always adjusted so that it
131  // will not have reference type (C++ [expr]p6). Use
132  // QualType::getNonReferenceType() to retrieve the non-reference
133  // type. Additionally, inspect Expr::isLvalue to determine whether
134  // an expression that is adjusted in this manner should be
135  // considered an lvalue.
136  assert((t.isNull() || !t->isReferenceType()) &&
137  "Expressions can't have reference type");
138 
139  TR = t;
140  }
141 
142  /// isValueDependent - Determines whether this expression is
143  /// value-dependent (C++ [temp.dep.constexpr]). For example, the
144  /// array bound of "Chars" in the following example is
145  /// value-dependent.
146  /// @code
147  /// template<int Size, char (&Chars)[Size]> struct meta_string;
148  /// @endcode
149  bool isValueDependent() const { return ExprBits.ValueDependent; }
150 
151  /// Set whether this expression is value-dependent or not.
152  void setValueDependent(bool VD) {
153  ExprBits.ValueDependent = VD;
154  }
155 
156  /// isTypeDependent - Determines whether this expression is
157  /// type-dependent (C++ [temp.dep.expr]), which means that its type
158  /// could change from one template instantiation to the next. For
159  /// example, the expressions "x" and "x + y" are type-dependent in
160  /// the following code, but "y" is not type-dependent:
161  /// @code
162  /// template<typename T>
163  /// void add(T x, int y) {
164  /// x + y;
165  /// }
166  /// @endcode
167  bool isTypeDependent() const { return ExprBits.TypeDependent; }
168 
169  /// Set whether this expression is type-dependent or not.
170  void setTypeDependent(bool TD) {
171  ExprBits.TypeDependent = TD;
172  }
173 
174  /// Whether this expression is instantiation-dependent, meaning that
175  /// it depends in some way on a template parameter, even if neither its type
176  /// nor (constant) value can change due to the template instantiation.
177  ///
178  /// In the following example, the expression \c sizeof(sizeof(T() + T())) is
179  /// instantiation-dependent (since it involves a template parameter \c T), but
180  /// is neither type- nor value-dependent, since the type of the inner
181  /// \c sizeof is known (\c std::size_t) and therefore the size of the outer
182  /// \c sizeof is known.
183  ///
184  /// \code
185  /// template<typename T>
186  /// void f(T x, T y) {
187  /// sizeof(sizeof(T() + T());
188  /// }
189  /// \endcode
190  ///
192  return ExprBits.InstantiationDependent;
193  }
194 
195  /// Set whether this expression is instantiation-dependent or not.
197  ExprBits.InstantiationDependent = ID;
198  }
199 
200  /// Whether this expression contains an unexpanded parameter
201  /// pack (for C++11 variadic templates).
202  ///
203  /// Given the following function template:
204  ///
205  /// \code
206  /// template<typename F, typename ...Types>
207  /// void forward(const F &f, Types &&...args) {
208  /// f(static_cast<Types&&>(args)...);
209  /// }
210  /// \endcode
211  ///
212  /// The expressions \c args and \c static_cast<Types&&>(args) both
213  /// contain parameter packs.
215  return ExprBits.ContainsUnexpandedParameterPack;
216  }
217 
218  /// Set the bit that describes whether this expression
219  /// contains an unexpanded parameter pack.
220  void setContainsUnexpandedParameterPack(bool PP = true) {
221  ExprBits.ContainsUnexpandedParameterPack = PP;
222  }
223 
224  /// getExprLoc - Return the preferred location for the arrow when diagnosing
225  /// a problem with a generic expression.
226  SourceLocation getExprLoc() const LLVM_READONLY;
227 
228  /// isUnusedResultAWarning - Return true if this immediate expression should
229  /// be warned about if the result is unused. If so, fill in expr, location,
230  /// and ranges with expr to warn on and source locations/ranges appropriate
231  /// for a warning.
232  bool isUnusedResultAWarning(const Expr *&WarnExpr, SourceLocation &Loc,
233  SourceRange &R1, SourceRange &R2,
234  ASTContext &Ctx) const;
235 
236  /// isLValue - True if this expression is an "l-value" according to
237  /// the rules of the current language. C and C++ give somewhat
238  /// different rules for this concept, but in general, the result of
239  /// an l-value expression identifies a specific object whereas the
240  /// result of an r-value expression is a value detached from any
241  /// specific storage.
242  ///
243  /// C++11 divides the concept of "r-value" into pure r-values
244  /// ("pr-values") and so-called expiring values ("x-values"), which
245  /// identify specific objects that can be safely cannibalized for
246  /// their resources. This is an unfortunate abuse of terminology on
247  /// the part of the C++ committee. In Clang, when we say "r-value",
248  /// we generally mean a pr-value.
249  bool isLValue() const { return getValueKind() == VK_LValue; }
250  bool isRValue() const { return getValueKind() == VK_RValue; }
251  bool isXValue() const { return getValueKind() == VK_XValue; }
252  bool isGLValue() const { return getValueKind() != VK_RValue; }
253 
264  LV_ArrayTemporary
265  };
266  /// Reasons why an expression might not be an l-value.
267  LValueClassification ClassifyLValue(ASTContext &Ctx) const;
268 
275  MLV_LValueCast, // Specialized form of MLV_InvalidExpression.
286  MLV_ArrayTemporary
287  };
288  /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type,
289  /// does not have an incomplete type, does not have a const-qualified type,
290  /// and if it is a structure or union, does not have any member (including,
291  /// recursively, any member or element of all contained aggregates or unions)
292  /// with a const-qualified type.
293  ///
294  /// \param Loc [in,out] - A source location which *may* be filled
295  /// in with the location of the expression making this a
296  /// non-modifiable lvalue, if specified.
298  isModifiableLvalue(ASTContext &Ctx, SourceLocation *Loc = nullptr) const;
299 
300  /// The return type of classify(). Represents the C++11 expression
301  /// taxonomy.
303  public:
304  /// The various classification results. Most of these mean prvalue.
305  enum Kinds {
308  CL_Function, // Functions cannot be lvalues in C.
309  CL_Void, // Void cannot be an lvalue in C.
310  CL_AddressableVoid, // Void expression whose address can be taken in C.
311  CL_DuplicateVectorComponents, // A vector shuffle with dupes.
312  CL_MemberFunction, // An expression referring to a member function
314  CL_ClassTemporary, // A temporary of class type, or subobject thereof.
315  CL_ArrayTemporary, // A temporary of array type.
316  CL_ObjCMessageRValue, // ObjC message is an rvalue
317  CL_PRValue // A prvalue for any other reason, of any other type
318  };
319  /// The results of modification testing.
321  CM_Untested, // testModifiable was false.
323  CM_RValue, // Not modifiable because it's an rvalue
324  CM_Function, // Not modifiable because it's a function; C++ only
325  CM_LValueCast, // Same as CM_RValue, but indicates GCC cast-as-lvalue ext
326  CM_NoSetterProperty,// Implicit assignment to ObjC property without setter
331  CM_IncompleteType
332  };
333 
334  private:
335  friend class Expr;
336 
337  unsigned short Kind;
338  unsigned short Modifiable;
339 
340  explicit Classification(Kinds k, ModifiableType m)
341  : Kind(k), Modifiable(m)
342  {}
343 
344  public:
346 
347  Kinds getKind() const { return static_cast<Kinds>(Kind); }
349  assert(Modifiable != CM_Untested && "Did not test for modifiability.");
350  return static_cast<ModifiableType>(Modifiable);
351  }
352  bool isLValue() const { return Kind == CL_LValue; }
353  bool isXValue() const { return Kind == CL_XValue; }
354  bool isGLValue() const { return Kind <= CL_XValue; }
355  bool isPRValue() const { return Kind >= CL_Function; }
356  bool isRValue() const { return Kind >= CL_XValue; }
357  bool isModifiable() const { return getModifiable() == CM_Modifiable; }
358 
359  /// Create a simple, modifiably lvalue
361  return Classification(CL_LValue, CM_Modifiable);
362  }
363 
364  };
365  /// Classify - Classify this expression according to the C++11
366  /// expression taxonomy.
367  ///
368  /// C++11 defines ([basic.lval]) a new taxonomy of expressions to replace the
369  /// old lvalue vs rvalue. This function determines the type of expression this
370  /// is. There are three expression types:
371  /// - lvalues are classical lvalues as in C++03.
372  /// - prvalues are equivalent to rvalues in C++03.
373  /// - xvalues are expressions yielding unnamed rvalue references, e.g. a
374  /// function returning an rvalue reference.
375  /// lvalues and xvalues are collectively referred to as glvalues, while
376  /// prvalues and xvalues together form rvalues.
378  return ClassifyImpl(Ctx, nullptr);
379  }
380 
381  /// ClassifyModifiable - Classify this expression according to the
382  /// C++11 expression taxonomy, and see if it is valid on the left side
383  /// of an assignment.
384  ///
385  /// This function extends classify in that it also tests whether the
386  /// expression is modifiable (C99 6.3.2.1p1).
387  /// \param Loc A source location that might be filled with a relevant location
388  /// if the expression is not modifiable.
390  return ClassifyImpl(Ctx, &Loc);
391  }
392 
393  /// getValueKindForType - Given a formal return or parameter type,
394  /// give its value kind.
396  if (const ReferenceType *RT = T->getAs<ReferenceType>())
397  return (isa<LValueReferenceType>(RT)
398  ? VK_LValue
399  : (RT->getPointeeType()->isFunctionType()
400  ? VK_LValue : VK_XValue));
401  return VK_RValue;
402  }
403 
404  /// getValueKind - The value kind that this expression produces.
406  return static_cast<ExprValueKind>(ExprBits.ValueKind);
407  }
408 
409  /// getObjectKind - The object kind that this expression produces.
410  /// Object kinds are meaningful only for expressions that yield an
411  /// l-value or x-value.
413  return static_cast<ExprObjectKind>(ExprBits.ObjectKind);
414  }
415 
417  ExprObjectKind OK = getObjectKind();
418  return (OK == OK_Ordinary || OK == OK_BitField);
419  }
420 
421  /// setValueKind - Set the value kind produced by this expression.
422  void setValueKind(ExprValueKind Cat) { ExprBits.ValueKind = Cat; }
423 
424  /// setObjectKind - Set the object kind produced by this expression.
425  void setObjectKind(ExprObjectKind Cat) { ExprBits.ObjectKind = Cat; }
426 
427 private:
428  Classification ClassifyImpl(ASTContext &Ctx, SourceLocation *Loc) const;
429 
430 public:
431 
432  /// Returns true if this expression is a gl-value that
433  /// potentially refers to a bit-field.
434  ///
435  /// In C++, whether a gl-value refers to a bitfield is essentially
436  /// an aspect of the value-kind type system.
437  bool refersToBitField() const { return getObjectKind() == OK_BitField; }
438 
439  /// If this expression refers to a bit-field, retrieve the
440  /// declaration of that bit-field.
441  ///
442  /// Note that this returns a non-null pointer in subtly different
443  /// places than refersToBitField returns true. In particular, this can
444  /// return a non-null pointer even for r-values loaded from
445  /// bit-fields, but it will return null for a conditional bit-field.
446  FieldDecl *getSourceBitField();
447 
448  const FieldDecl *getSourceBitField() const {
449  return const_cast<Expr*>(this)->getSourceBitField();
450  }
451 
452  Decl *getReferencedDeclOfCallee();
454  return const_cast<Expr*>(this)->getReferencedDeclOfCallee();
455  }
456 
457  /// If this expression is an l-value for an Objective C
458  /// property, find the underlying property reference expression.
459  const ObjCPropertyRefExpr *getObjCProperty() const;
460 
461  /// Check if this expression is the ObjC 'self' implicit parameter.
462  bool isObjCSelfExpr() const;
463 
464  /// Returns whether this expression refers to a vector element.
465  bool refersToVectorElement() const;
466 
467  /// Returns whether this expression refers to a global register
468  /// variable.
469  bool refersToGlobalRegisterVar() const;
470 
471  /// Returns whether this expression has a placeholder type.
472  bool hasPlaceholderType() const {
473  return getType()->isPlaceholderType();
474  }
475 
476  /// Returns whether this expression has a specific placeholder type.
479  if (const BuiltinType *BT = dyn_cast<BuiltinType>(getType()))
480  return BT->getKind() == K;
481  return false;
482  }
483 
484  /// isKnownToHaveBooleanValue - Return true if this is an integer expression
485  /// that is known to return 0 or 1. This happens for _Bool/bool expressions
486  /// but also int expressions which are produced by things like comparisons in
487  /// C.
488  bool isKnownToHaveBooleanValue() const;
489 
490  /// isIntegerConstantExpr - Return true if this expression is a valid integer
491  /// constant expression, and, if so, return its value in Result. If not a
492  /// valid i-c-e, return false and fill in Loc (if specified) with the location
493  /// of the invalid expression.
494  ///
495  /// Note: This does not perform the implicit conversions required by C++11
496  /// [expr.const]p5.
497  bool isIntegerConstantExpr(llvm::APSInt &Result, const ASTContext &Ctx,
498  SourceLocation *Loc = nullptr,
499  bool isEvaluated = true) const;
500  bool isIntegerConstantExpr(const ASTContext &Ctx,
501  SourceLocation *Loc = nullptr) const;
502 
503  /// isCXX98IntegralConstantExpr - Return true if this expression is an
504  /// integral constant expression in C++98. Can only be used in C++.
505  bool isCXX98IntegralConstantExpr(const ASTContext &Ctx) const;
506 
507  /// isCXX11ConstantExpr - Return true if this expression is a constant
508  /// expression in C++11. Can only be used in C++.
509  ///
510  /// Note: This does not perform the implicit conversions required by C++11
511  /// [expr.const]p5.
512  bool isCXX11ConstantExpr(const ASTContext &Ctx, APValue *Result = nullptr,
513  SourceLocation *Loc = nullptr) const;
514 
515  /// isPotentialConstantExpr - Return true if this function's definition
516  /// might be usable in a constant expression in C++11, if it were marked
517  /// constexpr. Return false if the function can never produce a constant
518  /// expression, along with diagnostics describing why not.
519  static bool isPotentialConstantExpr(const FunctionDecl *FD,
521  PartialDiagnosticAt> &Diags);
522 
523  /// isPotentialConstantExprUnevaluted - Return true if this expression might
524  /// be usable in a constant expression in C++11 in an unevaluated context, if
525  /// it were in function FD marked constexpr. Return false if the function can
526  /// never produce a constant expression, along with diagnostics describing
527  /// why not.
528  static bool isPotentialConstantExprUnevaluated(Expr *E,
529  const FunctionDecl *FD,
531  PartialDiagnosticAt> &Diags);
532 
533  /// isConstantInitializer - Returns true if this expression can be emitted to
534  /// IR as a constant, and thus can be used as a constant initializer in C.
535  /// If this expression is not constant and Culprit is non-null,
536  /// it is used to store the address of first non constant expr.
537  bool isConstantInitializer(ASTContext &Ctx, bool ForRef,
538  const Expr **Culprit = nullptr) const;
539 
540  /// EvalStatus is a struct with detailed info about an evaluation in progress.
541  struct EvalStatus {
542  /// Whether the evaluated expression has side effects.
543  /// For example, (f() && 0) can be folded, but it still has side effects.
545 
546  /// Whether the evaluation hit undefined behavior.
547  /// For example, 1.0 / 0.0 can be folded to Inf, but has undefined behavior.
548  /// Likewise, INT_MAX + 1 can be folded to INT_MIN, but has UB.
550 
551  /// Diag - If this is non-null, it will be filled in with a stack of notes
552  /// indicating why evaluation failed (or why it failed to produce a constant
553  /// expression).
554  /// If the expression is unfoldable, the notes will indicate why it's not
555  /// foldable. If the expression is foldable, but not a constant expression,
556  /// the notes will describes why it isn't a constant expression. If the
557  /// expression *is* a constant expression, no notes will be produced.
559 
561  : HasSideEffects(false), HasUndefinedBehavior(false), Diag(nullptr) {}
562 
563  // hasSideEffects - Return true if the evaluated expression has
564  // side effects.
565  bool hasSideEffects() const {
566  return HasSideEffects;
567  }
568  };
569 
570  /// EvalResult is a struct with detailed info about an evaluated expression.
572  /// Val - This is the value the expression can be folded to.
574 
575  // isGlobalLValue - Return true if the evaluated lvalue expression
576  // is global.
577  bool isGlobalLValue() const;
578  };
579 
580  /// EvaluateAsRValue - Return true if this is a constant which we can fold to
581  /// an rvalue using any crazy technique (that has nothing to do with language
582  /// standards) that we want to, even if the expression has side-effects. If
583  /// this function returns true, it returns the folded constant in Result. If
584  /// the expression is a glvalue, an lvalue-to-rvalue conversion will be
585  /// applied.
586  bool EvaluateAsRValue(EvalResult &Result, const ASTContext &Ctx) const;
587 
588  /// EvaluateAsBooleanCondition - Return true if this is a constant
589  /// which we can fold and convert to a boolean condition using
590  /// any crazy technique that we want to, even if the expression has
591  /// side-effects.
592  bool EvaluateAsBooleanCondition(bool &Result, const ASTContext &Ctx) const;
593 
595  SE_NoSideEffects, ///< Strictly evaluate the expression.
596  SE_AllowUndefinedBehavior, ///< Allow UB that we can give a value, but not
597  ///< arbitrary unmodeled side effects.
598  SE_AllowSideEffects ///< Allow any unmodeled side effect.
599  };
600 
601  /// EvaluateAsInt - Return true if this is a constant which we can fold and
602  /// convert to an integer, using any crazy technique that we want to.
603  bool EvaluateAsInt(llvm::APSInt &Result, const ASTContext &Ctx,
604  SideEffectsKind AllowSideEffects = SE_NoSideEffects) const;
605 
606  /// EvaluateAsFloat - Return true if this is a constant which we can fold and
607  /// convert to a floating point value, using any crazy technique that we
608  /// want to.
609  bool
610  EvaluateAsFloat(llvm::APFloat &Result, const ASTContext &Ctx,
611  SideEffectsKind AllowSideEffects = SE_NoSideEffects) const;
612 
613  /// isEvaluatable - Call EvaluateAsRValue to see if this expression can be
614  /// constant folded without side-effects, but discard the result.
615  bool isEvaluatable(const ASTContext &Ctx,
616  SideEffectsKind AllowSideEffects = SE_NoSideEffects) const;
617 
618  /// HasSideEffects - This routine returns true for all those expressions
619  /// which have any effect other than producing a value. Example is a function
620  /// call, volatile variable read, or throwing an exception. If
621  /// IncludePossibleEffects is false, this call treats certain expressions with
622  /// potential side effects (such as function call-like expressions,
623  /// instantiation-dependent expressions, or invocations from a macro) as not
624  /// having side effects.
625  bool HasSideEffects(const ASTContext &Ctx,
626  bool IncludePossibleEffects = true) const;
627 
628  /// Determine whether this expression involves a call to any function
629  /// that is not trivial.
630  bool hasNonTrivialCall(const ASTContext &Ctx) const;
631 
632  /// EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded
633  /// integer. This must be called on an expression that constant folds to an
634  /// integer.
635  llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx,
636  SmallVectorImpl<PartialDiagnosticAt> *Diag = nullptr) const;
637 
638  void EvaluateForOverflow(const ASTContext &Ctx) const;
639 
640  /// EvaluateAsLValue - Evaluate an expression to see if we can fold it to an
641  /// lvalue with link time known address, with no side-effects.
642  bool EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx) const;
643 
644  /// EvaluateAsInitializer - Evaluate an expression as if it were the
645  /// initializer of the given declaration. Returns true if the initializer
646  /// can be folded to a constant, and produces any relevant notes. In C++11,
647  /// notes will be produced if the expression is not a constant expression.
648  bool EvaluateAsInitializer(APValue &Result, const ASTContext &Ctx,
649  const VarDecl *VD,
651 
652  /// EvaluateWithSubstitution - Evaluate an expression as if from the context
653  /// of a call to the given function with the given arguments, inside an
654  /// unevaluated context. Returns true if the expression could be folded to a
655  /// constant.
656  bool EvaluateWithSubstitution(APValue &Value, ASTContext &Ctx,
657  const FunctionDecl *Callee,
659  const Expr *This = nullptr) const;
660 
661  /// Indicates how the constant expression will be used.
662  enum ConstExprUsage { EvaluateForCodeGen, EvaluateForMangling };
663 
664  /// Evaluate an expression that is required to be a constant expression.
665  bool EvaluateAsConstantExpr(EvalResult &Result, ConstExprUsage Usage,
666  const ASTContext &Ctx) const;
667 
668  /// If the current Expr is a pointer, this will try to statically
669  /// determine the number of bytes available where the pointer is pointing.
670  /// Returns true if all of the above holds and we were able to figure out the
671  /// size, false otherwise.
672  ///
673  /// \param Type - How to evaluate the size of the Expr, as defined by the
674  /// "type" parameter of __builtin_object_size
675  bool tryEvaluateObjectSize(uint64_t &Result, ASTContext &Ctx,
676  unsigned Type) const;
677 
678  /// Enumeration used to describe the kind of Null pointer constant
679  /// returned from \c isNullPointerConstant().
681  /// Expression is not a Null pointer constant.
682  NPCK_NotNull = 0,
683 
684  /// Expression is a Null pointer constant built from a zero integer
685  /// expression that is not a simple, possibly parenthesized, zero literal.
686  /// C++ Core Issue 903 will classify these expressions as "not pointers"
687  /// once it is adopted.
688  /// http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#903
690 
691  /// Expression is a Null pointer constant built from a literal zero.
693 
694  /// Expression is a C++11 nullptr.
696 
697  /// Expression is a GNU-style __null constant.
698  NPCK_GNUNull
699  };
700 
701  /// Enumeration used to describe how \c isNullPointerConstant()
702  /// should cope with value-dependent expressions.
704  /// Specifies that the expression should never be value-dependent.
705  NPC_NeverValueDependent = 0,
706 
707  /// Specifies that a value-dependent expression of integral or
708  /// dependent type should be considered a null pointer constant.
710 
711  /// Specifies that a value-dependent expression should be considered
712  /// to never be a null pointer constant.
713  NPC_ValueDependentIsNotNull
714  };
715 
716  /// isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to
717  /// a Null pointer constant. The return value can further distinguish the
718  /// kind of NULL pointer constant that was detected.
719  NullPointerConstantKind isNullPointerConstant(
720  ASTContext &Ctx,
722 
723  /// isOBJCGCCandidate - Return true if this expression may be used in a read/
724  /// write barrier.
725  bool isOBJCGCCandidate(ASTContext &Ctx) const;
726 
727  /// Returns true if this expression is a bound member function.
728  bool isBoundMemberFunction(ASTContext &Ctx) const;
729 
730  /// Given an expression of bound-member type, find the type
731  /// of the member. Returns null if this is an *overloaded* bound
732  /// member expression.
733  static QualType findBoundMemberType(const Expr *expr);
734 
735  /// IgnoreImpCasts - Skip past any implicit casts which might
736  /// surround this expression. Only skips ImplicitCastExprs.
737  Expr *IgnoreImpCasts() LLVM_READONLY;
738 
739  /// IgnoreImplicit - Skip past any implicit AST nodes which might
740  /// surround this expression.
741  Expr *IgnoreImplicit() LLVM_READONLY {
742  return cast<Expr>(Stmt::IgnoreImplicit());
743  }
744 
745  const Expr *IgnoreImplicit() const LLVM_READONLY {
746  return const_cast<Expr*>(this)->IgnoreImplicit();
747  }
748 
749  /// IgnoreParens - Ignore parentheses. If this Expr is a ParenExpr, return
750  /// its subexpression. If that subexpression is also a ParenExpr,
751  /// then this method recursively returns its subexpression, and so forth.
752  /// Otherwise, the method returns the current Expr.
753  Expr *IgnoreParens() LLVM_READONLY;
754 
755  /// IgnoreParenCasts - Ignore parentheses and casts. Strip off any ParenExpr
756  /// or CastExprs, returning their operand.
757  Expr *IgnoreParenCasts() LLVM_READONLY;
758 
759  /// Ignore casts. Strip off any CastExprs, returning their operand.
760  Expr *IgnoreCasts() LLVM_READONLY;
761 
762  /// IgnoreParenImpCasts - Ignore parentheses and implicit casts. Strip off
763  /// any ParenExpr or ImplicitCastExprs, returning their operand.
764  Expr *IgnoreParenImpCasts() LLVM_READONLY;
765 
766  /// IgnoreConversionOperator - Ignore conversion operator. If this Expr is a
767  /// call to a conversion operator, return the argument.
768  Expr *IgnoreConversionOperator() LLVM_READONLY;
769 
770  const Expr *IgnoreConversionOperator() const LLVM_READONLY {
771  return const_cast<Expr*>(this)->IgnoreConversionOperator();
772  }
773 
774  const Expr *IgnoreParenImpCasts() const LLVM_READONLY {
775  return const_cast<Expr*>(this)->IgnoreParenImpCasts();
776  }
777 
778  /// Ignore parentheses and lvalue casts. Strip off any ParenExpr and
779  /// CastExprs that represent lvalue casts, returning their operand.
780  Expr *IgnoreParenLValueCasts() LLVM_READONLY;
781 
782  const Expr *IgnoreParenLValueCasts() const LLVM_READONLY {
783  return const_cast<Expr*>(this)->IgnoreParenLValueCasts();
784  }
785 
786  /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the
787  /// value (including ptr->int casts of the same size). Strip off any
788  /// ParenExpr or CastExprs, returning their operand.
789  Expr *IgnoreParenNoopCasts(ASTContext &Ctx) LLVM_READONLY;
790 
791  /// Ignore parentheses and derived-to-base casts.
792  Expr *ignoreParenBaseCasts() LLVM_READONLY;
793 
794  const Expr *ignoreParenBaseCasts() const LLVM_READONLY {
795  return const_cast<Expr*>(this)->ignoreParenBaseCasts();
796  }
797 
798  /// Determine whether this expression is a default function argument.
799  ///
800  /// Default arguments are implicitly generated in the abstract syntax tree
801  /// by semantic analysis for function calls, object constructions, etc. in
802  /// C++. Default arguments are represented by \c CXXDefaultArgExpr nodes;
803  /// this routine also looks through any implicit casts to determine whether
804  /// the expression is a default argument.
805  bool isDefaultArgument() const;
806 
807  /// Determine whether the result of this expression is a
808  /// temporary object of the given class type.
809  bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const;
810 
811  /// Whether this expression is an implicit reference to 'this' in C++.
812  bool isImplicitCXXThis() const;
813 
814  const Expr *IgnoreImpCasts() const LLVM_READONLY {
815  return const_cast<Expr*>(this)->IgnoreImpCasts();
816  }
817  const Expr *IgnoreParens() const LLVM_READONLY {
818  return const_cast<Expr*>(this)->IgnoreParens();
819  }
820  const Expr *IgnoreParenCasts() const LLVM_READONLY {
821  return const_cast<Expr*>(this)->IgnoreParenCasts();
822  }
823  /// Strip off casts, but keep parentheses.
824  const Expr *IgnoreCasts() const LLVM_READONLY {
825  return const_cast<Expr*>(this)->IgnoreCasts();
826  }
827 
828  const Expr *IgnoreParenNoopCasts(ASTContext &Ctx) const LLVM_READONLY {
829  return const_cast<Expr*>(this)->IgnoreParenNoopCasts(Ctx);
830  }
831 
832  static bool hasAnyTypeDependentArguments(ArrayRef<Expr *> Exprs);
833 
834  /// For an expression of class type or pointer to class type,
835  /// return the most derived class decl the expression is known to refer to.
836  ///
837  /// If this expression is a cast, this method looks through it to find the
838  /// most derived decl that can be inferred from the expression.
839  /// This is valid because derived-to-base conversions have undefined
840  /// behavior if the object isn't dynamically of the derived type.
841  const CXXRecordDecl *getBestDynamicClassType() const;
842 
843  /// Get the inner expression that determines the best dynamic class.
844  /// If this is a prvalue, we guarantee that it is of the most-derived type
845  /// for the object itself.
846  const Expr *getBestDynamicClassTypeExpr() const;
847 
848  /// Walk outwards from an expression we want to bind a reference to and
849  /// find the expression whose lifetime needs to be extended. Record
850  /// the LHSs of comma expressions and adjustments needed along the path.
851  const Expr *skipRValueSubobjectAdjustments(
853  SmallVectorImpl<SubobjectAdjustment> &Adjustments) const;
857  return skipRValueSubobjectAdjustments(CommaLHSs, Adjustments);
858  }
859 
860  static bool classof(const Stmt *T) {
861  return T->getStmtClass() >= firstExprConstant &&
862  T->getStmtClass() <= lastExprConstant;
863  }
864 };
865 
866 //===----------------------------------------------------------------------===//
867 // Primary Expressions.
868 //===----------------------------------------------------------------------===//
869 
870 /// OpaqueValueExpr - An expression referring to an opaque object of a
871 /// fixed type and value class. These don't correspond to concrete
872 /// syntax; instead they're used to express operations (usually copy
873 /// operations) on values whose source is generally obvious from
874 /// context.
875 class OpaqueValueExpr : public Expr {
876  friend class ASTStmtReader;
877  Expr *SourceExpr;
878  SourceLocation Loc;
879 
880 public:
883  Expr *SourceExpr = nullptr)
884  : Expr(OpaqueValueExprClass, T, VK, OK,
885  T->isDependentType() ||
886  (SourceExpr && SourceExpr->isTypeDependent()),
887  T->isDependentType() ||
888  (SourceExpr && SourceExpr->isValueDependent()),
889  T->isInstantiationDependentType() ||
890  (SourceExpr && SourceExpr->isInstantiationDependent()),
891  false),
892  SourceExpr(SourceExpr), Loc(Loc) {
893  setIsUnique(false);
894  }
895 
896  /// Given an expression which invokes a copy constructor --- i.e. a
897  /// CXXConstructExpr, possibly wrapped in an ExprWithCleanups ---
898  /// find the OpaqueValueExpr that's the source of the construction.
899  static const OpaqueValueExpr *findInCopyConstruct(const Expr *expr);
900 
901  explicit OpaqueValueExpr(EmptyShell Empty)
902  : Expr(OpaqueValueExprClass, Empty) { }
903 
904  /// Retrieve the location of this expression.
905  SourceLocation getLocation() const { return Loc; }
906 
907  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocStart() const LLVM_READONLY,
908  "Use getBeginLoc instead") {
909  return getBeginLoc();
910  }
911  SourceLocation getBeginLoc() const LLVM_READONLY {
912  return SourceExpr ? SourceExpr->getBeginLoc() : Loc;
913  }
914  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocEnd() const LLVM_READONLY,
915  "Use getEndLoc instead") {
916  return getEndLoc();
917  }
918  SourceLocation getEndLoc() const LLVM_READONLY {
919  return SourceExpr ? SourceExpr->getEndLoc() : Loc;
920  }
921  SourceLocation getExprLoc() const LLVM_READONLY {
922  if (SourceExpr) return SourceExpr->getExprLoc();
923  return Loc;
924  }
925 
928  }
929 
932  }
933 
934  /// The source expression of an opaque value expression is the
935  /// expression which originally generated the value. This is
936  /// provided as a convenience for analyses that don't wish to
937  /// precisely model the execution behavior of the program.
938  ///
939  /// The source expression is typically set when building the
940  /// expression which binds the opaque value expression in the first
941  /// place.
942  Expr *getSourceExpr() const { return SourceExpr; }
943 
944  void setIsUnique(bool V) {
945  assert((!V || SourceExpr) &&
946  "unique OVEs are expected to have source expressions");
947  OpaqueValueExprBits.IsUnique = V;
948  }
949 
950  bool isUnique() const { return OpaqueValueExprBits.IsUnique; }
951 
952  static bool classof(const Stmt *T) {
953  return T->getStmtClass() == OpaqueValueExprClass;
954  }
955 };
956 
957 /// A reference to a declared variable, function, enum, etc.
958 /// [C99 6.5.1p2]
959 ///
960 /// This encodes all the information about how a declaration is referenced
961 /// within an expression.
962 ///
963 /// There are several optional constructs attached to DeclRefExprs only when
964 /// they apply in order to conserve memory. These are laid out past the end of
965 /// the object, and flags in the DeclRefExprBitfield track whether they exist:
966 ///
967 /// DeclRefExprBits.HasQualifier:
968 /// Specifies when this declaration reference expression has a C++
969 /// nested-name-specifier.
970 /// DeclRefExprBits.HasFoundDecl:
971 /// Specifies when this declaration reference expression has a record of
972 /// a NamedDecl (different from the referenced ValueDecl) which was found
973 /// during name lookup and/or overload resolution.
974 /// DeclRefExprBits.HasTemplateKWAndArgsInfo:
975 /// Specifies when this declaration reference expression has an explicit
976 /// C++ template keyword and/or template argument list.
977 /// DeclRefExprBits.RefersToEnclosingVariableOrCapture
978 /// Specifies when this declaration reference expression (validly)
979 /// refers to an enclosed local or a captured variable.
980 class DeclRefExpr final
981  : public Expr,
982  private llvm::TrailingObjects<DeclRefExpr, NestedNameSpecifierLoc,
983  NamedDecl *, ASTTemplateKWAndArgsInfo,
984  TemplateArgumentLoc> {
985  /// The declaration that we are referencing.
986  ValueDecl *D;
987 
988  /// The location of the declaration name itself.
989  SourceLocation Loc;
990 
991  /// Provides source/type location info for the declaration name
992  /// embedded in D.
993  DeclarationNameLoc DNLoc;
994 
995  size_t numTrailingObjects(OverloadToken<NestedNameSpecifierLoc>) const {
996  return hasQualifier() ? 1 : 0;
997  }
998 
999  size_t numTrailingObjects(OverloadToken<NamedDecl *>) const {
1000  return hasFoundDecl() ? 1 : 0;
1001  }
1002 
1003  size_t numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
1004  return hasTemplateKWAndArgsInfo() ? 1 : 0;
1005  }
1006 
1007  /// Test whether there is a distinct FoundDecl attached to the end of
1008  /// this DRE.
1009  bool hasFoundDecl() const { return DeclRefExprBits.HasFoundDecl; }
1010 
1011  DeclRefExpr(const ASTContext &Ctx,
1012  NestedNameSpecifierLoc QualifierLoc,
1013  SourceLocation TemplateKWLoc,
1014  ValueDecl *D, bool RefersToEnlosingVariableOrCapture,
1015  const DeclarationNameInfo &NameInfo,
1016  NamedDecl *FoundD,
1017  const TemplateArgumentListInfo *TemplateArgs,
1018  QualType T, ExprValueKind VK);
1019 
1020  /// Construct an empty declaration reference expression.
1021  explicit DeclRefExpr(EmptyShell Empty)
1022  : Expr(DeclRefExprClass, Empty) { }
1023 
1024  /// Computes the type- and value-dependence flags for this
1025  /// declaration reference expression.
1026  void computeDependence(const ASTContext &C);
1027 
1028 public:
1029  DeclRefExpr(ValueDecl *D, bool RefersToEnclosingVariableOrCapture, QualType T,
1031  const DeclarationNameLoc &LocInfo = DeclarationNameLoc())
1032  : Expr(DeclRefExprClass, T, VK, OK_Ordinary, false, false, false, false),
1033  D(D), Loc(L), DNLoc(LocInfo) {
1034  DeclRefExprBits.HasQualifier = 0;
1035  DeclRefExprBits.HasTemplateKWAndArgsInfo = 0;
1036  DeclRefExprBits.HasFoundDecl = 0;
1037  DeclRefExprBits.HadMultipleCandidates = 0;
1038  DeclRefExprBits.RefersToEnclosingVariableOrCapture =
1039  RefersToEnclosingVariableOrCapture;
1040  computeDependence(D->getASTContext());
1041  }
1042 
1043  static DeclRefExpr *
1044  Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc,
1045  SourceLocation TemplateKWLoc, ValueDecl *D,
1046  bool RefersToEnclosingVariableOrCapture, SourceLocation NameLoc,
1047  QualType T, ExprValueKind VK, NamedDecl *FoundD = nullptr,
1048  const TemplateArgumentListInfo *TemplateArgs = nullptr);
1049 
1050  static DeclRefExpr *
1051  Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc,
1052  SourceLocation TemplateKWLoc, ValueDecl *D,
1053  bool RefersToEnclosingVariableOrCapture,
1054  const DeclarationNameInfo &NameInfo, QualType T, ExprValueKind VK,
1055  NamedDecl *FoundD = nullptr,
1056  const TemplateArgumentListInfo *TemplateArgs = nullptr);
1057 
1058  /// Construct an empty declaration reference expression.
1059  static DeclRefExpr *CreateEmpty(const ASTContext &Context,
1060  bool HasQualifier,
1061  bool HasFoundDecl,
1062  bool HasTemplateKWAndArgsInfo,
1063  unsigned NumTemplateArgs);
1064 
1065  ValueDecl *getDecl() { return D; }
1066  const ValueDecl *getDecl() const { return D; }
1067  void setDecl(ValueDecl *NewD) { D = NewD; }
1068 
1070  return DeclarationNameInfo(getDecl()->getDeclName(), Loc, DNLoc);
1071  }
1072 
1073  SourceLocation getLocation() const { return Loc; }
1074  void setLocation(SourceLocation L) { Loc = L; }
1075  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocStart() const LLVM_READONLY,
1076  "Use getBeginLoc instead") {
1077  return getBeginLoc();
1078  }
1079  SourceLocation getBeginLoc() const LLVM_READONLY;
1080  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocEnd() const LLVM_READONLY,
1081  "Use getEndLoc instead") {
1082  return getEndLoc();
1083  }
1084  SourceLocation getEndLoc() const LLVM_READONLY;
1085 
1086  /// Determine whether this declaration reference was preceded by a
1087  /// C++ nested-name-specifier, e.g., \c N::foo.
1088  bool hasQualifier() const { return DeclRefExprBits.HasQualifier; }
1089 
1090  /// If the name was qualified, retrieves the nested-name-specifier
1091  /// that precedes the name, with source-location information.
1093  if (!hasQualifier())
1094  return NestedNameSpecifierLoc();
1095  return *getTrailingObjects<NestedNameSpecifierLoc>();
1096  }
1097 
1098  /// If the name was qualified, retrieves the nested-name-specifier
1099  /// that precedes the name. Otherwise, returns NULL.
1101  return getQualifierLoc().getNestedNameSpecifier();
1102  }
1103 
1104  /// Get the NamedDecl through which this reference occurred.
1105  ///
1106  /// This Decl may be different from the ValueDecl actually referred to in the
1107  /// presence of using declarations, etc. It always returns non-NULL, and may
1108  /// simple return the ValueDecl when appropriate.
1109 
1111  return hasFoundDecl() ? *getTrailingObjects<NamedDecl *>() : D;
1112  }
1113 
1114  /// Get the NamedDecl through which this reference occurred.
1115  /// See non-const variant.
1116  const NamedDecl *getFoundDecl() const {
1117  return hasFoundDecl() ? *getTrailingObjects<NamedDecl *>() : D;
1118  }
1119 
1121  return DeclRefExprBits.HasTemplateKWAndArgsInfo;
1122  }
1123 
1124  /// Retrieve the location of the template keyword preceding
1125  /// this name, if any.
1127  if (!hasTemplateKWAndArgsInfo()) return SourceLocation();
1128  return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->TemplateKWLoc;
1129  }
1130 
1131  /// Retrieve the location of the left angle bracket starting the
1132  /// explicit template argument list following the name, if any.
1134  if (!hasTemplateKWAndArgsInfo()) return SourceLocation();
1135  return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->LAngleLoc;
1136  }
1137 
1138  /// Retrieve the location of the right angle bracket ending the
1139  /// explicit template argument list following the name, if any.
1141  if (!hasTemplateKWAndArgsInfo()) return SourceLocation();
1142  return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->RAngleLoc;
1143  }
1144 
1145  /// Determines whether the name in this declaration reference
1146  /// was preceded by the template keyword.
1147  bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
1148 
1149  /// Determines whether this declaration reference was followed by an
1150  /// explicit template argument list.
1151  bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
1152 
1153  /// Copies the template arguments (if present) into the given
1154  /// structure.
1156  if (hasExplicitTemplateArgs())
1157  getTrailingObjects<ASTTemplateKWAndArgsInfo>()->copyInto(
1158  getTrailingObjects<TemplateArgumentLoc>(), List);
1159  }
1160 
1161  /// Retrieve the template arguments provided as part of this
1162  /// template-id.
1164  if (!hasExplicitTemplateArgs())
1165  return nullptr;
1166 
1167  return getTrailingObjects<TemplateArgumentLoc>();
1168  }
1169 
1170  /// Retrieve the number of template arguments provided as part of this
1171  /// template-id.
1172  unsigned getNumTemplateArgs() const {
1173  if (!hasExplicitTemplateArgs())
1174  return 0;
1175 
1176  return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs;
1177  }
1178 
1180  return {getTemplateArgs(), getNumTemplateArgs()};
1181  }
1182 
1183  /// Returns true if this expression refers to a function that
1184  /// was resolved from an overloaded set having size greater than 1.
1185  bool hadMultipleCandidates() const {
1186  return DeclRefExprBits.HadMultipleCandidates;
1187  }
1188  /// Sets the flag telling whether this expression refers to
1189  /// a function that was resolved from an overloaded set having size
1190  /// greater than 1.
1191  void setHadMultipleCandidates(bool V = true) {
1192  DeclRefExprBits.HadMultipleCandidates = V;
1193  }
1194 
1195  /// Does this DeclRefExpr refer to an enclosing local or a captured
1196  /// variable?
1198  return DeclRefExprBits.RefersToEnclosingVariableOrCapture;
1199  }
1200 
1201  static bool classof(const Stmt *T) {
1202  return T->getStmtClass() == DeclRefExprClass;
1203  }
1204 
1205  // Iterators
1208  }
1209 
1212  }
1213 
1215  friend class ASTStmtReader;
1216  friend class ASTStmtWriter;
1217 };
1218 
1219 /// [C99 6.4.2.2] - A predefined identifier such as __func__.
1220 class PredefinedExpr : public Expr {
1221 public:
1222  enum IdentType {
1225  LFunction, // Same as Function, but as wide string.
1228  LFuncSig, // Same as FuncSig, but as as wide string
1230  /// The same as PrettyFunction, except that the
1231  /// 'virtual' keyword is omitted for virtual member functions.
1232  PrettyFunctionNoVirtual
1233  };
1234 
1235 private:
1236  SourceLocation Loc;
1237  IdentType Type;
1238  Stmt *FnName;
1239 
1240 public:
1242  StringLiteral *SL);
1243 
1244  /// Construct an empty predefined expression.
1245  explicit PredefinedExpr(EmptyShell Empty)
1246  : Expr(PredefinedExprClass, Empty), Loc(), Type(Func), FnName(nullptr) {}
1247 
1248  IdentType getIdentType() const { return Type; }
1249 
1250  SourceLocation getLocation() const { return Loc; }
1251  void setLocation(SourceLocation L) { Loc = L; }
1252 
1253  StringLiteral *getFunctionName();
1255  return const_cast<PredefinedExpr *>(this)->getFunctionName();
1256  }
1257 
1258  static StringRef getIdentTypeName(IdentType IT);
1259  static std::string ComputeName(IdentType IT, const Decl *CurrentDecl);
1260 
1261  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocStart() const LLVM_READONLY,
1262  "Use getBeginLoc instead") {
1263  return getBeginLoc();
1264  }
1265  SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
1266  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocEnd() const LLVM_READONLY,
1267  "Use getEndLoc instead") {
1268  return getEndLoc();
1269  }
1270  SourceLocation getEndLoc() const LLVM_READONLY { return Loc; }
1271 
1272  static bool classof(const Stmt *T) {
1273  return T->getStmtClass() == PredefinedExprClass;
1274  }
1275 
1276  // Iterators
1277  child_range children() { return child_range(&FnName, &FnName + 1); }
1279  return const_child_range(&FnName, &FnName + 1);
1280  }
1281 
1282  friend class ASTStmtReader;
1283 };
1284 
1285 /// Used by IntegerLiteral/FloatingLiteral to store the numeric without
1286 /// leaking memory.
1287 ///
1288 /// For large floats/integers, APFloat/APInt will allocate memory from the heap
1289 /// to represent these numbers. Unfortunately, when we use a BumpPtrAllocator
1290 /// to allocate IntegerLiteral/FloatingLiteral nodes the memory associated with
1291 /// the APFloat/APInt values will never get freed. APNumericStorage uses
1292 /// ASTContext's allocator for memory allocation.
1294  union {
1295  uint64_t VAL; ///< Used to store the <= 64 bits integer value.
1296  uint64_t *pVal; ///< Used to store the >64 bits integer value.
1297  };
1298  unsigned BitWidth;
1299 
1300  bool hasAllocation() const { return llvm::APInt::getNumWords(BitWidth) > 1; }
1301 
1302  APNumericStorage(const APNumericStorage &) = delete;
1303  void operator=(const APNumericStorage &) = delete;
1304 
1305 protected:
1306  APNumericStorage() : VAL(0), BitWidth(0) { }
1307 
1308  llvm::APInt getIntValue() const {
1309  unsigned NumWords = llvm::APInt::getNumWords(BitWidth);
1310  if (NumWords > 1)
1311  return llvm::APInt(BitWidth, NumWords, pVal);
1312  else
1313  return llvm::APInt(BitWidth, VAL);
1314  }
1315  void setIntValue(const ASTContext &C, const llvm::APInt &Val);
1316 };
1317 
1319 public:
1320  llvm::APInt getValue() const { return getIntValue(); }
1321  void setValue(const ASTContext &C, const llvm::APInt &Val) {
1322  setIntValue(C, Val);
1323  }
1324 };
1325 
1327 public:
1328  llvm::APFloat getValue(const llvm::fltSemantics &Semantics) const {
1329  return llvm::APFloat(Semantics, getIntValue());
1330  }
1331  void setValue(const ASTContext &C, const llvm::APFloat &Val) {
1332  setIntValue(C, Val.bitcastToAPInt());
1333  }
1334 };
1335 
1336 class IntegerLiteral : public Expr, public APIntStorage {
1337  SourceLocation Loc;
1338 
1339  /// Construct an empty integer literal.
1340  explicit IntegerLiteral(EmptyShell Empty)
1341  : Expr(IntegerLiteralClass, Empty) { }
1342 
1343 public:
1344  // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy,
1345  // or UnsignedLongLongTy
1346  IntegerLiteral(const ASTContext &C, const llvm::APInt &V, QualType type,
1347  SourceLocation l);
1348 
1349  /// Returns a new integer literal with value 'V' and type 'type'.
1350  /// \param type - either IntTy, LongTy, LongLongTy, UnsignedIntTy,
1351  /// UnsignedLongTy, or UnsignedLongLongTy which should match the size of V
1352  /// \param V - the value that the returned integer literal contains.
1353  static IntegerLiteral *Create(const ASTContext &C, const llvm::APInt &V,
1354  QualType type, SourceLocation l);
1355  /// Returns a new empty integer literal.
1356  static IntegerLiteral *Create(const ASTContext &C, EmptyShell Empty);
1357 
1358  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocStart() const LLVM_READONLY,
1359  "Use getBeginLoc instead") {
1360  return getBeginLoc();
1361  }
1362  SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
1363  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocEnd() const LLVM_READONLY,
1364  "Use getEndLoc instead") {
1365  return getEndLoc();
1366  }
1367  SourceLocation getEndLoc() const LLVM_READONLY { return Loc; }
1368 
1369  /// Retrieve the location of the literal.
1370  SourceLocation getLocation() const { return Loc; }
1371 
1372  void setLocation(SourceLocation Location) { Loc = Location; }
1373 
1374  static bool classof(const Stmt *T) {
1375  return T->getStmtClass() == IntegerLiteralClass;
1376  }
1377 
1378  // Iterators
1381  }
1384  }
1385 };
1386 
1387 class FixedPointLiteral : public Expr, public APIntStorage {
1388  SourceLocation Loc;
1389  unsigned Scale;
1390 
1391  /// \brief Construct an empty integer literal.
1392  explicit FixedPointLiteral(EmptyShell Empty)
1393  : Expr(FixedPointLiteralClass, Empty) {}
1394 
1395  public:
1396  FixedPointLiteral(const ASTContext &C, const llvm::APInt &V, QualType type,
1397  SourceLocation l, unsigned Scale);
1398 
1399  // Store the int as is without any bit shifting.
1400  static FixedPointLiteral *CreateFromRawInt(const ASTContext &C,
1401  const llvm::APInt &V,
1402  QualType type, SourceLocation l,
1403  unsigned Scale);
1404 
1405  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocStart() const LLVM_READONLY,
1406  "Use getBeginLoc instead") {
1407  return getBeginLoc();
1408  }
1409  SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
1410  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocEnd() const LLVM_READONLY,
1411  "Use getEndLoc instead") {
1412  return getEndLoc();
1413  }
1414  SourceLocation getEndLoc() const LLVM_READONLY { return Loc; }
1415 
1416  /// \brief Retrieve the location of the literal.
1417  SourceLocation getLocation() const { return Loc; }
1418 
1419  void setLocation(SourceLocation Location) { Loc = Location; }
1420 
1421  static bool classof(const Stmt *T) {
1422  return T->getStmtClass() == FixedPointLiteralClass;
1423  }
1424 
1425  std::string getValueAsString(unsigned Radix) const;
1426 
1427  // Iterators
1430  }
1433  }
1434 };
1435 
1436 class CharacterLiteral : public Expr {
1437 public:
1443  UTF32
1444  };
1445 
1446 private:
1447  unsigned Value;
1448  SourceLocation Loc;
1449 public:
1450  // type should be IntTy
1452  SourceLocation l)
1453  : Expr(CharacterLiteralClass, type, VK_RValue, OK_Ordinary, false, false,
1454  false, false),
1455  Value(value), Loc(l) {
1456  CharacterLiteralBits.Kind = kind;
1457  }
1458 
1459  /// Construct an empty character literal.
1460  CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { }
1461 
1462  SourceLocation getLocation() const { return Loc; }
1464  return static_cast<CharacterKind>(CharacterLiteralBits.Kind);
1465  }
1466 
1467  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocStart() const LLVM_READONLY,
1468  "Use getBeginLoc instead") {
1469  return getBeginLoc();
1470  }
1471  SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
1472  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocEnd() const LLVM_READONLY,
1473  "Use getEndLoc instead") {
1474  return getEndLoc();
1475  }
1476  SourceLocation getEndLoc() const LLVM_READONLY { return Loc; }
1477 
1478  unsigned getValue() const { return Value; }
1479 
1480  void setLocation(SourceLocation Location) { Loc = Location; }
1481  void setKind(CharacterKind kind) { CharacterLiteralBits.Kind = kind; }
1482  void setValue(unsigned Val) { Value = Val; }
1483 
1484  static bool classof(const Stmt *T) {
1485  return T->getStmtClass() == CharacterLiteralClass;
1486  }
1487 
1488  // Iterators
1491  }
1494  }
1495 };
1496 
1497 class FloatingLiteral : public Expr, private APFloatStorage {
1498  SourceLocation Loc;
1499 
1500  FloatingLiteral(const ASTContext &C, const llvm::APFloat &V, bool isexact,
1501  QualType Type, SourceLocation L);
1502 
1503  /// Construct an empty floating-point literal.
1504  explicit FloatingLiteral(const ASTContext &C, EmptyShell Empty);
1505 
1506 public:
1507  static FloatingLiteral *Create(const ASTContext &C, const llvm::APFloat &V,
1508  bool isexact, QualType Type, SourceLocation L);
1509  static FloatingLiteral *Create(const ASTContext &C, EmptyShell Empty);
1510 
1511  llvm::APFloat getValue() const {
1512  return APFloatStorage::getValue(getSemantics());
1513  }
1514  void setValue(const ASTContext &C, const llvm::APFloat &Val) {
1515  assert(&getSemantics() == &Val.getSemantics() && "Inconsistent semantics");
1516  APFloatStorage::setValue(C, Val);
1517  }
1518 
1519  /// Get a raw enumeration value representing the floating-point semantics of
1520  /// this literal (32-bit IEEE, x87, ...), suitable for serialisation.
1522  return static_cast<APFloatSemantics>(FloatingLiteralBits.Semantics);
1523  }
1524 
1525  /// Set the raw enumeration value representing the floating-point semantics of
1526  /// this literal (32-bit IEEE, x87, ...), suitable for serialisation.
1528  FloatingLiteralBits.Semantics = Sem;
1529  }
1530 
1531  /// Return the APFloat semantics this literal uses.
1532  const llvm::fltSemantics &getSemantics() const;
1533 
1534  /// Set the APFloat semantics this literal uses.
1535  void setSemantics(const llvm::fltSemantics &Sem);
1536 
1537  bool isExact() const { return FloatingLiteralBits.IsExact; }
1538  void setExact(bool E) { FloatingLiteralBits.IsExact = E; }
1539 
1540  /// getValueAsApproximateDouble - This returns the value as an inaccurate
1541  /// double. Note that this may cause loss of precision, but is useful for
1542  /// debugging dumps, etc.
1543  double getValueAsApproximateDouble() const;
1544 
1545  SourceLocation getLocation() const { return Loc; }
1546  void setLocation(SourceLocation L) { Loc = L; }
1547 
1548  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocStart() const LLVM_READONLY,
1549  "Use getBeginLoc instead") {
1550  return getBeginLoc();
1551  }
1552  SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
1553  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocEnd() const LLVM_READONLY,
1554  "Use getEndLoc instead") {
1555  return getEndLoc();
1556  }
1557  SourceLocation getEndLoc() const LLVM_READONLY { return Loc; }
1558 
1559  static bool classof(const Stmt *T) {
1560  return T->getStmtClass() == FloatingLiteralClass;
1561  }
1562 
1563  // Iterators
1566  }
1569  }
1570 };
1571 
1572 /// ImaginaryLiteral - We support imaginary integer and floating point literals,
1573 /// like "1.0i". We represent these as a wrapper around FloatingLiteral and
1574 /// IntegerLiteral classes. Instances of this class always have a Complex type
1575 /// whose element type matches the subexpression.
1576 ///
1577 class ImaginaryLiteral : public Expr {
1578  Stmt *Val;
1579 public:
1581  : Expr(ImaginaryLiteralClass, Ty, VK_RValue, OK_Ordinary, false, false,
1582  false, false),
1583  Val(val) {}
1584 
1585  /// Build an empty imaginary literal.
1587  : Expr(ImaginaryLiteralClass, Empty) { }
1588 
1589  const Expr *getSubExpr() const { return cast<Expr>(Val); }
1590  Expr *getSubExpr() { return cast<Expr>(Val); }
1591  void setSubExpr(Expr *E) { Val = E; }
1592 
1593  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocStart() const LLVM_READONLY,
1594  "Use getBeginLoc instead") {
1595  return getBeginLoc();
1596  }
1597  SourceLocation getBeginLoc() const LLVM_READONLY {
1598  return Val->getBeginLoc();
1599  }
1600  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocEnd() const LLVM_READONLY,
1601  "Use getEndLoc instead") {
1602  return getEndLoc();
1603  }
1604  SourceLocation getEndLoc() const LLVM_READONLY { return Val->getEndLoc(); }
1605 
1606  static bool classof(const Stmt *T) {
1607  return T->getStmtClass() == ImaginaryLiteralClass;
1608  }
1609 
1610  // Iterators
1611  child_range children() { return child_range(&Val, &Val+1); }
1613  return const_child_range(&Val, &Val + 1);
1614  }
1615 };
1616 
1617 /// StringLiteral - This represents a string literal expression, e.g. "foo"
1618 /// or L"bar" (wide strings). The actual string is returned by getBytes()
1619 /// is NOT null-terminated, and the length of the string is determined by
1620 /// calling getByteLength(). The C type for a string is always a
1621 /// ConstantArrayType. In C++, the char type is const qualified, in C it is
1622 /// not.
1623 ///
1624 /// Note that strings in C can be formed by concatenation of multiple string
1625 /// literal pptokens in translation phase #6. This keeps track of the locations
1626 /// of each of these pieces.
1627 ///
1628 /// Strings in C can also be truncated and extended by assigning into arrays,
1629 /// e.g. with constructs like:
1630 /// char X[2] = "foobar";
1631 /// In this case, getByteLength() will return 6, but the string literal will
1632 /// have type "char[2]".
1633 class StringLiteral : public Expr {
1634 public:
1635  enum StringKind {
1640  UTF32
1641  };
1642 
1643 private:
1644  friend class ASTStmtReader;
1645 
1646  union {
1647  const char *asChar;
1648  const uint16_t *asUInt16;
1649  const uint32_t *asUInt32;
1650  } StrData;
1651  unsigned Length;
1652  unsigned CharByteWidth : 4;
1653  unsigned Kind : 3;
1654  unsigned IsPascal : 1;
1655  unsigned NumConcatenated;
1656  SourceLocation TokLocs[1];
1657 
1658  StringLiteral(QualType Ty) :
1659  Expr(StringLiteralClass, Ty, VK_LValue, OK_Ordinary, false, false, false,
1660  false) {}
1661 
1662  static int mapCharByteWidth(TargetInfo const &target,StringKind k);
1663 
1664 public:
1665  /// This is the "fully general" constructor that allows representation of
1666  /// strings formed from multiple concatenated tokens.
1667  static StringLiteral *Create(const ASTContext &C, StringRef Str,
1668  StringKind Kind, bool Pascal, QualType Ty,
1669  const SourceLocation *Loc, unsigned NumStrs);
1670 
1671  /// Simple constructor for string literals made from one token.
1672  static StringLiteral *Create(const ASTContext &C, StringRef Str,
1673  StringKind Kind, bool Pascal, QualType Ty,
1674  SourceLocation Loc) {
1675  return Create(C, Str, Kind, Pascal, Ty, &Loc, 1);
1676  }
1677 
1678  /// Construct an empty string literal.
1679  static StringLiteral *CreateEmpty(const ASTContext &C, unsigned NumStrs);
1680 
1681  StringRef getString() const {
1682  assert(CharByteWidth==1
1683  && "This function is used in places that assume strings use char");
1684  return StringRef(StrData.asChar, getByteLength());
1685  }
1686 
1687  /// Allow access to clients that need the byte representation, such as
1688  /// ASTWriterStmt::VisitStringLiteral().
1689  StringRef getBytes() const {
1690  // FIXME: StringRef may not be the right type to use as a result for this.
1691  if (CharByteWidth == 1)
1692  return StringRef(StrData.asChar, getByteLength());
1693  if (CharByteWidth == 4)
1694  return StringRef(reinterpret_cast<const char*>(StrData.asUInt32),
1695  getByteLength());
1696  assert(CharByteWidth == 2 && "unsupported CharByteWidth");
1697  return StringRef(reinterpret_cast<const char*>(StrData.asUInt16),
1698  getByteLength());
1699  }
1700 
1701  void outputString(raw_ostream &OS) const;
1702 
1703  uint32_t getCodeUnit(size_t i) const {
1704  assert(i < Length && "out of bounds access");
1705  if (CharByteWidth == 1)
1706  return static_cast<unsigned char>(StrData.asChar[i]);
1707  if (CharByteWidth == 4)
1708  return StrData.asUInt32[i];
1709  assert(CharByteWidth == 2 && "unsupported CharByteWidth");
1710  return StrData.asUInt16[i];
1711  }
1712 
1713  unsigned getByteLength() const { return CharByteWidth*Length; }
1714  unsigned getLength() const { return Length; }
1715  unsigned getCharByteWidth() const { return CharByteWidth; }
1716 
1717  /// Sets the string data to the given string data.
1718  void setString(const ASTContext &C, StringRef Str,
1719  StringKind Kind, bool IsPascal);
1720 
1721  StringKind getKind() const { return static_cast<StringKind>(Kind); }
1722 
1723 
1724  bool isAscii() const { return Kind == Ascii; }
1725  bool isWide() const { return Kind == Wide; }
1726  bool isUTF8() const { return Kind == UTF8; }
1727  bool isUTF16() const { return Kind == UTF16; }
1728  bool isUTF32() const { return Kind == UTF32; }
1729  bool isPascal() const { return IsPascal; }
1730 
1731  bool containsNonAscii() const {
1732  StringRef Str = getString();
1733  for (unsigned i = 0, e = Str.size(); i != e; ++i)
1734  if (!isASCII(Str[i]))
1735  return true;
1736  return false;
1737  }
1738 
1739  bool containsNonAsciiOrNull() const {
1740  StringRef Str = getString();
1741  for (unsigned i = 0, e = Str.size(); i != e; ++i)
1742  if (!isASCII(Str[i]) || !Str[i])
1743  return true;
1744  return false;
1745  }
1746 
1747  /// getNumConcatenated - Get the number of string literal tokens that were
1748  /// concatenated in translation phase #6 to form this string literal.
1749  unsigned getNumConcatenated() const { return NumConcatenated; }
1750 
1751  SourceLocation getStrTokenLoc(unsigned TokNum) const {
1752  assert(TokNum < NumConcatenated && "Invalid tok number");
1753  return TokLocs[TokNum];
1754  }
1755  void setStrTokenLoc(unsigned TokNum, SourceLocation L) {
1756  assert(TokNum < NumConcatenated && "Invalid tok number");
1757  TokLocs[TokNum] = L;
1758  }
1759 
1760  /// getLocationOfByte - Return a source location that points to the specified
1761  /// byte of this string literal.
1762  ///
1763  /// Strings are amazingly complex. They can be formed from multiple tokens
1764  /// and can have escape sequences in them in addition to the usual trigraph
1765  /// and escaped newline business. This routine handles this complexity.
1766  ///
1768  getLocationOfByte(unsigned ByteNo, const SourceManager &SM,
1769  const LangOptions &Features, const TargetInfo &Target,
1770  unsigned *StartToken = nullptr,
1771  unsigned *StartTokenByteOffset = nullptr) const;
1772 
1774  tokloc_iterator tokloc_begin() const { return TokLocs; }
1775  tokloc_iterator tokloc_end() const { return TokLocs + NumConcatenated; }
1776 
1777  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocStart() const LLVM_READONLY,
1778  "Use getBeginLoc instead") {
1779  return getBeginLoc();
1780  }
1781  SourceLocation getBeginLoc() const LLVM_READONLY { return TokLocs[0]; }
1782  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocEnd() const LLVM_READONLY,
1783  "Use getEndLoc instead") {
1784  return getEndLoc();
1785  }
1786  SourceLocation getEndLoc() const LLVM_READONLY {
1787  return TokLocs[NumConcatenated - 1];
1788  }
1789 
1790  static bool classof(const Stmt *T) {
1791  return T->getStmtClass() == StringLiteralClass;
1792  }
1793 
1794  // Iterators
1797  }
1800  }
1801 };
1802 
1803 /// ParenExpr - This represents a parethesized expression, e.g. "(1)". This
1804 /// AST node is only formed if full location information is requested.
1805 class ParenExpr : public Expr {
1806  SourceLocation L, R;
1807  Stmt *Val;
1808 public:
1810  : Expr(ParenExprClass, val->getType(),
1811  val->getValueKind(), val->getObjectKind(),
1812  val->isTypeDependent(), val->isValueDependent(),
1813  val->isInstantiationDependent(),
1814  val->containsUnexpandedParameterPack()),
1815  L(l), R(r), Val(val) {}
1816 
1817  /// Construct an empty parenthesized expression.
1818  explicit ParenExpr(EmptyShell Empty)
1819  : Expr(ParenExprClass, Empty) { }
1820 
1821  const Expr *getSubExpr() const { return cast<Expr>(Val); }
1822  Expr *getSubExpr() { return cast<Expr>(Val); }
1823  void setSubExpr(Expr *E) { Val = E; }
1824 
1825  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocStart() const LLVM_READONLY,
1826  "Use getBeginLoc instead") {
1827  return getBeginLoc();
1828  }
1829  SourceLocation getBeginLoc() const LLVM_READONLY { return L; }
1830  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocEnd() const LLVM_READONLY,
1831  "Use getEndLoc instead") {
1832  return getEndLoc();
1833  }
1834  SourceLocation getEndLoc() const LLVM_READONLY { return R; }
1835 
1836  /// Get the location of the left parentheses '('.
1837  SourceLocation getLParen() const { return L; }
1838  void setLParen(SourceLocation Loc) { L = Loc; }
1839 
1840  /// Get the location of the right parentheses ')'.
1841  SourceLocation getRParen() const { return R; }
1842  void setRParen(SourceLocation Loc) { R = Loc; }
1843 
1844  static bool classof(const Stmt *T) {
1845  return T->getStmtClass() == ParenExprClass;
1846  }
1847 
1848  // Iterators
1849  child_range children() { return child_range(&Val, &Val+1); }
1851  return const_child_range(&Val, &Val + 1);
1852  }
1853 };
1854 
1855 /// UnaryOperator - This represents the unary-expression's (except sizeof and
1856 /// alignof), the postinc/postdec operators from postfix-expression, and various
1857 /// extensions.
1858 ///
1859 /// Notes on various nodes:
1860 ///
1861 /// Real/Imag - These return the real/imag part of a complex operand. If
1862 /// applied to a non-complex value, the former returns its operand and the
1863 /// later returns zero in the type of the operand.
1864 ///
1865 class UnaryOperator : public Expr {
1866 public:
1868 
1869 private:
1870  unsigned Opc : 5;
1871  unsigned CanOverflow : 1;
1872  SourceLocation Loc;
1873  Stmt *Val;
1874 public:
1875  UnaryOperator(Expr *input, Opcode opc, QualType type, ExprValueKind VK,
1876  ExprObjectKind OK, SourceLocation l, bool CanOverflow)
1877  : Expr(UnaryOperatorClass, type, VK, OK,
1878  input->isTypeDependent() || type->isDependentType(),
1879  input->isValueDependent(),
1880  (input->isInstantiationDependent() ||
1881  type->isInstantiationDependentType()),
1882  input->containsUnexpandedParameterPack()),
1883  Opc(opc), CanOverflow(CanOverflow), Loc(l), Val(input) {}
1884 
1885  /// Build an empty unary operator.
1886  explicit UnaryOperator(EmptyShell Empty)
1887  : Expr(UnaryOperatorClass, Empty), Opc(UO_AddrOf) { }
1888 
1889  Opcode getOpcode() const { return static_cast<Opcode>(Opc); }
1890  void setOpcode(Opcode O) { Opc = O; }
1891 
1892  Expr *getSubExpr() const { return cast<Expr>(Val); }
1893  void setSubExpr(Expr *E) { Val = E; }
1894 
1895  /// getOperatorLoc - Return the location of the operator.
1896  SourceLocation getOperatorLoc() const { return Loc; }
1897  void setOperatorLoc(SourceLocation L) { Loc = L; }
1898 
1899  /// Returns true if the unary operator can cause an overflow. For instance,
1900  /// signed int i = INT_MAX; i++;
1901  /// signed char c = CHAR_MAX; c++;
1902  /// Due to integer promotions, c++ is promoted to an int before the postfix
1903  /// increment, and the result is an int that cannot overflow. However, i++
1904  /// can overflow.
1905  bool canOverflow() const { return CanOverflow; }
1906  void setCanOverflow(bool C) { CanOverflow = C; }
1907 
1908  /// isPostfix - Return true if this is a postfix operation, like x++.
1909  static bool isPostfix(Opcode Op) {
1910  return Op == UO_PostInc || Op == UO_PostDec;
1911  }
1912 
1913  /// isPrefix - Return true if this is a prefix operation, like --x.
1914  static bool isPrefix(Opcode Op) {
1915  return Op == UO_PreInc || Op == UO_PreDec;
1916  }
1917 
1918  bool isPrefix() const { return isPrefix(getOpcode()); }
1919  bool isPostfix() const { return isPostfix(getOpcode()); }
1920 
1921  static bool isIncrementOp(Opcode Op) {
1922  return Op == UO_PreInc || Op == UO_PostInc;
1923  }
1924  bool isIncrementOp() const {
1925  return isIncrementOp(getOpcode());
1926  }
1927 
1928  static bool isDecrementOp(Opcode Op) {
1929  return Op == UO_PreDec || Op == UO_PostDec;
1930  }
1931  bool isDecrementOp() const {
1932  return isDecrementOp(getOpcode());
1933  }
1934 
1935  static bool isIncrementDecrementOp(Opcode Op) { return Op <= UO_PreDec; }
1936  bool isIncrementDecrementOp() const {
1937  return isIncrementDecrementOp(getOpcode());
1938  }
1939 
1940  static bool isArithmeticOp(Opcode Op) {
1941  return Op >= UO_Plus && Op <= UO_LNot;
1942  }
1943  bool isArithmeticOp() const { return isArithmeticOp(getOpcode()); }
1944 
1945  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
1946  /// corresponds to, e.g. "sizeof" or "[pre]++"
1947  static StringRef getOpcodeStr(Opcode Op);
1948 
1949  /// Retrieve the unary opcode that corresponds to the given
1950  /// overloaded operator.
1951  static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix);
1952 
1953  /// Retrieve the overloaded operator kind that corresponds to
1954  /// the given unary opcode.
1955  static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
1956 
1957  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocStart() const LLVM_READONLY,
1958  "Use getBeginLoc instead") {
1959  return getBeginLoc();
1960  }
1961  SourceLocation getBeginLoc() const LLVM_READONLY {
1962  return isPostfix() ? Val->getBeginLoc() : Loc;
1963  }
1964  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocEnd() const LLVM_READONLY,
1965  "Use getEndLoc instead") {
1966  return getEndLoc();
1967  }
1968  SourceLocation getEndLoc() const LLVM_READONLY {
1969  return isPostfix() ? Loc : Val->getEndLoc();
1970  }
1971  SourceLocation getExprLoc() const LLVM_READONLY { return Loc; }
1972 
1973  static bool classof(const Stmt *T) {
1974  return T->getStmtClass() == UnaryOperatorClass;
1975  }
1976 
1977  // Iterators
1978  child_range children() { return child_range(&Val, &Val+1); }
1980  return const_child_range(&Val, &Val + 1);
1981  }
1982 };
1983 
1984 /// Helper class for OffsetOfExpr.
1985 
1986 // __builtin_offsetof(type, identifier(.identifier|[expr])*)
1988 public:
1989  /// The kind of offsetof node we have.
1990  enum Kind {
1991  /// An index into an array.
1992  Array = 0x00,
1993  /// A field.
1994  Field = 0x01,
1995  /// A field in a dependent type, known only by its name.
1996  Identifier = 0x02,
1997  /// An implicit indirection through a C++ base class, when the
1998  /// field found is in a base class.
1999  Base = 0x03
2000  };
2001 
2002 private:
2003  enum { MaskBits = 2, Mask = 0x03 };
2004 
2005  /// The source range that covers this part of the designator.
2006  SourceRange Range;
2007 
2008  /// The data describing the designator, which comes in three
2009  /// different forms, depending on the lower two bits.
2010  /// - An unsigned index into the array of Expr*'s stored after this node
2011  /// in memory, for [constant-expression] designators.
2012  /// - A FieldDecl*, for references to a known field.
2013  /// - An IdentifierInfo*, for references to a field with a given name
2014  /// when the class type is dependent.
2015  /// - A CXXBaseSpecifier*, for references that look at a field in a
2016  /// base class.
2017  uintptr_t Data;
2018 
2019 public:
2020  /// Create an offsetof node that refers to an array element.
2021  OffsetOfNode(SourceLocation LBracketLoc, unsigned Index,
2022  SourceLocation RBracketLoc)
2023  : Range(LBracketLoc, RBracketLoc), Data((Index << 2) | Array) {}
2024 
2025  /// Create an offsetof node that refers to a field.
2027  : Range(DotLoc.isValid() ? DotLoc : NameLoc, NameLoc),
2028  Data(reinterpret_cast<uintptr_t>(Field) | OffsetOfNode::Field) {}
2029 
2030  /// Create an offsetof node that refers to an identifier.
2032  SourceLocation NameLoc)
2033  : Range(DotLoc.isValid() ? DotLoc : NameLoc, NameLoc),
2034  Data(reinterpret_cast<uintptr_t>(Name) | Identifier) {}
2035 
2036  /// Create an offsetof node that refers into a C++ base class.
2038  : Range(), Data(reinterpret_cast<uintptr_t>(Base) | OffsetOfNode::Base) {}
2039 
2040  /// Determine what kind of offsetof node this is.
2041  Kind getKind() const { return static_cast<Kind>(Data & Mask); }
2042 
2043  /// For an array element node, returns the index into the array
2044  /// of expressions.
2045  unsigned getArrayExprIndex() const {
2046  assert(getKind() == Array);
2047  return Data >> 2;
2048  }
2049 
2050  /// For a field offsetof node, returns the field.
2051  FieldDecl *getField() const {
2052  assert(getKind() == Field);
2053  return reinterpret_cast<FieldDecl *>(Data & ~(uintptr_t)Mask);
2054  }
2055 
2056  /// For a field or identifier offsetof node, returns the name of
2057  /// the field.
2058  IdentifierInfo *getFieldName() const;
2059 
2060  /// For a base class node, returns the base specifier.
2062  assert(getKind() == Base);
2063  return reinterpret_cast<CXXBaseSpecifier *>(Data & ~(uintptr_t)Mask);
2064  }
2065 
2066  /// Retrieve the source range that covers this offsetof node.
2067  ///
2068  /// For an array element node, the source range contains the locations of
2069  /// the square brackets. For a field or identifier node, the source range
2070  /// contains the location of the period (if there is one) and the
2071  /// identifier.
2072  SourceRange getSourceRange() const LLVM_READONLY { return Range; }
2073  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocStart() const LLVM_READONLY,
2074  "Use getBeginLoc instead") {
2075  return getBeginLoc();
2076  }
2077  SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); }
2078  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocEnd() const LLVM_READONLY,
2079  "Use getEndLoc instead") {
2080  return getEndLoc();
2081  }
2082  SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); }
2083 };
2084 
2085 /// OffsetOfExpr - [C99 7.17] - This represents an expression of the form
2086 /// offsetof(record-type, member-designator). For example, given:
2087 /// @code
2088 /// struct S {
2089 /// float f;
2090 /// double d;
2091 /// };
2092 /// struct T {
2093 /// int i;
2094 /// struct S s[10];
2095 /// };
2096 /// @endcode
2097 /// we can represent and evaluate the expression @c offsetof(struct T, s[2].d).
2098 
2099 class OffsetOfExpr final
2100  : public Expr,
2101  private llvm::TrailingObjects<OffsetOfExpr, OffsetOfNode, Expr *> {
2102  SourceLocation OperatorLoc, RParenLoc;
2103  // Base type;
2104  TypeSourceInfo *TSInfo;
2105  // Number of sub-components (i.e. instances of OffsetOfNode).
2106  unsigned NumComps;
2107  // Number of sub-expressions (i.e. array subscript expressions).
2108  unsigned NumExprs;
2109 
2110  size_t numTrailingObjects(OverloadToken<OffsetOfNode>) const {
2111  return NumComps;
2112  }
2113 
2114  OffsetOfExpr(const ASTContext &C, QualType type,
2115  SourceLocation OperatorLoc, TypeSourceInfo *tsi,
2117  SourceLocation RParenLoc);
2118 
2119  explicit OffsetOfExpr(unsigned numComps, unsigned numExprs)
2120  : Expr(OffsetOfExprClass, EmptyShell()),
2121  TSInfo(nullptr), NumComps(numComps), NumExprs(numExprs) {}
2122 
2123 public:
2124 
2125  static OffsetOfExpr *Create(const ASTContext &C, QualType type,
2126  SourceLocation OperatorLoc, TypeSourceInfo *tsi,
2127  ArrayRef<OffsetOfNode> comps,
2128  ArrayRef<Expr*> exprs, SourceLocation RParenLoc);
2129 
2130  static OffsetOfExpr *CreateEmpty(const ASTContext &C,
2131  unsigned NumComps, unsigned NumExprs);
2132 
2133  /// getOperatorLoc - Return the location of the operator.
2134  SourceLocation getOperatorLoc() const { return OperatorLoc; }
2135  void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
2136 
2137  /// Return the location of the right parentheses.
2138  SourceLocation getRParenLoc() const { return RParenLoc; }
2139  void setRParenLoc(SourceLocation R) { RParenLoc = R; }
2140 
2142  return TSInfo;
2143  }
2145  TSInfo = tsi;
2146  }
2147 
2148  const OffsetOfNode &getComponent(unsigned Idx) const {
2149  assert(Idx < NumComps && "Subscript out of range");
2150  return getTrailingObjects<OffsetOfNode>()[Idx];
2151  }
2152 
2153  void setComponent(unsigned Idx, OffsetOfNode ON) {
2154  assert(Idx < NumComps && "Subscript out of range");
2155  getTrailingObjects<OffsetOfNode>()[Idx] = ON;
2156  }
2157 
2158  unsigned getNumComponents() const {
2159  return NumComps;
2160  }
2161 
2162  Expr* getIndexExpr(unsigned Idx) {
2163  assert(Idx < NumExprs && "Subscript out of range");
2164  return getTrailingObjects<Expr *>()[Idx];
2165  }
2166 
2167  const Expr *getIndexExpr(unsigned Idx) const {
2168  assert(Idx < NumExprs && "Subscript out of range");
2169  return getTrailingObjects<Expr *>()[Idx];
2170  }
2171 
2172  void setIndexExpr(unsigned Idx, Expr* E) {
2173  assert(Idx < NumComps && "Subscript out of range");
2174  getTrailingObjects<Expr *>()[Idx] = E;
2175  }
2176 
2177  unsigned getNumExpressions() const {
2178  return NumExprs;
2179  }
2180 
2181  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocStart() const LLVM_READONLY,
2182  "Use getBeginLoc instead") {
2183  return getBeginLoc();
2184  }
2185  SourceLocation getBeginLoc() const LLVM_READONLY { return OperatorLoc; }
2186  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocEnd() const LLVM_READONLY,
2187  "Use getEndLoc instead") {
2188  return getEndLoc();
2189  }
2190  SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
2191 
2192  static bool classof(const Stmt *T) {
2193  return T->getStmtClass() == OffsetOfExprClass;
2194  }
2195 
2196  // Iterators
2198  Stmt **begin = reinterpret_cast<Stmt **>(getTrailingObjects<Expr *>());
2199  return child_range(begin, begin + NumExprs);
2200  }
2202  Stmt *const *begin =
2203  reinterpret_cast<Stmt *const *>(getTrailingObjects<Expr *>());
2204  return const_child_range(begin, begin + NumExprs);
2205  }
2207 };
2208 
2209 /// UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated)
2210 /// expression operand. Used for sizeof/alignof (C99 6.5.3.4) and
2211 /// vec_step (OpenCL 1.1 6.11.12).
2213  union {
2216  } Argument;
2217  SourceLocation OpLoc, RParenLoc;
2218 
2219 public:
2221  QualType resultType, SourceLocation op,
2222  SourceLocation rp) :
2223  Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_RValue, OK_Ordinary,
2224  false, // Never type-dependent (C++ [temp.dep.expr]p3).
2225  // Value-dependent if the argument is type-dependent.
2226  TInfo->getType()->isDependentType(),
2227  TInfo->getType()->isInstantiationDependentType(),
2228  TInfo->getType()->containsUnexpandedParameterPack()),
2229  OpLoc(op), RParenLoc(rp) {
2230  UnaryExprOrTypeTraitExprBits.Kind = ExprKind;
2231  UnaryExprOrTypeTraitExprBits.IsType = true;
2232  Argument.Ty = TInfo;
2233  }
2234 
2236  QualType resultType, SourceLocation op,
2237  SourceLocation rp);
2238 
2239  /// Construct an empty sizeof/alignof expression.
2241  : Expr(UnaryExprOrTypeTraitExprClass, Empty) { }
2242 
2244  return static_cast<UnaryExprOrTypeTrait>(UnaryExprOrTypeTraitExprBits.Kind);
2245  }
2246  void setKind(UnaryExprOrTypeTrait K) { UnaryExprOrTypeTraitExprBits.Kind = K;}
2247 
2248  bool isArgumentType() const { return UnaryExprOrTypeTraitExprBits.IsType; }
2250  return getArgumentTypeInfo()->getType();
2251  }
2253  assert(isArgumentType() && "calling getArgumentType() when arg is expr");
2254  return Argument.Ty;
2255  }
2257  assert(!isArgumentType() && "calling getArgumentExpr() when arg is type");
2258  return static_cast<Expr*>(Argument.Ex);
2259  }
2260  const Expr *getArgumentExpr() const {
2261  return const_cast<UnaryExprOrTypeTraitExpr*>(this)->getArgumentExpr();
2262  }
2263 
2264  void setArgument(Expr *E) {
2265  Argument.Ex = E;
2266  UnaryExprOrTypeTraitExprBits.IsType = false;
2267  }
2269  Argument.Ty = TInfo;
2270  UnaryExprOrTypeTraitExprBits.IsType = true;
2271  }
2272 
2273  /// Gets the argument type, or the type of the argument expression, whichever
2274  /// is appropriate.
2276  return isArgumentType() ? getArgumentType() : getArgumentExpr()->getType();
2277  }
2278 
2279  SourceLocation getOperatorLoc() const { return OpLoc; }
2280  void setOperatorLoc(SourceLocation L) { OpLoc = L; }
2281 
2282  SourceLocation getRParenLoc() const { return RParenLoc; }
2283  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2284 
2285  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocStart() const LLVM_READONLY,
2286  "Use getBeginLoc instead") {
2287  return getBeginLoc();
2288  }
2289  SourceLocation getBeginLoc() const LLVM_READONLY { return OpLoc; }
2290  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocEnd() const LLVM_READONLY,
2291  "Use getEndLoc instead") {
2292  return getEndLoc();
2293  }
2294  SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
2295 
2296  static bool classof(const Stmt *T) {
2297  return T->getStmtClass() == UnaryExprOrTypeTraitExprClass;
2298  }
2299 
2300  // Iterators
2302  const_child_range children() const;
2303 };
2304 
2305 //===----------------------------------------------------------------------===//
2306 // Postfix Operators.
2307 //===----------------------------------------------------------------------===//
2308 
2309 /// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
2310 class ArraySubscriptExpr : public Expr {
2311  enum { LHS, RHS, END_EXPR=2 };
2312  Stmt* SubExprs[END_EXPR];
2313  SourceLocation RBracketLoc;
2314 public:
2317  SourceLocation rbracketloc)
2318  : Expr(ArraySubscriptExprClass, t, VK, OK,
2319  lhs->isTypeDependent() || rhs->isTypeDependent(),
2320  lhs->isValueDependent() || rhs->isValueDependent(),
2321  (lhs->isInstantiationDependent() ||
2322  rhs->isInstantiationDependent()),
2323  (lhs->containsUnexpandedParameterPack() ||
2324  rhs->containsUnexpandedParameterPack())),
2325  RBracketLoc(rbracketloc) {
2326  SubExprs[LHS] = lhs;
2327  SubExprs[RHS] = rhs;
2328  }
2329 
2330  /// Create an empty array subscript expression.
2332  : Expr(ArraySubscriptExprClass, Shell) { }
2333 
2334  /// An array access can be written A[4] or 4[A] (both are equivalent).
2335  /// - getBase() and getIdx() always present the normalized view: A[4].
2336  /// In this case getBase() returns "A" and getIdx() returns "4".
2337  /// - getLHS() and getRHS() present the syntactic view. e.g. for
2338  /// 4[A] getLHS() returns "4".
2339  /// Note: Because vector element access is also written A[4] we must
2340  /// predicate the format conversion in getBase and getIdx only on the
2341  /// the type of the RHS, as it is possible for the LHS to be a vector of
2342  /// integer type
2343  Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); }
2344  const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
2345  void setLHS(Expr *E) { SubExprs[LHS] = E; }
2346 
2347  Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); }
2348  const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
2349  void setRHS(Expr *E) { SubExprs[RHS] = E; }
2350 
2352  return getRHS()->getType()->isIntegerType() ? getLHS() : getRHS();
2353  }
2354 
2355  const Expr *getBase() const {
2356  return getRHS()->getType()->isIntegerType() ? getLHS() : getRHS();
2357  }
2358 
2360  return getRHS()->getType()->isIntegerType() ? getRHS() : getLHS();
2361  }
2362 
2363  const Expr *getIdx() const {
2364  return getRHS()->getType()->isIntegerType() ? getRHS() : getLHS();
2365  }
2366 
2367  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocStart() const LLVM_READONLY,
2368  "Use getBeginLoc instead") {
2369  return getBeginLoc();
2370  }
2371  SourceLocation getBeginLoc() const LLVM_READONLY {
2372  return getLHS()->getBeginLoc();
2373  }
2374  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocEnd() const LLVM_READONLY,
2375  "Use getEndLoc instead") {
2376  return getEndLoc();
2377  }
2378  SourceLocation getEndLoc() const LLVM_READONLY { return RBracketLoc; }
2379 
2380  SourceLocation getRBracketLoc() const { return RBracketLoc; }
2381  void setRBracketLoc(SourceLocation L) { RBracketLoc = L; }
2382 
2383  SourceLocation getExprLoc() const LLVM_READONLY {
2384  return getBase()->getExprLoc();
2385  }
2386 
2387  static bool classof(const Stmt *T) {
2388  return T->getStmtClass() == ArraySubscriptExprClass;
2389  }
2390 
2391  // Iterators
2393  return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
2394  }
2396  return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
2397  }
2398 };
2399 
2400 /// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
2401 /// CallExpr itself represents a normal function call, e.g., "f(x, 2)",
2402 /// while its subclasses may represent alternative syntax that (semantically)
2403 /// results in a function call. For example, CXXOperatorCallExpr is
2404 /// a subclass for overloaded operator calls that use operator syntax, e.g.,
2405 /// "str1 + str2" to resolve to a function call.
2406 class CallExpr : public Expr {
2407  enum { FN=0, PREARGS_START=1 };
2408  Stmt **SubExprs;
2409  unsigned NumArgs;
2410  SourceLocation RParenLoc;
2411 
2412  void updateDependenciesFromArg(Expr *Arg);
2413 
2414 protected:
2415  // These versions of the constructor are for derived classes.
2416  CallExpr(const ASTContext &C, StmtClass SC, Expr *fn,
2417  ArrayRef<Expr *> preargs, ArrayRef<Expr *> args, QualType t,
2418  ExprValueKind VK, SourceLocation rparenloc);
2419  CallExpr(const ASTContext &C, StmtClass SC, Expr *fn, ArrayRef<Expr *> args,
2420  QualType t, ExprValueKind VK, SourceLocation rparenloc);
2421  CallExpr(const ASTContext &C, StmtClass SC, unsigned NumPreArgs,
2422  EmptyShell Empty);
2423 
2424  Stmt *getPreArg(unsigned i) {
2425  assert(i < getNumPreArgs() && "Prearg access out of range!");
2426  return SubExprs[PREARGS_START+i];
2427  }
2428  const Stmt *getPreArg(unsigned i) const {
2429  assert(i < getNumPreArgs() && "Prearg access out of range!");
2430  return SubExprs[PREARGS_START+i];
2431  }
2432  void setPreArg(unsigned i, Stmt *PreArg) {
2433  assert(i < getNumPreArgs() && "Prearg access out of range!");
2434  SubExprs[PREARGS_START+i] = PreArg;
2435  }
2436 
2437  unsigned getNumPreArgs() const { return CallExprBits.NumPreArgs; }
2438 
2439 public:
2440  CallExpr(const ASTContext& C, Expr *fn, ArrayRef<Expr*> args, QualType t,
2441  ExprValueKind VK, SourceLocation rparenloc);
2442 
2443  /// Build an empty call expression.
2444  CallExpr(const ASTContext &C, StmtClass SC, EmptyShell Empty);
2445 
2446  const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); }
2447  Expr *getCallee() { return cast<Expr>(SubExprs[FN]); }
2448  void setCallee(Expr *F) { SubExprs[FN] = F; }
2449 
2450  Decl *getCalleeDecl();
2451  const Decl *getCalleeDecl() const {
2452  return const_cast<CallExpr*>(this)->getCalleeDecl();
2453  }
2454 
2455  /// If the callee is a FunctionDecl, return it. Otherwise return 0.
2456  FunctionDecl *getDirectCallee();
2458  return const_cast<CallExpr*>(this)->getDirectCallee();
2459  }
2460 
2461  /// getNumArgs - Return the number of actual arguments to this call.
2462  ///
2463  unsigned getNumArgs() const { return NumArgs; }
2464 
2465  /// Retrieve the call arguments.
2467  return reinterpret_cast<Expr **>(SubExprs+getNumPreArgs()+PREARGS_START);
2468  }
2469  const Expr *const *getArgs() const {
2470  return reinterpret_cast<Expr **>(SubExprs + getNumPreArgs() +
2471  PREARGS_START);
2472  }
2473 
2474  /// getArg - Return the specified argument.
2475  Expr *getArg(unsigned Arg) {
2476  assert(Arg < NumArgs && "Arg access out of range!");
2477  return cast_or_null<Expr>(SubExprs[Arg + getNumPreArgs() + PREARGS_START]);
2478  }
2479  const Expr *getArg(unsigned Arg) const {
2480  assert(Arg < NumArgs && "Arg access out of range!");
2481  return cast_or_null<Expr>(SubExprs[Arg + getNumPreArgs() + PREARGS_START]);
2482  }
2483 
2484  /// setArg - Set the specified argument.
2485  void setArg(unsigned Arg, Expr *ArgExpr) {
2486  assert(Arg < NumArgs && "Arg access out of range!");
2487  SubExprs[Arg+getNumPreArgs()+PREARGS_START] = ArgExpr;
2488  }
2489 
2490  /// setNumArgs - This changes the number of arguments present in this call.
2491  /// Any orphaned expressions are deleted by this, and any new operands are set
2492  /// to null.
2493  void setNumArgs(const ASTContext& C, unsigned NumArgs);
2494 
2497  typedef llvm::iterator_range<arg_iterator> arg_range;
2498  typedef llvm::iterator_range<const_arg_iterator> const_arg_range;
2499 
2500  arg_range arguments() { return arg_range(arg_begin(), arg_end()); }
2501  const_arg_range arguments() const {
2502  return const_arg_range(arg_begin(), arg_end());
2503  }
2504 
2505  arg_iterator arg_begin() { return SubExprs+PREARGS_START+getNumPreArgs(); }
2506  arg_iterator arg_end() {
2507  return SubExprs+PREARGS_START+getNumPreArgs()+getNumArgs();
2508  }
2509  const_arg_iterator arg_begin() const {
2510  return SubExprs+PREARGS_START+getNumPreArgs();
2511  }
2512  const_arg_iterator arg_end() const {
2513  return SubExprs+PREARGS_START+getNumPreArgs()+getNumArgs();
2514  }
2515 
2516  /// This method provides fast access to all the subexpressions of
2517  /// a CallExpr without going through the slower virtual child_iterator
2518  /// interface. This provides efficient reverse iteration of the
2519  /// subexpressions. This is currently used for CFG construction.
2521  return llvm::makeArrayRef(SubExprs,
2522  getNumPreArgs() + PREARGS_START + getNumArgs());
2523  }
2524 
2525  /// getNumCommas - Return the number of commas that must have been present in
2526  /// this function call.
2527  unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; }
2528 
2529  /// getBuiltinCallee - If this is a call to a builtin, return the builtin ID
2530  /// of the callee. If not, return 0.
2531  unsigned getBuiltinCallee() const;
2532 
2533  /// Returns \c true if this is a call to a builtin which does not
2534  /// evaluate side-effects within its arguments.
2535  bool isUnevaluatedBuiltinCall(const ASTContext &Ctx) const;
2536 
2537  /// getCallReturnType - Get the return type of the call expr. This is not
2538  /// always the type of the expr itself, if the return type is a reference
2539  /// type.
2540  QualType getCallReturnType(const ASTContext &Ctx) const;
2541 
2542  SourceLocation getRParenLoc() const { return RParenLoc; }
2543  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2544 
2545  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocStart() const LLVM_READONLY,
2546  "Use getBeginLoc instead") {
2547  return getBeginLoc();
2548  }
2549  SourceLocation getBeginLoc() const LLVM_READONLY;
2550  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocEnd() const LLVM_READONLY,
2551  "Use getEndLoc instead") {
2552  return getEndLoc();
2553  }
2554  SourceLocation getEndLoc() const LLVM_READONLY;
2555 
2556  /// Return true if this is a call to __assume() or __builtin_assume() with
2557  /// a non-value-dependent constant parameter evaluating as false.
2558  bool isBuiltinAssumeFalse(const ASTContext &Ctx) const;
2559 
2560  bool isCallToStdMove() const {
2561  const FunctionDecl* FD = getDirectCallee();
2562  return getNumArgs() == 1 && FD && FD->isInStdNamespace() &&
2563  FD->getIdentifier() && FD->getIdentifier()->isStr("move");
2564  }
2565 
2566  static bool classof(const Stmt *T) {
2567  return T->getStmtClass() >= firstCallExprConstant &&
2568  T->getStmtClass() <= lastCallExprConstant;
2569  }
2570 
2571  // Iterators
2573  return child_range(&SubExprs[0],
2574  &SubExprs[0]+NumArgs+getNumPreArgs()+PREARGS_START);
2575  }
2576 
2578  return const_child_range(&SubExprs[0], &SubExprs[0] + NumArgs +
2579  getNumPreArgs() + PREARGS_START);
2580  }
2581 };
2582 
2583 /// Extra data stored in some MemberExpr objects.
2585  /// The nested-name-specifier that qualifies the name, including
2586  /// source-location information.
2588 
2589  /// The DeclAccessPair through which the MemberDecl was found due to
2590  /// name qualifiers.
2592 };
2593 
2594 /// MemberExpr - [C99 6.5.2.3] Structure and Union Members. X->F and X.F.
2595 ///
2596 class MemberExpr final
2597  : public Expr,
2598  private llvm::TrailingObjects<MemberExpr, MemberExprNameQualifier,
2599  ASTTemplateKWAndArgsInfo,
2600  TemplateArgumentLoc> {
2601  /// Base - the expression for the base pointer or structure references. In
2602  /// X.F, this is "X".
2603  Stmt *Base;
2604 
2605  /// MemberDecl - This is the decl being referenced by the field/member name.
2606  /// In X.F, this is the decl referenced by F.
2607  ValueDecl *MemberDecl;
2608 
2609  /// MemberDNLoc - Provides source/type location info for the
2610  /// declaration name embedded in MemberDecl.
2611  DeclarationNameLoc MemberDNLoc;
2612 
2613  /// MemberLoc - This is the location of the member name.
2614  SourceLocation MemberLoc;
2615 
2616  /// This is the location of the -> or . in the expression.
2617  SourceLocation OperatorLoc;
2618 
2619  /// IsArrow - True if this is "X->F", false if this is "X.F".
2620  bool IsArrow : 1;
2621 
2622  /// True if this member expression used a nested-name-specifier to
2623  /// refer to the member, e.g., "x->Base::f", or found its member via a using
2624  /// declaration. When true, a MemberExprNameQualifier
2625  /// structure is allocated immediately after the MemberExpr.
2626  bool HasQualifierOrFoundDecl : 1;
2627 
2628  /// True if this member expression specified a template keyword
2629  /// and/or a template argument list explicitly, e.g., x->f<int>,
2630  /// x->template f, x->template f<int>.
2631  /// When true, an ASTTemplateKWAndArgsInfo structure and its
2632  /// TemplateArguments (if any) are present.
2633  bool HasTemplateKWAndArgsInfo : 1;
2634 
2635  /// True if this member expression refers to a method that
2636  /// was resolved from an overloaded set having size greater than 1.
2637  bool HadMultipleCandidates : 1;
2638 
2639  size_t numTrailingObjects(OverloadToken<MemberExprNameQualifier>) const {
2640  return HasQualifierOrFoundDecl ? 1 : 0;
2641  }
2642 
2643  size_t numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
2644  return HasTemplateKWAndArgsInfo ? 1 : 0;
2645  }
2646 
2647 public:
2648  MemberExpr(Expr *base, bool isarrow, SourceLocation operatorloc,
2649  ValueDecl *memberdecl, const DeclarationNameInfo &NameInfo,
2651  : Expr(MemberExprClass, ty, VK, OK, base->isTypeDependent(),
2652  base->isValueDependent(), base->isInstantiationDependent(),
2653  base->containsUnexpandedParameterPack()),
2654  Base(base), MemberDecl(memberdecl), MemberDNLoc(NameInfo.getInfo()),
2655  MemberLoc(NameInfo.getLoc()), OperatorLoc(operatorloc),
2656  IsArrow(isarrow), HasQualifierOrFoundDecl(false),
2657  HasTemplateKWAndArgsInfo(false), HadMultipleCandidates(false) {
2658  assert(memberdecl->getDeclName() == NameInfo.getName());
2659  }
2660 
2661  // NOTE: this constructor should be used only when it is known that
2662  // the member name can not provide additional syntactic info
2663  // (i.e., source locations for C++ operator names or type source info
2664  // for constructors, destructors and conversion operators).
2665  MemberExpr(Expr *base, bool isarrow, SourceLocation operatorloc,
2666  ValueDecl *memberdecl, SourceLocation l, QualType ty,
2668  : Expr(MemberExprClass, ty, VK, OK, base->isTypeDependent(),
2669  base->isValueDependent(), base->isInstantiationDependent(),
2670  base->containsUnexpandedParameterPack()),
2671  Base(base), MemberDecl(memberdecl), MemberDNLoc(), MemberLoc(l),
2672  OperatorLoc(operatorloc), IsArrow(isarrow),
2673  HasQualifierOrFoundDecl(false), HasTemplateKWAndArgsInfo(false),
2674  HadMultipleCandidates(false) {}
2675 
2676  static MemberExpr *Create(const ASTContext &C, Expr *base, bool isarrow,
2677  SourceLocation OperatorLoc,
2678  NestedNameSpecifierLoc QualifierLoc,
2679  SourceLocation TemplateKWLoc, ValueDecl *memberdecl,
2680  DeclAccessPair founddecl,
2681  DeclarationNameInfo MemberNameInfo,
2682  const TemplateArgumentListInfo *targs, QualType ty,
2683  ExprValueKind VK, ExprObjectKind OK);
2684 
2685  void setBase(Expr *E) { Base = E; }
2686  Expr *getBase() const { return cast<Expr>(Base); }
2687 
2688  /// Retrieve the member declaration to which this expression refers.
2689  ///
2690  /// The returned declaration will be a FieldDecl or (in C++) a VarDecl (for
2691  /// static data members), a CXXMethodDecl, or an EnumConstantDecl.
2692  ValueDecl *getMemberDecl() const { return MemberDecl; }
2693  void setMemberDecl(ValueDecl *D) { MemberDecl = D; }
2694 
2695  /// Retrieves the declaration found by lookup.
2697  if (!HasQualifierOrFoundDecl)
2698  return DeclAccessPair::make(getMemberDecl(),
2699  getMemberDecl()->getAccess());
2700  return getTrailingObjects<MemberExprNameQualifier>()->FoundDecl;
2701  }
2702 
2703  /// Determines whether this member expression actually had
2704  /// a C++ nested-name-specifier prior to the name of the member, e.g.,
2705  /// x->Base::foo.
2706  bool hasQualifier() const { return getQualifier() != nullptr; }
2707 
2708  /// If the member name was qualified, retrieves the
2709  /// nested-name-specifier that precedes the member name, with source-location
2710  /// information.
2712  if (!HasQualifierOrFoundDecl)
2713  return NestedNameSpecifierLoc();
2714 
2715  return getTrailingObjects<MemberExprNameQualifier>()->QualifierLoc;
2716  }
2717 
2718  /// If the member name was qualified, retrieves the
2719  /// nested-name-specifier that precedes the member name. Otherwise, returns
2720  /// NULL.
2722  return getQualifierLoc().getNestedNameSpecifier();
2723  }
2724 
2725  /// Retrieve the location of the template keyword preceding
2726  /// the member name, if any.
2728  if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2729  return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->TemplateKWLoc;
2730  }
2731 
2732  /// Retrieve the location of the left angle bracket starting the
2733  /// explicit template argument list following the member name, if any.
2735  if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2736  return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->LAngleLoc;
2737  }
2738 
2739  /// Retrieve the location of the right angle bracket ending the
2740  /// explicit template argument list following the member name, if any.
2742  if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2743  return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->RAngleLoc;
2744  }
2745 
2746  /// Determines whether the member name was preceded by the template keyword.
2747  bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
2748 
2749  /// Determines whether the member name was followed by an
2750  /// explicit template argument list.
2751  bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
2752 
2753  /// Copies the template arguments (if present) into the given
2754  /// structure.
2756  if (hasExplicitTemplateArgs())
2757  getTrailingObjects<ASTTemplateKWAndArgsInfo>()->copyInto(
2758  getTrailingObjects<TemplateArgumentLoc>(), List);
2759  }
2760 
2761  /// Retrieve the template arguments provided as part of this
2762  /// template-id.
2764  if (!hasExplicitTemplateArgs())
2765  return nullptr;
2766 
2767  return getTrailingObjects<TemplateArgumentLoc>();
2768  }
2769 
2770  /// Retrieve the number of template arguments provided as part of this
2771  /// template-id.
2772  unsigned getNumTemplateArgs() const {
2773  if (!hasExplicitTemplateArgs())
2774  return 0;
2775 
2776  return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs;
2777  }
2778 
2780  return {getTemplateArgs(), getNumTemplateArgs()};
2781  }
2782 
2783  /// Retrieve the member declaration name info.
2785  return DeclarationNameInfo(MemberDecl->getDeclName(),
2786  MemberLoc, MemberDNLoc);
2787  }
2788 
2789  SourceLocation getOperatorLoc() const LLVM_READONLY { return OperatorLoc; }
2790 
2791  bool isArrow() const { return IsArrow; }
2792  void setArrow(bool A) { IsArrow = A; }
2793 
2794  /// getMemberLoc - Return the location of the "member", in X->F, it is the
2795  /// location of 'F'.
2796  SourceLocation getMemberLoc() const { return MemberLoc; }
2797  void setMemberLoc(SourceLocation L) { MemberLoc = L; }
2798 
2799  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocStart() const LLVM_READONLY,
2800  "Use getBeginLoc instead") {
2801  return getBeginLoc();
2802  }
2803  SourceLocation getBeginLoc() const LLVM_READONLY;
2804  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocEnd() const LLVM_READONLY,
2805  "Use getEndLoc instead") {
2806  return getEndLoc();
2807  }
2808  SourceLocation getEndLoc() const LLVM_READONLY;
2809 
2810  SourceLocation getExprLoc() const LLVM_READONLY { return MemberLoc; }
2811 
2812  /// Determine whether the base of this explicit is implicit.
2813  bool isImplicitAccess() const {
2814  return getBase() && getBase()->isImplicitCXXThis();
2815  }
2816 
2817  /// Returns true if this member expression refers to a method that
2818  /// was resolved from an overloaded set having size greater than 1.
2819  bool hadMultipleCandidates() const {
2820  return HadMultipleCandidates;
2821  }
2822  /// Sets the flag telling whether this expression refers to
2823  /// a method that was resolved from an overloaded set having size
2824  /// greater than 1.
2825  void setHadMultipleCandidates(bool V = true) {
2826  HadMultipleCandidates = V;
2827  }
2828 
2829  /// Returns true if virtual dispatch is performed.
2830  /// If the member access is fully qualified, (i.e. X::f()), virtual
2831  /// dispatching is not performed. In -fapple-kext mode qualified
2832  /// calls to virtual method will still go through the vtable.
2833  bool performsVirtualDispatch(const LangOptions &LO) const {
2834  return LO.AppleKext || !hasQualifier();
2835  }
2836 
2837  static bool classof(const Stmt *T) {
2838  return T->getStmtClass() == MemberExprClass;
2839  }
2840 
2841  // Iterators
2842  child_range children() { return child_range(&Base, &Base+1); }
2844  return const_child_range(&Base, &Base + 1);
2845  }
2846 
2848  friend class ASTReader;
2849  friend class ASTStmtWriter;
2850 };
2851 
2852 /// CompoundLiteralExpr - [C99 6.5.2.5]
2853 ///
2854 class CompoundLiteralExpr : public Expr {
2855  /// LParenLoc - If non-null, this is the location of the left paren in a
2856  /// compound literal like "(int){4}". This can be null if this is a
2857  /// synthesized compound expression.
2858  SourceLocation LParenLoc;
2859 
2860  /// The type as written. This can be an incomplete array type, in
2861  /// which case the actual expression type will be different.
2862  /// The int part of the pair stores whether this expr is file scope.
2863  llvm::PointerIntPair<TypeSourceInfo *, 1, bool> TInfoAndScope;
2864  Stmt *Init;
2865 public:
2867  QualType T, ExprValueKind VK, Expr *init, bool fileScope)
2868  : Expr(CompoundLiteralExprClass, T, VK, OK_Ordinary,
2869  tinfo->getType()->isDependentType(),
2870  init->isValueDependent(),
2871  (init->isInstantiationDependent() ||
2872  tinfo->getType()->isInstantiationDependentType()),
2873  init->containsUnexpandedParameterPack()),
2874  LParenLoc(lparenloc), TInfoAndScope(tinfo, fileScope), Init(init) {}
2875 
2876  /// Construct an empty compound literal.
2878  : Expr(CompoundLiteralExprClass, Empty) { }
2879 
2880  const Expr *getInitializer() const { return cast<Expr>(Init); }
2881  Expr *getInitializer() { return cast<Expr>(Init); }
2882  void setInitializer(Expr *E) { Init = E; }
2883 
2884  bool isFileScope() const { return TInfoAndScope.getInt(); }
2885  void setFileScope(bool FS) { TInfoAndScope.setInt(FS); }
2886 
2887  SourceLocation getLParenLoc() const { return LParenLoc; }
2888  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2889 
2891  return TInfoAndScope.getPointer();
2892  }
2894  TInfoAndScope.setPointer(tinfo);
2895  }
2896 
2897  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocStart() const LLVM_READONLY,
2898  "Use getBeginLoc instead") {
2899  return getBeginLoc();
2900  }
2901  SourceLocation getBeginLoc() const LLVM_READONLY {
2902  // FIXME: Init should never be null.
2903  if (!Init)
2904  return SourceLocation();
2905  if (LParenLoc.isInvalid())
2906  return Init->getBeginLoc();
2907  return LParenLoc;
2908  }
2909  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocEnd() const LLVM_READONLY,
2910  "Use getEndLoc instead") {
2911  return getEndLoc();
2912  }
2913  SourceLocation getEndLoc() const LLVM_READONLY {
2914  // FIXME: Init should never be null.
2915  if (!Init)
2916  return SourceLocation();
2917  return Init->getEndLoc();
2918  }
2919 
2920  static bool classof(const Stmt *T) {
2921  return T->getStmtClass() == CompoundLiteralExprClass;
2922  }
2923 
2924  // Iterators
2925  child_range children() { return child_range(&Init, &Init+1); }
2927  return const_child_range(&Init, &Init + 1);
2928  }
2929 };
2930 
2931 /// CastExpr - Base class for type casts, including both implicit
2932 /// casts (ImplicitCastExpr) and explicit casts that have some
2933 /// representation in the source code (ExplicitCastExpr's derived
2934 /// classes).
2935 class CastExpr : public Expr {
2936 public:
2937  using BasePathSizeTy = unsigned int;
2938  static_assert(std::numeric_limits<BasePathSizeTy>::max() >= 16384,
2939  "[implimits] Direct and indirect base classes [16384].");
2940 
2941 private:
2942  Stmt *Op;
2943 
2944  bool CastConsistency() const;
2945 
2946  BasePathSizeTy *BasePathSize();
2947 
2948  const CXXBaseSpecifier * const *path_buffer() const {
2949  return const_cast<CastExpr*>(this)->path_buffer();
2950  }
2951  CXXBaseSpecifier **path_buffer();
2952 
2953  void setBasePathSize(BasePathSizeTy basePathSize) {
2954  assert(!path_empty() && basePathSize != 0);
2955  *(BasePathSize()) = basePathSize;
2956  }
2957 
2958 protected:
2960  Expr *op, unsigned BasePathSize)
2961  : Expr(SC, ty, VK, OK_Ordinary,
2962  // Cast expressions are type-dependent if the type is
2963  // dependent (C++ [temp.dep.expr]p3).
2964  ty->isDependentType(),
2965  // Cast expressions are value-dependent if the type is
2966  // dependent or if the subexpression is value-dependent.
2967  ty->isDependentType() || (op && op->isValueDependent()),
2968  (ty->isInstantiationDependentType() ||
2969  (op && op->isInstantiationDependent())),
2970  // An implicit cast expression doesn't (lexically) contain an
2971  // unexpanded pack, even if its target type does.
2972  ((SC != ImplicitCastExprClass &&
2973  ty->containsUnexpandedParameterPack()) ||
2974  (op && op->containsUnexpandedParameterPack()))),
2975  Op(op) {
2976  CastExprBits.Kind = kind;
2977  CastExprBits.PartOfExplicitCast = false;
2978  CastExprBits.BasePathIsEmpty = BasePathSize == 0;
2979  if (!path_empty())
2980  setBasePathSize(BasePathSize);
2981  assert(CastConsistency());
2982  }
2983 
2984  /// Construct an empty cast.
2985  CastExpr(StmtClass SC, EmptyShell Empty, unsigned BasePathSize)
2986  : Expr(SC, Empty) {
2987  CastExprBits.PartOfExplicitCast = false;
2988  CastExprBits.BasePathIsEmpty = BasePathSize == 0;
2989  if (!path_empty())
2990  setBasePathSize(BasePathSize);
2991  }
2992 
2993 public:
2994  CastKind getCastKind() const { return (CastKind) CastExprBits.Kind; }
2995  void setCastKind(CastKind K) { CastExprBits.Kind = K; }
2996 
2997  static const char *getCastKindName(CastKind CK);
2998  const char *getCastKindName() const { return getCastKindName(getCastKind()); }
2999 
3000  Expr *getSubExpr() { return cast<Expr>(Op); }
3001  const Expr *getSubExpr() const { return cast<Expr>(Op); }
3002  void setSubExpr(Expr *E) { Op = E; }
3003 
3004  /// Retrieve the cast subexpression as it was written in the source
3005  /// code, looking through any implicit casts or other intermediate nodes
3006  /// introduced by semantic analysis.
3007  Expr *getSubExprAsWritten();
3008  const Expr *getSubExprAsWritten() const {
3009  return const_cast<CastExpr *>(this)->getSubExprAsWritten();
3010  }
3011 
3012  /// If this cast applies a user-defined conversion, retrieve the conversion
3013  /// function that it invokes.
3014  NamedDecl *getConversionFunction() const;
3015 
3017  typedef const CXXBaseSpecifier * const *path_const_iterator;
3018  bool path_empty() const { return CastExprBits.BasePathIsEmpty; }
3019  unsigned path_size() const {
3020  if (path_empty())
3021  return 0U;
3022  return *(const_cast<CastExpr *>(this)->BasePathSize());
3023  }
3024  path_iterator path_begin() { return path_buffer(); }
3025  path_iterator path_end() { return path_buffer() + path_size(); }
3026  path_const_iterator path_begin() const { return path_buffer(); }
3027  path_const_iterator path_end() const { return path_buffer() + path_size(); }
3028 
3030  assert(getCastKind() == CK_ToUnion);
3031  return getTargetFieldForToUnionCast(getType(), getSubExpr()->getType());
3032  }
3033 
3034  static const FieldDecl *getTargetFieldForToUnionCast(QualType unionType,
3035  QualType opType);
3036  static const FieldDecl *getTargetFieldForToUnionCast(const RecordDecl *RD,
3037  QualType opType);
3038 
3039  static bool classof(const Stmt *T) {
3040  return T->getStmtClass() >= firstCastExprConstant &&
3041  T->getStmtClass() <= lastCastExprConstant;
3042  }
3043 
3044  // Iterators
3045  child_range children() { return child_range(&Op, &Op+1); }
3046  const_child_range children() const { return const_child_range(&Op, &Op + 1); }
3047 };
3048 
3049 /// ImplicitCastExpr - Allows us to explicitly represent implicit type
3050 /// conversions, which have no direct representation in the original
3051 /// source code. For example: converting T[]->T*, void f()->void
3052 /// (*f)(), float->double, short->int, etc.
3053 ///
3054 /// In C, implicit casts always produce rvalues. However, in C++, an
3055 /// implicit cast whose result is being bound to a reference will be
3056 /// an lvalue or xvalue. For example:
3057 ///
3058 /// @code
3059 /// class Base { };
3060 /// class Derived : public Base { };
3061 /// Derived &&ref();
3062 /// void f(Derived d) {
3063 /// Base& b = d; // initializer is an ImplicitCastExpr
3064 /// // to an lvalue of type Base
3065 /// Base&& r = ref(); // initializer is an ImplicitCastExpr
3066 /// // to an xvalue of type Base
3067 /// }
3068 /// @endcode
3069 class ImplicitCastExpr final
3070  : public CastExpr,
3071  private llvm::TrailingObjects<ImplicitCastExpr, CastExpr::BasePathSizeTy,
3072  CXXBaseSpecifier *> {
3073  size_t numTrailingObjects(OverloadToken<CastExpr::BasePathSizeTy>) const {
3074  return path_empty() ? 0 : 1;
3075  }
3076 
3077 private:
3079  unsigned BasePathLength, ExprValueKind VK)
3080  : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, BasePathLength) {
3081  }
3082 
3083  /// Construct an empty implicit cast.
3084  explicit ImplicitCastExpr(EmptyShell Shell, unsigned PathSize)
3085  : CastExpr(ImplicitCastExprClass, Shell, PathSize) { }
3086 
3087 public:
3088  enum OnStack_t { OnStack };
3090  ExprValueKind VK)
3091  : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, 0) {
3092  }
3093 
3094  bool isPartOfExplicitCast() const { return CastExprBits.PartOfExplicitCast; }
3095  void setIsPartOfExplicitCast(bool PartOfExplicitCast) {
3096  CastExprBits.PartOfExplicitCast = PartOfExplicitCast;
3097  }
3098 
3099  static ImplicitCastExpr *Create(const ASTContext &Context, QualType T,
3100  CastKind Kind, Expr *Operand,
3101  const CXXCastPath *BasePath,
3102  ExprValueKind Cat);
3103 
3104  static ImplicitCastExpr *CreateEmpty(const ASTContext &Context,
3105  unsigned PathSize);
3106 
3107  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocStart() const LLVM_READONLY,
3108  "Use getBeginLoc instead") {
3109  return getBeginLoc();
3110  }
3111  SourceLocation getBeginLoc() const LLVM_READONLY {
3112  return getSubExpr()->getBeginLoc();
3113  }
3114  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocEnd() const LLVM_READONLY,
3115  "Use getEndLoc instead") {
3116  return getEndLoc();
3117  }
3118  SourceLocation getEndLoc() const LLVM_READONLY {
3119  return getSubExpr()->getEndLoc();
3120  }
3121 
3122  static bool classof(const Stmt *T) {
3123  return T->getStmtClass() == ImplicitCastExprClass;
3124  }
3125 
3127  friend class CastExpr;
3128 };
3129 
3131  Expr *e = this;
3132  while (ImplicitCastExpr *ice = dyn_cast<ImplicitCastExpr>(e))
3133  e = ice->getSubExpr();
3134  return e;
3135 }
3136 
3137 /// ExplicitCastExpr - An explicit cast written in the source
3138 /// code.
3139 ///
3140 /// This class is effectively an abstract class, because it provides
3141 /// the basic representation of an explicitly-written cast without
3142 /// specifying which kind of cast (C cast, functional cast, static
3143 /// cast, etc.) was written; specific derived classes represent the
3144 /// particular style of cast and its location information.
3145 ///
3146 /// Unlike implicit casts, explicit cast nodes have two different
3147 /// types: the type that was written into the source code, and the
3148 /// actual type of the expression as determined by semantic
3149 /// analysis. These types may differ slightly. For example, in C++ one
3150 /// can cast to a reference type, which indicates that the resulting
3151 /// expression will be an lvalue or xvalue. The reference type, however,
3152 /// will not be used as the type of the expression.
3153 class ExplicitCastExpr : public CastExpr {
3154  /// TInfo - Source type info for the (written) type
3155  /// this expression is casting to.
3156  TypeSourceInfo *TInfo;
3157 
3158 protected:
3160  CastKind kind, Expr *op, unsigned PathSize,
3161  TypeSourceInfo *writtenTy)
3162  : CastExpr(SC, exprTy, VK, kind, op, PathSize), TInfo(writtenTy) {}
3163 
3164  /// Construct an empty explicit cast.
3165  ExplicitCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize)
3166  : CastExpr(SC, Shell, PathSize) { }
3167 
3168 public:
3169  /// getTypeInfoAsWritten - Returns the type source info for the type
3170  /// that this expression is casting to.
3171  TypeSourceInfo *getTypeInfoAsWritten() const { return TInfo; }
3172  void setTypeInfoAsWritten(TypeSourceInfo *writtenTy) { TInfo = writtenTy; }
3173 
3174  /// getTypeAsWritten - Returns the type that this expression is
3175  /// casting to, as written in the source code.
3176  QualType getTypeAsWritten() const { return TInfo->getType(); }
3177 
3178  static bool classof(const Stmt *T) {
3179  return T->getStmtClass() >= firstExplicitCastExprConstant &&
3180  T->getStmtClass() <= lastExplicitCastExprConstant;
3181  }
3182 };
3183 
3184 /// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style
3185 /// cast in C++ (C++ [expr.cast]), which uses the syntax
3186 /// (Type)expr. For example: @c (int)f.
3187 class CStyleCastExpr final
3188  : public ExplicitCastExpr,
3189  private llvm::TrailingObjects<CStyleCastExpr, CastExpr::BasePathSizeTy,
3190  CXXBaseSpecifier *> {
3191  SourceLocation LPLoc; // the location of the left paren
3192  SourceLocation RPLoc; // the location of the right paren
3193 
3194  CStyleCastExpr(QualType exprTy, ExprValueKind vk, CastKind kind, Expr *op,
3195  unsigned PathSize, TypeSourceInfo *writtenTy,
3197  : ExplicitCastExpr(CStyleCastExprClass, exprTy, vk, kind, op, PathSize,
3198  writtenTy), LPLoc(l), RPLoc(r) {}
3199 
3200  /// Construct an empty C-style explicit cast.
3201  explicit CStyleCastExpr(EmptyShell Shell, unsigned PathSize)
3202  : ExplicitCastExpr(CStyleCastExprClass, Shell, PathSize) { }
3203 
3204  size_t numTrailingObjects(OverloadToken<CastExpr::BasePathSizeTy>) const {
3205  return path_empty() ? 0 : 1;
3206  }
3207 
3208 public:
3209  static CStyleCastExpr *Create(const ASTContext &Context, QualType T,
3210  ExprValueKind VK, CastKind K,
3211  Expr *Op, const CXXCastPath *BasePath,
3212  TypeSourceInfo *WrittenTy, SourceLocation L,
3213  SourceLocation R);
3214 
3215  static CStyleCastExpr *CreateEmpty(const ASTContext &Context,
3216  unsigned PathSize);
3217 
3218  SourceLocation getLParenLoc() const { return LPLoc; }
3219  void setLParenLoc(SourceLocation L) { LPLoc = L; }
3220 
3221  SourceLocation getRParenLoc() const { return RPLoc; }
3222  void setRParenLoc(SourceLocation L) { RPLoc = L; }
3223 
3224  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocStart() const LLVM_READONLY,
3225  "Use getBeginLoc instead") {
3226  return getBeginLoc();
3227  }
3228  SourceLocation getBeginLoc() const LLVM_READONLY { return LPLoc; }
3229  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocEnd() const LLVM_READONLY,
3230  "Use getEndLoc instead") {
3231  return getEndLoc();
3232  }
3233  SourceLocation getEndLoc() const LLVM_READONLY {
3234  return getSubExpr()->getEndLoc();
3235  }
3236 
3237  static bool classof(const Stmt *T) {
3238  return T->getStmtClass() == CStyleCastExprClass;
3239  }
3240 
3242  friend class CastExpr;
3243 };
3244 
3245 /// A builtin binary operation expression such as "x + y" or "x <= y".
3246 ///
3247 /// This expression node kind describes a builtin binary operation,
3248 /// such as "x + y" for integer values "x" and "y". The operands will
3249 /// already have been converted to appropriate types (e.g., by
3250 /// performing promotions or conversions).
3251 ///
3252 /// In C++, where operators may be overloaded, a different kind of
3253 /// expression node (CXXOperatorCallExpr) is used to express the
3254 /// invocation of an overloaded operator with operator syntax. Within
3255 /// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is
3256 /// used to store an expression "x + y" depends on the subexpressions
3257 /// for x and y. If neither x or y is type-dependent, and the "+"
3258 /// operator resolves to a built-in operation, BinaryOperator will be
3259 /// used to express the computation (x and y may still be
3260 /// value-dependent). If either x or y is type-dependent, or if the
3261 /// "+" resolves to an overloaded operator, CXXOperatorCallExpr will
3262 /// be used to express the computation.
3263 class BinaryOperator : public Expr {
3264 public:
3266 
3267 private:
3268  unsigned Opc : 6;
3269 
3270  // This is only meaningful for operations on floating point types and 0
3271  // otherwise.
3272  unsigned FPFeatures : 3;
3273  SourceLocation OpLoc;
3274 
3275  enum { LHS, RHS, END_EXPR };
3276  Stmt* SubExprs[END_EXPR];
3277 public:
3278 
3279  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
3281  SourceLocation opLoc, FPOptions FPFeatures)
3282  : Expr(BinaryOperatorClass, ResTy, VK, OK,
3283  lhs->isTypeDependent() || rhs->isTypeDependent(),
3284  lhs->isValueDependent() || rhs->isValueDependent(),
3285  (lhs->isInstantiationDependent() ||
3286  rhs->isInstantiationDependent()),
3287  (lhs->containsUnexpandedParameterPack() ||
3288  rhs->containsUnexpandedParameterPack())),
3289  Opc(opc), FPFeatures(FPFeatures.getInt()), OpLoc(opLoc) {
3290  SubExprs[LHS] = lhs;
3291  SubExprs[RHS] = rhs;
3292  assert(!isCompoundAssignmentOp() &&
3293  "Use CompoundAssignOperator for compound assignments");
3294  }
3295 
3296  /// Construct an empty binary operator.
3297  explicit BinaryOperator(EmptyShell Empty)
3298  : Expr(BinaryOperatorClass, Empty), Opc(BO_Comma) { }
3299 
3300  SourceLocation getExprLoc() const LLVM_READONLY { return OpLoc; }
3301  SourceLocation getOperatorLoc() const { return OpLoc; }
3302  void setOperatorLoc(SourceLocation L) { OpLoc = L; }
3303 
3304  Opcode getOpcode() const { return static_cast<Opcode>(Opc); }
3305  void setOpcode(Opcode O) { Opc = O; }
3306 
3307  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
3308  void setLHS(Expr *E) { SubExprs[LHS] = E; }
3309  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
3310  void setRHS(Expr *E) { SubExprs[RHS] = E; }
3311 
3312  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocStart() const LLVM_READONLY,
3313  "Use getBeginLoc instead") {
3314  return getBeginLoc();
3315  }
3316  SourceLocation getBeginLoc() const LLVM_READONLY {
3317  return getLHS()->getBeginLoc();
3318  }
3319  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocEnd() const LLVM_READONLY,
3320  "Use getEndLoc instead") {
3321  return getEndLoc();
3322  }
3323  SourceLocation getEndLoc() const LLVM_READONLY {
3324  return getRHS()->getEndLoc();
3325  }
3326 
3327  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
3328  /// corresponds to, e.g. "<<=".
3329  static StringRef getOpcodeStr(Opcode Op);
3330 
3331  StringRef getOpcodeStr() const { return getOpcodeStr(getOpcode()); }
3332 
3333  /// Retrieve the binary opcode that corresponds to the given
3334  /// overloaded operator.
3335  static Opcode getOverloadedOpcode(OverloadedOperatorKind OO);
3336 
3337  /// Retrieve the overloaded operator kind that corresponds to
3338  /// the given binary opcode.
3339  static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
3340 
3341  /// predicates to categorize the respective opcodes.
3342  bool isPtrMemOp() const { return Opc == BO_PtrMemD || Opc == BO_PtrMemI; }
3343  static bool isMultiplicativeOp(Opcode Opc) {
3344  return Opc >= BO_Mul && Opc <= BO_Rem;
3345  }
3347  static bool isAdditiveOp(Opcode Opc) { return Opc == BO_Add || Opc==BO_Sub; }
3348  bool isAdditiveOp() const { return isAdditiveOp(getOpcode()); }
3349  static bool isShiftOp(Opcode Opc) { return Opc == BO_Shl || Opc == BO_Shr; }
3350  bool isShiftOp() const { return isShiftOp(getOpcode()); }
3351 
3352  static bool isBitwiseOp(Opcode Opc) { return Opc >= BO_And && Opc <= BO_Or; }
3353  bool isBitwiseOp() const { return isBitwiseOp(getOpcode()); }
3354 
3355  static bool isRelationalOp(Opcode Opc) { return Opc >= BO_LT && Opc<=BO_GE; }
3356  bool isRelationalOp() const { return isRelationalOp(getOpcode()); }
3357 
3358  static bool isEqualityOp(Opcode Opc) { return Opc == BO_EQ || Opc == BO_NE; }
3359  bool isEqualityOp() const { return isEqualityOp(getOpcode()); }
3360 
3361  static bool isComparisonOp(Opcode Opc) { return Opc >= BO_Cmp && Opc<=BO_NE; }
3362  bool isComparisonOp() const { return isComparisonOp(getOpcode()); }
3363 
3364  static Opcode negateComparisonOp(Opcode Opc) {
3365  switch (Opc) {
3366  default:
3367  llvm_unreachable("Not a comparison operator.");
3368  case BO_LT: return BO_GE;
3369  case BO_GT: return BO_LE;
3370  case BO_LE: return BO_GT;
3371  case BO_GE: return BO_LT;
3372  case BO_EQ: return BO_NE;
3373  case BO_NE: return BO_EQ;
3374  }
3375  }
3376 
3377  static Opcode reverseComparisonOp(Opcode Opc) {
3378  switch (Opc) {
3379  default:
3380  llvm_unreachable("Not a comparison operator.");
3381  case BO_LT: return BO_GT;
3382  case BO_GT: return BO_LT;
3383  case BO_LE: return BO_GE;
3384  case BO_GE: return BO_LE;
3385  case BO_EQ:
3386  case BO_NE:
3387  return Opc;
3388  }
3389  }
3390 
3391  static bool isLogicalOp(Opcode Opc) { return Opc == BO_LAnd || Opc==BO_LOr; }
3392  bool isLogicalOp() const { return isLogicalOp(getOpcode()); }
3393 
3394  static bool isAssignmentOp(Opcode Opc) {
3395  return Opc >= BO_Assign && Opc <= BO_OrAssign;
3396  }
3397  bool isAssignmentOp() const { return isAssignmentOp(getOpcode()); }
3398 
3399  static bool isCompoundAssignmentOp(Opcode Opc) {
3400  return Opc > BO_Assign && Opc <= BO_OrAssign;
3401  }
3402  bool isCompoundAssignmentOp() const {
3403  return isCompoundAssignmentOp(getOpcode());
3404  }
3405  static Opcode getOpForCompoundAssignment(Opcode Opc) {
3406  assert(isCompoundAssignmentOp(Opc));
3407  if (Opc >= BO_AndAssign)
3408  return Opcode(unsigned(Opc) - BO_AndAssign + BO_And);
3409  else
3410  return Opcode(unsigned(Opc) - BO_MulAssign + BO_Mul);
3411  }
3412 
3413  static bool isShiftAssignOp(Opcode Opc) {
3414  return Opc == BO_ShlAssign || Opc == BO_ShrAssign;
3415  }
3416  bool isShiftAssignOp() const {
3417  return isShiftAssignOp(getOpcode());
3418  }
3419 
3420  // Return true if a binary operator using the specified opcode and operands
3421  // would match the 'p = (i8*)nullptr + n' idiom for casting a pointer-sized
3422  // integer to a pointer.
3423  static bool isNullPointerArithmeticExtension(ASTContext &Ctx, Opcode Opc,
3424  Expr *LHS, Expr *RHS);
3425 
3426  static bool classof(const Stmt *S) {
3427  return S->getStmtClass() >= firstBinaryOperatorConstant &&
3428  S->getStmtClass() <= lastBinaryOperatorConstant;
3429  }
3430 
3431  // Iterators
3433  return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
3434  }
3436  return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
3437  }
3438 
3439  // Set the FP contractability status of this operator. Only meaningful for
3440  // operations on floating point types.
3441  void setFPFeatures(FPOptions F) { FPFeatures = F.getInt(); }
3442 
3443  FPOptions getFPFeatures() const { return FPOptions(FPFeatures); }
3444 
3445  // Get the FP contractability status of this operator. Only meaningful for
3446  // operations on floating point types.
3448  return FPOptions(FPFeatures).allowFPContractWithinStatement();
3449  }
3450 
3451  // Get the FENV_ACCESS status of this operator. Only meaningful for
3452  // operations on floating point types.
3453  bool isFEnvAccessOn() const {
3454  return FPOptions(FPFeatures).allowFEnvAccess();
3455  }
3456 
3457 protected:
3458  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
3460  SourceLocation opLoc, FPOptions FPFeatures, bool dead2)
3461  : Expr(CompoundAssignOperatorClass, ResTy, VK, OK,
3462  lhs->isTypeDependent() || rhs->isTypeDependent(),
3463  lhs->isValueDependent() || rhs->isValueDependent(),
3464  (lhs->isInstantiationDependent() ||
3465  rhs->isInstantiationDependent()),
3466  (lhs->containsUnexpandedParameterPack() ||
3467  rhs->containsUnexpandedParameterPack())),
3468  Opc(opc), FPFeatures(FPFeatures.getInt()), OpLoc(opLoc) {
3469  SubExprs[LHS] = lhs;
3470  SubExprs[RHS] = rhs;
3471  }
3472 
3474  : Expr(SC, Empty), Opc(BO_MulAssign) { }
3475 };
3476 
3477 /// CompoundAssignOperator - For compound assignments (e.g. +=), we keep
3478 /// track of the type the operation is performed in. Due to the semantics of
3479 /// these operators, the operands are promoted, the arithmetic performed, an
3480 /// implicit conversion back to the result type done, then the assignment takes
3481 /// place. This captures the intermediate type which the computation is done
3482 /// in.
3484  QualType ComputationLHSType;
3485  QualType ComputationResultType;
3486 public:
3487  CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResType,
3489  QualType CompLHSType, QualType CompResultType,
3490  SourceLocation OpLoc, FPOptions FPFeatures)
3491  : BinaryOperator(lhs, rhs, opc, ResType, VK, OK, OpLoc, FPFeatures,
3492  true),
3493  ComputationLHSType(CompLHSType),
3494  ComputationResultType(CompResultType) {
3495  assert(isCompoundAssignmentOp() &&
3496  "Only should be used for compound assignments");
3497  }
3498 
3499  /// Build an empty compound assignment operator expression.
3501  : BinaryOperator(CompoundAssignOperatorClass, Empty) { }
3502 
3503  // The two computation types are the type the LHS is converted
3504  // to for the computation and the type of the result; the two are
3505  // distinct in a few cases (specifically, int+=ptr and ptr-=ptr).
3506  QualType getComputationLHSType() const { return ComputationLHSType; }
3507  void setComputationLHSType(QualType T) { ComputationLHSType = T; }
3508 
3509  QualType getComputationResultType() const { return ComputationResultType; }
3510  void setComputationResultType(QualType T) { ComputationResultType = T; }
3511 
3512  static bool classof(const Stmt *S) {
3513  return S->getStmtClass() == CompoundAssignOperatorClass;
3514  }
3515 };
3516 
3517 /// AbstractConditionalOperator - An abstract base class for
3518 /// ConditionalOperator and BinaryConditionalOperator.
3520  SourceLocation QuestionLoc, ColonLoc;
3521  friend class ASTStmtReader;
3522 
3523 protected:
3526  bool TD, bool VD, bool ID,
3527  bool ContainsUnexpandedParameterPack,
3528  SourceLocation qloc,
3529  SourceLocation cloc)
3530  : Expr(SC, T, VK, OK, TD, VD, ID, ContainsUnexpandedParameterPack),
3531  QuestionLoc(qloc), ColonLoc(cloc) {}
3532 
3534  : Expr(SC, Empty) { }
3535 
3536 public:
3537  // getCond - Return the expression representing the condition for
3538  // the ?: operator.
3539  Expr *getCond() const;
3540 
3541  // getTrueExpr - Return the subexpression representing the value of
3542  // the expression if the condition evaluates to true.
3543  Expr *getTrueExpr() const;
3544 
3545  // getFalseExpr - Return the subexpression representing the value of
3546  // the expression if the condition evaluates to false. This is
3547  // the same as getRHS.
3548  Expr *getFalseExpr() const;
3549 
3550  SourceLocation getQuestionLoc() const { return QuestionLoc; }
3552 
3553  static bool classof(const Stmt *T) {
3554  return T->getStmtClass() == ConditionalOperatorClass ||
3555  T->getStmtClass() == BinaryConditionalOperatorClass;
3556  }
3557 };
3558 
3559 /// ConditionalOperator - The ?: ternary operator. The GNU "missing
3560 /// middle" extension is a BinaryConditionalOperator.
3562  enum { COND, LHS, RHS, END_EXPR };
3563  Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
3564 
3565  friend class ASTStmtReader;
3566 public:
3568  SourceLocation CLoc, Expr *rhs,
3570  : AbstractConditionalOperator(ConditionalOperatorClass, t, VK, OK,
3571  // FIXME: the type of the conditional operator doesn't
3572  // depend on the type of the conditional, but the standard
3573  // seems to imply that it could. File a bug!
3574  (lhs->isTypeDependent() || rhs->isTypeDependent()),
3575  (cond->isValueDependent() || lhs->isValueDependent() ||
3576  rhs->isValueDependent()),
3577  (cond->isInstantiationDependent() ||
3578  lhs->isInstantiationDependent() ||
3579  rhs->isInstantiationDependent()),
3580  (cond->containsUnexpandedParameterPack() ||
3581  lhs->containsUnexpandedParameterPack() ||
3582  rhs->containsUnexpandedParameterPack()),
3583  QLoc, CLoc) {
3584  SubExprs[COND] = cond;
3585  SubExprs[LHS] = lhs;
3586  SubExprs[RHS] = rhs;
3587  }
3588 
3589  /// Build an empty conditional operator.
3591  : AbstractConditionalOperator(ConditionalOperatorClass, Empty) { }
3592 
3593  // getCond - Return the expression representing the condition for
3594  // the ?: operator.
3595  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
3596 
3597  // getTrueExpr - Return the subexpression representing the value of
3598  // the expression if the condition evaluates to true.
3599  Expr *getTrueExpr() const { return cast<Expr>(SubExprs[LHS]); }
3600 
3601  // getFalseExpr - Return the subexpression representing the value of
3602  // the expression if the condition evaluates to false. This is
3603  // the same as getRHS.
3604  Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); }
3605 
3606  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
3607  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
3608 
3609  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocStart() const LLVM_READONLY,
3610  "Use getBeginLoc instead") {
3611  return getBeginLoc();
3612  }
3613  SourceLocation getBeginLoc() const LLVM_READONLY {
3614  return getCond()->getBeginLoc();
3615  }
3616  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocEnd() const LLVM_READONLY,
3617  "Use getEndLoc instead") {
3618  return getEndLoc();
3619  }
3620  SourceLocation getEndLoc() const LLVM_READONLY {
3621  return getRHS()->getEndLoc();
3622  }
3623 
3624  static bool classof(const Stmt *T) {
3625  return T->getStmtClass() == ConditionalOperatorClass;
3626  }
3627 
3628  // Iterators
3630  return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
3631  }
3633  return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
3634  }
3635 };
3636 
3637 /// BinaryConditionalOperator - The GNU extension to the conditional
3638 /// operator which allows the middle operand to be omitted.
3639 ///
3640 /// This is a different expression kind on the assumption that almost
3641 /// every client ends up needing to know that these are different.
3643  enum { COMMON, COND, LHS, RHS, NUM_SUBEXPRS };
3644 
3645  /// - the common condition/left-hand-side expression, which will be
3646  /// evaluated as the opaque value
3647  /// - the condition, expressed in terms of the opaque value
3648  /// - the left-hand-side, expressed in terms of the opaque value
3649  /// - the right-hand-side
3650  Stmt *SubExprs[NUM_SUBEXPRS];
3651  OpaqueValueExpr *OpaqueValue;
3652 
3653  friend class ASTStmtReader;
3654 public:
3656  Expr *cond, Expr *lhs, Expr *rhs,
3657  SourceLocation qloc, SourceLocation cloc,
3659  : AbstractConditionalOperator(BinaryConditionalOperatorClass, t, VK, OK,
3660  (common->isTypeDependent() || rhs->isTypeDependent()),
3661  (common->isValueDependent() || rhs->isValueDependent()),
3662  (common->isInstantiationDependent() ||
3663  rhs->isInstantiationDependent()),
3664  (common->containsUnexpandedParameterPack() ||
3665  rhs->containsUnexpandedParameterPack()),
3666  qloc, cloc),
3667  OpaqueValue(opaqueValue) {
3668  SubExprs[COMMON] = common;
3669  SubExprs[COND] = cond;
3670  SubExprs[LHS] = lhs;
3671  SubExprs[RHS] = rhs;
3672  assert(OpaqueValue->getSourceExpr() == common && "Wrong opaque value");
3673  }
3674 
3675  /// Build an empty conditional operator.
3677  : AbstractConditionalOperator(BinaryConditionalOperatorClass, Empty) { }
3678 
3679  /// getCommon - Return the common expression, written to the
3680  /// left of the condition. The opaque value will be bound to the
3681  /// result of this expression.
3682  Expr *getCommon() const { return cast<Expr>(SubExprs[COMMON]); }
3683 
3684  /// getOpaqueValue - Return the opaque value placeholder.
3685  OpaqueValueExpr *getOpaqueValue() const { return OpaqueValue; }
3686 
3687  /// getCond - Return the condition expression; this is defined
3688  /// in terms of the opaque value.
3689  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
3690 
3691  /// getTrueExpr - Return the subexpression which will be
3692  /// evaluated if the condition evaluates to true; this is defined
3693  /// in terms of the opaque value.
3694  Expr *getTrueExpr() const {
3695  return cast<Expr>(SubExprs[LHS]);
3696  }
3697 
3698  /// getFalseExpr - Return the subexpression which will be
3699  /// evaluated if the condnition evaluates to false; this is
3700  /// defined in terms of the opaque value.
3701  Expr *getFalseExpr() const {
3702  return cast<Expr>(SubExprs[RHS]);
3703  }
3704 
3705  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocStart() const LLVM_READONLY,
3706  "Use getBeginLoc instead") {
3707  return getBeginLoc();
3708  }
3709  SourceLocation getBeginLoc() const LLVM_READONLY {
3710  return getCommon()->getBeginLoc();
3711  }
3712  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocEnd() const LLVM_READONLY,
3713  "Use getEndLoc instead") {
3714  return getEndLoc();
3715  }
3716  SourceLocation getEndLoc() const LLVM_READONLY {
3717  return getFalseExpr()->getEndLoc();
3718  }
3719 
3720  static bool classof(const Stmt *T) {
3721  return T->getStmtClass() == BinaryConditionalOperatorClass;
3722  }
3723 
3724  // Iterators
3726  return child_range(SubExprs, SubExprs + NUM_SUBEXPRS);
3727  }
3729  return const_child_range(SubExprs, SubExprs + NUM_SUBEXPRS);
3730  }
3731 };
3732 
3734  if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this))
3735  return co->getCond();
3736  return cast<BinaryConditionalOperator>(this)->getCond();
3737 }
3738 
3740  if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this))
3741  return co->getTrueExpr();
3742  return cast<BinaryConditionalOperator>(this)->getTrueExpr();
3743 }
3744 
3746  if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this))
3747  return co->getFalseExpr();
3748  return cast<BinaryConditionalOperator>(this)->getFalseExpr();
3749 }
3750 
3751 /// AddrLabelExpr - The GNU address of label extension, representing &&label.
3752 class AddrLabelExpr : public Expr {
3753  SourceLocation AmpAmpLoc, LabelLoc;
3754  LabelDecl *Label;
3755 public:
3757  QualType t)
3758  : Expr(AddrLabelExprClass, t, VK_RValue, OK_Ordinary, false, false, false,
3759  false),
3760  AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {}
3761 
3762  /// Build an empty address of a label expression.
3763  explicit AddrLabelExpr(EmptyShell Empty)
3764  : Expr(AddrLabelExprClass, Empty) { }
3765 
3766  SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; }
3767  void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; }
3768  SourceLocation getLabelLoc() const { return LabelLoc; }
3769  void setLabelLoc(SourceLocation L) { LabelLoc = L; }
3770 
3771  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocStart() const LLVM_READONLY,
3772  "Use getBeginLoc instead") {
3773  return getBeginLoc();
3774  }
3775  SourceLocation getBeginLoc() const LLVM_READONLY { return AmpAmpLoc; }
3776  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocEnd() const LLVM_READONLY,
3777  "Use getEndLoc instead") {
3778  return getEndLoc();
3779  }
3780  SourceLocation getEndLoc() const LLVM_READONLY { return LabelLoc; }
3781 
3782  LabelDecl *getLabel() const { return Label; }
3783  void setLabel(LabelDecl *L) { Label = L; }
3784 
3785  static bool classof(const Stmt *T) {
3786  return T->getStmtClass() == AddrLabelExprClass;
3787  }
3788 
3789  // Iterators
3792  }
3795  }
3796 };
3797 
3798 /// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
3799 /// The StmtExpr contains a single CompoundStmt node, which it evaluates and
3800 /// takes the value of the last subexpression.
3801 ///
3802 /// A StmtExpr is always an r-value; values "returned" out of a
3803 /// StmtExpr will be copied.
3804 class StmtExpr : public Expr {
3805  Stmt *SubStmt;
3806  SourceLocation LParenLoc, RParenLoc;
3807 public:
3808  // FIXME: Does type-dependence need to be computed differently?
3809  // FIXME: Do we need to compute instantiation instantiation-dependence for
3810  // statements? (ugh!)
3812  SourceLocation lp, SourceLocation rp) :
3813  Expr(StmtExprClass, T, VK_RValue, OK_Ordinary,
3814  T->isDependentType(), false, false, false),
3815  SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) { }
3816 
3817  /// Build an empty statement expression.
3818  explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { }
3819 
3820  CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); }
3821  const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); }
3822  void setSubStmt(CompoundStmt *S) { SubStmt = S; }
3823 
3824  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocStart() const LLVM_READONLY,
3825  "Use getBeginLoc instead") {
3826  return getBeginLoc();
3827  }
3828  SourceLocation getBeginLoc() const LLVM_READONLY { return LParenLoc; }
3829  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocEnd() const LLVM_READONLY,
3830  "Use getEndLoc instead") {
3831  return getEndLoc();
3832  }
3833  SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
3834 
3835  SourceLocation getLParenLoc() const { return LParenLoc; }
3836  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
3837  SourceLocation getRParenLoc() const { return RParenLoc; }
3838  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
3839 
3840  static bool classof(const Stmt *T) {
3841  return T->getStmtClass() == StmtExprClass;
3842  }
3843 
3844  // Iterators
3845  child_range children() { return child_range(&SubStmt, &SubStmt+1); }
3847  return const_child_range(&SubStmt, &SubStmt + 1);
3848  }
3849 };
3850 
3851 /// ShuffleVectorExpr - clang-specific builtin-in function
3852 /// __builtin_shufflevector.
3853 /// This AST node represents a operator that does a constant
3854 /// shuffle, similar to LLVM's shufflevector instruction. It takes
3855 /// two vectors and a variable number of constant indices,
3856 /// and returns the appropriately shuffled vector.
3857 class ShuffleVectorExpr : public Expr {
3858  SourceLocation BuiltinLoc, RParenLoc;
3859 
3860  // SubExprs - the list of values passed to the __builtin_shufflevector
3861  // function. The first two are vectors, and the rest are constant
3862  // indices. The number of values in this list is always
3863  // 2+the number of indices in the vector type.
3864  Stmt **SubExprs;
3865  unsigned NumExprs;
3866 
3867 public:
3869  SourceLocation BLoc, SourceLocation RP);
3870 
3871  /// Build an empty vector-shuffle expression.
3873  : Expr(ShuffleVectorExprClass, Empty), SubExprs(nullptr) { }
3874 
3875  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
3876  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
3877 
3878  SourceLocation getRParenLoc() const { return RParenLoc; }
3879  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
3880 
3881  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocStart() const LLVM_READONLY,
3882  "Use getBeginLoc instead") {
3883  return getBeginLoc();
3884  }
3885  SourceLocation getBeginLoc() const LLVM_READONLY { return BuiltinLoc; }
3886  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocEnd() const LLVM_READONLY,
3887  "Use getEndLoc instead") {
3888  return getEndLoc();
3889  }
3890  SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
3891 
3892  static bool classof(const Stmt *T) {
3893  return T->getStmtClass() == ShuffleVectorExprClass;
3894  }
3895 
3896  /// getNumSubExprs - Return the size of the SubExprs array. This includes the
3897  /// constant expression, the actual arguments passed in, and the function
3898  /// pointers.
3899  unsigned getNumSubExprs() const { return NumExprs; }
3900 
3901  /// Retrieve the array of expressions.
3902  Expr **getSubExprs() { return reinterpret_cast<Expr **>(SubExprs); }
3903 
3904  /// getExpr - Return the Expr at the specified index.
3905  Expr *getExpr(unsigned Index) {
3906  assert((Index < NumExprs) && "Arg access out of range!");
3907  return cast<Expr>(SubExprs[Index]);
3908  }
3909  const Expr *getExpr(unsigned Index) const {
3910  assert((Index < NumExprs) && "Arg access out of range!");
3911  return cast<Expr>(SubExprs[Index]);
3912  }
3913 
3914  void setExprs(const ASTContext &C, ArrayRef<Expr *> Exprs);
3915 
3916  llvm::APSInt getShuffleMaskIdx(const ASTContext &Ctx, unsigned N) const {
3917  assert((N < NumExprs - 2) && "Shuffle idx out of range!");
3918  return getExpr(N+2)->EvaluateKnownConstInt(Ctx);
3919  }
3920 
3921  // Iterators
3923  return child_range(&SubExprs[0], &SubExprs[0]+NumExprs);
3924  }
3926  return const_child_range(&SubExprs[0], &SubExprs[0] + NumExprs);
3927  }
3928 };
3929 
3930 /// ConvertVectorExpr - Clang builtin function __builtin_convertvector
3931 /// This AST node provides support for converting a vector type to another
3932 /// vector type of the same arity.
3933 class ConvertVectorExpr : public Expr {
3934 private:
3935  Stmt *SrcExpr;
3936  TypeSourceInfo *TInfo;
3937  SourceLocation BuiltinLoc, RParenLoc;
3938 
3939  friend class ASTReader;
3940  friend class ASTStmtReader;
3941  explicit ConvertVectorExpr(EmptyShell Empty) : Expr(ConvertVectorExprClass, Empty) {}
3942 
3943 public:
3946  SourceLocation BuiltinLoc, SourceLocation RParenLoc)
3947  : Expr(ConvertVectorExprClass, DstType, VK, OK,
3948  DstType->isDependentType(),
3949  DstType->isDependentType() || SrcExpr->isValueDependent(),
3950  (DstType->isInstantiationDependentType() ||
3951  SrcExpr->isInstantiationDependent()),
3952  (DstType->containsUnexpandedParameterPack() ||
3953  SrcExpr->containsUnexpandedParameterPack())),
3954  SrcExpr(SrcExpr), TInfo(TI), BuiltinLoc(BuiltinLoc), RParenLoc(RParenLoc) {}
3955 
3956  /// getSrcExpr - Return the Expr to be converted.
3957  Expr *getSrcExpr() const { return cast<Expr>(SrcExpr); }
3958 
3959  /// getTypeSourceInfo - Return the destination type.
3961  return TInfo;
3962  }
3964  TInfo = ti;
3965  }
3966 
3967  /// getBuiltinLoc - Return the location of the __builtin_convertvector token.
3968  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
3969 
3970  /// getRParenLoc - Return the location of final right parenthesis.
3971  SourceLocation getRParenLoc() const { return RParenLoc; }
3972 
3973  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocStart() const LLVM_READONLY,
3974  "Use getBeginLoc instead") {
3975  return getBeginLoc();
3976  }
3977  SourceLocation getBeginLoc() const LLVM_READONLY { return BuiltinLoc; }
3978  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocEnd() const LLVM_READONLY,
3979  "Use getEndLoc instead") {
3980  return getEndLoc();
3981  }
3982  SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
3983 
3984  static bool classof(const Stmt *T) {
3985  return T->getStmtClass() == ConvertVectorExprClass;
3986  }
3987 
3988  // Iterators
3989  child_range children() { return child_range(&SrcExpr, &SrcExpr+1); }
3991  return const_child_range(&SrcExpr, &SrcExpr + 1);
3992  }
3993 };
3994 
3995 /// ChooseExpr - GNU builtin-in function __builtin_choose_expr.
3996 /// This AST node is similar to the conditional operator (?:) in C, with
3997 /// the following exceptions:
3998 /// - the test expression must be a integer constant expression.
3999 /// - the expression returned acts like the chosen subexpression in every
4000 /// visible way: the type is the same as that of the chosen subexpression,
4001 /// and all predicates (whether it's an l-value, whether it's an integer
4002 /// constant expression, etc.) return the same result as for the chosen
4003 /// sub-expression.
4004 class ChooseExpr : public Expr {
4005  enum { COND, LHS, RHS, END_EXPR };
4006  Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
4007  SourceLocation BuiltinLoc, RParenLoc;
4008  bool CondIsTrue;
4009 public:
4010  ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs,
4012  SourceLocation RP, bool condIsTrue,
4013  bool TypeDependent, bool ValueDependent)
4014  : Expr(ChooseExprClass, t, VK, OK, TypeDependent, ValueDependent,
4015  (cond->isInstantiationDependent() ||
4016  lhs->isInstantiationDependent() ||
4017  rhs->isInstantiationDependent()),
4018  (cond->containsUnexpandedParameterPack() ||
4019  lhs->containsUnexpandedParameterPack() ||
4020  rhs->containsUnexpandedParameterPack())),
4021  BuiltinLoc(BLoc), RParenLoc(RP), CondIsTrue(condIsTrue) {
4022  SubExprs[COND] = cond;
4023  SubExprs[LHS] = lhs;
4024  SubExprs[RHS] = rhs;
4025  }
4026 
4027  /// Build an empty __builtin_choose_expr.
4028  explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { }
4029 
4030  /// isConditionTrue - Return whether the condition is true (i.e. not
4031  /// equal to zero).
4032  bool isConditionTrue() const {
4033  assert(!isConditionDependent() &&
4034  "Dependent condition isn't true or false");
4035  return CondIsTrue;
4036  }
4037  void setIsConditionTrue(bool isTrue) { CondIsTrue = isTrue; }
4038 
4039  bool isConditionDependent() const {
4040  return getCond()->isTypeDependent() || getCond()->isValueDependent();
4041  }
4042 
4043  /// getChosenSubExpr - Return the subexpression chosen according to the
4044  /// condition.
4046  return isConditionTrue() ? getLHS() : getRHS();
4047  }
4048 
4049  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
4050  void setCond(Expr *E) { SubExprs[COND] = E; }
4051  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
4052  void setLHS(Expr *E) { SubExprs[LHS] = E; }
4053  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
4054  void setRHS(Expr *E) { SubExprs[RHS] = E; }
4055 
4056  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
4057  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
4058 
4059  SourceLocation getRParenLoc() const { return RParenLoc; }
4060  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
4061 
4062  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocStart() const LLVM_READONLY,
4063  "Use getBeginLoc instead") {
4064  return getBeginLoc();
4065  }
4066  SourceLocation getBeginLoc() const LLVM_READONLY { return BuiltinLoc; }
4067  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocEnd() const LLVM_READONLY,
4068  "Use getEndLoc instead") {
4069  return getEndLoc();
4070  }
4071  SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
4072 
4073  static bool classof(const Stmt *T) {
4074  return T->getStmtClass() == ChooseExprClass;
4075  }
4076 
4077  // Iterators
4079  return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
4080  }
4082  return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
4083  }
4084 };
4085 
4086 /// GNUNullExpr - Implements the GNU __null extension, which is a name
4087 /// for a null pointer constant that has integral type (e.g., int or
4088 /// long) and is the same size and alignment as a pointer. The __null
4089 /// extension is typically only used by system headers, which define
4090 /// NULL as __null in C++ rather than using 0 (which is an integer
4091 /// that may not match the size of a pointer).
4092 class GNUNullExpr : public Expr {
4093  /// TokenLoc - The location of the __null keyword.
4094  SourceLocation TokenLoc;
4095 
4096 public:
4098  : Expr(GNUNullExprClass, Ty, VK_RValue, OK_Ordinary, false, false, false,
4099  false),
4100  TokenLoc(Loc) { }
4101 
4102  /// Build an empty GNU __null expression.
4103  explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { }
4104 
4105  /// getTokenLocation - The location of the __null token.
4106  SourceLocation getTokenLocation() const { return TokenLoc; }
4107  void setTokenLocation(SourceLocation L) { TokenLoc = L; }
4108 
4109  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocStart() const LLVM_READONLY,
4110  "Use getBeginLoc instead") {
4111  return getBeginLoc();
4112  }
4113  SourceLocation getBeginLoc() const LLVM_READONLY { return TokenLoc; }
4114  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocEnd() const LLVM_READONLY,
4115  "Use getEndLoc instead") {
4116  return getEndLoc();
4117  }
4118  SourceLocation getEndLoc() const LLVM_READONLY { return TokenLoc; }
4119 
4120  static bool classof(const Stmt *T) {
4121  return T->getStmtClass() == GNUNullExprClass;
4122  }
4123 
4124  // Iterators
4127  }
4130  }
4131 };
4132 
4133 /// Represents a call to the builtin function \c __builtin_va_arg.
4134 class VAArgExpr : public Expr {
4135  Stmt *Val;
4136  llvm::PointerIntPair<TypeSourceInfo *, 1, bool> TInfo;
4137  SourceLocation BuiltinLoc, RParenLoc;
4138 public:
4140  SourceLocation RPLoc, QualType t, bool IsMS)
4141  : Expr(VAArgExprClass, t, VK_RValue, OK_Ordinary, t->isDependentType(),
4142  false, (TInfo->getType()->isInstantiationDependentType() ||
4143  e->isInstantiationDependent()),
4144  (TInfo->getType()->containsUnexpandedParameterPack() ||
4145  e->containsUnexpandedParameterPack())),
4146  Val(e), TInfo(TInfo, IsMS), BuiltinLoc(BLoc), RParenLoc(RPLoc) {}
4147 
4148  /// Create an empty __builtin_va_arg expression.
4149  explicit VAArgExpr(EmptyShell Empty)
4150  : Expr(VAArgExprClass, Empty), Val(nullptr), TInfo(nullptr, false) {}
4151 
4152  const Expr *getSubExpr() const { return cast<Expr>(Val); }
4153  Expr *getSubExpr() { return cast<Expr>(Val); }
4154  void setSubExpr(Expr *E) { Val = E; }
4155 
4156  /// Returns whether this is really a Win64 ABI va_arg expression.
4157  bool isMicrosoftABI() const { return TInfo.getInt(); }
4158  void setIsMicrosoftABI(bool IsMS) { TInfo.setInt(IsMS); }
4159 
4160  TypeSourceInfo *getWrittenTypeInfo() const { return TInfo.getPointer(); }
4161  void setWrittenTypeInfo(TypeSourceInfo *TI) { TInfo.setPointer(TI); }
4162 
4163  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
4164  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
4165 
4166  SourceLocation getRParenLoc() const { return RParenLoc; }
4167  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
4168 
4169  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocStart() const LLVM_READONLY,
4170  "Use getBeginLoc instead") {
4171  return getBeginLoc();
4172  }
4173  SourceLocation getBeginLoc() const LLVM_READONLY { return BuiltinLoc; }
4174  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocEnd() const LLVM_READONLY,
4175  "Use getEndLoc instead") {
4176  return getEndLoc();
4177  }
4178  SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
4179 
4180  static bool classof(const Stmt *T) {
4181  return T->getStmtClass() == VAArgExprClass;
4182  }
4183 
4184  // Iterators
4185  child_range children() { return child_range(&Val, &Val+1); }
4187  return const_child_range(&Val, &Val + 1);
4188  }
4189 };
4190 
4191 /// Describes an C or C++ initializer list.
4192 ///
4193 /// InitListExpr describes an initializer list, which can be used to
4194 /// initialize objects of different types, including
4195 /// struct/class/union types, arrays, and vectors. For example:
4196 ///
4197 /// @code
4198 /// struct foo x = { 1, { 2, 3 } };
4199 /// @endcode
4200 ///
4201 /// Prior to semantic analysis, an initializer list will represent the
4202 /// initializer list as written by the user, but will have the
4203 /// placeholder type "void". This initializer list is called the
4204 /// syntactic form of the initializer, and may contain C99 designated
4205 /// initializers (represented as DesignatedInitExprs), initializations
4206 /// of subobject members without explicit braces, and so on. Clients
4207 /// interested in the original syntax of the initializer list should
4208 /// use the syntactic form of the initializer list.
4209 ///
4210 /// After semantic analysis, the initializer list will represent the
4211 /// semantic form of the initializer, where the initializations of all
4212 /// subobjects are made explicit with nested InitListExpr nodes and
4213 /// C99 designators have been eliminated by placing the designated
4214 /// initializations into the subobject they initialize. Additionally,
4215 /// any "holes" in the initialization, where no initializer has been
4216 /// specified for a particular subobject, will be replaced with
4217 /// implicitly-generated ImplicitValueInitExpr expressions that
4218 /// value-initialize the subobjects. Note, however, that the
4219 /// initializer lists may still have fewer initializers than there are
4220 /// elements to initialize within the object.
4221 ///
4222 /// After semantic analysis has completed, given an initializer list,
4223 /// method isSemanticForm() returns true if and only if this is the
4224 /// semantic form of the initializer list (note: the same AST node
4225 /// may at the same time be the syntactic form).
4226 /// Given the semantic form of the initializer list, one can retrieve
4227 /// the syntactic form of that initializer list (when different)
4228 /// using method getSyntacticForm(); the method returns null if applied
4229 /// to a initializer list which is already in syntactic form.
4230 /// Similarly, given the syntactic form (i.e., an initializer list such
4231 /// that isSemanticForm() returns false), one can retrieve the semantic
4232 /// form using method getSemanticForm().
4233 /// Since many initializer lists have the same syntactic and semantic forms,
4234 /// getSyntacticForm() may return NULL, indicating that the current
4235 /// semantic initializer list also serves as its syntactic form.
4236 class InitListExpr : public Expr {
4237  // FIXME: Eliminate this vector in favor of ASTContext allocation
4239  InitExprsTy InitExprs;
4240  SourceLocation LBraceLoc, RBraceLoc;
4241 
4242  /// The alternative form of the initializer list (if it exists).
4243  /// The int part of the pair stores whether this initializer list is
4244  /// in semantic form. If not null, the pointer points to:
4245  /// - the syntactic form, if this is in semantic form;
4246  /// - the semantic form, if this is in syntactic form.
4247  llvm::PointerIntPair<InitListExpr *, 1, bool> AltForm;
4248 
4249  /// Either:
4250  /// If this initializer list initializes an array with more elements than
4251  /// there are initializers in the list, specifies an expression to be used
4252  /// for value initialization of the rest of the elements.
4253  /// Or
4254  /// If this initializer list initializes a union, specifies which
4255  /// field within the union will be initialized.
4256  llvm::PointerUnion<Expr *, FieldDecl *> ArrayFillerOrUnionFieldInit;
4257 
4258 public:
4259  InitListExpr(const ASTContext &C, SourceLocation lbraceloc,
4260  ArrayRef<Expr*> initExprs, SourceLocation rbraceloc);
4261 
4262  /// Build an empty initializer list.
4263  explicit InitListExpr(EmptyShell Empty)
4264  : Expr(InitListExprClass, Empty), AltForm(nullptr, true) { }
4265 
4266  unsigned getNumInits() const { return InitExprs.size(); }
4267 
4268  /// Retrieve the set of initializers.
4269  Expr **getInits() { return reinterpret_cast<Expr **>(InitExprs.data()); }
4270 
4271  /// Retrieve the set of initializers.
4272  Expr * const *getInits() const {
4273  return reinterpret_cast<Expr * const *>(InitExprs.data());
4274  }
4275 
4277  return llvm::makeArrayRef(getInits(), getNumInits());
4278  }
4279 
4281  return llvm::makeArrayRef(getInits(), getNumInits());
4282  }
4283 
4284  const Expr *getInit(unsigned Init) const {
4285  assert(Init < getNumInits() && "Initializer access out of range!");
4286  return cast_or_null<Expr>(InitExprs[Init]);
4287  }
4288 
4289  Expr *getInit(unsigned Init) {
4290  assert(Init < getNumInits() && "Initializer access out of range!");
4291  return cast_or_null<Expr>(InitExprs[Init]);
4292  }
4293 
4294  void setInit(unsigned Init, Expr *expr) {
4295  assert(Init < getNumInits() && "Initializer access out of range!");
4296  InitExprs[Init] = expr;
4297 
4298  if (expr) {
4299  ExprBits.TypeDependent |= expr->isTypeDependent();
4300  ExprBits.ValueDependent |= expr->isValueDependent();
4301  ExprBits.InstantiationDependent |= expr->isInstantiationDependent();
4302  ExprBits.ContainsUnexpandedParameterPack |=
4304  }
4305  }
4306 
4307  /// Reserve space for some number of initializers.
4308  void reserveInits(const ASTContext &C, unsigned NumInits);
4309 
4310  /// Specify the number of initializers
4311  ///
4312  /// If there are more than @p NumInits initializers, the remaining
4313  /// initializers will be destroyed. If there are fewer than @p
4314  /// NumInits initializers, NULL expressions will be added for the
4315  /// unknown initializers.
4316  void resizeInits(const ASTContext &Context, unsigned NumInits);
4317 
4318  /// Updates the initializer at index @p Init with the new
4319  /// expression @p expr, and returns the old expression at that
4320  /// location.
4321  ///
4322  /// When @p Init is out of range for this initializer list, the
4323  /// initializer list will be extended with NULL expressions to
4324  /// accommodate the new entry.
4325  Expr *updateInit(const ASTContext &C, unsigned Init, Expr *expr);
4326 
4327  /// If this initializer list initializes an array with more elements
4328  /// than there are initializers in the list, specifies an expression to be
4329  /// used for value initialization of the rest of the elements.
4331  return ArrayFillerOrUnionFieldInit.dyn_cast<Expr *>();
4332  }
4333  const Expr *getArrayFiller() const {
4334  return const_cast<InitListExpr *>(this)->getArrayFiller();
4335  }
4336  void setArrayFiller(Expr *filler);
4337 
4338  /// Return true if this is an array initializer and its array "filler"
4339  /// has been set.
4340  bool hasArrayFiller() const { return getArrayFiller(); }
4341 
4342  /// If this initializes a union, specifies which field in the
4343  /// union to initialize.
4344  ///
4345  /// Typically, this field is the first named field within the
4346  /// union. However, a designated initializer can specify the
4347  /// initialization of a different field within the union.
4349  return ArrayFillerOrUnionFieldInit.dyn_cast<FieldDecl *>();
4350  }
4352  return const_cast<InitListExpr *>(this)->getInitializedFieldInUnion();
4353  }
4355  assert((FD == nullptr
4356  || getInitializedFieldInUnion() == nullptr
4357  || getInitializedFieldInUnion() == FD)
4358  && "Only one field of a union may be initialized at a time!");
4359  ArrayFillerOrUnionFieldInit = FD;
4360  }
4361 
4362  // Explicit InitListExpr's originate from source code (and have valid source
4363  // locations). Implicit InitListExpr's are created by the semantic analyzer.
4364  bool isExplicit() const {
4365  return LBraceLoc.isValid() && RBraceLoc.isValid();
4366  }
4367 
4368  // Is this an initializer for an array of characters, initialized by a string
4369  // literal or an @encode?
4370  bool isStringLiteralInit() const;
4371 
4372  /// Is this a transparent initializer list (that is, an InitListExpr that is
4373  /// purely syntactic, and whose semantics are that of the sole contained
4374  /// initializer)?
4375  bool isTransparent() const;
4376 
4377  /// Is this the zero initializer {0} in a language which considers it
4378  /// idiomatic?
4379  bool isIdiomaticZeroInitializer(const LangOptions &LangOpts) const;
4380 
4381  SourceLocation getLBraceLoc() const { return LBraceLoc; }
4382  void setLBraceLoc(SourceLocation Loc) { LBraceLoc = Loc; }
4383  SourceLocation getRBraceLoc() const { return RBraceLoc; }
4384  void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; }
4385 
4386  bool isSemanticForm() const { return AltForm.getInt(); }
4388  return isSemanticForm() ? nullptr : AltForm.getPointer();
4389  }
4390  bool isSyntacticForm() const {
4391  return !AltForm.getInt() || !AltForm.getPointer();
4392  }
4394  return isSemanticForm() ? AltForm.getPointer() : nullptr;
4395  }
4396 
4398  AltForm.setPointer(Init);
4399  AltForm.setInt(true);
4400  Init->AltForm.setPointer(this);
4401  Init->AltForm.setInt(false);
4402  }
4403 
4405  return InitListExprBits.HadArrayRangeDesignator != 0;
4406  }
4407  void sawArrayRangeDesignator(bool ARD = true) {
4408  InitListExprBits.HadArrayRangeDesignator = ARD;
4409  }
4410 
4411  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocStart() const LLVM_READONLY,
4412  "Use getBeginLoc instead") {
4413  return getBeginLoc();
4414  }
4415  SourceLocation getBeginLoc() const LLVM_READONLY;
4416  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocEnd() const LLVM_READONLY,
4417  "Use getEndLoc instead") {
4418  return getEndLoc();
4419  }
4420  SourceLocation getEndLoc() const LLVM_READONLY;
4421 
4422  static bool classof(const Stmt *T) {
4423  return T->getStmtClass() == InitListExprClass;
4424  }
4425 
4426  // Iterators
4428  const_child_range CCR = const_cast<const InitListExpr *>(this)->children();
4429  return child_range(cast_away_const(CCR.begin()),
4430  cast_away_const(CCR.end()));
4431  }
4432 
4434  // FIXME: This does not include the array filler expression.
4435  if (InitExprs.empty())
4437  return const_child_range(&InitExprs[0], &InitExprs[0] + InitExprs.size());
4438  }
4439 
4444 
4445  iterator begin() { return InitExprs.begin(); }
4446  const_iterator begin() const { return InitExprs.begin(); }
4447  iterator end() { return InitExprs.end(); }
4448  const_iterator end() const { return InitExprs.end(); }
4449  reverse_iterator rbegin() { return InitExprs.rbegin(); }
4450  const_reverse_iterator rbegin() const { return InitExprs.rbegin(); }
4451  reverse_iterator rend() { return InitExprs.rend(); }
4452  const_reverse_iterator rend() const { return InitExprs.rend(); }
4453 
4454  friend class ASTStmtReader;
4455  friend class ASTStmtWriter;
4456 };
4457 
4458 /// Represents a C99 designated initializer expression.
4459 ///
4460 /// A designated initializer expression (C99 6.7.8) contains one or
4461 /// more designators (which can be field designators, array
4462 /// designators, or GNU array-range designators) followed by an
4463 /// expression that initializes the field or element(s) that the
4464 /// designators refer to. For example, given:
4465 ///
4466 /// @code
4467 /// struct point {
4468 /// double x;
4469 /// double y;
4470 /// };
4471 /// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 };
4472 /// @endcode
4473 ///
4474 /// The InitListExpr contains three DesignatedInitExprs, the first of
4475 /// which covers @c [2].y=1.0. This DesignatedInitExpr will have two
4476 /// designators, one array designator for @c [2] followed by one field
4477 /// designator for @c .y. The initialization expression will be 1.0.
4479  : public Expr,
4480  private llvm::TrailingObjects<DesignatedInitExpr, Stmt *> {
4481 public:
4482  /// Forward declaration of the Designator class.
4483  class Designator;
4484 
4485 private:
4486  /// The location of the '=' or ':' prior to the actual initializer
4487  /// expression.
4488  SourceLocation EqualOrColonLoc;
4489 
4490  /// Whether this designated initializer used the GNU deprecated
4491  /// syntax rather than the C99 '=' syntax.
4492  unsigned GNUSyntax : 1;
4493 
4494  /// The number of designators in this initializer expression.
4495  unsigned NumDesignators : 15;
4496 
4497  /// The number of subexpressions of this initializer expression,
4498  /// which contains both the initializer and any additional
4499  /// expressions used by array and array-range designators.
4500  unsigned NumSubExprs : 16;
4501 
4502  /// The designators in this designated initialization
4503  /// expression.
4504  Designator *Designators;
4505 
4506  DesignatedInitExpr(const ASTContext &C, QualType Ty,
4507  llvm::ArrayRef<Designator> Designators,
4508  SourceLocation EqualOrColonLoc, bool GNUSyntax,
4509  ArrayRef<Expr *> IndexExprs, Expr *Init);
4510 
4511  explicit DesignatedInitExpr(unsigned NumSubExprs)
4512  : Expr(DesignatedInitExprClass, EmptyShell()),
4513  NumDesignators(0), NumSubExprs(NumSubExprs), Designators(nullptr) { }
4514 
4515 public:
4516  /// A field designator, e.g., ".x".
4518  /// Refers to the field that is being initialized. The low bit
4519  /// of this field determines whether this is actually a pointer
4520  /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When
4521  /// initially constructed, a field designator will store an
4522  /// IdentifierInfo*. After semantic analysis has resolved that
4523  /// name, the field designator will instead store a FieldDecl*.
4525 
4526  /// The location of the '.' in the designated initializer.
4527  unsigned DotLoc;
4528 
4529  /// The location of the field name in the designated initializer.
4530  unsigned FieldLoc;
4531  };
4532 
4533  /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
4535  /// Location of the first index expression within the designated
4536  /// initializer expression's list of subexpressions.
4537  unsigned Index;
4538  /// The location of the '[' starting the array range designator.
4539  unsigned LBracketLoc;
4540  /// The location of the ellipsis separating the start and end
4541  /// indices. Only valid for GNU array-range designators.
4542  unsigned EllipsisLoc;
4543  /// The location of the ']' terminating the array range designator.
4544  unsigned RBracketLoc;
4545  };
4546 
4547  /// Represents a single C99 designator.
4548  ///
4549  /// @todo This class is infuriatingly similar to clang::Designator,
4550  /// but minor differences (storing indices vs. storing pointers)
4551  /// keep us from reusing it. Try harder, later, to rectify these
4552  /// differences.
4553  class Designator {
4554  /// The kind of designator this describes.
4555  enum {
4557  ArrayDesignator,
4558  ArrayRangeDesignator
4559  } Kind;
4560 
4561  union {
4562  /// A field designator, e.g., ".x".
4564  /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
4565  struct ArrayOrRangeDesignator ArrayOrRange;
4566  };
4567  friend class DesignatedInitExpr;
4568 
4569  public:
4571 
4572  /// Initializes a field designator.
4573  Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc,
4574  SourceLocation FieldLoc)
4575  : Kind(FieldDesignator) {
4576  Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01;
4577  Field.DotLoc = DotLoc.getRawEncoding();
4578  Field.FieldLoc = FieldLoc.getRawEncoding();
4579  }
4580 
4581  /// Initializes an array designator.
4582  Designator(unsigned Index, SourceLocation LBracketLoc,
4583  SourceLocation RBracketLoc)
4584  : Kind(ArrayDesignator) {
4585  ArrayOrRange.Index = Index;
4586  ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
4587  ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding();
4588  ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
4589  }
4590 
4591  /// Initializes a GNU array-range designator.
4592  Designator(unsigned Index, SourceLocation LBracketLoc,
4593  SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
4594  : Kind(ArrayRangeDesignator) {
4595  ArrayOrRange.Index = Index;
4596  ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
4597  ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding();
4598  ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
4599  }
4600 
4601  bool isFieldDesignator() const { return Kind == FieldDesignator; }
4602  bool isArrayDesignator() const { return Kind == ArrayDesignator; }
4603  bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; }
4604 
4605  IdentifierInfo *getFieldName() const;
4606 
4607  FieldDecl *getField() const {
4608  assert(Kind == FieldDesignator && "Only valid on a field designator");
4609  if (Field.NameOrField & 0x01)
4610  return nullptr;
4611  else
4612  return reinterpret_cast<FieldDecl *>(Field.NameOrField);
4613  }
4614 
4615  void setField(FieldDecl *FD) {
4616  assert(Kind == FieldDesignator && "Only valid on a field designator");
4617  Field.NameOrField = reinterpret_cast<uintptr_t>(FD);
4618  }
4619 
4621  assert(Kind == FieldDesignator && "Only valid on a field designator");
4623  }
4624 
4626  assert(Kind == FieldDesignator && "Only valid on a field designator");
4627  return SourceLocation::getFromRawEncoding(Field.FieldLoc);
4628  }
4629 
4631  assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
4632  "Only valid on an array or array-range designator");
4633  return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc);
4634  }
4635 
4637  assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
4638  "Only valid on an array or array-range designator");
4639  return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc);
4640  }
4641 
4643  assert(Kind == ArrayRangeDesignator &&
4644  "Only valid on an array-range designator");
4645  return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc);
4646  }
4647 
4648  unsigned getFirstExprIndex() const {
4649  assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
4650  "Only valid on an array or array-range designator");
4651  return ArrayOrRange.Index;
4652  }
4653 
4654  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocStart() const LLVM_READONLY,
4655  "Use getBeginLoc instead") {
4656  return getBeginLoc();
4657  }
4658  SourceLocation getBeginLoc() const LLVM_READONLY {
4659  if (Kind == FieldDesignator)
4660  return getDotLoc().isInvalid()? getFieldLoc() : getDotLoc();
4661  else
4662  return getLBracketLoc();
4663  }
4664  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocEnd() const LLVM_READONLY,
4665  "Use getEndLoc instead") {
4666  return getEndLoc();
4667  }
4668  SourceLocation getEndLoc() const LLVM_READONLY {
4669  return Kind == FieldDesignator ? getFieldLoc() : getRBracketLoc();
4670  }
4671  SourceRange getSourceRange() const LLVM_READONLY {
4672  return SourceRange(getBeginLoc(), getEndLoc());
4673  }
4674  };
4675 
4676  static DesignatedInitExpr *Create(const ASTContext &C,
4677  llvm::ArrayRef<Designator> Designators,
4678  ArrayRef<Expr*> IndexExprs,
4679  SourceLocation EqualOrColonLoc,
4680  bool GNUSyntax, Expr *Init);
4681 
4682  static DesignatedInitExpr *CreateEmpty(const ASTContext &C,
4683  unsigned NumIndexExprs);
4684 
4685  /// Returns the number of designators in this initializer.
4686  unsigned size() const { return NumDesignators; }
4687 
4688  // Iterator access to the designators.
4690  return {Designators, NumDesignators};
4691  }
4692 
4694  return {Designators, NumDesignators};
4695  }
4696 
4697  Designator *getDesignator(unsigned Idx) { return &designators()[Idx]; }
4698  const Designator *getDesignator(unsigned Idx) const {
4699  return &designators()[Idx];
4700  }
4701 
4702  void setDesignators(const ASTContext &C, const Designator *Desigs,
4703  unsigned NumDesigs);
4704 
4705  Expr *getArrayIndex(const Designator &D) const;
4706  Expr *getArrayRangeStart(const Designator &D) const;
4707  Expr *getArrayRangeEnd(const Designator &D) const;
4708 
4709  /// Retrieve the location of the '=' that precedes the
4710  /// initializer value itself, if present.
4711  SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; }
4712  void setEqualOrColonLoc(SourceLocation L) { EqualOrColonLoc = L; }
4713 
4714  /// Determines whether this designated initializer used the
4715  /// deprecated GNU syntax for designated initializers.
4716  bool usesGNUSyntax() const { return GNUSyntax; }
4717  void setGNUSyntax(bool GNU) { GNUSyntax = GNU; }
4718 
4719  /// Retrieve the initializer value.
4720  Expr *getInit() const {
4721  return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin());
4722  }
4723 
4724  void setInit(Expr *init) {
4725  *child_begin() = init;
4726  }
4727 
4728  /// Retrieve the total number of subexpressions in this
4729  /// designated initializer expression, including the actual
4730  /// initialized value and any expressions that occur within array
4731  /// and array-range designators.
4732  unsigned getNumSubExprs() const { return NumSubExprs; }
4733 
4734  Expr *getSubExpr(unsigned Idx) const {
4735  assert(Idx < NumSubExprs && "Subscript out of range");
4736  return cast<Expr>(getTrailingObjects<Stmt *>()[Idx]);
4737  }
4738 
4739  void setSubExpr(unsigned Idx, Expr *E) {
4740  assert(Idx < NumSubExprs && "Subscript out of range");
4741  getTrailingObjects<Stmt *>()[Idx] = E;
4742  }
4743 
4744  /// Replaces the designator at index @p Idx with the series
4745  /// of designators in [First, Last).
4746  void ExpandDesignator(const ASTContext &C, unsigned Idx,
4747  const Designator *First, const Designator *Last);
4748 
4749  SourceRange getDesignatorsSourceRange() const;
4750 
4751  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocStart() const LLVM_READONLY,
4752  "Use getBeginLoc instead") {
4753  return getBeginLoc();
4754  }
4755  SourceLocation getBeginLoc() const LLVM_READONLY;
4756  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocEnd() const LLVM_READONLY,
4757  "Use getEndLoc instead") {
4758  return getEndLoc();
4759  }
4760  SourceLocation getEndLoc() const LLVM_READONLY;
4761 
4762  static bool classof(const Stmt *T) {
4763  return T->getStmtClass() == DesignatedInitExprClass;
4764  }
4765 
4766  // Iterators
4768  Stmt **begin = getTrailingObjects<Stmt *>();
4769  return child_range(begin, begin + NumSubExprs);
4770  }
4772  Stmt * const *begin = getTrailingObjects<Stmt *>();
4773  return const_child_range(begin, begin + NumSubExprs);
4774  }
4775 
4777 };
4778 
4779 /// Represents a place-holder for an object not to be initialized by
4780 /// anything.
4781 ///
4782 /// This only makes sense when it appears as part of an updater of a
4783 /// DesignatedInitUpdateExpr (see below). The base expression of a DIUE
4784 /// initializes a big object, and the NoInitExpr's mark the spots within the
4785 /// big object not to be overwritten by the updater.
4786 ///
4787 /// \see DesignatedInitUpdateExpr
4788 class NoInitExpr : public Expr {
4789 public:
4790  explicit NoInitExpr(QualType ty)
4791  : Expr(NoInitExprClass, ty, VK_RValue, OK_Ordinary,
4792  false, false, ty->isInstantiationDependentType(), false) { }
4793 
4794  explicit NoInitExpr(EmptyShell Empty)
4795  : Expr(NoInitExprClass, Empty) { }
4796 
4797  static bool classof(const Stmt *T) {
4798  return T->getStmtClass() == NoInitExprClass;
4799  }
4800 
4801  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocStart() const LLVM_READONLY,
4802  "Use getBeginLoc instead") {
4803  return getBeginLoc();
4804  }
4805  SourceLocation getBeginLoc() const LLVM_READONLY { return SourceLocation(); }
4806  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocEnd() const LLVM_READONLY,
4807  "Use getEndLoc instead") {
4808  return getEndLoc();
4809  }
4810  SourceLocation getEndLoc() const LLVM_READONLY { return SourceLocation(); }
4811 
4812  // Iterators
4815  }
4818  }
4819 };
4820 
4821 // In cases like:
4822 // struct Q { int a, b, c; };
4823 // Q *getQ();
4824 // void foo() {
4825 // struct A { Q q; } a = { *getQ(), .q.b = 3 };
4826 // }
4827 //
4828 // We will have an InitListExpr for a, with type A, and then a
4829 // DesignatedInitUpdateExpr for "a.q" with type Q. The "base" for this DIUE
4830 // is the call expression *getQ(); the "updater" for the DIUE is ".q.b = 3"
4831 //
4833  // BaseAndUpdaterExprs[0] is the base expression;
4834  // BaseAndUpdaterExprs[1] is an InitListExpr overwriting part of the base.
4835  Stmt *BaseAndUpdaterExprs[2];
4836 
4837 public:
4839  Expr *baseExprs, SourceLocation rBraceLoc);
4840 
4842  : Expr(DesignatedInitUpdateExprClass, Empty) { }
4843 
4844  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocStart() const LLVM_READONLY,
4845  "Use getBeginLoc instead") {
4846  return getBeginLoc();
4847  }
4848  SourceLocation getBeginLoc() const LLVM_READONLY;
4849  LLVM_ATTRIBUTE_DEPRECATED(SourceLocation getLocEnd() const LLVM_READONLY,
4850  "Use getEndLoc instead") {
4851  return getEndLoc();
4852  }
4853  SourceLocation getEndLoc() const LLVM_READONLY;
4854 
4855  static bool classof(const Stmt *T) {
4856  return T->getStmtClass() == DesignatedInitUpdateExprClass;
4857  }
4858 
4859  Expr *getBase() const { return cast<Expr>(BaseAndUpdaterExprs[0]); }
4860  void setBase(Expr *Base) { BaseAndUpdaterExprs[0] = Base; }
4861