]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/clang/AST/Expr.h
Vendor import of clang trunk r351319 (just before the release_80 branch
[FreeBSD/FreeBSD.git] / include / clang / AST / Expr.h
1 //===--- Expr.h - Classes for representing expressions ----------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 //  This file defines the Expr interface and subclasses.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_CLANG_AST_EXPR_H
15 #define LLVM_CLANG_AST_EXPR_H
16
17 #include "clang/AST/APValue.h"
18 #include "clang/AST/ASTVector.h"
19 #include "clang/AST/Decl.h"
20 #include "clang/AST/DeclAccessPair.h"
21 #include "clang/AST/OperationKinds.h"
22 #include "clang/AST/Stmt.h"
23 #include "clang/AST/TemplateBase.h"
24 #include "clang/AST/Type.h"
25 #include "clang/Basic/CharInfo.h"
26 #include "clang/Basic/LangOptions.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.
57 typedef SmallVector<CXXBaseSpecifier*, 4> CXXCastPath;
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.
61 struct SubobjectAdjustment {
62   enum {
63     DerivedToBaseAdjustment,
64     FieldAdjustment,
65     MemberPointerAdjustment
66   } Kind;
67
68   struct DTB {
69     const CastExpr *BasePath;
70     const CXXRecordDecl *DerivedClass;
71   };
72
73   struct P {
74     const MemberPointerType *MPT;
75     Expr *RHS;
76   };
77
78   union {
79     struct DTB DerivedToBase;
80     FieldDecl *Field;
81     struct P Ptr;
82   };
83
84   SubobjectAdjustment(const CastExpr *BasePath,
85                       const CXXRecordDecl *DerivedClass)
86     : Kind(DerivedToBaseAdjustment) {
87     DerivedToBase.BasePath = BasePath;
88     DerivedToBase.DerivedClass = DerivedClass;
89   }
90
91   SubobjectAdjustment(FieldDecl *Field)
92     : Kind(FieldAdjustment) {
93     this->Field = Field;
94   }
95
96   SubobjectAdjustment(const MemberPointerType *MPT, Expr *RHS)
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:
110   Expr(StmtClass SC, QualType T, ExprValueKind VK, ExprObjectKind OK,
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   ///
191   bool isInstantiationDependent() const {
192     return ExprBits.InstantiationDependent;
193   }
194
195   /// Set whether this expression is instantiation-dependent or not.
196   void setInstantiationDependent(bool ID) {
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.
214   bool containsUnexpandedParameterPack() const {
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
254   enum LValueClassification {
255     LV_Valid,
256     LV_NotObjectType,
257     LV_IncompleteVoidType,
258     LV_DuplicateVectorComponents,
259     LV_InvalidExpression,
260     LV_InvalidMessageExpression,
261     LV_MemberFunction,
262     LV_SubObjCPropertySetting,
263     LV_ClassTemporary,
264     LV_ArrayTemporary
265   };
266   /// Reasons why an expression might not be an l-value.
267   LValueClassification ClassifyLValue(ASTContext &Ctx) const;
268
269   enum isModifiableLvalueResult {
270     MLV_Valid,
271     MLV_NotObjectType,
272     MLV_IncompleteVoidType,
273     MLV_DuplicateVectorComponents,
274     MLV_InvalidExpression,
275     MLV_LValueCast,           // Specialized form of MLV_InvalidExpression.
276     MLV_IncompleteType,
277     MLV_ConstQualified,
278     MLV_ConstQualifiedField,
279     MLV_ConstAddrSpace,
280     MLV_ArrayType,
281     MLV_NoSetterProperty,
282     MLV_MemberFunction,
283     MLV_SubObjCPropertySetting,
284     MLV_InvalidMessageExpression,
285     MLV_ClassTemporary,
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.
297   isModifiableLvalueResult
298   isModifiableLvalue(ASTContext &Ctx, SourceLocation *Loc = nullptr) const;
299
300   /// The return type of classify(). Represents the C++11 expression
301   ///        taxonomy.
302   class Classification {
303   public:
304     /// The various classification results. Most of these mean prvalue.
305     enum Kinds {
306       CL_LValue,
307       CL_XValue,
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
313       CL_SubObjCPropertySetting,
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.
320     enum ModifiableType {
321       CM_Untested, // testModifiable was false.
322       CM_Modifiable,
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
327       CM_ConstQualified,
328       CM_ConstQualifiedField,
329       CM_ConstAddrSpace,
330       CM_ArrayType,
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:
345     Classification() {}
346
347     Kinds getKind() const { return static_cast<Kinds>(Kind); }
348     ModifiableType getModifiable() const {
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
360     static Classification makeSimpleLValue() {
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.
377   Classification Classify(ASTContext &Ctx) const {
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.
389   Classification ClassifyModifiable(ASTContext &Ctx, SourceLocation &Loc) const{
390     return ClassifyImpl(Ctx, &Loc);
391   }
392
393   /// getValueKindForType - Given a formal return or parameter type,
394   /// give its value kind.
395   static ExprValueKind getValueKindForType(QualType T) {
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.
405   ExprValueKind getValueKind() const {
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.
412   ExprObjectKind getObjectKind() const {
413     return static_cast<ExprObjectKind>(ExprBits.ObjectKind);
414   }
415
416   bool isOrdinaryOrBitFieldObject() const {
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();
453   const Decl *getReferencedDeclOfCallee() const {
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.
477   bool hasPlaceholderType(BuiltinType::Kind K) const {
478     assert(BuiltinType::isPlaceholderTypeKind(K));
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,
520                                       SmallVectorImpl<
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,
530                                                  SmallVectorImpl<
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.
544     bool HasSideEffects;
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.
549     bool HasUndefinedBehavior;
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.
558     SmallVectorImpl<PartialDiagnosticAt> *Diag;
559
560     EvalStatus()
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.
571   struct EvalResult : EvalStatus {
572     /// Val - This is the value the expression can be folded to.
573     APValue Val;
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
595   enum SideEffectsKind {
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   /// isEvaluatable - Call EvaluateAsRValue to see if this expression can be
615   /// constant folded without side-effects, but discard the result.
616   bool isEvaluatable(const ASTContext &Ctx,
617                      SideEffectsKind AllowSideEffects = SE_NoSideEffects) const;
618
619   /// HasSideEffects - This routine returns true for all those expressions
620   /// which have any effect other than producing a value. Example is a function
621   /// call, volatile variable read, or throwing an exception. If
622   /// IncludePossibleEffects is false, this call treats certain expressions with
623   /// potential side effects (such as function call-like expressions,
624   /// instantiation-dependent expressions, or invocations from a macro) as not
625   /// having side effects.
626   bool HasSideEffects(const ASTContext &Ctx,
627                       bool IncludePossibleEffects = true) const;
628
629   /// Determine whether this expression involves a call to any function
630   /// that is not trivial.
631   bool hasNonTrivialCall(const ASTContext &Ctx) const;
632
633   /// EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded
634   /// integer. This must be called on an expression that constant folds to an
635   /// integer.
636   llvm::APSInt EvaluateKnownConstInt(
637       const ASTContext &Ctx,
638       SmallVectorImpl<PartialDiagnosticAt> *Diag = nullptr) const;
639
640   llvm::APSInt EvaluateKnownConstIntCheckOverflow(
641       const ASTContext &Ctx,
642       SmallVectorImpl<PartialDiagnosticAt> *Diag = nullptr) const;
643
644   void EvaluateForOverflow(const ASTContext &Ctx) const;
645
646   /// EvaluateAsLValue - Evaluate an expression to see if we can fold it to an
647   /// lvalue with link time known address, with no side-effects.
648   bool EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx) const;
649
650   /// EvaluateAsInitializer - Evaluate an expression as if it were the
651   /// initializer of the given declaration. Returns true if the initializer
652   /// can be folded to a constant, and produces any relevant notes. In C++11,
653   /// notes will be produced if the expression is not a constant expression.
654   bool EvaluateAsInitializer(APValue &Result, const ASTContext &Ctx,
655                              const VarDecl *VD,
656                              SmallVectorImpl<PartialDiagnosticAt> &Notes) const;
657
658   /// EvaluateWithSubstitution - Evaluate an expression as if from the context
659   /// of a call to the given function with the given arguments, inside an
660   /// unevaluated context. Returns true if the expression could be folded to a
661   /// constant.
662   bool EvaluateWithSubstitution(APValue &Value, ASTContext &Ctx,
663                                 const FunctionDecl *Callee,
664                                 ArrayRef<const Expr*> Args,
665                                 const Expr *This = nullptr) const;
666
667   /// Indicates how the constant expression will be used.
668   enum ConstExprUsage { EvaluateForCodeGen, EvaluateForMangling };
669
670   /// Evaluate an expression that is required to be a constant expression.
671   bool EvaluateAsConstantExpr(EvalResult &Result, ConstExprUsage Usage,
672                               const ASTContext &Ctx) const;
673
674   /// If the current Expr is a pointer, this will try to statically
675   /// determine the number of bytes available where the pointer is pointing.
676   /// Returns true if all of the above holds and we were able to figure out the
677   /// size, false otherwise.
678   ///
679   /// \param Type - How to evaluate the size of the Expr, as defined by the
680   /// "type" parameter of __builtin_object_size
681   bool tryEvaluateObjectSize(uint64_t &Result, ASTContext &Ctx,
682                              unsigned Type) const;
683
684   /// Enumeration used to describe the kind of Null pointer constant
685   /// returned from \c isNullPointerConstant().
686   enum NullPointerConstantKind {
687     /// Expression is not a Null pointer constant.
688     NPCK_NotNull = 0,
689
690     /// Expression is a Null pointer constant built from a zero integer
691     /// expression that is not a simple, possibly parenthesized, zero literal.
692     /// C++ Core Issue 903 will classify these expressions as "not pointers"
693     /// once it is adopted.
694     /// http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#903
695     NPCK_ZeroExpression,
696
697     /// Expression is a Null pointer constant built from a literal zero.
698     NPCK_ZeroLiteral,
699
700     /// Expression is a C++11 nullptr.
701     NPCK_CXX11_nullptr,
702
703     /// Expression is a GNU-style __null constant.
704     NPCK_GNUNull
705   };
706
707   /// Enumeration used to describe how \c isNullPointerConstant()
708   /// should cope with value-dependent expressions.
709   enum NullPointerConstantValueDependence {
710     /// Specifies that the expression should never be value-dependent.
711     NPC_NeverValueDependent = 0,
712
713     /// Specifies that a value-dependent expression of integral or
714     /// dependent type should be considered a null pointer constant.
715     NPC_ValueDependentIsNull,
716
717     /// Specifies that a value-dependent expression should be considered
718     /// to never be a null pointer constant.
719     NPC_ValueDependentIsNotNull
720   };
721
722   /// isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to
723   /// a Null pointer constant. The return value can further distinguish the
724   /// kind of NULL pointer constant that was detected.
725   NullPointerConstantKind isNullPointerConstant(
726       ASTContext &Ctx,
727       NullPointerConstantValueDependence NPC) const;
728
729   /// isOBJCGCCandidate - Return true if this expression may be used in a read/
730   /// write barrier.
731   bool isOBJCGCCandidate(ASTContext &Ctx) const;
732
733   /// Returns true if this expression is a bound member function.
734   bool isBoundMemberFunction(ASTContext &Ctx) const;
735
736   /// Given an expression of bound-member type, find the type
737   /// of the member.  Returns null if this is an *overloaded* bound
738   /// member expression.
739   static QualType findBoundMemberType(const Expr *expr);
740
741   /// IgnoreImpCasts - Skip past any implicit casts which might
742   /// surround this expression.  Only skips ImplicitCastExprs.
743   Expr *IgnoreImpCasts() LLVM_READONLY;
744
745   /// IgnoreImplicit - Skip past any implicit AST nodes which might
746   /// surround this expression.
747   Expr *IgnoreImplicit() LLVM_READONLY {
748     return cast<Expr>(Stmt::IgnoreImplicit());
749   }
750
751   const Expr *IgnoreImplicit() const LLVM_READONLY {
752     return const_cast<Expr*>(this)->IgnoreImplicit();
753   }
754
755   /// IgnoreParens - Ignore parentheses.  If this Expr is a ParenExpr, return
756   ///  its subexpression.  If that subexpression is also a ParenExpr,
757   ///  then this method recursively returns its subexpression, and so forth.
758   ///  Otherwise, the method returns the current Expr.
759   Expr *IgnoreParens() LLVM_READONLY;
760
761   /// IgnoreParenCasts - Ignore parentheses and casts.  Strip off any ParenExpr
762   /// or CastExprs, returning their operand.
763   Expr *IgnoreParenCasts() LLVM_READONLY;
764
765   /// Ignore casts.  Strip off any CastExprs, returning their operand.
766   Expr *IgnoreCasts() LLVM_READONLY;
767
768   /// IgnoreParenImpCasts - Ignore parentheses and implicit casts.  Strip off
769   /// any ParenExpr or ImplicitCastExprs, returning their operand.
770   Expr *IgnoreParenImpCasts() LLVM_READONLY;
771
772   /// IgnoreConversionOperator - Ignore conversion operator. If this Expr is a
773   /// call to a conversion operator, return the argument.
774   Expr *IgnoreConversionOperator() LLVM_READONLY;
775
776   const Expr *IgnoreConversionOperator() const LLVM_READONLY {
777     return const_cast<Expr*>(this)->IgnoreConversionOperator();
778   }
779
780   const Expr *IgnoreParenImpCasts() const LLVM_READONLY {
781     return const_cast<Expr*>(this)->IgnoreParenImpCasts();
782   }
783
784   /// Ignore parentheses and lvalue casts.  Strip off any ParenExpr and
785   /// CastExprs that represent lvalue casts, returning their operand.
786   Expr *IgnoreParenLValueCasts() LLVM_READONLY;
787
788   const Expr *IgnoreParenLValueCasts() const LLVM_READONLY {
789     return const_cast<Expr*>(this)->IgnoreParenLValueCasts();
790   }
791
792   /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the
793   /// value (including ptr->int casts of the same size).  Strip off any
794   /// ParenExpr or CastExprs, returning their operand.
795   Expr *IgnoreParenNoopCasts(ASTContext &Ctx) LLVM_READONLY;
796
797   /// Ignore parentheses and derived-to-base casts.
798   Expr *ignoreParenBaseCasts() LLVM_READONLY;
799
800   const Expr *ignoreParenBaseCasts() const LLVM_READONLY {
801     return const_cast<Expr*>(this)->ignoreParenBaseCasts();
802   }
803
804   /// Determine whether this expression is a default function argument.
805   ///
806   /// Default arguments are implicitly generated in the abstract syntax tree
807   /// by semantic analysis for function calls, object constructions, etc. in
808   /// C++. Default arguments are represented by \c CXXDefaultArgExpr nodes;
809   /// this routine also looks through any implicit casts to determine whether
810   /// the expression is a default argument.
811   bool isDefaultArgument() const;
812
813   /// Determine whether the result of this expression is a
814   /// temporary object of the given class type.
815   bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const;
816
817   /// Whether this expression is an implicit reference to 'this' in C++.
818   bool isImplicitCXXThis() const;
819
820   const Expr *IgnoreImpCasts() const LLVM_READONLY {
821     return const_cast<Expr*>(this)->IgnoreImpCasts();
822   }
823   const Expr *IgnoreParens() const LLVM_READONLY {
824     return const_cast<Expr*>(this)->IgnoreParens();
825   }
826   const Expr *IgnoreParenCasts() const LLVM_READONLY {
827     return const_cast<Expr*>(this)->IgnoreParenCasts();
828   }
829   /// Strip off casts, but keep parentheses.
830   const Expr *IgnoreCasts() const LLVM_READONLY {
831     return const_cast<Expr*>(this)->IgnoreCasts();
832   }
833
834   const Expr *IgnoreParenNoopCasts(ASTContext &Ctx) const LLVM_READONLY {
835     return const_cast<Expr*>(this)->IgnoreParenNoopCasts(Ctx);
836   }
837
838   static bool hasAnyTypeDependentArguments(ArrayRef<Expr *> Exprs);
839
840   /// For an expression of class type or pointer to class type,
841   /// return the most derived class decl the expression is known to refer to.
842   ///
843   /// If this expression is a cast, this method looks through it to find the
844   /// most derived decl that can be inferred from the expression.
845   /// This is valid because derived-to-base conversions have undefined
846   /// behavior if the object isn't dynamically of the derived type.
847   const CXXRecordDecl *getBestDynamicClassType() const;
848
849   /// Get the inner expression that determines the best dynamic class.
850   /// If this is a prvalue, we guarantee that it is of the most-derived type
851   /// for the object itself.
852   const Expr *getBestDynamicClassTypeExpr() const;
853
854   /// Walk outwards from an expression we want to bind a reference to and
855   /// find the expression whose lifetime needs to be extended. Record
856   /// the LHSs of comma expressions and adjustments needed along the path.
857   const Expr *skipRValueSubobjectAdjustments(
858       SmallVectorImpl<const Expr *> &CommaLHS,
859       SmallVectorImpl<SubobjectAdjustment> &Adjustments) const;
860   const Expr *skipRValueSubobjectAdjustments() const {
861     SmallVector<const Expr *, 8> CommaLHSs;
862     SmallVector<SubobjectAdjustment, 8> Adjustments;
863     return skipRValueSubobjectAdjustments(CommaLHSs, Adjustments);
864   }
865
866   static bool classof(const Stmt *T) {
867     return T->getStmtClass() >= firstExprConstant &&
868            T->getStmtClass() <= lastExprConstant;
869   }
870 };
871
872 //===----------------------------------------------------------------------===//
873 // Wrapper Expressions.
874 //===----------------------------------------------------------------------===//
875
876 /// FullExpr - Represents a "full-expression" node.
877 class FullExpr : public Expr {
878 protected:
879  Stmt *SubExpr;
880
881  FullExpr(StmtClass SC, Expr *subexpr)
882     : Expr(SC, subexpr->getType(),
883            subexpr->getValueKind(), subexpr->getObjectKind(),
884            subexpr->isTypeDependent(), subexpr->isValueDependent(),
885            subexpr->isInstantiationDependent(),
886            subexpr->containsUnexpandedParameterPack()), SubExpr(subexpr) {}
887   FullExpr(StmtClass SC, EmptyShell Empty)
888     : Expr(SC, Empty) {}
889 public:
890   const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
891   Expr *getSubExpr() { return cast<Expr>(SubExpr); }
892
893   /// As with any mutator of the AST, be very careful when modifying an
894   /// existing AST to preserve its invariants.
895   void setSubExpr(Expr *E) { SubExpr = E; }
896
897   static bool classof(const Stmt *T) {
898     return T->getStmtClass() >= firstFullExprConstant &&
899            T->getStmtClass() <= lastFullExprConstant;
900   }
901 };
902
903 /// ConstantExpr - An expression that occurs in a constant context.
904 class ConstantExpr : public FullExpr {
905   ConstantExpr(Expr *subexpr)
906     : FullExpr(ConstantExprClass, subexpr) {}
907
908 public:
909   static ConstantExpr *Create(const ASTContext &Context, Expr *E) {
910     assert(!isa<ConstantExpr>(E));
911     return new (Context) ConstantExpr(E);
912   }
913
914   /// Build an empty constant expression wrapper.
915   explicit ConstantExpr(EmptyShell Empty)
916     : FullExpr(ConstantExprClass, Empty) {}
917
918   SourceLocation getBeginLoc() const LLVM_READONLY {
919     return SubExpr->getBeginLoc();
920   }
921   SourceLocation getEndLoc() const LLVM_READONLY {
922     return SubExpr->getEndLoc();
923   }
924
925   static bool classof(const Stmt *T) {
926     return T->getStmtClass() == ConstantExprClass;
927   }
928
929   // Iterators
930   child_range children() { return child_range(&SubExpr, &SubExpr+1); }
931   const_child_range children() const {
932     return const_child_range(&SubExpr, &SubExpr + 1);
933   }
934 };
935
936 //===----------------------------------------------------------------------===//
937 // Primary Expressions.
938 //===----------------------------------------------------------------------===//
939
940 /// OpaqueValueExpr - An expression referring to an opaque object of a
941 /// fixed type and value class.  These don't correspond to concrete
942 /// syntax; instead they're used to express operations (usually copy
943 /// operations) on values whose source is generally obvious from
944 /// context.
945 class OpaqueValueExpr : public Expr {
946   friend class ASTStmtReader;
947   Expr *SourceExpr;
948
949 public:
950   OpaqueValueExpr(SourceLocation Loc, QualType T, ExprValueKind VK,
951                   ExprObjectKind OK = OK_Ordinary,
952                   Expr *SourceExpr = nullptr)
953     : Expr(OpaqueValueExprClass, T, VK, OK,
954            T->isDependentType() ||
955            (SourceExpr && SourceExpr->isTypeDependent()),
956            T->isDependentType() ||
957            (SourceExpr && SourceExpr->isValueDependent()),
958            T->isInstantiationDependentType() ||
959            (SourceExpr && SourceExpr->isInstantiationDependent()),
960            false),
961       SourceExpr(SourceExpr) {
962     setIsUnique(false);
963     OpaqueValueExprBits.Loc = Loc;
964   }
965
966   /// Given an expression which invokes a copy constructor --- i.e.  a
967   /// CXXConstructExpr, possibly wrapped in an ExprWithCleanups ---
968   /// find the OpaqueValueExpr that's the source of the construction.
969   static const OpaqueValueExpr *findInCopyConstruct(const Expr *expr);
970
971   explicit OpaqueValueExpr(EmptyShell Empty)
972     : Expr(OpaqueValueExprClass, Empty) {}
973
974   /// Retrieve the location of this expression.
975   SourceLocation getLocation() const { return OpaqueValueExprBits.Loc; }
976
977   SourceLocation getBeginLoc() const LLVM_READONLY {
978     return SourceExpr ? SourceExpr->getBeginLoc() : getLocation();
979   }
980   SourceLocation getEndLoc() const LLVM_READONLY {
981     return SourceExpr ? SourceExpr->getEndLoc() : getLocation();
982   }
983   SourceLocation getExprLoc() const LLVM_READONLY {
984     return SourceExpr ? SourceExpr->getExprLoc() : getLocation();
985   }
986
987   child_range children() {
988     return child_range(child_iterator(), child_iterator());
989   }
990
991   const_child_range children() const {
992     return const_child_range(const_child_iterator(), const_child_iterator());
993   }
994
995   /// The source expression of an opaque value expression is the
996   /// expression which originally generated the value.  This is
997   /// provided as a convenience for analyses that don't wish to
998   /// precisely model the execution behavior of the program.
999   ///
1000   /// The source expression is typically set when building the
1001   /// expression which binds the opaque value expression in the first
1002   /// place.
1003   Expr *getSourceExpr() const { return SourceExpr; }
1004
1005   void setIsUnique(bool V) {
1006     assert((!V || SourceExpr) &&
1007            "unique OVEs are expected to have source expressions");
1008     OpaqueValueExprBits.IsUnique = V;
1009   }
1010
1011   bool isUnique() const { return OpaqueValueExprBits.IsUnique; }
1012
1013   static bool classof(const Stmt *T) {
1014     return T->getStmtClass() == OpaqueValueExprClass;
1015   }
1016 };
1017
1018 /// A reference to a declared variable, function, enum, etc.
1019 /// [C99 6.5.1p2]
1020 ///
1021 /// This encodes all the information about how a declaration is referenced
1022 /// within an expression.
1023 ///
1024 /// There are several optional constructs attached to DeclRefExprs only when
1025 /// they apply in order to conserve memory. These are laid out past the end of
1026 /// the object, and flags in the DeclRefExprBitfield track whether they exist:
1027 ///
1028 ///   DeclRefExprBits.HasQualifier:
1029 ///       Specifies when this declaration reference expression has a C++
1030 ///       nested-name-specifier.
1031 ///   DeclRefExprBits.HasFoundDecl:
1032 ///       Specifies when this declaration reference expression has a record of
1033 ///       a NamedDecl (different from the referenced ValueDecl) which was found
1034 ///       during name lookup and/or overload resolution.
1035 ///   DeclRefExprBits.HasTemplateKWAndArgsInfo:
1036 ///       Specifies when this declaration reference expression has an explicit
1037 ///       C++ template keyword and/or template argument list.
1038 ///   DeclRefExprBits.RefersToEnclosingVariableOrCapture
1039 ///       Specifies when this declaration reference expression (validly)
1040 ///       refers to an enclosed local or a captured variable.
1041 class DeclRefExpr final
1042     : public Expr,
1043       private llvm::TrailingObjects<DeclRefExpr, NestedNameSpecifierLoc,
1044                                     NamedDecl *, ASTTemplateKWAndArgsInfo,
1045                                     TemplateArgumentLoc> {
1046   friend class ASTStmtReader;
1047   friend class ASTStmtWriter;
1048   friend TrailingObjects;
1049
1050   /// The declaration that we are referencing.
1051   ValueDecl *D;
1052
1053   /// Provides source/type location info for the declaration name
1054   /// embedded in D.
1055   DeclarationNameLoc DNLoc;
1056
1057   size_t numTrailingObjects(OverloadToken<NestedNameSpecifierLoc>) const {
1058     return hasQualifier();
1059   }
1060
1061   size_t numTrailingObjects(OverloadToken<NamedDecl *>) const {
1062     return hasFoundDecl();
1063   }
1064
1065   size_t numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
1066     return hasTemplateKWAndArgsInfo();
1067   }
1068
1069   /// Test whether there is a distinct FoundDecl attached to the end of
1070   /// this DRE.
1071   bool hasFoundDecl() const { return DeclRefExprBits.HasFoundDecl; }
1072
1073   DeclRefExpr(const ASTContext &Ctx, NestedNameSpecifierLoc QualifierLoc,
1074               SourceLocation TemplateKWLoc, ValueDecl *D,
1075               bool RefersToEnlosingVariableOrCapture,
1076               const DeclarationNameInfo &NameInfo, NamedDecl *FoundD,
1077               const TemplateArgumentListInfo *TemplateArgs, QualType T,
1078               ExprValueKind VK);
1079
1080   /// Construct an empty declaration reference expression.
1081   explicit DeclRefExpr(EmptyShell Empty) : Expr(DeclRefExprClass, Empty) {}
1082
1083   /// Computes the type- and value-dependence flags for this
1084   /// declaration reference expression.
1085   void computeDependence(const ASTContext &Ctx);
1086
1087 public:
1088   DeclRefExpr(const ASTContext &Ctx, ValueDecl *D,
1089               bool RefersToEnclosingVariableOrCapture, QualType T,
1090               ExprValueKind VK, SourceLocation L,
1091               const DeclarationNameLoc &LocInfo = DeclarationNameLoc());
1092
1093   static DeclRefExpr *
1094   Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc,
1095          SourceLocation TemplateKWLoc, ValueDecl *D,
1096          bool RefersToEnclosingVariableOrCapture, SourceLocation NameLoc,
1097          QualType T, ExprValueKind VK, NamedDecl *FoundD = nullptr,
1098          const TemplateArgumentListInfo *TemplateArgs = nullptr);
1099
1100   static DeclRefExpr *
1101   Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc,
1102          SourceLocation TemplateKWLoc, ValueDecl *D,
1103          bool RefersToEnclosingVariableOrCapture,
1104          const DeclarationNameInfo &NameInfo, QualType T, ExprValueKind VK,
1105          NamedDecl *FoundD = nullptr,
1106          const TemplateArgumentListInfo *TemplateArgs = nullptr);
1107
1108   /// Construct an empty declaration reference expression.
1109   static DeclRefExpr *CreateEmpty(const ASTContext &Context, bool HasQualifier,
1110                                   bool HasFoundDecl,
1111                                   bool HasTemplateKWAndArgsInfo,
1112                                   unsigned NumTemplateArgs);
1113
1114   ValueDecl *getDecl() { return D; }
1115   const ValueDecl *getDecl() const { return D; }
1116   void setDecl(ValueDecl *NewD) { D = NewD; }
1117
1118   DeclarationNameInfo getNameInfo() const {
1119     return DeclarationNameInfo(getDecl()->getDeclName(), getLocation(), DNLoc);
1120   }
1121
1122   SourceLocation getLocation() const { return DeclRefExprBits.Loc; }
1123   void setLocation(SourceLocation L) { DeclRefExprBits.Loc = L; }
1124   SourceLocation getBeginLoc() const LLVM_READONLY;
1125   SourceLocation getEndLoc() const LLVM_READONLY;
1126
1127   /// Determine whether this declaration reference was preceded by a
1128   /// C++ nested-name-specifier, e.g., \c N::foo.
1129   bool hasQualifier() const { return DeclRefExprBits.HasQualifier; }
1130
1131   /// If the name was qualified, retrieves the nested-name-specifier
1132   /// that precedes the name, with source-location information.
1133   NestedNameSpecifierLoc getQualifierLoc() const {
1134     if (!hasQualifier())
1135       return NestedNameSpecifierLoc();
1136     return *getTrailingObjects<NestedNameSpecifierLoc>();
1137   }
1138
1139   /// If the name was qualified, retrieves the nested-name-specifier
1140   /// that precedes the name. Otherwise, returns NULL.
1141   NestedNameSpecifier *getQualifier() const {
1142     return getQualifierLoc().getNestedNameSpecifier();
1143   }
1144
1145   /// Get the NamedDecl through which this reference occurred.
1146   ///
1147   /// This Decl may be different from the ValueDecl actually referred to in the
1148   /// presence of using declarations, etc. It always returns non-NULL, and may
1149   /// simple return the ValueDecl when appropriate.
1150
1151   NamedDecl *getFoundDecl() {
1152     return hasFoundDecl() ? *getTrailingObjects<NamedDecl *>() : D;
1153   }
1154
1155   /// Get the NamedDecl through which this reference occurred.
1156   /// See non-const variant.
1157   const NamedDecl *getFoundDecl() const {
1158     return hasFoundDecl() ? *getTrailingObjects<NamedDecl *>() : D;
1159   }
1160
1161   bool hasTemplateKWAndArgsInfo() const {
1162     return DeclRefExprBits.HasTemplateKWAndArgsInfo;
1163   }
1164
1165   /// Retrieve the location of the template keyword preceding
1166   /// this name, if any.
1167   SourceLocation getTemplateKeywordLoc() const {
1168     if (!hasTemplateKWAndArgsInfo())
1169       return SourceLocation();
1170     return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->TemplateKWLoc;
1171   }
1172
1173   /// Retrieve the location of the left angle bracket starting the
1174   /// explicit template argument list following the name, if any.
1175   SourceLocation getLAngleLoc() const {
1176     if (!hasTemplateKWAndArgsInfo())
1177       return SourceLocation();
1178     return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->LAngleLoc;
1179   }
1180
1181   /// Retrieve the location of the right angle bracket ending the
1182   /// explicit template argument list following the name, if any.
1183   SourceLocation getRAngleLoc() const {
1184     if (!hasTemplateKWAndArgsInfo())
1185       return SourceLocation();
1186     return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->RAngleLoc;
1187   }
1188
1189   /// Determines whether the name in this declaration reference
1190   /// was preceded by the template keyword.
1191   bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
1192
1193   /// Determines whether this declaration reference was followed by an
1194   /// explicit template argument list.
1195   bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
1196
1197   /// Copies the template arguments (if present) into the given
1198   /// structure.
1199   void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
1200     if (hasExplicitTemplateArgs())
1201       getTrailingObjects<ASTTemplateKWAndArgsInfo>()->copyInto(
1202           getTrailingObjects<TemplateArgumentLoc>(), List);
1203   }
1204
1205   /// Retrieve the template arguments provided as part of this
1206   /// template-id.
1207   const TemplateArgumentLoc *getTemplateArgs() const {
1208     if (!hasExplicitTemplateArgs())
1209       return nullptr;
1210     return getTrailingObjects<TemplateArgumentLoc>();
1211   }
1212
1213   /// Retrieve the number of template arguments provided as part of this
1214   /// template-id.
1215   unsigned getNumTemplateArgs() const {
1216     if (!hasExplicitTemplateArgs())
1217       return 0;
1218     return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs;
1219   }
1220
1221   ArrayRef<TemplateArgumentLoc> template_arguments() const {
1222     return {getTemplateArgs(), getNumTemplateArgs()};
1223   }
1224
1225   /// Returns true if this expression refers to a function that
1226   /// was resolved from an overloaded set having size greater than 1.
1227   bool hadMultipleCandidates() const {
1228     return DeclRefExprBits.HadMultipleCandidates;
1229   }
1230   /// Sets the flag telling whether this expression refers to
1231   /// a function that was resolved from an overloaded set having size
1232   /// greater than 1.
1233   void setHadMultipleCandidates(bool V = true) {
1234     DeclRefExprBits.HadMultipleCandidates = V;
1235   }
1236
1237   /// Does this DeclRefExpr refer to an enclosing local or a captured
1238   /// variable?
1239   bool refersToEnclosingVariableOrCapture() const {
1240     return DeclRefExprBits.RefersToEnclosingVariableOrCapture;
1241   }
1242
1243   static bool classof(const Stmt *T) {
1244     return T->getStmtClass() == DeclRefExprClass;
1245   }
1246
1247   // Iterators
1248   child_range children() {
1249     return child_range(child_iterator(), child_iterator());
1250   }
1251
1252   const_child_range children() const {
1253     return const_child_range(const_child_iterator(), const_child_iterator());
1254   }
1255 };
1256
1257 /// Used by IntegerLiteral/FloatingLiteral to store the numeric without
1258 /// leaking memory.
1259 ///
1260 /// For large floats/integers, APFloat/APInt will allocate memory from the heap
1261 /// to represent these numbers.  Unfortunately, when we use a BumpPtrAllocator
1262 /// to allocate IntegerLiteral/FloatingLiteral nodes the memory associated with
1263 /// the APFloat/APInt values will never get freed. APNumericStorage uses
1264 /// ASTContext's allocator for memory allocation.
1265 class APNumericStorage {
1266   union {
1267     uint64_t VAL;    ///< Used to store the <= 64 bits integer value.
1268     uint64_t *pVal;  ///< Used to store the >64 bits integer value.
1269   };
1270   unsigned BitWidth;
1271
1272   bool hasAllocation() const { return llvm::APInt::getNumWords(BitWidth) > 1; }
1273
1274   APNumericStorage(const APNumericStorage &) = delete;
1275   void operator=(const APNumericStorage &) = delete;
1276
1277 protected:
1278   APNumericStorage() : VAL(0), BitWidth(0) { }
1279
1280   llvm::APInt getIntValue() const {
1281     unsigned NumWords = llvm::APInt::getNumWords(BitWidth);
1282     if (NumWords > 1)
1283       return llvm::APInt(BitWidth, NumWords, pVal);
1284     else
1285       return llvm::APInt(BitWidth, VAL);
1286   }
1287   void setIntValue(const ASTContext &C, const llvm::APInt &Val);
1288 };
1289
1290 class APIntStorage : private APNumericStorage {
1291 public:
1292   llvm::APInt getValue() const { return getIntValue(); }
1293   void setValue(const ASTContext &C, const llvm::APInt &Val) {
1294     setIntValue(C, Val);
1295   }
1296 };
1297
1298 class APFloatStorage : private APNumericStorage {
1299 public:
1300   llvm::APFloat getValue(const llvm::fltSemantics &Semantics) const {
1301     return llvm::APFloat(Semantics, getIntValue());
1302   }
1303   void setValue(const ASTContext &C, const llvm::APFloat &Val) {
1304     setIntValue(C, Val.bitcastToAPInt());
1305   }
1306 };
1307
1308 class IntegerLiteral : public Expr, public APIntStorage {
1309   SourceLocation Loc;
1310
1311   /// Construct an empty integer literal.
1312   explicit IntegerLiteral(EmptyShell Empty)
1313     : Expr(IntegerLiteralClass, Empty) { }
1314
1315 public:
1316   // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy,
1317   // or UnsignedLongLongTy
1318   IntegerLiteral(const ASTContext &C, const llvm::APInt &V, QualType type,
1319                  SourceLocation l);
1320
1321   /// Returns a new integer literal with value 'V' and type 'type'.
1322   /// \param type - either IntTy, LongTy, LongLongTy, UnsignedIntTy,
1323   /// UnsignedLongTy, or UnsignedLongLongTy which should match the size of V
1324   /// \param V - the value that the returned integer literal contains.
1325   static IntegerLiteral *Create(const ASTContext &C, const llvm::APInt &V,
1326                                 QualType type, SourceLocation l);
1327   /// Returns a new empty integer literal.
1328   static IntegerLiteral *Create(const ASTContext &C, EmptyShell Empty);
1329
1330   SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
1331   SourceLocation getEndLoc() const LLVM_READONLY { return Loc; }
1332
1333   /// Retrieve the location of the literal.
1334   SourceLocation getLocation() const { return Loc; }
1335
1336   void setLocation(SourceLocation Location) { Loc = Location; }
1337
1338   static bool classof(const Stmt *T) {
1339     return T->getStmtClass() == IntegerLiteralClass;
1340   }
1341
1342   // Iterators
1343   child_range children() {
1344     return child_range(child_iterator(), child_iterator());
1345   }
1346   const_child_range children() const {
1347     return const_child_range(const_child_iterator(), const_child_iterator());
1348   }
1349 };
1350
1351 class FixedPointLiteral : public Expr, public APIntStorage {
1352   SourceLocation Loc;
1353   unsigned Scale;
1354
1355   /// \brief Construct an empty integer literal.
1356   explicit FixedPointLiteral(EmptyShell Empty)
1357       : Expr(FixedPointLiteralClass, Empty) {}
1358
1359  public:
1360   FixedPointLiteral(const ASTContext &C, const llvm::APInt &V, QualType type,
1361                     SourceLocation l, unsigned Scale);
1362
1363   // Store the int as is without any bit shifting.
1364   static FixedPointLiteral *CreateFromRawInt(const ASTContext &C,
1365                                              const llvm::APInt &V,
1366                                              QualType type, SourceLocation l,
1367                                              unsigned Scale);
1368
1369   SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
1370   SourceLocation getEndLoc() const LLVM_READONLY { return Loc; }
1371
1372   /// \brief Retrieve the location of the literal.
1373   SourceLocation getLocation() const { return Loc; }
1374
1375   void setLocation(SourceLocation Location) { Loc = Location; }
1376
1377   static bool classof(const Stmt *T) {
1378     return T->getStmtClass() == FixedPointLiteralClass;
1379   }
1380
1381   std::string getValueAsString(unsigned Radix) const;
1382
1383   // Iterators
1384   child_range children() {
1385     return child_range(child_iterator(), child_iterator());
1386   }
1387   const_child_range children() const {
1388     return const_child_range(const_child_iterator(), const_child_iterator());
1389   }
1390 };
1391
1392 class CharacterLiteral : public Expr {
1393 public:
1394   enum CharacterKind {
1395     Ascii,
1396     Wide,
1397     UTF8,
1398     UTF16,
1399     UTF32
1400   };
1401
1402 private:
1403   unsigned Value;
1404   SourceLocation Loc;
1405 public:
1406   // type should be IntTy
1407   CharacterLiteral(unsigned value, CharacterKind kind, QualType type,
1408                    SourceLocation l)
1409     : Expr(CharacterLiteralClass, type, VK_RValue, OK_Ordinary, false, false,
1410            false, false),
1411       Value(value), Loc(l) {
1412     CharacterLiteralBits.Kind = kind;
1413   }
1414
1415   /// Construct an empty character literal.
1416   CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { }
1417
1418   SourceLocation getLocation() const { return Loc; }
1419   CharacterKind getKind() const {
1420     return static_cast<CharacterKind>(CharacterLiteralBits.Kind);
1421   }
1422
1423   SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
1424   SourceLocation getEndLoc() const LLVM_READONLY { return Loc; }
1425
1426   unsigned getValue() const { return Value; }
1427
1428   void setLocation(SourceLocation Location) { Loc = Location; }
1429   void setKind(CharacterKind kind) { CharacterLiteralBits.Kind = kind; }
1430   void setValue(unsigned Val) { Value = Val; }
1431
1432   static bool classof(const Stmt *T) {
1433     return T->getStmtClass() == CharacterLiteralClass;
1434   }
1435
1436   // Iterators
1437   child_range children() {
1438     return child_range(child_iterator(), child_iterator());
1439   }
1440   const_child_range children() const {
1441     return const_child_range(const_child_iterator(), const_child_iterator());
1442   }
1443 };
1444
1445 class FloatingLiteral : public Expr, private APFloatStorage {
1446   SourceLocation Loc;
1447
1448   FloatingLiteral(const ASTContext &C, const llvm::APFloat &V, bool isexact,
1449                   QualType Type, SourceLocation L);
1450
1451   /// Construct an empty floating-point literal.
1452   explicit FloatingLiteral(const ASTContext &C, EmptyShell Empty);
1453
1454 public:
1455   static FloatingLiteral *Create(const ASTContext &C, const llvm::APFloat &V,
1456                                  bool isexact, QualType Type, SourceLocation L);
1457   static FloatingLiteral *Create(const ASTContext &C, EmptyShell Empty);
1458
1459   llvm::APFloat getValue() const {
1460     return APFloatStorage::getValue(getSemantics());
1461   }
1462   void setValue(const ASTContext &C, const llvm::APFloat &Val) {
1463     assert(&getSemantics() == &Val.getSemantics() && "Inconsistent semantics");
1464     APFloatStorage::setValue(C, Val);
1465   }
1466
1467   /// Get a raw enumeration value representing the floating-point semantics of
1468   /// this literal (32-bit IEEE, x87, ...), suitable for serialisation.
1469   APFloatSemantics getRawSemantics() const {
1470     return static_cast<APFloatSemantics>(FloatingLiteralBits.Semantics);
1471   }
1472
1473   /// Set the raw enumeration value representing the floating-point semantics of
1474   /// this literal (32-bit IEEE, x87, ...), suitable for serialisation.
1475   void setRawSemantics(APFloatSemantics Sem) {
1476     FloatingLiteralBits.Semantics = Sem;
1477   }
1478
1479   /// Return the APFloat semantics this literal uses.
1480   const llvm::fltSemantics &getSemantics() const;
1481
1482   /// Set the APFloat semantics this literal uses.
1483   void setSemantics(const llvm::fltSemantics &Sem);
1484
1485   bool isExact() const { return FloatingLiteralBits.IsExact; }
1486   void setExact(bool E) { FloatingLiteralBits.IsExact = E; }
1487
1488   /// getValueAsApproximateDouble - This returns the value as an inaccurate
1489   /// double.  Note that this may cause loss of precision, but is useful for
1490   /// debugging dumps, etc.
1491   double getValueAsApproximateDouble() const;
1492
1493   SourceLocation getLocation() const { return Loc; }
1494   void setLocation(SourceLocation L) { Loc = L; }
1495
1496   SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
1497   SourceLocation getEndLoc() const LLVM_READONLY { return Loc; }
1498
1499   static bool classof(const Stmt *T) {
1500     return T->getStmtClass() == FloatingLiteralClass;
1501   }
1502
1503   // Iterators
1504   child_range children() {
1505     return child_range(child_iterator(), child_iterator());
1506   }
1507   const_child_range children() const {
1508     return const_child_range(const_child_iterator(), const_child_iterator());
1509   }
1510 };
1511
1512 /// ImaginaryLiteral - We support imaginary integer and floating point literals,
1513 /// like "1.0i".  We represent these as a wrapper around FloatingLiteral and
1514 /// IntegerLiteral classes.  Instances of this class always have a Complex type
1515 /// whose element type matches the subexpression.
1516 ///
1517 class ImaginaryLiteral : public Expr {
1518   Stmt *Val;
1519 public:
1520   ImaginaryLiteral(Expr *val, QualType Ty)
1521     : Expr(ImaginaryLiteralClass, Ty, VK_RValue, OK_Ordinary, false, false,
1522            false, false),
1523       Val(val) {}
1524
1525   /// Build an empty imaginary literal.
1526   explicit ImaginaryLiteral(EmptyShell Empty)
1527     : Expr(ImaginaryLiteralClass, Empty) { }
1528
1529   const Expr *getSubExpr() const { return cast<Expr>(Val); }
1530   Expr *getSubExpr() { return cast<Expr>(Val); }
1531   void setSubExpr(Expr *E) { Val = E; }
1532
1533   SourceLocation getBeginLoc() const LLVM_READONLY {
1534     return Val->getBeginLoc();
1535   }
1536   SourceLocation getEndLoc() const LLVM_READONLY { return Val->getEndLoc(); }
1537
1538   static bool classof(const Stmt *T) {
1539     return T->getStmtClass() == ImaginaryLiteralClass;
1540   }
1541
1542   // Iterators
1543   child_range children() { return child_range(&Val, &Val+1); }
1544   const_child_range children() const {
1545     return const_child_range(&Val, &Val + 1);
1546   }
1547 };
1548
1549 /// StringLiteral - This represents a string literal expression, e.g. "foo"
1550 /// or L"bar" (wide strings). The actual string data can be obtained with
1551 /// getBytes() and is NOT null-terminated. The length of the string data is
1552 /// determined by calling getByteLength().
1553 ///
1554 /// The C type for a string is always a ConstantArrayType. In C++, the char
1555 /// type is const qualified, in C it is not.
1556 ///
1557 /// Note that strings in C can be formed by concatenation of multiple string
1558 /// literal pptokens in translation phase #6. This keeps track of the locations
1559 /// of each of these pieces.
1560 ///
1561 /// Strings in C can also be truncated and extended by assigning into arrays,
1562 /// e.g. with constructs like:
1563 ///   char X[2] = "foobar";
1564 /// In this case, getByteLength() will return 6, but the string literal will
1565 /// have type "char[2]".
1566 class StringLiteral final
1567     : public Expr,
1568       private llvm::TrailingObjects<StringLiteral, unsigned, SourceLocation,
1569                                     char> {
1570   friend class ASTStmtReader;
1571   friend TrailingObjects;
1572
1573   /// StringLiteral is followed by several trailing objects. They are in order:
1574   ///
1575   /// * A single unsigned storing the length in characters of this string. The
1576   ///   length in bytes is this length times the width of a single character.
1577   ///   Always present and stored as a trailing objects because storing it in
1578   ///   StringLiteral would increase the size of StringLiteral by sizeof(void *)
1579   ///   due to alignment requirements. If you add some data to StringLiteral,
1580   ///   consider moving it inside StringLiteral.
1581   ///
1582   /// * An array of getNumConcatenated() SourceLocation, one for each of the
1583   ///   token this string is made of.
1584   ///
1585   /// * An array of getByteLength() char used to store the string data.
1586
1587 public:
1588   enum StringKind { Ascii, Wide, UTF8, UTF16, UTF32 };
1589
1590 private:
1591   unsigned numTrailingObjects(OverloadToken<unsigned>) const { return 1; }
1592   unsigned numTrailingObjects(OverloadToken<SourceLocation>) const {
1593     return getNumConcatenated();
1594   }
1595
1596   unsigned numTrailingObjects(OverloadToken<char>) const {
1597     return getByteLength();
1598   }
1599
1600   char *getStrDataAsChar() { return getTrailingObjects<char>(); }
1601   const char *getStrDataAsChar() const { return getTrailingObjects<char>(); }
1602
1603   const uint16_t *getStrDataAsUInt16() const {
1604     return reinterpret_cast<const uint16_t *>(getTrailingObjects<char>());
1605   }
1606
1607   const uint32_t *getStrDataAsUInt32() const {
1608     return reinterpret_cast<const uint32_t *>(getTrailingObjects<char>());
1609   }
1610
1611   /// Build a string literal.
1612   StringLiteral(const ASTContext &Ctx, StringRef Str, StringKind Kind,
1613                 bool Pascal, QualType Ty, const SourceLocation *Loc,
1614                 unsigned NumConcatenated);
1615
1616   /// Build an empty string literal.
1617   StringLiteral(EmptyShell Empty, unsigned NumConcatenated, unsigned Length,
1618                 unsigned CharByteWidth);
1619
1620   /// Map a target and string kind to the appropriate character width.
1621   static unsigned mapCharByteWidth(TargetInfo const &Target, StringKind SK);
1622
1623   /// Set one of the string literal token.
1624   void setStrTokenLoc(unsigned TokNum, SourceLocation L) {
1625     assert(TokNum < getNumConcatenated() && "Invalid tok number");
1626     getTrailingObjects<SourceLocation>()[TokNum] = L;
1627   }
1628
1629 public:
1630   /// This is the "fully general" constructor that allows representation of
1631   /// strings formed from multiple concatenated tokens.
1632   static StringLiteral *Create(const ASTContext &Ctx, StringRef Str,
1633                                StringKind Kind, bool Pascal, QualType Ty,
1634                                const SourceLocation *Loc,
1635                                unsigned NumConcatenated);
1636
1637   /// Simple constructor for string literals made from one token.
1638   static StringLiteral *Create(const ASTContext &Ctx, StringRef Str,
1639                                StringKind Kind, bool Pascal, QualType Ty,
1640                                SourceLocation Loc) {
1641     return Create(Ctx, Str, Kind, Pascal, Ty, &Loc, 1);
1642   }
1643
1644   /// Construct an empty string literal.
1645   static StringLiteral *CreateEmpty(const ASTContext &Ctx,
1646                                     unsigned NumConcatenated, unsigned Length,
1647                                     unsigned CharByteWidth);
1648
1649   StringRef getString() const {
1650     assert(getCharByteWidth() == 1 &&
1651            "This function is used in places that assume strings use char");
1652     return StringRef(getStrDataAsChar(), getByteLength());
1653   }
1654
1655   /// Allow access to clients that need the byte representation, such as
1656   /// ASTWriterStmt::VisitStringLiteral().
1657   StringRef getBytes() const {
1658     // FIXME: StringRef may not be the right type to use as a result for this.
1659     return StringRef(getStrDataAsChar(), getByteLength());
1660   }
1661
1662   void outputString(raw_ostream &OS) const;
1663
1664   uint32_t getCodeUnit(size_t i) const {
1665     assert(i < getLength() && "out of bounds access");
1666     switch (getCharByteWidth()) {
1667     case 1:
1668       return static_cast<unsigned char>(getStrDataAsChar()[i]);
1669     case 2:
1670       return getStrDataAsUInt16()[i];
1671     case 4:
1672       return getStrDataAsUInt32()[i];
1673     }
1674     llvm_unreachable("Unsupported character width!");
1675   }
1676
1677   unsigned getByteLength() const { return getCharByteWidth() * getLength(); }
1678   unsigned getLength() const { return *getTrailingObjects<unsigned>(); }
1679   unsigned getCharByteWidth() const { return StringLiteralBits.CharByteWidth; }
1680
1681   StringKind getKind() const {
1682     return static_cast<StringKind>(StringLiteralBits.Kind);
1683   }
1684
1685   bool isAscii() const { return getKind() == Ascii; }
1686   bool isWide() const { return getKind() == Wide; }
1687   bool isUTF8() const { return getKind() == UTF8; }
1688   bool isUTF16() const { return getKind() == UTF16; }
1689   bool isUTF32() const { return getKind() == UTF32; }
1690   bool isPascal() const { return StringLiteralBits.IsPascal; }
1691
1692   bool containsNonAscii() const {
1693     for (auto c : getString())
1694       if (!isASCII(c))
1695         return true;
1696     return false;
1697   }
1698
1699   bool containsNonAsciiOrNull() const {
1700     for (auto c : getString())
1701       if (!isASCII(c) || !c)
1702         return true;
1703     return false;
1704   }
1705
1706   /// getNumConcatenated - Get the number of string literal tokens that were
1707   /// concatenated in translation phase #6 to form this string literal.
1708   unsigned getNumConcatenated() const {
1709     return StringLiteralBits.NumConcatenated;
1710   }
1711
1712   /// Get one of the string literal token.
1713   SourceLocation getStrTokenLoc(unsigned TokNum) const {
1714     assert(TokNum < getNumConcatenated() && "Invalid tok number");
1715     return getTrailingObjects<SourceLocation>()[TokNum];
1716   }
1717
1718   /// getLocationOfByte - Return a source location that points to the specified
1719   /// byte of this string literal.
1720   ///
1721   /// Strings are amazingly complex.  They can be formed from multiple tokens
1722   /// and can have escape sequences in them in addition to the usual trigraph
1723   /// and escaped newline business.  This routine handles this complexity.
1724   ///
1725   SourceLocation
1726   getLocationOfByte(unsigned ByteNo, const SourceManager &SM,
1727                     const LangOptions &Features, const TargetInfo &Target,
1728                     unsigned *StartToken = nullptr,
1729                     unsigned *StartTokenByteOffset = nullptr) const;
1730
1731   typedef const SourceLocation *tokloc_iterator;
1732
1733   tokloc_iterator tokloc_begin() const {
1734     return getTrailingObjects<SourceLocation>();
1735   }
1736
1737   tokloc_iterator tokloc_end() const {
1738     return getTrailingObjects<SourceLocation>() + getNumConcatenated();
1739   }
1740
1741   SourceLocation getBeginLoc() const LLVM_READONLY { return *tokloc_begin(); }
1742   SourceLocation getEndLoc() const LLVM_READONLY { return *(tokloc_end() - 1); }
1743
1744   static bool classof(const Stmt *T) {
1745     return T->getStmtClass() == StringLiteralClass;
1746   }
1747
1748   // Iterators
1749   child_range children() {
1750     return child_range(child_iterator(), child_iterator());
1751   }
1752   const_child_range children() const {
1753     return const_child_range(const_child_iterator(), const_child_iterator());
1754   }
1755 };
1756
1757 /// [C99 6.4.2.2] - A predefined identifier such as __func__.
1758 class PredefinedExpr final
1759     : public Expr,
1760       private llvm::TrailingObjects<PredefinedExpr, Stmt *> {
1761   friend class ASTStmtReader;
1762   friend TrailingObjects;
1763
1764   // PredefinedExpr is optionally followed by a single trailing
1765   // "Stmt *" for the predefined identifier. It is present if and only if
1766   // hasFunctionName() is true and is always a "StringLiteral *".
1767
1768 public:
1769   enum IdentKind {
1770     Func,
1771     Function,
1772     LFunction, // Same as Function, but as wide string.
1773     FuncDName,
1774     FuncSig,
1775     LFuncSig, // Same as FuncSig, but as as wide string
1776     PrettyFunction,
1777     /// The same as PrettyFunction, except that the
1778     /// 'virtual' keyword is omitted for virtual member functions.
1779     PrettyFunctionNoVirtual
1780   };
1781
1782 private:
1783   PredefinedExpr(SourceLocation L, QualType FNTy, IdentKind IK,
1784                  StringLiteral *SL);
1785
1786   explicit PredefinedExpr(EmptyShell Empty, bool HasFunctionName);
1787
1788   /// True if this PredefinedExpr has storage for a function name.
1789   bool hasFunctionName() const { return PredefinedExprBits.HasFunctionName; }
1790
1791   void setFunctionName(StringLiteral *SL) {
1792     assert(hasFunctionName() &&
1793            "This PredefinedExpr has no storage for a function name!");
1794     *getTrailingObjects<Stmt *>() = SL;
1795   }
1796
1797 public:
1798   /// Create a PredefinedExpr.
1799   static PredefinedExpr *Create(const ASTContext &Ctx, SourceLocation L,
1800                                 QualType FNTy, IdentKind IK, StringLiteral *SL);
1801
1802   /// Create an empty PredefinedExpr.
1803   static PredefinedExpr *CreateEmpty(const ASTContext &Ctx,
1804                                      bool HasFunctionName);
1805
1806   IdentKind getIdentKind() const {
1807     return static_cast<IdentKind>(PredefinedExprBits.Kind);
1808   }
1809
1810   SourceLocation getLocation() const { return PredefinedExprBits.Loc; }
1811   void setLocation(SourceLocation L) { PredefinedExprBits.Loc = L; }
1812
1813   StringLiteral *getFunctionName() {
1814     return hasFunctionName()
1815                ? static_cast<StringLiteral *>(*getTrailingObjects<Stmt *>())
1816                : nullptr;
1817   }
1818
1819   const StringLiteral *getFunctionName() const {
1820     return hasFunctionName()
1821                ? static_cast<StringLiteral *>(*getTrailingObjects<Stmt *>())
1822                : nullptr;
1823   }
1824
1825   static StringRef getIdentKindName(IdentKind IK);
1826   static std::string ComputeName(IdentKind IK, const Decl *CurrentDecl);
1827
1828   SourceLocation getBeginLoc() const { return getLocation(); }
1829   SourceLocation getEndLoc() const { return getLocation(); }
1830
1831   static bool classof(const Stmt *T) {
1832     return T->getStmtClass() == PredefinedExprClass;
1833   }
1834
1835   // Iterators
1836   child_range children() {
1837     return child_range(getTrailingObjects<Stmt *>(),
1838                        getTrailingObjects<Stmt *>() + hasFunctionName());
1839   }
1840 };
1841
1842 /// ParenExpr - This represents a parethesized expression, e.g. "(1)".  This
1843 /// AST node is only formed if full location information is requested.
1844 class ParenExpr : public Expr {
1845   SourceLocation L, R;
1846   Stmt *Val;
1847 public:
1848   ParenExpr(SourceLocation l, SourceLocation r, Expr *val)
1849     : Expr(ParenExprClass, val->getType(),
1850            val->getValueKind(), val->getObjectKind(),
1851            val->isTypeDependent(), val->isValueDependent(),
1852            val->isInstantiationDependent(),
1853            val->containsUnexpandedParameterPack()),
1854       L(l), R(r), Val(val) {}
1855
1856   /// Construct an empty parenthesized expression.
1857   explicit ParenExpr(EmptyShell Empty)
1858     : Expr(ParenExprClass, Empty) { }
1859
1860   const Expr *getSubExpr() const { return cast<Expr>(Val); }
1861   Expr *getSubExpr() { return cast<Expr>(Val); }
1862   void setSubExpr(Expr *E) { Val = E; }
1863
1864   SourceLocation getBeginLoc() const LLVM_READONLY { return L; }
1865   SourceLocation getEndLoc() const LLVM_READONLY { return R; }
1866
1867   /// Get the location of the left parentheses '('.
1868   SourceLocation getLParen() const { return L; }
1869   void setLParen(SourceLocation Loc) { L = Loc; }
1870
1871   /// Get the location of the right parentheses ')'.
1872   SourceLocation getRParen() const { return R; }
1873   void setRParen(SourceLocation Loc) { R = Loc; }
1874
1875   static bool classof(const Stmt *T) {
1876     return T->getStmtClass() == ParenExprClass;
1877   }
1878
1879   // Iterators
1880   child_range children() { return child_range(&Val, &Val+1); }
1881   const_child_range children() const {
1882     return const_child_range(&Val, &Val + 1);
1883   }
1884 };
1885
1886 /// UnaryOperator - This represents the unary-expression's (except sizeof and
1887 /// alignof), the postinc/postdec operators from postfix-expression, and various
1888 /// extensions.
1889 ///
1890 /// Notes on various nodes:
1891 ///
1892 /// Real/Imag - These return the real/imag part of a complex operand.  If
1893 ///   applied to a non-complex value, the former returns its operand and the
1894 ///   later returns zero in the type of the operand.
1895 ///
1896 class UnaryOperator : public Expr {
1897   Stmt *Val;
1898
1899 public:
1900   typedef UnaryOperatorKind Opcode;
1901
1902   UnaryOperator(Expr *input, Opcode opc, QualType type, ExprValueKind VK,
1903                 ExprObjectKind OK, SourceLocation l, bool CanOverflow)
1904       : Expr(UnaryOperatorClass, type, VK, OK,
1905              input->isTypeDependent() || type->isDependentType(),
1906              input->isValueDependent(),
1907              (input->isInstantiationDependent() ||
1908               type->isInstantiationDependentType()),
1909              input->containsUnexpandedParameterPack()),
1910         Val(input) {
1911     UnaryOperatorBits.Opc = opc;
1912     UnaryOperatorBits.CanOverflow = CanOverflow;
1913     UnaryOperatorBits.Loc = l;
1914   }
1915
1916   /// Build an empty unary operator.
1917   explicit UnaryOperator(EmptyShell Empty) : Expr(UnaryOperatorClass, Empty) {
1918     UnaryOperatorBits.Opc = UO_AddrOf;
1919   }
1920
1921   Opcode getOpcode() const {
1922     return static_cast<Opcode>(UnaryOperatorBits.Opc);
1923   }
1924   void setOpcode(Opcode Opc) { UnaryOperatorBits.Opc = Opc; }
1925
1926   Expr *getSubExpr() const { return cast<Expr>(Val); }
1927   void setSubExpr(Expr *E) { Val = E; }
1928
1929   /// getOperatorLoc - Return the location of the operator.
1930   SourceLocation getOperatorLoc() const { return UnaryOperatorBits.Loc; }
1931   void setOperatorLoc(SourceLocation L) { UnaryOperatorBits.Loc = L; }
1932
1933   /// Returns true if the unary operator can cause an overflow. For instance,
1934   ///   signed int i = INT_MAX; i++;
1935   ///   signed char c = CHAR_MAX; c++;
1936   /// Due to integer promotions, c++ is promoted to an int before the postfix
1937   /// increment, and the result is an int that cannot overflow. However, i++
1938   /// can overflow.
1939   bool canOverflow() const { return UnaryOperatorBits.CanOverflow; }
1940   void setCanOverflow(bool C) { UnaryOperatorBits.CanOverflow = C; }
1941
1942   /// isPostfix - Return true if this is a postfix operation, like x++.
1943   static bool isPostfix(Opcode Op) {
1944     return Op == UO_PostInc || Op == UO_PostDec;
1945   }
1946
1947   /// isPrefix - Return true if this is a prefix operation, like --x.
1948   static bool isPrefix(Opcode Op) {
1949     return Op == UO_PreInc || Op == UO_PreDec;
1950   }
1951
1952   bool isPrefix() const { return isPrefix(getOpcode()); }
1953   bool isPostfix() const { return isPostfix(getOpcode()); }
1954
1955   static bool isIncrementOp(Opcode Op) {
1956     return Op == UO_PreInc || Op == UO_PostInc;
1957   }
1958   bool isIncrementOp() const {
1959     return isIncrementOp(getOpcode());
1960   }
1961
1962   static bool isDecrementOp(Opcode Op) {
1963     return Op == UO_PreDec || Op == UO_PostDec;
1964   }
1965   bool isDecrementOp() const {
1966     return isDecrementOp(getOpcode());
1967   }
1968
1969   static bool isIncrementDecrementOp(Opcode Op) { return Op <= UO_PreDec; }
1970   bool isIncrementDecrementOp() const {
1971     return isIncrementDecrementOp(getOpcode());
1972   }
1973
1974   static bool isArithmeticOp(Opcode Op) {
1975     return Op >= UO_Plus && Op <= UO_LNot;
1976   }
1977   bool isArithmeticOp() const { return isArithmeticOp(getOpcode()); }
1978
1979   /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
1980   /// corresponds to, e.g. "sizeof" or "[pre]++"
1981   static StringRef getOpcodeStr(Opcode Op);
1982
1983   /// Retrieve the unary opcode that corresponds to the given
1984   /// overloaded operator.
1985   static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix);
1986
1987   /// Retrieve the overloaded operator kind that corresponds to
1988   /// the given unary opcode.
1989   static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
1990
1991   SourceLocation getBeginLoc() const LLVM_READONLY {
1992     return isPostfix() ? Val->getBeginLoc() : getOperatorLoc();
1993   }
1994   SourceLocation getEndLoc() const LLVM_READONLY {
1995     return isPostfix() ? getOperatorLoc() : Val->getEndLoc();
1996   }
1997   SourceLocation getExprLoc() const { return getOperatorLoc(); }
1998
1999   static bool classof(const Stmt *T) {
2000     return T->getStmtClass() == UnaryOperatorClass;
2001   }
2002
2003   // Iterators
2004   child_range children() { return child_range(&Val, &Val+1); }
2005   const_child_range children() const {
2006     return const_child_range(&Val, &Val + 1);
2007   }
2008 };
2009
2010 /// Helper class for OffsetOfExpr.
2011
2012 // __builtin_offsetof(type, identifier(.identifier|[expr])*)
2013 class OffsetOfNode {
2014 public:
2015   /// The kind of offsetof node we have.
2016   enum Kind {
2017     /// An index into an array.
2018     Array = 0x00,
2019     /// A field.
2020     Field = 0x01,
2021     /// A field in a dependent type, known only by its name.
2022     Identifier = 0x02,
2023     /// An implicit indirection through a C++ base class, when the
2024     /// field found is in a base class.
2025     Base = 0x03
2026   };
2027
2028 private:
2029   enum { MaskBits = 2, Mask = 0x03 };
2030
2031   /// The source range that covers this part of the designator.
2032   SourceRange Range;
2033
2034   /// The data describing the designator, which comes in three
2035   /// different forms, depending on the lower two bits.
2036   ///   - An unsigned index into the array of Expr*'s stored after this node
2037   ///     in memory, for [constant-expression] designators.
2038   ///   - A FieldDecl*, for references to a known field.
2039   ///   - An IdentifierInfo*, for references to a field with a given name
2040   ///     when the class type is dependent.
2041   ///   - A CXXBaseSpecifier*, for references that look at a field in a
2042   ///     base class.
2043   uintptr_t Data;
2044
2045 public:
2046   /// Create an offsetof node that refers to an array element.
2047   OffsetOfNode(SourceLocation LBracketLoc, unsigned Index,
2048                SourceLocation RBracketLoc)
2049       : Range(LBracketLoc, RBracketLoc), Data((Index << 2) | Array) {}
2050
2051   /// Create an offsetof node that refers to a field.
2052   OffsetOfNode(SourceLocation DotLoc, FieldDecl *Field, SourceLocation NameLoc)
2053       : Range(DotLoc.isValid() ? DotLoc : NameLoc, NameLoc),
2054         Data(reinterpret_cast<uintptr_t>(Field) | OffsetOfNode::Field) {}
2055
2056   /// Create an offsetof node that refers to an identifier.
2057   OffsetOfNode(SourceLocation DotLoc, IdentifierInfo *Name,
2058                SourceLocation NameLoc)
2059       : Range(DotLoc.isValid() ? DotLoc : NameLoc, NameLoc),
2060         Data(reinterpret_cast<uintptr_t>(Name) | Identifier) {}
2061
2062   /// Create an offsetof node that refers into a C++ base class.
2063   explicit OffsetOfNode(const CXXBaseSpecifier *Base)
2064       : Range(), Data(reinterpret_cast<uintptr_t>(Base) | OffsetOfNode::Base) {}
2065
2066   /// Determine what kind of offsetof node this is.
2067   Kind getKind() const { return static_cast<Kind>(Data & Mask); }
2068
2069   /// For an array element node, returns the index into the array
2070   /// of expressions.
2071   unsigned getArrayExprIndex() const {
2072     assert(getKind() == Array);
2073     return Data >> 2;
2074   }
2075
2076   /// For a field offsetof node, returns the field.
2077   FieldDecl *getField() const {
2078     assert(getKind() == Field);
2079     return reinterpret_cast<FieldDecl *>(Data & ~(uintptr_t)Mask);
2080   }
2081
2082   /// For a field or identifier offsetof node, returns the name of
2083   /// the field.
2084   IdentifierInfo *getFieldName() const;
2085
2086   /// For a base class node, returns the base specifier.
2087   CXXBaseSpecifier *getBase() const {
2088     assert(getKind() == Base);
2089     return reinterpret_cast<CXXBaseSpecifier *>(Data & ~(uintptr_t)Mask);
2090   }
2091
2092   /// Retrieve the source range that covers this offsetof node.
2093   ///
2094   /// For an array element node, the source range contains the locations of
2095   /// the square brackets. For a field or identifier node, the source range
2096   /// contains the location of the period (if there is one) and the
2097   /// identifier.
2098   SourceRange getSourceRange() const LLVM_READONLY { return Range; }
2099   SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); }
2100   SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); }
2101 };
2102
2103 /// OffsetOfExpr - [C99 7.17] - This represents an expression of the form
2104 /// offsetof(record-type, member-designator). For example, given:
2105 /// @code
2106 /// struct S {
2107 ///   float f;
2108 ///   double d;
2109 /// };
2110 /// struct T {
2111 ///   int i;
2112 ///   struct S s[10];
2113 /// };
2114 /// @endcode
2115 /// we can represent and evaluate the expression @c offsetof(struct T, s[2].d).
2116
2117 class OffsetOfExpr final
2118     : public Expr,
2119       private llvm::TrailingObjects<OffsetOfExpr, OffsetOfNode, Expr *> {
2120   SourceLocation OperatorLoc, RParenLoc;
2121   // Base type;
2122   TypeSourceInfo *TSInfo;
2123   // Number of sub-components (i.e. instances of OffsetOfNode).
2124   unsigned NumComps;
2125   // Number of sub-expressions (i.e. array subscript expressions).
2126   unsigned NumExprs;
2127
2128   size_t numTrailingObjects(OverloadToken<OffsetOfNode>) const {
2129     return NumComps;
2130   }
2131
2132   OffsetOfExpr(const ASTContext &C, QualType type,
2133                SourceLocation OperatorLoc, TypeSourceInfo *tsi,
2134                ArrayRef<OffsetOfNode> comps, ArrayRef<Expr*> exprs,
2135                SourceLocation RParenLoc);
2136
2137   explicit OffsetOfExpr(unsigned numComps, unsigned numExprs)
2138     : Expr(OffsetOfExprClass, EmptyShell()),
2139       TSInfo(nullptr), NumComps(numComps), NumExprs(numExprs) {}
2140
2141 public:
2142
2143   static OffsetOfExpr *Create(const ASTContext &C, QualType type,
2144                               SourceLocation OperatorLoc, TypeSourceInfo *tsi,
2145                               ArrayRef<OffsetOfNode> comps,
2146                               ArrayRef<Expr*> exprs, SourceLocation RParenLoc);
2147
2148   static OffsetOfExpr *CreateEmpty(const ASTContext &C,
2149                                    unsigned NumComps, unsigned NumExprs);
2150
2151   /// getOperatorLoc - Return the location of the operator.
2152   SourceLocation getOperatorLoc() const { return OperatorLoc; }
2153   void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
2154
2155   /// Return the location of the right parentheses.
2156   SourceLocation getRParenLoc() const { return RParenLoc; }
2157   void setRParenLoc(SourceLocation R) { RParenLoc = R; }
2158
2159   TypeSourceInfo *getTypeSourceInfo() const {
2160     return TSInfo;
2161   }
2162   void setTypeSourceInfo(TypeSourceInfo *tsi) {
2163     TSInfo = tsi;
2164   }
2165
2166   const OffsetOfNode &getComponent(unsigned Idx) const {
2167     assert(Idx < NumComps && "Subscript out of range");
2168     return getTrailingObjects<OffsetOfNode>()[Idx];
2169   }
2170
2171   void setComponent(unsigned Idx, OffsetOfNode ON) {
2172     assert(Idx < NumComps && "Subscript out of range");
2173     getTrailingObjects<OffsetOfNode>()[Idx] = ON;
2174   }
2175
2176   unsigned getNumComponents() const {
2177     return NumComps;
2178   }
2179
2180   Expr* getIndexExpr(unsigned Idx) {
2181     assert(Idx < NumExprs && "Subscript out of range");
2182     return getTrailingObjects<Expr *>()[Idx];
2183   }
2184
2185   const Expr *getIndexExpr(unsigned Idx) const {
2186     assert(Idx < NumExprs && "Subscript out of range");
2187     return getTrailingObjects<Expr *>()[Idx];
2188   }
2189
2190   void setIndexExpr(unsigned Idx, Expr* E) {
2191     assert(Idx < NumComps && "Subscript out of range");
2192     getTrailingObjects<Expr *>()[Idx] = E;
2193   }
2194
2195   unsigned getNumExpressions() const {
2196     return NumExprs;
2197   }
2198
2199   SourceLocation getBeginLoc() const LLVM_READONLY { return OperatorLoc; }
2200   SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
2201
2202   static bool classof(const Stmt *T) {
2203     return T->getStmtClass() == OffsetOfExprClass;
2204   }
2205
2206   // Iterators
2207   child_range children() {
2208     Stmt **begin = reinterpret_cast<Stmt **>(getTrailingObjects<Expr *>());
2209     return child_range(begin, begin + NumExprs);
2210   }
2211   const_child_range children() const {
2212     Stmt *const *begin =
2213         reinterpret_cast<Stmt *const *>(getTrailingObjects<Expr *>());
2214     return const_child_range(begin, begin + NumExprs);
2215   }
2216   friend TrailingObjects;
2217 };
2218
2219 /// UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated)
2220 /// expression operand.  Used for sizeof/alignof (C99 6.5.3.4) and
2221 /// vec_step (OpenCL 1.1 6.11.12).
2222 class UnaryExprOrTypeTraitExpr : public Expr {
2223   union {
2224     TypeSourceInfo *Ty;
2225     Stmt *Ex;
2226   } Argument;
2227   SourceLocation OpLoc, RParenLoc;
2228
2229 public:
2230   UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, TypeSourceInfo *TInfo,
2231                            QualType resultType, SourceLocation op,
2232                            SourceLocation rp) :
2233       Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_RValue, OK_Ordinary,
2234            false, // Never type-dependent (C++ [temp.dep.expr]p3).
2235            // Value-dependent if the argument is type-dependent.
2236            TInfo->getType()->isDependentType(),
2237            TInfo->getType()->isInstantiationDependentType(),
2238            TInfo->getType()->containsUnexpandedParameterPack()),
2239       OpLoc(op), RParenLoc(rp) {
2240     UnaryExprOrTypeTraitExprBits.Kind = ExprKind;
2241     UnaryExprOrTypeTraitExprBits.IsType = true;
2242     Argument.Ty = TInfo;
2243   }
2244
2245   UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, Expr *E,
2246                            QualType resultType, SourceLocation op,
2247                            SourceLocation rp);
2248
2249   /// Construct an empty sizeof/alignof expression.
2250   explicit UnaryExprOrTypeTraitExpr(EmptyShell Empty)
2251     : Expr(UnaryExprOrTypeTraitExprClass, Empty) { }
2252
2253   UnaryExprOrTypeTrait getKind() const {
2254     return static_cast<UnaryExprOrTypeTrait>(UnaryExprOrTypeTraitExprBits.Kind);
2255   }
2256   void setKind(UnaryExprOrTypeTrait K) { UnaryExprOrTypeTraitExprBits.Kind = K;}
2257
2258   bool isArgumentType() const { return UnaryExprOrTypeTraitExprBits.IsType; }
2259   QualType getArgumentType() const {
2260     return getArgumentTypeInfo()->getType();
2261   }
2262   TypeSourceInfo *getArgumentTypeInfo() const {
2263     assert(isArgumentType() && "calling getArgumentType() when arg is expr");
2264     return Argument.Ty;
2265   }
2266   Expr *getArgumentExpr() {
2267     assert(!isArgumentType() && "calling getArgumentExpr() when arg is type");
2268     return static_cast<Expr*>(Argument.Ex);
2269   }
2270   const Expr *getArgumentExpr() const {
2271     return const_cast<UnaryExprOrTypeTraitExpr*>(this)->getArgumentExpr();
2272   }
2273
2274   void setArgument(Expr *E) {
2275     Argument.Ex = E;
2276     UnaryExprOrTypeTraitExprBits.IsType = false;
2277   }
2278   void setArgument(TypeSourceInfo *TInfo) {
2279     Argument.Ty = TInfo;
2280     UnaryExprOrTypeTraitExprBits.IsType = true;
2281   }
2282
2283   /// Gets the argument type, or the type of the argument expression, whichever
2284   /// is appropriate.
2285   QualType getTypeOfArgument() const {
2286     return isArgumentType() ? getArgumentType() : getArgumentExpr()->getType();
2287   }
2288
2289   SourceLocation getOperatorLoc() const { return OpLoc; }
2290   void setOperatorLoc(SourceLocation L) { OpLoc = L; }
2291
2292   SourceLocation getRParenLoc() const { return RParenLoc; }
2293   void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2294
2295   SourceLocation getBeginLoc() const LLVM_READONLY { return OpLoc; }
2296   SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
2297
2298   static bool classof(const Stmt *T) {
2299     return T->getStmtClass() == UnaryExprOrTypeTraitExprClass;
2300   }
2301
2302   // Iterators
2303   child_range children();
2304   const_child_range children() const;
2305 };
2306
2307 //===----------------------------------------------------------------------===//
2308 // Postfix Operators.
2309 //===----------------------------------------------------------------------===//
2310
2311 /// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
2312 class ArraySubscriptExpr : public Expr {
2313   enum { LHS, RHS, END_EXPR };
2314   Stmt *SubExprs[END_EXPR];
2315
2316   bool lhsIsBase() const { return getRHS()->getType()->isIntegerType(); }
2317
2318 public:
2319   ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t,
2320                      ExprValueKind VK, ExprObjectKind OK,
2321                      SourceLocation rbracketloc)
2322   : Expr(ArraySubscriptExprClass, t, VK, OK,
2323          lhs->isTypeDependent() || rhs->isTypeDependent(),
2324          lhs->isValueDependent() || rhs->isValueDependent(),
2325          (lhs->isInstantiationDependent() ||
2326           rhs->isInstantiationDependent()),
2327          (lhs->containsUnexpandedParameterPack() ||
2328           rhs->containsUnexpandedParameterPack())) {
2329     SubExprs[LHS] = lhs;
2330     SubExprs[RHS] = rhs;
2331     ArraySubscriptExprBits.RBracketLoc = rbracketloc;
2332   }
2333
2334   /// Create an empty array subscript expression.
2335   explicit ArraySubscriptExpr(EmptyShell Shell)
2336     : Expr(ArraySubscriptExprClass, Shell) { }
2337
2338   /// An array access can be written A[4] or 4[A] (both are equivalent).
2339   /// - getBase() and getIdx() always present the normalized view: A[4].
2340   ///    In this case getBase() returns "A" and getIdx() returns "4".
2341   /// - getLHS() and getRHS() present the syntactic view. e.g. for
2342   ///    4[A] getLHS() returns "4".
2343   /// Note: Because vector element access is also written A[4] we must
2344   /// predicate the format conversion in getBase and getIdx only on the
2345   /// the type of the RHS, as it is possible for the LHS to be a vector of
2346   /// integer type
2347   Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); }
2348   const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
2349   void setLHS(Expr *E) { SubExprs[LHS] = E; }
2350
2351   Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); }
2352   const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
2353   void setRHS(Expr *E) { SubExprs[RHS] = E; }
2354
2355   Expr *getBase() { return lhsIsBase() ? getLHS() : getRHS(); }
2356   const Expr *getBase() const { return lhsIsBase() ? getLHS() : getRHS(); }
2357
2358   Expr *getIdx() { return lhsIsBase() ? getRHS() : getLHS(); }
2359   const Expr *getIdx() const { return lhsIsBase() ? getRHS() : getLHS(); }
2360
2361   SourceLocation getBeginLoc() const LLVM_READONLY {
2362     return getLHS()->getBeginLoc();
2363   }
2364   SourceLocation getEndLoc() const { return getRBracketLoc(); }
2365
2366   SourceLocation getRBracketLoc() const {
2367     return ArraySubscriptExprBits.RBracketLoc;
2368   }
2369   void setRBracketLoc(SourceLocation L) {
2370     ArraySubscriptExprBits.RBracketLoc = L;
2371   }
2372
2373   SourceLocation getExprLoc() const LLVM_READONLY {
2374     return getBase()->getExprLoc();
2375   }
2376
2377   static bool classof(const Stmt *T) {
2378     return T->getStmtClass() == ArraySubscriptExprClass;
2379   }
2380
2381   // Iterators
2382   child_range children() {
2383     return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
2384   }
2385   const_child_range children() const {
2386     return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
2387   }
2388 };
2389
2390 /// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
2391 /// CallExpr itself represents a normal function call, e.g., "f(x, 2)",
2392 /// while its subclasses may represent alternative syntax that (semantically)
2393 /// results in a function call. For example, CXXOperatorCallExpr is
2394 /// a subclass for overloaded operator calls that use operator syntax, e.g.,
2395 /// "str1 + str2" to resolve to a function call.
2396 class CallExpr : public Expr {
2397   enum { FN = 0, PREARGS_START = 1 };
2398
2399   /// The number of arguments in the call expression.
2400   unsigned NumArgs;
2401
2402   /// The location of the right parenthese. This has a different meaning for
2403   /// the derived classes of CallExpr.
2404   SourceLocation RParenLoc;
2405
2406   void updateDependenciesFromArg(Expr *Arg);
2407
2408   // CallExpr store some data in trailing objects. However since CallExpr
2409   // is used a base of other expression classes we cannot use
2410   // llvm::TrailingObjects. Instead we manually perform the pointer arithmetic
2411   // and casts.
2412   //
2413   // The trailing objects are in order:
2414   //
2415   // * A single "Stmt *" for the callee expression.
2416   //
2417   // * An array of getNumPreArgs() "Stmt *" for the pre-argument expressions.
2418   //
2419   // * An array of getNumArgs() "Stmt *" for the argument expressions.
2420   //
2421   // Note that we store the offset in bytes from the this pointer to the start
2422   // of the trailing objects. It would be perfectly possible to compute it
2423   // based on the dynamic kind of the CallExpr. However 1.) we have plenty of
2424   // space in the bit-fields of Stmt. 2.) It was benchmarked to be faster to
2425   // compute this once and then load the offset from the bit-fields of Stmt,
2426   // instead of re-computing the offset each time the trailing objects are
2427   // accessed.
2428
2429   /// Return a pointer to the start of the trailing array of "Stmt *".
2430   Stmt **getTrailingStmts() {
2431     return reinterpret_cast<Stmt **>(reinterpret_cast<char *>(this) +
2432                                      CallExprBits.OffsetToTrailingObjects);
2433   }
2434   Stmt *const *getTrailingStmts() const {
2435     return const_cast<CallExpr *>(this)->getTrailingStmts();
2436   }
2437
2438   /// Map a statement class to the appropriate offset in bytes from the
2439   /// this pointer to the trailing objects.
2440   static unsigned offsetToTrailingObjects(StmtClass SC);
2441
2442 public:
2443   enum class ADLCallKind : bool { NotADL, UsesADL };
2444   static constexpr ADLCallKind NotADL = ADLCallKind::NotADL;
2445   static constexpr ADLCallKind UsesADL = ADLCallKind::UsesADL;
2446
2447 protected:
2448   /// Build a call expression, assuming that appropriate storage has been
2449   /// allocated for the trailing objects.
2450   CallExpr(StmtClass SC, Expr *Fn, ArrayRef<Expr *> PreArgs,
2451            ArrayRef<Expr *> Args, QualType Ty, ExprValueKind VK,
2452            SourceLocation RParenLoc, unsigned MinNumArgs, ADLCallKind UsesADL);
2453
2454   /// Build an empty call expression, for deserialization.
2455   CallExpr(StmtClass SC, unsigned NumPreArgs, unsigned NumArgs,
2456            EmptyShell Empty);
2457
2458   /// Return the size in bytes needed for the trailing objects.
2459   /// Used by the derived classes to allocate the right amount of storage.
2460   static unsigned sizeOfTrailingObjects(unsigned NumPreArgs, unsigned NumArgs) {
2461     return (1 + NumPreArgs + NumArgs) * sizeof(Stmt *);
2462   }
2463
2464   Stmt *getPreArg(unsigned I) {
2465     assert(I < getNumPreArgs() && "Prearg access out of range!");
2466     return getTrailingStmts()[PREARGS_START + I];
2467   }
2468   const Stmt *getPreArg(unsigned I) const {
2469     assert(I < getNumPreArgs() && "Prearg access out of range!");
2470     return getTrailingStmts()[PREARGS_START + I];
2471   }
2472   void setPreArg(unsigned I, Stmt *PreArg) {
2473     assert(I < getNumPreArgs() && "Prearg access out of range!");
2474     getTrailingStmts()[PREARGS_START + I] = PreArg;
2475   }
2476
2477   unsigned getNumPreArgs() const { return CallExprBits.NumPreArgs; }
2478
2479 public:
2480   /// Create a call expression. Fn is the callee expression, Args is the
2481   /// argument array, Ty is the type of the call expression (which is *not*
2482   /// the return type in general), VK is the value kind of the call expression
2483   /// (lvalue, rvalue, ...), and RParenLoc is the location of the right
2484   /// parenthese in the call expression. MinNumArgs specifies the minimum
2485   /// number of arguments. The actual number of arguments will be the greater
2486   /// of Args.size() and MinNumArgs. This is used in a few places to allocate
2487   /// enough storage for the default arguments. UsesADL specifies whether the
2488   /// callee was found through argument-dependent lookup.
2489   ///
2490   /// Note that you can use CreateTemporary if you need a temporary call
2491   /// expression on the stack.
2492   static CallExpr *Create(const ASTContext &Ctx, Expr *Fn,
2493                           ArrayRef<Expr *> Args, QualType Ty, ExprValueKind VK,
2494                           SourceLocation RParenLoc, unsigned MinNumArgs = 0,
2495                           ADLCallKind UsesADL = NotADL);
2496
2497   /// Create a temporary call expression with no arguments in the memory
2498   /// pointed to by Mem. Mem must points to at least sizeof(CallExpr)
2499   /// + sizeof(Stmt *) bytes of storage, aligned to alignof(CallExpr):
2500   ///
2501   /// \code{.cpp}
2502   ///   llvm::AlignedCharArray<alignof(CallExpr),
2503   ///                          sizeof(CallExpr) + sizeof(Stmt *)> Buffer;
2504   ///   CallExpr *TheCall = CallExpr::CreateTemporary(Buffer.buffer, etc);
2505   /// \endcode
2506   static CallExpr *CreateTemporary(void *Mem, Expr *Fn, QualType Ty,
2507                                    ExprValueKind VK, SourceLocation RParenLoc,
2508                                    ADLCallKind UsesADL = NotADL);
2509
2510   /// Create an empty call expression, for deserialization.
2511   static CallExpr *CreateEmpty(const ASTContext &Ctx, unsigned NumArgs,
2512                                EmptyShell Empty);
2513
2514   Expr *getCallee() { return cast<Expr>(getTrailingStmts()[FN]); }
2515   const Expr *getCallee() const { return cast<Expr>(getTrailingStmts()[FN]); }
2516   void setCallee(Expr *F) { getTrailingStmts()[FN] = F; }
2517
2518   ADLCallKind getADLCallKind() const {
2519     return static_cast<ADLCallKind>(CallExprBits.UsesADL);
2520   }
2521   void setADLCallKind(ADLCallKind V = UsesADL) {
2522     CallExprBits.UsesADL = static_cast<bool>(V);
2523   }
2524   bool usesADL() const { return getADLCallKind() == UsesADL; }
2525
2526   Decl *getCalleeDecl() { return getCallee()->getReferencedDeclOfCallee(); }
2527   const Decl *getCalleeDecl() const {
2528     return getCallee()->getReferencedDeclOfCallee();
2529   }
2530
2531   /// If the callee is a FunctionDecl, return it. Otherwise return null.
2532   FunctionDecl *getDirectCallee() {
2533     return dyn_cast_or_null<FunctionDecl>(getCalleeDecl());
2534   }
2535   const FunctionDecl *getDirectCallee() const {
2536     return dyn_cast_or_null<FunctionDecl>(getCalleeDecl());
2537   }
2538
2539   /// getNumArgs - Return the number of actual arguments to this call.
2540   unsigned getNumArgs() const { return NumArgs; }
2541
2542   /// Retrieve the call arguments.
2543   Expr **getArgs() {
2544     return reinterpret_cast<Expr **>(getTrailingStmts() + PREARGS_START +
2545                                      getNumPreArgs());
2546   }
2547   const Expr *const *getArgs() const {
2548     return reinterpret_cast<const Expr *const *>(
2549         getTrailingStmts() + PREARGS_START + getNumPreArgs());
2550   }
2551
2552   /// getArg - Return the specified argument.
2553   Expr *getArg(unsigned Arg) {
2554     assert(Arg < getNumArgs() && "Arg access out of range!");
2555     return getArgs()[Arg];
2556   }
2557   const Expr *getArg(unsigned Arg) const {
2558     assert(Arg < getNumArgs() && "Arg access out of range!");
2559     return getArgs()[Arg];
2560   }
2561
2562   /// setArg - Set the specified argument.
2563   void setArg(unsigned Arg, Expr *ArgExpr) {
2564     assert(Arg < getNumArgs() && "Arg access out of range!");
2565     getArgs()[Arg] = ArgExpr;
2566   }
2567
2568   /// Reduce the number of arguments in this call expression. This is used for
2569   /// example during error recovery to drop extra arguments. There is no way
2570   /// to perform the opposite because: 1.) We don't track how much storage
2571   /// we have for the argument array 2.) This would potentially require growing
2572   /// the argument array, something we cannot support since the arguments are
2573   /// stored in a trailing array.
2574   void shrinkNumArgs(unsigned NewNumArgs) {
2575     assert((NewNumArgs <= getNumArgs()) &&
2576            "shrinkNumArgs cannot increase the number of arguments!");
2577     NumArgs = NewNumArgs;
2578   }
2579
2580   typedef ExprIterator arg_iterator;
2581   typedef ConstExprIterator const_arg_iterator;
2582   typedef llvm::iterator_range<arg_iterator> arg_range;
2583   typedef llvm::iterator_range<const_arg_iterator> const_arg_range;
2584
2585   arg_range arguments() { return arg_range(arg_begin(), arg_end()); }
2586   const_arg_range arguments() const {
2587     return const_arg_range(arg_begin(), arg_end());
2588   }
2589
2590   arg_iterator arg_begin() {
2591     return getTrailingStmts() + PREARGS_START + getNumPreArgs();
2592   }
2593   arg_iterator arg_end() { return arg_begin() + getNumArgs(); }
2594
2595   const_arg_iterator arg_begin() const {
2596     return getTrailingStmts() + PREARGS_START + getNumPreArgs();
2597   }
2598   const_arg_iterator arg_end() const { return arg_begin() + getNumArgs(); }
2599
2600   /// This method provides fast access to all the subexpressions of
2601   /// a CallExpr without going through the slower virtual child_iterator
2602   /// interface.  This provides efficient reverse iteration of the
2603   /// subexpressions.  This is currently used for CFG construction.
2604   ArrayRef<Stmt *> getRawSubExprs() {
2605     return llvm::makeArrayRef(getTrailingStmts(),
2606                               PREARGS_START + getNumPreArgs() + getNumArgs());
2607   }
2608
2609   /// getNumCommas - Return the number of commas that must have been present in
2610   /// this function call.
2611   unsigned getNumCommas() const { return getNumArgs() ? getNumArgs() - 1 : 0; }
2612
2613   /// getBuiltinCallee - If this is a call to a builtin, return the builtin ID
2614   /// of the callee. If not, return 0.
2615   unsigned getBuiltinCallee() const;
2616
2617   /// Returns \c true if this is a call to a builtin which does not
2618   /// evaluate side-effects within its arguments.
2619   bool isUnevaluatedBuiltinCall(const ASTContext &Ctx) const;
2620
2621   /// getCallReturnType - Get the return type of the call expr. This is not
2622   /// always the type of the expr itself, if the return type is a reference
2623   /// type.
2624   QualType getCallReturnType(const ASTContext &Ctx) const;
2625
2626   /// Returns the WarnUnusedResultAttr that is either declared on the called
2627   /// function, or its return type declaration.
2628   const Attr *getUnusedResultAttr(const ASTContext &Ctx) const;
2629
2630   /// Returns true if this call expression should warn on unused results.
2631   bool hasUnusedResultAttr(const ASTContext &Ctx) const {
2632     return getUnusedResultAttr(Ctx) != nullptr;
2633   }
2634
2635   SourceLocation getRParenLoc() const { return RParenLoc; }
2636   void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2637
2638   SourceLocation getBeginLoc() const LLVM_READONLY;
2639   SourceLocation getEndLoc() const LLVM_READONLY;
2640
2641   /// Return true if this is a call to __assume() or __builtin_assume() with
2642   /// a non-value-dependent constant parameter evaluating as false.
2643   bool isBuiltinAssumeFalse(const ASTContext &Ctx) const;
2644
2645   bool isCallToStdMove() const {
2646     const FunctionDecl *FD = getDirectCallee();
2647     return getNumArgs() == 1 && FD && FD->isInStdNamespace() &&
2648            FD->getIdentifier() && FD->getIdentifier()->isStr("move");
2649   }
2650
2651   static bool classof(const Stmt *T) {
2652     return T->getStmtClass() >= firstCallExprConstant &&
2653            T->getStmtClass() <= lastCallExprConstant;
2654   }
2655
2656   // Iterators
2657   child_range children() {
2658     return child_range(getTrailingStmts(), getTrailingStmts() + PREARGS_START +
2659                                                getNumPreArgs() + getNumArgs());
2660   }
2661
2662   const_child_range children() const {
2663     return const_child_range(getTrailingStmts(),
2664                              getTrailingStmts() + PREARGS_START +
2665                                  getNumPreArgs() + getNumArgs());
2666   }
2667 };
2668
2669 /// Extra data stored in some MemberExpr objects.
2670 struct MemberExprNameQualifier {
2671   /// The nested-name-specifier that qualifies the name, including
2672   /// source-location information.
2673   NestedNameSpecifierLoc QualifierLoc;
2674
2675   /// The DeclAccessPair through which the MemberDecl was found due to
2676   /// name qualifiers.
2677   DeclAccessPair FoundDecl;
2678 };
2679
2680 /// MemberExpr - [C99 6.5.2.3] Structure and Union Members.  X->F and X.F.
2681 ///
2682 class MemberExpr final
2683     : public Expr,
2684       private llvm::TrailingObjects<MemberExpr, MemberExprNameQualifier,
2685                                     ASTTemplateKWAndArgsInfo,
2686                                     TemplateArgumentLoc> {
2687   friend class ASTReader;
2688   friend class ASTStmtWriter;
2689   friend TrailingObjects;
2690
2691   /// Base - the expression for the base pointer or structure references.  In
2692   /// X.F, this is "X".
2693   Stmt *Base;
2694
2695   /// MemberDecl - This is the decl being referenced by the field/member name.
2696   /// In X.F, this is the decl referenced by F.
2697   ValueDecl *MemberDecl;
2698
2699   /// MemberDNLoc - Provides source/type location info for the
2700   /// declaration name embedded in MemberDecl.
2701   DeclarationNameLoc MemberDNLoc;
2702
2703   /// MemberLoc - This is the location of the member name.
2704   SourceLocation MemberLoc;
2705
2706   size_t numTrailingObjects(OverloadToken<MemberExprNameQualifier>) const {
2707     return hasQualifierOrFoundDecl();
2708   }
2709
2710   size_t numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
2711     return hasTemplateKWAndArgsInfo();
2712   }
2713
2714   bool hasQualifierOrFoundDecl() const {
2715     return MemberExprBits.HasQualifierOrFoundDecl;
2716   }
2717
2718   bool hasTemplateKWAndArgsInfo() const {
2719     return MemberExprBits.HasTemplateKWAndArgsInfo;
2720   }
2721
2722 public:
2723   MemberExpr(Expr *base, bool isarrow, SourceLocation operatorloc,
2724              ValueDecl *memberdecl, const DeclarationNameInfo &NameInfo,
2725              QualType ty, ExprValueKind VK, ExprObjectKind OK)
2726       : Expr(MemberExprClass, ty, VK, OK, base->isTypeDependent(),
2727              base->isValueDependent(), base->isInstantiationDependent(),
2728              base->containsUnexpandedParameterPack()),
2729         Base(base), MemberDecl(memberdecl), MemberDNLoc(NameInfo.getInfo()),
2730         MemberLoc(NameInfo.getLoc()) {
2731     assert(memberdecl->getDeclName() == NameInfo.getName());
2732     MemberExprBits.IsArrow = isarrow;
2733     MemberExprBits.HasQualifierOrFoundDecl = false;
2734     MemberExprBits.HasTemplateKWAndArgsInfo = false;
2735     MemberExprBits.HadMultipleCandidates = false;
2736     MemberExprBits.OperatorLoc = operatorloc;
2737   }
2738
2739   // NOTE: this constructor should be used only when it is known that
2740   // the member name can not provide additional syntactic info
2741   // (i.e., source locations for C++ operator names or type source info
2742   // for constructors, destructors and conversion operators).
2743   MemberExpr(Expr *base, bool isarrow, SourceLocation operatorloc,
2744              ValueDecl *memberdecl, SourceLocation l, QualType ty,
2745              ExprValueKind VK, ExprObjectKind OK)
2746       : Expr(MemberExprClass, ty, VK, OK, base->isTypeDependent(),
2747              base->isValueDependent(), base->isInstantiationDependent(),
2748              base->containsUnexpandedParameterPack()),
2749         Base(base), MemberDecl(memberdecl), MemberDNLoc(), MemberLoc(l) {
2750     MemberExprBits.IsArrow = isarrow;
2751     MemberExprBits.HasQualifierOrFoundDecl = false;
2752     MemberExprBits.HasTemplateKWAndArgsInfo = false;
2753     MemberExprBits.HadMultipleCandidates = false;
2754     MemberExprBits.OperatorLoc = operatorloc;
2755   }
2756
2757   static MemberExpr *Create(const ASTContext &C, Expr *base, bool isarrow,
2758                             SourceLocation OperatorLoc,
2759                             NestedNameSpecifierLoc QualifierLoc,
2760                             SourceLocation TemplateKWLoc, ValueDecl *memberdecl,
2761                             DeclAccessPair founddecl,
2762                             DeclarationNameInfo MemberNameInfo,
2763                             const TemplateArgumentListInfo *targs, QualType ty,
2764                             ExprValueKind VK, ExprObjectKind OK);
2765
2766   void setBase(Expr *E) { Base = E; }
2767   Expr *getBase() const { return cast<Expr>(Base); }
2768
2769   /// Retrieve the member declaration to which this expression refers.
2770   ///
2771   /// The returned declaration will be a FieldDecl or (in C++) a VarDecl (for
2772   /// static data members), a CXXMethodDecl, or an EnumConstantDecl.
2773   ValueDecl *getMemberDecl() const { return MemberDecl; }
2774   void setMemberDecl(ValueDecl *D) { MemberDecl = D; }
2775
2776   /// Retrieves the declaration found by lookup.
2777   DeclAccessPair getFoundDecl() const {
2778     if (!hasQualifierOrFoundDecl())
2779       return DeclAccessPair::make(getMemberDecl(),
2780                                   getMemberDecl()->getAccess());
2781     return getTrailingObjects<MemberExprNameQualifier>()->FoundDecl;
2782   }
2783
2784   /// Determines whether this member expression actually had
2785   /// a C++ nested-name-specifier prior to the name of the member, e.g.,
2786   /// x->Base::foo.
2787   bool hasQualifier() const { return getQualifier() != nullptr; }
2788
2789   /// If the member name was qualified, retrieves the
2790   /// nested-name-specifier that precedes the member name, with source-location
2791   /// information.
2792   NestedNameSpecifierLoc getQualifierLoc() const {
2793     if (!hasQualifierOrFoundDecl())
2794       return NestedNameSpecifierLoc();
2795     return getTrailingObjects<MemberExprNameQualifier>()->QualifierLoc;
2796   }
2797
2798   /// If the member name was qualified, retrieves the
2799   /// nested-name-specifier that precedes the member name. Otherwise, returns
2800   /// NULL.
2801   NestedNameSpecifier *getQualifier() const {
2802     return getQualifierLoc().getNestedNameSpecifier();
2803   }
2804
2805   /// Retrieve the location of the template keyword preceding
2806   /// the member name, if any.
2807   SourceLocation getTemplateKeywordLoc() const {
2808     if (!hasTemplateKWAndArgsInfo())
2809       return SourceLocation();
2810     return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->TemplateKWLoc;
2811   }
2812
2813   /// Retrieve the location of the left angle bracket starting the
2814   /// explicit template argument list following the member name, if any.
2815   SourceLocation getLAngleLoc() const {
2816     if (!hasTemplateKWAndArgsInfo())
2817       return SourceLocation();
2818     return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->LAngleLoc;
2819   }
2820
2821   /// Retrieve the location of the right angle bracket ending the
2822   /// explicit template argument list following the member name, if any.
2823   SourceLocation getRAngleLoc() const {
2824     if (!hasTemplateKWAndArgsInfo())
2825       return SourceLocation();
2826     return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->RAngleLoc;
2827   }
2828
2829   /// Determines whether the member name was preceded by the template keyword.
2830   bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
2831
2832   /// Determines whether the member name was followed by an
2833   /// explicit template argument list.
2834   bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
2835
2836   /// Copies the template arguments (if present) into the given
2837   /// structure.
2838   void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2839     if (hasExplicitTemplateArgs())
2840       getTrailingObjects<ASTTemplateKWAndArgsInfo>()->copyInto(
2841           getTrailingObjects<TemplateArgumentLoc>(), List);
2842   }
2843
2844   /// Retrieve the template arguments provided as part of this
2845   /// template-id.
2846   const TemplateArgumentLoc *getTemplateArgs() const {
2847     if (!hasExplicitTemplateArgs())
2848       return nullptr;
2849
2850     return getTrailingObjects<TemplateArgumentLoc>();
2851   }
2852
2853   /// Retrieve the number of template arguments provided as part of this
2854   /// template-id.
2855   unsigned getNumTemplateArgs() const {
2856     if (!hasExplicitTemplateArgs())
2857       return 0;
2858
2859     return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs;
2860   }
2861
2862   ArrayRef<TemplateArgumentLoc> template_arguments() const {
2863     return {getTemplateArgs(), getNumTemplateArgs()};
2864   }
2865
2866   /// Retrieve the member declaration name info.
2867   DeclarationNameInfo getMemberNameInfo() const {
2868     return DeclarationNameInfo(MemberDecl->getDeclName(),
2869                                MemberLoc, MemberDNLoc);
2870   }
2871
2872   SourceLocation getOperatorLoc() const { return MemberExprBits.OperatorLoc; }
2873
2874   bool isArrow() const { return MemberExprBits.IsArrow; }
2875   void setArrow(bool A) { MemberExprBits.IsArrow = A; }
2876
2877   /// getMemberLoc - Return the location of the "member", in X->F, it is the
2878   /// location of 'F'.
2879   SourceLocation getMemberLoc() const { return MemberLoc; }
2880   void setMemberLoc(SourceLocation L) { MemberLoc = L; }
2881
2882   SourceLocation getBeginLoc() const LLVM_READONLY;
2883   SourceLocation getEndLoc() const LLVM_READONLY;
2884
2885   SourceLocation getExprLoc() const LLVM_READONLY { return MemberLoc; }
2886
2887   /// Determine whether the base of this explicit is implicit.
2888   bool isImplicitAccess() const {
2889     return getBase() && getBase()->isImplicitCXXThis();
2890   }
2891
2892   /// Returns true if this member expression refers to a method that
2893   /// was resolved from an overloaded set having size greater than 1.
2894   bool hadMultipleCandidates() const {
2895     return MemberExprBits.HadMultipleCandidates;
2896   }
2897   /// Sets the flag telling whether this expression refers to
2898   /// a method that was resolved from an overloaded set having size
2899   /// greater than 1.
2900   void setHadMultipleCandidates(bool V = true) {
2901     MemberExprBits.HadMultipleCandidates = V;
2902   }
2903
2904   /// Returns true if virtual dispatch is performed.
2905   /// If the member access is fully qualified, (i.e. X::f()), virtual
2906   /// dispatching is not performed. In -fapple-kext mode qualified
2907   /// calls to virtual method will still go through the vtable.
2908   bool performsVirtualDispatch(const LangOptions &LO) const {
2909     return LO.AppleKext || !hasQualifier();
2910   }
2911
2912   static bool classof(const Stmt *T) {
2913     return T->getStmtClass() == MemberExprClass;
2914   }
2915
2916   // Iterators
2917   child_range children() { return child_range(&Base, &Base+1); }
2918   const_child_range children() const {
2919     return const_child_range(&Base, &Base + 1);
2920   }
2921 };
2922
2923 /// CompoundLiteralExpr - [C99 6.5.2.5]
2924 ///
2925 class CompoundLiteralExpr : public Expr {
2926   /// LParenLoc - If non-null, this is the location of the left paren in a
2927   /// compound literal like "(int){4}".  This can be null if this is a
2928   /// synthesized compound expression.
2929   SourceLocation LParenLoc;
2930
2931   /// The type as written.  This can be an incomplete array type, in
2932   /// which case the actual expression type will be different.
2933   /// The int part of the pair stores whether this expr is file scope.
2934   llvm::PointerIntPair<TypeSourceInfo *, 1, bool> TInfoAndScope;
2935   Stmt *Init;
2936 public:
2937   CompoundLiteralExpr(SourceLocation lparenloc, TypeSourceInfo *tinfo,
2938                       QualType T, ExprValueKind VK, Expr *init, bool fileScope)
2939     : Expr(CompoundLiteralExprClass, T, VK, OK_Ordinary,
2940            tinfo->getType()->isDependentType(),
2941            init->isValueDependent(),
2942            (init->isInstantiationDependent() ||
2943             tinfo->getType()->isInstantiationDependentType()),
2944            init->containsUnexpandedParameterPack()),
2945       LParenLoc(lparenloc), TInfoAndScope(tinfo, fileScope), Init(init) {}
2946
2947   /// Construct an empty compound literal.
2948   explicit CompoundLiteralExpr(EmptyShell Empty)
2949     : Expr(CompoundLiteralExprClass, Empty) { }
2950
2951   const Expr *getInitializer() const { return cast<Expr>(Init); }
2952   Expr *getInitializer() { return cast<Expr>(Init); }
2953   void setInitializer(Expr *E) { Init = E; }
2954
2955   bool isFileScope() const { return TInfoAndScope.getInt(); }
2956   void setFileScope(bool FS) { TInfoAndScope.setInt(FS); }
2957
2958   SourceLocation getLParenLoc() const { return LParenLoc; }
2959   void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2960
2961   TypeSourceInfo *getTypeSourceInfo() const {
2962     return TInfoAndScope.getPointer();
2963   }
2964   void setTypeSourceInfo(TypeSourceInfo *tinfo) {
2965     TInfoAndScope.setPointer(tinfo);
2966   }
2967
2968   SourceLocation getBeginLoc() const LLVM_READONLY {
2969     // FIXME: Init should never be null.
2970     if (!Init)
2971       return SourceLocation();
2972     if (LParenLoc.isInvalid())
2973       return Init->getBeginLoc();
2974     return LParenLoc;
2975   }
2976   SourceLocation getEndLoc() const LLVM_READONLY {
2977     // FIXME: Init should never be null.
2978     if (!Init)
2979       return SourceLocation();
2980     return Init->getEndLoc();
2981   }
2982
2983   static bool classof(const Stmt *T) {
2984     return T->getStmtClass() == CompoundLiteralExprClass;
2985   }
2986
2987   // Iterators
2988   child_range children() { return child_range(&Init, &Init+1); }
2989   const_child_range children() const {
2990     return const_child_range(&Init, &Init + 1);
2991   }
2992 };
2993
2994 /// CastExpr - Base class for type casts, including both implicit
2995 /// casts (ImplicitCastExpr) and explicit casts that have some
2996 /// representation in the source code (ExplicitCastExpr's derived
2997 /// classes).
2998 class CastExpr : public Expr {
2999   Stmt *Op;
3000
3001   bool CastConsistency() const;
3002
3003   const CXXBaseSpecifier * const *path_buffer() const {
3004     return const_cast<CastExpr*>(this)->path_buffer();
3005   }
3006   CXXBaseSpecifier **path_buffer();
3007
3008 protected:
3009   CastExpr(StmtClass SC, QualType ty, ExprValueKind VK, const CastKind kind,
3010            Expr *op, unsigned BasePathSize)
3011       : Expr(SC, ty, VK, OK_Ordinary,
3012              // Cast expressions are type-dependent if the type is
3013              // dependent (C++ [temp.dep.expr]p3).
3014              ty->isDependentType(),
3015              // Cast expressions are value-dependent if the type is
3016              // dependent or if the subexpression is value-dependent.
3017              ty->isDependentType() || (op && op->isValueDependent()),
3018              (ty->isInstantiationDependentType() ||
3019               (op && op->isInstantiationDependent())),
3020              // An implicit cast expression doesn't (lexically) contain an
3021              // unexpanded pack, even if its target type does.
3022              ((SC != ImplicitCastExprClass &&
3023                ty->containsUnexpandedParameterPack()) ||
3024               (op && op->containsUnexpandedParameterPack()))),
3025         Op(op) {
3026     CastExprBits.Kind = kind;
3027     CastExprBits.PartOfExplicitCast = false;
3028     CastExprBits.BasePathSize = BasePathSize;
3029     assert((CastExprBits.BasePathSize == BasePathSize) &&
3030            "BasePathSize overflow!");
3031     assert(CastConsistency());
3032   }
3033
3034   /// Construct an empty cast.
3035   CastExpr(StmtClass SC, EmptyShell Empty, unsigned BasePathSize)
3036     : Expr(SC, Empty) {
3037     CastExprBits.PartOfExplicitCast = false;
3038     CastExprBits.BasePathSize = BasePathSize;
3039     assert((CastExprBits.BasePathSize == BasePathSize) &&
3040            "BasePathSize overflow!");
3041   }
3042
3043 public:
3044   CastKind getCastKind() const { return (CastKind) CastExprBits.Kind; }
3045   void setCastKind(CastKind K) { CastExprBits.Kind = K; }
3046
3047   static const char *getCastKindName(CastKind CK);
3048   const char *getCastKindName() const { return getCastKindName(getCastKind()); }
3049
3050   Expr *getSubExpr() { return cast<Expr>(Op); }
3051   const Expr *getSubExpr() const { return cast<Expr>(Op); }
3052   void setSubExpr(Expr *E) { Op = E; }
3053
3054   /// Retrieve the cast subexpression as it was written in the source
3055   /// code, looking through any implicit casts or other intermediate nodes
3056   /// introduced by semantic analysis.
3057   Expr *getSubExprAsWritten();
3058   const Expr *getSubExprAsWritten() const {
3059     return const_cast<CastExpr *>(this)->getSubExprAsWritten();
3060   }
3061
3062   /// If this cast applies a user-defined conversion, retrieve the conversion
3063   /// function that it invokes.
3064   NamedDecl *getConversionFunction() const;
3065
3066   typedef CXXBaseSpecifier **path_iterator;
3067   typedef const CXXBaseSpecifier *const *path_const_iterator;
3068   bool path_empty() const { return path_size() == 0; }
3069   unsigned path_size() const { return CastExprBits.BasePathSize; }
3070   path_iterator path_begin() { return path_buffer(); }
3071   path_iterator path_end() { return path_buffer() + path_size(); }
3072   path_const_iterator path_begin() const { return path_buffer(); }
3073   path_const_iterator path_end() const { return path_buffer() + path_size(); }
3074
3075   const FieldDecl *getTargetUnionField() const {
3076     assert(getCastKind() == CK_ToUnion);
3077     return getTargetFieldForToUnionCast(getType(), getSubExpr()->getType());
3078   }
3079
3080   static const FieldDecl *getTargetFieldForToUnionCast(QualType unionType,
3081                                                        QualType opType);
3082   static const FieldDecl *getTargetFieldForToUnionCast(const RecordDecl *RD,
3083                                                        QualType opType);
3084
3085   static bool classof(const Stmt *T) {
3086     return T->getStmtClass() >= firstCastExprConstant &&
3087            T->getStmtClass() <= lastCastExprConstant;
3088   }
3089
3090   // Iterators
3091   child_range children() { return child_range(&Op, &Op+1); }
3092   const_child_range children() const { return const_child_range(&Op, &Op + 1); }
3093 };
3094
3095 /// ImplicitCastExpr - Allows us to explicitly represent implicit type
3096 /// conversions, which have no direct representation in the original
3097 /// source code. For example: converting T[]->T*, void f()->void
3098 /// (*f)(), float->double, short->int, etc.
3099 ///
3100 /// In C, implicit casts always produce rvalues. However, in C++, an
3101 /// implicit cast whose result is being bound to a reference will be
3102 /// an lvalue or xvalue. For example:
3103 ///
3104 /// @code
3105 /// class Base { };
3106 /// class Derived : public Base { };
3107 /// Derived &&ref();
3108 /// void f(Derived d) {
3109 ///   Base& b = d; // initializer is an ImplicitCastExpr
3110 ///                // to an lvalue of type Base
3111 ///   Base&& r = ref(); // initializer is an ImplicitCastExpr
3112 ///                     // to an xvalue of type Base
3113 /// }
3114 /// @endcode
3115 class ImplicitCastExpr final
3116     : public CastExpr,
3117       private llvm::TrailingObjects<ImplicitCastExpr, CXXBaseSpecifier *> {
3118
3119   ImplicitCastExpr(QualType ty, CastKind kind, Expr *op,
3120                    unsigned BasePathLength, ExprValueKind VK)
3121     : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, BasePathLength) { }
3122
3123   /// Construct an empty implicit cast.
3124   explicit ImplicitCastExpr(EmptyShell Shell, unsigned PathSize)
3125     : CastExpr(ImplicitCastExprClass, Shell, PathSize) { }
3126
3127 public:
3128   enum OnStack_t { OnStack };
3129   ImplicitCastExpr(OnStack_t _, QualType ty, CastKind kind, Expr *op,
3130                    ExprValueKind VK)
3131     : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, 0) {
3132   }
3133
3134   bool isPartOfExplicitCast() const { return CastExprBits.PartOfExplicitCast; }
3135   void setIsPartOfExplicitCast(bool PartOfExplicitCast) {
3136     CastExprBits.PartOfExplicitCast = PartOfExplicitCast;
3137   }
3138
3139   static ImplicitCastExpr *Create(const ASTContext &Context, QualType T,
3140                                   CastKind Kind, Expr *Operand,
3141                                   const CXXCastPath *BasePath,
3142                                   ExprValueKind Cat);
3143
3144   static ImplicitCastExpr *CreateEmpty(const ASTContext &Context,
3145                                        unsigned PathSize);
3146
3147   SourceLocation getBeginLoc() const LLVM_READONLY {
3148     return getSubExpr()->getBeginLoc();
3149   }
3150   SourceLocation getEndLoc() const LLVM_READONLY {
3151     return getSubExpr()->getEndLoc();
3152   }
3153
3154   static bool classof(const Stmt *T) {
3155     return T->getStmtClass() == ImplicitCastExprClass;
3156   }
3157
3158   friend TrailingObjects;
3159   friend class CastExpr;
3160 };
3161
3162 inline Expr *Expr::IgnoreImpCasts() {
3163   Expr *e = this;
3164   while (true)
3165     if (ImplicitCastExpr *ice = dyn_cast<ImplicitCastExpr>(e))
3166       e = ice->getSubExpr();
3167     else if (FullExpr *fe = dyn_cast<FullExpr>(e))
3168       e = fe->getSubExpr();
3169     else
3170       break;
3171   return e;
3172 }
3173
3174 /// ExplicitCastExpr - An explicit cast written in the source
3175 /// code.
3176 ///
3177 /// This class is effectively an abstract class, because it provides
3178 /// the basic representation of an explicitly-written cast without
3179 /// specifying which kind of cast (C cast, functional cast, static
3180 /// cast, etc.) was written; specific derived classes represent the
3181 /// particular style of cast and its location information.
3182 ///
3183 /// Unlike implicit casts, explicit cast nodes have two different
3184 /// types: the type that was written into the source code, and the
3185 /// actual type of the expression as determined by semantic
3186 /// analysis. These types may differ slightly. For example, in C++ one
3187 /// can cast to a reference type, which indicates that the resulting
3188 /// expression will be an lvalue or xvalue. The reference type, however,
3189 /// will not be used as the type of the expression.
3190 class ExplicitCastExpr : public CastExpr {
3191   /// TInfo - Source type info for the (written) type
3192   /// this expression is casting to.
3193   TypeSourceInfo *TInfo;
3194
3195 protected:
3196   ExplicitCastExpr(StmtClass SC, QualType exprTy, ExprValueKind VK,
3197                    CastKind kind, Expr *op, unsigned PathSize,
3198                    TypeSourceInfo *writtenTy)
3199     : CastExpr(SC, exprTy, VK, kind, op, PathSize), TInfo(writtenTy) {}
3200
3201   /// Construct an empty explicit cast.
3202   ExplicitCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize)
3203     : CastExpr(SC, Shell, PathSize) { }
3204
3205 public:
3206   /// getTypeInfoAsWritten - Returns the type source info for the type
3207   /// that this expression is casting to.
3208   TypeSourceInfo *getTypeInfoAsWritten() const { return TInfo; }
3209   void setTypeInfoAsWritten(TypeSourceInfo *writtenTy) { TInfo = writtenTy; }
3210
3211   /// getTypeAsWritten - Returns the type that this expression is
3212   /// casting to, as written in the source code.
3213   QualType getTypeAsWritten() const { return TInfo->getType(); }
3214
3215   static bool classof(const Stmt *T) {
3216      return T->getStmtClass() >= firstExplicitCastExprConstant &&
3217             T->getStmtClass() <= lastExplicitCastExprConstant;
3218   }
3219 };
3220
3221 /// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style
3222 /// cast in C++ (C++ [expr.cast]), which uses the syntax
3223 /// (Type)expr. For example: @c (int)f.
3224 class CStyleCastExpr final
3225     : public ExplicitCastExpr,
3226       private llvm::TrailingObjects<CStyleCastExpr, CXXBaseSpecifier *> {
3227   SourceLocation LPLoc; // the location of the left paren
3228   SourceLocation RPLoc; // the location of the right paren
3229
3230   CStyleCastExpr(QualType exprTy, ExprValueKind vk, CastKind kind, Expr *op,
3231                  unsigned PathSize, TypeSourceInfo *writtenTy,
3232                  SourceLocation l, SourceLocation r)
3233     : ExplicitCastExpr(CStyleCastExprClass, exprTy, vk, kind, op, PathSize,
3234                        writtenTy), LPLoc(l), RPLoc(r) {}
3235
3236   /// Construct an empty C-style explicit cast.
3237   explicit CStyleCastExpr(EmptyShell Shell, unsigned PathSize)
3238     : ExplicitCastExpr(CStyleCastExprClass, Shell, PathSize) { }
3239
3240 public:
3241   static CStyleCastExpr *Create(const ASTContext &Context, QualType T,
3242                                 ExprValueKind VK, CastKind K,
3243                                 Expr *Op, const CXXCastPath *BasePath,
3244                                 TypeSourceInfo *WrittenTy, SourceLocation L,
3245                                 SourceLocation R);
3246
3247   static CStyleCastExpr *CreateEmpty(const ASTContext &Context,
3248                                      unsigned PathSize);
3249
3250   SourceLocation getLParenLoc() const { return LPLoc; }
3251   void setLParenLoc(SourceLocation L) { LPLoc = L; }
3252
3253   SourceLocation getRParenLoc() const { return RPLoc; }
3254   void setRParenLoc(SourceLocation L) { RPLoc = L; }
3255
3256   SourceLocation getBeginLoc() const LLVM_READONLY { return LPLoc; }
3257   SourceLocation getEndLoc() const LLVM_READONLY {
3258     return getSubExpr()->getEndLoc();
3259   }
3260
3261   static bool classof(const Stmt *T) {
3262     return T->getStmtClass() == CStyleCastExprClass;
3263   }
3264
3265   friend TrailingObjects;
3266   friend class CastExpr;
3267 };
3268
3269 /// A builtin binary operation expression such as "x + y" or "x <= y".
3270 ///
3271 /// This expression node kind describes a builtin binary operation,
3272 /// such as "x + y" for integer values "x" and "y". The operands will
3273 /// already have been converted to appropriate types (e.g., by
3274 /// performing promotions or conversions).
3275 ///
3276 /// In C++, where operators may be overloaded, a different kind of
3277 /// expression node (CXXOperatorCallExpr) is used to express the
3278 /// invocation of an overloaded operator with operator syntax. Within
3279 /// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is
3280 /// used to store an expression "x + y" depends on the subexpressions
3281 /// for x and y. If neither x or y is type-dependent, and the "+"
3282 /// operator resolves to a built-in operation, BinaryOperator will be
3283 /// used to express the computation (x and y may still be
3284 /// value-dependent). If either x or y is type-dependent, or if the
3285 /// "+" resolves to an overloaded operator, CXXOperatorCallExpr will
3286 /// be used to express the computation.
3287 class BinaryOperator : public Expr {
3288   enum { LHS, RHS, END_EXPR };
3289   Stmt *SubExprs[END_EXPR];
3290
3291 public:
3292   typedef BinaryOperatorKind Opcode;
3293
3294   BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
3295                  ExprValueKind VK, ExprObjectKind OK,
3296                  SourceLocation opLoc, FPOptions FPFeatures)
3297     : Expr(BinaryOperatorClass, ResTy, VK, OK,
3298            lhs->isTypeDependent() || rhs->isTypeDependent(),
3299            lhs->isValueDependent() || rhs->isValueDependent(),
3300            (lhs->isInstantiationDependent() ||
3301             rhs->isInstantiationDependent()),
3302            (lhs->containsUnexpandedParameterPack() ||
3303             rhs->containsUnexpandedParameterPack())) {
3304     BinaryOperatorBits.Opc = opc;
3305     BinaryOperatorBits.FPFeatures = FPFeatures.getInt();
3306     BinaryOperatorBits.OpLoc = opLoc;
3307     SubExprs[LHS] = lhs;
3308     SubExprs[RHS] = rhs;
3309     assert(!isCompoundAssignmentOp() &&
3310            "Use CompoundAssignOperator for compound assignments");
3311   }
3312
3313   /// Construct an empty binary operator.
3314   explicit BinaryOperator(EmptyShell Empty) : Expr(BinaryOperatorClass, Empty) {
3315     BinaryOperatorBits.Opc = BO_Comma;
3316   }
3317
3318   SourceLocation getExprLoc() const { return getOperatorLoc(); }
3319   SourceLocation getOperatorLoc() const { return BinaryOperatorBits.OpLoc; }
3320   void setOperatorLoc(SourceLocation L) { BinaryOperatorBits.OpLoc = L; }
3321
3322   Opcode getOpcode() const {
3323     return static_cast<Opcode>(BinaryOperatorBits.Opc);
3324   }
3325   void setOpcode(Opcode Opc) { BinaryOperatorBits.Opc = Opc; }
3326
3327   Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
3328   void setLHS(Expr *E) { SubExprs[LHS] = E; }
3329   Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
3330   void setRHS(Expr *E) { SubExprs[RHS] = E; }
3331
3332   SourceLocation getBeginLoc() const LLVM_READONLY {
3333     return getLHS()->getBeginLoc();
3334   }
3335   SourceLocation getEndLoc() const LLVM_READONLY {
3336     return getRHS()->getEndLoc();
3337   }
3338
3339   /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
3340   /// corresponds to, e.g. "<<=".
3341   static StringRef getOpcodeStr(Opcode Op);
3342
3343   StringRef getOpcodeStr() const { return getOpcodeStr(getOpcode()); }
3344
3345   /// Retrieve the binary opcode that corresponds to the given
3346   /// overloaded operator.
3347   static Opcode getOverloadedOpcode(OverloadedOperatorKind OO);
3348
3349   /// Retrieve the overloaded operator kind that corresponds to
3350   /// the given binary opcode.
3351   static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
3352
3353   /// predicates to categorize the respective opcodes.
3354   static bool isPtrMemOp(Opcode Opc) {
3355     return Opc == BO_PtrMemD || Opc == BO_PtrMemI;
3356   }
3357   bool isPtrMemOp() const { return isPtrMemOp(getOpcode()); }
3358
3359   static bool isMultiplicativeOp(Opcode Opc) {
3360     return Opc >= BO_Mul && Opc <= BO_Rem;
3361   }
3362   bool isMultiplicativeOp() const { return isMultiplicativeOp(getOpcode()); }
3363   static bool isAdditiveOp(Opcode Opc) { return Opc == BO_Add || Opc==BO_Sub; }
3364   bool isAdditiveOp() const { return isAdditiveOp(getOpcode()); }
3365   static bool isShiftOp(Opcode Opc) { return Opc == BO_Shl || Opc == BO_Shr; }
3366   bool isShiftOp() const { return isShiftOp(getOpcode()); }
3367
3368   static bool isBitwiseOp(Opcode Opc) { return Opc >= BO_And && Opc <= BO_Or; }
3369   bool isBitwiseOp() const { return isBitwiseOp(getOpcode()); }
3370
3371   static bool isRelationalOp(Opcode Opc) { return Opc >= BO_LT && Opc<=BO_GE; }
3372   bool isRelationalOp() const { return isRelationalOp(getOpcode()); }
3373
3374   static bool isEqualityOp(Opcode Opc) { return Opc == BO_EQ || Opc == BO_NE; }
3375   bool isEqualityOp() const { return isEqualityOp(getOpcode()); }
3376
3377   static bool isComparisonOp(Opcode Opc) { return Opc >= BO_Cmp && Opc<=BO_NE; }
3378   bool isComparisonOp() const { return isComparisonOp(getOpcode()); }
3379
3380   static Opcode negateComparisonOp(Opcode Opc) {
3381     switch (Opc) {
3382     default:
3383       llvm_unreachable("Not a comparison operator.");
3384     case BO_LT: return BO_GE;
3385     case BO_GT: return BO_LE;
3386     case BO_LE: return BO_GT;
3387     case BO_GE: return BO_LT;
3388     case BO_EQ: return BO_NE;
3389     case BO_NE: return BO_EQ;
3390     }
3391   }
3392
3393   static Opcode reverseComparisonOp(Opcode Opc) {
3394     switch (Opc) {
3395     default:
3396       llvm_unreachable("Not a comparison operator.");
3397     case BO_LT: return BO_GT;
3398     case BO_GT: return BO_LT;
3399     case BO_LE: return BO_GE;
3400     case BO_GE: return BO_LE;
3401     case BO_EQ:
3402     case BO_NE:
3403       return Opc;
3404     }
3405   }
3406
3407   static bool isLogicalOp(Opcode Opc) { return Opc == BO_LAnd || Opc==BO_LOr; }
3408   bool isLogicalOp() const { return isLogicalOp(getOpcode()); }
3409
3410   static bool isAssignmentOp(Opcode Opc) {
3411     return Opc >= BO_Assign && Opc <= BO_OrAssign;
3412   }
3413   bool isAssignmentOp() const { return isAssignmentOp(getOpcode()); }
3414
3415   static bool isCompoundAssignmentOp(Opcode Opc) {
3416     return Opc > BO_Assign && Opc <= BO_OrAssign;
3417   }
3418   bool isCompoundAssignmentOp() const {
3419     return isCompoundAssignmentOp(getOpcode());
3420   }
3421   static Opcode getOpForCompoundAssignment(Opcode Opc) {
3422     assert(isCompoundAssignmentOp(Opc));
3423     if (Opc >= BO_AndAssign)
3424       return Opcode(unsigned(Opc) - BO_AndAssign + BO_And);
3425     else
3426       return Opcode(unsigned(Opc) - BO_MulAssign + BO_Mul);
3427   }
3428
3429   static bool isShiftAssignOp(Opcode Opc) {
3430     return Opc == BO_ShlAssign || Opc == BO_ShrAssign;
3431   }
3432   bool isShiftAssignOp() const {
3433     return isShiftAssignOp(getOpcode());
3434   }
3435
3436   // Return true if a binary operator using the specified opcode and operands
3437   // would match the 'p = (i8*)nullptr + n' idiom for casting a pointer-sized
3438   // integer to a pointer.
3439   static bool isNullPointerArithmeticExtension(ASTContext &Ctx, Opcode Opc,
3440                                                Expr *LHS, Expr *RHS);
3441
3442   static bool classof(const Stmt *S) {
3443     return S->getStmtClass() >= firstBinaryOperatorConstant &&
3444            S->getStmtClass() <= lastBinaryOperatorConstant;
3445   }
3446
3447   // Iterators
3448   child_range children() {
3449     return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
3450   }
3451   const_child_range children() const {
3452     return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
3453   }
3454
3455   // Set the FP contractability status of this operator. Only meaningful for
3456   // operations on floating point types.
3457   void setFPFeatures(FPOptions F) {
3458     BinaryOperatorBits.FPFeatures = F.getInt();
3459   }
3460
3461   FPOptions getFPFeatures() const {
3462     return FPOptions(BinaryOperatorBits.FPFeatures);
3463   }
3464
3465   // Get the FP contractability status of this operator. Only meaningful for
3466   // operations on floating point types.
3467   bool isFPContractableWithinStatement() const {
3468     return getFPFeatures().allowFPContractWithinStatement();
3469   }
3470
3471   // Get the FENV_ACCESS status of this operator. Only meaningful for
3472   // operations on floating point types.
3473   bool isFEnvAccessOn() const { return getFPFeatures().allowFEnvAccess(); }
3474
3475 protected:
3476   BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
3477                  ExprValueKind VK, ExprObjectKind OK,
3478                  SourceLocation opLoc, FPOptions FPFeatures, bool dead2)
3479     : Expr(CompoundAssignOperatorClass, ResTy, VK, OK,
3480            lhs->isTypeDependent() || rhs->isTypeDependent(),
3481            lhs->isValueDependent() || rhs->isValueDependent(),
3482            (lhs->isInstantiationDependent() ||
3483             rhs->isInstantiationDependent()),
3484            (lhs->containsUnexpandedParameterPack() ||
3485             rhs->containsUnexpandedParameterPack())) {
3486     BinaryOperatorBits.Opc = opc;
3487     BinaryOperatorBits.FPFeatures = FPFeatures.getInt();
3488     BinaryOperatorBits.OpLoc = opLoc;
3489     SubExprs[LHS] = lhs;
3490     SubExprs[RHS] = rhs;
3491   }
3492
3493   BinaryOperator(StmtClass SC, EmptyShell Empty) : Expr(SC, Empty) {
3494     BinaryOperatorBits.Opc = BO_MulAssign;
3495   }
3496 };
3497
3498 /// CompoundAssignOperator - For compound assignments (e.g. +=), we keep
3499 /// track of the type the operation is performed in.  Due to the semantics of
3500 /// these operators, the operands are promoted, the arithmetic performed, an
3501 /// implicit conversion back to the result type done, then the assignment takes
3502 /// place.  This captures the intermediate type which the computation is done
3503 /// in.
3504 class CompoundAssignOperator : public BinaryOperator {
3505   QualType ComputationLHSType;
3506   QualType ComputationResultType;
3507 public:
3508   CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResType,
3509                          ExprValueKind VK, ExprObjectKind OK,
3510                          QualType CompLHSType, QualType CompResultType,
3511                          SourceLocation OpLoc, FPOptions FPFeatures)
3512     : BinaryOperator(lhs, rhs, opc, ResType, VK, OK, OpLoc, FPFeatures,
3513                      true),
3514       ComputationLHSType(CompLHSType),
3515       ComputationResultType(CompResultType) {
3516     assert(isCompoundAssignmentOp() &&
3517            "Only should be used for compound assignments");
3518   }
3519
3520   /// Build an empty compound assignment operator expression.
3521   explicit CompoundAssignOperator(EmptyShell Empty)
3522     : BinaryOperator(CompoundAssignOperatorClass, Empty) { }
3523
3524   // The two computation types are the type the LHS is converted
3525   // to for the computation and the type of the result; the two are
3526   // distinct in a few cases (specifically, int+=ptr and ptr-=ptr).
3527   QualType getComputationLHSType() const { return ComputationLHSType; }
3528   void setComputationLHSType(QualType T) { ComputationLHSType = T; }
3529
3530   QualType getComputationResultType() const { return ComputationResultType; }
3531   void setComputationResultType(QualType T) { ComputationResultType = T; }
3532
3533   static bool classof(const Stmt *S) {
3534     return S->getStmtClass() == CompoundAssignOperatorClass;
3535   }
3536 };
3537
3538 /// AbstractConditionalOperator - An abstract base class for
3539 /// ConditionalOperator and BinaryConditionalOperator.
3540 class AbstractConditionalOperator : public Expr {
3541   SourceLocation QuestionLoc, ColonLoc;
3542   friend class ASTStmtReader;
3543
3544 protected:
3545   AbstractConditionalOperator(StmtClass SC, QualType T,
3546                               ExprValueKind VK, ExprObjectKind OK,
3547                               bool TD, bool VD, bool ID,
3548                               bool ContainsUnexpandedParameterPack,
3549                               SourceLocation qloc,
3550                               SourceLocation cloc)
3551     : Expr(SC, T, VK, OK, TD, VD, ID, ContainsUnexpandedParameterPack),
3552       QuestionLoc(qloc), ColonLoc(cloc) {}
3553
3554   AbstractConditionalOperator(StmtClass SC, EmptyShell Empty)
3555     : Expr(SC, Empty) { }
3556
3557 public:
3558   // getCond - Return the expression representing the condition for
3559   //   the ?: operator.
3560   Expr *getCond() const;
3561
3562   // getTrueExpr - Return the subexpression representing the value of
3563   //   the expression if the condition evaluates to true.
3564   Expr *getTrueExpr() const;
3565
3566   // getFalseExpr - Return the subexpression representing the value of
3567   //   the expression if the condition evaluates to false.  This is
3568   //   the same as getRHS.
3569   Expr *getFalseExpr() const;
3570
3571   SourceLocation getQuestionLoc() const { return QuestionLoc; }
3572   SourceLocation getColonLoc() const { return ColonLoc; }
3573
3574   static bool classof(const Stmt *T) {
3575     return T->getStmtClass() == ConditionalOperatorClass ||
3576            T->getStmtClass() == BinaryConditionalOperatorClass;
3577   }
3578 };
3579
3580 /// ConditionalOperator - The ?: ternary operator.  The GNU "missing
3581 /// middle" extension is a BinaryConditionalOperator.
3582 class ConditionalOperator : public AbstractConditionalOperator {
3583   enum { COND, LHS, RHS, END_EXPR };
3584   Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
3585
3586   friend class ASTStmtReader;
3587 public:
3588   ConditionalOperator(Expr *cond, SourceLocation QLoc, Expr *lhs,
3589                       SourceLocation CLoc, Expr *rhs,
3590                       QualType t, ExprValueKind VK, ExprObjectKind OK)
3591     : AbstractConditionalOperator(ConditionalOperatorClass, t, VK, OK,
3592            // FIXME: the type of the conditional operator doesn't
3593            // depend on the type of the conditional, but the standard
3594            // seems to imply that it could. File a bug!
3595            (lhs->isTypeDependent() || rhs->isTypeDependent()),
3596            (cond->isValueDependent() || lhs->isValueDependent() ||
3597             rhs->isValueDependent()),
3598            (cond->isInstantiationDependent() ||
3599             lhs->isInstantiationDependent() ||
3600             rhs->isInstantiationDependent()),
3601            (cond->containsUnexpandedParameterPack() ||
3602             lhs->containsUnexpandedParameterPack() ||
3603             rhs->containsUnexpandedParameterPack()),
3604                                   QLoc, CLoc) {
3605     SubExprs[COND] = cond;
3606     SubExprs[LHS] = lhs;
3607     SubExprs[RHS] = rhs;
3608   }
3609
3610   /// Build an empty conditional operator.
3611   explicit ConditionalOperator(EmptyShell Empty)
3612     : AbstractConditionalOperator(ConditionalOperatorClass, Empty) { }
3613
3614   // getCond - Return the expression representing the condition for
3615   //   the ?: operator.
3616   Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
3617
3618   // getTrueExpr - Return the subexpression representing the value of
3619   //   the expression if the condition evaluates to true.
3620   Expr *getTrueExpr() const { return cast<Expr>(SubExprs[LHS]); }
3621
3622   // getFalseExpr - Return the subexpression representing the value of
3623   //   the expression if the condition evaluates to false.  This is
3624   //   the same as getRHS.
3625   Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); }
3626
3627   Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
3628   Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
3629
3630   SourceLocation getBeginLoc() const LLVM_READONLY {
3631     return getCond()->getBeginLoc();
3632   }
3633   SourceLocation getEndLoc() const LLVM_READONLY {
3634     return getRHS()->getEndLoc();
3635   }
3636
3637   static bool classof(const Stmt *T) {
3638     return T->getStmtClass() == ConditionalOperatorClass;
3639   }
3640
3641   // Iterators
3642   child_range children() {
3643     return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
3644   }
3645   const_child_range children() const {
3646     return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
3647   }
3648 };
3649
3650 /// BinaryConditionalOperator - The GNU extension to the conditional
3651 /// operator which allows the middle operand to be omitted.
3652 ///
3653 /// This is a different expression kind on the assumption that almost
3654 /// every client ends up needing to know that these are different.
3655 class BinaryConditionalOperator : public AbstractConditionalOperator {
3656   enum { COMMON, COND, LHS, RHS, NUM_SUBEXPRS };
3657
3658   /// - the common condition/left-hand-side expression, which will be
3659   ///   evaluated as the opaque value
3660   /// - the condition, expressed in terms of the opaque value
3661   /// - the left-hand-side, expressed in terms of the opaque value
3662   /// - the right-hand-side
3663   Stmt *SubExprs[NUM_SUBEXPRS];
3664   OpaqueValueExpr *OpaqueValue;
3665
3666   friend class ASTStmtReader;
3667 public:
3668   BinaryConditionalOperator(Expr *common, OpaqueValueExpr *opaqueValue,
3669                             Expr *cond, Expr *lhs, Expr *rhs,
3670                             SourceLocation qloc, SourceLocation cloc,
3671                             QualType t, ExprValueKind VK, ExprObjectKind OK)
3672     : AbstractConditionalOperator(BinaryConditionalOperatorClass, t, VK, OK,
3673            (common->isTypeDependent() || rhs->isTypeDependent()),
3674            (common->isValueDependent() || rhs->isValueDependent()),
3675            (common->isInstantiationDependent() ||
3676             rhs->isInstantiationDependent()),
3677            (common->containsUnexpandedParameterPack() ||
3678             rhs->containsUnexpandedParameterPack()),
3679                                   qloc, cloc),
3680       OpaqueValue(opaqueValue) {
3681     SubExprs[COMMON] = common;
3682     SubExprs[COND] = cond;
3683     SubExprs[LHS] = lhs;
3684     SubExprs[RHS] = rhs;
3685     assert(OpaqueValue->getSourceExpr() == common && "Wrong opaque value");
3686   }
3687
3688   /// Build an empty conditional operator.
3689   explicit BinaryConditionalOperator(EmptyShell Empty)
3690     : AbstractConditionalOperator(BinaryConditionalOperatorClass, Empty) { }
3691
3692   /// getCommon - Return the common expression, written to the
3693   ///   left of the condition.  The opaque value will be bound to the
3694   ///   result of this expression.
3695   Expr *getCommon() const { return cast<Expr>(SubExprs[COMMON]); }
3696
3697   /// getOpaqueValue - Return the opaque value placeholder.
3698   OpaqueValueExpr *getOpaqueValue() const { return OpaqueValue; }
3699
3700   /// getCond - Return the condition expression; this is defined
3701   ///   in terms of the opaque value.
3702   Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
3703
3704   /// getTrueExpr - Return the subexpression which will be
3705   ///   evaluated if the condition evaluates to true;  this is defined
3706   ///   in terms of the opaque value.
3707   Expr *getTrueExpr() const {
3708     return cast<Expr>(SubExprs[LHS]);
3709   }
3710
3711   /// getFalseExpr - Return the subexpression which will be
3712   ///   evaluated if the condnition evaluates to false; this is
3713   ///   defined in terms of the opaque value.
3714   Expr *getFalseExpr() const {
3715     return cast<Expr>(SubExprs[RHS]);
3716   }
3717
3718   SourceLocation getBeginLoc() const LLVM_READONLY {
3719     return getCommon()->getBeginLoc();
3720   }
3721   SourceLocation getEndLoc() const LLVM_READONLY {
3722     return getFalseExpr()->getEndLoc();
3723   }
3724
3725   static bool classof(const Stmt *T) {
3726     return T->getStmtClass() == BinaryConditionalOperatorClass;
3727   }
3728
3729   // Iterators
3730   child_range children() {
3731     return child_range(SubExprs, SubExprs + NUM_SUBEXPRS);
3732   }
3733   const_child_range children() const {
3734     return const_child_range(SubExprs, SubExprs + NUM_SUBEXPRS);
3735   }
3736 };
3737
3738 inline Expr *AbstractConditionalOperator::getCond() const {
3739   if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this))
3740     return co->getCond();
3741   return cast<BinaryConditionalOperator>(this)->getCond();
3742 }
3743
3744 inline Expr *AbstractConditionalOperator::getTrueExpr() const {
3745   if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this))
3746     return co->getTrueExpr();
3747   return cast<BinaryConditionalOperator>(this)->getTrueExpr();
3748 }
3749
3750 inline Expr *AbstractConditionalOperator::getFalseExpr() const {
3751   if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this))
3752     return co->getFalseExpr();
3753   return cast<BinaryConditionalOperator>(this)->getFalseExpr();
3754 }
3755
3756 /// AddrLabelExpr - The GNU address of label extension, representing &&label.
3757 class AddrLabelExpr : public Expr {
3758   SourceLocation AmpAmpLoc, LabelLoc;
3759   LabelDecl *Label;
3760 public:
3761   AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelDecl *L,
3762                 QualType t)
3763     : Expr(AddrLabelExprClass, t, VK_RValue, OK_Ordinary, false, false, false,
3764            false),
3765       AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {}
3766
3767   /// Build an empty address of a label expression.
3768   explicit AddrLabelExpr(EmptyShell Empty)
3769     : Expr(AddrLabelExprClass, Empty) { }
3770
3771   SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; }
3772   void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; }
3773   SourceLocation getLabelLoc() const { return LabelLoc; }
3774   void setLabelLoc(SourceLocation L) { LabelLoc = L; }
3775
3776   SourceLocation getBeginLoc() const LLVM_READONLY { return AmpAmpLoc; }
3777   SourceLocation getEndLoc() const LLVM_READONLY { return LabelLoc; }
3778
3779   LabelDecl *getLabel() const { return Label; }
3780   void setLabel(LabelDecl *L) { Label = L; }
3781
3782   static bool classof(const Stmt *T) {
3783     return T->getStmtClass() == AddrLabelExprClass;
3784   }
3785
3786   // Iterators
3787   child_range children() {
3788     return child_range(child_iterator(), child_iterator());
3789   }
3790   const_child_range children() const {
3791     return const_child_range(const_child_iterator(), const_child_iterator());
3792   }
3793 };
3794
3795 /// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
3796 /// The StmtExpr contains a single CompoundStmt node, which it evaluates and
3797 /// takes the value of the last subexpression.
3798 ///
3799 /// A StmtExpr is always an r-value; values "returned" out of a
3800 /// StmtExpr will be copied.
3801 class StmtExpr : public Expr {
3802   Stmt *SubStmt;
3803   SourceLocation LParenLoc, RParenLoc;
3804 public:
3805   // FIXME: Does type-dependence need to be computed differently?
3806   // FIXME: Do we need to compute instantiation instantiation-dependence for
3807   // statements? (ugh!)
3808   StmtExpr(CompoundStmt *substmt, QualType T,
3809            SourceLocation lp, SourceLocation rp) :
3810     Expr(StmtExprClass, T, VK_RValue, OK_Ordinary,
3811          T->isDependentType(), false, false, false),
3812     SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) { }
3813
3814   /// Build an empty statement expression.
3815   explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { }
3816
3817   CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); }
3818   const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); }
3819   void setSubStmt(CompoundStmt *S) { SubStmt = S; }
3820
3821   SourceLocation getBeginLoc() const LLVM_READONLY { return LParenLoc; }
3822   SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
3823
3824   SourceLocation getLParenLoc() const { return LParenLoc; }
3825   void setLParenLoc(SourceLocation L) { LParenLoc = L; }
3826   SourceLocation getRParenLoc() const { return RParenLoc; }
3827   void setRParenLoc(SourceLocation L) { RParenLoc = L; }
3828
3829   static bool classof(const Stmt *T) {
3830     return T->getStmtClass() == StmtExprClass;
3831   }
3832
3833   // Iterators
3834   child_range children() { return child_range(&SubStmt, &SubStmt+1); }
3835   const_child_range children() const {
3836     return const_child_range(&SubStmt, &SubStmt + 1);
3837   }
3838 };
3839
3840 /// ShuffleVectorExpr - clang-specific builtin-in function
3841 /// __builtin_shufflevector.
3842 /// This AST node represents a operator that does a constant
3843 /// shuffle, similar to LLVM's shufflevector instruction. It takes
3844 /// two vectors and a variable number of constant indices,
3845 /// and returns the appropriately shuffled vector.
3846 class ShuffleVectorExpr : public Expr {
3847   SourceLocation BuiltinLoc, RParenLoc;
3848
3849   // SubExprs - the list of values passed to the __builtin_shufflevector
3850   // function. The first two are vectors, and the rest are constant
3851   // indices.  The number of values in this list is always
3852   // 2+the number of indices in the vector type.
3853   Stmt **SubExprs;
3854   unsigned NumExprs;
3855
3856 public:
3857   ShuffleVectorExpr(const ASTContext &C, ArrayRef<Expr*> args, QualType Type,
3858                     SourceLocation BLoc, SourceLocation RP);
3859
3860   /// Build an empty vector-shuffle expression.
3861   explicit ShuffleVectorExpr(EmptyShell Empty)
3862     : Expr(ShuffleVectorExprClass, Empty), SubExprs(nullptr) { }
3863
3864   SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
3865   void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
3866
3867   SourceLocation getRParenLoc() const { return RParenLoc; }
3868   void setRParenLoc(SourceLocation L) { RParenLoc = L; }
3869
3870   SourceLocation getBeginLoc() const LLVM_READONLY { return BuiltinLoc; }
3871   SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
3872
3873   static bool classof(const Stmt *T) {
3874     return T->getStmtClass() == ShuffleVectorExprClass;
3875   }
3876
3877   /// getNumSubExprs - Return the size of the SubExprs array.  This includes the
3878   /// constant expression, the actual arguments passed in, and the function
3879   /// pointers.
3880   unsigned getNumSubExprs() const { return NumExprs; }
3881
3882   /// Retrieve the array of expressions.
3883   Expr **getSubExprs() { return reinterpret_cast<Expr **>(SubExprs); }
3884
3885   /// getExpr - Return the Expr at the specified index.
3886   Expr *getExpr(unsigned Index) {
3887     assert((Index < NumExprs) && "Arg access out of range!");
3888     return cast<Expr>(SubExprs[Index]);
3889   }
3890   const Expr *getExpr(unsigned Index) const {
3891     assert((Index < NumExprs) && "Arg access out of range!");
3892     return cast<Expr>(SubExprs[Index]);
3893   }
3894
3895   void setExprs(const ASTContext &C, ArrayRef<Expr *> Exprs);
3896
3897   llvm::APSInt getShuffleMaskIdx(const ASTContext &Ctx, unsigned N) const {
3898     assert((N < NumExprs - 2) && "Shuffle idx out of range!");
3899     return getExpr(N+2)->EvaluateKnownConstInt(Ctx);
3900   }
3901
3902   // Iterators
3903   child_range children() {
3904     return child_range(&SubExprs[0], &SubExprs[0]+NumExprs);
3905   }
3906   const_child_range children() const {
3907     return const_child_range(&SubExprs[0], &SubExprs[0] + NumExprs);
3908   }
3909 };
3910
3911 /// ConvertVectorExpr - Clang builtin function __builtin_convertvector
3912 /// This AST node provides support for converting a vector type to another
3913 /// vector type of the same arity.
3914 class ConvertVectorExpr : public Expr {
3915 private:
3916   Stmt *SrcExpr;
3917   TypeSourceInfo *TInfo;
3918   SourceLocation BuiltinLoc, RParenLoc;
3919
3920   friend class ASTReader;
3921   friend class ASTStmtReader;
3922   explicit ConvertVectorExpr(EmptyShell Empty) : Expr(ConvertVectorExprClass, Empty) {}
3923
3924 public:
3925   ConvertVectorExpr(Expr* SrcExpr, TypeSourceInfo *TI, QualType DstType,
3926              ExprValueKind VK, ExprObjectKind OK,
3927              SourceLocation BuiltinLoc, SourceLocation RParenLoc)
3928     : Expr(ConvertVectorExprClass, DstType, VK, OK,
3929            DstType->isDependentType(),
3930            DstType->isDependentType() || SrcExpr->isValueDependent(),
3931            (DstType->isInstantiationDependentType() ||
3932             SrcExpr->isInstantiationDependent()),
3933            (DstType->containsUnexpandedParameterPack() ||
3934             SrcExpr->containsUnexpandedParameterPack())),
3935   SrcExpr(SrcExpr), TInfo(TI), BuiltinLoc(BuiltinLoc), RParenLoc(RParenLoc) {}
3936
3937   /// getSrcExpr - Return the Expr to be converted.
3938   Expr *getSrcExpr() const { return cast<Expr>(SrcExpr); }
3939
3940   /// getTypeSourceInfo - Return the destination type.
3941   TypeSourceInfo *getTypeSourceInfo() const {
3942     return TInfo;
3943   }
3944   void setTypeSourceInfo(TypeSourceInfo *ti) {
3945     TInfo = ti;
3946   }
3947
3948   /// getBuiltinLoc - Return the location of the __builtin_convertvector token.
3949   SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
3950
3951   /// getRParenLoc - Return the location of final right parenthesis.
3952   SourceLocation getRParenLoc() const { return RParenLoc; }
3953
3954   SourceLocation getBeginLoc() const LLVM_READONLY { return BuiltinLoc; }
3955   SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
3956
3957   static bool classof(const Stmt *T) {
3958     return T->getStmtClass() == ConvertVectorExprClass;
3959   }
3960
3961   // Iterators
3962   child_range children() { return child_range(&SrcExpr, &SrcExpr+1); }
3963   const_child_range children() const {
3964     return const_child_range(&SrcExpr, &SrcExpr + 1);
3965   }
3966 };
3967
3968 /// ChooseExpr - GNU builtin-in function __builtin_choose_expr.
3969 /// This AST node is similar to the conditional operator (?:) in C, with
3970 /// the following exceptions:
3971 /// - the test expression must be a integer constant expression.
3972 /// - the expression returned acts like the chosen subexpression in every
3973 ///   visible way: the type is the same as that of the chosen subexpression,
3974 ///   and all predicates (whether it's an l-value, whether it's an integer
3975 ///   constant expression, etc.) return the same result as for the chosen
3976 ///   sub-expression.
3977 class ChooseExpr : public Expr {
3978   enum { COND, LHS, RHS, END_EXPR };
3979   Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
3980   SourceLocation BuiltinLoc, RParenLoc;
3981   bool CondIsTrue;
3982 public:
3983   ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs,
3984              QualType t, ExprValueKind VK, ExprObjectKind OK,
3985              SourceLocation RP, bool condIsTrue,
3986              bool TypeDependent, bool ValueDependent)
3987     : Expr(ChooseExprClass, t, VK, OK, TypeDependent, ValueDependent,
3988            (cond->isInstantiationDependent() ||
3989             lhs->isInstantiationDependent() ||
3990             rhs->isInstantiationDependent()),
3991            (cond->containsUnexpandedParameterPack() ||
3992             lhs->containsUnexpandedParameterPack() ||
3993             rhs->containsUnexpandedParameterPack())),
3994       BuiltinLoc(BLoc), RParenLoc(RP), CondIsTrue(condIsTrue) {
3995       SubExprs[COND] = cond;
3996       SubExprs[LHS] = lhs;
3997       SubExprs[RHS] = rhs;
3998     }
3999
4000   /// Build an empty __builtin_choose_expr.
4001   explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { }
4002
4003   /// isConditionTrue - Return whether the condition is true (i.e. not
4004   /// equal to zero).
4005   bool isConditionTrue() const {
4006     assert(!isConditionDependent() &&
4007            "Dependent condition isn't true or false");
4008     return CondIsTrue;
4009   }
4010   void setIsConditionTrue(bool isTrue) { CondIsTrue = isTrue; }
4011
4012   bool isConditionDependent() const {
4013     return getCond()->isTypeDependent() || getCond()->isValueDependent();
4014   }
4015
4016   /// getChosenSubExpr - Return the subexpression chosen according to the
4017   /// condition.
4018   Expr *getChosenSubExpr() const {
4019     return isConditionTrue() ? getLHS() : getRHS();
4020   }
4021
4022   Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
4023   void setCond(Expr *E) { SubExprs[COND] = E; }
4024   Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
4025   void setLHS(Expr *E) { SubExprs[LHS] = E; }
4026   Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
4027   void setRHS(Expr *E) { SubExprs[RHS] = E; }
4028
4029   SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
4030   void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
4031
4032   SourceLocation getRParenLoc() const { return RParenLoc; }
4033   void setRParenLoc(SourceLocation L) { RParenLoc = L; }
4034
4035   SourceLocation getBeginLoc() const LLVM_READONLY { return BuiltinLoc; }
4036   SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
4037
4038   static bool classof(const Stmt *T) {
4039     return T->getStmtClass() == ChooseExprClass;
4040   }
4041
4042   // Iterators
4043   child_range children() {
4044     return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
4045   }
4046   const_child_range children() const {
4047     return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
4048   }
4049 };
4050
4051 /// GNUNullExpr - Implements the GNU __null extension, which is a name
4052 /// for a null pointer constant that has integral type (e.g., int or
4053 /// long) and is the same size and alignment as a pointer. The __null
4054 /// extension is typically only used by system headers, which define
4055 /// NULL as __null in C++ rather than using 0 (which is an integer
4056 /// that may not match the size of a pointer).
4057 class GNUNullExpr : public Expr {
4058   /// TokenLoc - The location of the __null keyword.
4059   SourceLocation TokenLoc;
4060
4061 public:
4062   GNUNullExpr(QualType Ty, SourceLocation Loc)
4063     : Expr(GNUNullExprClass, Ty, VK_RValue, OK_Ordinary, false, false, false,
4064            false),
4065       TokenLoc(Loc) { }
4066
4067   /// Build an empty GNU __null expression.
4068   explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { }
4069
4070   /// getTokenLocation - The location of the __null token.
4071   SourceLocation getTokenLocation() const { return TokenLoc; }
4072   void setTokenLocation(SourceLocation L) { TokenLoc = L; }
4073
4074   SourceLocation getBeginLoc() const LLVM_READONLY { return TokenLoc; }
4075   SourceLocation getEndLoc() const LLVM_READONLY { return TokenLoc; }
4076
4077   static bool classof(const Stmt *T) {
4078     return T->getStmtClass() == GNUNullExprClass;
4079   }
4080
4081   // Iterators
4082   child_range children() {
4083     return child_range(child_iterator(), child_iterator());
4084   }
4085   const_child_range children() const {
4086     return const_child_range(const_child_iterator(), const_child_iterator());
4087   }
4088 };
4089
4090 /// Represents a call to the builtin function \c __builtin_va_arg.
4091 class VAArgExpr : public Expr {
4092   Stmt *Val;
4093   llvm::PointerIntPair<TypeSourceInfo *, 1, bool> TInfo;
4094   SourceLocation BuiltinLoc, RParenLoc;
4095 public:
4096   VAArgExpr(SourceLocation BLoc, Expr *e, TypeSourceInfo *TInfo,
4097             SourceLocation RPLoc, QualType t, bool IsMS)
4098       : Expr(VAArgExprClass, t, VK_RValue, OK_Ordinary, t->isDependentType(),
4099              false, (TInfo->getType()->isInstantiationDependentType() ||
4100                      e->isInstantiationDependent()),
4101              (TInfo->getType()->containsUnexpandedParameterPack() ||
4102               e->containsUnexpandedParameterPack())),
4103         Val(e), TInfo(TInfo, IsMS), BuiltinLoc(BLoc), RParenLoc(RPLoc) {}
4104
4105   /// Create an empty __builtin_va_arg expression.
4106   explicit VAArgExpr(EmptyShell Empty)
4107       : Expr(VAArgExprClass, Empty), Val(nullptr), TInfo(nullptr, false) {}
4108
4109   const Expr *getSubExpr() const { return cast<Expr>(Val); }
4110   Expr *getSubExpr() { return cast<Expr>(Val); }
4111   void setSubExpr(Expr *E) { Val = E; }
4112
4113   /// Returns whether this is really a Win64 ABI va_arg expression.
4114   bool isMicrosoftABI() const { return TInfo.getInt(); }
4115   void setIsMicrosoftABI(bool IsMS) { TInfo.setInt(IsMS); }
4116
4117   TypeSourceInfo *getWrittenTypeInfo() const { return TInfo.getPointer(); }
4118   void setWrittenTypeInfo(TypeSourceInfo *TI) { TInfo.setPointer(TI); }
4119
4120   SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
4121   void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
4122
4123   SourceLocation getRParenLoc() const { return RParenLoc; }
4124   void setRParenLoc(SourceLocation L) { RParenLoc = L; }
4125
4126   SourceLocation getBeginLoc() const LLVM_READONLY { return BuiltinLoc; }
4127   SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
4128
4129   static bool classof(const Stmt *T) {
4130     return T->getStmtClass() == VAArgExprClass;
4131   }
4132
4133   // Iterators
4134   child_range children() { return child_range(&Val, &Val+1); }
4135   const_child_range children() const {
4136     return const_child_range(&Val, &Val + 1);
4137   }
4138 };
4139
4140 /// Describes an C or C++ initializer list.
4141 ///
4142 /// InitListExpr describes an initializer list, which can be used to
4143 /// initialize objects of different types, including
4144 /// struct/class/union types, arrays, and vectors. For example:
4145 ///
4146 /// @code
4147 /// struct foo x = { 1, { 2, 3 } };
4148 /// @endcode
4149 ///
4150 /// Prior to semantic analysis, an initializer list will represent the
4151 /// initializer list as written by the user, but will have the
4152 /// placeholder type "void". This initializer list is called the
4153 /// syntactic form of the initializer, and may contain C99 designated
4154 /// initializers (represented as DesignatedInitExprs), initializations
4155 /// of subobject members without explicit braces, and so on. Clients
4156 /// interested in the original syntax of the initializer list should
4157 /// use the syntactic form of the initializer list.
4158 ///
4159 /// After semantic analysis, the initializer list will represent the
4160 /// semantic form of the initializer, where the initializations of all
4161 /// subobjects are made explicit with nested InitListExpr nodes and
4162 /// C99 designators have been eliminated by placing the designated
4163 /// initializations into the subobject they initialize. Additionally,
4164 /// any "holes" in the initialization, where no initializer has been
4165 /// specified for a particular subobject, will be replaced with
4166 /// implicitly-generated ImplicitValueInitExpr expressions that
4167 /// value-initialize the subobjects. Note, however, that the
4168 /// initializer lists may still have fewer initializers than there are
4169 /// elements to initialize within the object.
4170 ///
4171 /// After semantic analysis has completed, given an initializer list,
4172 /// method isSemanticForm() returns true if and only if this is the
4173 /// semantic form of the initializer list (note: the same AST node
4174 /// may at the same time be the syntactic form).
4175 /// Given the semantic form of the initializer list, one can retrieve
4176 /// the syntactic form of that initializer list (when different)
4177 /// using method getSyntacticForm(); the method returns null if applied
4178 /// to a initializer list which is already in syntactic form.
4179 /// Similarly, given the syntactic form (i.e., an initializer list such
4180 /// that isSemanticForm() returns false), one can retrieve the semantic
4181 /// form using method getSemanticForm().
4182 /// Since many initializer lists have the same syntactic and semantic forms,
4183 /// getSyntacticForm() may return NULL, indicating that the current
4184 /// semantic initializer list also serves as its syntactic form.
4185 class InitListExpr : public Expr {
4186   // FIXME: Eliminate this vector in favor of ASTContext allocation
4187   typedef ASTVector<Stmt *> InitExprsTy;
4188   InitExprsTy InitExprs;
4189   SourceLocation LBraceLoc, RBraceLoc;
4190
4191   /// The alternative form of the initializer list (if it exists).
4192   /// The int part of the pair stores whether this initializer list is
4193   /// in semantic form. If not null, the pointer points to:
4194   ///   - the syntactic form, if this is in semantic form;
4195   ///   - the semantic form, if this is in syntactic form.
4196   llvm::PointerIntPair<InitListExpr *, 1, bool> AltForm;
4197
4198   /// Either:
4199   ///  If this initializer list initializes an array with more elements than
4200   ///  there are initializers in the list, specifies an expression to be used
4201   ///  for value initialization of the rest of the elements.
4202   /// Or
4203   ///  If this initializer list initializes a union, specifies which
4204   ///  field within the union will be initialized.
4205   llvm::PointerUnion<Expr *, FieldDecl *> ArrayFillerOrUnionFieldInit;
4206
4207 public:
4208   InitListExpr(const ASTContext &C, SourceLocation lbraceloc,
4209                ArrayRef<Expr*> initExprs, SourceLocation rbraceloc);
4210
4211   /// Build an empty initializer list.
4212   explicit InitListExpr(EmptyShell Empty)
4213     : Expr(InitListExprClass, Empty), AltForm(nullptr, true) { }
4214
4215   unsigned getNumInits() const { return InitExprs.size(); }
4216
4217   /// Retrieve the set of initializers.
4218   Expr **getInits() { return reinterpret_cast<Expr **>(InitExprs.data()); }
4219
4220   /// Retrieve the set of initializers.
4221   Expr * const *getInits() const {
4222     return reinterpret_cast<Expr * const *>(InitExprs.data());
4223   }
4224
4225   ArrayRef<Expr *> inits() {
4226     return llvm::makeArrayRef(getInits(), getNumInits());
4227   }
4228
4229   ArrayRef<Expr *> inits() const {
4230     return llvm::makeArrayRef(getInits(), getNumInits());
4231   }
4232
4233   const Expr *getInit(unsigned Init) const {
4234     assert(Init < getNumInits() && "Initializer access out of range!");
4235     return cast_or_null<Expr>(InitExprs[Init]);
4236   }
4237
4238   Expr *getInit(unsigned Init) {
4239     assert(Init < getNumInits() && "Initializer access out of range!");
4240     return cast_or_null<Expr>(InitExprs[Init]);
4241   }
4242
4243   void setInit(unsigned Init, Expr *expr) {
4244     assert(Init < getNumInits() && "Initializer access out of range!");
4245     InitExprs[Init] = expr;
4246
4247     if (expr) {
4248       ExprBits.TypeDependent |= expr->isTypeDependent();
4249       ExprBits.ValueDependent |= expr->isValueDependent();
4250       ExprBits.InstantiationDependent |= expr->isInstantiationDependent();
4251       ExprBits.ContainsUnexpandedParameterPack |=
4252           expr->containsUnexpandedParameterPack();
4253     }
4254   }
4255
4256   /// Reserve space for some number of initializers.
4257   void reserveInits(const ASTContext &C, unsigned NumInits);
4258
4259   /// Specify the number of initializers
4260   ///
4261   /// If there are more than @p NumInits initializers, the remaining
4262   /// initializers will be destroyed. If there are fewer than @p
4263   /// NumInits initializers, NULL expressions will be added for the
4264   /// unknown initializers.
4265   void resizeInits(const ASTContext &Context, unsigned NumInits);
4266
4267   /// Updates the initializer at index @p Init with the new
4268   /// expression @p expr, and returns the old expression at that
4269   /// location.
4270   ///
4271   /// When @p Init is out of range for this initializer list, the
4272   /// initializer list will be extended with NULL expressions to
4273   /// accommodate the new entry.
4274   Expr *updateInit(const ASTContext &C, unsigned Init, Expr *expr);
4275
4276   /// If this initializer list initializes an array with more elements
4277   /// than there are initializers in the list, specifies an expression to be
4278   /// used for value initialization of the rest of the elements.
4279   Expr *getArrayFiller() {
4280     return ArrayFillerOrUnionFieldInit.dyn_cast<Expr *>();
4281   }
4282   const Expr *getArrayFiller() const {
4283     return const_cast<InitListExpr *>(this)->getArrayFiller();
4284   }
4285   void setArrayFiller(Expr *filler);
4286
4287   /// Return true if this is an array initializer and its array "filler"
4288   /// has been set.
4289   bool hasArrayFiller() const { return getArrayFiller(); }
4290
4291   /// If this initializes a union, specifies which field in the
4292   /// union to initialize.
4293   ///
4294   /// Typically, this field is the first named field within the
4295   /// union. However, a designated initializer can specify the
4296   /// initialization of a different field within the union.
4297   FieldDecl *getInitializedFieldInUnion() {
4298     return ArrayFillerOrUnionFieldInit.dyn_cast<FieldDecl *>();
4299   }
4300   const FieldDecl *getInitializedFieldInUnion() const {
4301     return const_cast<InitListExpr *>(this)->getInitializedFieldInUnion();
4302   }
4303   void setInitializedFieldInUnion(FieldDecl *FD) {
4304     assert((FD == nullptr
4305             || getInitializedFieldInUnion() == nullptr
4306             || getInitializedFieldInUnion() == FD)
4307            && "Only one field of a union may be initialized at a time!");
4308     ArrayFillerOrUnionFieldInit = FD;
4309   }
4310
4311   // Explicit InitListExpr's originate from source code (and have valid source
4312   // locations). Implicit InitListExpr's are created by the semantic analyzer.
4313   bool isExplicit() const {
4314     return LBraceLoc.isValid() && RBraceLoc.isValid();
4315   }
4316
4317   // Is this an initializer for an array of characters, initialized by a string
4318   // literal or an @encode?
4319   bool isStringLiteralInit() const;
4320
4321   /// Is this a transparent initializer list (that is, an InitListExpr that is
4322   /// purely syntactic, and whose semantics are that of the sole contained
4323   /// initializer)?
4324   bool isTransparent() const;
4325
4326   /// Is this the zero initializer {0} in a language which considers it
4327   /// idiomatic?
4328   bool isIdiomaticZeroInitializer(const LangOptions &LangOpts) const;
4329
4330   SourceLocation getLBraceLoc() const { return LBraceLoc; }
4331   void setLBraceLoc(SourceLocation Loc) { LBraceLoc = Loc; }
4332   SourceLocation getRBraceLoc() const { return RBraceLoc; }
4333   void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; }
4334
4335   bool isSemanticForm() const { return AltForm.getInt(); }
4336   InitListExpr *getSemanticForm() const {
4337     return isSemanticForm() ? nullptr : AltForm.getPointer();
4338   }
4339   bool isSyntacticForm() const {
4340     return !AltForm.getInt() || !AltForm.getPointer();
4341   }
4342   InitListExpr *getSyntacticForm() const {
4343     return isSemanticForm() ? AltForm.getPointer() : nullptr;
4344   }
4345
4346   void setSyntacticForm(InitListExpr *Init) {
4347     AltForm.setPointer(Init);
4348     AltForm.setInt(true);
4349     Init->AltForm.setPointer(this);
4350     Init->AltForm.setInt(false);
4351   }
4352
4353   bool hadArrayRangeDesignator() const {
4354     return InitListExprBits.HadArrayRangeDesignator != 0;
4355   }
4356   void sawArrayRangeDesignator(bool ARD = true) {
4357     InitListExprBits.HadArrayRangeDesignator = ARD;
4358   }
4359
4360   SourceLocation getBeginLoc() const LLVM_READONLY;
4361   SourceLocation getEndLoc() const LLVM_READONLY;
4362
4363   static bool classof(const Stmt *T) {
4364     return T->getStmtClass() == InitListExprClass;
4365   }
4366
4367   // Iterators
4368   child_range children() {
4369     const_child_range CCR = const_cast<const InitListExpr *>(this)->children();
4370     return child_range(cast_away_const(CCR.begin()),
4371                        cast_away_const(CCR.end()));
4372   }
4373
4374   const_child_range children() const {
4375     // FIXME: This does not include the array filler expression.
4376     if (InitExprs.empty())
4377       return const_child_range(const_child_iterator(), const_child_iterator());
4378     return const_child_range(&InitExprs[0], &InitExprs[0] + InitExprs.size());
4379   }
4380
4381   typedef InitExprsTy::iterator iterator;
4382   typedef InitExprsTy::const_iterator const_iterator;
4383   typedef InitExprsTy::reverse_iterator reverse_iterator;
4384   typedef InitExprsTy::const_reverse_iterator const_reverse_iterator;
4385
4386   iterator begin() { return InitExprs.begin(); }
4387   const_iterator begin() const { return InitExprs.begin(); }
4388   iterator end() { return InitExprs.end(); }
4389   const_iterator end() const { return InitExprs.end(); }
4390   reverse_iterator rbegin() { return InitExprs.rbegin(); }
4391   const_reverse_iterator rbegin() const { return InitExprs.rbegin(); }
4392   reverse_iterator rend() { return InitExprs.rend(); }
4393   const_reverse_iterator rend() const { return InitExprs.rend(); }
4394
4395   friend class ASTStmtReader;
4396   friend class ASTStmtWriter;
4397 };
4398
4399 /// Represents a C99 designated initializer expression.
4400 ///
4401 /// A designated initializer expression (C99 6.7.8) contains one or
4402 /// more designators (which can be field designators, array
4403 /// designators, or GNU array-range designators) followed by an
4404 /// expression that initializes the field or element(s) that the
4405 /// designators refer to. For example, given:
4406 ///
4407 /// @code
4408 /// struct point {
4409 ///   double x;
4410 ///   double y;
4411 /// };
4412 /// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 };
4413 /// @endcode
4414 ///
4415 /// The InitListExpr contains three DesignatedInitExprs, the first of
4416 /// which covers @c [2].y=1.0. This DesignatedInitExpr will have two
4417 /// designators, one array designator for @c [2] followed by one field
4418 /// designator for @c .y. The initialization expression will be 1.0.
4419 class DesignatedInitExpr final
4420     : public Expr,
4421       private llvm::TrailingObjects<DesignatedInitExpr, Stmt *> {
4422 public:
4423   /// Forward declaration of the Designator class.
4424   class Designator;
4425
4426 private:
4427   /// The location of the '=' or ':' prior to the actual initializer
4428   /// expression.
4429   SourceLocation EqualOrColonLoc;
4430
4431   /// Whether this designated initializer used the GNU deprecated
4432   /// syntax rather than the C99 '=' syntax.
4433   unsigned GNUSyntax : 1;
4434
4435   /// The number of designators in this initializer expression.
4436   unsigned NumDesignators : 15;
4437
4438   /// The number of subexpressions of this initializer expression,
4439   /// which contains both the initializer and any additional
4440   /// expressions used by array and array-range designators.
4441   unsigned NumSubExprs : 16;
4442
4443   /// The designators in this designated initialization
4444   /// expression.
4445   Designator *Designators;
4446
4447   DesignatedInitExpr(const ASTContext &C, QualType Ty,
4448                      llvm::ArrayRef<Designator> Designators,
4449                      SourceLocation EqualOrColonLoc, bool GNUSyntax,
4450                      ArrayRef<Expr *> IndexExprs, Expr *Init);
4451
4452   explicit DesignatedInitExpr(unsigned NumSubExprs)
4453     : Expr(DesignatedInitExprClass, EmptyShell()),
4454       NumDesignators(0), NumSubExprs(NumSubExprs), Designators(nullptr) { }
4455
4456 public:
4457   /// A field designator, e.g., ".x".
4458   struct FieldDesignator {
4459     /// Refers to the field that is being initialized. The low bit
4460     /// of this field determines whether this is actually a pointer
4461     /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When
4462     /// initially constructed, a field designator will store an
4463     /// IdentifierInfo*. After semantic analysis has resolved that
4464     /// name, the field designator will instead store a FieldDecl*.
4465     uintptr_t NameOrField;
4466
4467     /// The location of the '.' in the designated initializer.
4468     unsigned DotLoc;
4469
4470     /// The location of the field name in the designated initializer.
4471     unsigned FieldLoc;
4472   };
4473
4474   /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
4475   struct ArrayOrRangeDesignator {
4476     /// Location of the first index expression within the designated
4477     /// initializer expression's list of subexpressions.
4478     unsigned Index;
4479     /// The location of the '[' starting the array range designator.
4480     unsigned LBracketLoc;
4481     /// The location of the ellipsis separating the start and end
4482     /// indices. Only valid for GNU array-range designators.
4483     unsigned EllipsisLoc;
4484     /// The location of the ']' terminating the array range designator.
4485     unsigned RBracketLoc;
4486   };
4487
4488   /// Represents a single C99 designator.
4489   ///
4490   /// @todo This class is infuriatingly similar to clang::Designator,
4491   /// but minor differences (storing indices vs. storing pointers)
4492   /// keep us from reusing it. Try harder, later, to rectify these
4493   /// differences.
4494   class Designator {
4495     /// The kind of designator this describes.
4496     enum {
4497       FieldDesignator,
4498       ArrayDesignator,
4499       ArrayRangeDesignator
4500     } Kind;
4501
4502     union {
4503       /// A field designator, e.g., ".x".
4504       struct FieldDesignator Field;
4505       /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
4506       struct ArrayOrRangeDesignator ArrayOrRange;
4507     };
4508     friend class DesignatedInitExpr;
4509
4510   public:
4511     Designator() {}
4512
4513     /// Initializes a field designator.
4514     Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc,
4515                SourceLocation FieldLoc)
4516       : Kind(FieldDesignator) {
4517       Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01;
4518       Field.DotLoc = DotLoc.getRawEncoding();
4519       Field.FieldLoc = FieldLoc.getRawEncoding();
4520     }
4521
4522     /// Initializes an array designator.
4523     Designator(unsigned Index, SourceLocation LBracketLoc,
4524                SourceLocation RBracketLoc)
4525       : Kind(ArrayDesignator) {
4526       ArrayOrRange.Index = Index;
4527       ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
4528       ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding();
4529       ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
4530     }
4531
4532     /// Initializes a GNU array-range designator.
4533     Designator(unsigned Index, SourceLocation LBracketLoc,
4534                SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
4535       : Kind(ArrayRangeDesignator) {
4536       ArrayOrRange.Index = Index;
4537       ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
4538       ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding();
4539       ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
4540     }
4541
4542     bool isFieldDesignator() const { return Kind == FieldDesignator; }
4543     bool isArrayDesignator() const { return Kind == ArrayDesignator; }
4544     bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; }
4545
4546     IdentifierInfo *getFieldName() const;
4547
4548     FieldDecl *getField() const {
4549       assert(Kind == FieldDesignator && "Only valid on a field designator");
4550       if (Field.NameOrField & 0x01)
4551         return nullptr;
4552       else
4553         return reinterpret_cast<FieldDecl *>(Field.NameOrField);
4554     }
4555
4556     void setField(FieldDecl *FD) {
4557       assert(Kind == FieldDesignator && "Only valid on a field designator");
4558       Field.NameOrField = reinterpret_cast<uintptr_t>(FD);
4559     }
4560
4561     SourceLocation getDotLoc() const {
4562       assert(Kind == FieldDesignator && "Only valid on a field designator");
4563       return SourceLocation::getFromRawEncoding(Field.DotLoc);
4564     }
4565
4566     SourceLocation getFieldLoc() const {
4567       assert(Kind == FieldDesignator && "Only valid on a field designator");
4568       return SourceLocation::getFromRawEncoding(Field.FieldLoc);
4569     }
4570
4571     SourceLocation getLBracketLoc() const {
4572       assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
4573              "Only valid on an array or array-range designator");
4574       return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc);
4575     }
4576
4577     SourceLocation getRBracketLoc() const {
4578       assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
4579              "Only valid on an array or array-range designator");
4580       return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc);
4581     }
4582
4583     SourceLocation getEllipsisLoc() const {
4584       assert(Kind == ArrayRangeDesignator &&
4585              "Only valid on an array-range designator");
4586       return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc);
4587     }
4588
4589     unsigned getFirstExprIndex() const {
4590       assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
4591              "Only valid on an array or array-range designator");
4592       return ArrayOrRange.Index;
4593     }
4594
4595     SourceLocation getBeginLoc() const LLVM_READONLY {
4596       if (Kind == FieldDesignator)
4597         return getDotLoc().isInvalid()? getFieldLoc() : getDotLoc();
4598       else
4599         return getLBracketLoc();
4600     }
4601     SourceLocation getEndLoc() const LLVM_READONLY {
4602       return Kind == FieldDesignator ? getFieldLoc() : getRBracketLoc();
4603     }
4604     SourceRange getSourceRange() const LLVM_READONLY {
4605       return SourceRange(getBeginLoc(), getEndLoc());
4606     }
4607   };
4608
4609   static DesignatedInitExpr *Create(const ASTContext &C,
4610                                     llvm::ArrayRef<Designator> Designators,
4611                                     ArrayRef<Expr*> IndexExprs,
4612                                     SourceLocation EqualOrColonLoc,
4613                                     bool GNUSyntax, Expr *Init);
4614
4615   static DesignatedInitExpr *CreateEmpty(const ASTContext &C,
4616                                          unsigned NumIndexExprs);
4617
4618   /// Returns the number of designators in this initializer.
4619   unsigned size() const { return NumDesignators; }
4620
4621   // Iterator access to the designators.
4622   llvm::MutableArrayRef<Designator> designators() {
4623     return {Designators, NumDesignators};
4624   }
4625
4626   llvm::ArrayRef<Designator> designators() const {
4627     return {Designators, NumDesignators};
4628   }
4629
4630   Designator *getDesignator(unsigned Idx) { return &designators()[Idx]; }
4631   const Designator *getDesignator(unsigned Idx) const {
4632     return &designators()[Idx];
4633   }
4634
4635   void setDesignators(const ASTContext &C, const Designator *Desigs,
4636                       unsigned NumDesigs);
4637
4638   Expr *getArrayIndex(const Designator &D) const;
4639   Expr *getArrayRangeStart(const Designator &D) const;
4640   Expr *getArrayRangeEnd(const Designator &D) const;
4641
4642   /// Retrieve the location of the '=' that precedes the
4643   /// initializer value itself, if present.
4644   SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; }
4645   void setEqualOrColonLoc(SourceLocation L) { EqualOrColonLoc = L; }
4646
4647   /// Determines whether this designated initializer used the
4648   /// deprecated GNU syntax for designated initializers.
4649   bool usesGNUSyntax() const { return GNUSyntax; }
4650   void setGNUSyntax(bool GNU) { GNUSyntax = GNU; }
4651
4652   /// Retrieve the initializer value.
4653   Expr *getInit() const {
4654     return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin());
4655   }
4656
4657   void setInit(Expr *init) {
4658     *child_begin() = init;
4659   }
4660
4661   /// Retrieve the total number of subexpressions in this
4662   /// designated initializer expression, including the actual
4663   /// initialized value and any expressions that occur within array
4664   /// and array-range designators.
4665   unsigned getNumSubExprs() const { return NumSubExprs; }
4666
4667   Expr *getSubExpr(unsigned Idx) const {
4668     assert(Idx < NumSubExprs && "Subscript out of range");
4669     return cast<Expr>(getTrailingObjects<Stmt *>()[Idx]);
4670   }
4671
4672   void setSubExpr(unsigned Idx, Expr *E) {
4673     assert(Idx < NumSubExprs && "Subscript out of range");
4674     getTrailingObjects<Stmt *>()[Idx] = E;
4675   }
4676
4677   /// Replaces the designator at index @p Idx with the series
4678   /// of designators in [First, Last).
4679   void ExpandDesignator(const ASTContext &C, unsigned Idx,
4680                         const Designator *First, const Designator *Last);
4681
4682   SourceRange getDesignatorsSourceRange() const;
4683
4684   SourceLocation getBeginLoc() const LLVM_READONLY;
4685   SourceLocation getEndLoc() const LLVM_READONLY;
4686
4687   static bool classof(const Stmt *T) {
4688     return T->getStmtClass() == DesignatedInitExprClass;
4689   }
4690
4691   // Iterators
4692   child_range children() {
4693     Stmt **begin = getTrailingObjects<Stmt *>();
4694     return child_range(begin, begin + NumSubExprs);
4695   }
4696   const_child_range children() const {
4697     Stmt * const *begin = getTrailingObjects<Stmt *>();
4698     return const_child_range(begin, begin + NumSubExprs);
4699   }
4700
4701   friend TrailingObjects;
4702 };
4703
4704 /// Represents a place-holder for an object not to be initialized by
4705 /// anything.
4706 ///
4707 /// This only makes sense when it appears as part of an updater of a
4708 /// DesignatedInitUpdateExpr (see below). The base expression of a DIUE
4709 /// initializes a big object, and the NoInitExpr's mark the spots within the
4710 /// big object not to be overwritten by the updater.
4711 ///
4712 /// \see DesignatedInitUpdateExpr
4713 class NoInitExpr : public Expr {
4714 public:
4715   explicit NoInitExpr(QualType ty)
4716     : Expr(NoInitExprClass, ty, VK_RValue, OK_Ordinary,
4717            false, false, ty->isInstantiationDependentType(), false) { }
4718
4719   explicit NoInitExpr(EmptyShell Empty)
4720     : Expr(NoInitExprClass, Empty) { }
4721
4722   static bool classof(const Stmt *T) {
4723     return T->getStmtClass() == NoInitExprClass;
4724   }
4725
4726   SourceLocation getBeginLoc() const LLVM_READONLY { return SourceLocation(); }
4727   SourceLocation getEndLoc() const LLVM_READONLY { return SourceLocation(); }
4728
4729   // Iterators
4730   child_range children() {
4731     return child_range(child_iterator(), child_iterator());
4732   }
4733   const_child_range children() const {
4734     return const_child_range(const_child_iterator(), const_child_iterator());
4735   }
4736 };
4737
4738 // In cases like:
4739 //   struct Q { int a, b, c; };
4740 //   Q *getQ();
4741 //   void foo() {
4742 //     struct A { Q q; } a = { *getQ(), .q.b = 3 };
4743 //   }
4744 //
4745 // We will have an InitListExpr for a, with type A, and then a
4746 // DesignatedInitUpdateExpr for "a.q" with type Q. The "base" for this DIUE
4747 // is the call expression *getQ(); the "updater" for the DIUE is ".q.b = 3"
4748 //
4749 class DesignatedInitUpdateExpr : public Expr {
4750   // BaseAndUpdaterExprs[0] is the base expression;
4751   // BaseAndUpdaterExprs[1] is an InitListExpr overwriting part of the base.
4752   Stmt *BaseAndUpdaterExprs[2];
4753
4754 public:
4755   DesignatedInitUpdateExpr(const ASTContext &C, SourceLocation lBraceLoc,
4756                            Expr *baseExprs, SourceLocation rBraceLoc);
4757
4758   explicit DesignatedInitUpdateExpr(EmptyShell Empty)
4759     : Expr(DesignatedInitUpdateExprClass, Empty) { }
4760
4761   SourceLocation getBeginLoc() const LLVM_READONLY;
4762   SourceLocation getEndLoc() const LLVM_READONLY;
4763
4764   static bool classof(const Stmt *T) {
4765     return T->getStmtClass() == DesignatedInitUpdateExprClass;
4766   }
4767
4768   Expr *getBase() const { return cast<Expr>(BaseAndUpdaterExprs[0]); }
4769   void setBase(Expr *Base) { BaseAndUpdaterExprs[0] = Base; }
4770
4771   InitListExpr *getUpdater() const {
4772     return cast<InitListExpr>(BaseAndUpdaterExprs[1]);
4773   }
4774   void setUpdater(Expr *Updater) { BaseAndUpdaterExprs[1] = Updater; }
4775
4776   // Iterators
4777   // children = the base and the updater
4778   child_range children() {
4779     return child_range(&BaseAndUpdaterExprs[0], &BaseAndUpdaterExprs[0] + 2);
4780   }
4781   const_child_range children() const {
4782     return const_child_range(&BaseAndUpdaterExprs[0],
4783                              &BaseAndUpdaterExprs[0] + 2);
4784   }
4785 };
4786
4787 /// Represents a loop initializing the elements of an array.
4788 ///
4789 /// The need to initialize the elements of an array occurs in a number of
4790 /// contexts:
4791 ///
4792 ///  * in the implicit copy/move constructor for a class with an array member
4793 ///  * when a lambda-expression captures an array by value
4794 ///  * when a decomposition declaration decomposes an array
4795 ///
4796 /// There are two subexpressions: a common expression (the source array)
4797 /// that is evaluated once up-front, and a per-element initializer that
4798 /// runs once for each array element.
4799 ///
4800 /// Within the per-element initializer, the common expression may be referenced
4801 /// via an OpaqueValueExpr, and the current index may be obtained via an
4802 /// ArrayInitIndexExpr.
4803 class ArrayInitLoopExpr : public Expr {
4804   Stmt *SubExprs[2];
4805
4806   explicit ArrayInitLoopExpr(EmptyShell Empty)
4807       : Expr(ArrayInitLoopExprClass, Empty), SubExprs{} {}
4808
4809 public:
4810   explicit ArrayInitLoopExpr(QualType T, Expr *CommonInit, Expr *ElementInit)
4811       : Expr(ArrayInitLoopExprClass, T, VK_RValue, OK_Ordinary, false,
4812              CommonInit->isValueDependent() || ElementInit->isValueDependent(),
4813              T->isInstantiationDependentType(),
4814              CommonInit->containsUnexpandedParameterPack() ||
4815                  ElementInit->containsUnexpandedParameterPack()),
4816         SubExprs{CommonInit, ElementInit} {}
4817
4818   /// Get the common subexpression shared by all initializations (the source
4819   /// array).
4820   OpaqueValueExpr *getCommonExpr() const {
4821     return cast<OpaqueValueExpr>(SubExprs[0]);
4822   }
4823
4824   /// Get the initializer to use for each array element.
4825   Expr *getSubExpr() const { return cast<Expr>(SubExprs[1]); }
4826
4827   llvm::APInt getArraySize() const {
4828     return cast<ConstantArrayType>(getType()->castAsArrayTypeUnsafe())
4829         ->getSize();
4830   }
4831
4832   static bool classof(const Stmt *S) {
4833     return S->getStmtClass() == ArrayInitLoopExprClass;
4834   }
4835
4836   SourceLocation getBeginLoc() const LLVM_READONLY {
4837     return getCommonExpr()->getBeginLoc();
4838   }
4839   SourceLocation getEndLoc() const LLVM_READONLY {
4840     return getCommonExpr()->getEndLoc();
4841   }
4842
4843   child_range children() {
4844     return child_range(SubExprs, SubExprs + 2);
4845   }
4846   const_child_range children() const {
4847     return const_child_range(SubExprs, SubExprs + 2);
4848   }
4849
4850   friend class ASTReader;
4851   friend class ASTStmtReader;
4852   friend class ASTStmtWriter;
4853 };
4854
4855 /// Represents the index of the current element of an array being
4856 /// initialized by an ArrayInitLoopExpr. This can only appear within the
4857 /// subexpression of an ArrayInitLoopExpr.
4858 class ArrayInitIndexExpr : public Expr {
4859   explicit ArrayInitIndexExpr(EmptyShell Empty)
4860       : Expr(ArrayInitIndexExprClass, Empty) {}
4861
4862 public:
4863   explicit ArrayInitIndexExpr(QualType T)
4864       : Expr(ArrayInitIndexExprClass, T, VK_RValue, OK_Ordinary,
4865              false, false, false, false) {}
4866
4867   static bool classof(const Stmt *S) {
4868     return S->getStmtClass() == ArrayInitIndexExprClass;
4869   }
4870
4871   SourceLocation getBeginLoc() const LLVM_READONLY { return SourceLocation(); }
4872   SourceLocation getEndLoc() const LLVM_READONLY { return SourceLocation(); }
4873
4874   child_range children() {
4875     return child_range(child_iterator(), child_iterator());
4876   }
4877   const_child_range children() const {
4878     return const_child_range(const_child_iterator(), const_child_iterator());
4879   }
4880
4881   friend class ASTReader;
4882   friend class ASTStmtReader;
4883 };
4884
4885 /// Represents an implicitly-generated value initialization of
4886 /// an object of a given type.
4887 ///
4888 /// Implicit value initializations occur within semantic initializer
4889 /// list expressions (InitListExpr) as placeholders for subobject
4890 /// initializations not explicitly specified by the user.
4891 ///
4892 /// \see InitListExpr
4893 class ImplicitValueInitExpr : public Expr {
4894 public:
4895   explicit ImplicitValueInitExpr(QualType ty)
4896     : Expr(ImplicitValueInitExprClass, ty, VK_RValue, OK_Ordinary,
4897            false, false, ty->isInstantiationDependentType(), false) { }
4898
4899   /// Construct an empty implicit value initialization.
4900   explicit ImplicitValueInitExpr(EmptyShell Empty)
4901     : Expr(ImplicitValueInitExprClass, Empty) { }
4902
4903   static bool classof(const Stmt *T) {
4904     return T->getStmtClass() == ImplicitValueInitExprClass;
4905   }
4906
4907   SourceLocation getBeginLoc() const LLVM_READONLY { return SourceLocation(); }
4908   SourceLocation getEndLoc() const LLVM_READONLY { return SourceLocation(); }
4909
4910   // Iterators
4911   child_range children() {
4912     return child_range(child_iterator(), child_iterator());
4913   }
4914   const_child_range children() const {
4915     return const_child_range(const_child_iterator(), const_child_iterator());
4916   }
4917 };
4918
4919 class ParenListExpr final
4920     : public Expr,
4921       private llvm::TrailingObjects<ParenListExpr, Stmt *> {
4922   friend class ASTStmtReader;
4923   friend TrailingObjects;
4924
4925   /// The location of the left and right parentheses.
4926   SourceLocation LParenLoc, RParenLoc;
4927
4928   /// Build a paren list.
4929   ParenListExpr(SourceLocation LParenLoc, ArrayRef<Expr *> Exprs,
4930                 SourceLocation RParenLoc);
4931
4932   /// Build an empty paren list.
4933   ParenListExpr(EmptyShell Empty, unsigned NumExprs);
4934
4935 public:
4936   /// Create a paren list.
4937   static ParenListExpr *Create(const ASTContext &Ctx, SourceLocation LParenLoc,
4938                                ArrayRef<Expr *> Exprs,
4939                                SourceLocation RParenLoc);
4940
4941   /// Create an empty paren list.
4942   static ParenListExpr *CreateEmpty(const ASTContext &Ctx, unsigned NumExprs);
4943
4944   /// Return the number of expressions in this paren list.
4945   unsigned getNumExprs() const { return ParenListExprBits.NumExprs; }
4946
4947   Expr *getExpr(unsigned Init) {
4948     assert(Init < getNumExprs() && "Initializer access out of range!");
4949     return getExprs()[Init];
4950   }
4951
4952   const Expr *getExpr(unsigned Init) const {
4953     return const_cast<ParenListExpr *>(this)->getExpr(Init);
4954   }
4955
4956   Expr **getExprs() {
4957     return reinterpret_cast<Expr **>(getTrailingObjects<Stmt *>());
4958   }
4959
4960   ArrayRef<Expr *> exprs() {
4961     return llvm::makeArrayRef(getExprs(), getNumExprs());
4962   }
4963
4964   SourceLocation getLParenLoc() const { return LParenLoc; }
4965   SourceLocation getRParenLoc() const { return RParenLoc; }
4966   SourceLocation getBeginLoc() const { return getLParenLoc(); }
4967   SourceLocation getEndLoc() const { return getRParenLoc(); }
4968
4969   static bool classof(const Stmt *T) {
4970     return T->getStmtClass() == ParenListExprClass;
4971   }
4972
4973   // Iterators
4974   child_range children() {
4975     return child_range(getTrailingObjects<Stmt *>(),
4976                        getTrailingObjects<Stmt *>() + getNumExprs());
4977   }
4978   const_child_range children() const {
4979     return const_child_range(getTrailingObjects<Stmt *>(),
4980                              getTrailingObjects<Stmt *>() + getNumExprs());
4981   }
4982 };
4983
4984 /// Represents a C11 generic selection.
4985 ///
4986 /// A generic selection (C11 6.5.1.1) contains an unevaluated controlling
4987 /// expression, followed by one or more generic associations.  Each generic
4988 /// association specifies a type name and an expression, or "default" and an
4989 /// expression (in which case it is known as a default generic association).
4990 /// The type and value of the generic selection are identical to those of its
4991 /// result expression, which is defined as the expression in the generic
4992 /// association with a type name that is compatible with the type of the
4993 /// controlling expression, or the expression in the default generic association
4994 /// if no types are compatible.  For example:
4995 ///
4996 /// @code
4997 /// _Generic(X, double: 1, float: 2, default: 3)
4998 /// @endcode
4999 ///
5000 /// The above expression evaluates to 1 if 1.0 is substituted for X, 2 if 1.0f
5001 /// or 3 if "hello".
5002 ///
5003 /// As an extension, generic selections are allowed in C++, where the following
5004 /// additional semantics apply:
5005 ///
5006 /// Any generic selection whose controlling expression is type-dependent or
5007 /// which names a dependent type in its association list is result-dependent,
5008 /// which means that the choice of result expression is dependent.
5009 /// Result-dependent generic associations are both type- and value-dependent.
5010 class GenericSelectionExpr : public Expr {
5011   enum { CONTROLLING, END_EXPR };
5012   TypeSourceInfo **AssocTypes;
5013   Stmt **SubExprs;
5014   unsigned NumAssocs, ResultIndex;
5015   SourceLocation GenericLoc, DefaultLoc, RParenLoc;
5016
5017 public:
5018   GenericSelectionExpr(const ASTContext &Context,
5019                        SourceLocation GenericLoc, Expr *ControllingExpr,
5020                        ArrayRef<TypeSourceInfo*> AssocTypes,
5021                        ArrayRef<Expr*> AssocExprs,
5022                        SourceLocation DefaultLoc, SourceLocation RParenLoc,
5023                        bool ContainsUnexpandedParameterPack,
5024                        unsigned ResultIndex);
5025
5026   /// This constructor is used in the result-dependent case.
5027   GenericSelectionExpr(const ASTContext &Context,
5028                        SourceLocation GenericLoc, Expr *ControllingExpr,
5029                        ArrayRef<TypeSourceInfo*> AssocTypes,
5030                        ArrayRef<Expr*> AssocExprs,
5031                        SourceLocation DefaultLoc, SourceLocation RParenLoc,
5032                        bool ContainsUnexpandedParameterPack);
5033
5034   explicit GenericSelectionExpr(EmptyShell Empty)
5035     : Expr(GenericSelectionExprClass, Empty) { }
5036
5037   unsigned getNumAssocs() const { return NumAssocs; }
5038
5039   SourceLocation getGenericLoc() const { return GenericLoc; }
5040   SourceLocation getDefaultLoc() const { return DefaultLoc; }
5041   SourceLocation getRParenLoc() const { return RParenLoc; }
5042
5043   const Expr *getAssocExpr(unsigned i) const {
5044     return cast<Expr>(SubExprs[END_EXPR+i]);
5045   }
5046   Expr *getAssocExpr(unsigned i) { return cast<Expr>(SubExprs[END_EXPR+i]); }
5047   ArrayRef<Expr *> getAssocExprs() const {
5048     return NumAssocs
5049                ? llvm::makeArrayRef(
5050                      &reinterpret_cast<Expr **>(SubExprs)[END_EXPR], NumAssocs)
5051                : None;
5052   }
5053   const TypeSourceInfo *getAssocTypeSourceInfo(unsigned i) const {
5054     return AssocTypes[i];
5055   }
5056   TypeSourceInfo *getAssocTypeSourceInfo(unsigned i) { return AssocTypes[i]; }
5057   ArrayRef<TypeSourceInfo *> getAssocTypeSourceInfos() const {
5058     return NumAssocs ? llvm::makeArrayRef(&AssocTypes[0], NumAssocs) : None;
5059   }
5060
5061   QualType getAssocType(unsigned i) const {
5062     if (const TypeSourceInfo *TS = getAssocTypeSourceInfo(i))
5063       return TS->getType();
5064     else
5065       return QualType();
5066   }
5067
5068   const Expr *getControllingExpr() const {
5069     return cast<Expr>(SubExprs[CONTROLLING]);
5070   }
5071   Expr *getControllingExpr() { return cast<Expr>(SubExprs[CONTROLLING]); }
5072
5073   /// Whether this generic selection is result-dependent.
5074   bool isResultDependent() const { return ResultIndex == -1U; }
5075
5076   /// The zero-based index of the result expression's generic association in
5077   /// the generic selection's association list.  Defined only if the
5078   /// generic selection is not result-dependent.
5079   unsigned getResultIndex() const {
5080     assert(!isResultDependent() && "Generic selection is result-dependent");
5081     return ResultIndex;
5082   }
5083
5084   /// The generic selection's result expression.  Defined only if the
5085   /// generic selection is not result-dependent.
5086   const Expr *getResultExpr() const { return getAssocExpr(getResultIndex()); }
5087   Expr *getResultExpr() { return getAssocExpr(getResultIndex()); }
5088
5089   SourceLocation getBeginLoc() const LLVM_READONLY { return GenericLoc; }
5090   SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
5091
5092   static bool classof(const Stmt *T) {
5093     return T->getStmtClass() == GenericSelectionExprClass;
5094   }
5095
5096   child_range children() {
5097     return child_range(SubExprs, SubExprs+END_EXPR+NumAssocs);
5098   }
5099   const_child_range children() const {
5100     return const_child_range(SubExprs, SubExprs + END_EXPR + NumAssocs);
5101   }
5102   friend class ASTStmtReader;
5103 };
5104
5105 //===----------------------------------------------------------------------===//
5106 // Clang Extensions
5107 //===----------------------------------------------------------------------===//
5108
5109 /// ExtVectorElementExpr - This represents access to specific elements of a
5110 /// vector, and may occur on the left hand side or right hand side.  For example
5111 /// the following is legal:  "V.xy = V.zw" if V is a 4 element extended vector.
5112 ///
5113 /// Note that the base may have either vector or pointer to vector type, just
5114 /// like a struct field reference.
5115 ///
5116 class ExtVectorElementExpr : public Expr {
5117   Stmt *Base;
5118   IdentifierInfo *Accessor;
5119   SourceLocation AccessorLoc;
5120 public:
5121   ExtVectorElementExpr(QualType ty, ExprValueKind VK, Expr *base,
5122                        IdentifierInfo &accessor, SourceLocation loc)
5123     : Expr(ExtVectorElementExprClass, ty, VK,
5124            (VK == VK_RValue ? OK_Ordinary : OK_VectorComponent),
5125            base->isTypeDependent(), base->isValueDependent(),
5126            base->isInstantiationDependent(),
5127            base->containsUnexpandedParameterPack()),
5128       Base(base), Accessor(&accessor), AccessorLoc(loc) {}
5129
5130   /// Build an empty vector element expression.
5131   explicit ExtVectorElementExpr(EmptyShell Empty)
5132     : Expr(ExtVectorElementExprClass, Empty) { }
5133
5134   const Expr *getBase() const { return cast<Expr>(Base); }
5135   Expr *getBase() { return cast<Expr>(Base); }
5136   void setBase(Expr *E) { Base = E; }
5137
5138   IdentifierInfo &getAccessor() const { return *Accessor; }
5139   void setAccessor(IdentifierInfo *II) { Accessor = II; }
5140
5141   SourceLocation getAccessorLoc() const { return AccessorLoc; }
5142   void setAccessorLoc(SourceLocation L) { AccessorLoc = L; }
5143
5144   /// getNumElements - Get the number of components being selected.
5145   unsigned getNumElements() const;
5146
5147   /// containsDuplicateElements - Return true if any element access is
5148   /// repeated.
5149   bool containsDuplicateElements() const;
5150
5151   /// getEncodedElementAccess - Encode the elements accessed into an llvm
5152   /// aggregate Constant of ConstantInt(s).
5153   void getEncodedElementAccess(SmallVectorImpl<uint32_t> &Elts) const;
5154
5155   SourceLocation getBeginLoc() const LLVM_READONLY {
5156     return getBase()->getBeginLoc();
5157   }
5158   SourceLocation getEndLoc() const LLVM_READONLY { return AccessorLoc; }
5159
5160   /// isArrow - Return true if the base expression is a pointer to vector,
5161   /// return false if the base expression is a vector.
5162   bool isArrow() const;
5163
5164   static bool classof(const Stmt *T) {
5165     return T->getStmtClass() == ExtVectorElementExprClass;
5166   }
5167
5168   // Iterators
5169   child_range children() { return child_range(&Base, &Base+1); }
5170   const_child_range children() const {
5171     return const_child_range(&Base, &Base + 1);
5172   }
5173 };
5174
5175 /// BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
5176 /// ^{ statement-body }   or   ^(int arg1, float arg2){ statement-body }
5177 class BlockExpr : public Expr {
5178 protected:
5179   BlockDecl *TheBlock;
5180 public:
5181   BlockExpr(BlockDecl *BD, QualType ty)
5182     : Expr(BlockExprClass, ty, VK_RValue, OK_Ordinary,
5183            ty->isDependentType(), ty->isDependentType(),
5184            ty->isInstantiationDependentType() || BD->isDependentContext(),
5185            false),
5186       TheBlock(BD) {}
5187
5188   /// Build an empty block expression.
5189   explicit BlockExpr(EmptyShell Empty) : Expr(BlockExprClass, Empty) { }
5190
5191   const BlockDecl *getBlockDecl() const { return TheBlock; }
5192   BlockDecl *getBlockDecl() { return TheBlock; }
5193   void setBlockDecl(BlockDecl *BD) { TheBlock = BD; }
5194
5195   // Convenience functions for probing the underlying BlockDecl.
5196   SourceLocation getCaretLocation() const;
5197   const Stmt *getBody() const;
5198   Stmt *getBody();
5199
5200   SourceLocation getBeginLoc() const LLVM_READONLY {
5201     return getCaretLocation();
5202   }
5203   SourceLocation getEndLoc() const LLVM_READONLY {
5204     return getBody()->getEndLoc();
5205   }
5206
5207   /// getFunctionType - Return the underlying function type for this block.
5208   const FunctionProtoType *getFunctionType() const;
5209
5210   static bool classof(const Stmt *T) {
5211     return T->getStmtClass() == BlockExprClass;
5212   }
5213
5214   // Iterators
5215   child_range children() {
5216     return child_range(child_iterator(), child_iterator());
5217   }
5218   const_child_range children() const {
5219     return const_child_range(const_child_iterator(), const_child_iterator());
5220   }
5221 };
5222
5223 /// AsTypeExpr - Clang builtin function __builtin_astype [OpenCL 6.2.4.2]
5224 /// This AST node provides support for reinterpreting a type to another
5225 /// type of the same size.
5226 class AsTypeExpr : public Expr {
5227 private:
5228   Stmt *SrcExpr;
5229   SourceLocation BuiltinLoc, RParenLoc;
5230
5231   friend class ASTReader;
5232   friend class ASTStmtReader;
5233   explicit AsTypeExpr(EmptyShell Empty) : Expr(AsTypeExprClass, Empty) {}
5234
5235 public:
5236   AsTypeExpr(Expr* SrcExpr, QualType DstType,
5237              ExprValueKind VK, ExprObjectKind OK,
5238              SourceLocation BuiltinLoc, SourceLocation RParenLoc)
5239     : Expr(AsTypeExprClass, DstType, VK, OK,
5240            DstType->isDependentType(),
5241            DstType->isDependentType() || SrcExpr->isValueDependent(),
5242            (DstType->isInstantiationDependentType() ||
5243             SrcExpr->isInstantiationDependent()),
5244            (DstType->containsUnexpandedParameterPack() ||
5245             SrcExpr->containsUnexpandedParameterPack())),
5246   SrcExpr(SrcExpr), BuiltinLoc(BuiltinLoc), RParenLoc(RParenLoc) {}
5247
5248   /// getSrcExpr - Return the Expr to be converted.
5249   Expr *getSrcExpr() const { return cast<Expr>(SrcExpr); }
5250
5251   /// getBuiltinLoc - Return the location of the __builtin_astype token.
5252   SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
5253
5254   /// getRParenLoc - Return the location of final right parenthesis.
5255   SourceLocation getRParenLoc() const { return RParenLoc; }
5256
5257   SourceLocation getBeginLoc() const LLVM_READONLY { return BuiltinLoc; }
5258   SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
5259
5260   static bool classof(const Stmt *T) {
5261     return T->getStmtClass() == AsTypeExprClass;
5262   }
5263
5264   // Iterators
5265   child_range children() { return child_range(&SrcExpr, &SrcExpr+1); }
5266   const_child_range children() const {
5267     return const_child_range(&SrcExpr, &SrcExpr + 1);
5268   }
5269 };
5270
5271 /// PseudoObjectExpr - An expression which accesses a pseudo-object
5272 /// l-value.  A pseudo-object is an abstract object, accesses to which
5273 /// are translated to calls.  The pseudo-object expression has a
5274 /// syntactic form, which shows how the expression was actually
5275 /// written in the source code, and a semantic form, which is a series
5276 /// of expressions to be executed in order which detail how the
5277 /// operation is actually evaluated.  Optionally, one of the semantic
5278 /// forms may also provide a result value for the expression.
5279 ///
5280 /// If any of the semantic-form expressions is an OpaqueValueExpr,
5281 /// that OVE is required to have a source expression, and it is bound
5282 /// to the result of that source expression.  Such OVEs may appear
5283 /// only in subsequent semantic-form expressions and as
5284 /// sub-expressions of the syntactic form.
5285 ///
5286 /// PseudoObjectExpr should be used only when an operation can be
5287 /// usefully described in terms of fairly simple rewrite rules on
5288 /// objects and functions that are meant to be used by end-developers.
5289 /// For example, under the Itanium ABI, dynamic casts are implemented
5290 /// as a call to a runtime function called __dynamic_cast; using this
5291 /// class to describe that would be inappropriate because that call is
5292 /// not really part of the user-visible semantics, and instead the
5293 /// cast is properly reflected in the AST and IR-generation has been
5294 /// taught to generate the call as necessary.  In contrast, an
5295 /// Objective-C property access is semantically defined to be
5296 /// equivalent to a particular message send, and this is very much
5297 /// part of the user model.  The name of this class encourages this
5298 /// modelling design.
5299 class PseudoObjectExpr final
5300     : public Expr,
5301       private llvm::TrailingObjects<PseudoObjectExpr, Expr *> {
5302   // PseudoObjectExprBits.NumSubExprs - The number of sub-expressions.
5303   // Always at least two, because the first sub-expression is the
5304   // syntactic form.
5305
5306   // PseudoObjectExprBits.ResultIndex - The index of the
5307   // sub-expression holding the result.  0 means the result is void,
5308   // which is unambiguous because it's the index of the syntactic
5309   // form.  Note that this is therefore 1 higher than the value passed
5310   // in to Create, which is an index within the semantic forms.
5311   // Note also that ASTStmtWriter assumes this encoding.
5312
5313   Expr **getSubExprsBuffer() { return getTrailingObjects<Expr *>(); }
5314   const Expr * const *getSubExprsBuffer() const {
5315     return getTrailingObjects<Expr *>();
5316   }
5317
5318   PseudoObjectExpr(QualType type, ExprValueKind VK,
5319                    Expr *syntactic, ArrayRef<Expr*> semantic,
5320                    unsigned resultIndex);
5321
5322   PseudoObjectExpr(EmptyShell shell, unsigned numSemanticExprs);
5323
5324   unsigned getNumSubExprs() const {
5325     return PseudoObjectExprBits.NumSubExprs;
5326   }
5327
5328 public:
5329   /// NoResult - A value for the result index indicating that there is
5330   /// no semantic result.
5331   enum : unsigned { NoResult = ~0U };
5332
5333   static PseudoObjectExpr *Create(const ASTContext &Context, Expr *syntactic,
5334                                   ArrayRef<Expr*> semantic,
5335                                   unsigned resultIndex);
5336
5337   static PseudoObjectExpr *Create(const ASTContext &Context, EmptyShell shell,
5338                                   unsigned numSemanticExprs);
5339
5340   /// Return the syntactic form of this expression, i.e. the
5341   /// expression it actually looks like.  Likely to be expressed in
5342   /// terms of OpaqueValueExprs bound in the semantic form.
5343   Expr *getSyntacticForm() { return getSubExprsBuffer()[0]; }
5344   const Expr *getSyntacticForm() const { return getSubExprsBuffer()[0]; }
5345
5346   /// Return the index of the result-bearing expression into the semantics
5347   /// expressions, or PseudoObjectExpr::NoResult if there is none.
5348   unsigned getResultExprIndex() const {
5349     if (PseudoObjectExprBits.ResultIndex == 0) return NoResult;
5350     return PseudoObjectExprBits.ResultIndex - 1;
5351   }
5352
5353   /// Return the result-bearing expression, or null if there is none.
5354   Expr *getResultExpr() {
5355     if (PseudoObjectExprBits.ResultIndex == 0)
5356       return nullptr;
5357     return getSubExprsBuffer()[PseudoObjectExprBits.ResultIndex];
5358   }
5359   const Expr *getResultExpr() const {
5360     return const_cast<PseudoObjectExpr*>(this)->getResultExpr();
5361   }
5362
5363   unsigned getNumSemanticExprs() const { return getNumSubExprs() - 1; }
5364
5365   typedef Expr * const *semantics_iterator;
5366   typedef const Expr * const *const_semantics_iterator;
5367   semantics_iterator semantics_begin() {
5368     return getSubExprsBuffer() + 1;
5369   }
5370   const_semantics_iterator semantics_begin() const {
5371     return getSubExprsBuffer() + 1;
5372   }
5373   semantics_iterator semantics_end() {
5374     return getSubExprsBuffer() + getNumSubExprs();
5375   }
5376   const_semantics_iterator semantics_end() const {
5377     return getSubExprsBuffer() + getNumSubExprs();
5378   }
5379
5380   llvm::iterator_range<semantics_iterator> semantics() {
5381     return llvm::make_range(semantics_begin(), semantics_end());
5382   }
5383   llvm::iterator_range<const_semantics_iterator> semantics() const {
5384     return llvm::make_range(semantics_begin(), semantics_end());
5385   }
5386
5387   Expr *getSemanticExpr(unsigned index) {
5388     assert(index + 1 < getNumSubExprs());
5389     return getSubExprsBuffer()[index + 1];
5390   }
5391   const Expr *getSemanticExpr(unsigned index) const {
5392     return const_cast<PseudoObjectExpr*>(this)->getSemanticExpr(index);
5393   }
5394
5395   SourceLocation getExprLoc() const LLVM_READONLY {
5396     return getSyntacticForm()->getExprLoc();
5397   }
5398
5399   SourceLocation getBeginLoc() const LLVM_READONLY {
5400     return getSyntacticForm()->getBeginLoc();
5401   }
5402   SourceLocation getEndLoc() const LLVM_READONLY {
5403     return getSyntacticForm()->getEndLoc();
5404   }
5405
5406   child_range children() {
5407     const_child_range CCR =
5408         const_cast<const PseudoObjectExpr *>(this)->children();
5409     return child_range(cast_away_const(CCR.begin()),
5410                        cast_away_const(CCR.end()));
5411   }
5412   const_child_range children() const {
5413     Stmt *const *cs = const_cast<Stmt *const *>(
5414         reinterpret_cast<const Stmt *const *>(getSubExprsBuffer()));
5415     return const_child_range(cs, cs + getNumSubExprs());
5416   }
5417
5418   static bool classof(const Stmt *T) {
5419     return T->getStmtClass() == PseudoObjectExprClass;
5420   }
5421
5422   friend TrailingObjects;
5423   friend class ASTStmtReader;
5424 };
5425
5426 /// AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*,
5427 /// __atomic_load, __atomic_store, and __atomic_compare_exchange_*, for the
5428 /// similarly-named C++11 instructions, and __c11 variants for <stdatomic.h>,
5429 /// and corresponding __opencl_atomic_* for OpenCL 2.0.
5430 /// All of these instructions take one primary pointer, at least one memory
5431 /// order. The instructions for which getScopeModel returns non-null value
5432 /// take one synch scope.
5433 class AtomicExpr : public Expr {
5434 public:
5435   enum AtomicOp {
5436 #define BUILTIN(ID, TYPE, ATTRS)
5437 #define ATOMIC_BUILTIN(ID, TYPE, ATTRS) AO ## ID,
5438 #include "clang/Basic/Builtins.def"
5439     // Avoid trailing comma
5440     BI_First = 0
5441   };
5442
5443 private:
5444   /// Location of sub-expressions.
5445   /// The location of Scope sub-expression is NumSubExprs - 1, which is
5446   /// not fixed, therefore is not defined in enum.
5447   enum { PTR, ORDER, VAL1, ORDER_FAIL, VAL2, WEAK, END_EXPR };
5448   Stmt *SubExprs[END_EXPR + 1];
5449   unsigned NumSubExprs;
5450   SourceLocation BuiltinLoc, RParenLoc;
5451   AtomicOp Op;
5452
5453   friend class ASTStmtReader;
5454 public:
5455   AtomicExpr(SourceLocation BLoc, ArrayRef<Expr*> args, QualType t,
5456              AtomicOp op, SourceLocation RP);
5457
5458   /// Determine the number of arguments the specified atomic builtin
5459   /// should have.
5460   static unsigned getNumSubExprs(AtomicOp Op);
5461
5462   /// Build an empty AtomicExpr.
5463   explicit AtomicExpr(EmptyShell Empty) : Expr(AtomicExprClass, Empty) { }
5464
5465   Expr *getPtr() const {
5466     return cast<Expr>(SubExprs[PTR]);
5467   }
5468   Expr *getOrder() const {
5469     return cast<Expr>(SubExprs[ORDER]);
5470   }
5471   Expr *getScope() const {
5472     assert(getScopeModel() && "No scope");
5473     return cast<Expr>(SubExprs[NumSubExprs - 1]);
5474   }
5475   Expr *getVal1() const {
5476     if (Op == AO__c11_atomic_init || Op == AO__opencl_atomic_init)
5477       return cast<Expr>(SubExprs[ORDER]);
5478     assert(NumSubExprs > VAL1);
5479     return cast<Expr>(SubExprs[VAL1]);
5480   }
5481   Expr *getOrderFail() const {
5482     assert(NumSubExprs > ORDER_FAIL);
5483     return cast<Expr>(SubExprs[ORDER_FAIL]);
5484   }
5485   Expr *getVal2() const {
5486     if (Op == AO__atomic_exchange)
5487       return cast<Expr>(SubExprs[ORDER_FAIL]);
5488     assert(NumSubExprs > VAL2);
5489     return cast<Expr>(SubExprs[VAL2]);
5490   }
5491   Expr *getWeak() const {
5492     assert(NumSubExprs > WEAK);
5493     return cast<Expr>(SubExprs[WEAK]);
5494   }
5495   QualType getValueType() const;
5496
5497   AtomicOp getOp() const { return Op; }
5498   unsigned getNumSubExprs() const { return NumSubExprs; }
5499
5500   Expr **getSubExprs() { return reinterpret_cast<Expr **>(SubExprs); }
5501   const Expr * const *getSubExprs() const {
5502     return reinterpret_cast<Expr * const *>(SubExprs);
5503   }
5504
5505   bool isVolatile() const {
5506     return getPtr()->getType()->getPointeeType().isVolatileQualified();
5507   }
5508
5509   bool isCmpXChg() const {
5510     return getOp() == AO__c11_atomic_compare_exchange_strong ||
5511            getOp() == AO__c11_atomic_compare_exchange_weak ||
5512            getOp() == AO__opencl_atomic_compare_exchange_strong ||
5513            getOp() == AO__opencl_atomic_compare_exchange_weak ||
5514            getOp() == AO__atomic_compare_exchange ||
5515            getOp() == AO__atomic_compare_exchange_n;
5516   }
5517
5518   bool isOpenCL() const {
5519     return getOp() >= AO__opencl_atomic_init &&
5520            getOp() <= AO__opencl_atomic_fetch_max;
5521   }
5522
5523   SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
5524   SourceLocation getRParenLoc() const { return RParenLoc; }
5525
5526   SourceLocation getBeginLoc() const LLVM_READONLY { return BuiltinLoc; }
5527   SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
5528
5529   static bool classof(const Stmt *T) {
5530     return T->getStmtClass() == AtomicExprClass;
5531   }
5532
5533   // Iterators
5534   child_range children() {
5535     return child_range(SubExprs, SubExprs+NumSubExprs);
5536   }
5537   const_child_range children() const {
5538     return const_child_range(SubExprs, SubExprs + NumSubExprs);
5539   }
5540
5541   /// Get atomic scope model for the atomic op code.
5542   /// \return empty atomic scope model if the atomic op code does not have
5543   ///   scope operand.
5544   static std::unique_ptr<AtomicScopeModel> getScopeModel(AtomicOp Op) {
5545     auto Kind =
5546         (Op >= AO__opencl_atomic_load && Op <= AO__opencl_atomic_fetch_max)
5547             ? AtomicScopeModelKind::OpenCL
5548             : AtomicScopeModelKind::None;
5549     return AtomicScopeModel::create(Kind);
5550   }
5551
5552   /// Get atomic scope model.
5553   /// \return empty atomic scope model if this atomic expression does not have
5554   ///   scope operand.
5555   std::unique_ptr<AtomicScopeModel> getScopeModel() const {
5556     return getScopeModel(getOp());
5557   }
5558 };
5559
5560 /// TypoExpr - Internal placeholder for expressions where typo correction
5561 /// still needs to be performed and/or an error diagnostic emitted.
5562 class TypoExpr : public Expr {
5563 public:
5564   TypoExpr(QualType T)
5565       : Expr(TypoExprClass, T, VK_LValue, OK_Ordinary,
5566              /*isTypeDependent*/ true,
5567              /*isValueDependent*/ true,
5568              /*isInstantiationDependent*/ true,
5569              /*containsUnexpandedParameterPack*/ false) {
5570     assert(T->isDependentType() && "TypoExpr given a non-dependent type");
5571   }
5572
5573   child_range children() {
5574     return child_range(child_iterator(), child_iterator());
5575   }
5576   const_child_range children() const {
5577     return const_child_range(const_child_iterator(), const_child_iterator());
5578   }
5579
5580   SourceLocation getBeginLoc() const LLVM_READONLY { return SourceLocation(); }
5581   SourceLocation getEndLoc() const LLVM_READONLY { return SourceLocation(); }
5582
5583   static bool classof(const Stmt *T) {
5584     return T->getStmtClass() == TypoExprClass;
5585   }
5586
5587 };
5588 } // end namespace clang
5589
5590 #endif // LLVM_CLANG_AST_EXPR_H