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