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