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