Expr.h revision ec5bc81fd55bfcc26fc4bde6d5e33113d94c2209
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- Expr.h - Classes for representing expressions ----------*- C++ -*-===//
25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//                     The LLVM Compiler Infrastructure
45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source
60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details.
75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//  This file defines the Expr interface and subclasses.
115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#ifndef LLVM_CLANG_AST_EXPR_H
155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#define LLVM_CLANG_AST_EXPR_H
165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson#include "clang/AST/APValue.h"
185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Stmt.h"
195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Type.h"
20161755a09898c95d21bfff33707da9ca41cd53c5John McCall#include "clang/AST/DeclAccessPair.h"
215baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall#include "clang/AST/OperationKinds.h"
22709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek#include "clang/AST/ASTVector.h"
23409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson#include "clang/AST/UsuallyTinyPtrVector.h"
245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/Basic/TypeTraits.h"
25525a05093a4816af961fe2bc6b8a81c17e2e26c2Chris Lattner#include "llvm/ADT/APSInt.h"
263b8d116703db8018f855cbb4733ace426422623bNate Begeman#include "llvm/ADT/APFloat.h"
27b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar#include "llvm/ADT/SmallVector.h"
28c5ae899b4bbf65488445316c63168079177db0edSteve Naroff#include "llvm/ADT/StringRef.h"
295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include <cctype>
305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
31590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattnernamespace clang {
32c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson  class ASTContext;
33c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class APValue;
34c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class Decl;
35c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class IdentifierInfo;
368e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor  class ParmVarDecl;
37c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class NamedDecl;
3856ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  class ValueDecl;
39409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  class BlockDecl;
4088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  class CXXBaseSpecifier;
4188a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  class CXXOperatorCallExpr;
42833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  class CXXMemberCallExpr;
43d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  class ObjCPropertyRefExpr;
4488a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  class TemplateArgumentLoc;
457ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson  class TemplateArgumentListInfo;
46f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  class OpaqueValueExpr;
477ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson
485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// \brief A simple array of base specifiers.
495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertypedef SmallVector<CXXBaseSpecifier*, 4> CXXCastPath;
505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Expr - This represents one expression.  Note that Expr's are subclasses of
525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Stmt.  This allows an expression to be transparently used any place a Stmt
535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is required.
54898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor///
55bef0efd11bc4430a3ee437a3213cec5c18af855aChris Lattnerclass Expr : public Stmt {
569ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor  QualType TR;
571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
58898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorprotected:
59898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  Expr(StmtClass SC, QualType T, ExprValueKind VK, ExprObjectKind OK,
60898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor       bool TD, bool VD, bool ID, bool ContainsUnexpandedParameterPack)
611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : Stmt(SC)
62898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  {
63898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    ExprBits.TypeDependent = TD;
64898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    ExprBits.ValueDependent = VD;
655baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall    ExprBits.InstantiationDependent = ID;
665baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall    ExprBits.ValueKind = VK;
675baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall    ExprBits.ObjectKind = OK;
685baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall    ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack;
695baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall    setType(T);
70f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  }
71898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
725baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall  /// \brief Construct an empty expression.
73898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  explicit Expr(StmtClass SC, EmptyShell) : Stmt(SC) { }
74898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
75898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorpublic:
760b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  QualType getType() const { return TR; }
770b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  void setType(QualType t) {
780b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor    // In C++, the type of an expression is always adjusted so that it
791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    // will not have reference type an expression will never have
8043d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor    // reference type (C++ [expr]p6). Use
8143d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor    // QualType::getNonReferenceType() to retrieve the non-reference
8243d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor    // type. Additionally, inspect Expr::isLvalue to determine whether
8343d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor    // an expression that is adjusted in this manner should be
8443d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor    // considered an lvalue.
8543d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor    assert((t.isNull() || !t->isReferenceType()) &&
8643d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor           "Expressions can't have reference type");
8743d9d9243329b1b75d1a6efdad9f16d6fb386b8eDouglas Gregor
881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    TR = t;
89f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor  }
901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
919d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor  /// isValueDependent - Determines whether this expression is
929d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor  /// value-dependent (C++ [temp.dep.constexpr]). For example, the
939d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor  /// array bound of "Chars" in the following example is
949d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor  /// value-dependent.
959d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor  /// @code
969d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor  /// template<int Size, char (&Chars)[Size]> struct meta_string;
979d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor  /// @endcode
98905d11d53aeb6b26744f44fedc2b2820c7a62df6Douglas Gregor  bool isValueDependent() const { return ExprBits.ValueDependent; }
998320aaaa01d931aa234fc3bce05b399ef41898d5Daniel Dunbar
100f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor  /// \brief Set whether this expression is value-dependent or not.
1011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setValueDependent(bool VD) {
1029d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    ExprBits.ValueDependent = VD;
10377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek    if (VD)
104898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor      ExprBits.InstantiationDependent = true;
105898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
106898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// isTypeDependent - Determines whether this expression is
108898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// type-dependent (C++ [temp.dep.expr]), which means that its type
109898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// could change from one template instantiation to the next. For
110898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// example, the expressions "x" and "x + y" are type-dependent in
111898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// the following code, but "y" is not type-dependent:
112898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// @code
1130b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// template<typename T>
1140b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// void add(T x, int y) {
1150b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  ///   x + y;
116898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// }
117898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// @endcode
118898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  bool isTypeDependent() const { return ExprBits.TypeDependent; }
119898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
120898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// \brief Set whether this expression is type-dependent or not.
121898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  void setTypeDependent(bool TD) {
1221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    ExprBits.TypeDependent = TD;
123898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    if (TD)
124898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor      ExprBits.InstantiationDependent = true;
125898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
126898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
127898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// \brief Whether this expression is instantiation-dependent, meaning that
128898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// it depends in some way on a template parameter, even if neither its type
1290b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// nor (constant) value can change due to the template instantiation.
1300b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  ///
1310b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// In the following example, the expression \c sizeof(sizeof(T() + T())) is
1325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// instantiation-dependent (since it involves a template parameter \c T), but
1335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// is neither type- nor value-dependent, since the type of the inner
1345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// \c sizeof is known (\c std::size_t) and therefore the size of the outer
1355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// \c sizeof is known.
1365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
1375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// \code
1385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// template<typename T>
1395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// void f(T x, T y) {
1401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///   sizeof(sizeof(T() + T());
141026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  /// }
142026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  /// \endcode
143026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  ///
144026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  bool isInstantiationDependent() const {
145026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    return ExprBits.InstantiationDependent;
146df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump  }
1471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// \brief Set whether this expression is instantiation-dependent or not.
1495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void setInstantiationDependent(bool ID) {
1505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ExprBits.InstantiationDependent = ID;
1515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// \brief Whether this expression contains an unexpanded parameter
1545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// pack (for C++0x variadic templates).
1555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
1565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Given the following function template:
15708ad47cbd1f81fcb31dbc731c13b885a07e12704Bill Wendling  ///
15876458501a8963fa11b91c9337a487de6871169b4Sebastian Redl  /// \code
1595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// template<typename F, typename ...Types>
1605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// void forward(const F &f, Types &&...args) {
1615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///   f(static_cast<Types&&>(args)...);
1625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// }
1635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// \endcode
164fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff  ///
16586f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor  /// The expressions \c args and \c static_cast<Types&&>(args) both
1662514a309204341798f96912ce7a90841bea59727Fariborz Jahanian  /// contain parameter packs.
167e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian  bool containsUnexpandedParameterPack() const {
168e873fb74219f48407ae0b8fa083aa7f0b6ff1427Douglas Gregor    return ExprBits.ContainsUnexpandedParameterPack;
1695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
17028be73f74c9e241a23ea24fe5756623de6bf1084Chris Lattner
17153202857c60214d80950a975e6e52aebf30bd16aEli Friedman  /// \brief Set the bit that describes whether this expression
1725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// contains an unexpanded parameter pack.
1735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void setContainsUnexpandedParameterPack(bool PP = true) {
1741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    ExprBits.ContainsUnexpandedParameterPack = PP;
1755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
17744e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar  /// getExprLoc - Return the preferred location for the arrow when diagnosing
17844e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar  /// a problem with a generic expression.
17944e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar  SourceLocation getExprLoc() const;
18044e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar
1815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isUnusedResultAWarning - Return true if this immediate expression should
1825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// be warned about if the result is unused.  If so, fill in Loc and Ranges
1835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// with location to warn on and the source range[s] to report with the
1845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// warning.
185fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff  bool isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1,
1865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                              SourceRange &R2, ASTContext &Ctx) const;
187ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner
1885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isLValue - True if this expression is an "l-value" according to
1895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// the rules of the current language.  C and C++ give somewhat
1904f6a7d7ead09b439216c32f2de806a998aeb222aSteve Naroff  /// different rules for this concept, but in general, the result of
1915daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian  /// an l-value expression identifies a specific object whereas the
192ba8d2d684e74a20bef03828c21c991d222c7e9e5Fariborz Jahanian  /// result of an r-value expression is a value detached from any
19386f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor  /// specific storage.
1942514a309204341798f96912ce7a90841bea59727Fariborz Jahanian  ///
195e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian  /// C++0x divides the concept of "r-value" into pure r-values
196e873fb74219f48407ae0b8fa083aa7f0b6ff1427Douglas Gregor  /// ("pr-values") and so-called expiring values ("x-values"), which
1975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// identify specific objects that can be safely cannibalized for
19844e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar  /// their resources.  This is an unfortunate abuse of terminology on
19944e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar  /// the part of the C++ committee.  In Clang, when we say "r-value",
2001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// we generally mean a pr-value.
2012111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  bool isLValue() const { return getValueKind() == VK_LValue; }
2022111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  bool isRValue() const { return getValueKind() == VK_RValue; }
2032111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  bool isXValue() const { return getValueKind() == VK_XValue; }
2042111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  bool isGLValue() const { return getValueKind() != VK_RValue; }
2052111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl
2062111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  enum LValueClassification {
2072111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    LV_Valid,
2082111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    LV_NotObjectType,
2092111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    LV_IncompleteVoidType,
2102111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    LV_DuplicateVectorComponents,
2112111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    LV_InvalidExpression,
2122111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    LV_InvalidMessageExpression,
2132111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    LV_MemberFunction,
2142111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    LV_SubObjCPropertySetting,
2152111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    LV_ClassTemporary
2162111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  };
2172111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// Reasons why an expression might not be an l-value.
2182111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  LValueClassification ClassifyLValue(ASTContext &Ctx) const;
2192111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl
2202111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type,
2212111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// does not have an incomplete type, does not have a const-qualified type,
2222111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// and if it is a structure or union, does not have any member (including,
2232111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// recursively, any member or element of all contained aggregates or unions)
2242111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// with a const-qualified type.
2252111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  ///
2262111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// \param Loc [in] [out] - A source location which *may* be filled
2272111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// in with the location of the expression making this a
2282111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// non-modifiable lvalue, if specified.
2292111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  enum isModifiableLvalueResult {
2302111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    MLV_Valid,
2312111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    MLV_NotObjectType,
2322111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    MLV_IncompleteVoidType,
2332111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    MLV_DuplicateVectorComponents,
2342111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    MLV_InvalidExpression,
2352111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    MLV_LValueCast,           // Specialized form of MLV_InvalidExpression.
2362111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    MLV_IncompleteType,
2372111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    MLV_ConstQualified,
2382111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    MLV_ArrayType,
2392111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    MLV_NotBlockQualified,
2402111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    MLV_ReadonlyProperty,
2412111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    MLV_NoSetterProperty,
2422111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    MLV_MemberFunction,
2432111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    MLV_SubObjCPropertySetting,
2442111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    MLV_InvalidMessageExpression,
2452111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    MLV_ClassTemporary
2462111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  };
2472111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx,
2482111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl                                              SourceLocation *Loc = 0) const;
2492111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl
2502111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// \brief The return type of classify(). Represents the C++0x expression
2512111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  ///        taxonomy.
2522111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  class Classification {
2532111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  public:
2542111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    /// \brief The various classification results. Most of these mean prvalue.
2552111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    enum Kinds {
2562111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CL_LValue,
2572111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CL_XValue,
2582111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CL_Function, // Functions cannot be lvalues in C.
2592111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CL_Void, // Void cannot be an lvalue in C.
2602111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CL_AddressableVoid, // Void expression whose address can be taken in C.
2612111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CL_DuplicateVectorComponents, // A vector shuffle with dupes.
2622111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CL_MemberFunction, // An expression referring to a member function
2632111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CL_SubObjCPropertySetting,
2642111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CL_ClassTemporary, // A prvalue of class type
2652111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CL_ObjCMessageRValue, // ObjC message is an rvalue
2662111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CL_PRValue // A prvalue for any other reason, of any other type
2672111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    };
2682111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    /// \brief The results of modification testing.
2692111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    enum ModifiableType {
2702111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CM_Untested, // testModifiable was false.
2712111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CM_Modifiable,
2722111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CM_RValue, // Not modifiable because it's an rvalue
2732111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CM_Function, // Not modifiable because it's a function; C++ only
2742111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CM_LValueCast, // Same as CM_RValue, but indicates GCC cast-as-lvalue ext
2752111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CM_NotBlockQualified, // Not captured in the closure
2762111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CM_NoSetterProperty,// Implicit assignment to ObjC property without setter
2772111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CM_ConstQualified,
2782111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CM_ArrayType,
2792111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      CM_IncompleteType
2802111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    };
2812111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl
2822111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  private:
2832111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    friend class Expr;
2842111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl
2852111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    unsigned short Kind;
2862111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    unsigned short Modifiable;
2872111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl
2882111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    explicit Classification(Kinds k, ModifiableType m)
28933bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor      : Kind(k), Modifiable(m)
29033bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor    {}
29133bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor
2925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  public:
29338d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson    Classification() {}
29438d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson
29538d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson    Kinds getKind() const { return static_cast<Kinds>(Kind); }
2961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    ModifiableType getModifiable() const {
297093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson      assert(Modifiable != CM_Untested && "Did not test for modifiability.");
298093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson      return static_cast<ModifiableType>(Modifiable);
299c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    }
3002b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner    bool isLValue() const { return Kind == CL_LValue; }
3012b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner    bool isXValue() const { return Kind == CL_XValue; }
3022b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner    bool isGLValue() const { return Kind <= CL_XValue; }
3032b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner    bool isPRValue() const { return Kind >= CL_Function; }
3042b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner    bool isRValue() const { return Kind >= CL_XValue; }
305c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    bool isModifiable() const { return getModifiable() == CM_Modifiable; }
3065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    /// \brief Create a simple, modifiably lvalue
3085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    static Classification makeSimpleLValue() {
3095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return Classification(CL_LValue, CM_Modifiable);
310590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner    }
311590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner
3125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
313590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner  /// \brief Classify - Classify this expression according to the C++0x
3148070a8497c0fb3e6f70a557f788405d8945b1208Daniel Dunbar  ///        expression taxonomy.
315590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner  ///
3165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// C++0x defines ([basic.lval]) a new taxonomy of expressions to replace the
317c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman  /// old lvalue vs rvalue. This function determines the type of expression this
318c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman  /// is. There are three expression types:
3194204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall  /// - lvalues are classical lvalues as in C++03.
3201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// - prvalues are equivalent to rvalues in C++03.
32194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  /// - xvalues are expressions yielding unnamed rvalue references, e.g. a
32294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  ///   function returning an rvalue reference.
3232d6744ff04c1690a1485178d550d2fab84a0270bDaniel Dunbar  /// lvalues and xvalues are collectively referred to as glvalues, while
32494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  /// prvalues and xvalues together form rvalues.
3251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Classification Classify(ASTContext &Ctx) const {
32694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    return ClassifyImpl(Ctx, 0);
32794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  }
32894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson
3291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief ClassifyModifiable - Classify this expression according to the
33094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  ///        C++0x expression taxonomy, and see if it is valid on the left side
33194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  ///        of an assignment.
33294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  ///
33394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  /// This function extends classify in that it also tests whether the
33494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  /// expression is modifiable (C99 6.3.2.1p1).
33594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  /// \param Loc A source location that might be filled with a relevant location
33694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  ///            if the expression is not modifiable.
33794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  Classification ClassifyModifiable(ASTContext &Ctx, SourceLocation &Loc) const{
33894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    return ClassifyImpl(Ctx, &Loc);
33994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  }
34094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson
3411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// getValueKindForType - Given a formal return or parameter type,
34294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  /// give its value kind.
343e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara  static ExprValueKind getValueKindForType(QualType T) {
344e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara    if (const ReferenceType *RT = T->getAs<ReferenceType>())
345e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara      return (isa<LValueReferenceType>(RT)
346e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara                ? VK_LValue
347e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara                : (RT->getPointeeType()->isFunctionType()
348e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara                     ? VK_LValue : VK_XValue));
349e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara    return VK_RValue;
350e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara  }
351e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara
35294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  /// getValueKind - The value kind that this expression produces.
35394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  ExprValueKind getValueKind() const {
3546ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner    return static_cast<ExprValueKind>(ExprBits.ValueKind);
355019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner  }
356019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner
357019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner  /// getObjectKind - The object kind that this expression produces.
3585b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson  /// Object kinds are meaningful only for expressions that yield an
3595b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson  /// l-value or x-value.
360cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall  ExprObjectKind getObjectKind() const {
361cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall    return static_cast<ExprObjectKind>(ExprBits.ObjectKind);
362cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall  }
363cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall
364cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall  bool isOrdinaryOrBitFieldObject() const {
3656ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner    ExprObjectKind OK = getObjectKind();
36645b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner    return (OK == OK_Ordinary || OK == OK_BitField);
36745b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner  }
368c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson
3696ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian  /// setValueKind - Set the value kind produced by this expression.
370c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  void setValueKind(ExprValueKind Cat) { ExprBits.ValueKind = Cat; }
3716ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian
3726ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian  /// setObjectKind - Set the object kind produced by this expression.
373393c247fe025ccb5f914e37e948192ea86faef8cFariborz Jahanian  void setObjectKind(ExprObjectKind Cat) { ExprBits.ObjectKind = Cat; }
374c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
37551fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlssonprivate:
37651fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson  Classification ClassifyImpl(ASTContext &Ctx, SourceLocation *Loc) const;
37751fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson
37851fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlssonpublic:
379b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman
380b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman  /// \brief If this expression refers to a bit-field, retrieve the
3811b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson  /// declaration of that bit-field.
3821b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson  FieldDecl *getBitField();
383e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara
384e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara  const FieldDecl *getBitField() const {
385e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara    return const_cast<Expr*>(this)->getBitField();
386ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  }
387ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor
388ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  /// \brief If this expression is an l-value for an Objective C
389ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  /// property, find the underlying property reference expression.
390ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  const ObjCPropertyRefExpr *getObjCProperty() const;
391c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
392ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  /// \brief Returns whether this expression refers to a vector element.
393ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  bool refersToVectorElement() const;
394ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor
395c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  /// isKnownToHaveBooleanValue - Return true if this is an integer expression
396ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  /// that is known to return 0 or 1.  This happens for _Bool/bool expressions
397ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  /// but also int expressions which are produced by things like comparisons in
398ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  /// C.
399ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  bool isKnownToHaveBooleanValue() const;
400c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
401efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson  /// isIntegerConstantExpr - Return true if this expression is a valid integer
402efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson  /// constant expression, and, if so, return its value in Result.  If not a
403efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson  /// valid i-c-e, return false and fill in Loc (if specified) with the location
404ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  /// of the invalid expression.
405ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
406efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson                             SourceLocation *Loc = 0,
40744baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian                             bool isEvaluated = true) const;
4081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const {
409102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian    llvm::APSInt X;
4101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return isIntegerConstantExpr(X, Ctx, Loc);
4114e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  }
4121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// isConstantInitializer - Returns true if this expression is a constant
4134e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  /// initializer, which can be emitted at compile-time.
4144e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  bool isConstantInitializer(ASTContext &Ctx, bool ForRef) const;
4152b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner
41656f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  /// EvalResult is a struct with detailed info about an evaluated expression.
41756f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  struct EvalResult {
41827c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor    /// Val - This is the value the expression can be folded to.
41956f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner    APValue Val;
4201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4212fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall    /// HasSideEffects - Whether the evaluated expression has side effects.
4222fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall    /// For example, (f() && 0) can be folded, but it still has side effects.
4232fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall    bool HasSideEffects;
4242fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall
425ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner    /// Diag - If the expression is unfoldable, then Diag contains a note
426ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner    /// diagnostic indicating why it's not foldable. DiagLoc indicates a caret
427ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner    /// position for the error, and DiagExpr is the expression that caused
428ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner    /// the error.
4291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    /// If the expression is foldable, but not an integer constant expression,
4306eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    /// Diag contains a note diagnostic that describes why it isn't an integer
4316eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    /// constant expression. If the expression *is* an integer constant
4326eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    /// expression, then Diag will be zero.
433c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    unsigned Diag;
4346eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    const Expr *DiagExpr;
4356eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    SourceLocation DiagLoc;
4366eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor
4376eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    EvalResult() : HasSideEffects(false), Diag(0), DiagExpr(0) {}
438c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
4392f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor    // isGlobalLValue - Return true if the evaluated lvalue expression
4402f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor    // is global.
4412f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor    bool isGlobalLValue() const;
4422f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor    // hasSideEffects - Return true if the evaluated expression has
4432f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor    // side effects.
4442f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor    bool hasSideEffects() const {
4452f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor      return HasSideEffects;
4462f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor    }
4472f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor  };
4482b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner
4494e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  /// Evaluate - Return true if this is a constant which we can fold using
4504e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  /// any crazy technique (that has nothing to do with language standards) that
45156f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  /// we want to.  If this function returns true, it returns the folded constant
45256f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  /// in Result.
45356f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  bool Evaluate(EvalResult &Result, const ASTContext &Ctx) const;
454ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner
455ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  /// EvaluateAsBooleanCondition - Return true if this is a constant
456ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  /// which we we can fold and convert to a boolean condition using
4571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// any crazy technique that we want to.
458898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  bool EvaluateAsBooleanCondition(bool &Result, const ASTContext &Ctx) const;
459898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
460898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// isEvaluatable - Call Evaluate to see if this expression can be constant
4611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// folded, but discard the result.
4625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isEvaluatable(const ASTContext &Ctx) const;
4631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// HasSideEffects - This routine returns true for all those expressions
4655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// which must be evaluated each time and must not be optimized away
4665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// or evaluated at compile time. Example is a function call, volatile
4675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// variable read.
4681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool HasSideEffects(const ASTContext &Ctx) const;
4695549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek
4705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// EvaluateAsInt - Call Evaluate and return the folded integer. This
4715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// must be called on an expression that constant folds to an integer.
4725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::APSInt EvaluateAsInt(const ASTContext &Ctx) const;
473a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
474a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// EvaluateAsLValue - Evaluate an expression to see if it's a lvalue
475a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// with link time known address.
476a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  bool EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx) const;
477a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
478c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  /// EvaluateAsLValue - Evaluate an expression to see if it's a lvalue.
479a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  bool EvaluateAsAnyLValue(EvalResult &Result, const ASTContext &Ctx) const;
480a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
481a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Enumeration used to describe the kind of Null pointer constant
482a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// returned from \c isNullPointerConstant().
483a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  enum NullPointerConstantKind {
484a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    /// \brief Expression is not a Null pointer constant.
485a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    NPCK_NotNull = 0,
486a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
487a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    /// \brief Expression is a Null pointer constant built from a zero integer.
488c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    NPCK_ZeroInteger,
489a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
490a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    /// \brief Expression is a C++0X nullptr.
491c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    NPCK_CXX0X_nullptr,
492a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
493a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    /// \brief Expression is a GNU-style __null constant.
494a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    NPCK_GNUNull
495a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  };
496c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
497a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Enumeration used to describe how \c isNullPointerConstant()
498833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  /// should cope with value-dependent expressions.
499833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  enum NullPointerConstantValueDependence {
500a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    /// \brief Specifies that the expression should never be value-dependent.
501c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    NPC_NeverValueDependent = 0,
502a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
503833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    /// \brief Specifies that a value-dependent expression of integral or
504833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    /// dependent type should be considered a null pointer constant.
505a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    NPC_ValueDependentIsNull,
506d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
507d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    /// \brief Specifies that a value-dependent expression should be considered
508d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    /// to never be a null pointer constant.
5098dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis    NPC_ValueDependentIsNotNull
510d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  };
511a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
512c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  /// isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to
5135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// a Null pointer constant. The return value can further distinguish the
5145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// kind of NULL pointer constant that was detected.
5155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  NullPointerConstantKind isNullPointerConstant(
516a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      ASTContext &Ctx,
517c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt      NullPointerConstantValueDependence NPC) const;
518a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
519a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// isOBJCGCCandidate - Return true if this expression may be used in a read/
520c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  /// write barrier.
521a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  bool isOBJCGCCandidate(ASTContext &Ctx) const;
522a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
523a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Returns true if this expression is a bound member function.
524c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  bool isBoundMemberFunction(ASTContext &Ctx) const;
525c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
526a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Given an expression of bound-member type, find the type
527c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  /// of the member.  Returns null if this is an *overloaded* bound
528a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// member expression.
529dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  static QualType findBoundMemberType(const Expr *expr);
5302577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
531a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Result type of CanThrow().
5325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum CanThrowResult {
5339e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis    CT_Cannot,
5342577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    CT_Dependent,
5352577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    CT_Can
5362577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  };
5372577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// \brief Test if this expression, if evaluated, might throw, according to
538a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  ///        the rules of C++ [expr.unary.noexcept].
539a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  CanThrowResult CanThrow(ASTContext &C) const;
5402cf719c3c3d805f630dfc6b1255e52647820888eSebastian Redl
541a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// IgnoreImpCasts - Skip past any implicit casts which might
542c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  /// surround this expression.  Only skips ImplicitCastExprs.
543a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  Expr *IgnoreImpCasts();
544a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
545c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  /// IgnoreImplicit - Skip past any implicit AST nodes which might
546a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// surround this expression.
547a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  Expr *IgnoreImplicit() { return cast<Expr>(Stmt::IgnoreImplicit()); }
548a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
549a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// IgnoreParens - Ignore parentheses.  If this Expr is a ParenExpr, return
550096832c5ed5b9106fa177ebc148489760c3bc496John McCall  ///  its subexpression.  If that subexpression is also a ParenExpr,
551a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  ///  then this method recursively returns its subexpression, and so forth.
552dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  ///  Otherwise, the method returns the current Expr.
553d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  Expr *IgnoreParens();
5540da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor
555663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis  /// IgnoreParenCasts - Ignore parentheses and casts.  Strip off any ParenExpr
5562577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// or CastExprs, returning their operand.
5572577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  Expr *IgnoreParenCasts();
5582577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
5592577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// IgnoreParenImpCasts - Ignore parentheses and implicit casts.  Strip off any
5602577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// ParenExpr or ImplicitCastExprs, returning their operand.
561663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis  Expr *IgnoreParenImpCasts();
562663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis
563663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis  /// IgnoreConversionOperator - Ignore conversion operator. If this Expr is a
564c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  /// call to a conversion operator, return the argument.
5650da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  Expr *IgnoreConversionOperator();
5660da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor
5670da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  const Expr *IgnoreConversionOperator() const {
5689e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis    return const_cast<Expr*>(this)->IgnoreConversionOperator();
5695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
570dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall
5710da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  const Expr *IgnoreParenImpCasts() const {
5720da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor    return const_cast<Expr*>(this)->IgnoreParenImpCasts();
5730da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  }
5741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
575a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// Ignore parentheses and lvalue casts.  Strip off any ParenExpr and
576a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// CastExprs that represent lvalue casts, returning their operand.
577a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  Expr *IgnoreParenLValueCasts();
578dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall
579a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  const Expr *IgnoreParenLValueCasts() const {
5800da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor    return const_cast<Expr*>(this)->IgnoreParenLValueCasts();
5810da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  }
582663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis
5832577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the
5842577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// value (including ptr->int casts of the same size).  Strip off any
5852577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// ParenExpr or CastExprs, returning their operand.
5862577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  Expr *IgnoreParenNoopCasts(ASTContext &Ctx);
5872577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
5882577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// \brief Determine whether this expression is a default function argument.
5892577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  ///
5902577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// Default arguments are implicitly generated in the abstract syntax tree
591663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis  /// by semantic analysis for function calls, object constructions, etc. in
592663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis  /// C++. Default arguments are represented by \c CXXDefaultArgExpr nodes;
593663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis  /// this routine also looks through any implicit casts to determine whether
594c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  /// the expression is a default argument.
595dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  bool isDefaultArgument() const;
596dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall
597dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  /// \brief Determine whether the result of this expression is a
598904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor  /// temporary object of the given class type.
5992577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const;
6002577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
6012577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// \brief Whether this expression is an implicit reference to 'this' in C++.
6022577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  bool isImplicitCXXThis() const;
6039e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis
6040b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  const Expr *IgnoreImpCasts() const {
605a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return const_cast<Expr*>(this)->IgnoreImpCasts();
6061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
607a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  const Expr *IgnoreParens() const {
608a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return const_cast<Expr*>(this)->IgnoreParens();
609a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
610c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  const Expr *IgnoreParenCasts() const {
611a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return const_cast<Expr*>(this)->IgnoreParenCasts();
612a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
613a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  const Expr *IgnoreParenNoopCasts(ASTContext &Ctx) const {
614a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return const_cast<Expr*>(this)->IgnoreParenNoopCasts(Ctx);
615a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
616a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
617c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  static bool hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs);
618a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  static bool hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs);
619a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
620c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  static bool classof(const Stmt *T) {
621c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return T->getStmtClass() >= firstExprConstant &&
622a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor           T->getStmtClass() <= lastExprConstant;
623a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
624a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  static bool classof(const Expr *) { return true; }
625a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor};
626c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
627a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
628a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor//===----------------------------------------------------------------------===//
629c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt// Primary Expressions.
630096832c5ed5b9106fa177ebc148489760c3bc496John McCall//===----------------------------------------------------------------------===//
631096832c5ed5b9106fa177ebc148489760c3bc496John McCall
632096832c5ed5b9106fa177ebc148489760c3bc496John McCall/// OpaqueValueExpr - An expression referring to an opaque object of a
633096832c5ed5b9106fa177ebc148489760c3bc496John McCall/// fixed type and value class.  These don't correspond to concrete
634096832c5ed5b9106fa177ebc148489760c3bc496John McCall/// syntax; instead they're used to express operations (usually copy
635096832c5ed5b9106fa177ebc148489760c3bc496John McCall/// operations) on values whose source is generally obvious from
636096832c5ed5b9106fa177ebc148489760c3bc496John McCall/// context.
637096832c5ed5b9106fa177ebc148489760c3bc496John McCallclass OpaqueValueExpr : public Expr {
638096832c5ed5b9106fa177ebc148489760c3bc496John McCall  friend class ASTStmtReader;
639096832c5ed5b9106fa177ebc148489760c3bc496John McCall  Expr *SourceExpr;
640096832c5ed5b9106fa177ebc148489760c3bc496John McCall  SourceLocation Loc;
641096832c5ed5b9106fa177ebc148489760c3bc496John McCall
642096832c5ed5b9106fa177ebc148489760c3bc496John McCallpublic:
643096832c5ed5b9106fa177ebc148489760c3bc496John McCall  OpaqueValueExpr(SourceLocation Loc, QualType T, ExprValueKind VK,
644096832c5ed5b9106fa177ebc148489760c3bc496John McCall                  ExprObjectKind OK = OK_Ordinary)
645096832c5ed5b9106fa177ebc148489760c3bc496John McCall    : Expr(OpaqueValueExprClass, T, VK, OK,
646096832c5ed5b9106fa177ebc148489760c3bc496John McCall           T->isDependentType(), T->isDependentType(),
647096832c5ed5b9106fa177ebc148489760c3bc496John McCall           T->isInstantiationDependentType(),
648096832c5ed5b9106fa177ebc148489760c3bc496John McCall           false),
649096832c5ed5b9106fa177ebc148489760c3bc496John McCall      SourceExpr(0), Loc(Loc) {
650a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
651d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
652096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// Given an expression which invokes a copy constructor --- i.e.  a
653096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// CXXConstructExpr, possibly wrapped in an ExprWithCleanups ---
654096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// find the OpaqueValueExpr that's the source of the construction.
655096832c5ed5b9106fa177ebc148489760c3bc496John McCall  static const OpaqueValueExpr *findInCopyConstruct(const Expr *expr);
656096832c5ed5b9106fa177ebc148489760c3bc496John McCall
657096832c5ed5b9106fa177ebc148489760c3bc496John McCall  explicit OpaqueValueExpr(EmptyShell Empty)
658096832c5ed5b9106fa177ebc148489760c3bc496John McCall    : Expr(OpaqueValueExprClass, Empty) { }
659096832c5ed5b9106fa177ebc148489760c3bc496John McCall
660d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  /// \brief Retrieve the location of this expression.
661d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  SourceLocation getLocation() const { return Loc; }
662d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
663096832c5ed5b9106fa177ebc148489760c3bc496John McCall  SourceRange getSourceRange() const {
664096832c5ed5b9106fa177ebc148489760c3bc496John McCall    if (SourceExpr) return SourceExpr->getSourceRange();
665d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    return Loc;
666c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  }
667a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  SourceLocation getExprLoc() const {
668a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    if (SourceExpr) return SourceExpr->getExprLoc();
669a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return Loc;
670096832c5ed5b9106fa177ebc148489760c3bc496John McCall  }
671a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
672c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  child_range children() { return child_range(); }
673096832c5ed5b9106fa177ebc148489760c3bc496John McCall
674a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// The source expression of an opaque value expression is the
675c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  /// expression which originally generated the value.  This is
676a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// provided as a convenience for analyses that don't wish to
677a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// precisely model the execution behavior of the program.
678833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  ///
679096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// The source expression is typically set when building the
680a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// expression which binds the opaque value expression in the first
681c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  /// place.
682096832c5ed5b9106fa177ebc148489760c3bc496John McCall  Expr *getSourceExpr() const { return SourceExpr; }
683a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  void setSourceExpr(Expr *e) { SourceExpr = e; }
684c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
685a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  static bool classof(const Stmt *T) {
686a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return T->getStmtClass() == OpaqueValueExprClass;
687a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
688096832c5ed5b9106fa177ebc148489760c3bc496John McCall  static bool classof(const OpaqueValueExpr *) { return true; }
689a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor};
690c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
691096832c5ed5b9106fa177ebc148489760c3bc496John McCall/// \brief Represents an explicit template argument list in C++, e.g.,
692a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// the "<int>" in "sort<int>".
693c302113179a1c2b1254224ea9b6f5316ceeb375cSean Huntstruct ExplicitTemplateArgumentList {
694a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief The source location of the left angle bracket ('<');
695a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  SourceLocation LAngleLoc;
696a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
697096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// \brief The source location of the right angle bracket ('>');
698a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  SourceLocation RAngleLoc;
699c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
700096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// \brief The number of template arguments in TemplateArgs.
701a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// The actual template arguments (if any) are stored after the
702c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  /// ExplicitTemplateArgumentList structure.
7031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  unsigned NumTemplateArgs;
70499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor
7055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// \brief Retrieve the template arguments
7065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TemplateArgumentLoc *getTemplateArgs() {
7071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return reinterpret_cast<TemplateArgumentLoc *> (this + 1);
70877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  }
70977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
71077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  /// \brief Retrieve the template arguments
711663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis  const TemplateArgumentLoc *getTemplateArgs() const {
71260adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl    return reinterpret_cast<const TemplateArgumentLoc *> (this + 1);
7133397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl  }
7145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void initializeFrom(const TemplateArgumentListInfo &List);
716d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner  void initializeFrom(const TemplateArgumentListInfo &List,
717d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner                      bool &Dependent, bool &InstantiationDependent,
718227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson                      bool &ContainsUnexpandedParameterPack);
719227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  void copyInto(TemplateArgumentListInfo &List) const;
720227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  static std::size_t sizeFor(unsigned NumTemplateArgs);
721227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  static std::size_t sizeFor(const TemplateArgumentListInfo &List);
722848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson};
723848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson
724848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson/// \brief A reference to a declared variable, function, enum, etc.
725848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson/// [C99 6.5.1p2]
726227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson///
7271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// This encodes all the information about how a declaration is referenced
728227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson/// within an expression.
729227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson///
730227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson/// There are several optional constructs attached to DeclRefExprs only when
731227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson/// they apply in order to conserve memory. These are laid out past the end of
7321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// the object, and flags in the DeclRefExprBitfield track whether they exist:
733c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt///
734773f3973cf5e2b6b8788e895967dcb3c1e6ffe79Anders Carlsson///   DeclRefExprBits.HasQualifier:
7351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///       Specifies when this declaration reference expression has a C++
73617fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor///       nested-name-specifier.
7371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///   DeclRefExprBits.HasFoundDecl:
73817fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor///       Specifies when this declaration reference expression has a record of
73917fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor///       a NamedDecl (different from the referenced ValueDecl) which was found
740227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson///       during name lookup and/or overload resolution.
74117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor///   DeclRefExprBits.HasExplicitTemplateArgs:
74217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor///       Specifies when this declaration reference expression has an explicit
74317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor///       C++ template argument list.
74417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregorclass DeclRefExpr : public Expr {
74517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  /// \brief The declaration that we are referencing.
746848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson  ValueDecl *D;
7473a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson
748227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  /// \brief The location of the declaration name itself.
749227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  SourceLocation Loc;
7501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Provides source/type location info for the declaration name
752227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  /// embedded in D.
753d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner  DeclarationNameLoc DNLoc;
7541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
75577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  /// \brief Helper to retrieve the optional NestedNameSpecifierLoc.
75677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  NestedNameSpecifierLoc &getInternalQualifierLoc() {
75777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek    assert(hasQualifier());
758227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson    return *reinterpret_cast<NestedNameSpecifierLoc *>(this + 1);
759227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  }
7609996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
7619996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  /// \brief Helper to retrieve the optional NestedNameSpecifierLoc.
7629996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  const NestedNameSpecifierLoc &getInternalQualifierLoc() const {
7639996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    return const_cast<DeclRefExpr *>(this)->getInternalQualifierLoc();
7649996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  }
7659996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
7669996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  /// \brief Test whether there is a distinct FoundDecl attached to the end of
7679996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  /// this DRE.
7689996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  bool hasFoundDecl() const { return DeclRefExprBits.HasFoundDecl; }
7699996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
7709996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  /// \brief Helper to retrieve the optional NamedDecl through which this
7719996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  /// reference occured.
7729996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  NamedDecl *&getInternalFoundDecl() {
7739996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    assert(hasFoundDecl());
7749996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    if (hasQualifier())
7759996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis      return *reinterpret_cast<NamedDecl **>(&getInternalQualifierLoc() + 1);
7769996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    return *reinterpret_cast<NamedDecl **>(this + 1);
7779996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  }
7789996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
7799996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  /// \brief Helper to retrieve the optional NamedDecl through which this
7809996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  /// reference occured.
7819996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  NamedDecl *getInternalFoundDecl() const {
7829996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    return const_cast<DeclRefExpr *>(this)->getInternalFoundDecl();
7839996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  }
7849996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
7859996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  DeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
7869996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis              ValueDecl *D, const DeclarationNameInfo &NameInfo,
7879996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis              NamedDecl *FoundD,
7889996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis              const TemplateArgumentListInfo *TemplateArgs,
7899996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis              QualType T, ExprValueKind VK);
7909996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
7919996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  /// \brief Construct an empty declaration reference expression.
7929996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  explicit DeclRefExpr(EmptyShell Empty)
7939996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    : Expr(DeclRefExprClass, Empty) { }
7949996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
7959996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  /// \brief Computes the type- and value-dependence flags for this
7969996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  /// declaration reference expression.
7979996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  void computeDependence();
7989996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
7999996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidispublic:
8009996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  DeclRefExpr(ValueDecl *D, QualType T, ExprValueKind VK, SourceLocation L,
8019996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis              const DeclarationNameLoc &LocInfo = DeclarationNameLoc())
8029996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    : Expr(DeclRefExprClass, T, VK, OK_Ordinary, false, false, false, false),
8039996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis      D(D), Loc(L), DNLoc(LocInfo) {
8049996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    DeclRefExprBits.HasQualifier = 0;
8059996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    DeclRefExprBits.HasExplicitTemplateArgs = 0;
8069996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    DeclRefExprBits.HasFoundDecl = 0;
8075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    computeDependence();
8089996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  }
8095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8109996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  static DeclRefExpr *Create(ASTContext &Context,
8119996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                             NestedNameSpecifierLoc QualifierLoc,
8129996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                             ValueDecl *D,
8139996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                             SourceLocation NameLoc,
8149996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                             QualType T, ExprValueKind VK,
8155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                             NamedDecl *FoundD = 0,
8161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                             const TemplateArgumentListInfo *TemplateArgs = 0);
8175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8189996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  static DeclRefExpr *Create(ASTContext &Context,
8199996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                             NestedNameSpecifierLoc QualifierLoc,
8209996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                             ValueDecl *D,
8215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                             const DeclarationNameInfo &NameInfo,
8229996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                             QualType T, ExprValueKind VK,
8235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                             NamedDecl *FoundD = 0,
824a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson                             const TemplateArgumentListInfo *TemplateArgs = 0);
8259996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
8269996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  /// \brief Construct an empty declaration reference expression.
8279996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  static DeclRefExpr *CreateEmpty(ASTContext &Context,
8289996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                                  bool HasQualifier,
8299996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                                  bool HasFoundDecl,
8300b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor                                  bool HasExplicitTemplateArgs,
8319996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis                                  unsigned NumTemplateArgs);
8325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ValueDecl *getDecl() { return D; }
834313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  const ValueDecl *getDecl() const { return D; }
835313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  void setDecl(ValueDecl *NewD) { D = NewD; }
836313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor
8379996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  DeclarationNameInfo getNameInfo() const {
8380b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor    return DeclarationNameInfo(getDecl()->getDeclName(), Loc, DNLoc);
8390b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  }
8401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation getLocation() const { return Loc; }
8425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void setLocation(SourceLocation L) { Loc = L; }
8435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceRange getSourceRange() const;
8441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
84577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  /// \brief Determine whether this declaration reference was preceded by a
84677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  /// C++ nested-name-specifier, e.g., \c N::foo.
84777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  bool hasQualifier() const { return DeclRefExprBits.HasQualifier; }
8485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// \brief If the name was qualified, retrieves the nested-name-specifier
8505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// that precedes the name. Otherwise, returns NULL.
8515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  NestedNameSpecifier *getQualifier() const {
8525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (!hasQualifier())
853c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner      return 0;
8545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return getInternalQualifierLoc().getNestedNameSpecifier();
856c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner  }
8572333f7727f97018d6742e1e0938133bcfad967abEli Friedman
8582333f7727f97018d6742e1e0938133bcfad967abEli Friedman  /// \brief If the name was qualified, retrieves the nested-name-specifier
8595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// that precedes the name, with source-location information.
8600b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  NestedNameSpecifierLoc getQualifierLoc() const {
8610b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor    if (!hasQualifier())
8620b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor      return NestedNameSpecifierLoc();
8630b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
864018d8e0596dd57401eeddcf11ac84ff0a065fbbeChris Lattner    return getInternalQualifierLoc();
865c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner  }
8661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// \brief Get the NamedDecl through which this reference occured.
8681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
8695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// This Decl may be different from the ValueDecl actually referred to in the
8705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// presence of using declarations, etc. It always returns non-NULL, and may
8710b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// simple return the ValueDecl when appropriate.
8720b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  NamedDecl *getFoundDecl() {
8730b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor    return hasFoundDecl() ? getInternalFoundDecl() : D;
8740b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  }
8751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Get the NamedDecl through which this reference occurred.
8775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// See non-const variant.
8785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const NamedDecl *getFoundDecl() const {
87977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek    return hasFoundDecl() ? getInternalFoundDecl() : D;
88077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  }
88177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
88277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  /// \brief Determines whether this declaration reference was followed by an
8835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// explict template argument list.
8845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool hasExplicitTemplateArgs() const {
8855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return DeclRefExprBits.HasExplicitTemplateArgs;
8869996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  }
887720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek
8885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// \brief Retrieve the explicit template argument list that followed the
8899996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  /// member template name.
8909996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
891720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek    assert(hasExplicitTemplateArgs());
8929996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    if (hasFoundDecl())
8939996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis      return *reinterpret_cast<ExplicitTemplateArgumentList *>(
8949996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis        &getInternalFoundDecl() + 1);
8959996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
8965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (hasQualifier())
89717fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor      return *reinterpret_cast<ExplicitTemplateArgumentList *>(
8981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump        &getInternalQualifierLoc() + 1);
8999996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
90017fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor    return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
9019996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  }
9029996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
9039996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  /// \brief Retrieve the explicit template argument list that followed the
9049996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  /// member template name.
9059996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
9069996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    return const_cast<DeclRefExpr *>(this)->getExplicitTemplateArgs();
9079996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  }
9089996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
9099996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  /// \brief Retrieves the optional explicit template arguments.
91017fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  /// This points to the same data as getExplicitTemplateArgs(), but
911720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek  /// returns null if there are no explicit template arguments.
91217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  const ExplicitTemplateArgumentList *getExplicitTemplateArgsOpt() const {
913c9bec4bfea9090a08dd83a7b213f0c8adf8d78ecChris Lattner    if (!hasExplicitTemplateArgs()) return 0;
914da8249e57f3badecf925571881fe57243935c6c1Chris Lattner    return &getExplicitTemplateArgs();
915da8249e57f3badecf925571881fe57243935c6c1Chris Lattner  }
916da8249e57f3badecf925571881fe57243935c6c1Chris Lattner
917da8249e57f3badecf925571881fe57243935c6c1Chris Lattner  /// \brief Copies the template arguments (if present) into the given
9181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// structure.
91917fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
92017fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor    if (hasExplicitTemplateArgs())
92117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor      getExplicitTemplateArgs().copyInto(List);
9225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
9235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Retrieve the location of the left angle bracket following the
9251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// member name ('<'), if any.
9265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation getLAngleLoc() const {
9275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (!hasExplicitTemplateArgs())
9281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      return SourceLocation();
92977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
93077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek    return getExplicitTemplateArgs().LAngleLoc;
93177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  }
9325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// \brief Retrieve the template arguments provided as part of this
9345d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  /// template-id.
9355d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  const TemplateArgumentLoc *getTemplateArgs() const {
9365d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner    if (!hasExplicitTemplateArgs())
9375d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner      return 0;
9385d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner
9395d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner    return getExplicitTemplateArgs().getTemplateArgs();
9405549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  }
9415d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner
9425d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  /// \brief Retrieve the number of template arguments provided as part of this
9432333f7727f97018d6742e1e0938133bcfad967abEli Friedman  /// template-id.
9441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  unsigned getNumTemplateArgs() const {
945cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor    if (!hasExplicitTemplateArgs())
9461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      return 0;
947cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
948cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor    return getExplicitTemplateArgs().NumTemplateArgs;
9495549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  }
9505549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek
951cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  /// \brief Retrieve the location of the right angle bracket following the
952cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  /// template arguments ('>').
9535d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  SourceLocation getRAngleLoc() const {
9541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    if (!hasExplicitTemplateArgs())
9551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      return SourceLocation();
9565d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner
9575d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner    return getExplicitTemplateArgs().RAngleLoc;
9581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
9595d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner
9605d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  static bool classof(const Stmt *T) {
9615d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner    return T->getStmtClass() == DeclRefExprClass;
9625d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  }
9635d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  static bool classof(const DeclRefExpr *) { return true; }
964e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek
965e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek  // Iterators
966e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek  child_range children() { return child_range(); }
967a7ad98ff0919d6a24ea7c46634ea29bea551c1a0Chris Lattner
968c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner  friend class ASTStmtReader;
969c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner  friend class ASTStmtWriter;
970690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner};
971690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner
9728bea7c0ee44c71c817de7dc2be932b73bec90c9fChris Lattner/// PredefinedExpr - [C99 6.4.2.2] - A predefined identifier such as __func__.
973690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattnerclass PredefinedExpr : public Expr {
974c4a09c189981b4561428e4b56fd250718e2717bbChris Lattnerpublic:
975c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner  enum IdentType {
976c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner    Func,
977c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner    Function,
978c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner    PrettyFunction,
979c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner    /// PrettyFunctionNoVirtual - The same as PrettyFunction, except that the
9805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    /// 'virtual' keyword is omitted for virtual member functions.
9815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PrettyFunctionNoVirtual
9825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
9835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
984726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattnerprivate:
985726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  SourceLocation Loc;
9862085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  IdentType Type;
9872333f7727f97018d6742e1e0938133bcfad967abEli Friedmanpublic:
9881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  PredefinedExpr(SourceLocation l, QualType type, IdentType IT)
9895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    : Expr(PredefinedExprClass, type, VK_LValue, OK_Ordinary,
9902085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner           type->isDependentType(), type->isDependentType(),
9912085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner           type->isInstantiationDependentType(),
9922085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner           /*ContainsUnexpandedParameterPack=*/false),
9932085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner      Loc(l), Type(IT) {}
994a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson
9952085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  /// \brief Construct an empty predefined expression.
9962085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  explicit PredefinedExpr(EmptyShell Empty)
9971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : Expr(PredefinedExprClass, Empty) { }
9982085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner
9992085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  IdentType getIdentType() const { return Type; }
10002085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  void setIdentType(IdentType IT) { Type = IT; }
10012085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner
1002a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson  SourceLocation getLocation() const { return Loc; }
1003673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  void setLocation(SourceLocation L) { Loc = L; }
1004673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
1005673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  static std::string ComputeName(IdentType IT, const Decl *CurrentDecl);
1006b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar
1007b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar  SourceRange getSourceRange() const { return SourceRange(Loc); }
1008b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar
10092f4eaef37476ae6891ede8ba215d0f6fd093629bBenjamin Kramer  static bool classof(const Stmt *T) {
10105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getStmtClass() == PredefinedExprClass;
1011673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  }
1012673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  static bool classof(const PredefinedExpr *) { return true; }
1013b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar
1014673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  // Iterators
10155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  child_range children() { return child_range(); }
1016673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor};
1017673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
10188d4141f83d9de379547cf05bd75d4c6cf894b189Steve Naroff/// \brief Used by IntegerLiteral/FloatingLiteral to store the numeric without
1019b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar/// leaking memory.
1020b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar///
1021b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar/// For large floats/integers, APFloat/APInt will allocate memory from the heap
102233fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff/// to represent these numbers.  Unfortunately, when we use a BumpPtrAllocator
102333fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff/// to allocate IntegerLiteral/FloatingLiteral nodes the memory associated with
102433fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff/// the APFloat/APInt values will never get freed. APNumericStorage uses
1025726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner/// ASTContext's allocator for memory allocation.
1026726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattnerclass APNumericStorage {
1027726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  unsigned BitWidth;
10281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  union {
1029726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner    uint64_t VAL;    ///< Used to store the <= 64 bits integer value.
1030726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner    uint64_t *pVal;  ///< Used to store the >64 bits integer value.
1031726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  };
1032726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner
10331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool hasAllocation() const { return llvm::APInt::getNumWords(BitWidth) > 1; }
1034673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
1035673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  APNumericStorage(const APNumericStorage&); // do not implement
1036673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  APNumericStorage& operator=(const APNumericStorage&); // do not implement
1037673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
1038b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattnerprotected:
1039b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner  APNumericStorage() : BitWidth(0), VAL(0) { }
1040b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner
10415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::APInt getIntValue() const {
10421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    unsigned NumWords = llvm::APInt::getNumWords(BitWidth);
10431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    if (NumWords > 1)
10445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return llvm::APInt(BitWidth, NumWords, pVal);
10451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    else
10461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      return llvm::APInt(BitWidth, VAL);
10475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
10485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void setIntValue(ASTContext &C, const llvm::APInt &Val);
10491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump};
105077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
105177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenekclass APIntStorage : public APNumericStorage {
105277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenekpublic:
10535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::APInt getValue() const { return getIntValue(); }
10545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void setValue(ASTContext &C, const llvm::APInt &Val) { setIntValue(C, Val); }
10555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
10565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass APFloatStorage : public APNumericStorage {
10585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
10595549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  llvm::APFloat getValue() const { return llvm::APFloat(getIntValue()); }
10605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void setValue(ASTContext &C, const llvm::APFloat &Val) {
10615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    setIntValue(C, Val.bitcastToAPInt());
1062898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
10631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump};
1064898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
10651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass IntegerLiteral : public Expr {
1066c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor  APIntStorage Num;
10671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation Loc;
1068c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor
1069c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor  /// \brief Construct an empty integer literal.
10705549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  explicit IntegerLiteral(EmptyShell Empty)
10715549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    : Expr(IntegerLiteralClass, Empty) { }
1072c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor
1073c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregorpublic:
1074866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek  // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy,
10755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // or UnsignedLongLongTy
1076313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  IntegerLiteral(ASTContext &C, const llvm::APInt &V,
1077313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor                 QualType type, SourceLocation l)
1078c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor    : Expr(IntegerLiteralClass, type, VK_RValue, OK_Ordinary, false, false,
1079313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor           false, false),
1080313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor      Loc(l) {
1081313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor    assert(type->isIntegerType() && "Illegal type in IntegerLiteral");
1082c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor    assert(V.getBitWidth() == C.getIntWidth(type) &&
1083313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor           "Integer type is not the correct size for constant.");
10841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    setValue(C, V);
10851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
10865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// \brief Returns a new integer literal with value 'V' and type 'type'.
10881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \param type - either IntTy, LongTy, LongLongTy, UnsignedIntTy,
108977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  /// UnsignedLongTy, or UnsignedLongLongTy which should match the size of V
109077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  /// \param V - the value that the returned integer literal contains.
109177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  static IntegerLiteral *Create(ASTContext &C, const llvm::APInt &V,
10925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                                QualType type, SourceLocation l);
10935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// \brief Returns a new empty integer literal.
10945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static IntegerLiteral *Create(ASTContext &C, EmptyShell Empty);
10950518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl
10960518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  llvm::APInt getValue() const { return Num.getValue(); }
10975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceRange getSourceRange() const { return SourceRange(Loc); }
1098dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner
1099dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner  /// \brief Retrieve the location of the literal.
1100dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner  SourceLocation getLocation() const { return Loc; }
1101dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner
1102dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner  void setValue(ASTContext &C, const llvm::APInt &Val) { Num.setValue(C, Val); }
1103dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner  void setLocation(SourceLocation Location) { Loc = Location; }
1104dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner
11055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
11065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getStmtClass() == IntegerLiteralClass;
11075baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall  }
11085baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall  static bool classof(const IntegerLiteral *) { return true; }
11095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11100799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  // Iterators
11115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  child_range children() { return child_range(); }
11120799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall};
11131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CharacterLiteral : public Expr {
11155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
11169103bb27f4eefa0e0d7935387750e3aca24abc49Douglas Gregor  enum CharacterKind {
1117de7e66256b1bdfcf6526994825a8c8fced52a31cEli Friedman    Ascii,
11181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Wide,
11190799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall    UTF16,
11205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    UTF32
11210b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  };
11221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11232de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCallprivate:
11240b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  unsigned Value;
11250799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  SourceLocation Loc;
11260b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  unsigned Kind : 2;
11270b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregorpublic:
11285549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  // type should be IntTy
11290b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  CharacterLiteral(unsigned value, CharacterKind kind, QualType type,
11300b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor                   SourceLocation l)
11315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    : Expr(CharacterLiteralClass, type, VK_RValue, OK_Ordinary, false, false,
11325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           false, false),
11330b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor      Value(value), Loc(l), Kind(kind) {
11340b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  }
11355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11362085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  /// \brief Construct an empty character literal.
11372de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { }
11382085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner
11395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation getLocation() const { return Loc; }
11405a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek  CharacterKind getKind() const { return static_cast<CharacterKind>(Kind); }
11412085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner
11422de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  SourceRange getSourceRange() const { return SourceRange(Loc); }
11432085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner
11445a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek  unsigned getValue() const { return Value; }
11450799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall
11460799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  void setLocation(SourceLocation Location) { Loc = Location; }
11472de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  void setKind(CharacterKind kind) { Kind = kind; }
1148993cdca0fed7deb646e4654dfb2607227a497faaBenjamin Kramer  void setValue(unsigned Val) { Value = Val; }
11492de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall
11502de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  static bool classof(const Stmt *T) {
1151993cdca0fed7deb646e4654dfb2607227a497faaBenjamin Kramer    return T->getStmtClass() == CharacterLiteralClass;
11522de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  }
11532de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  static bool classof(const CharacterLiteral *) { return true; }
11542de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall
11552de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  // Iterators
11560799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  child_range children() { return child_range(); }
11571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump};
11585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FloatingLiteral : public Expr {
11605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  APFloatStorage Num;
11615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool IsExact : 1;
1162bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  SourceLocation Loc;
1163bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor
1164bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  FloatingLiteral(ASTContext &C, const llvm::APFloat &V, bool isexact,
1165bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor                  QualType Type, SourceLocation L)
1166bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor    : Expr(FloatingLiteralClass, Type, VK_RValue, OK_Ordinary, false, false,
1167bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor           false, false),
1168bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor      IsExact(isexact), Loc(L) {
1169bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor    setValue(C, V);
11705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
11715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// \brief Construct an empty floating-point literal.
11735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  explicit FloatingLiteral(EmptyShell Empty)
11745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    : Expr(FloatingLiteralClass, Empty), IsExact(false) { }
11755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
11771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static FloatingLiteral *Create(ASTContext &C, const llvm::APFloat &V,
11781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                 bool isexact, QualType Type, SourceLocation L);
11791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static FloatingLiteral *Create(ASTContext &C, EmptyShell Empty);
11805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::APFloat getValue() const { return Num.getValue(); }
11821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setValue(ASTContext &C, const llvm::APFloat &Val) {
118377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek    Num.setValue(C, Val);
118477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  }
118577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
11865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isExact() const { return IsExact; }
11875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void setExact(bool E) { IsExact = E; }
11888ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
11898ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// getValueAsApproximateDouble - This returns the value as an inaccurate
11908ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// double.  Note that this may cause loss of precision, but is useful for
11918ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// debugging dumps, etc.
11928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  double getValueAsApproximateDouble() const;
1193c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
11948ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  SourceLocation getLocation() const { return Loc; }
11958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  void setLocation(SourceLocation L) { Loc = L; }
11968ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
11978ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  SourceRange getSourceRange() const { return SourceRange(Loc); }
11988ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
11998ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  static bool classof(const Stmt *T) {
1200c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return T->getStmtClass() == FloatingLiteralClass;
12018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
12028ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  static bool classof(const FloatingLiteral *) { return true; }
12038ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
12048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Iterators
12058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  child_range children() { return child_range(); }
12068ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor};
12078ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
12088ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// ImaginaryLiteral - We support imaginary integer and floating point literals,
1209cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor/// like "1.0i".  We represent these as a wrapper around FloatingLiteral and
12108ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// IntegerLiteral classes.  Instances of this class always have a Complex type
1211cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor/// whose element type matches the subexpression.
12128ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor///
1213cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregorclass ImaginaryLiteral : public Expr {
1214cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor  Stmt *Val;
1215cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregorpublic:
1216cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor  ImaginaryLiteral(Expr *val, QualType Ty)
1217cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor    : Expr(ImaginaryLiteralClass, Ty, VK_RValue, OK_Ordinary, false, false,
12188ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor           false, false),
12198ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Val(val) {}
12208ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
12218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// \brief Build an empty imaginary literal.
1222c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  explicit ImaginaryLiteral(EmptyShell Empty)
12238ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    : Expr(ImaginaryLiteralClass, Empty) { }
12248ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
1225c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  const Expr *getSubExpr() const { return cast<Expr>(Val); }
12268ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  Expr *getSubExpr() { return cast<Expr>(Val); }
12278ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  void setSubExpr(Expr *E) { Val = E; }
1228c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
12298ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  SourceRange getSourceRange() const { return Val->getSourceRange(); }
12308ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  static bool classof(const Stmt *T) {
12318ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return T->getStmtClass() == ImaginaryLiteralClass;
12328ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
1233c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  static bool classof(const ImaginaryLiteral *) { return true; }
1234cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor
12358ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Iterators
1236c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  child_range children() { return child_range(&Val, &Val+1); }
12378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor};
12388ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
1239c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt/// StringLiteral - This represents a string literal expression, e.g. "foo"
12408ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// or L"bar" (wide strings).  The actual string is returned by getStrData()
12418ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// is NOT null-terminated, and the length of the string is determined by
1242c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt/// calling getByteLength().  The C type for a string is always a
12438ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// ConstantArrayType.  In C++, the char type is const qualified, in C it is
1244c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt/// not.
12458ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor///
1246c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt/// Note that strings in C can be formed by concatenation of multiple string
12478ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// literal pptokens in translation phase #6.  This keeps track of the locations
1248c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt/// of each of these pieces.
12498ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor///
12508ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// Strings in C can also be truncated and extended by assigning into arrays,
12518ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// e.g. with constructs like:
1252c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt///   char X[2] = "foobar";
12538ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// In this case, getByteLength() will return 6, but the string literal will
1254cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor/// have type "char[2]".
1255cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregorclass StringLiteral : public Expr {
1256cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregorpublic:
1257cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor  enum StringKind {
1258c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    Ascii,
12598ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    Wide,
1260c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    UTF8,
12618ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    UTF16,
12628ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    UTF32
1263c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  };
12648ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
12658ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorprivate:
12668ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  friend class ASTStmtReader;
12678ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
12688ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  const char *StrData;
12698ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  unsigned ByteLength;
12708ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  unsigned NumConcatenated;
12718ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  unsigned Kind : 3;
12728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  bool IsPascal : 1;
12738ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  SourceLocation TokLocs[1];
1274cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor
12758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  StringLiteral(QualType Ty) :
1276c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    Expr(StringLiteralClass, Ty, VK_LValue, OK_Ordinary, false, false, false,
12778ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor         false) {}
12788ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
12798ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorpublic:
1280c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  /// This is the "fully general" constructor that allows representation of
1281cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor  /// strings formed from multiple concatenated tokens.
1282cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor  static StringLiteral *Create(ASTContext &C, StringRef Str, StringKind Kind,
1283cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor                               bool Pascal, QualType Ty,
1284c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                               const SourceLocation *Loc, unsigned NumStrs);
1285cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor
1286c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  /// Simple constructor for string literals made from one token.
12878ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  static StringLiteral *Create(ASTContext &C, StringRef Str, StringKind Kind,
12888ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                               bool Pascal, QualType Ty,
12898ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                               SourceLocation Loc) {
12908ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return Create(C, Str, Kind, Pascal, Ty, &Loc, 1);
1291c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  }
12928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
12938ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// \brief Construct an empty string literal.
12948ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  static StringLiteral *CreateEmpty(ASTContext &C, unsigned NumStrs);
12958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
12968ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  StringRef getString() const {
1297c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return StringRef(StrData, ByteLength);
12988ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
12998ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
13008ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  unsigned getByteLength() const { return ByteLength; }
13018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
13028ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// \brief Sets the string data to the given string data.
13038ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  void setString(ASTContext &C, StringRef Str);
13048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
1305c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  StringKind getKind() const { return static_cast<StringKind>(Kind); }
1306c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  bool isAscii() const { return Kind == Ascii; }
13078ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  bool isWide() const { return Kind == Wide; }
1308c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  bool isUTF8() const { return Kind == UTF8; }
13098ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  bool isUTF16() const { return Kind == UTF16; }
13108ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  bool isUTF32() const { return Kind == UTF32; }
13118ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  bool isPascal() const { return IsPascal; }
13128ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
13138ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  bool containsNonAsciiOrNull() const {
1314c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    StringRef Str = getString();
13158ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    for (unsigned i = 0, e = Str.size(); i != e; ++i)
13168ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      if (!isascii(Str[i]) || !Str[i])
1317c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt        return true;
1318c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return false;
1319c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  }
1320c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  /// getNumConcatenated - Get the number of string literal tokens that were
13218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// concatenated in translation phase #6 to form this string literal.
13228ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  unsigned getNumConcatenated() const { return NumConcatenated; }
13238ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
1324c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  SourceLocation getStrTokenLoc(unsigned TokNum) const {
13258ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    assert(TokNum < NumConcatenated && "Invalid tok number");
13268ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return TokLocs[TokNum];
13278ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
13288ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  void setStrTokenLoc(unsigned TokNum, SourceLocation L) {
13298ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    assert(TokNum < NumConcatenated && "Invalid tok number");
13308ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    TokLocs[TokNum] = L;
13318ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
13328ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
13338ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// getLocationOfByte - Return a source location that points to the specified
1334c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  /// byte of this string literal.
13358ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  ///
13368ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// Strings are amazingly complex.  They can be formed from multiple tokens
13378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// and can have escape sequences in them in addition to the usual trigraph
13388ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// and escaped newline business.  This routine handles this complexity.
13398ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  ///
13408ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  SourceLocation getLocationOfByte(unsigned ByteNo, const SourceManager &SM,
1341c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                                   const LangOptions &Features,
13428ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                   const TargetInfo &Target) const;
13438ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
13448ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  typedef const SourceLocation *tokloc_iterator;
13458ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  tokloc_iterator tokloc_begin() const { return TokLocs; }
13468ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  tokloc_iterator tokloc_end() const { return TokLocs+NumConcatenated; }
13478ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
13488ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  SourceRange getSourceRange() const {
13498ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return SourceRange(TokLocs[0], TokLocs[NumConcatenated-1]);
13508ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
1351c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  static bool classof(const Stmt *T) {
13528ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return T->getStmtClass() == StringLiteralClass;
13538ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
13548ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  static bool classof(const StringLiteral *) { return true; }
13558ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
13568ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Iterators
13578ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  child_range children() { return child_range(); }
13588ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor};
13598ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
13608ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// ParenExpr - This represents a parethesized expression, e.g. "(1)".  This
13618ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// AST node is only formed if full location information is requested.
13628ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorclass ParenExpr : public Expr {
13638ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  SourceLocation L, R;
13648ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  Stmt *Val;
13658ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorpublic:
13668ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  ParenExpr(SourceLocation l, SourceLocation r, Expr *val)
1367c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    : Expr(ParenExprClass, val->getType(),
13688ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor           val->getValueKind(), val->getObjectKind(),
13698ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor           val->isTypeDependent(), val->isValueDependent(),
13708ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor           val->isInstantiationDependent(),
13718ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor           val->containsUnexpandedParameterPack()),
13728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      L(l), R(r), Val(val) {}
13738ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
13748ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// \brief Construct an empty parenthesized expression.
13758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  explicit ParenExpr(EmptyShell Empty)
13768ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    : Expr(ParenExprClass, Empty) { }
13778ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
13788ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  const Expr *getSubExpr() const { return cast<Expr>(Val); }
13798ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  Expr *getSubExpr() { return cast<Expr>(Val); }
13808ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  void setSubExpr(Expr *E) { Val = E; }
13818ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
13828ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  SourceRange getSourceRange() const { return SourceRange(L, R); }
13838ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
13848ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// \brief Get the location of the left parentheses '('.
13858ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  SourceLocation getLParen() const { return L; }
13868ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  void setLParen(SourceLocation Loc) { L = Loc; }
13870518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl
13880518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  /// \brief Get the location of the right parentheses ')'.
13890518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  SourceLocation getRParen() const { return R; }
13900518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  void setRParen(SourceLocation Loc) { R = Loc; }
13910518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl
1392d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl  static bool classof(const Stmt *T) {
1393a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    return T->getStmtClass() == ParenExprClass;
1394d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl  }
1395d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl  static bool classof(const ParenExpr *) { return true; }
13965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
139742602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor  // Iterators
13985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  child_range children() { return child_range(&Val, &Val+1); }
1399a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall};
14000518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl
14010518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl
14022850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl/// UnaryOperator - This represents the unary-expression's (except sizeof and
1403ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor/// alignof), the postinc/postdec operators from postfix-expression, and various
14042850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl/// extensions.
1405a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall///
1406ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor/// Notes on various nodes:
1407a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall///
1408ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor/// Real/Imag - These return the real/imag part of a complex operand.  If
1409ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor///   applied to a non-complex value, the former returns its operand and the
14101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///   later returns zero in the type of the operand.
1411ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor///
1412ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregorclass UnaryOperator : public Expr {
1413ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregorpublic:
1414ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor  typedef UnaryOperatorKind Opcode;
1415ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor
1416ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregorprivate:
1417ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor  unsigned Opc : 5;
1418ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor  SourceLocation Loc;
1419d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl  Stmt *Val;
14200518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redlpublic:
14210b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
14220b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  UnaryOperator(Expr *input, Opcode opc, QualType type,
14230b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor                ExprValueKind VK, ExprObjectKind OK, SourceLocation l)
14240b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor    : Expr(UnaryOperatorClass, type, VK, OK,
14255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           input->isTypeDependent() || type->isDependentType(),
14260b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor           input->isValueDependent(),
14270b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor           (input->isInstantiationDependent() ||
14280518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl            type->isInstantiationDependentType()),
14290518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl           input->containsUnexpandedParameterPack()),
14305ab75172051a6d2ea71a80a79e81c65519fd3462John McCall      Opc(opc), Loc(l), Val(input) {}
14315ab75172051a6d2ea71a80a79e81c65519fd3462John McCall
1432a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  /// \brief Build an empty unary operator.
14330518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  explicit UnaryOperator(EmptyShell Empty)
14345ab75172051a6d2ea71a80a79e81c65519fd3462John McCall    : Expr(UnaryOperatorClass, Empty), Opc(UO_AddrOf) { }
14350518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl
1436caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner  Opcode getOpcode() const { return static_cast<Opcode>(Opc); }
14370518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  void setOpcode(Opcode O) { Opc = O; }
1438d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl
14390518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  Expr *getSubExpr() const { return cast<Expr>(Val); }
1440caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner  void setSubExpr(Expr *E) { Val = E; }
1441caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner
1442caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner  /// getOperatorLoc - Return the location of the operator.
14430b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  SourceLocation getOperatorLoc() const { return Loc; }
14440b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setOperatorLoc(SourceLocation L) { Loc = L; }
1445a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall
1446a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  /// isPostfix - Return true if this is a postfix operation, like x++.
14471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool isPostfix(Opcode Op) {
14480b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor    return Op == UO_PostInc || Op == UO_PostDec;
14490b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  }
14500518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl
14510518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  /// isPrefix - Return true if this is a prefix operation, like --x.
14520518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  static bool isPrefix(Opcode Op) {
14530518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    return Op == UO_PreInc || Op == UO_PreDec;
14540518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  }
14550518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl
145676e773a443be9f006610f46529e07d4c8d857680Chris Lattner  bool isPrefix() const { return isPrefix(getOpcode()); }
14570b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  bool isPostfix() const { return isPostfix(getOpcode()); }
14580b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  bool isIncrementOp() const {
14590b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor    return Opc == UO_PreInc || Opc == UO_PostInc;
14600b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  }
1461866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek  bool isIncrementDecrementOp() const {
1462866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek    return Opc <= UO_PreDec;
1463866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek  }
1464866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek  static bool isArithmeticOp(Opcode Op) {
14655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return Op >= UO_Plus && Op <= UO_LNot;
14661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
14671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool isArithmeticOp() const { return isArithmeticOp(getOpcode()); }
14685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
14690518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
14701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// corresponds to, e.g. "sizeof" or "[pre]++"
147177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  static const char *getOpcodeStr(Opcode Op);
147277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
147377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  /// \brief Retrieve the unary opcode that corresponds to the given
14745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// overloaded operator.
14755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix);
14765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
14775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// \brief Retrieve the overloaded operator kind that corresponds to
14785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// the given unary opcode.
14795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
14805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
14815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceRange getSourceRange() const {
148277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek    if (isPostfix())
14831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      return SourceRange(Val->getLocStart(), Loc);
14845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    else
14855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return SourceRange(Loc, Val->getLocEnd());
14862324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  }
148773d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner  SourceLocation getExprLoc() const { return Loc; }
14882850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl
14892850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl  static bool classof(const Stmt *T) {
14902850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl    return T->getStmtClass() == UnaryOperatorClass;
14912850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl  }
149273d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner  static bool classof(const UnaryOperator *) { return true; }
149373d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner
149473d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner  // Iterators
14951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  child_range children() { return child_range(&Val, &Val+1); }
1496cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor};
1497cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
1498cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor/// OffsetOfExpr - [C99 7.17] - This represents an expression of the form
1499cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor/// offsetof(record-type, member-designator). For example, given:
15002324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek/// @code
15012324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek/// struct S {
15022324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek///   float f;
15032324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek///   double d;
15042324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek/// };
150533fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb/// struct T {
150633fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb///   int i;
150733fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb///   struct S s[10];
150833fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb/// };
15095549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek/// @endcode
15105549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek/// we can represent and evaluate the expression @c offsetof(struct T, s[2].d).
1511cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
1512cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregorclass OffsetOfExpr : public Expr {
15135549976193e34417d4474a5f4a514268ef6666c7Ted Kremenekpublic:
15145549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  // __builtin_offsetof(type, identifier(.identifier|[expr])*)
1515cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  class OffsetOfNode {
15161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  public:
15171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    /// \brief The kind of offsetof node we have.
15185549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    enum Kind {
151977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek      /// \brief An index into an array.
15201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      Array = 0x00,
15211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      /// \brief A field.
15225549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek      Field = 0x01,
15232324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek      /// \brief A field in a dependent type, known only by its name.
15241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      Identifier = 0x02,
15251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      /// \brief An implicit indirection through a C++ base class, when the
15265549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek      /// field found is in a base class.
15272324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek      Base = 0x03
15281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    };
152977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
15305549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  private:
15311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    enum { MaskBits = 2, Mask = 0x03 };
15321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    /// \brief The source range that covers this part of the designator.
153477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek    SourceRange Range;
15355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
15361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    /// \brief The data describing the designator, which comes in three
1537026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    /// different forms, depending on the lower two bits.
1538cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor    ///   - An unsigned index into the array of Expr*'s stored after this node
1539cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor    ///     in memory, for [constant-expression] designators.
15405cd9d6daf3acd4cc87fecebd81d9495b9e4ba9cdChris Lattner    ///   - A FieldDecl*, for references to a known field.
15415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ///   - An IdentifierInfo*, for references to a field with a given name
15421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    ///     when the class type is dependent.
15431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    ///   - A CXXBaseSpecifier*, for references that look at a field in a
15445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ///     base class.
15455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    uintptr_t Data;
15461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
154777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  public:
154877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek    /// \brief Create an offsetof node that refers to an array element.
154977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek    OffsetOfNode(SourceLocation LBracketLoc, unsigned Index,
15505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                 SourceLocation RBracketLoc)
15515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      : Range(LBracketLoc, RBracketLoc), Data((Index << 2) | Array) { }
15525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1553b4609806e9232593ece09ce08b630836e825865cDouglas Gregor    /// \brief Create an offsetof node that refers to a field.
15541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    OffsetOfNode(SourceLocation DotLoc, FieldDecl *Field,
1555b4609806e9232593ece09ce08b630836e825865cDouglas Gregor                 SourceLocation NameLoc)
15561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc),
1557b4609806e9232593ece09ce08b630836e825865cDouglas Gregor        Data(reinterpret_cast<uintptr_t>(Field) | OffsetOfNode::Field) { }
1558b4609806e9232593ece09ce08b630836e825865cDouglas Gregor
15595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    /// \brief Create an offsetof node that refers to an identifier.
156077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek    OffsetOfNode(SourceLocation DotLoc, IdentifierInfo *Name,
15615549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek                 SourceLocation NameLoc)
15625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc),
15635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer        Data(reinterpret_cast<uintptr_t>(Name) | Identifier) { }
15641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1565b4609806e9232593ece09ce08b630836e825865cDouglas Gregor    /// \brief Create an offsetof node that refers into a C++ base class.
1566b4609806e9232593ece09ce08b630836e825865cDouglas Gregor    explicit OffsetOfNode(const CXXBaseSpecifier *Base)
1567668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek      : Range(), Data(reinterpret_cast<uintptr_t>(Base) | OffsetOfNode::Base) {}
1568668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek
156942602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor    /// \brief Determine what kind of offsetof node this is.
15705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Kind getKind() const {
15711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      return static_cast<Kind>(Data & Mask);
15725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    }
15731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15741f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor    /// \brief For an array element node, returns the index into the array
1575ba0a9006dbc4814e1e35f82812cb5a1dad65e8b8Argyrios Kyrtzidis    /// of expressions.
15761f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor    unsigned getArrayExprIndex() const {
15775549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek      assert(getKind() == Array);
15785549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek      return Data >> 2;
157918b2515e1bf8c86a4900792692e42fe1296be28dChris Lattner    }
1580a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu
1581d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes    /// \brief For a field offsetof node, returns the field.
1582d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes    FieldDecl *getField() const {
1583d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes      assert(getKind() == Field);
1584d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes      return reinterpret_cast<FieldDecl *>(Data & ~(uintptr_t)Mask);
1585d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes    }
1586a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu
1587a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu    /// \brief For a field or identifier offsetof node, returns the name of
1588bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner    /// the field.
1589bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner    IdentifierInfo *getFieldName() const;
1590bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner
1591a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu    /// \brief For a base class node, returns the base specifier.
15925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    CXXBaseSpecifier *getBase() const {
15935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      assert(getKind() == Base);
15945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return reinterpret_cast<CXXBaseSpecifier *>(Data & ~(uintptr_t)Mask);
15951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    }
15965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
15975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    /// \brief Retrieve the source range that covers this offsetof node.
15985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ///
15995549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    /// For an array element node, the source range contains the locations of
16005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    /// the square brackets. For a field or identifier node, the source range
16015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    /// contains the location of the period (if there is one) and the
16025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    /// identifier.
16035549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    SourceRange getSourceRange() const { return Range; }
16045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
16051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1606934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroffprivate:
1607934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff
1608934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff  SourceLocation OperatorLoc, RParenLoc;
1609934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff  // Base type;
1610934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff  TypeSourceInfo *TSInfo;
16111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // Number of sub-components (i.e. instances of OffsetOfNode).
1612d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  unsigned NumComps;
1613d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  // Number of sub-expressions (i.e. array subscript expressions).
1614d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  unsigned NumExprs;
16158189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek
16161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  OffsetOfExpr(ASTContext &C, QualType type,
16175549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek               SourceLocation OperatorLoc, TypeSourceInfo *tsi,
16185549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek               OffsetOfNode* compsPtr, unsigned numComps,
16191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump               Expr** exprsPtr, unsigned numExprs,
1620d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner               SourceLocation RParenLoc);
1621d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner
16225549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  explicit OffsetOfExpr(unsigned numComps, unsigned numExprs)
16235549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    : Expr(OffsetOfExprClass, EmptyShell()),
16241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      TSInfo(0), NumComps(numComps), NumExprs(numExprs) {}
16255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
16265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
16275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
16285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static OffsetOfExpr *Create(ASTContext &C, QualType type,
1629cb888967400a03504c88acedd5248d6778a82f46Chris Lattner                              SourceLocation OperatorLoc, TypeSourceInfo *tsi,
1630cb888967400a03504c88acedd5248d6778a82f46Chris Lattner                              OffsetOfNode* compsPtr, unsigned numComps,
16313c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregor                              Expr** exprsPtr, unsigned numExprs,
16321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                              SourceLocation RParenLoc);
16331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static OffsetOfExpr *CreateEmpty(ASTContext &C,
16356dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson                                   unsigned NumComps, unsigned NumExprs);
16366dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson
16371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// getOperatorLoc - Return the location of the operator.
1638d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  SourceLocation getOperatorLoc() const { return OperatorLoc; }
16391f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
1640866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek
16411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Return the location of the right parentheses.
164277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  SourceLocation getRParenLoc() const { return RParenLoc; }
16435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void setRParenLoc(SourceLocation R) { RParenLoc = R; }
16441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  TypeSourceInfo *getTypeSourceInfo() const {
16464bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt    return TSInfo;
16474bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt  }
16485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void setTypeSourceInfo(TypeSourceInfo *tsi) {
16495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    TSInfo = tsi;
165088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  }
165177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
165277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  const OffsetOfNode &getComponent(unsigned Idx) const {
165377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek    assert(Idx < NumComps && "Subscript out of range");
16545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return reinterpret_cast<const OffsetOfNode *> (this + 1)[Idx];
16555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1656ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner
16575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void setComponent(unsigned Idx, OffsetOfNode ON) {
16585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(Idx < NumComps && "Subscript out of range");
16596bb8017bb9e828d118e15e59d71c66bba323c364John McCall    reinterpret_cast<OffsetOfNode *> (this + 1)[Idx] = ON;
16606bb8017bb9e828d118e15e59d71c66bba323c364John McCall  }
1661161755a09898c95d21bfff33707da9ca41cd53c5John McCall
16626bb8017bb9e828d118e15e59d71c66bba323c364John McCall  unsigned getNumComponents() const {
16636bb8017bb9e828d118e15e59d71c66bba323c364John McCall    return NumComps;
1664ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  }
1665ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner
16665549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr* getIndexExpr(unsigned Idx) {
16671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    assert(Idx < NumExprs && "Subscript out of range");
1668ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner    return reinterpret_cast<Expr **>(
1669ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner                    reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx];
1670f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman  }
16711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Expr *getIndexExpr(unsigned Idx) const {
1672ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner    return const_cast<OffsetOfExpr*>(this)->getIndexExpr(Idx);
16735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
16741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16752577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  void setIndexExpr(unsigned Idx, Expr* E) {
16762577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    assert(Idx < NumComps && "Subscript out of range");
16772577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    reinterpret_cast<Expr **>(
16782577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx] = E;
1679ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  }
168083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor
16811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  unsigned getNumExpressions() const {
168283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    return NumExprs;
16836bb8017bb9e828d118e15e59d71c66bba323c364John McCall  }
16846bb8017bb9e828d118e15e59d71c66bba323c364John McCall
1685c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  SourceRange getSourceRange() const {
16866bb8017bb9e828d118e15e59d71c66bba323c364John McCall    return SourceRange(OperatorLoc, RParenLoc);
16871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
1688c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor
1689c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  static bool classof(const Stmt *T) {
1690c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    return T->getStmtClass() == OffsetOfExprClass;
1691c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
16926bb8017bb9e828d118e15e59d71c66bba323c364John McCall
1693c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  static bool classof(const OffsetOfExpr *) { return true; }
16941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
169583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  // Iterators
16966bb8017bb9e828d118e15e59d71c66bba323c364John McCall  child_range children() {
16976bb8017bb9e828d118e15e59d71c66bba323c364John McCall    Stmt **begin =
16986bb8017bb9e828d118e15e59d71c66bba323c364John McCall      reinterpret_cast<Stmt**>(reinterpret_cast<OffsetOfNode*>(this + 1)
169983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor                               + NumComps);
170083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    return child_range(begin, begin + NumExprs);
170183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  }
17026bb8017bb9e828d118e15e59d71c66bba323c364John McCall};
1703c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor
1704c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor/// UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated)
17051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// expression operand.  Used for sizeof/alignof (C99 6.5.3.4) and
17065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// vec_step (OpenCL 1.1 6.11.12).
1707f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedmanclass UnaryExprOrTypeTraitExpr : public Expr {
17082577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  unsigned Kind : 2;
17092577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  bool isType : 1;    // true if operand is a type, false if an expression
17102577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  union {
17112577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    TypeSourceInfo *Ty;
17122577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    Stmt *Ex;
17132577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  } Argument;
17142577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  SourceLocation OpLoc, RParenLoc;
17152577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
17162577743c5650c646fb705df01403707e94f2df04Abramo Bagnarapublic:
17172577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, TypeSourceInfo *TInfo,
17182577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                           QualType resultType, SourceLocation op,
17192577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                           SourceLocation rp) :
17202577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_RValue, OK_Ordinary,
17212577743c5650c646fb705df01403707e94f2df04Abramo Bagnara           false, // Never type-dependent (C++ [temp.dep.expr]p3).
1722f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman           // Value-dependent if the argument is type-dependent.
17231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           TInfo->getType()->isDependentType(),
1724ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson           TInfo->getType()->isInstantiationDependentType(),
17252577743c5650c646fb705df01403707e94f2df04Abramo Bagnara           TInfo->getType()->containsUnexpandedParameterPack()),
17262577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      Kind(ExprKind), isType(true), OpLoc(op), RParenLoc(rp) {
17276bb8017bb9e828d118e15e59d71c66bba323c364John McCall    Argument.Ty = TInfo;
1728510190777c4bd53e960eea4665b204778fec1b64Eli Friedman  }
17291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
173083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, Expr *E,
1731161755a09898c95d21bfff33707da9ca41cd53c5John McCall                           QualType resultType, SourceLocation op,
17322577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                           SourceLocation rp) :
1733d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall      Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_RValue, OK_Ordinary,
1734c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor           false, // Never type-dependent (C++ [temp.dep.expr]p3).
17351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           // Value-dependent if the argument is type-dependent.
173688a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor           E->isTypeDependent(),
17375549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek           E->isInstantiationDependent(),
173857e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor           E->containsUnexpandedParameterPack()),
173957e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor      Kind(ExprKind), isType(false), OpLoc(op), RParenLoc(rp) {
174057e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor    Argument.Ex = E;
174157e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor  }
174257e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor
1743f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman  /// \brief Construct an empty sizeof/alignof expression.
1744f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman  explicit UnaryExprOrTypeTraitExpr(EmptyShell Empty)
17451f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor    : Expr(UnaryExprOrTypeTraitExprClass, Empty) { }
17466bb8017bb9e828d118e15e59d71c66bba323c364John McCall
1747161755a09898c95d21bfff33707da9ca41cd53c5John McCall  UnaryExprOrTypeTrait getKind() const {
17486bb8017bb9e828d118e15e59d71c66bba323c364John McCall    return static_cast<UnaryExprOrTypeTrait>(Kind);
1749161755a09898c95d21bfff33707da9ca41cd53c5John McCall  }
1750161755a09898c95d21bfff33707da9ca41cd53c5John McCall  void setKind(UnaryExprOrTypeTrait K) { Kind = K; }
17516bb8017bb9e828d118e15e59d71c66bba323c364John McCall
17526bb8017bb9e828d118e15e59d71c66bba323c364John McCall  bool isArgumentType() const { return isType; }
17536bb8017bb9e828d118e15e59d71c66bba323c364John McCall  QualType getArgumentType() const {
17541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return getArgumentTypeInfo()->getType();
17550979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor  }
17560979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor  TypeSourceInfo *getArgumentTypeInfo() const {
17576bb8017bb9e828d118e15e59d71c66bba323c364John McCall    assert(isArgumentType() && "calling getArgumentType() when arg is expr");
17581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return Argument.Ty;
175983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  }
176083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  Expr *getArgumentExpr() {
176183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    assert(!isArgumentType() && "calling getArgumentExpr() when arg is type");
17621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return static_cast<Expr*>(Argument.Ex);
17636bb8017bb9e828d118e15e59d71c66bba323c364John McCall  }
176483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  const Expr *getArgumentExpr() const {
17651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return const_cast<UnaryExprOrTypeTraitExpr*>(this)->getArgumentExpr();
176683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  }
176783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor
17681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setArgument(Expr *E) { Argument.Ex = E; isType = false; }
17691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setArgument(TypeSourceInfo *TInfo) {
177083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    Argument.Ty = TInfo;
177183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    isType = true;
17721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
17736bb8017bb9e828d118e15e59d71c66bba323c364John McCall
177483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// Gets the argument type, or the type of the argument expression, whichever
17751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// is appropriate.
177683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  QualType getTypeOfArgument() const {
177783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    return isArgumentType() ? getArgumentType() : getArgumentExpr()->getType();
1778c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
1779c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor
1780c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  SourceLocation getOperatorLoc() const { return OpLoc; }
1781096832c5ed5b9106fa177ebc148489760c3bc496John McCall  void setOperatorLoc(SourceLocation L) { OpLoc = L; }
17821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1783c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
17841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1785d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
1786d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  SourceRange getSourceRange() const {
1787d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    return SourceRange(OpLoc, RParenLoc);
1788096832c5ed5b9106fa177ebc148489760c3bc496John McCall  }
1789096832c5ed5b9106fa177ebc148489760c3bc496John McCall
1790096832c5ed5b9106fa177ebc148489760c3bc496John McCall  static bool classof(const Stmt *T) {
1791096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return T->getStmtClass() == UnaryExprOrTypeTraitExprClass;
1792096832c5ed5b9106fa177ebc148489760c3bc496John McCall  }
1793096832c5ed5b9106fa177ebc148489760c3bc496John McCall  static bool classof(const UnaryExprOrTypeTraitExpr *) { return true; }
1794096832c5ed5b9106fa177ebc148489760c3bc496John McCall
1795096832c5ed5b9106fa177ebc148489760c3bc496John McCall  // Iterators
1796096832c5ed5b9106fa177ebc148489760c3bc496John McCall  child_range children();
1797096832c5ed5b9106fa177ebc148489760c3bc496John McCall};
1798096832c5ed5b9106fa177ebc148489760c3bc496John McCall
1799096832c5ed5b9106fa177ebc148489760c3bc496John McCall//===----------------------------------------------------------------------===//
1800096832c5ed5b9106fa177ebc148489760c3bc496John McCall// Postfix Operators.
1801096832c5ed5b9106fa177ebc148489760c3bc496John McCall//===----------------------------------------------------------------------===//
1802096832c5ed5b9106fa177ebc148489760c3bc496John McCall
1803096832c5ed5b9106fa177ebc148489760c3bc496John McCall/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
1804096832c5ed5b9106fa177ebc148489760c3bc496John McCallclass ArraySubscriptExpr : public Expr {
1805096832c5ed5b9106fa177ebc148489760c3bc496John McCall  enum { LHS, RHS, END_EXPR=2 };
1806096832c5ed5b9106fa177ebc148489760c3bc496John McCall  Stmt* SubExprs[END_EXPR];
1807096832c5ed5b9106fa177ebc148489760c3bc496John McCall  SourceLocation RBracketLoc;
1808096832c5ed5b9106fa177ebc148489760c3bc496John McCallpublic:
1809096832c5ed5b9106fa177ebc148489760c3bc496John McCall  ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t,
1810096832c5ed5b9106fa177ebc148489760c3bc496John McCall                     ExprValueKind VK, ExprObjectKind OK,
1811096832c5ed5b9106fa177ebc148489760c3bc496John McCall                     SourceLocation rbracketloc)
1812096832c5ed5b9106fa177ebc148489760c3bc496John McCall  : Expr(ArraySubscriptExprClass, t, VK, OK,
1813096832c5ed5b9106fa177ebc148489760c3bc496John McCall         lhs->isTypeDependent() || rhs->isTypeDependent(),
1814096832c5ed5b9106fa177ebc148489760c3bc496John McCall         lhs->isValueDependent() || rhs->isValueDependent(),
1815096832c5ed5b9106fa177ebc148489760c3bc496John McCall         (lhs->isInstantiationDependent() ||
1816096832c5ed5b9106fa177ebc148489760c3bc496John McCall          rhs->isInstantiationDependent()),
1817d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall         (lhs->containsUnexpandedParameterPack() ||
1818c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt          rhs->containsUnexpandedParameterPack())),
18191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    RBracketLoc(rbracketloc) {
1820c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    SubExprs[LHS] = lhs;
18211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    SubExprs[RHS] = rhs;
1822c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
1823c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor
18241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Create an empty array subscript expression.
1825096832c5ed5b9106fa177ebc148489760c3bc496John McCall  explicit ArraySubscriptExpr(EmptyShell Shell)
1826c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    : Expr(ArraySubscriptExprClass, Shell) { }
18271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1828c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// An array access can be written A[4] or 4[A] (both are equivalent).
1829c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// - getBase() and getIdx() always present the normalized view: A[4].
1830833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  ///    In this case getBase() returns "A" and getIdx() returns "4".
1831c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// - getLHS() and getRHS() present the syntactic view. e.g. for
18321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///    4[A] getLHS() returns "4".
18331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// Note: Because vector element access is also written A[4] we must
1834096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// predicate the format conversion in getBase and getIdx only on the
1835c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  /// the type of the RHS, as it is possible for the LHS to be a vector of
18361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// integer type
1837c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); }
1838c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
18391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setLHS(Expr *E) { SubExprs[LHS] = E; }
1840c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor
18411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); }
18421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
1843096832c5ed5b9106fa177ebc148489760c3bc496John McCall  void setRHS(Expr *E) { SubExprs[RHS] = E; }
1844c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor
18451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getBase() {
18461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS());
1847c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
18481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1849c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  const Expr *getBase() const {
1850c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS());
18511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
1852096832c5ed5b9106fa177ebc148489760c3bc496John McCall
1853c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  Expr *getIdx() {
18541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS());
18552577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  }
18562577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
18572577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  const Expr *getIdx() const {
18582577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS());
18592577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  }
18602577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
18615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceRange getSourceRange() const {
18621f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor    return SourceRange(getLHS()->getLocStart(), RBracketLoc);
18631f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  }
1864ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner
1865ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  SourceLocation getRBracketLoc() const { return RBracketLoc; }
1866026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  void setRBracketLoc(SourceLocation L) { RBracketLoc = L; }
18671f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor
18685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation getExprLoc() const { return getBase()->getExprLoc(); }
18695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
187072527137c521ad9330ecb81ccd841159719dc8cdEli Friedman  static bool classof(const Stmt *T) {
187172527137c521ad9330ecb81ccd841159719dc8cdEli Friedman    return T->getStmtClass() == ArraySubscriptExprClass;
18722577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  }
18732577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  static bool classof(const ArraySubscriptExpr *) { return true; }
18741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
187572527137c521ad9330ecb81ccd841159719dc8cdEli Friedman  // Iterators
187672527137c521ad9330ecb81ccd841159719dc8cdEli Friedman  child_range children() {
1877c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
1878c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
18795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
18801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
18815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
18825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
18831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CallExpr itself represents a normal function call, e.g., "f(x, 2)",
188483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor/// while its subclasses may represent alternative syntax that (semantically)
18855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// results in a function call. For example, CXXOperatorCallExpr is
18865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// a subclass for overloaded operator calls that use operator syntax, e.g.,
18871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// "str1 + str2" to resolve to a function call.
18881237c673c07f9d827129ba02720108816abde562Ted Kremenekclass CallExpr : public Expr {
18891237c673c07f9d827129ba02720108816abde562Ted Kremenek  enum { FN=0, PREARGS_START=1 };
18901237c673c07f9d827129ba02720108816abde562Ted Kremenek  Stmt **SubExprs;
18915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned NumArgs;
18925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation RParenLoc;
18931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1894aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffprotected:
1895aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff  // These versions of the constructor are for derived classes.
18960fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  CallExpr(ASTContext& C, StmtClass SC, Expr *fn, unsigned NumPreArgs,
18970fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner           Expr **args, unsigned numargs, QualType t, ExprValueKind VK,
18980fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner           SourceLocation rparenloc);
18990fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  CallExpr(ASTContext &C, StmtClass SC, unsigned NumPreArgs, EmptyShell Empty);
19001d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall
19011d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall  Stmt *getPreArg(unsigned i) {
19021d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall    assert(i < getNumPreArgs() && "Prearg access out of range!");
190342f56b50062cd3b3c6b23fdb9053578ae9145664John McCall    return SubExprs[PREARGS_START+i];
19045549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  }
1905e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff  const Stmt *getPreArg(unsigned i) const {
1906aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff    assert(i < getNumPreArgs() && "Prearg access out of range!");
19072333f7727f97018d6742e1e0938133bcfad967abEli Friedman    return SubExprs[PREARGS_START+i];
190842f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  }
19091d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall  void setPreArg(unsigned i, Stmt *PreArg) {
19101d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall    assert(i < getNumPreArgs() && "Prearg access out of range!");
191142f56b50062cd3b3c6b23fdb9053578ae9145664John McCall    SubExprs[PREARGS_START+i] = PreArg;
191242f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  }
19131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1914ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  unsigned getNumPreArgs() const { return CallExprBits.NumPreArgs; }
1915ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor
1916ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregorpublic:
1917ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, QualType t,
19185549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek           ExprValueKind VK, SourceLocation rparenloc);
19195549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek
1920ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  /// \brief Build an empty call expression.
1921e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff  CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty);
1922e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff
1923ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); }
1924ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  Expr *getCallee() { return cast<Expr>(SubExprs[FN]); }
19250fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  void setCallee(Expr *F) { SubExprs[FN] = F; }
1926ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor
1927ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  Decl *getCalleeDecl();
192842f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  const Decl *getCalleeDecl() const {
192942f56b50062cd3b3c6b23fdb9053578ae9145664John McCall    return const_cast<CallExpr*>(this)->getCalleeDecl();
193042f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  }
193173d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner
19320fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  /// \brief If the callee is a FunctionDecl, return it. Otherwise return 0.
19330fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  FunctionDecl *getDirectCallee();
19340fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  const FunctionDecl *getDirectCallee() const {
19350fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner    return const_cast<CallExpr*>(this)->getDirectCallee();
193673d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner  }
19370fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner
193873d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner  /// getNumArgs - Return the number of actual arguments to this call.
1939aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff  ///
19401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  unsigned getNumArgs() const { return NumArgs; }
19411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1942aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff  /// \brief Retrieve the call arguments.
1943aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff  Expr **getArgs() {
19441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return reinterpret_cast<Expr **>(SubExprs+getNumPreArgs()+PREARGS_START);
19451237c673c07f9d827129ba02720108816abde562Ted Kremenek  }
19461237c673c07f9d827129ba02720108816abde562Ted Kremenek
19471237c673c07f9d827129ba02720108816abde562Ted Kremenek  /// getArg - Return the specified argument.
1948aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff  Expr *getArg(unsigned Arg) {
1949aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff    assert(Arg < NumArgs && "Arg access out of range!");
195049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    return cast<Expr>(SubExprs[Arg+getNumPreArgs()+PREARGS_START]);
195149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
195249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  const Expr *getArg(unsigned Arg) const {
195349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    assert(Arg < NumArgs && "Arg access out of range!");
19540835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis    return cast<Expr>(SubExprs[Arg+getNumPreArgs()+PREARGS_START]);
1955cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson  }
19565baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall
19571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// setArg - Set the specified argument.
1958cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson  void setArg(unsigned Arg, Expr *ArgExpr) {
1959f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    assert(Arg < NumArgs && "Arg access out of range!");
1960f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    SubExprs[Arg+getNumPreArgs()+PREARGS_START] = ArgExpr;
19610835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  }
1962409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson
19637ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson  /// setNumArgs - This changes the number of arguments present in this call.
1964409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  /// Any orphaned expressions are deleted by this, and any new operands are set
1965409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  /// to null.
19665cf86ba6b5a724bf91cb52feade1158f1fbeb605Anders Carlsson  void setNumArgs(ASTContext& C, unsigned NumArgs);
1967cee22421929c91b481f4d1bb85cd48c0f6b7510bAnders Carlsson
1968cee22421929c91b481f4d1bb85cd48c0f6b7510bAnders Carlsson  typedef ExprIterator arg_iterator;
1969409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  typedef ConstExprIterator const_arg_iterator;
1970409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson
1971f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  arg_iterator arg_begin() { return SubExprs+PREARGS_START+getNumPreArgs(); }
1972f9d68e1dd015972318b2448f75115ff4fc3d5008Anders Carlsson  arg_iterator arg_end() {
1973409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    return SubExprs+PREARGS_START+getNumPreArgs()+getNumArgs();
1974409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  }
1975409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  const_arg_iterator arg_begin() const {
1976409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    return SubExprs+PREARGS_START+getNumPreArgs();
1977e39a3894513349908cdb3beba2614e53cb288e6cDouglas Gregor  }
1978409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  const_arg_iterator arg_end() const {
1979409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    return SubExprs+PREARGS_START+getNumPreArgs()+getNumArgs();
1980409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  }
1981409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson
1982409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  /// getNumCommas - Return the number of commas that must have been present in
1983409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  /// this function call.
1984409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; }
1985409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson
1986409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  /// isBuiltinCall - If this is a call to a builtin, return the builtin ID.  If
1987409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  /// not, return 0.
1988409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  unsigned isBuiltinCall(const ASTContext &Context) const;
1989409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson
1990409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  /// getCallReturnType - Get the return type of the call expr. This is not
1991409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  /// always the type of the expr itself, if the return type is a reference
1992409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  /// type.
1993409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  QualType getCallReturnType() const;
1994409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson
1995409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  SourceLocation getRParenLoc() const { return RParenLoc; }
1996409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1997569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor
1998f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  SourceRange getSourceRange() const;
1999409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson
2000409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  static bool classof(const Stmt *T) {
2001409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    return T->getStmtClass() >= firstCallExprConstant &&
2002409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson           T->getStmtClass() <= lastCallExprConstant;
2003409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  }
2004f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static bool classof(const CallExpr *) { return true; }
2005f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
2006f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  // Iterators
2007f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  child_range children() {
2008f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    return child_range(&SubExprs[0],
20090835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis                       &SubExprs[0]+NumArgs+getNumPreArgs()+PREARGS_START);
2010409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  }
2011f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall};
2012898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
2013898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// MemberExpr - [C99 6.5.2.3] Structure and Union Members.  X->F and X.F.
2014898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor///
2015898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorclass MemberExpr : public Expr {
2016898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// Extra data stored in some member expressions.
2017898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  struct MemberNameQualifier {
20181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    /// \brief The nested-name-specifier that qualifies the name, including
2019f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    /// source-location information.
2020f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    NestedNameSpecifierLoc QualifierLoc;
2021f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
20221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    /// \brief The DeclAccessPair through which the MemberDecl was found due to
2023087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor    /// name qualifiers.
2024f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    DeclAccessPair FoundDecl;
2025f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  };
20261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20270835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  /// Base - the expression for the base pointer or structure references.  In
2028f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  /// X.F, this is "X".
2029cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson  Stmt *Base;
2030f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson
2031f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson  /// MemberDecl - This is the decl being referenced by the field/member name.
20320835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  /// In X.F, this is the decl referenced by F.
20330835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  ValueDecl *MemberDecl;
2034087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor
2035087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor  /// MemberLoc - This is the location of the member name.
20366eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  SourceLocation MemberLoc;
20376eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor
20386eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// MemberDNLoc - Provides source/type location info for the
20396eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// declaration name embedded in MemberDecl.
20406eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  DeclarationNameLoc MemberDNLoc;
20416eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor
20426eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// IsArrow - True if this is "X->F", false if this is "X.F".
204341b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson  bool IsArrow : 1;
2044f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
2045f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  /// \brief True if this member expression used a nested-name-specifier to
2046f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  /// refer to the member, e.g., "x->Base::f", or found its member via a using
2047f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  /// declaration.  When true, a MemberNameQualifier
2048f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  /// structure is allocated immediately after the MemberExpr.
2049f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  bool HasQualifierOrFoundDecl : 1;
2050f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
2051f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  /// \brief True if this member expression specified a template argument list
2052f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  /// explicitly, e.g., x->f<int>. When true, an ExplicitTemplateArgumentList
2053f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  /// structure (and its TemplateArguments) are allocated immediately after
205441b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson  /// the MemberExpr or, if the member expression also has a qualifier, after
20551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// the MemberNameQualifier structure.
20564bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt  bool HasExplicitTemplateArgumentList : 1;
20574bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt
20580835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  /// \brief Retrieve the qualifier that preceded the member name, if any.
20590835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  MemberNameQualifier *getMemberQualifier() {
20601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    assert(HasQualifierOrFoundDecl);
20610835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis    return reinterpret_cast<MemberNameQualifier *> (this + 1);
20620835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  }
20630835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis
20640835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  /// \brief Retrieve the qualifier that preceded the member name, if any.
20650835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  const MemberNameQualifier *getMemberQualifier() const {
206649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    return const_cast<MemberExpr *>(this)->getMemberQualifier();
206749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
206849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
206949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorpublic:
207049b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff  MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl,
2071bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor             const DeclarationNameInfo &NameInfo, QualType ty,
2072bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor             ExprValueKind VK, ExprObjectKind OK)
2073906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl    : Expr(MemberExprClass, ty, VK, OK,
2074bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor           base->isTypeDependent(),
2075bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor           base->isValueDependent(),
2076bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor           base->isInstantiationDependent(),
2077bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor           base->containsUnexpandedParameterPack()),
2078906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl      Base(base), MemberDecl(memberdecl), MemberLoc(NameInfo.getLoc()),
20791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      MemberDNLoc(NameInfo.getInfo()), IsArrow(isarrow),
2080906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl      HasQualifierOrFoundDecl(false), HasExplicitTemplateArgumentList(false) {
2081906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl    assert(memberdecl->getDeclName() == NameInfo.getName());
2082906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl  }
2083906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl
2084bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor  // NOTE: this constructor should be used only when it is known that
2085bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor  // the member name can not provide additional syntactic info
20860835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  // (i.e., source locations for C++ operator names or type source info
2087906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl  // for constructors, destructors and conversion oeprators).
2088f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl,
20895baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall             SourceLocation l, QualType ty,
20905baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall             ExprValueKind VK, ExprObjectKind OK)
20915baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall    : Expr(MemberExprClass, ty, VK, OK,
20925baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall           base->isTypeDependent(), base->isValueDependent(),
209390045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff           base->isInstantiationDependent(),
2094087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor           base->containsUnexpandedParameterPack()),
2095f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall      Base(base), MemberDecl(memberdecl), MemberLoc(l), MemberDNLoc(),
2096f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall      IsArrow(isarrow),
2097f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall      HasQualifierOrFoundDecl(false), HasExplicitTemplateArgumentList(false) {}
2098f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
2099f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  static MemberExpr *Create(ASTContext &C, Expr *base, bool isarrow,
2100f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                            NestedNameSpecifierLoc QualifierLoc,
21015baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall                            ValueDecl *memberdecl, DeclAccessPair founddecl,
21025baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall                            DeclarationNameInfo MemberNameInfo,
21035baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall                            const TemplateArgumentListInfo *targs,
21045baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall                            QualType ty, ExprValueKind VK, ExprObjectKind OK);
2105f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
2106f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  void setBase(Expr *E) { Base = E; }
2107f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  Expr *getBase() const { return cast<Expr>(Base); }
2108f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
21095baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall  /// \brief Retrieve the member declaration to which this expression refers.
2110f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  ///
2111f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  /// The returned declaration will either be a FieldDecl or (in C++)
2112087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor  /// a CXXMethodDecl.
21130835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  ValueDecl *getMemberDecl() const { return MemberDecl; }
21140835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  void setMemberDecl(ValueDecl *D) { MemberDecl = D; }
21150835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis
211690045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff  /// \brief Retrieves the declaration found by lookup.
21175baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall  DeclAccessPair getFoundDecl() const {
21185baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall    if (!HasQualifierOrFoundDecl)
21195baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall      return DeclAccessPair::make(getMemberDecl(),
21205baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall                                  getMemberDecl()->getAccess());
2121eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor    return getMemberQualifier()->FoundDecl;
21225baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall  }
21235baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall
2124eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor  /// \brief Determines whether this member expression actually had
21251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// a C++ nested-name-specifier prior to the name of the member, e.g.,
21261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// x->Base::foo.
212749b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff  bool hasQualifier() const { return getQualifier() != 0; }
212849b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff
212949b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff  /// \brief If the member name was qualified, retrieves the
213049b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff  /// nested-name-specifier that precedes the member name. Otherwise, returns
213149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// NULL.
21321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  NestedNameSpecifier *getQualifier() const {
213349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    if (!HasQualifierOrFoundDecl)
213449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor      return 0;
213549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
213649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    return getMemberQualifier()->QualifierLoc.getNestedNameSpecifier();
213749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
213849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
21395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// \brief If the member name was qualified, retrieves the
214049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// nested-name-specifier that precedes the member name, with source-location
214149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// information.
214249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  NestedNameSpecifierLoc getQualifierLoc() const {
214349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    if (!hasQualifier())
214449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor      return NestedNameSpecifierLoc();
2145906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl
2146906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl    return getMemberQualifier()->QualifierLoc;
21470835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  }
21489d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall
21499d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  /// \brief Determines whether this member expression actually had a C++
21509d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  /// template argument list explicitly specified, e.g., x.f<int>.
215149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  bool hasExplicitTemplateArgs() const {
215249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    return HasExplicitTemplateArgumentList;
2153c0a2fd8f092722c8f78b566ac4506a21437040e9Anders Carlsson  }
2154f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
2155f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  /// \brief Copies the template arguments (if present) into the given
215649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// structure.
2157db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2158f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    if (hasExplicitTemplateArgs())
2159f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall      getExplicitTemplateArgs().copyInto(List);
2160db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  }
216149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
21629d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  /// \brief Retrieve the explicit template argument list that
21639d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  /// follow the member template name.  This must only be called on an
21649d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  /// expression with explicit template arguments.
21659d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
21669d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall    assert(HasExplicitTemplateArgumentList);
216749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    if (!HasQualifierOrFoundDecl)
216849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor      return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
21699d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall
217049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    return *reinterpret_cast<ExplicitTemplateArgumentList *>(
21711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                                      getMemberQualifier() + 1);
21724bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt  }
21734bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt
217449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// \brief Retrieve the explicit template argument list that
217549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// followed the member template name.  This must only be called on
217649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// an expression with explicit template arguments.
217749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
21786eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor    return const_cast<MemberExpr *>(this)->getExplicitTemplateArgs();
217949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
218049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
21816eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor  /// \brief Retrieves the optional explicit template arguments.
2182b2f9e516327310d95840d442416084508f80c183Steve Naroff  /// This points to the same data as getExplicitTemplateArgs(), but
2183b2f9e516327310d95840d442416084508f80c183Steve Naroff  /// returns null if there are no explicit template arguments.
2184f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() const {
21859d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall    if (!hasExplicitTemplateArgs()) return 0;
2186f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    return &getExplicitTemplateArgs();
218741b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson  }
2188f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
218941b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson  /// \brief Retrieve the location of the left angle bracket following the
219049b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff  /// member name ('<'), if any.
2191db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  SourceLocation getLAngleLoc() const {
2192f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    if (!HasExplicitTemplateArgumentList)
2193f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall      return SourceLocation();
2194f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
2195f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    return getExplicitTemplateArgs().LAngleLoc;
2196f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  }
2197f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
2198f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  /// \brief Retrieve the template arguments provided as part of this
2199f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  /// template-id.
2200f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  const TemplateArgumentLoc *getTemplateArgs() const {
2201f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    if (!HasExplicitTemplateArgumentList)
2202db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor      return 0;
2203b2f9e516327310d95840d442416084508f80c183Steve Naroff
2204db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor    return getExplicitTemplateArgs().getTemplateArgs();
2205db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  }
2206b2f9e516327310d95840d442416084508f80c183Steve Naroff
2207db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  /// \brief Retrieve the number of template arguments provided as part of this
2208db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  /// template-id.
22095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getNumTemplateArgs() const {
2210b2f9e516327310d95840d442416084508f80c183Steve Naroff    if (!HasExplicitTemplateArgumentList)
22115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return 0;
22121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return getExplicitTemplateArgs().NumTemplateArgs;
22145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
22156eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor
22165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// \brief Retrieve the location of the right angle bracket following the
22175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// template arguments ('>').
22183fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor  SourceLocation getRAngleLoc() const {
22193fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor    if (!HasExplicitTemplateArgumentList)
22203fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor      return SourceLocation();
22213fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor
22223fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor    return getExplicitTemplateArgs().RAngleLoc;
22233fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor  }
22243fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor
22253fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor  /// \brief Retrieve the member declaration name info.
22263fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor  DeclarationNameInfo getMemberNameInfo() const {
22273fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor    return DeclarationNameInfo(MemberDecl->getDeclName(),
22283fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor                               MemberLoc, MemberDNLoc);
22293fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor  }
22303fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor
22313fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor  bool isArrow() const { return IsArrow; }
22323fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor  void setArrow(bool A) { IsArrow = A; }
22333fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor
22343fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor  /// getMemberLoc - Return the location of the "member", in X->F, it is the
22353fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor  /// location of 'F'.
22365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation getMemberLoc() const { return MemberLoc; }
22375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void setMemberLoc(SourceLocation L) { MemberLoc = L; }
22385baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall
22395baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall  SourceRange getSourceRange() const;
224017d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner
22410799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  SourceLocation getExprLoc() const { return MemberLoc; }
22420799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall
22430799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  /// \brief Determine whether the base of this explicit is implicit.
224417d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  bool isImplicitAccess() const {
22455549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return getBase() && getBase()->isImplicitCXXThis();
22461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
22471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
224817d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  static bool classof(const Stmt *T) {
224917d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner    return T->getStmtClass() == MemberExprClass;
2250898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
2251898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  static bool classof(const MemberExpr *) { return true; }
22521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2253898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  // Iterators
22541237c673c07f9d827129ba02720108816abde562Ted Kremenek  child_range children() { return child_range(&Base, &Base+1); }
22551237c673c07f9d827129ba02720108816abde562Ted Kremenek
22561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  friend class ASTReader;
22575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTStmtWriter;
22585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
22595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2260db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor/// CompoundLiteralExpr - [C99 6.5.2.5]
22611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
22622de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCallclass CompoundLiteralExpr : public Expr {
2263db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  /// LParenLoc - If non-null, this is the location of the left paren in a
226417d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  /// compound literal like "(int){4}".  This can be null if this is a
2265db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  /// synthesized compound expression.
2266db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  SourceLocation LParenLoc;
22670799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall
2268db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  /// The type as written.  This can be an incomplete array type, in
2269db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  /// which case the actual expression type will be different.
22705549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  TypeSourceInfo *TInfo;
2271db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  Stmt *Init;
22725549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  bool FileScope;
2273db600c330a37b1c3ab4533310729910ee188f900Douglas Gregorpublic:
2274db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  CompoundLiteralExpr(SourceLocation lparenloc, TypeSourceInfo *tinfo,
22755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                      QualType T, ExprValueKind VK, Expr *init, bool fileScope)
22765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    : Expr(CompoundLiteralExprClass, T, VK, OK_Ordinary,
22775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           tinfo->getType()->isDependentType(),
22781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           init->isValueDependent(),
22795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           (init->isInstantiationDependent() ||
22805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer            tinfo->getType()->isInstantiationDependentType()),
22815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           init->containsUnexpandedParameterPack()),
22825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      LParenLoc(lparenloc), TInfo(tinfo), Init(init), FileScope(fileScope) {}
22830799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall
2284a84c02d0f4d63975a1c52b9bb8308d88e9d79352Ted Kremenek  /// \brief Construct an empty compound literal.
2285063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  explicit CompoundLiteralExpr(EmptyShell Empty)
2286063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    : Expr(CompoundLiteralExprClass, Empty) { }
2287063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor
2288063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  const Expr *getInitializer() const { return cast<Expr>(Init); }
2289063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  Expr *getInitializer() { return cast<Expr>(Init); }
2290063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  void setInitializer(Expr *E) { Init = E; }
2291063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor
2292063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  bool isFileScope() const { return FileScope; }
22935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void setFileScope(bool FS) { FileScope = FS; }
22942de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall
22952de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  SourceLocation getLParenLoc() const { return LParenLoc; }
22960799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
22972de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall
22980799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  TypeSourceInfo *getTypeSourceInfo() const { return TInfo; }
2299aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl  void setTypeSourceInfo(TypeSourceInfo* tinfo) { TInfo = tinfo; }
23002de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall
23010799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  SourceRange getSourceRange() const {
2302f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek    // FIXME: Init should never be null.
23032de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    if (!Init)
23040799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall      return SourceRange();
2305f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek    if (LParenLoc.isInvalid())
23062de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall      return Init->getSourceRange();
23070799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall    return SourceRange(LParenLoc, Init->getLocEnd());
23081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
23092de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall
23100799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  static bool classof(const Stmt *T) {
2311aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl    return T->getStmtClass() == CompoundLiteralExprClass;
23122de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  }
23130799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  static bool classof(const CompoundLiteralExpr *) { return true; }
2314f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek
23152de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  // Iterators
23162de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  child_range children() { return child_range(&Init, &Init+1); }
23172de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall};
23182de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall
23192de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall/// CastExpr - Base class for type casts, including both implicit
23202de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall/// casts (ImplicitCastExpr) and explicit casts that have some
23212de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall/// representation in the source code (ExplicitCastExpr's derived
23221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// classes).
23231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass CastExpr : public Expr {
23244bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Huntpublic:
23254bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt  typedef clang::CastKind CastKind;
23265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
23275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
23281237c673c07f9d827129ba02720108816abde562Ted Kremenek  Stmt *Op;
23291237c673c07f9d827129ba02720108816abde562Ted Kremenek
23301237c673c07f9d827129ba02720108816abde562Ted Kremenek  void CheckCastConsistency() const {
23311237c673c07f9d827129ba02720108816abde562Ted Kremenek#ifndef NDEBUG
23321237c673c07f9d827129ba02720108816abde562Ted Kremenek    switch (getCastKind()) {
23335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case CK_DerivedToBase:
233417d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner    case CK_UncheckedDerivedToBase:
23352333f7727f97018d6742e1e0938133bcfad967abEli Friedman    case CK_DerivedToBaseMemberPointer:
23362333f7727f97018d6742e1e0938133bcfad967abEli Friedman    case CK_BaseToDerived:
23372333f7727f97018d6742e1e0938133bcfad967abEli Friedman    case CK_BaseToDerivedMemberPointer:
23382333f7727f97018d6742e1e0938133bcfad967abEli Friedman      assert(!path_empty() && "Cast kind should have a base path!");
23392333f7727f97018d6742e1e0938133bcfad967abEli Friedman      break;
23401237c673c07f9d827129ba02720108816abde562Ted Kremenek
23411237c673c07f9d827129ba02720108816abde562Ted Kremenek    // These should not have an inheritance path.
23425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case CK_BitCast:
2343ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor    case CK_Dynamic:
23441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    case CK_ToUnion:
23452de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    case CK_ArrayToPointerDecay:
23465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case CK_FunctionToPointerDecay:
23475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case CK_NullToMemberPointer:
23485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case CK_NullToPointer:
23495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case CK_ConstructorConversion:
23505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case CK_IntegralToPointer:
23515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case CK_PointerToIntegral:
23525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case CK_ToVoid:
23535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case CK_VectorSplat:
23545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case CK_IntegralCast:
2355ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman    case CK_IntegralToFloating:
2356ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman    case CK_FloatingToIntegral:
23575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case CK_FloatingCast:
23585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case CK_AnyPointerToObjCPointerCast:
2359ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman    case CK_AnyPointerToBlockPointerCast:
2360ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman    case CK_ObjCObjectLValueCast:
236117d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner    case CK_FloatingRealToComplex:
236217d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner    case CK_FloatingComplexToReal:
2363ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman    case CK_FloatingComplexCast:
2364ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman    case CK_FloatingComplexToIntegralComplex:
23651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    case CK_IntegralRealToComplex:
23665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case CK_IntegralComplexToReal:
23675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case CK_IntegralComplexCast:
23685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case CK_IntegralComplexToFloatingComplex:
2369ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor    case CK_ObjCProduceObject:
2370ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor    case CK_ObjCConsumeObject:
2371ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor    case CK_ObjCReclaimReturnedObject:
2372ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor      assert(!getType()->isBooleanType() && "unheralded conversion to bool");
2373ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman      // fallthrough to check for null base path
2374ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman
2375ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman    case CK_Dependent:
2376ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman    case CK_LValueToRValue:
2377ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor    case CK_GetObjCProperty:
2378ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor    case CK_NoOp:
2379ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman    case CK_PointerToBoolean:
2380ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor    case CK_IntegralToBoolean:
2381ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor    case CK_FloatingToBoolean:
23825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case CK_MemberPointerToBoolean:
23831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    case CK_FloatingComplexToBoolean:
23841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    case CK_IntegralComplexToBoolean:
23855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case CK_LValueBitCast:            // -> bool&
23865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case CK_UserDefinedConversion:    // operator bool()
23875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      assert(path_empty() && "Cast kind should not have a base path!");
23885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      break;
23895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    }
23905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
23915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
23921237c673c07f9d827129ba02720108816abde562Ted Kremenek
23935549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const CXXBaseSpecifier * const *path_buffer() const {
239447e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor    return const_cast<CastExpr*>(this)->path_buffer();
23955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
239647e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor  CXXBaseSpecifier **path_buffer();
239747e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor
2398898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  void setBasePathSize(unsigned basePathSize) {
2399898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    CastExprBits.BasePathSize = basePathSize;
2400898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    assert(CastExprBits.BasePathSize == basePathSize &&
2401898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           "basePathSize doesn't fit in bits of CastExprBits.BasePathSize!");
2402898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
24031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2404898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorprotected:
240547e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor  CastExpr(StmtClass SC, QualType ty, ExprValueKind VK,
240647e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor           const CastKind kind, Expr *op, unsigned BasePathSize) :
240747e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor    Expr(SC, ty, VK, OK_Ordinary,
24081237c673c07f9d827129ba02720108816abde562Ted Kremenek         // Cast expressions are type-dependent if the type is
24091237c673c07f9d827129ba02720108816abde562Ted Kremenek         // dependent (C++ [temp.dep.expr]p3).
24101237c673c07f9d827129ba02720108816abde562Ted Kremenek         ty->isDependentType(),
24111237c673c07f9d827129ba02720108816abde562Ted Kremenek         // Cast expressions are value-dependent if the type is
24125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer         // dependent or if the subexpression is value-dependent.
2413ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor         ty->isDependentType() || (op && op->isValueDependent()),
2414ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor         (ty->isInstantiationDependentType() ||
2415ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor          (op && op->isInstantiationDependent())),
2416ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor         (ty->containsUnexpandedParameterPack() ||
2417395a2abf0028968d85958610e393e067885dc14fTed Kremenek          op->containsUnexpandedParameterPack())),
2418395a2abf0028968d85958610e393e067885dc14fTed Kremenek    Op(op) {
24195549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    assert(kind != CK_Invalid && "creating cast with invalid cast kind");
2420ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor    CastExprBits.Kind = kind;
2421395a2abf0028968d85958610e393e067885dc14fTed Kremenek    setBasePathSize(BasePathSize);
2422395a2abf0028968d85958610e393e067885dc14fTed Kremenek    CheckCastConsistency();
2423395a2abf0028968d85958610e393e067885dc14fTed Kremenek  }
2424395a2abf0028968d85958610e393e067885dc14fTed Kremenek
2425395a2abf0028968d85958610e393e067885dc14fTed Kremenek  /// \brief Construct an empty cast.
2426395a2abf0028968d85958610e393e067885dc14fTed Kremenek  CastExpr(StmtClass SC, EmptyShell Empty, unsigned BasePathSize)
24271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : Expr(SC, Empty) {
2428395a2abf0028968d85958610e393e067885dc14fTed Kremenek    setBasePathSize(BasePathSize);
24295549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  }
2430395a2abf0028968d85958610e393e067885dc14fTed Kremenek
24311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
2432395a2abf0028968d85958610e393e067885dc14fTed Kremenek  CastKind getCastKind() const { return (CastKind) CastExprBits.Kind; }
2433395a2abf0028968d85958610e393e067885dc14fTed Kremenek  void setCastKind(CastKind K) { CastExprBits.Kind = K; }
24345549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const char *getCastKindName() const;
24351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24365549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Expr *getSubExpr() { return cast<Expr>(Op); }
2437ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  const Expr *getSubExpr() const { return cast<Expr>(Op); }
2438ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  void setSubExpr(Expr *E) { Op = E; }
24395549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek
2440ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  /// \brief Retrieve the cast subexpression as it was written in the source
24415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// code, looking through any implicit casts or other intermediate nodes
244247e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor  /// introduced by semantic analysis.
244347e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor  Expr *getSubExprAsWritten();
244447e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor  const Expr *getSubExprAsWritten() const {
244547e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor    return const_cast<CastExpr *>(this)->getSubExprAsWritten();
244647e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor  }
244747e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor
24485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  typedef CXXBaseSpecifier **path_iterator;
24495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  typedef const CXXBaseSpecifier * const *path_const_iterator;
24505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool path_empty() const { return CastExprBits.BasePathSize == 0; }
24511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  unsigned path_size() const { return CastExprBits.BasePathSize; }
24521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  path_iterator path_begin() { return path_buffer(); }
24535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  path_iterator path_end() { return path_buffer() + path_size(); }
24545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  path_const_iterator path_begin() const { return path_buffer(); }
24551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  path_const_iterator path_end() const { return path_buffer() + path_size(); }
24561237c673c07f9d827129ba02720108816abde562Ted Kremenek
24571237c673c07f9d827129ba02720108816abde562Ted Kremenek  void setCastPath(const CXXCastPath &Path);
24581237c673c07f9d827129ba02720108816abde562Ted Kremenek
24595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
24605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getStmtClass() >= firstCastExprConstant &&
24616481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner           T->getStmtClass() <= lastCastExprConstant;
24626481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner  }
24635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const CastExpr *) { return true; }
24645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
24655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Iterators
24666481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner  child_range children() { return child_range(&Op, &Op+1); }
24676481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner};
24682333f7727f97018d6742e1e0938133bcfad967abEli Friedman
24692333f7727f97018d6742e1e0938133bcfad967abEli Friedman/// ImplicitCastExpr - Allows us to explicitly represent implicit type
24701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// conversions, which have no direct representation in the original
24717d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor/// source code. For example: converting T[]->T*, void f()->void
24721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// (*f)(), float->double, short->int, etc.
24737d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor///
24747d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor/// In C, implicit casts always produce rvalues. However, in C++, an
24757d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor/// implicit cast whose result is being bound to a reference will be
24767d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor/// an lvalue or xvalue. For example:
24777d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor///
24787d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor/// @code
24797d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor/// class Base { };
24805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// class Derived : public Base { };
24815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Derived &&ref();
24825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// void f(Derived d) {
24831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///   Base& b = d; // initializer is an ImplicitCastExpr
24845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///                // to an lvalue of type Base
24857d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor///   Base&& r = ref(); // initializer is an ImplicitCastExpr
24867d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor///                     // to an xvalue of type Base
24875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// }
24881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// @endcode
24895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ImplicitCastExpr : public CastExpr {
24906481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattnerprivate:
24911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ImplicitCastExpr(QualType ty, CastKind kind, Expr *op,
24921237c673c07f9d827129ba02720108816abde562Ted Kremenek                   unsigned BasePathLength, ExprValueKind VK)
24931237c673c07f9d827129ba02720108816abde562Ted Kremenek    : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, BasePathLength) {
24941237c673c07f9d827129ba02720108816abde562Ted Kremenek  }
24955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2496ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  /// \brief Construct an empty implicit cast.
2497ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  explicit ImplicitCastExpr(EmptyShell Shell, unsigned PathSize)
2498ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner    : CastExpr(ImplicitCastExprClass, Shell, PathSize) { }
2499ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner
2500ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerpublic:
25015549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  enum OnStack_t { OnStack };
2502ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  ImplicitCastExpr(OnStack_t _, QualType ty, CastKind kind, Expr *op,
2503ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner                   ExprValueKind VK)
25042333f7727f97018d6742e1e0938133bcfad967abEli Friedman    : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, 0) {
2505d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  }
2506d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff
25072333f7727f97018d6742e1e0938133bcfad967abEli Friedman  static ImplicitCastExpr *Create(ASTContext &Context, QualType T,
25082333f7727f97018d6742e1e0938133bcfad967abEli Friedman                                  CastKind Kind, Expr *Operand,
25091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                  const CXXCastPath *BasePath,
25106a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor                                  ExprValueKind Cat);
25116a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor
25126a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  static ImplicitCastExpr *CreateEmpty(ASTContext &Context, unsigned PathSize);
25135549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek
25145549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  SourceRange getSourceRange() const {
25156a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor    return getSubExpr()->getSourceRange();
25166a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  }
2517ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner
2518ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  static bool classof(const Stmt *T) {
2519ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner    return T->getStmtClass() == ImplicitCastExprClass;
25201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
2521026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  static bool classof(const ImplicitCastExpr *) { return true; }
25226a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor};
2523026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner
25246a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregorinline Expr *Expr::IgnoreImpCasts() {
25251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *e = this;
2526ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  while (ImplicitCastExpr *ice = dyn_cast<ImplicitCastExpr>(e))
25271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    e = ice->getSubExpr();
2528ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  return e;
2529ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner}
25301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
25311237c673c07f9d827129ba02720108816abde562Ted Kremenek/// ExplicitCastExpr - An explicit cast written in the source
25321237c673c07f9d827129ba02720108816abde562Ted Kremenek/// code.
25331237c673c07f9d827129ba02720108816abde562Ted Kremenek///
2534ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// This class is effectively an abstract class, because it provides
2535ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// the basic representation of an explicitly-written cast without
2536dc241b42c7588f99027b035a09b71557a6db219eDouglas Gregor/// specifying which kind of cast (C cast, functional cast, static
2537d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// cast, etc.) was written; specific derived classes represent the
2538d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// particular style of cast and its location information.
2539d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff///
2540d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// Unlike implicit casts, explicit cast nodes have two different
25413fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara/// types: the type that was written into the source code, and the
25423fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara/// actual type of the expression as determined by semantic
2543363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff/// analysis. These types may differ slightly. For example, in C++ one
2544d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// can cast to a reference type, which indicates that the resulting
25451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// expression will be an lvalue or xvalue. The reference type, however,
25463fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara/// will not be used as the type of the expression.
25473fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnaraclass ExplicitCastExpr : public CastExpr {
25482333f7727f97018d6742e1e0938133bcfad967abEli Friedman  /// TInfo - Source type info for the (written) type
25493fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara  /// this expression is casting to.
2550d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  TypeSourceInfo *TInfo;
255144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor
255244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregorprotected:
255344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  ExplicitCastExpr(StmtClass SC, QualType exprTy, ExprValueKind VK,
255444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor                   CastKind kind, Expr *op, unsigned PathSize,
25553fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara                   TypeSourceInfo *writtenTy)
25563fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara    : CastExpr(SC, exprTy, VK, kind, op, PathSize), TInfo(writtenTy) {}
25573fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara
25583fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara  /// \brief Construct an empty explicit cast.
25593fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara  ExplicitCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize)
25603fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara    : CastExpr(SC, Shell, PathSize) { }
25613fcb73dae91be42b071cf0dde9222b7ec362146dAbramo Bagnara
25621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
256344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  /// getTypeInfoAsWritten - Returns the type source info for the type
256444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  /// that this expression is casting to.
25651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  TypeSourceInfo *getTypeInfoAsWritten() const { return TInfo; }
256644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setTypeInfoAsWritten(TypeSourceInfo *writtenTy) { TInfo = writtenTy; }
256744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor
25681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// getTypeAsWritten - Returns the type that this expression is
2569d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  /// casting to, as written in the source code.
2570363bcff47df2fda3cfcfcd994b7888157df58c43Steve Naroff  QualType getTypeAsWritten() const { return TInfo->getType(); }
2571d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff
2572d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  static bool classof(const Stmt *T) {
25731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump     return T->getStmtClass() >= firstExplicitCastExprConstant &&
2574d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff            T->getStmtClass() <= lastExplicitCastExprConstant;
2575d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  }
25761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const ExplicitCastExpr *) { return true; }
25771237c673c07f9d827129ba02720108816abde562Ted Kremenek};
25781237c673c07f9d827129ba02720108816abde562Ted Kremenek
25791237c673c07f9d827129ba02720108816abde562Ted Kremenek/// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style
2580d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// cast in C++ (C++ [expr.cast]), which uses the syntax
2581d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff/// (Type)expr. For example: @c (int)f.
2582d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanclass CStyleCastExpr : public ExplicitCastExpr {
2583d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  SourceLocation LPLoc; // the location of the left paren
2584d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  SourceLocation RPLoc; // the location of the right paren
2585d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
2586d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  CStyleCastExpr(QualType exprTy, ExprValueKind vk, CastKind kind, Expr *op,
2587d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman                 unsigned PathSize, TypeSourceInfo *writtenTy,
2588d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman                 SourceLocation l, SourceLocation r)
2589d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    : ExplicitCastExpr(CStyleCastExprClass, exprTy, vk, kind, op, PathSize,
2590d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman                       writtenTy), LPLoc(l), RPLoc(r) {}
2591d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
2592d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  /// \brief Construct an empty C-style explicit cast.
2593d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  explicit CStyleCastExpr(EmptyShell Shell, unsigned PathSize)
2594d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    : ExplicitCastExpr(CStyleCastExprClass, Shell, PathSize) { }
25955549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek
2596d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanpublic:
2597d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  static CStyleCastExpr *Create(ASTContext &Context, QualType T,
2598d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman                                ExprValueKind VK, CastKind K,
25992333f7727f97018d6742e1e0938133bcfad967abEli Friedman                                Expr *Op, const CXXCastPath *BasePath,
26002333f7727f97018d6742e1e0938133bcfad967abEli Friedman                                TypeSourceInfo *WrittenTy, SourceLocation L,
2601a88dc3079bedf70a5cfc39791727e43a10383006Nate Begeman                                SourceLocation R);
26021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static CStyleCastExpr *CreateEmpty(ASTContext &Context, unsigned PathSize);
26042333f7727f97018d6742e1e0938133bcfad967abEli Friedman
26052333f7727f97018d6742e1e0938133bcfad967abEli Friedman  SourceLocation getLParenLoc() const { return LPLoc; }
26061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setLParenLoc(SourceLocation L) { LPLoc = L; }
2607a88dc3079bedf70a5cfc39791727e43a10383006Nate Begeman
2608d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  SourceLocation getRParenLoc() const { return RPLoc; }
2609d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  void setRParenLoc(SourceLocation L) { RPLoc = L; }
2610d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
261194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  SourceRange getSourceRange() const {
261294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor    return SourceRange(LPLoc, getSubExpr()->getSourceRange().getEnd());
26131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
261494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  static bool classof(const Stmt *T) {
261594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor    return T->getStmtClass() == CStyleCastExprClass;
261694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  }
261794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  static bool classof(const CStyleCastExpr *) { return true; }
26181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump};
261994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
262094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor/// \brief A builtin binary operation expression such as "x + y" or "x <= y".
262194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor///
2622d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// This expression node kind describes a builtin binary operation,
2623d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// such as "x + y" for integer values "x" and "y". The operands will
2624d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// already have been converted to appropriate types (e.g., by
2625d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// performing promotions or conversions).
26261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
2627d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// In C++, where operators may be overloaded, a different kind of
2628d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// expression node (CXXOperatorCallExpr) is used to express the
26291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// invocation of an overloaded operator with operator syntax. Within
2630d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is
2631d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// used to store an expression "x + y" depends on the subexpressions
2632d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// for x and y. If neither x or y is type-dependent, and the "+"
2633d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// operator resolves to a built-in operation, BinaryOperator will be
26341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// used to express the computation (x and y may still be
2635d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// value-dependent). If either x or y is type-dependent, or if the
2636d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// "+" resolves to an overloaded operator, CXXOperatorCallExpr will
2637d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// be used to express the computation.
26385549976193e34417d4474a5f4a514268ef6666c7Ted Kremenekclass BinaryOperator : public Expr {
2639d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanpublic:
2640d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  typedef BinaryOperatorKind Opcode;
2641d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
26425549976193e34417d4474a5f4a514268ef6666c7Ted Kremenekprivate:
2643d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  unsigned Opc : 6;
26441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation OpLoc;
2645888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman
264694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  enum { LHS, RHS, END_EXPR };
2647dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman  Stmt* SubExprs[END_EXPR];
2648dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedmanpublic:
26499a901bb63990574ff0bcc12ff851d7a71cff8ddbEli Friedman
2650d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
26511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                 ExprValueKind VK, ExprObjectKind OK,
2652d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman                 SourceLocation opLoc)
2653d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    : Expr(BinaryOperatorClass, ResTy, VK, OK,
2654d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman           lhs->isTypeDependent() || rhs->isTypeDependent(),
2655d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman           lhs->isValueDependent() || rhs->isValueDependent(),
2656d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman           (lhs->isInstantiationDependent() ||
2657d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff            rhs->isInstantiationDependent()),
26581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           (lhs->containsUnexpandedParameterPack() ||
2659d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff            rhs->containsUnexpandedParameterPack())),
26607976932a1c256d447316ffac58e9821417725e34Eli Friedman      Opc(opc), OpLoc(opLoc) {
26617976932a1c256d447316ffac58e9821417725e34Eli Friedman    SubExprs[LHS] = lhs;
26627976932a1c256d447316ffac58e9821417725e34Eli Friedman    SubExprs[RHS] = rhs;
26637976932a1c256d447316ffac58e9821417725e34Eli Friedman    assert(!isCompoundAssignmentOp() &&
26647976932a1c256d447316ffac58e9821417725e34Eli Friedman           "Use ArithAssignBinaryOperator for compound assignments");
26657976932a1c256d447316ffac58e9821417725e34Eli Friedman  }
2666d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff
26671237c673c07f9d827129ba02720108816abde562Ted Kremenek  /// \brief Construct an empty binary operator.
26685549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  explicit BinaryOperator(EmptyShell Empty)
2669d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff    : Expr(BinaryOperatorClass, Empty), Opc(BO_Comma) { }
2670d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff
2671d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  SourceLocation getOperatorLoc() const { return OpLoc; }
2672ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  void setOperatorLoc(SourceLocation L) { OpLoc = L; }
2673ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor
26741237c673c07f9d827129ba02720108816abde562Ted Kremenek  Opcode getOpcode() const { return static_cast<Opcode>(Opc); }
26751237c673c07f9d827129ba02720108816abde562Ted Kremenek  void setOpcode(Opcode O) { Opc = O; }
26761237c673c07f9d827129ba02720108816abde562Ted Kremenek
26771237c673c07f9d827129ba02720108816abde562Ted Kremenek  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
26781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setLHS(Expr *E) { SubExprs[LHS] = E; }
26797976932a1c256d447316ffac58e9821417725e34Eli Friedman  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
268044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  void setRHS(Expr *E) { SubExprs[RHS] = E; }
268144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor
268244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  SourceRange getSourceRange() const {
26837976932a1c256d447316ffac58e9821417725e34Eli Friedman    return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd());
26847976932a1c256d447316ffac58e9821417725e34Eli Friedman  }
268527437caadea35f84d550cd29f024fcf3ea240eecChris Lattner
26867976932a1c256d447316ffac58e9821417725e34Eli Friedman  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
26877976932a1c256d447316ffac58e9821417725e34Eli Friedman  /// corresponds to, e.g. "<<=".
26887976932a1c256d447316ffac58e9821417725e34Eli Friedman  static const char *getOpcodeStr(Opcode Op);
26897976932a1c256d447316ffac58e9821417725e34Eli Friedman
26907976932a1c256d447316ffac58e9821417725e34Eli Friedman  const char *getOpcodeStr() const { return getOpcodeStr(getOpcode()); }
26917976932a1c256d447316ffac58e9821417725e34Eli Friedman
26927976932a1c256d447316ffac58e9821417725e34Eli Friedman  /// \brief Retrieve the binary opcode that corresponds to the given
26935549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  /// overloaded operator.
269444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  static Opcode getOverloadedOpcode(OverloadedOperatorKind OO);
26955549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek
269644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  /// \brief Retrieve the overloaded operator kind that corresponds to
26975549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  /// the given binary opcode.
269844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
269944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor
270044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  /// predicates to categorize the respective opcodes.
270144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  bool isPtrMemOp() const { return Opc == BO_PtrMemD || Opc == BO_PtrMemI; }
27021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool isMultiplicativeOp() const { return Opc >= BO_Mul && Opc <= BO_Rem; }
270344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  static bool isAdditiveOp(Opcode Opc) { return Opc == BO_Add || Opc==BO_Sub; }
270444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  bool isAdditiveOp() const { return isAdditiveOp(getOpcode()); }
27051237c673c07f9d827129ba02720108816abde562Ted Kremenek  static bool isShiftOp(Opcode Opc) { return Opc == BO_Shl || Opc == BO_Shr; }
2706d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  bool isShiftOp() const { return isShiftOp(getOpcode()); }
2707d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff
2708d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  static bool isBitwiseOp(Opcode Opc) { return Opc >= BO_And && Opc <= BO_Or; }
2709d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  bool isBitwiseOp() const { return isBitwiseOp(getOpcode()); }
27101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2711d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  static bool isRelationalOp(Opcode Opc) { return Opc >= BO_LT && Opc<=BO_GE; }
2712d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  bool isRelationalOp() const { return isRelationalOp(getOpcode()); }
27131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
27141237c673c07f9d827129ba02720108816abde562Ted Kremenek  static bool isEqualityOp(Opcode Opc) { return Opc == BO_EQ || Opc == BO_NE; }
27151237c673c07f9d827129ba02720108816abde562Ted Kremenek  bool isEqualityOp() const { return isEqualityOp(getOpcode()); }
27161237c673c07f9d827129ba02720108816abde562Ted Kremenek
2717d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  static bool isComparisonOp(Opcode Opc) { return Opc >= BO_LT && Opc<=BO_NE; }
2718d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  bool isComparisonOp() const { return isComparisonOp(getOpcode()); }
27192d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
27202d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  static bool isLogicalOp(Opcode Opc) { return Opc == BO_LAnd || Opc==BO_LOr; }
27212d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  bool isLogicalOp() const { return isLogicalOp(getOpcode()); }
27222d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
27232d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  static bool isAssignmentOp(Opcode Opc) {
27242d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor    return Opc >= BO_Assign && Opc <= BO_OrAssign;
27252d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  }
27262d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  bool isAssignmentOp() const { return isAssignmentOp(getOpcode()); }
27272d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
27282d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  static bool isCompoundAssignmentOp(Opcode Opc) {
27292d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor    return Opc > BO_Assign && Opc <= BO_OrAssign;
27301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
27312333f7727f97018d6742e1e0938133bcfad967abEli Friedman  bool isCompoundAssignmentOp() const {
27322d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor    return isCompoundAssignmentOp(getOpcode());
273344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  }
273444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor
273544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  static bool isShiftAssignOp(Opcode Opc) {
27362d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor    return Opc == BO_ShlAssign || Opc == BO_ShrAssign;
27372d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  }
273844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  bool isShiftAssignOp() const {
27392d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor    return isShiftAssignOp(getOpcode());
27402d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  }
27412d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
27422d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  static bool classof(const Stmt *S) {
27432d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor    return S->getStmtClass() >= firstBinaryOperatorConstant &&
27441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           S->getStmtClass() <= lastBinaryOperatorConstant;
27452d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  }
27462d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  static bool classof(const BinaryOperator *) { return true; }
27471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
27482d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  // Iterators
27492d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  child_range children() {
27502d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
27512d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  }
27522d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
275374626d6ef2e194fcc911e071556660ff331eb4a8Zhongxing Xuprotected:
27547c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
27555549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek                 ExprValueKind VK, ExprObjectKind OK,
27562cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara                 SourceLocation opLoc, bool dead)
27577c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson    : Expr(CompoundAssignOperatorClass, ResTy, VK, OK,
27587c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson           lhs->isTypeDependent() || rhs->isTypeDependent(),
27592cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara           lhs->isValueDependent() || rhs->isValueDependent(),
27602cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara           (lhs->isInstantiationDependent() ||
27612333f7727f97018d6742e1e0938133bcfad967abEli Friedman            rhs->isInstantiationDependent()),
27622cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara           (lhs->containsUnexpandedParameterPack() ||
27637c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson            rhs->containsUnexpandedParameterPack())),
27647c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson      Opc(opc), OpLoc(opLoc) {
27651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    SubExprs[LHS] = lhs;
276674626d6ef2e194fcc911e071556660ff331eb4a8Zhongxing Xu    SubExprs[RHS] = rhs;
2767d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  }
2768d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
27695549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  BinaryOperator(StmtClass SC, EmptyShell Empty)
27705549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    : Expr(SC, Empty), Opc(BO_MulAssign) { }
2771d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor};
2772d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
27732cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep
27742cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara/// track of the type the operation is performed in.  Due to the semantics of
27752cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara/// these operators, the operands are promoted, the arithmetic performed, an
2776d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor/// implicit conversion back to the result type done, then the assignment takes
2777d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor/// place.  This captures the intermediate type which the computation is done
27781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// in.
2779d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregorclass CompoundAssignOperator : public BinaryOperator {
2780d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  QualType ComputationLHSType;
2781d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  QualType ComputationResultType;
27827c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonpublic:
27837c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResType,
27841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                         ExprValueKind VK, ExprObjectKind OK,
27857c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson                         QualType CompLHSType, QualType CompResultType,
27867c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson                         SourceLocation OpLoc)
27877c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson    : BinaryOperator(lhs, rhs, opc, ResType, VK, OK, OpLoc, true),
27887c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson      ComputationLHSType(CompLHSType),
27891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      ComputationResultType(CompResultType) {
27907c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson    assert(isCompoundAssignmentOp() &&
27917c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson           "Only should be used for compound assignments");
27921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
27937c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson
27941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Build an empty compound assignment operator expression.
27954c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  explicit CompoundAssignOperator(EmptyShell Empty)
27964c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    : BinaryOperator(CompoundAssignOperatorClass, Empty) { }
27974c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
27984c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  // The two computation types are the type the LHS is converted
27994c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  // to for the computation and the type of the result; the two are
28004c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  // distinct in a few cases (specifically, int+=ptr and ptr-=ptr).
28014c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  QualType getComputationLHSType() const { return ComputationLHSType; }
28024c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  void setComputationLHSType(QualType T) { ComputationLHSType = T; }
28034c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
2804196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner  QualType getComputationResultType() const { return ComputationResultType; }
28054c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  void setComputationResultType(QualType T) { ComputationResultType = T; }
28064c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
28074c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  static bool classof(const CompoundAssignOperator *) { return true; }
28084c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  static bool classof(const Stmt *S) {
28094c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    return S->getStmtClass() == CompoundAssignOperatorClass;
28104c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  }
28114c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor};
28124c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
2813196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// AbstractConditionalOperator - An abstract base class for
28144c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// ConditionalOperator and BinaryConditionalOperator.
28154c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregorclass AbstractConditionalOperator : public Expr {
28164c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  SourceLocation QuestionLoc, ColonLoc;
28174c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  friend class ASTStmtReader;
28184c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
28194c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregorprotected:
28204c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  AbstractConditionalOperator(StmtClass SC, QualType T,
28213498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor                              ExprValueKind VK, ExprObjectKind OK,
28224c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor                              bool TD, bool VD, bool ID,
28234c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor                              bool ContainsUnexpandedParameterPack,
28244c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor                              SourceLocation qloc,
2825196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner                              SourceLocation cloc)
28264c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    : Expr(SC, T, VK, OK, TD, VD, ID, ContainsUnexpandedParameterPack),
28274c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor      QuestionLoc(qloc), ColonLoc(cloc) {}
28284c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
28294c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  AbstractConditionalOperator(StmtClass SC, EmptyShell Empty)
28304c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    : Expr(SC, Empty) { }
28314c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
283266b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonpublic:
2833ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek  // getCond - Return the expression representing the condition for
2834709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  //   the ?: operator.
2835709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  Expr *getCond() const;
283666b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson
28371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // getTrueExpr - Return the subexpression representing the value of
28384c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  //   the expression if the condition evaluates to true.
28394c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  Expr *getTrueExpr() const;
28404c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
28414c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  // getFalseExpr - Return the subexpression representing the value of
28420bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  //   the expression if the condition evaluates to false.  This is
28430bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  //   the same as getRHS.
28440bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  Expr *getFalseExpr() const;
28450bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor
2846a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  SourceLocation getQuestionLoc() const { return QuestionLoc; }
2847a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  SourceLocation getColonLoc() const { return ColonLoc; }
2848a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor
2849a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  static bool classof(const Stmt *T) {
285066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson    return T->getStmtClass() == ConditionalOperatorClass ||
2851709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek           T->getStmtClass() == BinaryConditionalOperatorClass;
2852709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  }
2853ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek  static bool classof(const AbstractConditionalOperator *) { return true; }
2854d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor};
2855d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
2856709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek/// ConditionalOperator - The ?: ternary operator.  The GNU "missing
2857709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek/// middle" extension is a BinaryConditionalOperator.
28581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass ConditionalOperator : public AbstractConditionalOperator {
2859ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek  enum { COND, LHS, RHS, END_EXPR };
28601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
28611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2862c5ae899b4bbf65488445316c63168079177db0edSteve Naroff  friend class ASTStmtReader;
28634c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregorpublic:
286466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  ConditionalOperator(Expr *cond, SourceLocation QLoc, Expr *lhs,
28651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                      SourceLocation CLoc, Expr *rhs,
28661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                      QualType t, ExprValueKind VK, ExprObjectKind OK)
2867c5ae899b4bbf65488445316c63168079177db0edSteve Naroff    : AbstractConditionalOperator(ConditionalOperatorClass, t, VK, OK,
28684c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor           // FIXME: the type of the conditional operator doesn't
286966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson           // depend on the type of the conditional, but the standard
28701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           // seems to imply that it could. File a bug!
28711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           (lhs->isTypeDependent() || rhs->isTypeDependent()),
2872c5ae899b4bbf65488445316c63168079177db0edSteve Naroff           (cond->isValueDependent() || lhs->isValueDependent() ||
28739e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff            rhs->isValueDependent()),
28749e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff           (cond->isInstantiationDependent() ||
2875c5ae899b4bbf65488445316c63168079177db0edSteve Naroff            lhs->isInstantiationDependent() ||
2876fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor            rhs->isInstantiationDependent()),
2877709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek           (cond->containsUnexpandedParameterPack() ||
28781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump            lhs->containsUnexpandedParameterPack() ||
28794c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor            rhs->containsUnexpandedParameterPack()),
28804c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor                                  QLoc, CLoc) {
28814c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    SubExprs[COND] = cond;
28824c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    SubExprs[LHS] = lhs;
28834c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    SubExprs[RHS] = rhs;
28844c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  }
28854c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
28864c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// \brief Build an empty conditional operator.
28874c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  explicit ConditionalOperator(EmptyShell Empty)
28884c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    : AbstractConditionalOperator(ConditionalOperatorClass, Empty) { }
28894c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
28904c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  // getCond - Return the expression representing the condition for
28914c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  //   the ?: operator.
28924c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
28934c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
2894709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  // getTrueExpr - Return the subexpression representing the value of
2895c5ae899b4bbf65488445316c63168079177db0edSteve Naroff  //   the expression if the condition evaluates to true.
28960bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  Expr *getTrueExpr() const { return cast<Expr>(SubExprs[LHS]); }
28970bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor
28980bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  // getFalseExpr - Return the subexpression representing the value of
28990bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  //   the expression if the condition evaluates to false.  This is
29000bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  //   the same as getRHS.
29010bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); }
29020bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor
29030bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
29040bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
2905c5ae899b4bbf65488445316c63168079177db0edSteve Naroff
2906c5ae899b4bbf65488445316c63168079177db0edSteve Naroff  SourceRange getSourceRange() const {
2907b3eef68111ffc220e449be96da1747998c057790Douglas Gregor    return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd());
2908b3eef68111ffc220e449be96da1747998c057790Douglas Gregor  }
2909b3eef68111ffc220e449be96da1747998c057790Douglas Gregor  static bool classof(const Stmt *T) {
29101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == ConditionalOperatorClass;
2911d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  }
2912d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  static bool classof(const ConditionalOperator *) { return true; }
2913d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
291487fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor  // Iterators
291587fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor  child_range children() {
29164c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
29174c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  }
29184c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor};
29191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
29204c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// BinaryConditionalOperator - The GNU extension to the conditional
29214c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// operator which allows the middle operand to be omitted.
29224c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor///
2923a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor/// This is a different expression kind on the assumption that almost
29241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// every client ends up needing to know that these are different.
2925d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregorclass BinaryConditionalOperator : public AbstractConditionalOperator {
2926a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  enum { COMMON, COND, LHS, RHS, NUM_SUBEXPRS };
2927a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor
292866b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  /// - the common condition/left-hand-side expression, which will be
292966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  ///   evaluated as the opaque value
29301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// - the condition, expressed in terms of the opaque value
293166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  /// - the left-hand-side, expressed in terms of the opaque value
29321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// - the right-hand-side
293366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  Stmt *SubExprs[NUM_SUBEXPRS];
293466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  OpaqueValueExpr *OpaqueValue;
29351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
293666b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  friend class ASTStmtReader;
293766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonpublic:
293866b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  BinaryConditionalOperator(Expr *common, OpaqueValueExpr *opaqueValue,
29391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                            Expr *cond, Expr *lhs, Expr *rhs,
2940709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek                            SourceLocation qloc, SourceLocation cloc,
29418111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu                            QualType t, ExprValueKind VK, ExprObjectKind OK)
2942709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek    : AbstractConditionalOperator(BinaryConditionalOperatorClass, t, VK, OK,
29438111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu           (common->isTypeDependent() || rhs->isTypeDependent()),
29441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           (common->isValueDependent() || rhs->isValueDependent()),
2945ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek           (common->isInstantiationDependent() ||
29468111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu            rhs->isInstantiationDependent()),
2947ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek           (common->containsUnexpandedParameterPack() ||
29488111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu            rhs->containsUnexpandedParameterPack()),
2949ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek                                  qloc, cloc),
29508111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu      OpaqueValue(opaqueValue) {
2951ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek    SubExprs[COMMON] = common;
29528111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu    SubExprs[COND] = cond;
295366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson    SubExprs[LHS] = lhs;
295466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson    SubExprs[RHS] = rhs;
295505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
295605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    OpaqueValue->setSourceExpr(common);
295705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
295805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
295905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// \brief Build an empty conditional operator.
296005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  explicit BinaryConditionalOperator(EmptyShell Empty)
296105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    : AbstractConditionalOperator(BinaryConditionalOperatorClass, Empty) { }
29621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
296305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// \brief getCommon - Return the common expression, written to the
296405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  ///   left of the condition.  The opaque value will be bound to the
296505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  ///   result of this expression.
296605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Expr *getCommon() const { return cast<Expr>(SubExprs[COMMON]); }
296705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
296805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// \brief getOpaqueValue - Return the opaque value placeholder.
296905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  OpaqueValueExpr *getOpaqueValue() const { return OpaqueValue; }
297005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
297105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// \brief getCond - Return the condition expression; this is defined
297205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  ///   in terms of the opaque value.
297305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
297405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
297505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// \brief getTrueExpr - Return the subexpression which will be
2976ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  ///   evaluated if the condition evaluates to true;  this is defined
2977ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  ///   in terms of the opaque value.
2978ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  Expr *getTrueExpr() const {
2979ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor    return cast<Expr>(SubExprs[LHS]);
2980ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  }
298105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
298205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// \brief getFalseExpr - Return the subexpression which will be
298305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  ///   evaluated if the condnition evaluates to false; this is
298405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  ///   defined in terms of the opaque value.
2985eeae8f072748affce25ab4064982626361293390Douglas Gregor  Expr *getFalseExpr() const {
298605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    return cast<Expr>(SubExprs[RHS]);
2987eeae8f072748affce25ab4064982626361293390Douglas Gregor  }
298805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
298905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  SourceRange getSourceRange() const {
299005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    return SourceRange(getCommon()->getLocStart(), getFalseExpr()->getLocEnd());
299105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
2992ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  static bool classof(const Stmt *T) {
2993ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor    return T->getStmtClass() == BinaryConditionalOperatorClass;
2994ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  }
2995ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  static bool classof(const BinaryConditionalOperator *) { return true; }
299605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
299705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  // Iterators
299805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  child_range children() {
299905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    return child_range(SubExprs, SubExprs + NUM_SUBEXPRS);
300005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
3001ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor};
3002319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor
3003ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorinline Expr *AbstractConditionalOperator::getCond() const {
3004eeae8f072748affce25ab4064982626361293390Douglas Gregor  if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this))
30059ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor    return co->getCond();
30069ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor  return cast<BinaryConditionalOperator>(this)->getCond();
300705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}
3008d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
3009d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregorinline Expr *AbstractConditionalOperator::getTrueExpr() const {
3010d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this))
3011d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    return co->getTrueExpr();
301205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  return cast<BinaryConditionalOperator>(this)->getTrueExpr();
301305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}
301405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
301505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorinline Expr *AbstractConditionalOperator::getFalseExpr() const {
301605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this))
301705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    return co->getFalseExpr();
301805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  return cast<BinaryConditionalOperator>(this)->getFalseExpr();
301905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}
302005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
302105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// AddrLabelExpr - The GNU address of label extension, representing &&label.
30221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass AddrLabelExpr : public Expr {
302305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  SourceLocation AmpAmpLoc, LabelLoc;
302405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  LabelDecl *Label;
30251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
302605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelDecl *L,
302705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                QualType t)
302805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    : Expr(AddrLabelExprClass, t, VK_RValue, OK_Ordinary, false, false, false,
302905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor           false),
303005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {}
303105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
303205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// \brief Build an empty address of a label expression.
303305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  explicit AddrLabelExpr(EmptyShell Empty)
303405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    : Expr(AddrLabelExprClass, Empty) { }
303505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
303605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; }
303705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; }
303805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  SourceLocation getLabelLoc() const { return LabelLoc; }
303905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  void setLabelLoc(SourceLocation L) { LabelLoc = L; }
304005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
30411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceRange getSourceRange() const {
304205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    return SourceRange(AmpAmpLoc, LabelLoc);
304305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
304405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
304505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  LabelDecl *getLabel() const { return Label; }
304605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  void setLabel(LabelDecl *L) { Label = L; }
304705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
304805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  static bool classof(const Stmt *T) {
304905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    return T->getStmtClass() == AddrLabelExprClass;
305005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
305105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  static bool classof(const AddrLabelExpr *) { return true; }
305205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
305305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  // Iterators
305405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  child_range children() { return child_range(); }
305505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor};
305605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
305705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
305805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// The StmtExpr contains a single CompoundStmt node, which it evaluates and
305905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// takes the value of the last subexpression.
306005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor///
306105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// A StmtExpr is always an r-value; values "returned" out of a
306205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// StmtExpr will be copied.
306305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorclass StmtExpr : public Expr {
306405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Stmt *SubStmt;
306505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  SourceLocation LParenLoc, RParenLoc;
306605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorpublic:
3067ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  // FIXME: Does type-dependence need to be computed differently?
3068ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  // FIXME: Do we need to compute instantiation instantiation-dependence for
306905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  // statements? (ugh!)
30701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  StmtExpr(CompoundStmt *substmt, QualType T,
30711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           SourceLocation lp, SourceLocation rp) :
307205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    Expr(StmtExprClass, T, VK_RValue, OK_Ordinary,
307305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor         T->isDependentType(), false, false, false),
307405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) { }
307505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
307605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// \brief Build an empty statement expression.
307705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { }
307805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
30791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); }
308005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); }
308105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  void setSubStmt(CompoundStmt *S) { SubStmt = S; }
308205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
308305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  SourceRange getSourceRange() const {
308405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    return SourceRange(LParenLoc, RParenLoc);
308505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
308605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
308705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  SourceLocation getLParenLoc() const { return LParenLoc; }
308805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
30891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation getRParenLoc() const { return RParenLoc; }
309005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
309105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
309205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  static bool classof(const Stmt *T) {
309305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    return T->getStmtClass() == StmtExprClass;
309405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
309505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  static bool classof(const StmtExpr *) { return true; }
309605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
309705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  // Iterators
309805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  child_range children() { return child_range(&SubStmt, &SubStmt+1); }
309905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor};
310005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
310105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
310205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// ShuffleVectorExpr - clang-specific builtin-in function
310305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// __builtin_shufflevector.
310405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// This AST node represents a operator that does a constant
310505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// shuffle, similar to LLVM's shufflevector instruction. It takes
310605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// two vectors and a variable number of constant indices,
310705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// and returns the appropriately shuffled vector.
310805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorclass ShuffleVectorExpr : public Expr {
310905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  SourceLocation BuiltinLoc, RParenLoc;
311005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
311105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  // SubExprs - the list of values passed to the __builtin_shufflevector
311205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  // function. The first two are vectors, and the rest are constant
311305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  // indices.  The number of values in this list is always
311405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  // 2+the number of indices in the vector type.
311505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Stmt **SubExprs;
311605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  unsigned NumExprs;
311787f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor
311887f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregorpublic:
311987f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor  ShuffleVectorExpr(ASTContext &C, Expr **args, unsigned nexpr,
312087f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor                    QualType Type, SourceLocation BLoc,
312187f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor                    SourceLocation RP);
312205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
312305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// \brief Build an empty vector-shuffle expression.
312405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  explicit ShuffleVectorExpr(EmptyShell Empty)
312505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    : Expr(ShuffleVectorExprClass, Empty), SubExprs(0) { }
312605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
312705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
312805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
312905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
313005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
313105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
313205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
313305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  SourceRange getSourceRange() const {
313405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    return SourceRange(BuiltinLoc, RParenLoc);
313505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
313605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  static bool classof(const Stmt *T) {
313705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    return T->getStmtClass() == ShuffleVectorExprClass;
313805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
313905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  static bool classof(const ShuffleVectorExpr *) { return true; }
314005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
314105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// getNumSubExprs - Return the size of the SubExprs array.  This includes the
314205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// constant expression, the actual arguments passed in, and the function
314305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// pointers.
31444c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  unsigned getNumSubExprs() const { return NumExprs; }
3145d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
3146d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// \brief Retrieve the array of expressions.
3147d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  Expr **getSubExprs() { return reinterpret_cast<Expr **>(SubExprs); }
3148d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
3149d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// getExpr - Return the Expr at the specified index.
3150d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  Expr *getExpr(unsigned Index) {
31514c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    assert((Index < NumExprs) && "Arg access out of range!");
31524c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    return cast<Expr>(SubExprs[Index]);
31534c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  }
31544c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  const Expr *getExpr(unsigned Index) const {
31554c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    assert((Index < NumExprs) && "Arg access out of range!");
31564c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    return cast<Expr>(SubExprs[Index]);
315705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
315805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
31591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setExprs(ASTContext &C, Expr ** Exprs, unsigned NumExprs);
316005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
316105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  unsigned getShuffleMaskIdx(ASTContext &Ctx, unsigned N) {
316205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    assert((N < NumExprs - 2) && "Shuffle idx out of range!");
3163eeae8f072748affce25ab4064982626361293390Douglas Gregor    return getExpr(N+2)->EvaluateAsInt(Ctx).getZExtValue();
316405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
3165d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
3166d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  // Iterators
316705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  child_range children() {
316805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    return child_range(&SubExprs[0], &SubExprs[0]+NumExprs);
316905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
317005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor};
317105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
3172ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor/// ChooseExpr - GNU builtin-in function __builtin_choose_expr.
31731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// This AST node is similar to the conditional operator (?:) in C, with
31741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// the following exceptions:
3175ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor/// - the test expression must be a integer constant expression.
317605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// - the expression returned acts like the chosen subexpression in every
3177711997184366d584c9c437102cae1e9d9927b986Douglas Gregor///   visible way: the type is the same as that of the chosen subexpression,
3178711997184366d584c9c437102cae1e9d9927b986Douglas Gregor///   and all predicates (whether it's an l-value, whether it's an integer
3179c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt///   constant expression, etc.) return the same result as for the chosen
3180319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor///   sub-expression.
3181d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregorclass ChooseExpr : public Expr {
318205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  enum { COND, LHS, RHS, END_EXPR };
318305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
318405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  SourceLocation BuiltinLoc, RParenLoc;
318505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorpublic:
318605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs,
318705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor             QualType t, ExprValueKind VK, ExprObjectKind OK,
318805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor             SourceLocation RP, bool TypeDependent, bool ValueDependent)
3189d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    : Expr(ChooseExprClass, t, VK, OK, TypeDependent, ValueDependent,
319005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor           (cond->isInstantiationDependent() ||
319105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor            lhs->isInstantiationDependent() ||
3192eeae8f072748affce25ab4064982626361293390Douglas Gregor            rhs->isInstantiationDependent()),
3193eeae8f072748affce25ab4064982626361293390Douglas Gregor           (cond->containsUnexpandedParameterPack() ||
3194d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor            lhs->containsUnexpandedParameterPack() ||
319505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor            rhs->containsUnexpandedParameterPack())),
319605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      BuiltinLoc(BLoc), RParenLoc(RP) {
31971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      SubExprs[COND] = cond;
319805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      SubExprs[LHS] = lhs;
319905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      SubExprs[RHS] = rhs;
320005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    }
320105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
320205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// \brief Build an empty __builtin_choose_expr.
320305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { }
320405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
3205d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// isConditionTrue - Return whether the condition is true (i.e. not
3206d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// equal to zero).
3207d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  bool isConditionTrue(const ASTContext &C) const;
3208d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
3209d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// getChosenSubExpr - Return the subexpression chosen according to the
3210d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// condition.
3211d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  Expr *getChosenSubExpr(const ASTContext &C) const {
3212d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    return isConditionTrue(C) ? getLHS() : getRHS();
3213d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  }
3214d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
3215d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
3216d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  void setCond(Expr *E) { SubExprs[COND] = E; }
3217d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
3218d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  void setLHS(Expr *E) { SubExprs[LHS] = E; }
3219d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
3220d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  void setRHS(Expr *E) { SubExprs[RHS] = E; }
3221d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
3222d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
3223d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
3224d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
3225ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
3226ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
3227319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor
3228ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  SourceRange getSourceRange() const {
3229ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor    return SourceRange(BuiltinLoc, RParenLoc);
323005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
323105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  static bool classof(const Stmt *T) {
323205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    return T->getStmtClass() == ChooseExprClass;
32331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
323405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  static bool classof(const ChooseExpr *) { return true; }
323505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
323605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  // Iterators
323705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  child_range children() {
323805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
32391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
32403498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor};
32413498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
32423498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// GNUNullExpr - Implements the GNU __null extension, which is a name
32433498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// for a null pointer constant that has integral type (e.g., int or
32443498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// long) and is the same size and alignment as a pointer. The __null
32451a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// extension is typically only used by system headers, which define
32461a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// NULL as __null in C++ rather than using 0 (which is an integer
32473498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// that may not match the size of a pointer).
32481a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregorclass GNUNullExpr : public Expr {
32491a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor  /// TokenLoc - The location of the __null keyword.
32501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation TokenLoc;
32513498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
32521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
32532333f7727f97018d6742e1e0938133bcfad967abEli Friedman  GNUNullExpr(QualType Ty, SourceLocation Loc)
32543498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor    : Expr(GNUNullExprClass, Ty, VK_RValue, OK_Ordinary, false, false, false,
3255d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor           false),
3256d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor      TokenLoc(Loc) { }
3257d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
3258d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// \brief Build an empty GNU __null expression.
32591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { }
32603498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
32613498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  /// getTokenLocation - The location of the __null token.
32623498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  SourceLocation getTokenLocation() const { return TokenLoc; }
32633498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  void setTokenLocation(SourceLocation L) { TokenLoc = L; }
32643498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
32653498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  SourceRange getSourceRange() const {
32663498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor    return SourceRange(TokenLoc);
32673498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  }
32683498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  static bool classof(const Stmt *T) {
32693498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor    return T->getStmtClass() == GNUNullExprClass;
32701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
327105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  static bool classof(const GNUNullExpr *) { return true; }
327205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
32732ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  // Iterators
32742ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  child_range children() { return child_range(); }
32752ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman};
32762ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
32772ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman/// VAArgExpr, used for the builtin function __builtin_va_arg.
32782ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanclass VAArgExpr : public Expr {
32792ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  Stmt *Val;
32801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  TypeSourceInfo *TInfo;
32812ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  SourceLocation BuiltinLoc, RParenLoc;
32822ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanpublic:
32832ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  VAArgExpr(SourceLocation BLoc, Expr* e, TypeSourceInfo *TInfo,
328437bdfe284ad365f753741d1d89c078c148b3f4afArgyrios Kyrtzidis            SourceLocation RPLoc, QualType t)
32851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : Expr(VAArgExprClass, t, VK_RValue, OK_Ordinary,
32862ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman           t->isDependentType(), false,
32871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           (TInfo->getType()->isInstantiationDependentType() ||
32881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump            e->isInstantiationDependent()),
32892ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman           (TInfo->getType()->containsUnexpandedParameterPack() ||
32902ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman            e->containsUnexpandedParameterPack())),
32912ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman      Val(e), TInfo(TInfo),
32921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      BuiltinLoc(BLoc),
32931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      RParenLoc(RPLoc) { }
32942ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
32952ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  /// \brief Create an empty __builtin_va_arg expression.
32962ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  explicit VAArgExpr(EmptyShell Empty) : Expr(VAArgExprClass, Empty) { }
32972ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
329883ddad3ab513f5d73698cf9fbeb4ed3f011bc3b9Douglas Gregor  const Expr *getSubExpr() const { return cast<Expr>(Val); }
32991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getSubExpr() { return cast<Expr>(Val); }
33002ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  void setSubExpr(Expr *E) { Val = E; }
33012ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
33022ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  TypeSourceInfo *getWrittenTypeInfo() const { return TInfo; }
33032ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  void setWrittenTypeInfo(TypeSourceInfo *TI) { TInfo = TI; }
33042ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
33051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
33062ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
33071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
33082ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  SourceLocation getRParenLoc() const { return RParenLoc; }
33092ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
33101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
33112ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  SourceRange getSourceRange() const {
33122ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman    return SourceRange(BuiltinLoc, RParenLoc);
33132ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  }
331437bdfe284ad365f753741d1d89c078c148b3f4afArgyrios Kyrtzidis  static bool classof(const Stmt *T) {
331560adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl    return T->getStmtClass() == VAArgExprClass;
33163397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl  }
33172ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  static bool classof(const VAArgExpr *) { return true; }
33182ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
33191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // Iterators
33204eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  child_range children() { return child_range(&Val, &Val+1); }
33214eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff};
33224eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
33234eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// @brief Describes an C or C++ initializer list.
3324a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner///
3325a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// InitListExpr describes an initializer list, which can be used to
3326a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// initialize objects of different types, including
3327a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// struct/class/union types, arrays, and vectors. For example:
3328a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner///
332973525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// @code
333073525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// struct foo x = { 1, { 2, 3 } };
333173525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// @endcode
3332a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner///
3333a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// Prior to semantic analysis, an initializer list will represent the
3334d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor/// initializer list as written by the user, but will have the
3335a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// placeholder type "void". This initializer list is called the
3336a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// syntactic form of the initializer, and may contain C99 designated
3337a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// initializers (represented as DesignatedInitExprs), initializations
3338a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// of subobject members without explicit braces, and so on. Clients
33392333f7727f97018d6742e1e0938133bcfad967abEli Friedman/// interested in the original syntax of the initializer list should
33402333f7727f97018d6742e1e0938133bcfad967abEli Friedman/// use the syntactic form of the initializer list.
3341d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor///
33421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// After semantic analysis, the initializer list will represent the
3343d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor/// semantic form of the initializer, where the initializations of all
3344d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor/// subobjects are made explicit with nested InitListExpr nodes and
3345d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor/// C99 designators have been eliminated by placing the designated
3346d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor/// initializations into the subobject they initialize. Additionally,
3347a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// any "holes" in the initialization, where no initializer has been
3348a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// specified for a particular subobject, will be replaced with
3349d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor/// implicitly-generated ImplicitValueInitExpr expressions that
3350d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor/// value-initialize the subobjects. Note, however, that the
3351d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor/// initializer lists may still have fewer initializers than there are
3352d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor/// elements to initialize within the object.
3353d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor///
3354d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor/// Given the semantic form of the initializer list, one can retrieve
3355d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor/// the original syntactic form of that initializer list (if it
3356d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor/// exists) using getSyntacticForm(). Since many initializer lists
3357a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// have the same syntactic and semantic forms, getSyntacticForm() may
3358a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// return NULL, indicating that the current initializer list also
33591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// serves as its syntactic form.
3360a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerclass InitListExpr : public Expr {
3361a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  // FIXME: Eliminate this vector in favor of ASTContext allocation
3362a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  typedef ASTVector<Stmt *> InitExprsTy;
33631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  InitExprsTy InitExprs;
3364a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  SourceLocation LBraceLoc, RBraceLoc;
3365a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
3366a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// Contains the initializer list that describes the syntactic form
33671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// written in the source code.
3368a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  InitListExpr *SyntacticForm;
3369a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
3370a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// \brief Either:
33711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///  If this initializer list initializes an array with more elements than
33722140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner  ///  there are initializers in the list, specifies an expression to be used
33732140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner  ///  for value initialization of the rest of the elements.
33742140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner  /// Or
33751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///  If this initializer list initializes a union, specifies which
33761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///  field within the union will be initialized.
33771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  llvm::PointerUnion<Expr *, FieldDecl *> ArrayFillerOrUnionFieldInit;
3378a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
3379a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// Whether this initializer list originally had a GNU array-range
33801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// designator in it. This is a temporary marker used by CodeGen.
3381a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  bool HadArrayRangeDesignator;
3382a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
3383a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerpublic:
3384a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  InitListExpr(ASTContext &C, SourceLocation lbraceloc,
3385a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner               Expr **initexprs, unsigned numinits,
3386a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner               SourceLocation rbraceloc);
338756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff
33889c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff  /// \brief Build an empty initializer list.
33894eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  explicit InitListExpr(ASTContext &C, EmptyShell Empty)
339056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff    : Expr(InitListExprClass, Empty), InitExprs(C) { }
339156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff
3392b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump  unsigned getNumInits() const { return InitExprs.size(); }
33934eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
3394b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump  /// \brief Retrieve the set of initializers.
33952333f7727f97018d6742e1e0938133bcfad967abEli Friedman  Expr **getInits() { return reinterpret_cast<Expr **>(InitExprs.data()); }
3396b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump
33979c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff  const Expr *getInit(unsigned Init) const {
339884af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor    assert(Init < getNumInits() && "Initializer access out of range!");
339984af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor    return cast_or_null<Expr>(InitExprs[Init]);
340084af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor  }
3401d5cab5435371b8cc74a9e05ebd40b5995ebad149Anders Carlsson
340256ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  Expr *getInit(unsigned Init) {
340384af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor    assert(Init < getNumInits() && "Initializer access out of range!");
340484af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor    return cast_or_null<Expr>(InitExprs[Init]);
340556ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  }
340656ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff
340756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  void setInit(unsigned Init, Expr *expr) {
340856ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff    assert(Init < getNumInits() && "Initializer access out of range!");
34099c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff    InitExprs[Init] = expr;
34109c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff  }
341156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff
34129c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff  /// \brief Reserve space for some number of initializers.
34139c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff  void reserveInits(ASTContext &C, unsigned NumInits);
341456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff
341556ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  /// @brief Specify the number of initializers
341656ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  ///
3417b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump  /// If there are more than @p NumInits initializers, the remaining
34185b54b88c4082bb81b8b341b622fda9a85cbd5fadChris Lattner  /// initializers will be destroyed. If there are fewer than @p
3419b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump  /// NumInits initializers, NULL expressions will be added for the
342084af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor  /// unknown initializers.
3421b83d287bc7f47d36fb0751a481e2ef9308b37252Mike Stump  void resizeInits(ASTContext &Context, unsigned NumInits);
34221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
34239c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff  /// @brief Updates the initializer at index @p Init with the new
34244eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  /// expression @p expr, and returns the old expression at that
34254eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  /// location.
34261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
34274eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  /// When @p Init is out of range for this initializer list, the
34284eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  /// initializer list will be extended with NULL expressions to
34294eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  /// accommodate the new entry.
34304eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  Expr *updateInit(ASTContext &C, unsigned Init, Expr *expr);
34311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
34324eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  /// \brief If this initializer list initializes an array with more elements
34334eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  /// than there are initializers in the list, specifies an expression to be
34344eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  /// used for value initialization of the rest of the elements.
34351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getArrayFiller() {
34364eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff    return ArrayFillerOrUnionFieldInit.dyn_cast<Expr *>();
34377d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian  }
34387d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian  const Expr *getArrayFiller() const {
343989f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian    return const_cast<InitListExpr *>(this)->getArrayFiller();
34404eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  }
34412333f7727f97018d6742e1e0938133bcfad967abEli Friedman  void setArrayFiller(Expr *filler);
34421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
344389f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian  /// \brief If this initializes a union, specifies which field in the
344484ca008a462b515f63871253f494d53c9190363cFariborz Jahanian  /// union to initialize.
344584ca008a462b515f63871253f494d53c9190363cFariborz Jahanian  ///
344652bc56a296b11b4fc6bf5ddf4ded5262f6484bdbFariborz Jahanian  /// Typically, this field is the first named field within the
344789f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian  /// union. However, a designated initializer can specify the
344894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  /// initialization of a different field within the union.
344994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  FieldDecl *getInitializedFieldInUnion() {
345094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor    return ArrayFillerOrUnionFieldInit.dyn_cast<FieldDecl *>();
345194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  }
345294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  const FieldDecl *getInitializedFieldInUnion() const {
34531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return const_cast<InitListExpr *>(this)->getInitializedFieldInUnion();
34544eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  }
34554eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  void setInitializedFieldInUnion(FieldDecl *FD) {
345694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor    ArrayFillerOrUnionFieldInit = FD;
345794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  }
345894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
345994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  // Explicit InitListExpr's originate from source code (and have valid source
346094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  // locations). Implicit InitListExpr's are created by the semantic analyzer.
34614eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  bool isExplicit() {
34621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return LBraceLoc.isValid() && RBraceLoc.isValid();
34634eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  }
346494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
34651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation getLBraceLoc() const { return LBraceLoc; }
34667d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian  void setLBraceLoc(SourceLocation Loc) { LBraceLoc = Loc; }
34677d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian  SourceLocation getRBraceLoc() const { return RBraceLoc; }
346889f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian  void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; }
346989f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian
347089f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian  /// @brief Retrieve the initializer list that describes the
347189f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian  /// syntactic form of the initializer.
347289f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian  ///
347389f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian  ///
347494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  InitListExpr *getSyntacticForm() const { return SyntacticForm; }
34751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setSyntacticForm(InitListExpr *Init) { SyntacticForm = Init; }
34761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
34774eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  bool hadArrayRangeDesignator() const { return HadArrayRangeDesignator; }
34784eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  void sawArrayRangeDesignator(bool ARD = true) {
34791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    HadArrayRangeDesignator = ARD;
34804eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  }
34814eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
34824eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  SourceRange getSourceRange() const;
34834eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
34844eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  static bool classof(const Stmt *T) {
34855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getStmtClass() == InitListExprClass;
34865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
34875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const InitListExpr *) { return true; }
3488
3489  // Iterators
3490  child_range children() {
3491    if (InitExprs.empty()) return child_range();
3492    return child_range(&InitExprs[0], &InitExprs[0] + InitExprs.size());
3493  }
3494
3495  typedef InitExprsTy::iterator iterator;
3496  typedef InitExprsTy::const_iterator const_iterator;
3497  typedef InitExprsTy::reverse_iterator reverse_iterator;
3498  typedef InitExprsTy::const_reverse_iterator const_reverse_iterator;
3499
3500  iterator begin() { return InitExprs.begin(); }
3501  const_iterator begin() const { return InitExprs.begin(); }
3502  iterator end() { return InitExprs.end(); }
3503  const_iterator end() const { return InitExprs.end(); }
3504  reverse_iterator rbegin() { return InitExprs.rbegin(); }
3505  const_reverse_iterator rbegin() const { return InitExprs.rbegin(); }
3506  reverse_iterator rend() { return InitExprs.rend(); }
3507  const_reverse_iterator rend() const { return InitExprs.rend(); }
3508
3509  friend class ASTStmtReader;
3510  friend class ASTStmtWriter;
3511};
3512
3513/// @brief Represents a C99 designated initializer expression.
3514///
3515/// A designated initializer expression (C99 6.7.8) contains one or
3516/// more designators (which can be field designators, array
3517/// designators, or GNU array-range designators) followed by an
3518/// expression that initializes the field or element(s) that the
3519/// designators refer to. For example, given:
3520///
3521/// @code
3522/// struct point {
3523///   double x;
3524///   double y;
3525/// };
3526/// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 };
3527/// @endcode
3528///
3529/// The InitListExpr contains three DesignatedInitExprs, the first of
3530/// which covers @c [2].y=1.0. This DesignatedInitExpr will have two
3531/// designators, one array designator for @c [2] followed by one field
3532/// designator for @c .y. The initalization expression will be 1.0.
3533class DesignatedInitExpr : public Expr {
3534public:
3535  /// \brief Forward declaration of the Designator class.
3536  class Designator;
3537
3538private:
3539  /// The location of the '=' or ':' prior to the actual initializer
3540  /// expression.
3541  SourceLocation EqualOrColonLoc;
3542
3543  /// Whether this designated initializer used the GNU deprecated
3544  /// syntax rather than the C99 '=' syntax.
3545  bool GNUSyntax : 1;
3546
3547  /// The number of designators in this initializer expression.
3548  unsigned NumDesignators : 15;
3549
3550  /// \brief The designators in this designated initialization
3551  /// expression.
3552  Designator *Designators;
3553
3554  /// The number of subexpressions of this initializer expression,
3555  /// which contains both the initializer and any additional
3556  /// expressions used by array and array-range designators.
3557  unsigned NumSubExprs : 16;
3558
3559
3560  DesignatedInitExpr(ASTContext &C, QualType Ty, unsigned NumDesignators,
3561                     const Designator *Designators,
3562                     SourceLocation EqualOrColonLoc, bool GNUSyntax,
3563                     Expr **IndexExprs, unsigned NumIndexExprs,
3564                     Expr *Init);
3565
3566  explicit DesignatedInitExpr(unsigned NumSubExprs)
3567    : Expr(DesignatedInitExprClass, EmptyShell()),
3568      NumDesignators(0), Designators(0), NumSubExprs(NumSubExprs) { }
3569
3570public:
3571  /// A field designator, e.g., ".x".
3572  struct FieldDesignator {
3573    /// Refers to the field that is being initialized. The low bit
3574    /// of this field determines whether this is actually a pointer
3575    /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When
3576    /// initially constructed, a field designator will store an
3577    /// IdentifierInfo*. After semantic analysis has resolved that
3578    /// name, the field designator will instead store a FieldDecl*.
3579    uintptr_t NameOrField;
3580
3581    /// The location of the '.' in the designated initializer.
3582    unsigned DotLoc;
3583
3584    /// The location of the field name in the designated initializer.
3585    unsigned FieldLoc;
3586  };
3587
3588  /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
3589  struct ArrayOrRangeDesignator {
3590    /// Location of the first index expression within the designated
3591    /// initializer expression's list of subexpressions.
3592    unsigned Index;
3593    /// The location of the '[' starting the array range designator.
3594    unsigned LBracketLoc;
3595    /// The location of the ellipsis separating the start and end
3596    /// indices. Only valid for GNU array-range designators.
3597    unsigned EllipsisLoc;
3598    /// The location of the ']' terminating the array range designator.
3599    unsigned RBracketLoc;
3600  };
3601
3602  /// @brief Represents a single C99 designator.
3603  ///
3604  /// @todo This class is infuriatingly similar to clang::Designator,
3605  /// but minor differences (storing indices vs. storing pointers)
3606  /// keep us from reusing it. Try harder, later, to rectify these
3607  /// differences.
3608  class Designator {
3609    /// @brief The kind of designator this describes.
3610    enum {
3611      FieldDesignator,
3612      ArrayDesignator,
3613      ArrayRangeDesignator
3614    } Kind;
3615
3616    union {
3617      /// A field designator, e.g., ".x".
3618      struct FieldDesignator Field;
3619      /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
3620      struct ArrayOrRangeDesignator ArrayOrRange;
3621    };
3622    friend class DesignatedInitExpr;
3623
3624  public:
3625    Designator() {}
3626
3627    /// @brief Initializes a field designator.
3628    Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc,
3629               SourceLocation FieldLoc)
3630      : Kind(FieldDesignator) {
3631      Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01;
3632      Field.DotLoc = DotLoc.getRawEncoding();
3633      Field.FieldLoc = FieldLoc.getRawEncoding();
3634    }
3635
3636    /// @brief Initializes an array designator.
3637    Designator(unsigned Index, SourceLocation LBracketLoc,
3638               SourceLocation RBracketLoc)
3639      : Kind(ArrayDesignator) {
3640      ArrayOrRange.Index = Index;
3641      ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
3642      ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding();
3643      ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
3644    }
3645
3646    /// @brief Initializes a GNU array-range designator.
3647    Designator(unsigned Index, SourceLocation LBracketLoc,
3648               SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
3649      : Kind(ArrayRangeDesignator) {
3650      ArrayOrRange.Index = Index;
3651      ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
3652      ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding();
3653      ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
3654    }
3655
3656    bool isFieldDesignator() const { return Kind == FieldDesignator; }
3657    bool isArrayDesignator() const { return Kind == ArrayDesignator; }
3658    bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; }
3659
3660    IdentifierInfo *getFieldName() const;
3661
3662    FieldDecl *getField() const {
3663      assert(Kind == FieldDesignator && "Only valid on a field designator");
3664      if (Field.NameOrField & 0x01)
3665        return 0;
3666      else
3667        return reinterpret_cast<FieldDecl *>(Field.NameOrField);
3668    }
3669
3670    void setField(FieldDecl *FD) {
3671      assert(Kind == FieldDesignator && "Only valid on a field designator");
3672      Field.NameOrField = reinterpret_cast<uintptr_t>(FD);
3673    }
3674
3675    SourceLocation getDotLoc() const {
3676      assert(Kind == FieldDesignator && "Only valid on a field designator");
3677      return SourceLocation::getFromRawEncoding(Field.DotLoc);
3678    }
3679
3680    SourceLocation getFieldLoc() const {
3681      assert(Kind == FieldDesignator && "Only valid on a field designator");
3682      return SourceLocation::getFromRawEncoding(Field.FieldLoc);
3683    }
3684
3685    SourceLocation getLBracketLoc() const {
3686      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
3687             "Only valid on an array or array-range designator");
3688      return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc);
3689    }
3690
3691    SourceLocation getRBracketLoc() const {
3692      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
3693             "Only valid on an array or array-range designator");
3694      return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc);
3695    }
3696
3697    SourceLocation getEllipsisLoc() const {
3698      assert(Kind == ArrayRangeDesignator &&
3699             "Only valid on an array-range designator");
3700      return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc);
3701    }
3702
3703    unsigned getFirstExprIndex() const {
3704      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
3705             "Only valid on an array or array-range designator");
3706      return ArrayOrRange.Index;
3707    }
3708
3709    SourceLocation getStartLocation() const {
3710      if (Kind == FieldDesignator)
3711        return getDotLoc().isInvalid()? getFieldLoc() : getDotLoc();
3712      else
3713        return getLBracketLoc();
3714    }
3715    SourceLocation getEndLocation() const {
3716      return Kind == FieldDesignator ? getFieldLoc() : getRBracketLoc();
3717    }
3718    SourceRange getSourceRange() const {
3719      return SourceRange(getStartLocation(), getEndLocation());
3720    }
3721  };
3722
3723  static DesignatedInitExpr *Create(ASTContext &C, Designator *Designators,
3724                                    unsigned NumDesignators,
3725                                    Expr **IndexExprs, unsigned NumIndexExprs,
3726                                    SourceLocation EqualOrColonLoc,
3727                                    bool GNUSyntax, Expr *Init);
3728
3729  static DesignatedInitExpr *CreateEmpty(ASTContext &C, unsigned NumIndexExprs);
3730
3731  /// @brief Returns the number of designators in this initializer.
3732  unsigned size() const { return NumDesignators; }
3733
3734  // Iterator access to the designators.
3735  typedef Designator *designators_iterator;
3736  designators_iterator designators_begin() { return Designators; }
3737  designators_iterator designators_end() {
3738    return Designators + NumDesignators;
3739  }
3740
3741  typedef const Designator *const_designators_iterator;
3742  const_designators_iterator designators_begin() const { return Designators; }
3743  const_designators_iterator designators_end() const {
3744    return Designators + NumDesignators;
3745  }
3746
3747  typedef std::reverse_iterator<designators_iterator>
3748          reverse_designators_iterator;
3749  reverse_designators_iterator designators_rbegin() {
3750    return reverse_designators_iterator(designators_end());
3751  }
3752  reverse_designators_iterator designators_rend() {
3753    return reverse_designators_iterator(designators_begin());
3754  }
3755
3756  typedef std::reverse_iterator<const_designators_iterator>
3757          const_reverse_designators_iterator;
3758  const_reverse_designators_iterator designators_rbegin() const {
3759    return const_reverse_designators_iterator(designators_end());
3760  }
3761  const_reverse_designators_iterator designators_rend() const {
3762    return const_reverse_designators_iterator(designators_begin());
3763  }
3764
3765  Designator *getDesignator(unsigned Idx) { return &designators_begin()[Idx]; }
3766
3767  void setDesignators(ASTContext &C, const Designator *Desigs,
3768                      unsigned NumDesigs);
3769
3770  Expr *getArrayIndex(const Designator& D);
3771  Expr *getArrayRangeStart(const Designator& D);
3772  Expr *getArrayRangeEnd(const Designator& D);
3773
3774  /// @brief Retrieve the location of the '=' that precedes the
3775  /// initializer value itself, if present.
3776  SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; }
3777  void setEqualOrColonLoc(SourceLocation L) { EqualOrColonLoc = L; }
3778
3779  /// @brief Determines whether this designated initializer used the
3780  /// deprecated GNU syntax for designated initializers.
3781  bool usesGNUSyntax() const { return GNUSyntax; }
3782  void setGNUSyntax(bool GNU) { GNUSyntax = GNU; }
3783
3784  /// @brief Retrieve the initializer value.
3785  Expr *getInit() const {
3786    return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin());
3787  }
3788
3789  void setInit(Expr *init) {
3790    *child_begin() = init;
3791  }
3792
3793  /// \brief Retrieve the total number of subexpressions in this
3794  /// designated initializer expression, including the actual
3795  /// initialized value and any expressions that occur within array
3796  /// and array-range designators.
3797  unsigned getNumSubExprs() const { return NumSubExprs; }
3798
3799  Expr *getSubExpr(unsigned Idx) {
3800    assert(Idx < NumSubExprs && "Subscript out of range");
3801    char* Ptr = static_cast<char*>(static_cast<void *>(this));
3802    Ptr += sizeof(DesignatedInitExpr);
3803    return reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx];
3804  }
3805
3806  void setSubExpr(unsigned Idx, Expr *E) {
3807    assert(Idx < NumSubExprs && "Subscript out of range");
3808    char* Ptr = static_cast<char*>(static_cast<void *>(this));
3809    Ptr += sizeof(DesignatedInitExpr);
3810    reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx] = E;
3811  }
3812
3813  /// \brief Replaces the designator at index @p Idx with the series
3814  /// of designators in [First, Last).
3815  void ExpandDesignator(ASTContext &C, unsigned Idx, const Designator *First,
3816                        const Designator *Last);
3817
3818  SourceRange getDesignatorsSourceRange() const;
3819
3820  SourceRange getSourceRange() const;
3821
3822  static bool classof(const Stmt *T) {
3823    return T->getStmtClass() == DesignatedInitExprClass;
3824  }
3825  static bool classof(const DesignatedInitExpr *) { return true; }
3826
3827  // Iterators
3828  child_range children() {
3829    Stmt **begin = reinterpret_cast<Stmt**>(this + 1);
3830    return child_range(begin, begin + NumSubExprs);
3831  }
3832};
3833
3834/// \brief Represents an implicitly-generated value initialization of
3835/// an object of a given type.
3836///
3837/// Implicit value initializations occur within semantic initializer
3838/// list expressions (InitListExpr) as placeholders for subobject
3839/// initializations not explicitly specified by the user.
3840///
3841/// \see InitListExpr
3842class ImplicitValueInitExpr : public Expr {
3843public:
3844  explicit ImplicitValueInitExpr(QualType ty)
3845    : Expr(ImplicitValueInitExprClass, ty, VK_RValue, OK_Ordinary,
3846           false, false, ty->isInstantiationDependentType(), false) { }
3847
3848  /// \brief Construct an empty implicit value initialization.
3849  explicit ImplicitValueInitExpr(EmptyShell Empty)
3850    : Expr(ImplicitValueInitExprClass, Empty) { }
3851
3852  static bool classof(const Stmt *T) {
3853    return T->getStmtClass() == ImplicitValueInitExprClass;
3854  }
3855  static bool classof(const ImplicitValueInitExpr *) { return true; }
3856
3857  SourceRange getSourceRange() const {
3858    return SourceRange();
3859  }
3860
3861  // Iterators
3862  child_range children() { return child_range(); }
3863};
3864
3865
3866class ParenListExpr : public Expr {
3867  Stmt **Exprs;
3868  unsigned NumExprs;
3869  SourceLocation LParenLoc, RParenLoc;
3870
3871public:
3872  ParenListExpr(ASTContext& C, SourceLocation lparenloc, Expr **exprs,
3873                unsigned numexprs, SourceLocation rparenloc, QualType T);
3874
3875  /// \brief Build an empty paren list.
3876  explicit ParenListExpr(EmptyShell Empty) : Expr(ParenListExprClass, Empty) { }
3877
3878  unsigned getNumExprs() const { return NumExprs; }
3879
3880  const Expr* getExpr(unsigned Init) const {
3881    assert(Init < getNumExprs() && "Initializer access out of range!");
3882    return cast_or_null<Expr>(Exprs[Init]);
3883  }
3884
3885  Expr* getExpr(unsigned Init) {
3886    assert(Init < getNumExprs() && "Initializer access out of range!");
3887    return cast_or_null<Expr>(Exprs[Init]);
3888  }
3889
3890  Expr **getExprs() { return reinterpret_cast<Expr **>(Exprs); }
3891
3892  SourceLocation getLParenLoc() const { return LParenLoc; }
3893  SourceLocation getRParenLoc() const { return RParenLoc; }
3894
3895  SourceRange getSourceRange() const {
3896    return SourceRange(LParenLoc, RParenLoc);
3897  }
3898  static bool classof(const Stmt *T) {
3899    return T->getStmtClass() == ParenListExprClass;
3900  }
3901  static bool classof(const ParenListExpr *) { return true; }
3902
3903  // Iterators
3904  child_range children() {
3905    return child_range(&Exprs[0], &Exprs[0]+NumExprs);
3906  }
3907
3908  friend class ASTStmtReader;
3909  friend class ASTStmtWriter;
3910};
3911
3912
3913/// \brief Represents a C1X generic selection.
3914///
3915/// A generic selection (C1X 6.5.1.1) contains an unevaluated controlling
3916/// expression, followed by one or more generic associations.  Each generic
3917/// association specifies a type name and an expression, or "default" and an
3918/// expression (in which case it is known as a default generic association).
3919/// The type and value of the generic selection are identical to those of its
3920/// result expression, which is defined as the expression in the generic
3921/// association with a type name that is compatible with the type of the
3922/// controlling expression, or the expression in the default generic association
3923/// if no types are compatible.  For example:
3924///
3925/// @code
3926/// _Generic(X, double: 1, float: 2, default: 3)
3927/// @endcode
3928///
3929/// The above expression evaluates to 1 if 1.0 is substituted for X, 2 if 1.0f
3930/// or 3 if "hello".
3931///
3932/// As an extension, generic selections are allowed in C++, where the following
3933/// additional semantics apply:
3934///
3935/// Any generic selection whose controlling expression is type-dependent or
3936/// which names a dependent type in its association list is result-dependent,
3937/// which means that the choice of result expression is dependent.
3938/// Result-dependent generic associations are both type- and value-dependent.
3939class GenericSelectionExpr : public Expr {
3940  enum { CONTROLLING, END_EXPR };
3941  TypeSourceInfo **AssocTypes;
3942  Stmt **SubExprs;
3943  unsigned NumAssocs, ResultIndex;
3944  SourceLocation GenericLoc, DefaultLoc, RParenLoc;
3945
3946public:
3947  GenericSelectionExpr(ASTContext &Context,
3948                       SourceLocation GenericLoc, Expr *ControllingExpr,
3949                       TypeSourceInfo **AssocTypes, Expr **AssocExprs,
3950                       unsigned NumAssocs, SourceLocation DefaultLoc,
3951                       SourceLocation RParenLoc,
3952                       bool ContainsUnexpandedParameterPack,
3953                       unsigned ResultIndex);
3954
3955  /// This constructor is used in the result-dependent case.
3956  GenericSelectionExpr(ASTContext &Context,
3957                       SourceLocation GenericLoc, Expr *ControllingExpr,
3958                       TypeSourceInfo **AssocTypes, Expr **AssocExprs,
3959                       unsigned NumAssocs, SourceLocation DefaultLoc,
3960                       SourceLocation RParenLoc,
3961                       bool ContainsUnexpandedParameterPack);
3962
3963  explicit GenericSelectionExpr(EmptyShell Empty)
3964    : Expr(GenericSelectionExprClass, Empty) { }
3965
3966  unsigned getNumAssocs() const { return NumAssocs; }
3967
3968  SourceLocation getGenericLoc() const { return GenericLoc; }
3969  SourceLocation getDefaultLoc() const { return DefaultLoc; }
3970  SourceLocation getRParenLoc() const { return RParenLoc; }
3971
3972  const Expr *getAssocExpr(unsigned i) const {
3973    return cast<Expr>(SubExprs[END_EXPR+i]);
3974  }
3975  Expr *getAssocExpr(unsigned i) { return cast<Expr>(SubExprs[END_EXPR+i]); }
3976
3977  const TypeSourceInfo *getAssocTypeSourceInfo(unsigned i) const {
3978    return AssocTypes[i];
3979  }
3980  TypeSourceInfo *getAssocTypeSourceInfo(unsigned i) { return AssocTypes[i]; }
3981
3982  QualType getAssocType(unsigned i) const {
3983    if (const TypeSourceInfo *TS = getAssocTypeSourceInfo(i))
3984      return TS->getType();
3985    else
3986      return QualType();
3987  }
3988
3989  const Expr *getControllingExpr() const {
3990    return cast<Expr>(SubExprs[CONTROLLING]);
3991  }
3992  Expr *getControllingExpr() { return cast<Expr>(SubExprs[CONTROLLING]); }
3993
3994  /// Whether this generic selection is result-dependent.
3995  bool isResultDependent() const { return ResultIndex == -1U; }
3996
3997  /// The zero-based index of the result expression's generic association in
3998  /// the generic selection's association list.  Defined only if the
3999  /// generic selection is not result-dependent.
4000  unsigned getResultIndex() const {
4001    assert(!isResultDependent() && "Generic selection is result-dependent");
4002    return ResultIndex;
4003  }
4004
4005  /// The generic selection's result expression.  Defined only if the
4006  /// generic selection is not result-dependent.
4007  const Expr *getResultExpr() const { return getAssocExpr(getResultIndex()); }
4008  Expr *getResultExpr() { return getAssocExpr(getResultIndex()); }
4009
4010  SourceRange getSourceRange() const {
4011    return SourceRange(GenericLoc, RParenLoc);
4012  }
4013  static bool classof(const Stmt *T) {
4014    return T->getStmtClass() == GenericSelectionExprClass;
4015  }
4016  static bool classof(const GenericSelectionExpr *) { return true; }
4017
4018  child_range children() {
4019    return child_range(SubExprs, SubExprs+END_EXPR+NumAssocs);
4020  }
4021
4022  friend class ASTStmtReader;
4023};
4024
4025//===----------------------------------------------------------------------===//
4026// Clang Extensions
4027//===----------------------------------------------------------------------===//
4028
4029
4030/// ExtVectorElementExpr - This represents access to specific elements of a
4031/// vector, and may occur on the left hand side or right hand side.  For example
4032/// the following is legal:  "V.xy = V.zw" if V is a 4 element extended vector.
4033///
4034/// Note that the base may have either vector or pointer to vector type, just
4035/// like a struct field reference.
4036///
4037class ExtVectorElementExpr : public Expr {
4038  Stmt *Base;
4039  IdentifierInfo *Accessor;
4040  SourceLocation AccessorLoc;
4041public:
4042  ExtVectorElementExpr(QualType ty, ExprValueKind VK, Expr *base,
4043                       IdentifierInfo &accessor, SourceLocation loc)
4044    : Expr(ExtVectorElementExprClass, ty, VK,
4045           (VK == VK_RValue ? OK_Ordinary : OK_VectorComponent),
4046           base->isTypeDependent(), base->isValueDependent(),
4047           base->isInstantiationDependent(),
4048           base->containsUnexpandedParameterPack()),
4049      Base(base), Accessor(&accessor), AccessorLoc(loc) {}
4050
4051  /// \brief Build an empty vector element expression.
4052  explicit ExtVectorElementExpr(EmptyShell Empty)
4053    : Expr(ExtVectorElementExprClass, Empty) { }
4054
4055  const Expr *getBase() const { return cast<Expr>(Base); }
4056  Expr *getBase() { return cast<Expr>(Base); }
4057  void setBase(Expr *E) { Base = E; }
4058
4059  IdentifierInfo &getAccessor() const { return *Accessor; }
4060  void setAccessor(IdentifierInfo *II) { Accessor = II; }
4061
4062  SourceLocation getAccessorLoc() const { return AccessorLoc; }
4063  void setAccessorLoc(SourceLocation L) { AccessorLoc = L; }
4064
4065  /// getNumElements - Get the number of components being selected.
4066  unsigned getNumElements() const;
4067
4068  /// containsDuplicateElements - Return true if any element access is
4069  /// repeated.
4070  bool containsDuplicateElements() const;
4071
4072  /// getEncodedElementAccess - Encode the elements accessed into an llvm
4073  /// aggregate Constant of ConstantInt(s).
4074  void getEncodedElementAccess(SmallVectorImpl<unsigned> &Elts) const;
4075
4076  SourceRange getSourceRange() const {
4077    return SourceRange(getBase()->getLocStart(), AccessorLoc);
4078  }
4079
4080  /// isArrow - Return true if the base expression is a pointer to vector,
4081  /// return false if the base expression is a vector.
4082  bool isArrow() const;
4083
4084  static bool classof(const Stmt *T) {
4085    return T->getStmtClass() == ExtVectorElementExprClass;
4086  }
4087  static bool classof(const ExtVectorElementExpr *) { return true; }
4088
4089  // Iterators
4090  child_range children() { return child_range(&Base, &Base+1); }
4091};
4092
4093
4094/// BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
4095/// ^{ statement-body }   or   ^(int arg1, float arg2){ statement-body }
4096class BlockExpr : public Expr {
4097protected:
4098  BlockDecl *TheBlock;
4099public:
4100  BlockExpr(BlockDecl *BD, QualType ty)
4101    : Expr(BlockExprClass, ty, VK_RValue, OK_Ordinary,
4102           ty->isDependentType(), false,
4103           // FIXME: Check for instantiate-dependence in the statement?
4104           ty->isInstantiationDependentType(),
4105           false),
4106      TheBlock(BD) {}
4107
4108  /// \brief Build an empty block expression.
4109  explicit BlockExpr(EmptyShell Empty) : Expr(BlockExprClass, Empty) { }
4110
4111  const BlockDecl *getBlockDecl() const { return TheBlock; }
4112  BlockDecl *getBlockDecl() { return TheBlock; }
4113  void setBlockDecl(BlockDecl *BD) { TheBlock = BD; }
4114
4115  // Convenience functions for probing the underlying BlockDecl.
4116  SourceLocation getCaretLocation() const;
4117  const Stmt *getBody() const;
4118  Stmt *getBody();
4119
4120  SourceRange getSourceRange() const {
4121    return SourceRange(getCaretLocation(), getBody()->getLocEnd());
4122  }
4123
4124  /// getFunctionType - Return the underlying function type for this block.
4125  const FunctionType *getFunctionType() const;
4126
4127  static bool classof(const Stmt *T) {
4128    return T->getStmtClass() == BlockExprClass;
4129  }
4130  static bool classof(const BlockExpr *) { return true; }
4131
4132  // Iterators
4133  child_range children() { return child_range(); }
4134};
4135
4136/// BlockDeclRefExpr - A reference to a local variable declared in an
4137/// enclosing scope.
4138class BlockDeclRefExpr : public Expr {
4139  VarDecl *D;
4140  SourceLocation Loc;
4141  bool IsByRef : 1;
4142  bool ConstQualAdded : 1;
4143public:
4144  BlockDeclRefExpr(VarDecl *d, QualType t, ExprValueKind VK,
4145                   SourceLocation l, bool ByRef, bool constAdded = false);
4146
4147  // \brief Build an empty reference to a declared variable in a
4148  // block.
4149  explicit BlockDeclRefExpr(EmptyShell Empty)
4150    : Expr(BlockDeclRefExprClass, Empty) { }
4151
4152  VarDecl *getDecl() { return D; }
4153  const VarDecl *getDecl() const { return D; }
4154  void setDecl(VarDecl *VD) { D = VD; }
4155
4156  SourceLocation getLocation() const { return Loc; }
4157  void setLocation(SourceLocation L) { Loc = L; }
4158
4159  SourceRange getSourceRange() const { return SourceRange(Loc); }
4160
4161  bool isByRef() const { return IsByRef; }
4162  void setByRef(bool BR) { IsByRef = BR; }
4163
4164  bool isConstQualAdded() const { return ConstQualAdded; }
4165  void setConstQualAdded(bool C) { ConstQualAdded = C; }
4166
4167  static bool classof(const Stmt *T) {
4168    return T->getStmtClass() == BlockDeclRefExprClass;
4169  }
4170  static bool classof(const BlockDeclRefExpr *) { return true; }
4171
4172  // Iterators
4173  child_range children() { return child_range(); }
4174};
4175
4176/// AsTypeExpr - Clang builtin function __builtin_astype [OpenCL 6.2.4.2]
4177/// This AST node provides support for reinterpreting a type to another
4178/// type of the same size.
4179class AsTypeExpr : public Expr { // Should this be an ExplicitCastExpr?
4180private:
4181  Stmt *SrcExpr;
4182  SourceLocation BuiltinLoc, RParenLoc;
4183
4184  friend class ASTReader;
4185  friend class ASTStmtReader;
4186  explicit AsTypeExpr(EmptyShell Empty) : Expr(AsTypeExprClass, Empty) {}
4187
4188public:
4189  AsTypeExpr(Expr* SrcExpr, QualType DstType,
4190             ExprValueKind VK, ExprObjectKind OK,
4191             SourceLocation BuiltinLoc, SourceLocation RParenLoc)
4192    : Expr(AsTypeExprClass, DstType, VK, OK,
4193           DstType->isDependentType(),
4194           DstType->isDependentType() || SrcExpr->isValueDependent(),
4195           (DstType->isInstantiationDependentType() ||
4196            SrcExpr->isInstantiationDependent()),
4197           (DstType->containsUnexpandedParameterPack() ||
4198            SrcExpr->containsUnexpandedParameterPack())),
4199  SrcExpr(SrcExpr), BuiltinLoc(BuiltinLoc), RParenLoc(RParenLoc) {}
4200
4201  /// getSrcExpr - Return the Expr to be converted.
4202  Expr *getSrcExpr() const { return cast<Expr>(SrcExpr); }
4203
4204  /// getBuiltinLoc - Return the location of the __builtin_astype token.
4205  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
4206
4207  /// getRParenLoc - Return the location of final right parenthesis.
4208  SourceLocation getRParenLoc() const { return RParenLoc; }
4209
4210  SourceRange getSourceRange() const {
4211    return SourceRange(BuiltinLoc, RParenLoc);
4212  }
4213
4214  static bool classof(const Stmt *T) {
4215    return T->getStmtClass() == AsTypeExprClass;
4216  }
4217  static bool classof(const AsTypeExpr *) { return true; }
4218
4219  // Iterators
4220  child_range children() { return child_range(&SrcExpr, &SrcExpr+1); }
4221};
4222}  // end namespace clang
4223
4224#endif
4225