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