Expr.h revision 4e43dec4df9d7dd8e07b47bb15967f1b733a9bc6
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/ASTVector.h"
195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Decl.h"
20161755a09898c95d21bfff33707da9ca41cd53c5John McCall#include "clang/AST/DeclAccessPair.h"
215baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall#include "clang/AST/OperationKinds.h"
22709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek#include "clang/AST/Stmt.h"
23409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson#include "clang/AST/TemplateBase.h"
245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Type.h"
25525a05093a4816af961fe2bc6b8a81c17e2e26c2Chris Lattner#include "clang/Basic/CharInfo.h"
263b8d116703db8018f855cbb4733ace426422623bNate Begeman#include "clang/Basic/TypeTraits.h"
27b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar#include "llvm/ADT/APFloat.h"
28403ba3522d1b1c97ae5fad81c1a2c4b3a754e1c1Nick Lewycky#include "llvm/ADT/APSInt.h"
29c5ae899b4bbf65488445316c63168079177db0edSteve Naroff#include "llvm/ADT/SmallVector.h"
305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/StringRef.h"
315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/Support/Compiler.h"
32590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner
33c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlssonnamespace clang {
34c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class APValue;
35c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class ASTContext;
36c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class BlockDecl;
378e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor  class CXXBaseSpecifier;
38c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class CXXMemberCallExpr;
3956ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  class CXXOperatorCallExpr;
40409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  class CastExpr;
4188a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  class Decl;
4288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  class IdentifierInfo;
43f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall  class MaterializeTemporaryExpr;
44833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  class NamedDecl;
45d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  class ObjCPropertyRefExpr;
4688a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  class OpaqueValueExpr;
477ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson  class ParmVarDecl;
48f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  class TargetInfo;
497ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson  class ValueDecl;
505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// \brief A simple array of base specifiers.
525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertypedef SmallVector<CXXBaseSpecifier*, 4> CXXCastPath;
535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// \brief An adjustment to be made to the temporary created when emitting a
555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// reference binding, which accesses a particular subobject of that temporary.
56898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorstruct SubobjectAdjustment {
57bef0efd11bc4430a3ee437a3213cec5c18af855aChris Lattner  enum {
585baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall    DerivedToBaseAdjustment,
598e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    FieldAdjustment,
60f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    MemberPointerAdjustment
61bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  } Kind;
628e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
638e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
64f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  struct DTB {
65f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    const CastExpr *BasePath;
66bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    const CXXRecordDecl *DerivedClass;
67898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  };
68898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
69898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  struct P {
700b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor    const MemberPointerType *MPT;
710b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor    Expr *RHS;
720b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  };
731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
74f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor  union {
751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    struct DTB DerivedToBase;
769d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    FieldDecl *Field;
779d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    struct P Ptr;
789d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor  };
799d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor
809d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor  SubobjectAdjustment(const CastExpr *BasePath,
819d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor                      const CXXRecordDecl *DerivedClass)
829d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor    : Kind(DerivedToBaseAdjustment) {
83905d11d53aeb6b26744f44fedc2b2820c7a62df6Douglas Gregor    DerivedToBase.BasePath = BasePath;
848320aaaa01d931aa234fc3bce05b399ef41898d5Daniel Dunbar    DerivedToBase.DerivedClass = DerivedClass;
85f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor  }
861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
879d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor  SubobjectAdjustment(FieldDecl *Field)
8877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek    : Kind(FieldAdjustment) {
89898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    this->Field = Field;
90898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
91898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SubobjectAdjustment(const MemberPointerType *MPT, Expr *RHS)
93898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    : Kind(MemberPointerAdjustment) {
94898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    this->Ptr.MPT = MPT;
95898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    this->Ptr.RHS = RHS;
968e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  }
97898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor};
980b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
998e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall/// Expr - This represents one expression.  Note that Expr's are subclasses of
1000b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor/// Stmt.  This allows an expression to be transparently used any place a Stmt
101898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// is required.
102898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor///
103898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorclass Expr : public Stmt {
104898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  QualType TR;
105898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
106898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorprotected:
1071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr(StmtClass SC, QualType T, ExprValueKind VK, ExprObjectKind OK,
108898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor       bool TD, bool VD, bool ID, bool ContainsUnexpandedParameterPack)
109898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    : Stmt(SC)
110898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  {
111898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    ExprBits.TypeDependent = TD;
1128e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    ExprBits.ValueDependent = VD;
113898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    ExprBits.InstantiationDependent = ID;
1140b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor    ExprBits.ValueKind = VK;
1158e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall    ExprBits.ObjectKind = OK;
1160b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor    ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack;
117d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    setType(T);
118d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  }
119d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
120d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// \brief Construct an empty expression.
121d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  explicit Expr(StmtClass SC, EmptyShell) : Stmt(SC) { }
122d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
123d0937224f383c7cc72c947119380f9713a070c73Douglas Gregorpublic:
124d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  QualType getType() const { return TR; }
125d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  void setType(QualType t) {
126d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    // In C++, the type of an expression is always adjusted so that it
127d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    // will not have reference type an expression will never have
128d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    // reference type (C++ [expr]p6). Use
129d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    // QualType::getNonReferenceType() to retrieve the non-reference
130d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    // type. Additionally, inspect Expr::isLvalue to determine whether
131d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    // an expression that is adjusted in this manner should be
132d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    // considered an lvalue.
133d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    assert((t.isNull() || !t->isReferenceType()) &&
134d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           "Expressions can't have reference type");
135bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor
136bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    TR = t;
137bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  }
138bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor
139bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  /// isValueDependent - Determines whether this expression is
140bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  /// value-dependent (C++ [temp.dep.constexpr]). For example, the
1415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// array bound of "Chars" in the following example is
1425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// value-dependent.
1435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// @code
1445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// template<int Size, char (&Chars)[Size]> struct meta_string;
1455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// @endcode
1465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isValueDependent() const { return ExprBits.ValueDependent; }
1475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// \brief Set whether this expression is value-dependent or not.
1491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setValueDependent(bool VD) {
150026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    ExprBits.ValueDependent = VD;
151026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    if (VD)
152026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner      ExprBits.InstantiationDependent = true;
153026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  }
154026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner
155df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump  /// isTypeDependent - Determines whether this expression is
1561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// type-dependent (C++ [temp.dep.expr]), which means that its type
1577eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  /// could change from one template instantiation to the next. For
1587eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  /// example, the expressions "x" and "x + y" are type-dependent in
1597eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  /// the following code, but "y" is not type-dependent:
1607eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  /// @code
1617eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  /// template<typename T>
1627eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  /// void add(T x, int y) {
1635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///   x + y;
1647eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  /// }
1657eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  /// @endcode
1667eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  bool isTypeDependent() const { return ExprBits.TypeDependent; }
1677eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall
1687eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  /// \brief Set whether this expression is type-dependent or not.
1697eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  void setTypeDependent(bool TD) {
1707eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall    ExprBits.TypeDependent = TD;
1717eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall    if (TD)
1727eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall      ExprBits.InstantiationDependent = true;
1737eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  }
1747eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall
1757eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  /// \brief Whether this expression is instantiation-dependent, meaning that
1765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// it depends in some way on a template parameter, even if neither its type
1775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// nor (constant) value can change due to the template instantiation.
1785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
179fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff  /// In the following example, the expression \c sizeof(sizeof(T() + T())) is
18086f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor  /// instantiation-dependent (since it involves a template parameter \c T), but
1812514a309204341798f96912ce7a90841bea59727Fariborz Jahanian  /// is neither type- nor value-dependent, since the type of the inner
182e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian  /// \c sizeof is known (\c std::size_t) and therefore the size of the outer
183e873fb74219f48407ae0b8fa083aa7f0b6ff1427Douglas Gregor  /// \c sizeof is known.
1845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
1857eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  /// \code
1867eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall  /// template<typename T>
18753202857c60214d80950a975e6e52aebf30bd16aEli Friedman  /// void f(T x, T y) {
1885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///   sizeof(sizeof(T() + T());
1895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// }
1901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \endcode
1915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
1925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isInstantiationDependent() const {
19344e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar    return ExprBits.InstantiationDependent;
19444e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar  }
19544e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar
19644e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar  /// \brief Set whether this expression is instantiation-dependent or not.
1975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void setInstantiationDependent(bool ID) {
1985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ExprBits.InstantiationDependent = ID;
1995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
201fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff  /// \brief Whether this expression contains an unexpanded parameter
2025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// pack (for C++11 variadic templates).
203ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner  ///
2045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Given the following function template:
2055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
2064f6a7d7ead09b439216c32f2de806a998aeb222aSteve Naroff  /// \code
2075daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian  /// template<typename F, typename ...Types>
208ba8d2d684e74a20bef03828c21c991d222c7e9e5Fariborz Jahanian  /// void forward(const F &f, Types &&...args) {
20986f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor  ///   f(static_cast<Types&&>(args)...);
2102514a309204341798f96912ce7a90841bea59727Fariborz Jahanian  /// }
211e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian  /// \endcode
212e873fb74219f48407ae0b8fa083aa7f0b6ff1427Douglas Gregor  ///
2135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// The expressions \c args and \c static_cast<Types&&>(args) both
21444e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar  /// contain parameter packs.
21544e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar  bool containsUnexpandedParameterPack() const {
2161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return ExprBits.ContainsUnexpandedParameterPack;
2172111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  }
2182111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl
2192111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// \brief Set the bit that describes whether this expression
2202111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// contains an unexpanded parameter pack.
2212111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  void setContainsUnexpandedParameterPack(bool PP = true) {
2222111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    ExprBits.ContainsUnexpandedParameterPack = PP;
2232111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  }
2242111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl
2252111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// getExprLoc - Return the preferred location for the arrow when diagnosing
2262111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// a problem with a generic expression.
2272111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  SourceLocation getExprLoc() const LLVM_READONLY;
2282111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl
2292111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// isUnusedResultAWarning - Return true if this immediate expression should
2302111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// be warned about if the result is unused.  If so, fill in expr, location,
2312111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// and ranges with expr to warn on and source locations/ranges appropriate
2322111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// for a warning.
2332111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  bool isUnusedResultAWarning(const Expr *&WarnExpr, SourceLocation &Loc,
2342111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl                              SourceRange &R1, SourceRange &R2,
2352111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl                              ASTContext &Ctx) const;
2362111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl
2372111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// isLValue - True if this expression is an "l-value" according to
2382111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// the rules of the current language.  C and C++ give somewhat
2392111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// different rules for this concept, but in general, the result of
2402111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// an l-value expression identifies a specific object whereas the
2412111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// result of an r-value expression is a value detached from any
2422111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// specific storage.
2432111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  ///
2442111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// C++11 divides the concept of "r-value" into pure r-values
2452111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// ("pr-values") and so-called expiring values ("x-values"), which
2462111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// identify specific objects that can be safely cannibalized for
2472111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// their resources.  This is an unfortunate abuse of terminology on
2482111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// the part of the C++ committee.  In Clang, when we say "r-value",
2492111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// we generally mean a pr-value.
2502111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  bool isLValue() const { return getValueKind() == VK_LValue; }
2512111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  bool isRValue() const { return getValueKind() == VK_RValue; }
2522111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  bool isXValue() const { return getValueKind() == VK_XValue; }
2532111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  bool isGLValue() const { return getValueKind() != VK_RValue; }
2542111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl
2552111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  enum LValueClassification {
2562111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    LV_Valid,
2572111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    LV_NotObjectType,
2582111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    LV_IncompleteVoidType,
2592111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    LV_DuplicateVectorComponents,
2602111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    LV_InvalidExpression,
2612111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    LV_InvalidMessageExpression,
2622111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    LV_MemberFunction,
2632111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    LV_SubObjCPropertySetting,
2642111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    LV_ClassTemporary,
2652111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    LV_ArrayTemporary
2662111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  };
2672111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// Reasons why an expression might not be an l-value.
2682111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  LValueClassification ClassifyLValue(ASTContext &Ctx) const;
2692111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl
2702111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  enum isModifiableLvalueResult {
2712c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor    MLV_Valid,
2722c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor    MLV_NotObjectType,
2732c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor    MLV_IncompleteVoidType,
2742c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor    MLV_DuplicateVectorComponents,
2752c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor    MLV_InvalidExpression,
2762c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor    MLV_LValueCast,           // Specialized form of MLV_InvalidExpression.
2772111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    MLV_IncompleteType,
278369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    MLV_ConstQualified,
2792111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    MLV_ArrayType,
2802111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    MLV_ReadonlyProperty,
2812111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    MLV_NoSetterProperty,
2822111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    MLV_MemberFunction,
2832111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    MLV_SubObjCPropertySetting,
2842111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    MLV_InvalidMessageExpression,
2852111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    MLV_ClassTemporary,
2862111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    MLV_ArrayTemporary
2872111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  };
2882111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type,
2892111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// does not have an incomplete type, does not have a const-qualified type,
2902111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// and if it is a structure or union, does not have any member (including,
2912111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// recursively, any member or element of all contained aggregates or unions)
2922111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// with a const-qualified type.
2932111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  ///
294369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  /// \param Loc [in,out] - A source location which *may* be filled
2952111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// in with the location of the expression making this a
2962111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// non-modifiable lvalue, if specified.
2972111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx,
2982111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl                                              SourceLocation *Loc = 0) const;
2992111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl
3002111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  /// \brief The return type of classify(). Represents the C++11 expression
3012111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  ///        taxonomy.
3022111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  class Classification {
3032111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl  public:
3042111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    /// \brief The various classification results. Most of these mean prvalue.
3052111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    enum Kinds {
306f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      CL_LValue,
307f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      CL_XValue,
308f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      CL_Function, // Functions cannot be lvalues in C.
309f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      CL_Void, // Void cannot be an lvalue in C.
3100943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall      CL_AddressableVoid, // Void expression whose address can be taken in C.
3110943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall      CL_DuplicateVectorComponents, // A vector shuffle with dupes.
3120943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall      CL_MemberFunction, // An expression referring to a member function
3130943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall      CL_SubObjCPropertySetting,
314f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      CL_ClassTemporary, // A temporary of class type, or subobject thereof.
315f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      CL_ArrayTemporary, // A temporary of array type.
316f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      CL_ObjCMessageRValue, // ObjC message is an rvalue
317f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      CL_PRValue // A prvalue for any other reason, of any other type
318f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    };
319f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    /// \brief The results of modification testing.
320f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    enum ModifiableType {
321f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      CM_Untested, // testModifiable was false.
322f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      CM_Modifiable,
323f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      CM_RValue, // Not modifiable because it's an rvalue
324f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      CM_Function, // Not modifiable because it's a function; C++ only
325f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      CM_LValueCast, // Same as CM_RValue, but indicates GCC cast-as-lvalue ext
326f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      CM_NoSetterProperty,// Implicit assignment to ObjC property without setter
327f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      CM_ConstQualified,
328f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      CM_ArrayType,
329f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      CM_IncompleteType
330f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    };
331f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall
332f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  private:
333f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    friend class Expr;
334f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall
3352111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    unsigned short Kind;
3362111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    unsigned short Modifiable;
3372111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl
3382111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl    explicit Classification(Kinds k, ModifiableType m)
3392111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl      : Kind(k), Modifiable(m)
34033bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor    {}
34133bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor
34233bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor  public:
3435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Classification() {}
34438d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson
34538d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson    Kinds getKind() const { return static_cast<Kinds>(Kind); }
34638d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson    ModifiableType getModifiable() const {
3471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      assert(Modifiable != CM_Untested && "Did not test for modifiability.");
348f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall      return static_cast<ModifiableType>(Modifiable);
349f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall    }
350f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall    bool isLValue() const { return Kind == CL_LValue; }
351f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall    bool isXValue() const { return Kind == CL_XValue; }
352093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson    bool isGLValue() const { return Kind <= CL_XValue; }
353093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson    bool isPRValue() const { return Kind >= CL_Function; }
354c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    bool isRValue() const { return Kind >= CL_XValue; }
3552b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner    bool isModifiable() const { return getModifiable() == CM_Modifiable; }
3562b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner
3572b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner    /// \brief Create a simple, modifiably lvalue
3582b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner    static Classification makeSimpleLValue() {
3592b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner      return Classification(CL_LValue, CM_Modifiable);
360c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    }
3615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
3635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// \brief Classify - Classify this expression according to the C++11
3645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///        expression taxonomy.
365590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner  ///
366590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner  /// C++11 defines ([basic.lval]) a new taxonomy of expressions to replace the
3675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// old lvalue vs rvalue. This function determines the type of expression this
368590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner  /// is. There are three expression types:
3698070a8497c0fb3e6f70a557f788405d8945b1208Daniel Dunbar  /// - lvalues are classical lvalues as in C++03.
370590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner  /// - prvalues are equivalent to rvalues in C++03.
3715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// - xvalues are expressions yielding unnamed rvalue references, e.g. a
372c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman  ///   function returning an rvalue reference.
373c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman  /// lvalues and xvalues are collectively referred to as glvalues, while
3744204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall  /// prvalues and xvalues together form rvalues.
3751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Classification Classify(ASTContext &Ctx) const {
37694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    return ClassifyImpl(Ctx, 0);
37794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  }
3782d6744ff04c1690a1485178d550d2fab84a0270bDaniel Dunbar
37994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  /// \brief ClassifyModifiable - Classify this expression according to the
3801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///        C++11 expression taxonomy, and see if it is valid on the left side
38194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  ///        of an assignment.
38294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  ///
38394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  /// This function extends classify in that it also tests whether the
3841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// expression is modifiable (C99 6.3.2.1p1).
38594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  /// \param Loc A source location that might be filled with a relevant location
38694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  ///            if the expression is not modifiable.
38794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  Classification ClassifyModifiable(ASTContext &Ctx, SourceLocation &Loc) const{
38894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    return ClassifyImpl(Ctx, &Loc);
38994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  }
39094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson
39194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  /// getValueKindForType - Given a formal return or parameter type,
39294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  /// give its value kind.
39394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  static ExprValueKind getValueKindForType(QualType T) {
39494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson    if (const ReferenceType *RT = T->getAs<ReferenceType>())
39594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson      return (isa<LValueReferenceType>(RT)
3961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                ? VK_LValue
39794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson                : (RT->getPointeeType()->isFunctionType()
398e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara                     ? VK_LValue : VK_XValue));
399e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara    return VK_RValue;
400e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara  }
401e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara
402e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara  /// getValueKind - The value kind that this expression produces.
403e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara  ExprValueKind getValueKind() const {
404e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara    return static_cast<ExprValueKind>(ExprBits.ValueKind);
405e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara  }
406e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara
40794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  /// getObjectKind - The object kind that this expression produces.
40894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson  /// Object kinds are meaningful only for expressions that yield an
4096ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner  /// l-value or x-value.
410019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner  ExprObjectKind getObjectKind() const {
411019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner    return static_cast<ExprObjectKind>(ExprBits.ObjectKind);
412019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner  }
4134ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad
4145b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson  bool isOrdinaryOrBitFieldObject() const {
415cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall    ExprObjectKind OK = getObjectKind();
416cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall    return (OK == OK_Ordinary || OK == OK_BitField);
417cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall  }
4184ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad
419cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall  /// setValueKind - Set the value kind produced by this expression.
4206ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner  void setValueKind(ExprValueKind Cat) { ExprBits.ValueKind = Cat; }
42145b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner
4224ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  /// setObjectKind - Set the object kind produced by this expression.
423c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson  void setObjectKind(ExprObjectKind Cat) { ExprBits.ObjectKind = Cat; }
4246ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian
425138d6a6890c171068ac60430431eaadb3fcef9abGabor Greifprivate:
4266ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian  Classification ClassifyImpl(ASTContext &Ctx, SourceLocation *Loc) const;
4276ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian
4284ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadpublic:
429c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
43051fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson  /// \brief Returns true if this expression is a gl-value that
43151fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson  /// potentially refers to a bit-field.
4324ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  ///
43351fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson  /// In C++, whether a gl-value refers to a bitfield is essentially
434b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman  /// an aspect of the value-kind type system.
435b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman  bool refersToBitField() const { return getObjectKind() == OK_BitField; }
4364ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad
4371b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson  /// \brief If this expression refers to a bit-field, retrieve the
438e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara  /// declaration of that bit-field.
4394ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  ///
440e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara  /// Note that this returns a non-null pointer in subtly different
441ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  /// places than refersToBitField returns true.  In particular, this can
442ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  /// return a non-null pointer even for r-values loaded from
443ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  /// bit-fields, but it will return null for a conditional bit-field.
444ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  FieldDecl *getSourceBitField();
445ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor
446c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  const FieldDecl *getSourceBitField() const {
447ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor    return const_cast<Expr*>(this)->getSourceBitField();
448ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  }
449ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor
450c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  /// \brief If this expression is an l-value for an Objective C
451ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  /// property, find the underlying property reference expression.
452ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  const ObjCPropertyRefExpr *getObjCProperty() const;
453ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor
454ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  /// \brief Check if this expression is the ObjC 'self' implicit parameter.
455c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  bool isObjCSelfExpr() const;
456efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson
457efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson  /// \brief Returns whether this expression refers to a vector element.
458efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson  bool refersToVectorElement() const;
459ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor
460ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor  /// \brief Returns whether this expression has a placeholder type.
461efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson  bool hasPlaceholderType() const {
46244baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian    return getType()->isPlaceholderType();
4631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
464102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian
4651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Returns whether this expression has a specific placeholder type.
46611ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis  bool hasPlaceholderType(BuiltinType::Kind K) const {
46711ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis    assert(BuiltinType::isPlaceholderTypeKind(K));
46811ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis    if (const BuiltinType *BT = dyn_cast<BuiltinType>(getType()))
469369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl      return BT->getKind() == K;
470369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl    return false;
471369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  }
472369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl
473369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  /// isKnownToHaveBooleanValue - Return true if this is an integer expression
474369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  /// that is known to return 0 or 1.  This happens for _Bool/bool expressions
475369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  /// but also int expressions which are produced by things like comparisons in
476369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  /// C.
477369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl  bool isKnownToHaveBooleanValue() const;
478369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl
4794e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  /// isIntegerConstantExpr - Return true if this expression is a valid integer
4801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// constant expression, and, if so, return its value in Result.  If not a
4814e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  /// valid i-c-e, return false and fill in Loc (if specified) with the location
4824e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  /// of the invalid expression.
4832b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner  ///
48456f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  /// Note: This does not perform the implicit conversions required by C++11
48556f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  /// [expr.const]p5.
48627c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor  bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
48756f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner                             SourceLocation *Loc = 0,
4881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                             bool isEvaluated = true) const;
4892fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall  bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const;
4902fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall
4912fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall  /// isCXX98IntegralConstantExpr - Return true if this expression is an
4922fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall  /// integral constant expression in C++98. Can only be used in C++.
4934d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek  bool isCXX98IntegralConstantExpr(ASTContext &Ctx) const;
4944d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek
4954d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek  /// isCXX11ConstantExpr - Return true if this expression is a constant
496f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall  /// expression in C++11. Can only be used in C++.
497f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall  ///
498f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall  /// Note: This does not perform the implicit conversions required by C++11
499f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall  /// [expr.const]p5.
500f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall  bool isCXX11ConstantExpr(ASTContext &Ctx, APValue *Result = 0,
501f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall                           SourceLocation *Loc = 0) const;
502f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall
503f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall  /// isPotentialConstantExpr - Return true if this function's definition
5044d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek  /// might be usable in a constant expression in C++11, if it were marked
505ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  /// constexpr. Return false if the function can never produce a constant
506ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  /// expression, along with diagnostics describing why not.
507ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner  static bool isPotentialConstantExpr(const FunctionDecl *FD,
508ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner                                      SmallVectorImpl<
5091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                        PartialDiagnosticAt> &Diags);
5106eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor
5116eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// isConstantInitializer - Returns true if this expression can be emitted to
5126eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// IR as a constant, and thus can be used as a constant initializer in C.
513c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  bool isConstantInitializer(ASTContext &Ctx, bool ForRef) const;
5146eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor
5156eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// EvalStatus is a struct with detailed info about an evaluation in progress.
5166eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  struct EvalStatus {
5176eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    /// HasSideEffects - Whether the evaluated expression has side effects.
518c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    /// For example, (f() && 0) can be folded, but it still has side effects.
519558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall    bool HasSideEffects;
520558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall
521558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall    /// Diag - If this is non-null, it will be filled in with a stack of notes
5222f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor    /// indicating why evaluation failed (or why it failed to produce a constant
5232b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner    /// expression).
5244e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek    /// If the expression is unfoldable, the notes will indicate why it's not
5254e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek    /// foldable. If the expression is foldable, but not a constant expression,
52656f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner    /// the notes will describes why it isn't a constant expression. If the
52756f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner    /// expression *is* a constant expression, no notes will be produced.
52856f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner    SmallVectorImpl<PartialDiagnosticAt> *Diag;
529ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner
530ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner    EvalStatus() : HasSideEffects(false), Diag(0) {}
531ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner
5321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    // hasSideEffects - Return true if the evaluated expression has
533898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    // side effects.
534898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    bool hasSideEffects() const {
535898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor      return HasSideEffects;
5361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    }
5375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
5381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// EvalResult is a struct with detailed info about an evaluated expression.
5405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  struct EvalResult : EvalStatus {
5415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    /// Val - This is the value the expression can be folded to.
5425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    APValue Val;
5431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5445549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    // isGlobalLValue - Return true if the evaluated lvalue expression
5455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // is global.
5465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    bool isGlobalLValue() const;
5475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
548a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
549a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// EvaluateAsRValue - Return true if this is a constant which we can fold to
550a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// an rvalue using any crazy technique (that has nothing to do with language
551a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// standards) that we want to, even if the expression has side-effects. If
552a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// this function returns true, it returns the folded constant in Result. If
553c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  /// the expression is a glvalue, an lvalue-to-rvalue conversion will be
554a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// applied.
555a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  bool EvaluateAsRValue(EvalResult &Result, const ASTContext &Ctx) const;
556a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
557a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// EvaluateAsBooleanCondition - Return true if this is a constant
558a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// which we we can fold and convert to a boolean condition using
559a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// any crazy technique that we want to, even if the expression has
560a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// side-effects.
561a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  bool EvaluateAsBooleanCondition(bool &Result, const ASTContext &Ctx) const;
562a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
563c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  enum SideEffectsKind { SE_NoSideEffects, SE_AllowSideEffects };
564a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
565a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// EvaluateAsInt - Return true if this is a constant which we can fold and
566c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  /// convert to an integer, using any crazy technique that we want to.
567a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  bool EvaluateAsInt(llvm::APSInt &Result, const ASTContext &Ctx,
568a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor                     SideEffectsKind AllowSideEffects = SE_NoSideEffects) const;
569a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
570a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// isEvaluatable - Call EvaluateAsRValue to see if this expression can be
571c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  /// constant folded without side-effects, but discard the result.
572a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  bool isEvaluatable(const ASTContext &Ctx) const;
573833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
574833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  /// HasSideEffects - This routine returns true for all those expressions
575a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// which have any effect other than producing a value. Example is a function
576c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  /// call, volatile variable read, or throwing an exception.
577a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  bool HasSideEffects(const ASTContext &Ctx) const;
578833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
579833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  /// \brief Determine whether this expression involves a call to any function
580a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// that is not trivial.
581d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  bool hasNonTrivialCall(ASTContext &Ctx);
582d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
583bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  /// EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded
584bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  /// integer. This must be called on an expression that constant folds to an
585d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  /// integer.
5868dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis  llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx,
587d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                          SmallVectorImpl<PartialDiagnosticAt> *Diag=0) const;
588a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
589c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  void EvaluateForOverflow(const ASTContext &Ctx,
5905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                           SmallVectorImpl<PartialDiagnosticAt> *Diag) const;
5915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// EvaluateAsLValue - Evaluate an expression to see if we can fold it to an
593a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// lvalue with link time known address, with no side-effects.
594c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  bool EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx) const;
595a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
596a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// EvaluateAsInitializer - Evaluate an expression as if it were the
597c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  /// initializer of the given declaration. Returns true if the initializer
598a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// can be folded to a constant, and produces any relevant notes. In C++11,
599a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// notes will be produced if the expression is not a constant expression.
600a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  bool EvaluateAsInitializer(APValue &Result, const ASTContext &Ctx,
601c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                             const VarDecl *VD,
602c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt                             SmallVectorImpl<PartialDiagnosticAt> &Notes) const;
603a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
604c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  /// \brief Enumeration used to describe the kind of Null pointer constant
605a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// returned from \c isNullPointerConstant().
606dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  enum NullPointerConstantKind {
6072577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    /// \brief Expression is not a Null pointer constant.
608a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    NPCK_NotNull = 0,
6095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6109e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis    /// \brief Expression is a Null pointer constant built from a zero integer
6112577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    /// expression that is not a simple, possibly parenthesized, zero literal.
6122577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    /// C++ Core Issue 903 will classify these expressions as "not pointers"
6132577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    /// once it is adopted.
6142577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    /// http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#903
615a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    NPCK_ZeroExpression,
616a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
6172cf719c3c3d805f630dfc6b1255e52647820888eSebastian Redl    /// \brief Expression is a Null pointer constant built from a literal zero.
618a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    NPCK_ZeroLiteral,
619c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
620a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    /// \brief Expression is a C++11 nullptr.
621a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    NPCK_CXX11_nullptr,
622c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
623a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    /// \brief Expression is a GNU-style __null constant.
624a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    NPCK_GNUNull
625a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  };
626a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
627096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// \brief Enumeration used to describe how \c isNullPointerConstant()
628a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// should cope with value-dependent expressions.
629dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  enum NullPointerConstantValueDependence {
630d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    /// \brief Specifies that the expression should never be value-dependent.
631f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    NPC_NeverValueDependent = 0,
632663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis
6332577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    /// \brief Specifies that a value-dependent expression of integral or
6342577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    /// dependent type should be considered a null pointer constant.
6352577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    NPC_ValueDependentIsNull,
636f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall
6372577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    /// \brief Specifies that a value-dependent expression should be considered
638663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis    /// to never be a null pointer constant.
639663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis    NPC_ValueDependentIsNotNull
640663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis  };
641c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
6420da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  /// isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to
6430da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  /// a Null pointer constant. The return value can further distinguish the
6440da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  /// kind of NULL pointer constant that was detected.
6459e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis  NullPointerConstantKind isNullPointerConstant(
6465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      ASTContext &Ctx,
647f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall      NullPointerConstantValueDependence NPC) const;
648bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor
649f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  /// isOBJCGCCandidate - Return true if this expression may be used in a read/
6500da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  /// write barrier.
6510da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  bool isOBJCGCCandidate(ASTContext &Ctx) const;
6521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
653a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief Returns true if this expression is a bound member function.
654a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  bool isBoundMemberFunction(ASTContext &Ctx) const;
655a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
656dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  /// \brief Given an expression of bound-member type, find the type
657a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// of the member.  Returns null if this is an *overloaded* bound
658f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  /// member expression.
6590da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor  static QualType findBoundMemberType(const Expr *expr);
660663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis
6612577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// IgnoreImpCasts - Skip past any implicit casts which might
6622577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// surround this expression.  Only skips ImplicitCastExprs.
6632577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  Expr *IgnoreImpCasts() LLVM_READONLY;
6642577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
6652577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  /// IgnoreImplicit - Skip past any implicit AST nodes which might
666f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  /// surround this expression.
6672577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  Expr *IgnoreImplicit() LLVM_READONLY {
6682577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    return cast<Expr>(Stmt::IgnoreImplicit());
669663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis  }
670663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis
671663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis  const Expr *IgnoreImplicit() const LLVM_READONLY {
672c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return const_cast<Expr*>(this)->IgnoreImplicit();
673dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  }
674dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall
675dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall  /// IgnoreParens - Ignore parentheses.  If this Expr is a ParenExpr, return
676904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor  ///  its subexpression.  If that subexpression is also a ParenExpr,
6772577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  ///  then this method recursively returns its subexpression, and so forth.
6782577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  ///  Otherwise, the method returns the current Expr.
6792577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  Expr *IgnoreParens() LLVM_READONLY;
6802577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
6819e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis  /// IgnoreParenCasts - Ignore parentheses and casts.  Strip off any ParenExpr
6820b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  /// or CastExprs, returning their operand.
683a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  Expr *IgnoreParenCasts() LLVM_READONLY;
6841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
685a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// IgnoreParenImpCasts - Ignore parentheses and implicit casts.  Strip off
686a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// any ParenExpr or ImplicitCastExprs, returning their operand.
687a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  Expr *IgnoreParenImpCasts() LLVM_READONLY;
688c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
689a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// IgnoreConversionOperator - Ignore conversion operator. If this Expr is a
690a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// call to a conversion operator, return the argument.
691a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  Expr *IgnoreConversionOperator() LLVM_READONLY;
692a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
693a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  const Expr *IgnoreConversionOperator() const LLVM_READONLY {
694a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return const_cast<Expr*>(this)->IgnoreConversionOperator();
695c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  }
696a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
697a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  const Expr *IgnoreParenImpCasts() const LLVM_READONLY {
698c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return const_cast<Expr*>(this)->IgnoreParenImpCasts();
699c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  }
700a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
701a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// Ignore parentheses and lvalue casts.  Strip off any ParenExpr and
702a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// CastExprs that represent lvalue casts, returning their operand.
703a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  Expr *IgnoreParenLValueCasts() LLVM_READONLY;
704c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
705a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  const Expr *IgnoreParenLValueCasts() const LLVM_READONLY {
706a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return const_cast<Expr*>(this)->IgnoreParenLValueCasts();
707c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  }
708096832c5ed5b9106fa177ebc148489760c3bc496John McCall
709096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the
710096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// value (including ptr->int casts of the same size).  Strip off any
711096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// ParenExpr or CastExprs, returning their operand.
712096832c5ed5b9106fa177ebc148489760c3bc496John McCall  Expr *IgnoreParenNoopCasts(ASTContext &Ctx) LLVM_READONLY;
713096832c5ed5b9106fa177ebc148489760c3bc496John McCall
714096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// Ignore parentheses and derived-to-base casts.
715096832c5ed5b9106fa177ebc148489760c3bc496John McCall  Expr *ignoreParenBaseCasts() LLVM_READONLY;
716096832c5ed5b9106fa177ebc148489760c3bc496John McCall
717096832c5ed5b9106fa177ebc148489760c3bc496John McCall  const Expr *ignoreParenBaseCasts() const LLVM_READONLY {
718096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return const_cast<Expr*>(this)->ignoreParenBaseCasts();
719096832c5ed5b9106fa177ebc148489760c3bc496John McCall  }
720096832c5ed5b9106fa177ebc148489760c3bc496John McCall
721096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// \brief Determine whether this expression is a default function argument.
722096832c5ed5b9106fa177ebc148489760c3bc496John McCall  ///
723096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// Default arguments are implicitly generated in the abstract syntax tree
724096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// by semantic analysis for function calls, object constructions, etc. in
725096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// C++. Default arguments are represented by \c CXXDefaultArgExpr nodes;
726096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// this routine also looks through any implicit casts to determine whether
727096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// the expression is a default argument.
728a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  bool isDefaultArgument() const;
729d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
730096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// \brief Determine whether the result of this expression is a
731096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// temporary object of the given class type.
732096832c5ed5b9106fa177ebc148489760c3bc496John McCall  bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const;
733096832c5ed5b9106fa177ebc148489760c3bc496John McCall
734096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// \brief Whether this expression is an implicit reference to 'this' in C++.
735096832c5ed5b9106fa177ebc148489760c3bc496John McCall  bool isImplicitCXXThis() const;
736096832c5ed5b9106fa177ebc148489760c3bc496John McCall
737096832c5ed5b9106fa177ebc148489760c3bc496John McCall  const Expr *IgnoreImpCasts() const LLVM_READONLY {
738d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    return const_cast<Expr*>(this)->IgnoreImpCasts();
739d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  }
740d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  const Expr *IgnoreParens() const LLVM_READONLY {
741096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return const_cast<Expr*>(this)->IgnoreParens();
742096832c5ed5b9106fa177ebc148489760c3bc496John McCall  }
743d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  const Expr *IgnoreParenCasts() const LLVM_READONLY {
744c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    return const_cast<Expr*>(this)->IgnoreParenCasts();
745a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
746a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  const Expr *IgnoreParenNoopCasts(ASTContext &Ctx) const LLVM_READONLY {
747a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return const_cast<Expr*>(this)->IgnoreParenNoopCasts(Ctx);
748096832c5ed5b9106fa177ebc148489760c3bc496John McCall  }
749a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
750c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  static bool hasAnyTypeDependentArguments(ArrayRef<Expr *> Exprs);
751096832c5ed5b9106fa177ebc148489760c3bc496John McCall
752a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// \brief For an expression of class type or pointer to class type,
753c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  /// return the most derived class decl the expression is known to refer to.
754a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  ///
755a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// If this expression is a cast, this method looks through it to find the
756833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  /// most derived decl that can be inferred from the expression.
757096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// This is valid because derived-to-base conversions have undefined
758a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// behavior if the object isn't dynamically of the derived type.
759c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  const CXXRecordDecl *getBestDynamicClassType() const;
760096832c5ed5b9106fa177ebc148489760c3bc496John McCall
761a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// Walk outwards from an expression we want to bind a reference to and
762c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  /// find the expression whose lifetime needs to be extended. Record
763a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  /// the LHSs of comma expressions and adjustments needed along the path.
764a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  const Expr *skipRValueSubobjectAdjustments(
765a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor      SmallVectorImpl<const Expr *> &CommaLHS,
766096832c5ed5b9106fa177ebc148489760c3bc496John McCall      SmallVectorImpl<SubobjectAdjustment> &Adjustments) const;
767a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
768c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  /// Skip irrelevant expressions to find what should be materialize for
769096832c5ed5b9106fa177ebc148489760c3bc496John McCall  /// binding with a reference.
770a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  const Expr *
771c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  findMaterializedTemporary(const MaterializeTemporaryExpr *&MTE) const;
772a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
773a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  static bool classof(const Stmt *T) {
774a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor    return T->getStmtClass() >= firstExprConstant &&
775096832c5ed5b9106fa177ebc148489760c3bc496John McCall           T->getStmtClass() <= lastExprConstant;
776a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor  }
777c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt};
778096832c5ed5b9106fa177ebc148489760c3bc496John McCall
779a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor
780c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt//===----------------------------------------------------------------------===//
7811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump// Primary Expressions.
78299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor//===----------------------------------------------------------------------===//
7835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// OpaqueValueExpr - An expression referring to an opaque object of a
7851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// fixed type and value class.  These don't correspond to concrete
78677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek/// syntax; instead they're used to express operations (usually copy
78777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek/// operations) on values whose source is generally obvious from
78877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek/// context.
789663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidisclass OpaqueValueExpr : public Expr {
79060adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl  friend class ASTStmtReader;
7913397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl  Expr *SourceExpr;
7925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation Loc;
7935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
794d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattnerpublic:
795d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner  OpaqueValueExpr(SourceLocation Loc, QualType T, ExprValueKind VK,
796227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson                  ExprObjectKind OK = OK_Ordinary,
797227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson                  Expr *SourceExpr = 0)
798227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson    : Expr(OpaqueValueExprClass, T, VK, OK,
799227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson           T->isDependentType(),
800848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson           T->isDependentType() ||
801848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson           (SourceExpr && SourceExpr->isValueDependent()),
802848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson           T->isInstantiationDependentType(),
803848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson           false),
804227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson      SourceExpr(SourceExpr), Loc(Loc) {
8051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
806227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson
807227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  /// Given an expression which invokes a copy constructor --- i.e.  a
808227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  /// CXXConstructExpr, possibly wrapped in an ExprWithCleanups ---
809227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  /// find the OpaqueValueExpr that's the source of the construction.
8101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static const OpaqueValueExpr *findInCopyConstruct(const Expr *expr);
811f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall
812bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  explicit OpaqueValueExpr(EmptyShell Empty)
813bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    : Expr(OpaqueValueExprClass, Empty) { }
814f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall
8151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Retrieve the location of this expression.
81617fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  SourceLocation getLocation() const { return Loc; }
8171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
81817fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  SourceLocation getLocStart() const LLVM_READONLY {
81917fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor    return SourceExpr ? SourceExpr->getLocStart() : Loc;
820227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  }
82117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  SourceLocation getLocEnd() const LLVM_READONLY {
82217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor    return SourceExpr ? SourceExpr->getLocEnd() : Loc;
82317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  }
82417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  SourceLocation getExprLoc() const LLVM_READONLY {
82517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor    if (SourceExpr) return SourceExpr->getExprLoc();
826848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson    return Loc;
8273a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson  }
828227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson
829227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  child_range children() { return child_range(); }
8301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// The source expression of an opaque value expression is the
832227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  /// expression which originally generated the value.  This is
833d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner  /// provided as a convenience for analyses that don't wish to
8341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// precisely model the execution behavior of the program.
83577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  ///
83677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  /// The source expression is typically set when building the
83777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  /// expression which binds the opaque value expression in the first
838227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  /// place.
839227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson  Expr *getSourceExpr() const { return SourceExpr; }
8409996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
8419996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  static bool classof(const Stmt *T) {
8429996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    return T->getStmtClass() == OpaqueValueExprClass;
8439996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  }
8449996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis};
8459996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
8469996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// \brief A reference to a declared variable, function, enum, etc.
8479996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// [C99 6.5.1p2]
8489996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis///
8499996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// This encodes all the information about how a declaration is referenced
8509996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// within an expression.
8519996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis///
8529996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// There are several optional constructs attached to DeclRefExprs only when
8539996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// they apply in order to conserve memory. These are laid out past the end of
8549996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// the object, and flags in the DeclRefExprBitfield track whether they exist:
8559996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis///
8569996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis///   DeclRefExprBits.HasQualifier:
8579996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis///       Specifies when this declaration reference expression has a C++
8589996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis///       nested-name-specifier.
8599996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis///   DeclRefExprBits.HasFoundDecl:
8609996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis///       Specifies when this declaration reference expression has a record of
8619996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis///       a NamedDecl (different from the referenced ValueDecl) which was found
8629996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis///       during name lookup and/or overload resolution.
8639996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis///   DeclRefExprBits.HasTemplateKWAndArgsInfo:
8649996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis///       Specifies when this declaration reference expression has an explicit
8659996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis///       C++ template keyword and/or template argument list.
8669996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis///   DeclRefExprBits.RefersToEnclosingLocal
8679996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis///       Specifies when this declaration reference expression (validly)
8689996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis///       refers to a local variable from a different function.
8699996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisclass DeclRefExpr : public Expr {
8709996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  /// \brief The declaration that we are referencing.
8719996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  ValueDecl *D;
8729996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
8739996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  /// \brief The location of the declaration name itself.
8749996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  SourceLocation Loc;
8759996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
8769996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  /// \brief Provides source/type location info for the declaration name
8779996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  /// embedded in D.
8789996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  DeclarationNameLoc DNLoc;
8799996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
8809996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  /// \brief Helper to retrieve the optional NestedNameSpecifierLoc.
8819996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  NestedNameSpecifierLoc &getInternalQualifierLoc() {
8829996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    assert(hasQualifier());
8839996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    return *reinterpret_cast<NestedNameSpecifierLoc *>(this + 1);
8849996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  }
8859996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
8869996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  /// \brief Helper to retrieve the optional NestedNameSpecifierLoc.
8875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const NestedNameSpecifierLoc &getInternalQualifierLoc() const {
8889996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    return const_cast<DeclRefExpr *>(this)->getInternalQualifierLoc();
8895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
8909996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
8919996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  /// \brief Test whether there is a distinct FoundDecl attached to the end of
8929996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  /// this DRE.
8939996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  bool hasFoundDecl() const { return DeclRefExprBits.HasFoundDecl; }
8949996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
8955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// \brief Helper to retrieve the optional NamedDecl through which this
8961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// reference occured.
8975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  NamedDecl *&getInternalFoundDecl() {
8989996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    assert(hasFoundDecl());
8999996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    if (hasQualifier())
900bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor      return *reinterpret_cast<NamedDecl **>(&getInternalQualifierLoc() + 1);
901bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    return *reinterpret_cast<NamedDecl **>(this + 1);
902f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  }
9035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9049996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  /// \brief Helper to retrieve the optional NamedDecl through which this
9055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// reference occured.
906a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson  NamedDecl *getInternalFoundDecl() const {
9079996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    return const_cast<DeclRefExpr *>(this)->getInternalFoundDecl();
9089996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  }
9099996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
9109996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  DeclRefExpr(ASTContext &Ctx,
9119996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis              NestedNameSpecifierLoc QualifierLoc,
9120b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor              SourceLocation TemplateKWLoc,
9139996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis              ValueDecl *D, bool refersToEnclosingLocal,
9145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer              const DeclarationNameInfo &NameInfo,
9155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer              NamedDecl *FoundD,
916313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor              const TemplateArgumentListInfo *TemplateArgs,
917313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor              QualType T, ExprValueKind VK);
918313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor
9199996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  /// \brief Construct an empty declaration reference expression.
9200b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor  explicit DeclRefExpr(EmptyShell Empty)
9210b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor    : Expr(DeclRefExprClass, Empty) { }
9221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Computes the type- and value-dependence flags for this
9245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// declaration reference expression.
9255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void computeDependence(ASTContext &C);
9261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
92777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenekpublic:
92877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  DeclRefExpr(ValueDecl *D, bool refersToEnclosingLocal, QualType T,
92977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek              ExprValueKind VK, SourceLocation L,
9305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer              const DeclarationNameLoc &LocInfo = DeclarationNameLoc())
9315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    : Expr(DeclRefExprClass, T, VK, OK_Ordinary, false, false, false, false),
9325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      D(D), Loc(L), DNLoc(LocInfo) {
9335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    DeclRefExprBits.HasQualifier = 0;
9345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    DeclRefExprBits.HasTemplateKWAndArgsInfo = 0;
935c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner    DeclRefExprBits.HasFoundDecl = 0;
9365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    DeclRefExprBits.HadMultipleCandidates = 0;
9375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    DeclRefExprBits.RefersToEnclosingLocal = refersToEnclosingLocal;
938c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner    computeDependence(D->getASTContext());
939bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  }
940bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor
941f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  static DeclRefExpr *Create(ASTContext &Context,
9425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                             NestedNameSpecifierLoc QualifierLoc,
9430b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor                             SourceLocation TemplateKWLoc,
9440b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor                             ValueDecl *D,
9450b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor                             bool isEnclosingLocal,
9460b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor                             SourceLocation NameLoc,
947018d8e0596dd57401eeddcf11ac84ff0a065fbbeChris Lattner                             QualType T, ExprValueKind VK,
948c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner                             NamedDecl *FoundD = 0,
9491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                             const TemplateArgumentListInfo *TemplateArgs = 0);
9505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static DeclRefExpr *Create(ASTContext &Context,
9525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                             NestedNameSpecifierLoc QualifierLoc,
9535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                             SourceLocation TemplateKWLoc,
9540b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor                             ValueDecl *D,
9550b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor                             bool isEnclosingLocal,
9560b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor                             const DeclarationNameInfo &NameInfo,
9570b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor                             QualType T, ExprValueKind VK,
9581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                             NamedDecl *FoundD = 0,
9591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                             const TemplateArgumentListInfo *TemplateArgs = 0);
9605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// \brief Construct an empty declaration reference expression.
96277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  static DeclRefExpr *CreateEmpty(ASTContext &Context,
96377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek                                  bool HasQualifier,
96477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek                                  bool HasFoundDecl,
96577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek                                  bool HasTemplateKWAndArgsInfo,
9665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                                  unsigned NumTemplateArgs);
9675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ValueDecl *getDecl() { return D; }
9699996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  const ValueDecl *getDecl() const { return D; }
970720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek  void setDecl(ValueDecl *NewD) { D = NewD; }
9715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9729996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  DeclarationNameInfo getNameInfo() const {
9739996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    return DeclarationNameInfo(getDecl()->getDeclName(), Loc, DNLoc);
974720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek  }
975bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor
976bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  SourceLocation getLocation() const { return Loc; }
9779996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  void setLocation(SourceLocation L) { Loc = L; }
9789996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  SourceLocation getLocStart() const LLVM_READONLY;
9799996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  SourceLocation getLocEnd() const LLVM_READONLY;
9805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
98117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  /// \brief Determine whether this declaration reference was preceded by a
9821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// C++ nested-name-specifier, e.g., \c N::foo.
9839996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  bool hasQualifier() const { return DeclRefExprBits.HasQualifier; }
98417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
9859996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  /// \brief If the name was qualified, retrieves the nested-name-specifier
9869996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  /// that precedes the name. Otherwise, returns NULL.
9879996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  NestedNameSpecifier *getQualifier() const {
9889996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    if (!hasQualifier())
9899996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis      return 0;
9909996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
9919996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis    return getInternalQualifierLoc().getNestedNameSpecifier();
9929996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis  }
9939996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis
99417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  /// \brief If the name was qualified, retrieves the nested-name-specifier
995720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek  /// that precedes the name, with source-location information.
99617fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  NestedNameSpecifierLoc getQualifierLoc() const {
997c9bec4bfea9090a08dd83a7b213f0c8adf8d78ecChris Lattner    if (!hasQualifier())
998da8249e57f3badecf925571881fe57243935c6c1Chris Lattner      return NestedNameSpecifierLoc();
999da8249e57f3badecf925571881fe57243935c6c1Chris Lattner
1000da8249e57f3badecf925571881fe57243935c6c1Chris Lattner    return getInternalQualifierLoc();
1001da8249e57f3badecf925571881fe57243935c6c1Chris Lattner  }
10021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
100317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  /// \brief Get the NamedDecl through which this reference occured.
100417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  ///
100517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  /// This Decl may be different from the ValueDecl actually referred to in the
10065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// presence of using declarations, etc. It always returns non-NULL, and may
10075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// simple return the ValueDecl when appropriate.
10081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  NamedDecl *getFoundDecl() {
10091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return hasFoundDecl() ? getInternalFoundDecl() : D;
10105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
10115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Get the NamedDecl through which this reference occurred.
101377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  /// See non-const variant.
101477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  const NamedDecl *getFoundDecl() const {
101577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek    return hasFoundDecl() ? getInternalFoundDecl() : D;
10165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
10175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10185d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  bool hasTemplateKWAndArgsInfo() const {
10195d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner    return DeclRefExprBits.HasTemplateKWAndArgsInfo;
10205d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  }
10215d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner
10225d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  /// \brief Return the optional template keyword and arguments info.
10235d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() {
10245549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    if (!hasTemplateKWAndArgsInfo())
10255d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner      return 0;
10265d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner
1027bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    if (hasFoundDecl())
1028bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor      return reinterpret_cast<ASTTemplateKWAndArgsInfo *>(
1029f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall        &getInternalFoundDecl() + 1);
10301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1031cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor    if (hasQualifier())
10321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      return reinterpret_cast<ASTTemplateKWAndArgsInfo *>(
1033cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor        &getInternalQualifierLoc() + 1);
1034cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
10355549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return reinterpret_cast<ASTTemplateKWAndArgsInfo *>(this + 1);
10365549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  }
1037cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
1038cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  /// \brief Return the optional template keyword and arguments info.
10395d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
10401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return const_cast<DeclRefExpr*>(this)->getTemplateKWAndArgsInfo();
10411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
10425d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner
10435d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  /// \brief Retrieve the location of the template keyword preceding
10441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// this name, if any.
10455d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  SourceLocation getTemplateKeywordLoc() const {
10465d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner    if (!hasTemplateKWAndArgsInfo()) return SourceLocation();
10475d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner    return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
10485d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner  }
10495d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner
1050e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek  /// \brief Retrieve the location of the left angle bracket starting the
1051e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek  /// explicit template argument list following the name, if any.
1052e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek  SourceLocation getLAngleLoc() const {
1053a7ad98ff0919d6a24ea7c46634ea29bea551c1a0Chris Lattner    if (!hasTemplateKWAndArgsInfo()) return SourceLocation();
1054c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner    return getTemplateKWAndArgsInfo()->LAngleLoc;
1055c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner  }
1056690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner
1057690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner  /// \brief Retrieve the location of the right angle bracket ending the
10588bea7c0ee44c71c817de7dc2be932b73bec90c9fChris Lattner  /// explicit template argument list following the name, if any.
1059690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner  SourceLocation getRAngleLoc() const {
1060c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner    if (!hasTemplateKWAndArgsInfo()) return SourceLocation();
1061c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner    return getTemplateKWAndArgsInfo()->RAngleLoc;
1062c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner  }
1063c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner
1064c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner  /// \brief Determines whether the name in this declaration reference
1065c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner  /// was preceded by the template keyword.
10665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
10675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// \brief Determines whether this declaration reference was followed by an
10695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// explicit template argument list.
1070726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
1071726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner
10722085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  /// \brief Retrieve the explicit template argument list that followed the
1073f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  /// member template name.
1074bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
10751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    assert(hasExplicitTemplateArgs());
10765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return *getTemplateKWAndArgsInfo();
10772085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  }
10782085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner
10792085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  /// \brief Retrieve the explicit template argument list that followed the
10802085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  /// member template name.
1081a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson  const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
10822085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner    return const_cast<DeclRefExpr *>(this)->getExplicitTemplateArgs();
10832085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  }
10841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10852085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  /// \brief Retrieves the optional explicit template arguments.
10862085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  /// This points to the same data as getExplicitTemplateArgs(), but
10872085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  /// returns null if there are no explicit template arguments.
10882085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const {
1089a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson    if (!hasExplicitTemplateArgs()) return 0;
1090673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor    return &getExplicitTemplateArgs();
1091673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  }
1092673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
1093b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar  /// \brief Copies the template arguments (if present) into the given
1094b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar  /// structure.
1095b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
10962f4eaef37476ae6891ede8ba215d0f6fd093629bBenjamin Kramer    if (hasExplicitTemplateArgs())
10975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      getExplicitTemplateArgs().copyInto(List);
1098673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  }
1099673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
1100b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar  /// \brief Retrieve the template arguments provided as part of this
1101673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  /// template-id.
11025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const TemplateArgumentLoc *getTemplateArgs() const {
1103673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor    if (!hasExplicitTemplateArgs())
1104673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor      return 0;
11058d4141f83d9de379547cf05bd75d4c6cf894b189Steve Naroff
1106b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar    return getExplicitTemplateArgs().getTemplateArgs();
1107b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar  }
1108b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar
110933fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff  /// \brief Retrieve the number of template arguments provided as part of this
111033fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff  /// template-id.
111133fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff  unsigned getNumTemplateArgs() const {
1112726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner    if (!hasExplicitTemplateArgs())
1113726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner      return 0;
1114726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner
11151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return getExplicitTemplateArgs().NumTemplateArgs;
1116726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  }
1117726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner
1118726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  /// \brief Returns true if this expression refers to a function that
1119726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner  /// was resolved from an overloaded set having size greater than 1.
11201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool hadMultipleCandidates() const {
1121673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor    return DeclRefExprBits.HadMultipleCandidates;
1122673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  }
1123673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor  /// \brief Sets the flag telling whether this expression refers to
112408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner  /// a function that was resolved from an overloaded set having size
112508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner  /// greater than 1.
112608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner  void setHadMultipleCandidates(bool V = true) {
112708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner    DeclRefExprBits.HadMultipleCandidates = V;
112808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner  }
112908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner
113008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner  /// Does this DeclRefExpr refer to a local declaration from an
113108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner  /// enclosing function scope?
113208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner  bool refersToEnclosingLocal() const {
113308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner    return DeclRefExprBits.RefersToEnclosingLocal;
113408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner  }
1135673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor
1136b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner  static bool classof(const Stmt *T) {
1137b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner    return T->getStmtClass() == DeclRefExprClass;
1138b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner  }
11395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // Iterators
11411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  child_range children() { return child_range(); }
11425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  friend class ASTStmtReader;
11441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  friend class ASTStmtWriter;
11455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
11465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// PredefinedExpr - [C99 6.4.2.2] - A predefined identifier such as __func__.
114877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenekclass PredefinedExpr : public Expr {
114977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenekpublic:
115077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  enum IdentType {
11515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Func,
11525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Function,
11535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LFunction,  // Same as Function, but as wide string.
11545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    PrettyFunction,
11555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    /// PrettyFunctionNoVirtual - The same as PrettyFunction, except that the
11565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    /// 'virtual' keyword is omitted for virtual member functions.
11575549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    PrettyFunctionNoVirtual
11585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
11595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1160898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorprivate:
1161f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  SourceLocation Loc;
1162bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  IdentType Type;
1163bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregorpublic:
1164898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  PredefinedExpr(SourceLocation l, QualType type, IdentType IT)
11651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : Expr(PredefinedExprClass, type, VK_LValue, OK_Ordinary,
1166c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor           type->isDependentType(), type->isDependentType(),
11671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           type->isInstantiationDependentType(),
1168c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
1169c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor      Loc(l), Type(IT) {}
11705549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek
11715549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  /// \brief Construct an empty predefined expression.
1172c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor  explicit PredefinedExpr(EmptyShell Empty)
1173c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor    : Expr(PredefinedExprClass, Empty) { }
1174866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek
11755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  IdentType getIdentType() const { return Type; }
1176313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  void setIdentType(IdentType IT) { Type = IT; }
1177313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor
1178c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor  SourceLocation getLocation() const { return Loc; }
1179313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  void setLocation(SourceLocation L) { Loc = L; }
1180313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor
1181313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  static std::string ComputeName(IdentType IT, const Decl *CurrentDecl);
1182c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor
1183313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor  SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
11841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
11851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
11875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getStmtClass() == PredefinedExprClass;
11881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
118977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
119077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // Iterators
119177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  child_range children() { return child_range(); }
11925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
11935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// \brief Used by IntegerLiteral/FloatingLiteral to store the numeric without
11950518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// leaking memory.
11960518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl///
11975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// For large floats/integers, APFloat/APInt will allocate memory from the heap
1198dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// to represent these numbers.  Unfortunately, when we use a BumpPtrAllocator
1199dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// to allocate IntegerLiteral/FloatingLiteral nodes the memory associated with
1200dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// the APFloat/APInt values will never get freed. APNumericStorage uses
1201dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// ASTContext's allocator for memory allocation.
1202dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattnerclass APNumericStorage {
1203dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner  union {
1204dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner    uint64_t VAL;    ///< Used to store the <= 64 bits integer value.
12055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    uint64_t *pVal;  ///< Used to store the >64 bits integer value.
12065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
12075baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall  unsigned BitWidth;
12085baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall
12095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool hasAllocation() const { return llvm::APInt::getNumWords(BitWidth) > 1; }
12100799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall
12115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  APNumericStorage(const APNumericStorage &) LLVM_DELETED_FUNCTION;
12120799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  void operator=(const APNumericStorage &) LLVM_DELETED_FUNCTION;
12131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected:
1215f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  APNumericStorage() : VAL(0), BitWidth(0) { }
1216f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall
1217f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  llvm::APInt getIntValue() const {
1218de7e66256b1bdfcf6526994825a8c8fced52a31cEli Friedman    unsigned NumWords = llvm::APInt::getNumWords(BitWidth);
1219bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    if (NumWords > 1)
1220bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor      return llvm::APInt(BitWidth, NumWords, pVal);
12210799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall    else
12225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return llvm::APInt(BitWidth, VAL);
12230b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  }
12241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setIntValue(ASTContext &C, const llvm::APInt &Val);
12252de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall};
12260b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
12270799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCallclass APIntStorage : private APNumericStorage {
12280b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregorpublic:
12290b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  llvm::APInt getValue() const { return getIntValue(); }
12305549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  void setValue(ASTContext &C, const llvm::APInt &Val) { setIntValue(C, Val); }
12310b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor};
12320b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
12335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass APFloatStorage : private APNumericStorage {
12345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
12350b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  llvm::APFloat getValue(const llvm::fltSemantics &Semantics) const {
12360b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor    return llvm::APFloat(Semantics, getIntValue());
12375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12382085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  void setValue(ASTContext &C, const llvm::APFloat &Val) {
12392de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    setIntValue(C, Val.bitcastToAPInt());
12402085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner  }
12415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
1242cc7bd10c0de9449b795bda3c5dcc6d83cc48436bZhanyong Wan
12432085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattnerclass IntegerLiteral : public Expr, public APIntStorage {
12442de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  SourceLocation Loc;
12452085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner
12465a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek  /// \brief Construct an empty integer literal.
12470799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  explicit IntegerLiteral(EmptyShell Empty)
12480799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall    : Expr(IntegerLiteralClass, Empty) { }
12492de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall
1250993cdca0fed7deb646e4654dfb2607227a497faaBenjamin Kramerpublic:
12512de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy,
12522de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  // or UnsignedLongLongTy
1253993cdca0fed7deb646e4654dfb2607227a497faaBenjamin Kramer  IntegerLiteral(ASTContext &C, const llvm::APInt &V, QualType type,
12542de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall                 SourceLocation l);
12552de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall
12562de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  /// \brief Returns a new integer literal with value 'V' and type 'type'.
12572de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  /// \param type - either IntTy, LongTy, LongLongTy, UnsignedIntTy,
12580799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  /// UnsignedLongTy, or UnsignedLongLongTy which should match the size of V
12591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \param V - the value that the returned integer literal contains.
12605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static IntegerLiteral *Create(ASTContext &C, const llvm::APInt &V,
12615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                                QualType type, SourceLocation l);
12625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// \brief Returns a new empty integer literal.
12635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static IntegerLiteral *Create(ASTContext &C, EmptyShell Empty);
1264bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor
1265bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
1266bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
1267bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor
1268bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  /// \brief Retrieve the location of the literal.
1269bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  SourceLocation getLocation() const { return Loc; }
1270bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor
1271bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor  void setLocation(SourceLocation Location) { Loc = Location; }
12725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
12745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getStmtClass() == IntegerLiteralClass;
12755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
12765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Iterators
12785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  child_range children() { return child_range(); }
12791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump};
12801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass CharacterLiteral : public Expr {
12825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
12835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum CharacterKind {
12841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Ascii,
128577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek    Wide,
128677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek    UTF16,
128777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek    UTF32
12885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
12895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12908ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorprivate:
12918ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  unsigned Value;
12928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  SourceLocation Loc;
12938ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorpublic:
12948ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // type should be IntTy
1295c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  CharacterLiteral(unsigned value, CharacterKind kind, QualType type,
12968ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                   SourceLocation l)
12978ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    : Expr(CharacterLiteralClass, type, VK_RValue, OK_Ordinary, false, false,
12988ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor           false, false),
12998ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Value(value), Loc(l) {
13008ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    CharacterLiteralBits.Kind = kind;
13018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
1302c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
13038ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// \brief Construct an empty character literal.
13048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { }
13058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
13068ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  SourceLocation getLocation() const { return Loc; }
13078ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  CharacterKind getKind() const {
13088ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return static_cast<CharacterKind>(CharacterLiteralBits.Kind);
13098ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
13108ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
1311cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor  SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
13128ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
1313cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor
13148ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  unsigned getValue() const { return Value; }
1315cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor
1316cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor  void setLocation(SourceLocation Location) { Loc = Location; }
1317cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor  void setKind(CharacterKind kind) { CharacterLiteralBits.Kind = kind; }
1318cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor  void setValue(unsigned Val) { Value = Val; }
1319cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor
13208ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  static bool classof(const Stmt *T) {
13218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return T->getStmtClass() == CharacterLiteralClass;
13228ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
13238ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
1324c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  // Iterators
13258ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  child_range children() { return child_range(); }
13268ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor};
1327c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
13288ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorclass FloatingLiteral : public Expr, private APFloatStorage {
13298ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  SourceLocation Loc;
1330c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
13318ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  FloatingLiteral(ASTContext &C, const llvm::APFloat &V, bool isexact,
13328ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                  QualType Type, SourceLocation L);
13338ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
13348ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// \brief Construct an empty floating-point literal.
1335c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  explicit FloatingLiteral(ASTContext &C, EmptyShell Empty);
1336cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor
13378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorpublic:
1338c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  static FloatingLiteral *Create(ASTContext &C, const llvm::APFloat &V,
13398ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                                 bool isexact, QualType Type, SourceLocation L);
13408ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  static FloatingLiteral *Create(ASTContext &C, EmptyShell Empty);
1341c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
13428ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  llvm::APFloat getValue() const {
13438ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return APFloatStorage::getValue(getSemantics());
1344c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  }
13458ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  void setValue(ASTContext &C, const llvm::APFloat &Val) {
1346c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    assert(&getSemantics() == &Val.getSemantics() && "Inconsistent semantics");
13478ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    APFloatStorage::setValue(C, Val);
1348c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  }
13498ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
1350c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  /// Get a raw enumeration value representing the floating-point semantics of
13518ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// this literal (32-bit IEEE, x87, ...), suitable for serialisation.
13528ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  APFloatSemantics getRawSemantics() const {
13538ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return static_cast<APFloatSemantics>(FloatingLiteralBits.Semantics);
1354c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  }
13558ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
1356cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor  /// Set the raw enumeration value representing the floating-point semantics of
1357cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor  /// this literal (32-bit IEEE, x87, ...), suitable for serialisation.
1358cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor  void setRawSemantics(APFloatSemantics Sem) {
1359cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor    FloatingLiteralBits.Semantics = Sem;
1360c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  }
13618ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
1362c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  /// Return the APFloat semantics this literal uses.
13638ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  const llvm::fltSemantics &getSemantics() const;
13648ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
1365c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  /// Set the APFloat semantics this literal uses.
13668ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  void setSemantics(const llvm::fltSemantics &Sem);
13678ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
13688ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  bool isExact() const { return FloatingLiteralBits.IsExact; }
13698ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  void setExact(bool E) { FloatingLiteralBits.IsExact = E; }
13708ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
13718ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// getValueAsApproximateDouble - This returns the value as an inaccurate
13728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// double.  Note that this may cause loss of precision, but is useful for
13738ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// debugging dumps, etc.
13748ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  double getValueAsApproximateDouble() const;
13758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
1376cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor  SourceLocation getLocation() const { return Loc; }
13778ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  void setLocation(SourceLocation L) { Loc = L; }
1378c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
13798ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  SourceLocation getLocStart() const LLVM_READONLY { return Loc; }
13808ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  SourceLocation getLocEnd() const LLVM_READONLY { return Loc; }
13818ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
1382c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  static bool classof(const Stmt *T) {
1383cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor    return T->getStmtClass() == FloatingLiteralClass;
1384cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor  }
1385cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor
1386c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  // Iterators
1387cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor  child_range children() { return child_range(); }
1388c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt};
13898ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
13908ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// ImaginaryLiteral - We support imaginary integer and floating point literals,
13918ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// like "1.0i".  We represent these as a wrapper around FloatingLiteral and
13928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// IntegerLiteral classes.  Instances of this class always have a Complex type
1393c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt/// whose element type matches the subexpression.
13948ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor///
13958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorclass ImaginaryLiteral : public Expr {
13968ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  Stmt *Val;
13978ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorpublic:
13988ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  ImaginaryLiteral(Expr *val, QualType Ty)
1399c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    : Expr(ImaginaryLiteralClass, Ty, VK_RValue, OK_Ordinary, false, false,
14008ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor           false, false),
14018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor      Val(val) {}
14028ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
14038ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// \brief Build an empty imaginary literal.
14048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  explicit ImaginaryLiteral(EmptyShell Empty)
14058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    : Expr(ImaginaryLiteralClass, Empty) { }
14068ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
1407c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  const Expr *getSubExpr() const { return cast<Expr>(Val); }
1408c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  Expr *getSubExpr() { return cast<Expr>(Val); }
14098ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  void setSubExpr(Expr *E) { Val = E; }
1410c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
14118ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  SourceLocation getLocStart() const LLVM_READONLY { return Val->getLocStart(); }
14128ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  SourceLocation getLocEnd() const LLVM_READONLY { return Val->getLocEnd(); }
14138ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
14148ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  static bool classof(const Stmt *T) {
14158ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return T->getStmtClass() == ImaginaryLiteralClass;
1416c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  }
14178ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
14188ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  // Iterators
1419c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt  child_range children() { return child_range(&Val, &Val+1); }
1420c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt};
1421c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt
1422c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt/// StringLiteral - This represents a string literal expression, e.g. "foo"
14238ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// or L"bar" (wide strings).  The actual string is returned by getStrData()
14248ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// is NOT null-terminated, and the length of the string is determined by
14258ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// calling getByteLength().  The C type for a string is always a
1426c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt/// ConstantArrayType.  In C++, the char type is const qualified, in C it is
14278ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// not.
14288ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor///
14298ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// Note that strings in C can be formed by concatenation of multiple string
14308ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// literal pptokens in translation phase #6.  This keeps track of the locations
14318ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// of each of these pieces.
14328ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor///
14338ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// Strings in C can also be truncated and extended by assigning into arrays,
14348ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// e.g. with constructs like:
14358ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor///   char X[2] = "foobar";
1436c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt/// In this case, getByteLength() will return 6, but the string literal will
14378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// have type "char[2]".
14388ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorclass StringLiteral : public Expr {
14398ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorpublic:
14408ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  enum StringKind {
14418ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    Ascii,
14428ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    Wide,
1443c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    UTF8,
14448ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    UTF16,
14458ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    UTF32
14468ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  };
14478ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
14488ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorprivate:
14498ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  friend class ASTStmtReader;
14508ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
14518ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  union {
14528ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    const char *asChar;
1453c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    const uint16_t *asUInt16;
14548ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    const uint32_t *asUInt32;
14558ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  } StrData;
14568ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  unsigned Length;
14578ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  unsigned CharByteWidth : 4;
14588ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  unsigned Kind : 3;
14598ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  unsigned IsPascal : 1;
14608ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  unsigned NumConcatenated;
14618ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  SourceLocation TokLocs[1];
14628ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
14638ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  StringLiteral(QualType Ty) :
14648ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    Expr(StringLiteralClass, Ty, VK_LValue, OK_Ordinary, false, false, false,
14658ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor         false) {}
14668ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
14678ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  static int mapCharByteWidth(TargetInfo const &target,StringKind k);
14688ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
1469c302113179a1c2b1254224ea9b6f5316ceeb375cSean Huntpublic:
14708ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// This is the "fully general" constructor that allows representation of
14718ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// strings formed from multiple concatenated tokens.
14728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  static StringLiteral *Create(ASTContext &C, StringRef Str, StringKind Kind,
14738ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                               bool Pascal, QualType Ty,
14748ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                               const SourceLocation *Loc, unsigned NumStrs);
14758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
14768ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// Simple constructor for string literals made from one token.
14778ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  static StringLiteral *Create(ASTContext &C, StringRef Str, StringKind Kind,
14788ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                               bool Pascal, QualType Ty,
14798ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor                               SourceLocation Loc) {
14808ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    return Create(C, Str, Kind, Pascal, Ty, &Loc, 1);
14818ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  }
14828ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
14838ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  /// \brief Construct an empty string literal.
14848ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  static StringLiteral *CreateEmpty(ASTContext &C, unsigned NumStrs);
14858ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor
14868ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor  StringRef getString() const {
14878ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor    assert(CharByteWidth==1
14888ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor           && "This function is used in places that assume strings use char");
14890518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    return StringRef(StrData.asChar, getByteLength());
14900518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  }
14910518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl
14920518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  /// Allow access to clients that need the byte representation, such as
14930518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  /// ASTWriterStmt::VisitStringLiteral().
1494d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl  StringRef getBytes() const {
1495a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    // FIXME: StringRef may not be the right type to use as a result for this.
1496d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl    if (CharByteWidth == 1)
1497d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl      return StringRef(StrData.asChar, getByteLength());
14985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (CharByteWidth == 4)
149942602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor      return StringRef(reinterpret_cast<const char*>(StrData.asUInt32),
15005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                       getByteLength());
1501a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    assert(CharByteWidth == 2 && "unsupported CharByteWidth");
15020518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    return StringRef(reinterpret_cast<const char*>(StrData.asUInt16),
15030518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl                     getByteLength());
1504f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  }
1505ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor
15062850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl  void outputString(raw_ostream &OS) const;
1507bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor
1508bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  uint32_t getCodeUnit(size_t i) const {
1509ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor    assert(i < Length && "out of bounds access");
1510a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    if (CharByteWidth == 1)
1511ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor      return static_cast<unsigned char>(StrData.asChar[i]);
1512ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor    if (CharByteWidth == 4)
15131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      return StrData.asUInt32[i];
1514ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor    assert(CharByteWidth == 2 && "unsupported CharByteWidth");
1515ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor    return StrData.asUInt16[i];
1516f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  }
1517ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor
1518ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor  unsigned getByteLength() const { return CharByteWidth*Length; }
1519bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  unsigned getLength() const { return Length; }
1520bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  unsigned getCharByteWidth() const { return CharByteWidth; }
1521ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor
1522ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor  /// \brief Sets the string data to the given string data.
1523d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl  void setString(ASTContext &C, StringRef Str,
15240518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl                 StringKind Kind, bool IsPascal);
15250b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
15260b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  StringKind getKind() const { return static_cast<StringKind>(Kind); }
15270b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
15280b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
15295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isAscii() const { return Kind == Ascii; }
15300b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  bool isWide() const { return Kind == Wide; }
15310b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  bool isUTF8() const { return Kind == UTF8; }
15320518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  bool isUTF16() const { return Kind == UTF16; }
15330518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  bool isUTF32() const { return Kind == UTF32; }
15345ab75172051a6d2ea71a80a79e81c65519fd3462John McCall  bool isPascal() const { return IsPascal; }
15355ab75172051a6d2ea71a80a79e81c65519fd3462John McCall
1536a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall  bool containsNonAsciiOrNull() const {
15370518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    StringRef Str = getString();
15385ab75172051a6d2ea71a80a79e81c65519fd3462John McCall    for (unsigned i = 0, e = Str.size(); i != e; ++i)
15390518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl      if (!isASCII(Str[i]) || !Str[i])
1540caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner        return true;
15410518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    return false;
1542d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl  }
15430518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl
1544caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner  /// getNumConcatenated - Get the number of string literal tokens that were
1545caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner  /// concatenated in translation phase #6 to form this string literal.
1546caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner  unsigned getNumConcatenated() const { return NumConcatenated; }
15470b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor
15480b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  SourceLocation getStrTokenLoc(unsigned TokNum) const {
1549a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    assert(TokNum < NumConcatenated && "Invalid tok number");
1550a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall    return TokLocs[TokNum];
15511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
15520b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  void setStrTokenLoc(unsigned TokNum, SourceLocation L) {
15530b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor    assert(TokNum < NumConcatenated && "Invalid tok number");
15540518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl    TokLocs[TokNum] = L;
15550518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  }
15560518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl
15570518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  /// getLocationOfByte - Return a source location that points to the specified
15580518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  /// byte of this string literal.
15590518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  ///
156076e773a443be9f006610f46529e07d4c8d857680Chris Lattner  /// Strings are amazingly complex.  They can be formed from multiple tokens
15610b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  /// and can have escape sequences in them in addition to the usual trigraph
15620b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  /// and escaped newline business.  This routine handles this complexity.
15630b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  ///
15640b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor  SourceLocation getLocationOfByte(unsigned ByteNo, const SourceManager &SM,
1565866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek                                   const LangOptions &Features,
1566866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek                                   const TargetInfo &Target) const;
1567866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek
1568866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek  typedef const SourceLocation *tokloc_iterator;
15695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  tokloc_iterator tokloc_begin() const { return TokLocs; }
15701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  tokloc_iterator tokloc_end() const { return TokLocs+NumConcatenated; }
15711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation getLocStart() const LLVM_READONLY { return TokLocs[0]; }
15730518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl  SourceLocation getLocEnd() const LLVM_READONLY {
15741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return TokLocs[NumConcatenated - 1];
157577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  }
157677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
157777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  static bool classof(const Stmt *T) {
15785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getStmtClass() == StringLiteralClass;
15795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
15805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
15815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Iterators
15825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  child_range children() { return child_range(); }
15835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
15845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
15855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ParenExpr - This represents a parethesized expression, e.g. "(1)".  This
158677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek/// AST node is only formed if full location information is requested.
15871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass ParenExpr : public Expr {
15885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation L, R;
15895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Stmt *Val;
15902324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenekpublic:
1591f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  ParenExpr(SourceLocation l, SourceLocation r, Expr *val)
159273d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner    : Expr(ParenExprClass, val->getType(),
1593f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall           val->getValueKind(), val->getObjectKind(),
15942850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl           val->isTypeDependent(), val->isValueDependent(),
1595bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           val->isInstantiationDependent(),
1596bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor           val->containsUnexpandedParameterPack()),
1597bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor      L(l), R(r), Val(val) {}
15982850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl
159973d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner  /// \brief Construct an empty parenthesized expression.
160073d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner  explicit ParenExpr(EmptyShell Empty)
160173d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner    : Expr(ParenExprClass, Empty) { }
16021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1603cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  const Expr *getSubExpr() const { return cast<Expr>(Val); }
1604cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  Expr *getSubExpr() { return cast<Expr>(Val); }
1605cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  void setSubExpr(Expr *E) { Val = E; }
1606cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
16072324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  SourceLocation getLocStart() const LLVM_READONLY { return L; }
16082324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  SourceLocation getLocEnd() const LLVM_READONLY { return R; }
16092324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek
16102324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  /// \brief Get the location of the left parentheses '('.
16112324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek  SourceLocation getLParen() const { return L; }
161233fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb  void setLParen(SourceLocation Loc) { L = Loc; }
161333fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb
161433fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb  /// \brief Get the location of the right parentheses ')'.
161533fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb  SourceLocation getRParen() const { return R; }
16165549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  void setRParen(SourceLocation Loc) { R = Loc; }
16175549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek
1618cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  static bool classof(const Stmt *T) {
1619cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor    return T->getStmtClass() == ParenExprClass;
16205549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  }
16215549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek
1622cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor  // Iterators
16231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  child_range children() { return child_range(&Val, &Val+1); }
16241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump};
16255549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek
162677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
16271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// UnaryOperator - This represents the unary-expression's (except sizeof and
16281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// alignof), the postinc/postdec operators from postfix-expression, and various
16295549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek/// extensions.
16302324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek///
16311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Notes on various nodes:
16321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
16335549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek/// Real/Imag - These return the real/imag part of a complex operand.  If
16342324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek///   applied to a non-complex value, the former returns its operand and the
16351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///   later returns zero in the type of the operand.
163677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek///
16375549976193e34417d4474a5f4a514268ef6666c7Ted Kremenekclass UnaryOperator : public Expr {
16381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
16391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  typedef UnaryOperatorKind Opcode;
16401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
164177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenekprivate:
16425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned Opc : 5;
16431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation Loc;
1644026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  Stmt *Val;
1645cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregorpublic:
1646cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor
16475cd9d6daf3acd4cc87fecebd81d9495b9e4ba9cdChris Lattner  UnaryOperator(Expr *input, Opcode opc, QualType type,
16485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                ExprValueKind VK, ExprObjectKind OK, SourceLocation l)
16491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : Expr(UnaryOperatorClass, type, VK, OK,
16501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           input->isTypeDependent() || type->isDependentType(),
16515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           input->isValueDependent(),
16525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           (input->isInstantiationDependent() ||
16531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump            type->isInstantiationDependentType()),
165477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek           input->containsUnexpandedParameterPack()),
165577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek      Opc(opc), Loc(l), Val(input) {}
165677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
16575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// \brief Build an empty unary operator.
16585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  explicit UnaryOperator(EmptyShell Empty)
16595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    : Expr(UnaryOperatorClass, Empty), Opc(UO_AddrOf) { }
1660b4609806e9232593ece09ce08b630836e825865cDouglas Gregor
16611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Opcode getOpcode() const { return static_cast<Opcode>(Opc); }
1662b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  void setOpcode(Opcode O) { Opc = O; }
16631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1664b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  Expr *getSubExpr() const { return cast<Expr>(Val); }
1665b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  void setSubExpr(Expr *E) { Val = E; }
16665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
166777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  /// getOperatorLoc - Return the location of the operator.
16685549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  SourceLocation getOperatorLoc() const { return Loc; }
16695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void setOperatorLoc(SourceLocation L) { Loc = L; }
16705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
16711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// isPostfix - Return true if this is a postfix operation, like x++.
1672b4609806e9232593ece09ce08b630836e825865cDouglas Gregor  static bool isPostfix(Opcode Op) {
1673b4609806e9232593ece09ce08b630836e825865cDouglas Gregor    return Op == UO_PostInc || Op == UO_PostDec;
1674668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek  }
1675f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall
167642602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor  /// isPrefix - Return true if this is a prefix operation, like --x.
16775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool isPrefix(Opcode Op) {
16781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return Op == UO_PreInc || Op == UO_PreDec;
1679f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  }
16801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16811f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  bool isPrefix() const { return isPrefix(getOpcode()); }
1682ba0a9006dbc4814e1e35f82812cb5a1dad65e8b8Argyrios Kyrtzidis  bool isPostfix() const { return isPostfix(getOpcode()); }
16831f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor
16845549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  static bool isIncrementOp(Opcode Op) {
16855549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    return Op == UO_PreInc || Op == UO_PostInc;
168618b2515e1bf8c86a4900792692e42fe1296be28dChris Lattner  }
1687a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu  bool isIncrementOp() const {
1688d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes    return isIncrementOp(getOpcode());
1689d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes  }
1690d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes
1691d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes  static bool isDecrementOp(Opcode Op) {
1692d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes    return Op == UO_PreDec || Op == UO_PostDec;
1693a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu  }
1694a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu  bool isDecrementOp() const {
1695bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner    return isDecrementOp(getOpcode());
1696bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner  }
1697bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner
1698a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu  static bool isIncrementDecrementOp(Opcode Op) { return Op <= UO_PreDec; }
16995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isIncrementDecrementOp() const {
17005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return isIncrementDecrementOp(getOpcode());
17015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
17021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1703aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  static bool isArithmeticOp(Opcode Op) {
1704aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor    return Op >= UO_Plus && Op <= UO_LNot;
1705aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  }
17065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isArithmeticOp() const { return isArithmeticOp(getOpcode()); }
17075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
17085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
17095549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  /// corresponds to, e.g. "sizeof" or "[pre]++"
17105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static StringRef getOpcodeStr(Opcode Op);
17115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
17125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// \brief Retrieve the unary opcode that corresponds to the given
17135549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  /// overloaded operator.
17145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix);
17151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1716934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff  /// \brief Retrieve the overloaded operator kind that corresponds to
1717934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff  /// the given unary opcode.
1718934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff  static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
1719934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff
1720934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff  SourceLocation getLocStart() const LLVM_READONLY {
17211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return isPostfix() ? Val->getLocStart() : Loc;
1722d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  }
1723d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  SourceLocation getLocEnd() const LLVM_READONLY {
1724d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner    return isPostfix() ? Loc : Val->getLocEnd();
17258189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek  }
17261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation getExprLoc() const LLVM_READONLY { return Loc; }
17275549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek
17285549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  static bool classof(const Stmt *T) {
17291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == UnaryOperatorClass;
1730d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  }
1731d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner
17325549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  // Iterators
17335549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  child_range children() { return child_range(&Val, &Val+1); }
17341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump};
17355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
17365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// OffsetOfExpr - [C99 7.17] - This represents an expression of the form
17375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// offsetof(record-type, member-designator). For example, given:
17385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// @code
1739cb888967400a03504c88acedd5248d6778a82f46Chris Lattner/// struct S {
1740cb888967400a03504c88acedd5248d6778a82f46Chris Lattner///   float f;
17414ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad///   double d;
17421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// };
17431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// struct T {
17441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///   int i;
17456dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson///   struct S s[10];
17466dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson/// };
17471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// @endcode
1748d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// we can represent and evaluate the expression @c offsetof(struct T, s[2].d).
17491f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor
1750866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenekclass OffsetOfExpr : public Expr {
17511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
175277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  // __builtin_offsetof(type, identifier(.identifier|[expr])*)
17535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class OffsetOfNode {
17541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  public:
17551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    /// \brief The kind of offsetof node we have.
17564bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt    enum Kind {
17574bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt      /// \brief An index into an array.
17585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      Array = 0x00,
17595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      /// \brief A field.
176088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor      Field = 0x01,
176177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek      /// \brief A field in a dependent type, known only by its name.
176277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek      Identifier = 0x02,
176377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek      /// \brief An implicit indirection through a C++ base class, when the
17645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      /// field found is in a base class.
17655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      Base = 0x03
1766ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner    };
17675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
17685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  private:
17696bb8017bb9e828d118e15e59d71c66bba323c364John McCall    enum { MaskBits = 2, Mask = 0x03 };
17706bb8017bb9e828d118e15e59d71c66bba323c364John McCall
1771161755a09898c95d21bfff33707da9ca41cd53c5John McCall    /// \brief The source range that covers this part of the designator.
17726bb8017bb9e828d118e15e59d71c66bba323c364John McCall    SourceRange Range;
17736bb8017bb9e828d118e15e59d71c66bba323c364John McCall
1774ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner    /// \brief The data describing the designator, which comes in three
1775ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner    /// different forms, depending on the lower two bits.
17765549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    ///   - An unsigned index into the array of Expr*'s stored after this node
17771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    ///     in memory, for [constant-expression] designators.
1778ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner    ///   - A FieldDecl*, for references to a known field.
1779ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner    ///   - An IdentifierInfo*, for references to a field with a given name
1780f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman    ///     when the class type is dependent.
17811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    ///   - A CXXBaseSpecifier*, for references that look at a field in a
1782ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner    ///     base class.
17835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    uintptr_t Data;
17841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17852577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  public:
17862577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    /// \brief Create an offsetof node that refers to an array element.
17872577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    OffsetOfNode(SourceLocation LBracketLoc, unsigned Index,
17882577743c5650c646fb705df01403707e94f2df04Abramo Bagnara                 SourceLocation RBracketLoc)
1789ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner      : Range(LBracketLoc, RBracketLoc), Data((Index << 2) | Array) { }
179083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor
17911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    /// \brief Create an offsetof node that refers to a field.
179283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    OffsetOfNode(SourceLocation DotLoc, FieldDecl *Field,
17936bb8017bb9e828d118e15e59d71c66bba323c364John McCall                 SourceLocation NameLoc)
17946bb8017bb9e828d118e15e59d71c66bba323c364John McCall      : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc),
1795c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor        Data(reinterpret_cast<uintptr_t>(Field) | OffsetOfNode::Field) { }
17966bb8017bb9e828d118e15e59d71c66bba323c364John McCall
17971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    /// \brief Create an offsetof node that refers to an identifier.
1798c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    OffsetOfNode(SourceLocation DotLoc, IdentifierInfo *Name,
1799c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor                 SourceLocation NameLoc)
1800c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor      : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc),
1801c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor        Data(reinterpret_cast<uintptr_t>(Name) | Identifier) { }
18026bb8017bb9e828d118e15e59d71c66bba323c364John McCall
1803c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    /// \brief Create an offsetof node that refers into a C++ base class.
18041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    explicit OffsetOfNode(const CXXBaseSpecifier *Base)
180583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor      : Range(), Data(reinterpret_cast<uintptr_t>(Base) | OffsetOfNode::Base) {}
18066bb8017bb9e828d118e15e59d71c66bba323c364John McCall
18076bb8017bb9e828d118e15e59d71c66bba323c364John McCall    /// \brief Determine what kind of offsetof node this is.
18086bb8017bb9e828d118e15e59d71c66bba323c364John McCall    Kind getKind() const {
180983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor      return static_cast<Kind>(Data & Mask);
181083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    }
181183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor
18126bb8017bb9e828d118e15e59d71c66bba323c364John McCall    /// \brief For an array element node, returns the index into the array
1813c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    /// of expressions.
1814c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    unsigned getArrayExprIndex() const {
18151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      assert(getKind() == Array);
18165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return Data >> 2;
1817f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman    }
1818f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall
1819f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    /// \brief For a field offsetof node, returns the field.
1820f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    FieldDecl *getField() const {
1821bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor      assert(getKind() == Field);
1822bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor      return reinterpret_cast<FieldDecl *>(Data & ~(uintptr_t)Mask);
18232577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    }
18242577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
18252577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    /// \brief For a field or identifier offsetof node, returns the name of
18262577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    /// the field.
18272577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    IdentifierInfo *getFieldName() const;
18282577743c5650c646fb705df01403707e94f2df04Abramo Bagnara
18292577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    /// \brief For a base class node, returns the base specifier.
18302577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    CXXBaseSpecifier *getBase() const {
18312577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      assert(getKind() == Base);
18322577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      return reinterpret_cast<CXXBaseSpecifier *>(Data & ~(uintptr_t)Mask);
18332577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    }
1834f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall
1835f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    /// \brief Retrieve the source range that covers this offsetof node.
1836f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    ///
1837bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    /// For an array element node, the source range contains the locations of
1838bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    /// the square brackets. For a field or identifier node, the source range
18392577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    /// contains the location of the period (if there is one) and the
18402577743c5650c646fb705df01403707e94f2df04Abramo Bagnara    /// identifier.
18416bb8017bb9e828d118e15e59d71c66bba323c364John McCall    SourceRange getSourceRange() const LLVM_READONLY { return Range; }
1842510190777c4bd53e960eea4665b204778fec1b64Eli Friedman    SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); }
18431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); }
184483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  };
1845161755a09898c95d21bfff33707da9ca41cd53c5John McCall
18462577743c5650c646fb705df01403707e94f2df04Abramo Bagnaraprivate:
1847d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
1848f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  SourceLocation OperatorLoc, RParenLoc;
18491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // Base type;
185088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor  TypeSourceInfo *TSInfo;
18515549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  // Number of sub-components (i.e. instances of OffsetOfNode).
185257e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor  unsigned NumComps;
185357e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor  // Number of sub-expressions (i.e. array subscript expressions).
185457e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor  unsigned NumExprs;
185557e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor
185657e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor  OffsetOfExpr(ASTContext &C, QualType type,
1857f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman               SourceLocation OperatorLoc, TypeSourceInfo *tsi,
1858f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman               ArrayRef<OffsetOfNode> comps, ArrayRef<Expr*> exprs,
18591f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor               SourceLocation RParenLoc);
18606bb8017bb9e828d118e15e59d71c66bba323c364John McCall
1861161755a09898c95d21bfff33707da9ca41cd53c5John McCall  explicit OffsetOfExpr(unsigned numComps, unsigned numExprs)
18626bb8017bb9e828d118e15e59d71c66bba323c364John McCall    : Expr(OffsetOfExprClass, EmptyShell()),
1863161755a09898c95d21bfff33707da9ca41cd53c5John McCall      TSInfo(0), NumComps(numComps), NumExprs(numExprs) {}
1864161755a09898c95d21bfff33707da9ca41cd53c5John McCall
18656bb8017bb9e828d118e15e59d71c66bba323c364John McCallpublic:
18666bb8017bb9e828d118e15e59d71c66bba323c364John McCall
18676bb8017bb9e828d118e15e59d71c66bba323c364John McCall  static OffsetOfExpr *Create(ASTContext &C, QualType type,
18681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                              SourceLocation OperatorLoc, TypeSourceInfo *tsi,
18690979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor                              ArrayRef<OffsetOfNode> comps,
18700979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor                              ArrayRef<Expr*> exprs, SourceLocation RParenLoc);
18716bb8017bb9e828d118e15e59d71c66bba323c364John McCall
18721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static OffsetOfExpr *CreateEmpty(ASTContext &C,
187383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor                                   unsigned NumComps, unsigned NumExprs);
187483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor
187583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  /// getOperatorLoc - Return the location of the operator.
18761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation getOperatorLoc() const { return OperatorLoc; }
18776bb8017bb9e828d118e15e59d71c66bba323c364John McCall  void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
187883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor
18791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Return the location of the right parentheses.
188083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  SourceLocation getRParenLoc() const { return RParenLoc; }
188183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  void setRParenLoc(SourceLocation R) { RParenLoc = R; }
18821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
18831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  TypeSourceInfo *getTypeSourceInfo() const {
188483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    return TSInfo;
188583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  }
18861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setTypeSourceInfo(TypeSourceInfo *tsi) {
18876bb8017bb9e828d118e15e59d71c66bba323c364John McCall    TSInfo = tsi;
188883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  }
18891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
189083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor  const OffsetOfNode &getComponent(unsigned Idx) const {
189183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    assert(Idx < NumComps && "Subscript out of range");
1892c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    return reinterpret_cast<const OffsetOfNode *> (this + 1)[Idx];
1893c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
1894c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor
1895096832c5ed5b9106fa177ebc148489760c3bc496John McCall  void setComponent(unsigned Idx, OffsetOfNode ON) {
18961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    assert(Idx < NumComps && "Subscript out of range");
1897c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    reinterpret_cast<OffsetOfNode *> (this + 1)[Idx] = ON;
18981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
1899d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
1900d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  unsigned getNumComponents() const {
1901d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall    return NumComps;
1902096832c5ed5b9106fa177ebc148489760c3bc496John McCall  }
1903096832c5ed5b9106fa177ebc148489760c3bc496John McCall
1904096832c5ed5b9106fa177ebc148489760c3bc496John McCall  Expr* getIndexExpr(unsigned Idx) {
1905096832c5ed5b9106fa177ebc148489760c3bc496John McCall    assert(Idx < NumExprs && "Subscript out of range");
1906096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return reinterpret_cast<Expr **>(
1907096832c5ed5b9106fa177ebc148489760c3bc496John McCall                    reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx];
1908096832c5ed5b9106fa177ebc148489760c3bc496John McCall  }
1909096832c5ed5b9106fa177ebc148489760c3bc496John McCall  const Expr *getIndexExpr(unsigned Idx) const {
1910096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return const_cast<OffsetOfExpr*>(this)->getIndexExpr(Idx);
1911096832c5ed5b9106fa177ebc148489760c3bc496John McCall  }
1912096832c5ed5b9106fa177ebc148489760c3bc496John McCall
1913096832c5ed5b9106fa177ebc148489760c3bc496John McCall  void setIndexExpr(unsigned Idx, Expr* E) {
1914096832c5ed5b9106fa177ebc148489760c3bc496John McCall    assert(Idx < NumComps && "Subscript out of range");
1915096832c5ed5b9106fa177ebc148489760c3bc496John McCall    reinterpret_cast<Expr **>(
1916096832c5ed5b9106fa177ebc148489760c3bc496John McCall                reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx] = E;
1917096832c5ed5b9106fa177ebc148489760c3bc496John McCall  }
1918096832c5ed5b9106fa177ebc148489760c3bc496John McCall
1919096832c5ed5b9106fa177ebc148489760c3bc496John McCall  unsigned getNumExpressions() const {
1920096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return NumExprs;
1921096832c5ed5b9106fa177ebc148489760c3bc496John McCall  }
1922096832c5ed5b9106fa177ebc148489760c3bc496John McCall
1923096832c5ed5b9106fa177ebc148489760c3bc496John McCall  SourceLocation getLocStart() const LLVM_READONLY { return OperatorLoc; }
1924096832c5ed5b9106fa177ebc148489760c3bc496John McCall  SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
1925096832c5ed5b9106fa177ebc148489760c3bc496John McCall
1926096832c5ed5b9106fa177ebc148489760c3bc496John McCall  static bool classof(const Stmt *T) {
1927096832c5ed5b9106fa177ebc148489760c3bc496John McCall    return T->getStmtClass() == OffsetOfExprClass;
1928096832c5ed5b9106fa177ebc148489760c3bc496John McCall  }
1929096832c5ed5b9106fa177ebc148489760c3bc496John McCall
1930096832c5ed5b9106fa177ebc148489760c3bc496John McCall  // Iterators
1931d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  child_range children() {
1932c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt    Stmt **begin =
19331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      reinterpret_cast<Stmt**>(reinterpret_cast<OffsetOfNode*>(this + 1)
1934c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor                               + NumComps);
19351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return child_range(begin, begin + NumExprs);
1936c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
1937c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor};
19381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1939096832c5ed5b9106fa177ebc148489760c3bc496John McCall/// UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated)
1940c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor/// expression operand.  Used for sizeof/alignof (C99 6.5.3.4) and
19411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// vec_step (OpenCL 1.1 6.11.12).
1942c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregorclass UnaryExprOrTypeTraitExpr : public Expr {
1943c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  union {
1944833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall    TypeSourceInfo *Ty;
1945c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    Stmt *Ex;
19461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  } Argument;
19471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation OpLoc, RParenLoc;
1948096832c5ed5b9106fa177ebc148489760c3bc496John McCall
1949c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregorpublic:
19501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, TypeSourceInfo *TInfo,
1951c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor                           QualType resultType, SourceLocation op,
1952c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor                           SourceLocation rp) :
19531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_RValue, OK_Ordinary,
1954c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor           false, // Never type-dependent (C++ [temp.dep.expr]p3).
19551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           // Value-dependent if the argument is type-dependent.
19561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           TInfo->getType()->isDependentType(),
1957096832c5ed5b9106fa177ebc148489760c3bc496John McCall           TInfo->getType()->isInstantiationDependentType(),
1958c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor           TInfo->getType()->containsUnexpandedParameterPack()),
19591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      OpLoc(op), RParenLoc(rp) {
19601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    UnaryExprOrTypeTraitExprBits.Kind = ExprKind;
1961c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    UnaryExprOrTypeTraitExprBits.IsType = true;
19621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Argument.Ty = TInfo;
1963c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
1964c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor
19651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, Expr *E,
1966096832c5ed5b9106fa177ebc148489760c3bc496John McCall                           QualType resultType, SourceLocation op,
1967c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor                           SourceLocation rp) :
19681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_RValue, OK_Ordinary,
19692577743c5650c646fb705df01403707e94f2df04Abramo Bagnara           false, // Never type-dependent (C++ [temp.dep.expr]p3).
19702577743c5650c646fb705df01403707e94f2df04Abramo Bagnara           // Value-dependent if the argument is type-dependent.
19712577743c5650c646fb705df01403707e94f2df04Abramo Bagnara           E->isTypeDependent(),
19722577743c5650c646fb705df01403707e94f2df04Abramo Bagnara           E->isInstantiationDependent(),
19732577743c5650c646fb705df01403707e94f2df04Abramo Bagnara           E->containsUnexpandedParameterPack()),
19742577743c5650c646fb705df01403707e94f2df04Abramo Bagnara      OpLoc(op), RParenLoc(rp) {
19755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    UnaryExprOrTypeTraitExprBits.Kind = ExprKind;
19761f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor    UnaryExprOrTypeTraitExprBits.IsType = false;
19771f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor    Argument.Ex = E;
1978ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner  }
1979ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner
1980026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner  /// \brief Construct an empty sizeof/alignof expression.
19811f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor  explicit UnaryExprOrTypeTraitExpr(EmptyShell Empty)
19825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    : Expr(UnaryExprOrTypeTraitExprClass, Empty) { }
19835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
198472527137c521ad9330ecb81ccd841159719dc8cdEli Friedman  UnaryExprOrTypeTrait getKind() const {
198572527137c521ad9330ecb81ccd841159719dc8cdEli Friedman    return static_cast<UnaryExprOrTypeTrait>(UnaryExprOrTypeTraitExprBits.Kind);
19862577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  }
19872577743c5650c646fb705df01403707e94f2df04Abramo Bagnara  void setKind(UnaryExprOrTypeTrait K) { UnaryExprOrTypeTraitExprBits.Kind = K;}
19881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
198972527137c521ad9330ecb81ccd841159719dc8cdEli Friedman  bool isArgumentType() const { return UnaryExprOrTypeTraitExprBits.IsType; }
199072527137c521ad9330ecb81ccd841159719dc8cdEli Friedman  QualType getArgumentType() const {
1991c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor    return getArgumentTypeInfo()->getType();
1992c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor  }
19935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TypeSourceInfo *getArgumentTypeInfo() const {
19941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    assert(isArgumentType() && "calling getArgumentType() when arg is expr");
19955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return Argument.Ty;
19965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
19971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getArgumentExpr() {
199883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor    assert(!isArgumentType() && "calling getArgumentExpr() when arg is type");
19995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return static_cast<Expr*>(Argument.Ex);
20005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
20011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Expr *getArgumentExpr() const {
20021237c673c07f9d827129ba02720108816abde562Ted Kremenek    return const_cast<UnaryExprOrTypeTraitExpr*>(this)->getArgumentExpr();
20031237c673c07f9d827129ba02720108816abde562Ted Kremenek  }
20041237c673c07f9d827129ba02720108816abde562Ted Kremenek
20054045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis  void setArgument(Expr *E) {
20064045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis    Argument.Ex = E;
20074045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis    UnaryExprOrTypeTraitExprBits.IsType = false;
20085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
20095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void setArgument(TypeSourceInfo *TInfo) {
20101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Argument.Ty = TInfo;
2011aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff    UnaryExprOrTypeTraitExprBits.IsType = true;
2012aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff  }
20130fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner
20140fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  /// Gets the argument type, or the type of the argument expression, whichever
20150fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  /// is appropriate.
20160fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  QualType getTypeOfArgument() const {
20171d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall    return isArgumentType() ? getArgumentType() : getArgumentExpr()->getType();
20181d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall  }
20191d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall
202042f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  SourceLocation getOperatorLoc() const { return OpLoc; }
20215549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  void setOperatorLoc(SourceLocation L) { OpLoc = L; }
2022e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff
2023aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff  SourceLocation getRParenLoc() const { return RParenLoc; }
202442f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2025f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall
2026f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  SourceLocation getLocStart() const LLVM_READONLY { return OpLoc; }
2027bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
2028bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor
2029bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  static bool classof(const Stmt *T) {
203042f56b50062cd3b3c6b23fdb9053578ae9145664John McCall    return T->getStmtClass() == UnaryExprOrTypeTraitExprClass;
20311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
2032ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor
2033ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  // Iterators
2034ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  child_range children();
2035ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor};
20365549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek
20375549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek//===----------------------------------------------------------------------===//
2038ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor// Postfix Operators.
2039e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff//===----------------------------------------------------------------------===//
2040e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff
2041ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
2042ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregorclass ArraySubscriptExpr : public Expr {
20430fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  enum { LHS, RHS, END_EXPR=2 };
2044ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  Stmt* SubExprs[END_EXPR];
2045ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor  SourceLocation RBracketLoc;
204642f56b50062cd3b3c6b23fdb9053578ae9145664John McCallpublic:
204742f56b50062cd3b3c6b23fdb9053578ae9145664John McCall  ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t,
204842f56b50062cd3b3c6b23fdb9053578ae9145664John McCall                     ExprValueKind VK, ExprObjectKind OK,
204973d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner                     SourceLocation rbracketloc)
20500fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner  : Expr(ArraySubscriptExprClass, t, VK, OK,
20510fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner         lhs->isTypeDependent() || rhs->isTypeDependent(),
20520fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner         lhs->isValueDependent() || rhs->isValueDependent(),
20530fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner         (lhs->isInstantiationDependent() ||
205473d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner          rhs->isInstantiationDependent()),
20550fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner         (lhs->containsUnexpandedParameterPack() ||
205673d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner          rhs->containsUnexpandedParameterPack())),
2057aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff    RBracketLoc(rbracketloc) {
20581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    SubExprs[LHS] = lhs;
20591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    SubExprs[RHS] = rhs;
2060aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff  }
2061aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff
20621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Create an empty array subscript expression.
20631237c673c07f9d827129ba02720108816abde562Ted Kremenek  explicit ArraySubscriptExpr(EmptyShell Shell)
20641237c673c07f9d827129ba02720108816abde562Ted Kremenek    : Expr(ArraySubscriptExprClass, Shell) { }
20651237c673c07f9d827129ba02720108816abde562Ted Kremenek
2066aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff  /// An array access can be written A[4] or 4[A] (both are equivalent).
2067aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff  /// - getBase() and getIdx() always present the normalized view: A[4].
206849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  ///    In this case getBase() returns "A" and getIdx() returns "4".
206949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// - getLHS() and getRHS() present the syntactic view. e.g. for
207049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  ///    4[A] getLHS() returns "4".
207149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// Note: Because vector element access is also written A[4] we must
20720835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  /// predicate the format conversion in getBase and getIdx only on the
2073cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson  /// the type of the RHS, as it is possible for the LHS to be a vector of
20745baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall  /// integer type
20751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); }
2076cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlsson  const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
20770835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  void setLHS(Expr *E) { SubExprs[LHS] = E; }
2078409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson
2079daa8e4e888758d55a7a759dd4a91b83921cef222John McCall  Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); }
2080409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
2081409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  void setRHS(Expr *E) { SubExprs[RHS] = E; }
20825cf86ba6b5a724bf91cb52feade1158f1fbeb605Anders Carlsson
2083cee22421929c91b481f4d1bb85cd48c0f6b7510bAnders Carlsson  Expr *getBase() {
2084cee22421929c91b481f4d1bb85cd48c0f6b7510bAnders Carlsson    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS());
2085409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  }
2086409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson
2087f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  const Expr *getBase() const {
2088f9d68e1dd015972318b2448f75115ff4fc3d5008Anders Carlsson    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS());
2089409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  }
2090409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson
2091409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  Expr *getIdx() {
2092409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS());
2093409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  }
2094409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson
2095409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  const Expr *getIdx() const {
2096409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS());
2097404cd1669c3ba138a9ae0a619bd689cce5aae271John McCall  }
2098409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson
2099409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  SourceLocation getLocStart() const LLVM_READONLY {
2100409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    return getLHS()->getLocStart();
2101409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  }
2102409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  SourceLocation getLocEnd() const LLVM_READONLY { return RBracketLoc; }
2103409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson
2104409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  SourceLocation getRBracketLoc() const { return RBracketLoc; }
2105409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  void setRBracketLoc(SourceLocation L) { RBracketLoc = L; }
2106409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson
2107409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  SourceLocation getExprLoc() const LLVM_READONLY {
2108409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson    return getBase()->getExprLoc();
2109569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor  }
21102bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall
2111f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall  static bool classof(const Stmt *T) {
21122bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall    return T->getStmtClass() == ArraySubscriptExprClass;
2113f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall  }
21142bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall
2115f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall  // Iterators
21162bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall  child_range children() {
2117f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
2118daa8e4e888758d55a7a759dd4a91b83921cef222John McCall  }
2119daa8e4e888758d55a7a759dd4a91b83921cef222John McCall};
2120daa8e4e888758d55a7a759dd4a91b83921cef222John McCall
2121daa8e4e888758d55a7a759dd4a91b83921cef222John McCall
21220ae287a498b8cec2086fe6b7e753cbb3df63e74aJohn McCall/// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
2123f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall/// CallExpr itself represents a normal function call, e.g., "f(x, 2)",
2124daa8e4e888758d55a7a759dd4a91b83921cef222John McCall/// while its subclasses may represent alternative syntax that (semantically)
2125daa8e4e888758d55a7a759dd4a91b83921cef222John McCall/// results in a function call. For example, CXXOperatorCallExpr is
2126daa8e4e888758d55a7a759dd4a91b83921cef222John McCall/// a subclass for overloaded operator calls that use operator syntax, e.g.,
2127daa8e4e888758d55a7a759dd4a91b83921cef222John McCall/// "str1 + str2" to resolve to a function call.
2128daa8e4e888758d55a7a759dd4a91b83921cef222John McCallclass CallExpr : public Expr {
2129daa8e4e888758d55a7a759dd4a91b83921cef222John McCall  enum { FN=0, PREARGS_START=1 };
2130daa8e4e888758d55a7a759dd4a91b83921cef222John McCall  Stmt **SubExprs;
21315082d34e4107a44ac7f07b62f7a6c917e0e6e71eJohn McCall  unsigned NumArgs;
21325082d34e4107a44ac7f07b62f7a6c917e0e6e71eJohn McCall  SourceLocation RParenLoc;
2133f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
2134409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlssonprotected:
2135409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  // These versions of the constructor are for derived classes.
2136409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson  CallExpr(ASTContext& C, StmtClass SC, Expr *fn, unsigned NumPreArgs,
2137409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson           ArrayRef<Expr*> args, QualType t, ExprValueKind VK,
2138409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson           SourceLocation rparenloc);
2139f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  CallExpr(ASTContext &C, StmtClass SC, unsigned NumPreArgs, EmptyShell Empty);
2140f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
2141f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  Stmt *getPreArg(unsigned i) {
2142f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    assert(i < getNumPreArgs() && "Prearg access out of range!");
2143f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    return SubExprs[PREARGS_START+i];
21440835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  }
2145f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  const Stmt *getPreArg(unsigned i) const {
2146f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    assert(i < getNumPreArgs() && "Prearg access out of range!");
2147f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    return SubExprs[PREARGS_START+i];
2148898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
2149898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  void setPreArg(unsigned i, Stmt *PreArg) {
2150898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    assert(i < getNumPreArgs() && "Prearg access out of range!");
2151898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    SubExprs[PREARGS_START+i] = PreArg;
2152898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
2153bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor
2154bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  unsigned getNumPreArgs() const { return CallExprBits.NumPreArgs; }
2155bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor
21568e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCallpublic:
2157daa8e4e888758d55a7a759dd4a91b83921cef222John McCall  CallExpr(ASTContext& C, Expr *fn, ArrayRef<Expr*> args, QualType t,
21588e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall           ExprValueKind VK, SourceLocation rparenloc);
21598e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
2160daa8e4e888758d55a7a759dd4a91b83921cef222John McCall  /// \brief Build an empty call expression.
2161f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty);
21621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2163087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor  const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); }
2164f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  Expr *getCallee() { return cast<Expr>(SubExprs[FN]); }
21658e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  void setCallee(Expr *F) { SubExprs[FN] = F; }
21668e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
21678e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  Decl *getCalleeDecl();
21681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Decl *getCalleeDecl() const {
21690835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis    return const_cast<CallExpr*>(this)->getCalleeDecl();
21708e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  }
21718e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
2172f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson  /// \brief If the callee is a FunctionDecl, return it. Otherwise return 0.
2173f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson  FunctionDecl *getDirectCallee();
21740835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  const FunctionDecl *getDirectCallee() const {
21750835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis    return const_cast<CallExpr*>(this)->getDirectCallee();
2176087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor  }
2177087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor
21786eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// getNumArgs - Return the number of actual arguments to this call.
21796eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  ///
21806eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  unsigned getNumArgs() const { return NumArgs; }
21816eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor
21826eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  /// \brief Retrieve the call arguments.
21836eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor  Expr **getArgs() {
21846eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor    return reinterpret_cast<Expr **>(SubExprs+getNumPreArgs()+PREARGS_START);
218541b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson  }
2186f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  const Expr *const *getArgs() const {
2187f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    return const_cast<CallExpr*>(this)->getArgs();
21888e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall  }
21898e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall
2190f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  /// getArg - Return the specified argument.
2191f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  Expr *getArg(unsigned Arg) {
2192f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    assert(Arg < NumArgs && "Arg access out of range!");
2193f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    return cast<Expr>(SubExprs[Arg+getNumPreArgs()+PREARGS_START]);
2194f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  }
2195f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  const Expr *getArg(unsigned Arg) const {
219641b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson    assert(Arg < NumArgs && "Arg access out of range!");
21971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return cast<Expr>(SubExprs[Arg+getNumPreArgs()+PREARGS_START]);
21984bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt  }
21994bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt
22000835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  /// setArg - Set the specified argument.
22010835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  void setArg(unsigned Arg, Expr *ArgExpr) {
22021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    assert(Arg < NumArgs && "Arg access out of range!");
22030835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis    SubExprs[Arg+getNumPreArgs()+PREARGS_START] = ArgExpr;
22040835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  }
22050835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis
22060835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  /// setNumArgs - This changes the number of arguments present in this call.
22070835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  /// Any orphaned expressions are deleted by this, and any new operands are set
220849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// to null.
220949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  void setNumArgs(ASTContext& C, unsigned NumArgs);
221049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
221149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  typedef ExprIterator arg_iterator;
221249b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff  typedef ConstExprIterator const_arg_iterator;
2213bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor
2214bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor  arg_iterator arg_begin() { return SubExprs+PREARGS_START+getNumPreArgs(); }
2215906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl  arg_iterator arg_end() {
2216bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor    return SubExprs+PREARGS_START+getNumPreArgs()+getNumArgs();
2217bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor  }
2218bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor  const_arg_iterator arg_begin() const {
2219bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor    return SubExprs+PREARGS_START+getNumPreArgs();
2220906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl  }
22211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const_arg_iterator arg_end() const {
2222906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl    return SubExprs+PREARGS_START+getNumPreArgs()+getNumArgs();
2223906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl  }
2224906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl
2225906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl  /// This method provides fast access to all the subexpressions of
2226bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor  /// a CallExpr without going through the slower virtual child_iterator
2227bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor  /// interface.  This provides efficient reverse iteration of the
22280835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  /// subexpressions.  This is currently used for CFG construction.
2229906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl  ArrayRef<Stmt*> getRawSubExprs() {
2230f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    return ArrayRef<Stmt*>(SubExprs,
22315baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall                           getNumPreArgs() + PREARGS_START + getNumArgs());
2232f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  }
22335baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall
223490045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff  /// getNumCommas - Return the number of commas that must have been present in
2235087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor  /// this function call.
2236f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; }
2237f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
2238f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  /// isBuiltinCall - If this is a call to a builtin, return the builtin ID.  If
2239f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  /// not, return 0.
2240f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  unsigned isBuiltinCall() const;
2241f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
22425baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall  /// \brief Returns \c true if this is a call to a builtin which does not
2243f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  /// evaluate side-effects within its arguments.
22445baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall  bool isUnevaluatedBuiltinCall(ASTContext &Ctx) const;
2245f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
2246f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  /// getCallReturnType - Get the return type of the call expr. This is not
2247f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  /// always the type of the expr itself, if the return type is a reference
2248f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  /// type.
22495baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall  QualType getCallReturnType() const;
2250f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
2251f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  SourceLocation getRParenLoc() const { return RParenLoc; }
2252087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
22530835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis
22540835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  SourceLocation getLocStart() const LLVM_READONLY;
22550835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  SourceLocation getLocEnd() const LLVM_READONLY;
225690045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff
22571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
22581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() >= firstCallExprConstant &&
225949b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff           T->getStmtClass() <= lastCallExprConstant;
226049b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff  }
226149b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff
226249b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff  // Iterators
226349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  child_range children() {
22641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return child_range(&SubExprs[0],
226549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor                       &SubExprs[0]+NumArgs+getNumPreArgs()+PREARGS_START);
226649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  }
226749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor};
226849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
226949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// MemberExpr - [C99 6.5.2.3] Structure and Union Members.  X->F and X.F.
227049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor///
22715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass MemberExpr : public Expr {
227249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// Extra data stored in some member expressions.
227349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  struct MemberNameQualifier {
227449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    /// \brief The nested-name-specifier that qualifies the name, including
227549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    /// source-location information.
227649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor    NestedNameSpecifierLoc QualifierLoc;
2277906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl
2278906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl    /// \brief The DeclAccessPair through which the MemberDecl was found due to
22790835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis    /// name qualifiers.
22809d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall    DeclAccessPair FoundDecl;
22819d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  };
22829d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall
228349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// Base - the expression for the base pointer or structure references.  In
228449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// X.F, this is "X".
2285f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  Stmt *Base;
2286f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall
2287f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  /// MemberDecl - This is the decl being referenced by the field/member name.
2288f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  /// In X.F, this is the decl referenced by F.
228949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  ValueDecl *MemberDecl;
2290db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
2291f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  /// MemberDNLoc - Provides source/type location info for the
2292f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  /// declaration name embedded in MemberDecl.
2293db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  DeclarationNameLoc MemberDNLoc;
229449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
22959d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  /// MemberLoc - This is the location of the member name.
22969d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  SourceLocation MemberLoc;
22979d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall
22989d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  /// IsArrow - True if this is "X->F", false if this is "X.F".
22999d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  bool IsArrow : 1;
230049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor
230149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// \brief True if this member expression used a nested-name-specifier to
23029d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall  /// refer to the member, e.g., "x->Base::f", or found its member via a using
230349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// declaration.  When true, a MemberNameQualifier
23041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// structure is allocated immediately after the MemberExpr.
23054bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt  bool HasQualifierOrFoundDecl : 1;
23064bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt
230749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// \brief True if this member expression specified a template keyword
230849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// and/or a template argument list explicitly, e.g., x->f<int>,
230949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// x->template f, x->template f<int>.
231049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// When true, an ASTTemplateKWAndArgsInfo structure and its
23116eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor  /// TemplateArguments (if any) are allocated immediately after
231249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// the MemberExpr or, if the member expression also has a qualifier,
231349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor  /// after the MemberNameQualifier structure.
23146eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor  bool HasTemplateKWAndArgsInfo : 1;
2315b2f9e516327310d95840d442416084508f80c183Steve Naroff
2316b2f9e516327310d95840d442416084508f80c183Steve Naroff  /// \brief True if this member expression refers to a method that
2317f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  /// was resolved from an overloaded set having size greater than 1.
2318f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  bool HadMultipleCandidates : 1;
2319f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
232041b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson  /// \brief Retrieve the qualifier that preceded the member name, if any.
2321f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  MemberNameQualifier *getMemberQualifier() {
232241b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson    assert(HasQualifierOrFoundDecl);
232349b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff    return reinterpret_cast<MemberNameQualifier *> (this + 1);
2324db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  }
2325f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall
2326f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  /// \brief Retrieve the qualifier that preceded the member name, if any.
2327f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  const MemberNameQualifier *getMemberQualifier() const {
2328f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    return const_cast<MemberExpr *>(this)->getMemberQualifier();
2329f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  }
2330f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall
2331f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic:
2332f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall  MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl,
2333f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall             const DeclarationNameInfo &NameInfo, QualType ty,
2334f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall             ExprValueKind VK, ExprObjectKind OK)
2335f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall    : Expr(MemberExprClass, ty, VK, OK,
2336db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor           base->isTypeDependent(),
2337b2f9e516327310d95840d442416084508f80c183Steve Naroff           base->isValueDependent(),
2338db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor           base->isInstantiationDependent(),
2339db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor           base->containsUnexpandedParameterPack()),
2340b2f9e516327310d95840d442416084508f80c183Steve Naroff      Base(base), MemberDecl(memberdecl), MemberDNLoc(NameInfo.getInfo()),
2341db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor      MemberLoc(NameInfo.getLoc()), IsArrow(isarrow),
2342db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor      HasQualifierOrFoundDecl(false), HasTemplateKWAndArgsInfo(false),
23435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      HadMultipleCandidates(false) {
2344b2f9e516327310d95840d442416084508f80c183Steve Naroff    assert(memberdecl->getDeclName() == NameInfo.getName());
23455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
23461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // NOTE: this constructor should be used only when it is known that
23485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // the member name can not provide additional syntactic info
23496eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor  // (i.e., source locations for C++ operator names or type source info
23505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // for constructors, destructors and conversion operators).
23515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl,
23523fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor             SourceLocation l, QualType ty,
23533fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor             ExprValueKind VK, ExprObjectKind OK)
23543fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor    : Expr(MemberExprClass, ty, VK, OK,
23553fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor           base->isTypeDependent(), base->isValueDependent(),
23563fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor           base->isInstantiationDependent(),
23573fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor           base->containsUnexpandedParameterPack()),
23583fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor      Base(base), MemberDecl(memberdecl), MemberDNLoc(), MemberLoc(l),
23593fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor      IsArrow(isarrow),
23603fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor      HasQualifierOrFoundDecl(false), HasTemplateKWAndArgsInfo(false),
23613fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor      HadMultipleCandidates(false) {}
23623fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor
23633fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor  static MemberExpr *Create(ASTContext &C, Expr *base, bool isarrow,
23643fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor                            NestedNameSpecifierLoc QualifierLoc,
23653fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor                            SourceLocation TemplateKWLoc,
23663fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor                            ValueDecl *memberdecl, DeclAccessPair founddecl,
23673fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor                            DeclarationNameInfo MemberNameInfo,
23683fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor                            const TemplateArgumentListInfo *targs,
23693fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor                            QualType ty, ExprValueKind VK, ExprObjectKind OK);
23705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
23715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void setBase(Expr *E) { Base = E; }
23725baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall  Expr *getBase() const { return cast<Expr>(Base); }
23735baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall
237417d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  /// \brief Retrieve the member declaration to which this expression refers.
23750799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  ///
23760799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  /// The returned declaration will either be a FieldDecl or (in C++)
23770799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  /// a CXXMethodDecl.
237817d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  ValueDecl *getMemberDecl() const { return MemberDecl; }
23795549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  void setMemberDecl(ValueDecl *D) { MemberDecl = D; }
23801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Retrieves the declaration found by lookup.
238217d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  DeclAccessPair getFoundDecl() const {
2383f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    if (!HasQualifierOrFoundDecl)
238417d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner      return DeclAccessPair::make(getMemberDecl(),
2385f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                                  getMemberDecl()->getAccess());
2386898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    return getMemberQualifier()->FoundDecl;
2387bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  }
2388bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor
2389bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  /// \brief Determines whether this member expression actually had
2390898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// a C++ nested-name-specifier prior to the name of the member, e.g.,
23911237c673c07f9d827129ba02720108816abde562Ted Kremenek  /// x->Base::foo.
23921237c673c07f9d827129ba02720108816abde562Ted Kremenek  bool hasQualifier() const { return getQualifier() != 0; }
23931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// \brief If the member name was qualified, retrieves the
23955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// nested-name-specifier that precedes the member name. Otherwise, returns
23965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// NULL.
2397db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  NestedNameSpecifier *getQualifier() const {
23981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    if (!HasQualifierOrFoundDecl)
23992de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall      return 0;
2400db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
240117d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner    return getMemberQualifier()->QualifierLoc.getNestedNameSpecifier();
2402db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  }
2403db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
24040799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  /// \brief If the member name was qualified, retrieves the
2405db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  /// nested-name-specifier that precedes the member name, with source-location
2406db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor  /// information.
24075549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  NestedNameSpecifierLoc getQualifierLoc() const {
2408db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor    if (!hasQualifier())
24095549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek      return NestedNameSpecifierLoc();
2410db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor
2411db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor    return getMemberQualifier()->QualifierLoc;
24125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
24135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
24145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// \brief Return the optional template keyword and arguments info.
24151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() {
24165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (!HasTemplateKWAndArgsInfo)
24175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return 0;
24185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
24195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (!HasQualifierOrFoundDecl)
24200799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall      return reinterpret_cast<ASTTemplateKWAndArgsInfo *>(this + 1);
2421a84c02d0f4d63975a1c52b9bb8308d88e9d79352Ted Kremenek
2422063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    return reinterpret_cast<ASTTemplateKWAndArgsInfo *>(
2423063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor                                                      getMemberQualifier() + 1);
2424063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  }
2425063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor
2426063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  /// \brief Return the optional template keyword and arguments info.
2427063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
2428063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor    return const_cast<MemberExpr*>(this)->getTemplateKWAndArgsInfo();
2429063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  }
24305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2431200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl  /// \brief Retrieve the location of the template keyword preceding
24322de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  /// the member name, if any.
24332de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  SourceLocation getTemplateKeywordLoc() const {
24340799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
24352de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
24360799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  }
2437aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl
24382de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  /// \brief Retrieve the location of the left angle bracket starting the
24390799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  /// explicit template argument list following the member name, if any.
2440f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek  SourceLocation getLAngleLoc() const {
24412de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
24420799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall    return getTemplateKWAndArgsInfo()->LAngleLoc;
2443f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek  }
24442de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall
24450799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall  /// \brief Retrieve the location of the right angle bracket ending the
24461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// explicit template argument list following the member name, if any.
24472de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  SourceLocation getRAngleLoc() const {
24480799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall    if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2449aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl    return getTemplateKWAndArgsInfo()->RAngleLoc;
24502de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  }
24510799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall
2452f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek  /// Determines whether the member name was preceded by the template keyword.
24530e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall  bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
24540e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall
24550e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall  /// \brief Determines whether the member name was followed by an
24560e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall  /// explicit template argument list.
24570e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall  bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
24580e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall
24592de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  /// \brief Copies the template arguments (if present) into the given
24602de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  /// structure.
24610e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
24620e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall    if (hasExplicitTemplateArgs())
24630e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall      getExplicitTemplateArgs().copyInto(List);
24640e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall  }
24650e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall
24662de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  /// \brief Retrieve the explicit template argument list that
24672de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall  /// follow the member template name.  This must only be called on an
24680e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall  /// expression with explicit template arguments.
24690e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall  ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
24700e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall    assert(hasExplicitTemplateArgs());
24711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return *getTemplateKWAndArgsInfo();
24721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
24734bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt
24744bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt  /// \brief Retrieve the explicit template argument list that
24755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// followed the member template name.  This must only be called on
24765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// an expression with explicit template arguments.
24771237c673c07f9d827129ba02720108816abde562Ted Kremenek  const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
24781237c673c07f9d827129ba02720108816abde562Ted Kremenek    return const_cast<MemberExpr *>(this)->getExplicitTemplateArgs();
24791237c673c07f9d827129ba02720108816abde562Ted Kremenek  }
24801237c673c07f9d827129ba02720108816abde562Ted Kremenek
24811237c673c07f9d827129ba02720108816abde562Ted Kremenek  /// \brief Retrieves the optional explicit template arguments.
24825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// This points to the same data as getExplicitTemplateArgs(), but
248317d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  /// returns null if there are no explicit template arguments.
2484f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const {
24852333f7727f97018d6742e1e0938133bcfad967abEli Friedman    if (!hasExplicitTemplateArgs()) return 0;
2486f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    return &getExplicitTemplateArgs();
24872333f7727f97018d6742e1e0938133bcfad967abEli Friedman  }
2488bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor
2489bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  /// \brief Retrieve the template arguments provided as part of this
2490bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  /// template-id.
24912333f7727f97018d6742e1e0938133bcfad967abEli Friedman  const TemplateArgumentLoc *getTemplateArgs() const {
24921237c673c07f9d827129ba02720108816abde562Ted Kremenek    if (!hasExplicitTemplateArgs())
24931237c673c07f9d827129ba02720108816abde562Ted Kremenek      return 0;
24945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2495ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor    return getExplicitTemplateArgs().getTemplateArgs();
24961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
24972de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall
24985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// \brief Retrieve the number of template arguments provided as part of this
24995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// template-id.
25005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getNumTemplateArgs() const {
25015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (!hasExplicitTemplateArgs())
25025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return 0;
25035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
25045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return getExplicitTemplateArgs().NumTemplateArgs;
25055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
25065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2507ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  /// \brief Retrieve the member declaration name info.
2508ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  DeclarationNameInfo getMemberNameInfo() const {
25095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return DeclarationNameInfo(MemberDecl->getDeclName(),
2510f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall                               MemberLoc, MemberDNLoc);
2511f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  }
2512f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall
251317d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner  bool isArrow() const { return IsArrow; }
2514f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  void setArrow(bool A) { IsArrow = A; }
2515ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman
2516ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  /// getMemberLoc - Return the location of the "member", in X->F, it is the
25171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// location of 'F'.
25185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation getMemberLoc() const { return MemberLoc; }
25195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void setMemberLoc(SourceLocation L) { MemberLoc = L; }
25205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2521ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  SourceLocation getLocStart() const LLVM_READONLY;
2522ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  SourceLocation getLocEnd() const LLVM_READONLY;
2523ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
2524ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  SourceLocation getExprLoc() const LLVM_READONLY { return MemberLoc; }
2525ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman
2526ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  /// \brief Determine whether the base of this explicit is implicit.
2527ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  bool isImplicitAccess() const {
2528ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman    return getBase() && getBase()->isImplicitCXXThis();
2529ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  }
2530ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
2531ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman  /// \brief Returns true if this member expression refers to a method that
2532ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  /// was resolved from an overloaded set having size greater than 1.
2533ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  bool hadMultipleCandidates() const {
25345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return HadMultipleCandidates;
25351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
25361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Sets the flag telling whether this expression refers to
25375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// a method that was resolved from an overloaded set having size
25385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// greater than 1.
25395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void setHadMultipleCandidates(bool V = true) {
25405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    HadMultipleCandidates = V;
25415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
25425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
25435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
25441237c673c07f9d827129ba02720108816abde562Ted Kremenek    return T->getStmtClass() == MemberExprClass;
25455549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  }
2546f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian
254747e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor  // Iterators
25485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  child_range children() { return child_range(&Base, &Base+1); }
254947e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor
2550f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  friend class ASTReader;
25510943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall  friend class ASTStmtWriter;
25520943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall};
2553898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
2554898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// CompoundLiteralExpr - [C99 6.5.2.5]
2555898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor///
2556898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorclass CompoundLiteralExpr : public Expr {
25571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// LParenLoc - If non-null, this is the location of the left paren in a
2558898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// compound literal like "(int){4}".  This can be null if this is a
2559bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  /// synthesized compound expression.
2560bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  SourceLocation LParenLoc;
2561bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor
2562bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  /// The type as written.  This can be an incomplete array type, in
256347e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor  /// which case the actual expression type will be different.
256447e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor  /// The int part of the pair stores whether this expr is file scope.
25651237c673c07f9d827129ba02720108816abde562Ted Kremenek  llvm::PointerIntPair<TypeSourceInfo *, 1, bool> TInfoAndScope;
25661237c673c07f9d827129ba02720108816abde562Ted Kremenek  Stmt *Init;
25671237c673c07f9d827129ba02720108816abde562Ted Kremenekpublic:
2568f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian  CompoundLiteralExpr(SourceLocation lparenloc, TypeSourceInfo *tinfo,
25691237c673c07f9d827129ba02720108816abde562Ted Kremenek                      QualType T, ExprValueKind VK, Expr *init, bool fileScope)
25705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    : Expr(CompoundLiteralExprClass, T, VK, OK_Ordinary,
2571ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor           tinfo->getType()->isDependentType(),
2572ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor           init->isValueDependent(),
2573ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor           (init->isInstantiationDependent() ||
2574ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor            tinfo->getType()->isInstantiationDependentType()),
2575395a2abf0028968d85958610e393e067885dc14fTed Kremenek           init->containsUnexpandedParameterPack()),
2576395a2abf0028968d85958610e393e067885dc14fTed Kremenek      LParenLoc(lparenloc), TInfoAndScope(tinfo, fileScope), Init(init) {}
25775549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek
2578ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  /// \brief Construct an empty compound literal.
2579395a2abf0028968d85958610e393e067885dc14fTed Kremenek  explicit CompoundLiteralExpr(EmptyShell Empty)
2580395a2abf0028968d85958610e393e067885dc14fTed Kremenek    : Expr(CompoundLiteralExprClass, Empty) { }
2581f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian
2582395a2abf0028968d85958610e393e067885dc14fTed Kremenek  const Expr *getInitializer() const { return cast<Expr>(Init); }
2583af9b96828f9126d993c3e155b8453be62013b735Fariborz Jahanian  Expr *getInitializer() { return cast<Expr>(Init); }
2584395a2abf0028968d85958610e393e067885dc14fTed Kremenek  void setInitializer(Expr *E) { Init = E; }
25851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2586ae2777cfe7d21f73e5a4155082fe20197cec62bdNick Lewycky  bool isFileScope() const { return TInfoAndScope.getInt(); }
2587395a2abf0028968d85958610e393e067885dc14fTed Kremenek  void setFileScope(bool FS) { TInfoAndScope.setInt(FS); }
25885549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek
2589f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian  SourceLocation getLParenLoc() const { return LParenLoc; }
2590f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2591f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian
2592f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian  TypeSourceInfo *getTypeSourceInfo() const {
2593f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian    return TInfoAndScope.getPointer();
2594f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian  }
2595f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian  void setTypeSourceInfo(TypeSourceInfo *tinfo) {
2596f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian    TInfoAndScope.setPointer(tinfo);
2597f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian  }
2598ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor
2599ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor  SourceLocation getLocStart() const LLVM_READONLY {
26005549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek    // FIXME: Init should never be null.
2601ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor    if (!Init)
26025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return SourceLocation();
2603f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian    if (LParenLoc.isInvalid())
2604f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian      return Init->getLocStart();
2605f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian    return LParenLoc;
260647e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor  }
260747e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor  SourceLocation getLocEnd() const LLVM_READONLY {
260847e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor    // FIXME: Init should never be null.
260947e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor    if (!Init)
261047e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor      return SourceLocation();
261147e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor    return Init->getLocEnd();
26125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
26135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
26145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Stmt *T) {
26151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getStmtClass() == CompoundLiteralExprClass;
26161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
26175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
26185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Iterators
26191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  child_range children() { return child_range(&Init, &Init+1); }
26201237c673c07f9d827129ba02720108816abde562Ted Kremenek};
26211237c673c07f9d827129ba02720108816abde562Ted Kremenek
26221237c673c07f9d827129ba02720108816abde562Ted Kremenek/// CastExpr - Base class for type casts, including both implicit
26235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// casts (ImplicitCastExpr) and explicit casts that have some
26245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// representation in the source code (ExplicitCastExpr's derived
26256481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner/// classes).
26266481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattnerclass CastExpr : public Expr {
26275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
26285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  typedef clang::CastKind CastKind;
26295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
26306481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattnerprivate:
26316481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner  Stmt *Op;
2632bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor
26332333f7727f97018d6742e1e0938133bcfad967abEli Friedman  void CheckCastConsistency() const;
26341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26357d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  const CXXBaseSpecifier * const *path_buffer() const {
26361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return const_cast<CastExpr*>(this)->path_buffer();
26377d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  }
26387d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  CXXBaseSpecifier **path_buffer();
26397d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor
26407d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor  void setBasePathSize(unsigned basePathSize) {
26417d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor    CastExprBits.BasePathSize = basePathSize;
26427d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor    assert(CastExprBits.BasePathSize == basePathSize &&
26437d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor           "basePathSize doesn't fit in bits of CastExprBits.BasePathSize!");
26445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
26455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
26465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected:
26471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  CastExpr(StmtClass SC, QualType ty, ExprValueKind VK,
26485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           const CastKind kind, Expr *op, unsigned BasePathSize) :
26497d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor    Expr(SC, ty, VK, OK_Ordinary,
26507d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor         // Cast expressions are type-dependent if the type is
26515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer         // dependent (C++ [temp.dep.expr]p3).
26521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump         ty->isDependentType(),
26535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer         // Cast expressions are value-dependent if the type is
26546481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner         // dependent or if the subexpression is value-dependent.
26551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump         ty->isDependentType() || (op && op->isValueDependent()),
26561237c673c07f9d827129ba02720108816abde562Ted Kremenek         (ty->isInstantiationDependentType() ||
26571237c673c07f9d827129ba02720108816abde562Ted Kremenek          (op && op->isInstantiationDependent())),
26581237c673c07f9d827129ba02720108816abde562Ted Kremenek         (ty->containsUnexpandedParameterPack() ||
26595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer          (op && op->containsUnexpandedParameterPack()))),
2660ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner    Op(op) {
2661ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner    assert(kind != CK_Invalid && "creating cast with invalid cast kind");
2662ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner    CastExprBits.Kind = kind;
2663ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner    setBasePathSize(BasePathSize);
2664f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall#ifndef NDEBUG
2665f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall    CheckCastConsistency();
2666f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall#endif
2667ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  }
26685549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek
2669ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  /// \brief Construct an empty cast.
2670ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  CastExpr(StmtClass SC, EmptyShell Empty, unsigned BasePathSize)
26712333f7727f97018d6742e1e0938133bcfad967abEli Friedman    : Expr(SC, Empty) {
2672d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff    setBasePathSize(BasePathSize);
2673d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff  }
2674f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall
2675bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregorpublic:
26762333f7727f97018d6742e1e0938133bcfad967abEli Friedman  CastKind getCastKind() const { return (CastKind) CastExprBits.Kind; }
26771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setCastKind(CastKind K) { CastExprBits.Kind = K; }
26786a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  const char *getCastKindName() const;
26796a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor
26806a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  Expr *getSubExpr() { return cast<Expr>(Op); }
26815549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  const Expr *getSubExpr() const { return cast<Expr>(Op); }
26825549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  void setSubExpr(Expr *E) { Op = E; }
26836a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor
26846a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  /// \brief Retrieve the cast subexpression as it was written in the source
2685ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  /// code, looking through any implicit casts or other intermediate nodes
2686ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  /// introduced by semantic analysis.
2687ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  Expr *getSubExprAsWritten();
26881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const Expr *getSubExprAsWritten() const {
2689026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner    return const_cast<CastExpr *>(this)->getSubExprAsWritten();
26906a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  }
2691026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner
26926a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor  typedef CXXBaseSpecifier **path_iterator;
26931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  typedef const CXXBaseSpecifier * const *path_const_iterator;
2694ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  bool path_empty() const { return CastExprBits.BasePathSize == 0; }
26951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  unsigned path_size() const { return CastExprBits.BasePathSize; }
2696ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  path_iterator path_begin() { return path_buffer(); }
2697ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  path_iterator path_end() { return path_buffer() + path_size(); }
26981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  path_const_iterator path_begin() const { return path_buffer(); }
26991237c673c07f9d827129ba02720108816abde562Ted Kremenek  path_const_iterator path_end() const { return path_buffer() + path_size(); }
27001237c673c07f9d827129ba02720108816abde562Ted Kremenek
27011237c673c07f9d827129ba02720108816abde562Ted Kremenek  void setCastPath(const CXXCastPath &Path);
2702ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner
2703ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner  static bool classof(const Stmt *T) {
2704d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff    return T->getStmtClass() >= firstCastExprConstant &&
2705d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman           T->getStmtClass() <= lastCastExprConstant;
2706d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
2707d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
2708d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  // Iterators
2709d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  child_range children() { return child_range(&Op, &Op+1); }
2710d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman};
2711d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
2712d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// ImplicitCastExpr - Allows us to explicitly represent implicit type
2713d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// conversions, which have no direct representation in the original
2714d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// source code. For example: converting T[]->T*, void f()->void
2715d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// (*f)(), float->double, short->int, etc.
2716d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman///
2717d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// In C, implicit casts always produce rvalues. However, in C++, an
27185549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek/// implicit cast whose result is being bound to a reference will be
2719d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// an lvalue or xvalue. For example:
2720d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman///
2721d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// @code
2722a88dc3079bedf70a5cfc39791727e43a10383006Nate Begeman/// class Base { };
27231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// class Derived : public Base { };
2724bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor/// Derived &&ref();
272594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor/// void f(Derived d) {
272694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor///   Base& b = d; // initializer is an ImplicitCastExpr
27271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///                // to an lvalue of type Base
272894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor///   Base&& r = ref(); // initializer is an ImplicitCastExpr
272994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor///                     // to an xvalue of type Base
273094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor/// }
273194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor/// @endcode
27321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass ImplicitCastExpr : public CastExpr {
273394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregorprivate:
273494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  ImplicitCastExpr(QualType ty, CastKind kind, Expr *op,
273594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor                   unsigned BasePathLength, ExprValueKind VK)
2736d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, BasePathLength) {
2737d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  }
2738d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
2739d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  /// \brief Construct an empty implicit cast.
27401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit ImplicitCastExpr(EmptyShell Shell, unsigned PathSize)
2741d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    : CastExpr(ImplicitCastExprClass, Shell, PathSize) { }
2742d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
27431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
2744d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  enum OnStack_t { OnStack };
2745d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  ImplicitCastExpr(OnStack_t _, QualType ty, CastKind kind, Expr *op,
2746d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman                   ExprValueKind VK)
2747d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, 0) {
27481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
2749aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
2750aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  static ImplicitCastExpr *Create(ASTContext &Context, QualType T,
2751aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor                                  CastKind Kind, Expr *Operand,
2752d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman                                  const CXXCastPath *BasePath,
2753d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman                                  ExprValueKind Cat);
2754d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
27555549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  static ImplicitCastExpr *CreateEmpty(ASTContext &Context, unsigned PathSize);
2756d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
2757d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  SourceLocation getLocStart() const LLVM_READONLY {
2758d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    return getSubExpr()->getLocStart();
27595549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  }
2760d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  SourceLocation getLocEnd() const LLVM_READONLY {
27611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return getSubExpr()->getLocEnd();
2762888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman  }
276394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
2764dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman  static bool classof(const Stmt *T) {
2765dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman    return T->getStmtClass() == ImplicitCastExprClass;
27669a901bb63990574ff0bcc12ff851d7a71cff8ddbEli Friedman  }
2767d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman};
27681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2769d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmaninline Expr *Expr::IgnoreImpCasts() {
2770d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  Expr *e = this;
2771d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  while (ImplicitCastExpr *ice = dyn_cast<ImplicitCastExpr>(e))
2772d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman    e = ice->getSubExpr();
2773d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman  return e;
2774d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff}
27751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2776d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// ExplicitCastExpr - An explicit cast written in the source
27777976932a1c256d447316ffac58e9821417725e34Eli Friedman/// code.
27787976932a1c256d447316ffac58e9821417725e34Eli Friedman///
27797976932a1c256d447316ffac58e9821417725e34Eli Friedman/// This class is effectively an abstract class, because it provides
27807976932a1c256d447316ffac58e9821417725e34Eli Friedman/// the basic representation of an explicitly-written cast without
27817976932a1c256d447316ffac58e9821417725e34Eli Friedman/// specifying which kind of cast (C cast, functional cast, static
27827976932a1c256d447316ffac58e9821417725e34Eli Friedman/// cast, etc.) was written; specific derived classes represent the
2783d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// particular style of cast and its location information.
27841237c673c07f9d827129ba02720108816abde562Ted Kremenek///
27855549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek/// Unlike implicit casts, explicit cast nodes have two different
2786d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// types: the type that was written into the source code, and the
2787d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// actual type of the expression as determined by semantic
2788f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall/// analysis. These types may differ slightly. For example, in C++ one
2789f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall/// can cast to a reference type, which indicates that the resulting
2790ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor/// expression will be an lvalue or xvalue. The reference type, however,
2791bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor/// will not be used as the type of the expression.
2792bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregorclass ExplicitCastExpr : public CastExpr {
2793bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  /// TInfo - Source type info for the (written) type
2794bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  /// this expression is casting to.
27951237c673c07f9d827129ba02720108816abde562Ted Kremenek  TypeSourceInfo *TInfo;
27961237c673c07f9d827129ba02720108816abde562Ted Kremenek
27971237c673c07f9d827129ba02720108816abde562Ted Kremenekprotected:
27981237c673c07f9d827129ba02720108816abde562Ted Kremenek  ExplicitCastExpr(StmtClass SC, QualType exprTy, ExprValueKind VK,
27991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                   CastKind kind, Expr *op, unsigned PathSize,
28007976932a1c256d447316ffac58e9821417725e34Eli Friedman                   TypeSourceInfo *writtenTy)
280144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor    : CastExpr(SC, exprTy, VK, kind, op, PathSize), TInfo(writtenTy) {}
280244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor
280344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  /// \brief Construct an empty explicit cast.
28047976932a1c256d447316ffac58e9821417725e34Eli Friedman  ExplicitCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize)
28057976932a1c256d447316ffac58e9821417725e34Eli Friedman    : CastExpr(SC, Shell, PathSize) { }
28064ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad
28077976932a1c256d447316ffac58e9821417725e34Eli Friedmanpublic:
28087976932a1c256d447316ffac58e9821417725e34Eli Friedman  /// getTypeInfoAsWritten - Returns the type source info for the type
28097976932a1c256d447316ffac58e9821417725e34Eli Friedman  /// that this expression is casting to.
28104ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  TypeSourceInfo *getTypeInfoAsWritten() const { return TInfo; }
28117976932a1c256d447316ffac58e9821417725e34Eli Friedman  void setTypeInfoAsWritten(TypeSourceInfo *writtenTy) { TInfo = writtenTy; }
28127976932a1c256d447316ffac58e9821417725e34Eli Friedman
28137976932a1c256d447316ffac58e9821417725e34Eli Friedman  /// getTypeAsWritten - Returns the type that this expression is
28145549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  /// casting to, as written in the source code.
281544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  QualType getTypeAsWritten() const { return TInfo->getType(); }
28165549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek
281744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  static bool classof(const Stmt *T) {
28185549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek     return T->getStmtClass() >= firstExplicitCastExprConstant &&
281944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor            T->getStmtClass() <= lastExplicitCastExprConstant;
282044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  }
282144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor};
282244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor
28231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style
282444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor/// cast in C++ (C++ [expr.cast]), which uses the syntax
282544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor/// (Type)expr. For example: @c (int)f.
28261237c673c07f9d827129ba02720108816abde562Ted Kremenekclass CStyleCastExpr : public ExplicitCastExpr {
2827d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  SourceLocation LPLoc; // the location of the left paren
2828d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  SourceLocation RPLoc; // the location of the right paren
2829d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff
2830d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff  CStyleCastExpr(QualType exprTy, ExprValueKind vk, CastKind kind, Expr *op,
28311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                 unsigned PathSize, TypeSourceInfo *writtenTy,
2832d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff                 SourceLocation l, SourceLocation r)
2833d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff    : ExplicitCastExpr(CStyleCastExprClass, exprTy, vk, kind, op, PathSize,
28341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                       writtenTy), LPLoc(l), RPLoc(r) {}
28351237c673c07f9d827129ba02720108816abde562Ted Kremenek
28361237c673c07f9d827129ba02720108816abde562Ted Kremenek  /// \brief Construct an empty C-style explicit cast.
28371237c673c07f9d827129ba02720108816abde562Ted Kremenek  explicit CStyleCastExpr(EmptyShell Shell, unsigned PathSize)
2838d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff    : ExplicitCastExpr(CStyleCastExprClass, Shell, PathSize) { }
2839d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff
28402d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorpublic:
28412d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  static CStyleCastExpr *Create(ASTContext &Context, QualType T,
28422d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor                                ExprValueKind VK, CastKind K,
28432d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor                                Expr *Op, const CXXCastPath *BasePath,
28442d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor                                TypeSourceInfo *WrittenTy, SourceLocation L,
28452d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor                                SourceLocation R);
28462d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
28472d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  static CStyleCastExpr *CreateEmpty(ASTContext &Context, unsigned PathSize);
28482d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
28492d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  SourceLocation getLParenLoc() const { return LPLoc; }
28502d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  void setLParenLoc(SourceLocation L) { LPLoc = L; }
28511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2852bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  SourceLocation getRParenLoc() const { return RPLoc; }
2853f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  void setRParenLoc(SourceLocation L) { RPLoc = L; }
28542d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
285544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  SourceLocation getLocStart() const LLVM_READONLY { return LPLoc; }
285644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  SourceLocation getLocEnd() const LLVM_READONLY {
285744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor    return getSubExpr()->getLocEnd();
28582d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  }
28592d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
286044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor  static bool classof(const Stmt *T) {
28612d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor    return T->getStmtClass() == CStyleCastExprClass;
28622d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor  }
28632d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor};
28642d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor
28652d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// \brief A builtin binary operation expression such as "x + y" or "x <= y".
28661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
28672d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// This expression node kind describes a builtin binary operation,
28682d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// such as "x + y" for integer values "x" and "y". The operands will
28691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// already have been converted to appropriate types (e.g., by
28702d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// performing promotions or conversions).
28712d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor///
28722d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// In C++, where operators may be overloaded, a different kind of
28732d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// expression node (CXXOperatorCallExpr) is used to express the
28742d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// invocation of an overloaded operator with operator syntax. Within
287574626d6ef2e194fcc911e071556660ff331eb4a8Zhongxing Xu/// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is
28767c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson/// used to store an expression "x + y" depends on the subexpressions
28775549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek/// for x and y. If neither x or y is type-dependent, and the "+"
28782cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara/// operator resolves to a built-in operation, BinaryOperator will be
28797c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson/// used to express the computation (x and y may still be
28807c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson/// value-dependent). If either x or y is type-dependent, or if the
28812cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara/// "+" resolves to an overloaded operator, CXXOperatorCallExpr will
28822cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara/// be used to express the computation.
2883f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCallclass BinaryOperator : public Expr {
2884bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregorpublic:
2885bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  typedef BinaryOperatorKind Opcode;
2886bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor
28872cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnaraprivate:
28887c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  unsigned Opc : 6;
28897c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson
28901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // Records the FP_CONTRACT pragma status at the point that this binary
289174626d6ef2e194fcc911e071556660ff331eb4a8Zhongxing Xu  // operator was parsed. This bit is only meaningful for operations on
2892d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  // floating point types. For all other types it should default to
2893d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  // false.
28945549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  unsigned FPContractable : 1;
28955549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  SourceLocation OpLoc;
2896d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
2897d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  enum { LHS, RHS, END_EXPR };
28982cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara  Stmt* SubExprs[END_EXPR];
28992cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnarapublic:
29002cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara
2901d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
2902d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor                 ExprValueKind VK, ExprObjectKind OK,
29031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                 SourceLocation opLoc, bool fpContractable)
2904d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor    : Expr(BinaryOperatorClass, ResTy, VK, OK,
2905d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor           lhs->isTypeDependent() || rhs->isTypeDependent(),
2906d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor           lhs->isValueDependent() || rhs->isValueDependent(),
29077c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson           (lhs->isInstantiationDependent() ||
29087c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson            rhs->isInstantiationDependent()),
29091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           (lhs->containsUnexpandedParameterPack() ||
29107c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson            rhs->containsUnexpandedParameterPack())),
29117c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson      Opc(opc), FPContractable(fpContractable), OpLoc(opLoc) {
29127c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson    SubExprs[LHS] = lhs;
29137c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson    SubExprs[RHS] = rhs;
29141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    assert(!isCompoundAssignmentOp() &&
29157c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson           "Use CompoundAssignOperator for compound assignments");
29167c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  }
29171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
29187c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson  /// \brief Construct an empty binary operator.
29191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit BinaryOperator(EmptyShell Empty)
29204c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    : Expr(BinaryOperatorClass, Empty), Opc(BO_Comma) { }
29214c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
29224c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  SourceLocation getExprLoc() const LLVM_READONLY { return OpLoc; }
29234c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  SourceLocation getOperatorLoc() const { return OpLoc; }
29244c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  void setOperatorLoc(SourceLocation L) { OpLoc = L; }
29254c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
29264c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  Opcode getOpcode() const { return static_cast<Opcode>(Opc); }
29274c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  void setOpcode(Opcode O) { Opc = O; }
29284c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
2929196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
29304c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  void setLHS(Expr *E) { SubExprs[LHS] = E; }
29314c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
29324c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  void setRHS(Expr *E) { SubExprs[RHS] = E; }
29334c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
29344c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  SourceLocation getLocStart() const LLVM_READONLY {
29354c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    return getLHS()->getLocStart();
29364c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  }
29374c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  SourceLocation getLocEnd() const LLVM_READONLY {
2938196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner    return getRHS()->getLocEnd();
29394c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  }
29404c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
29414c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
29424c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// corresponds to, e.g. "<<=".
29434c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  static StringRef getOpcodeStr(Opcode Op);
29444c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
29454c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  StringRef getOpcodeStr() const { return getOpcodeStr(getOpcode()); }
29463498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
29474c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// \brief Retrieve the binary opcode that corresponds to the given
29484c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// overloaded operator.
29494c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  static Opcode getOverloadedOpcode(OverloadedOperatorKind OO);
2950196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner
29514c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// \brief Retrieve the overloaded operator kind that corresponds to
29524c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// the given binary opcode.
29534c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
29544c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
29554c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// predicates to categorize the respective opcodes.
29564c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  bool isPtrMemOp() const { return Opc == BO_PtrMemD || Opc == BO_PtrMemI; }
295766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  bool isMultiplicativeOp() const { return Opc >= BO_Mul && Opc <= BO_Rem; }
2958ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek  static bool isAdditiveOp(Opcode Opc) { return Opc == BO_Add || Opc==BO_Sub; }
2959709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  bool isAdditiveOp() const { return isAdditiveOp(getOpcode()); }
2960709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  static bool isShiftOp(Opcode Opc) { return Opc == BO_Shl || Opc == BO_Shr; }
296166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  bool isShiftOp() const { return isShiftOp(getOpcode()); }
29621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
29634c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  static bool isBitwiseOp(Opcode Opc) { return Opc >= BO_And && Opc <= BO_Or; }
29644c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  bool isBitwiseOp() const { return isBitwiseOp(getOpcode()); }
29654c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
29664c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  static bool isRelationalOp(Opcode Opc) { return Opc >= BO_LT && Opc<=BO_GE; }
29670bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  bool isRelationalOp() const { return isRelationalOp(getOpcode()); }
29680bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor
29690bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  static bool isEqualityOp(Opcode Opc) { return Opc == BO_EQ || Opc == BO_NE; }
29700bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  bool isEqualityOp() const { return isEqualityOp(getOpcode()); }
2971a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor
2972a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  static bool isComparisonOp(Opcode Opc) { return Opc >= BO_LT && Opc<=BO_NE; }
2973a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor  bool isComparisonOp() const { return isComparisonOp(getOpcode()); }
2974a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor
297566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  static Opcode negateComparisonOp(Opcode Opc) {
2976709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek    switch (Opc) {
2977709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek    default:
2978ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek      llvm_unreachable("Not a comparsion operator.");
2979d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    case BO_LT: return BO_GE;
2980d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    case BO_GT: return BO_LE;
2981709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek    case BO_LE: return BO_GT;
2982709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek    case BO_GE: return BO_LT;
29831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    case BO_EQ: return BO_NE;
2984ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek    case BO_NE: return BO_EQ;
29851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    }
2986aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  }
2987aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor
2988aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor  static Opcode reverseComparisonOp(Opcode Opc) {
298916c5dea6c2d3e4cf529de9d9b37f6a40441acb2cChris Lattner    switch (Opc) {
2990c5ae899b4bbf65488445316c63168079177db0edSteve Naroff    default:
29914c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor      llvm_unreachable("Not a comparsion operator.");
299266b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson    case BO_LT: return BO_GT;
29931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    case BO_GT: return BO_LT;
299416c5dea6c2d3e4cf529de9d9b37f6a40441acb2cChris Lattner    case BO_LE: return BO_GE;
2995c5ae899b4bbf65488445316c63168079177db0edSteve Naroff    case BO_GE: return BO_LE;
29964c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    case BO_EQ:
299766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson    case BO_NE:
29981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      return Opc;
29991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    }
3000c5ae899b4bbf65488445316c63168079177db0edSteve Naroff  }
30019e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff
30029e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff  static bool isLogicalOp(Opcode Opc) { return Opc == BO_LAnd || Opc==BO_LOr; }
3003c5ae899b4bbf65488445316c63168079177db0edSteve Naroff  bool isLogicalOp() const { return isLogicalOp(getOpcode()); }
3004fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor
3005709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  static bool isAssignmentOp(Opcode Opc) {
30061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return Opc >= BO_Assign && Opc <= BO_OrAssign;
30074c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  }
30084c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  bool isAssignmentOp() const { return isAssignmentOp(getOpcode()); }
30094c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
30104c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  static bool isCompoundAssignmentOp(Opcode Opc) {
30114c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    return Opc > BO_Assign && Opc <= BO_OrAssign;
30124c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  }
30134c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  bool isCompoundAssignmentOp() const {
30144c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    return isCompoundAssignmentOp(getOpcode());
30154c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  }
30164c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  static Opcode getOpForCompoundAssignment(Opcode Opc) {
30174c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    assert(isCompoundAssignmentOp(Opc));
30184c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    if (Opc >= BO_AndAssign)
30194c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor      return Opcode(unsigned(Opc) - BO_AndAssign + BO_And);
30204c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    else
30214c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor      return Opcode(unsigned(Opc) - BO_MulAssign + BO_Mul);
3022709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek  }
3023c5ae899b4bbf65488445316c63168079177db0edSteve Naroff
30240bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  static bool isShiftAssignOp(Opcode Opc) {
30250bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor    return Opc == BO_ShlAssign || Opc == BO_ShrAssign;
30260bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  }
30270bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  bool isShiftAssignOp() const {
30280bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor    return isShiftAssignOp(getOpcode());
30290bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  }
30300bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor
30310bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor  static bool classof(const Stmt *S) {
30320bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor    return S->getStmtClass() >= firstBinaryOperatorConstant &&
3033c5ae899b4bbf65488445316c63168079177db0edSteve Naroff           S->getStmtClass() <= lastBinaryOperatorConstant;
3034c5ae899b4bbf65488445316c63168079177db0edSteve Naroff  }
3035b3eef68111ffc220e449be96da1747998c057790Douglas Gregor
3036b3eef68111ffc220e449be96da1747998c057790Douglas Gregor  // Iterators
3037b3eef68111ffc220e449be96da1747998c057790Douglas Gregor  child_range children() {
30381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
3039d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  }
3040d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
3041d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  // Set the FP contractability status of this operator. Only meaningful for
304287fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor  // operations on floating point types.
304387fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor  void setFPContractable(bool FPC) { FPContractable = FPC; }
30444c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
30454c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  // Get the FP contractability status of this operator. Only meaningful for
30464c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  // operations on floating point types.
30471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool isFPContractable() const { return FPContractable; }
30484c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
30494c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregorprotected:
30504c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
3051a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor                 ExprValueKind VK, ExprObjectKind OK,
30521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                 SourceLocation opLoc, bool fpContractable, bool dead2)
3053d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    : Expr(CompoundAssignOperatorClass, ResTy, VK, OK,
3054a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor           lhs->isTypeDependent() || rhs->isTypeDependent(),
3055a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor           lhs->isValueDependent() || rhs->isValueDependent(),
3056c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek           (lhs->isInstantiationDependent() ||
3057c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek            rhs->isInstantiationDependent()),
305866b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson           (lhs->containsUnexpandedParameterPack() ||
30591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump            rhs->containsUnexpandedParameterPack())),
306066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson      Opc(opc), FPContractable(fpContractable), OpLoc(opLoc) {
306166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson    SubExprs[LHS] = lhs;
30621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    SubExprs[RHS] = rhs;
306366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  }
306466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson
306566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  BinaryOperator(StmtClass SC, EmptyShell Empty)
30661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    : Expr(SC, Empty), Opc(BO_MulAssign) { }
3067709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek};
30688111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu
3069709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep
30708111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu/// track of the type the operation is performed in.  Due to the semantics of
30711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// these operators, the operands are promoted, the arithmetic performed, an
3072ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek/// implicit conversion back to the result type done, then the assignment takes
30738111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu/// place.  This captures the intermediate type which the computation is done
3074ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek/// in.
30758111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xuclass CompoundAssignOperator : public BinaryOperator {
3076ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek  QualType ComputationLHSType;
30778111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu  QualType ComputationResultType;
3078ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenekpublic:
30798111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu  CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResType,
308066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson                         ExprValueKind VK, ExprObjectKind OK,
308166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson                         QualType CompLHSType, QualType CompResultType,
308205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                         SourceLocation OpLoc, bool fpContractable)
308305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    : BinaryOperator(lhs, rhs, opc, ResType, VK, OK, OpLoc, fpContractable,
308405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                     true),
308505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ComputationLHSType(CompLHSType),
308605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      ComputationResultType(CompResultType) {
308705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    assert(isCompoundAssignmentOp() &&
308805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor           "Only should be used for compound assignments");
30891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
309005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
309105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// \brief Build an empty compound assignment operator expression.
309205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  explicit CompoundAssignOperator(EmptyShell Empty)
309305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    : BinaryOperator(CompoundAssignOperatorClass, Empty) { }
309405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
309505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  // The two computation types are the type the LHS is converted
309605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  // to for the computation and the type of the result; the two are
309705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  // distinct in a few cases (specifically, int+=ptr and ptr-=ptr).
309805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  QualType getComputationLHSType() const { return ComputationLHSType; }
309905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  void setComputationLHSType(QualType T) { ComputationLHSType = T; }
310005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
310105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  QualType getComputationResultType() const { return ComputationResultType; }
310205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  void setComputationResultType(QualType T) { ComputationResultType = T; }
3103ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
3104ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  static bool classof(const Stmt *S) {
3105ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor    return S->getStmtClass() == CompoundAssignOperatorClass;
3106ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  }
3107ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor};
310805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
310905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// AbstractConditionalOperator - An abstract base class for
311005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// ConditionalOperator and BinaryConditionalOperator.
311105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorclass AbstractConditionalOperator : public Expr {
3112eeae8f072748affce25ab4064982626361293390Douglas Gregor  SourceLocation QuestionLoc, ColonLoc;
311305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  friend class ASTStmtReader;
3114eeae8f072748affce25ab4064982626361293390Douglas Gregor
311505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorprotected:
311605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  AbstractConditionalOperator(StmtClass SC, QualType T,
311705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                              ExprValueKind VK, ExprObjectKind OK,
311805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                              bool TD, bool VD, bool ID,
3119ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor                              bool ContainsUnexpandedParameterPack,
3120ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor                              SourceLocation qloc,
3121ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor                              SourceLocation cloc)
3122ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor    : Expr(SC, T, VK, OK, TD, VD, ID, ContainsUnexpandedParameterPack),
312305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor      QuestionLoc(qloc), ColonLoc(cloc) {}
312405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
312505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  AbstractConditionalOperator(StmtClass SC, EmptyShell Empty)
312605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    : Expr(SC, Empty) { }
312705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
3128ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorpublic:
3129319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor  // getCond - Return the expression representing the condition for
3130ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  //   the ?: operator.
3131eeae8f072748affce25ab4064982626361293390Douglas Gregor  Expr *getCond() const;
31329ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor
31339ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor  // getTrueExpr - Return the subexpression representing the value of
313405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  //   the expression if the condition evaluates to true.
3135d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  Expr *getTrueExpr() const;
3136d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
3137d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  // getFalseExpr - Return the subexpression representing the value of
3138d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  //   the expression if the condition evaluates to false.  This is
313905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  //   the same as getRHS.
314005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Expr *getFalseExpr() const;
314105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
314205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  SourceLocation getQuestionLoc() const { return QuestionLoc; }
314305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  SourceLocation getColonLoc() const { return ColonLoc; }
314405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
314505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  static bool classof(const Stmt *T) {
314605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    return T->getStmtClass() == ConditionalOperatorClass ||
314705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor           T->getStmtClass() == BinaryConditionalOperatorClass;
314805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
31491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump};
315005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
315105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// ConditionalOperator - The ?: ternary operator.  The GNU "missing
31521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// middle" extension is a BinaryConditionalOperator.
315305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorclass ConditionalOperator : public AbstractConditionalOperator {
315405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  enum { COND, LHS, RHS, END_EXPR };
315505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
315605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
315705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  friend class ASTStmtReader;
315805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorpublic:
315905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  ConditionalOperator(Expr *cond, SourceLocation QLoc, Expr *lhs,
316005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                      SourceLocation CLoc, Expr *rhs,
316105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                      QualType t, ExprValueKind VK, ExprObjectKind OK)
316205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    : AbstractConditionalOperator(ConditionalOperatorClass, t, VK, OK,
316305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor           // FIXME: the type of the conditional operator doesn't
316405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor           // depend on the type of the conditional, but the standard
316505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor           // seems to imply that it could. File a bug!
316605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor           (lhs->isTypeDependent() || rhs->isTypeDependent()),
316705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor           (cond->isValueDependent() || lhs->isValueDependent() ||
31681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump            rhs->isValueDependent()),
316905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor           (cond->isInstantiationDependent() ||
317005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor            lhs->isInstantiationDependent() ||
317105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor            rhs->isInstantiationDependent()),
317205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor           (cond->containsUnexpandedParameterPack() ||
317305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor            lhs->containsUnexpandedParameterPack() ||
317405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor            rhs->containsUnexpandedParameterPack()),
317505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                                  QLoc, CLoc) {
317605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    SubExprs[COND] = cond;
317705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    SubExprs[LHS] = lhs;
317805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    SubExprs[RHS] = rhs;
317905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
318005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
318105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// \brief Build an empty conditional operator.
318205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  explicit ConditionalOperator(EmptyShell Empty)
318305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    : AbstractConditionalOperator(ConditionalOperatorClass, Empty) { }
318405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
318505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  // getCond - Return the expression representing the condition for
318605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  //   the ?: operator.
318705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
318805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
318905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  // getTrueExpr - Return the subexpression representing the value of
319005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  //   the expression if the condition evaluates to true.
319105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Expr *getTrueExpr() const { return cast<Expr>(SubExprs[LHS]); }
319205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
319305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  // getFalseExpr - Return the subexpression representing the value of
3194ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  //   the expression if the condition evaluates to false.  This is
3195ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  //   the same as getRHS.
319605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); }
31971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
31981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
319905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
320005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
320105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  SourceLocation getLocStart() const LLVM_READONLY {
320205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    return getCond()->getLocStart();
320305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
320405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  SourceLocation getLocEnd() const LLVM_READONLY {
320505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    return getRHS()->getLocEnd();
32061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
320705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
320805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  static bool classof(const Stmt *T) {
320905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    return T->getStmtClass() == ConditionalOperatorClass;
321005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
321105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
321205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  // Iterators
321305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  child_range children() {
321405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
321505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
32161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump};
321705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
321805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// BinaryConditionalOperator - The GNU extension to the conditional
321905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// operator which allows the middle operand to be omitted.
322005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor///
322105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// This is a different expression kind on the assumption that almost
322205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// every client ends up needing to know that these are different.
322305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorclass BinaryConditionalOperator : public AbstractConditionalOperator {
322405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  enum { COMMON, COND, LHS, RHS, NUM_SUBEXPRS };
322505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
322605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// - the common condition/left-hand-side expression, which will be
322705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  ///   evaluated as the opaque value
322805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// - the condition, expressed in terms of the opaque value
322905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// - the left-hand-side, expressed in terms of the opaque value
323005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// - the right-hand-side
323105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Stmt *SubExprs[NUM_SUBEXPRS];
323205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  OpaqueValueExpr *OpaqueValue;
323305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
323405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  friend class ASTStmtReader;
323505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorpublic:
323605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  BinaryConditionalOperator(Expr *common, OpaqueValueExpr *opaqueValue,
323705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                            Expr *cond, Expr *lhs, Expr *rhs,
323805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                            SourceLocation qloc, SourceLocation cloc,
323905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                            QualType t, ExprValueKind VK, ExprObjectKind OK)
324005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    : AbstractConditionalOperator(BinaryConditionalOperatorClass, t, VK, OK,
324105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor           (common->isTypeDependent() || rhs->isTypeDependent()),
324205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor           (common->isValueDependent() || rhs->isValueDependent()),
324305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor           (common->isInstantiationDependent() ||
324487f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor            rhs->isInstantiationDependent()),
324587f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor           (common->containsUnexpandedParameterPack() ||
324687f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor            rhs->containsUnexpandedParameterPack()),
324787f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor                                  qloc, cloc),
324887f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor      OpaqueValue(opaqueValue) {
324905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    SubExprs[COMMON] = common;
325005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    SubExprs[COND] = cond;
325105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    SubExprs[LHS] = lhs;
325205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    SubExprs[RHS] = rhs;
325305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    assert(OpaqueValue->getSourceExpr() == common && "Wrong opaque value");
325405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
325505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
325605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// \brief Build an empty conditional operator.
325705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  explicit BinaryConditionalOperator(EmptyShell Empty)
325805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    : AbstractConditionalOperator(BinaryConditionalOperatorClass, Empty) { }
325905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
326005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// \brief getCommon - Return the common expression, written to the
326105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  ///   left of the condition.  The opaque value will be bound to the
326205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  ///   result of this expression.
326305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Expr *getCommon() const { return cast<Expr>(SubExprs[COMMON]); }
326405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
326505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// \brief getOpaqueValue - Return the opaque value placeholder.
326605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  OpaqueValueExpr *getOpaqueValue() const { return OpaqueValue; }
326705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
326805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// \brief getCond - Return the condition expression; this is defined
326905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  ///   in terms of the opaque value.
327005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
32714c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
3272d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  /// \brief getTrueExpr - Return the subexpression which will be
3273d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  ///   evaluated if the condition evaluates to true;  this is defined
3274d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  ///   in terms of the opaque value.
3275d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  Expr *getTrueExpr() const {
3276d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    return cast<Expr>(SubExprs[LHS]);
3277d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  }
32784c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor
32794c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  /// \brief getFalseExpr - Return the subexpression which will be
32804c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  ///   evaluated if the condnition evaluates to false; this is
32814c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  ///   defined in terms of the opaque value.
32824c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor  Expr *getFalseExpr() const {
32834c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor    return cast<Expr>(SubExprs[RHS]);
328405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
328505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
32861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation getLocStart() const LLVM_READONLY {
328705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    return getCommon()->getLocStart();
328805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
328905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  SourceLocation getLocEnd() const LLVM_READONLY {
3290eeae8f072748affce25ab4064982626361293390Douglas Gregor    return getFalseExpr()->getLocEnd();
329105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
3292d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
3293d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  static bool classof(const Stmt *T) {
329405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    return T->getStmtClass() == BinaryConditionalOperatorClass;
329505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  }
329605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
329705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  // Iterators
329805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  child_range children() {
3299ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor    return child_range(SubExprs, SubExprs + NUM_SUBEXPRS);
33001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
33011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump};
3302ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor
330305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorinline Expr *AbstractConditionalOperator::getCond() const {
3304cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek  if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this))
3305cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek    return co->getCond();
3306cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek  return cast<BinaryConditionalOperator>(this)->getCond();
3307cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek}
3308cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek
3309cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenekinline Expr *AbstractConditionalOperator::getTrueExpr() const {
3310cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek  if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this))
3311cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek    return co->getTrueExpr();
3312cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek  return cast<BinaryConditionalOperator>(this)->getTrueExpr();
3313711997184366d584c9c437102cae1e9d9927b986Douglas Gregor}
3314711997184366d584c9c437102cae1e9d9927b986Douglas Gregor
3315c302113179a1c2b1254224ea9b6f5316ceeb375cSean Huntinline Expr *AbstractConditionalOperator::getFalseExpr() const {
3316319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor  if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this))
3317d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    return co->getFalseExpr();
331805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  return cast<BinaryConditionalOperator>(this)->getFalseExpr();
331905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}
332005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
332105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// AddrLabelExpr - The GNU address of label extension, representing &&label.
332205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorclass AddrLabelExpr : public Expr {
332305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  SourceLocation AmpAmpLoc, LabelLoc;
332405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  LabelDecl *Label;
3325d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregorpublic:
332605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelDecl *L,
332705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor                QualType t)
3328eeae8f072748affce25ab4064982626361293390Douglas Gregor    : Expr(AddrLabelExprClass, t, VK_RValue, OK_Ordinary, false, false, false,
3329eeae8f072748affce25ab4064982626361293390Douglas Gregor           false),
3330d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor      AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {}
333105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
333205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// \brief Build an empty address of a label expression.
33331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit AddrLabelExpr(EmptyShell Empty)
333405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    : Expr(AddrLabelExprClass, Empty) { }
333505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
333605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; }
333705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; }
333805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  SourceLocation getLabelLoc() const { return LabelLoc; }
333905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  void setLabelLoc(SourceLocation L) { LabelLoc = L; }
334005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
3341d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  SourceLocation getLocStart() const LLVM_READONLY { return AmpAmpLoc; }
3342d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  SourceLocation getLocEnd() const LLVM_READONLY { return LabelLoc; }
3343d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
3344d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  LabelDecl *getLabel() const { return Label; }
3345d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  void setLabel(LabelDecl *L) { Label = L; }
3346d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
3347d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  static bool classof(const Stmt *T) {
3348d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor    return T->getStmtClass() == AddrLabelExprClass;
3349d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  }
3350d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
3351d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  // Iterators
3352d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  child_range children() { return child_range(); }
3353d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor};
3354d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
3355d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
3356d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor/// The StmtExpr contains a single CompoundStmt node, which it evaluates and
3357d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor/// takes the value of the last subexpression.
3358d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor///
3359d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor/// A StmtExpr is always an r-value; values "returned" out of a
3360d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor/// StmtExpr will be copied.
3361ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorclass StmtExpr : public Expr {
3362ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  Stmt *SubStmt;
3363319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor  SourceLocation LParenLoc, RParenLoc;
3364ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorpublic:
3365ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor  // FIXME: Does type-dependence need to be computed differently?
336605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  // FIXME: Do we need to compute instantiation instantiation-dependence for
336705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  // statements? (ugh!)
336805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  StmtExpr(CompoundStmt *substmt, QualType T,
33691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump           SourceLocation lp, SourceLocation rp) :
337005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    Expr(StmtExprClass, T, VK_RValue, OK_Ordinary,
337105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor         T->isDependentType(), false, false, false),
337205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor    SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) { }
337305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor
337405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  /// \brief Build an empty statement expression.
33751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { }
33763498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
33773498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); }
33783498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); }
33793498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  void setSubStmt(CompoundStmt *S) { SubStmt = S; }
33803498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
33811a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor  SourceLocation getLocStart() const LLVM_READONLY { return LParenLoc; }
33821a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor  SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
33833498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
33841a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor  SourceLocation getLParenLoc() const { return LParenLoc; }
33851a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
33861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation getRParenLoc() const { return RParenLoc; }
33873498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
33881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3389f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  static bool classof(const Stmt *T) {
3390bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor    return T->getStmtClass() == StmtExprClass;
33913498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  }
3392d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor
3393d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  // Iterators
3394d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor  child_range children() { return child_range(&SubStmt, &SubStmt+1); }
3395d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor};
33961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
33973498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
33983498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// ShuffleVectorExpr - clang-specific builtin-in function
33993498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// __builtin_shufflevector.
34003498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// This AST node represents a operator that does a constant
34013498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// shuffle, similar to LLVM's shufflevector instruction. It takes
34023498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// two vectors and a variable number of constant indices,
34033498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// and returns the appropriately shuffled vector.
34043498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregorclass ShuffleVectorExpr : public Expr {
34053498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor  SourceLocation BuiltinLoc, RParenLoc;
34063498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor
34071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // SubExprs - the list of values passed to the __builtin_shufflevector
340805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  // function. The first two are vectors, and the rest are constant
340905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor  // indices.  The number of values in this list is always
34102ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  // 2+the number of indices in the vector type.
34112ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  Stmt **SubExprs;
34122ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  unsigned NumExprs;
34132ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
34142ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanpublic:
34152ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  ShuffleVectorExpr(ASTContext &C, ArrayRef<Expr*> args, QualType Type,
34162ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman                    SourceLocation BLoc, SourceLocation RP);
34171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
34182ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  /// \brief Build an empty vector-shuffle expression.
34192ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  explicit ShuffleVectorExpr(EmptyShell Empty)
34202ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman    : Expr(ShuffleVectorExprClass, Empty), SubExprs(0) { }
342137bdfe284ad365f753741d1d89c078c148b3f4afArgyrios Kyrtzidis
34221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
34232ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
34241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
34251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation getRParenLoc() const { return RParenLoc; }
34262ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
34272ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
34282ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  SourceLocation getLocStart() const LLVM_READONLY { return BuiltinLoc; }
34291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
34301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
34312ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  static bool classof(const Stmt *T) {
34322ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman    return T->getStmtClass() == ShuffleVectorExprClass;
34332ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  }
34342ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
343583ddad3ab513f5d73698cf9fbeb4ed3f011bc3b9Douglas Gregor  /// getNumSubExprs - Return the size of the SubExprs array.  This includes the
34361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// constant expression, the actual arguments passed in, and the function
34372ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  /// pointers.
34382ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  unsigned getNumSubExprs() const { return NumExprs; }
34392ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
34402ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  /// \brief Retrieve the array of expressions.
34412ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  Expr **getSubExprs() { return reinterpret_cast<Expr **>(SubExprs); }
34421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
34432ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  /// getExpr - Return the Expr at the specified index.
34441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getExpr(unsigned Index) {
34452ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman    assert((Index < NumExprs) && "Arg access out of range!");
34462ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman    return cast<Expr>(SubExprs[Index]);
34471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
34482ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  const Expr *getExpr(unsigned Index) const {
34492ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman    assert((Index < NumExprs) && "Arg access out of range!");
34502ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman    return cast<Expr>(SubExprs[Index]);
345137bdfe284ad365f753741d1d89c078c148b3f4afArgyrios Kyrtzidis  }
345260adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl
34533397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl  void setExprs(ASTContext &C, ArrayRef<Expr *> Exprs);
34542ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman
34552ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman  unsigned getShuffleMaskIdx(ASTContext &Ctx, unsigned N) const {
34561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    assert((N < NumExprs - 2) && "Shuffle idx out of range!");
34574eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff    return getExpr(N+2)->EvaluateKnownConstInt(Ctx).getZExtValue();
34584eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  }
34594eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
34604eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  // Iterators
3461a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  child_range children() {
3462a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner    return child_range(&SubExprs[0], &SubExprs[0]+NumExprs);
3463a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  }
3464a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner};
3465a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
346673525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// ChooseExpr - GNU builtin-in function __builtin_choose_expr.
346773525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// This AST node is similar to the conditional operator (?:) in C, with
346873525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// the following exceptions:
3469a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// - the test expression must be a integer constant expression.
3470a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// - the expression returned acts like the chosen subexpression in every
3471d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor///   visible way: the type is the same as that of the chosen subexpression,
3472a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner///   and all predicates (whether it's an l-value, whether it's an integer
3473a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner///   constant expression, etc.) return the same result as for the chosen
3474f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall///   sub-expression.
3475f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCallclass ChooseExpr : public Expr {
34760943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall  enum { COND, LHS, RHS, END_EXPR };
34770943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall  Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
3478bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor  SourceLocation BuiltinLoc, RParenLoc;
3479bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregorpublic:
3480d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor  ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs,
34811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump             QualType t, ExprValueKind VK, ExprObjectKind OK,
3482d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor             SourceLocation RP, bool TypeDependent, bool ValueDependent)
3483d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor    : Expr(ChooseExprClass, t, VK, OK, TypeDependent, ValueDependent,
3484d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor           (cond->isInstantiationDependent() ||
3485d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor            lhs->isInstantiationDependent() ||
3486a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner            rhs->isInstantiationDependent()),
3487a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner           (cond->containsUnexpandedParameterPack() ||
3488d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor            lhs->containsUnexpandedParameterPack() ||
3489d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor            rhs->containsUnexpandedParameterPack())),
3490d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor      BuiltinLoc(BLoc), RParenLoc(RP) {
3491d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor      SubExprs[COND] = cond;
3492d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor      SubExprs[LHS] = lhs;
3493d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor      SubExprs[RHS] = rhs;
3494d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor    }
3495d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor
3496a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// \brief Build an empty __builtin_choose_expr.
3497a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { }
34981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3499a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// isConditionTrue - Return whether the condition is true (i.e. not
3500a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// equal to zero).
3501a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  bool isConditionTrue(const ASTContext &C) const;
35021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3503a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// getChosenSubExpr - Return the subexpression chosen according to the
3504a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  /// condition.
3505a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  Expr *getChosenSubExpr(const ASTContext &C) const {
35061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return isConditionTrue(C) ? getLHS() : getRHS();
3507a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  }
3508a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
3509a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
35101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setCond(Expr *E) { SubExprs[COND] = E; }
35112140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
35122140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner  void setLHS(Expr *E) { SubExprs[LHS] = E; }
35132140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
35141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setRHS(Expr *E) { SubExprs[RHS] = E; }
35151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
35161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
3517a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
3518a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
35191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  SourceLocation getRParenLoc() const { return RParenLoc; }
3520a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
3521a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
3522a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  SourceLocation getLocStart() const LLVM_READONLY { return BuiltinLoc; }
3523a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
3524a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner
3525a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner  static bool classof(const Stmt *T) {
352656ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff    return T->getStmtClass() == ChooseExprClass;
35279c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff  }
35284eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
352956ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  // Iterators
353056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  child_range children() {
35314eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
3532469a1eb996e1cb0be54f9b210f836afbddcbb2ccJohn McCall  }
3533f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall};
3534bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor
3535469a1eb996e1cb0be54f9b210f836afbddcbb2ccJohn McCall/// GNUNullExpr - Implements the GNU __null extension, which is a name
35369c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff/// for a null pointer constant that has integral type (e.g., int or
353784af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor/// long) and is the same size and alignment as a pointer. The __null
353884af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor/// extension is typically only used by system headers, which define
353984af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor/// NULL as __null in C++ rather than using 0 (which is an integer
3540d5cab5435371b8cc74a9e05ebd40b5995ebad149Anders Carlsson/// that may not match the size of a pointer).
354156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroffclass GNUNullExpr : public Expr {
354284af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor  /// TokenLoc - The location of the __null keyword.
354384af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor  SourceLocation TokenLoc;
354456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff
354556ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroffpublic:
354656ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  GNUNullExpr(QualType Ty, SourceLocation Loc)
354756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff    : Expr(GNUNullExprClass, Ty, VK_RValue, OK_Ordinary, false, false, false,
35489c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff           false),
35499c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff      TokenLoc(Loc) { }
355056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff
35519c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff  /// \brief Build an empty GNU __null expression.
35529c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff  explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { }
355356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff
355456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  /// getTokenLocation - The location of the __null token.
355556ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  SourceLocation getTokenLocation() const { return TokenLoc; }
35561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setTokenLocation(SourceLocation L) { TokenLoc = L; }
35579c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff
35584eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  SourceLocation getLocStart() const LLVM_READONLY { return TokenLoc; }
35594eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  SourceLocation getLocEnd() const LLVM_READONLY { return TokenLoc; }
35601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
35614eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  static bool classof(const Stmt *T) {
35624eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff    return T->getStmtClass() == GNUNullExprClass;
35634eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  }
35644eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
35651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // Iterators
35664eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  child_range children() { return child_range(); }
35674eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff};
35684eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
35691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// VAArgExpr, used for the builtin function __builtin_va_arg.
35704eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass VAArgExpr : public Expr {
35717d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian  Stmt *Val;
35727d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian  TypeSourceInfo *TInfo;
357389f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian  SourceLocation BuiltinLoc, RParenLoc;
35744eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic:
3575f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall  VAArgExpr(SourceLocation BLoc, Expr* e, TypeSourceInfo *TInfo,
3576f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall            SourceLocation RPLoc, QualType t)
3577a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor    : Expr(VAArgExprClass, t, VK_RValue, OK_Ordinary,
357894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor           t->isDependentType(), false,
357994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor           (TInfo->getType()->isInstantiationDependentType() ||
358094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor            e->isInstantiationDependent()),
358194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor           (TInfo->getType()->containsUnexpandedParameterPack() ||
358294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor            e->containsUnexpandedParameterPack())),
35831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      Val(e), TInfo(TInfo),
35844eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff      BuiltinLoc(BLoc),
35854eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff      RParenLoc(RPLoc) { }
358694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
358794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  /// \brief Create an empty __builtin_va_arg expression.
358894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  explicit VAArgExpr(EmptyShell Empty) : Expr(VAArgExprClass, Empty) { }
358994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor
359094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  const Expr *getSubExpr() const { return cast<Expr>(Val); }
35914eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  Expr *getSubExpr() { return cast<Expr>(Val); }
35921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setSubExpr(Expr *E) { Val = E; }
35934eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
359494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  TypeSourceInfo *getWrittenTypeInfo() const { return TInfo; }
35951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void setWrittenTypeInfo(TypeSourceInfo *TI) { TInfo = TI; }
35967d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian
35977d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
359889f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
359989f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian
360089f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian  SourceLocation getRParenLoc() const { return RParenLoc; }
360189f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
360289f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian
360389f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian  SourceLocation getLocStart() const LLVM_READONLY { return BuiltinLoc; }
360494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor  SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
36051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
36061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Stmt *T) {
36074eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff    return T->getStmtClass() == VAArgExprClass;
36084eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  }
36091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
36104eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  // Iterators
36114eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  child_range children() { return child_range(&Val, &Val+1); }
36124eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff};
36134eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
36144eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// @brief Describes an C or C++ initializer list.
36157cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall///
36167cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall/// InitListExpr describes an initializer list, which can be used to
36177cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall/// initialize objects of different types, including
36187cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall/// struct/class/union types, arrays, and vectors. For example:
36197cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall///
36207cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall/// @code
36217cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall/// struct foo x = { 1, { 2, 3 } };
3622b608b987718c6d841115464f79ab2d1820a63e17Douglas Gregor/// @endcode
3623b608b987718c6d841115464f79ab2d1820a63e17Douglas Gregor///
36247cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall/// Prior to semantic analysis, an initializer list will represent the
3625b608b987718c6d841115464f79ab2d1820a63e17Douglas Gregor/// initializer list as written by the user, but will have the
3626b608b987718c6d841115464f79ab2d1820a63e17Douglas Gregor/// placeholder type "void". This initializer list is called the
3627f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall/// syntactic form of the initializer, and may contain C99 designated
3628b608b987718c6d841115464f79ab2d1820a63e17Douglas Gregor/// initializers (represented as DesignatedInitExprs), initializations
3629b608b987718c6d841115464f79ab2d1820a63e17Douglas Gregor/// of subobject members without explicit braces, and so on. Clients
36307cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall/// interested in the original syntax of the initializer list should
36317cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall/// use the syntactic form of the initializer list.
36327cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall///
36337cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall/// After semantic analysis, the initializer list will represent the
36347cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall/// semantic form of the initializer, where the initializations of all
3635b608b987718c6d841115464f79ab2d1820a63e17Douglas Gregor/// subobjects are made explicit with nested InitListExpr nodes and
3636b608b987718c6d841115464f79ab2d1820a63e17Douglas Gregor/// C99 designators have been eliminated by placing the designated
3637b608b987718c6d841115464f79ab2d1820a63e17Douglas Gregor/// initializations into the subobject they initialize. Additionally,
36387cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall/// any "holes" in the initialization, where no initializer has been
36397cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall/// specified for a particular subobject, will be replaced with
36407cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall/// implicitly-generated ImplicitValueInitExpr expressions that
36417cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall/// value-initialize the subobjects. Note, however, that the
36427cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall/// initializer lists may still have fewer initializers than there are
36437cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall/// elements to initialize within the object.
36447cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall///
36457cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall/// After semantic analysis has completed, given an initializer list,
36467cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall/// method isSemanticForm() returns true if and only if this is the
36477cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall/// semantic form of the initializer list (note: the same AST node
36485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// may at the same time be the syntactic form).
36495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Given the semantic form of the initializer list, one can retrieve
36505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the syntactic form of that initializer list (when different)
3651/// using method getSyntacticForm(); the method returns null if applied
3652/// to a initializer list which is already in syntactic form.
3653/// Similarly, given the syntactic form (i.e., an initializer list such
3654/// that isSemanticForm() returns false), one can retrieve the semantic
3655/// form using method getSemanticForm().
3656/// Since many initializer lists have the same syntactic and semantic forms,
3657/// getSyntacticForm() may return NULL, indicating that the current
3658/// semantic initializer list also serves as its syntactic form.
3659class InitListExpr : public Expr {
3660  // FIXME: Eliminate this vector in favor of ASTContext allocation
3661  typedef ASTVector<Stmt *> InitExprsTy;
3662  InitExprsTy InitExprs;
3663  SourceLocation LBraceLoc, RBraceLoc;
3664
3665  /// The alternative form of the initializer list (if it exists).
3666  /// The int part of the pair stores whether this initalizer list is
3667  /// in semantic form. If not null, the pointer points to:
3668  ///   - the syntactic form, if this is in semantic form;
3669  ///   - the semantic form, if this is in syntactic form.
3670  llvm::PointerIntPair<InitListExpr *, 1, bool> AltForm;
3671
3672  /// \brief Either:
3673  ///  If this initializer list initializes an array with more elements than
3674  ///  there are initializers in the list, specifies an expression to be used
3675  ///  for value initialization of the rest of the elements.
3676  /// Or
3677  ///  If this initializer list initializes a union, specifies which
3678  ///  field within the union will be initialized.
3679  llvm::PointerUnion<Expr *, FieldDecl *> ArrayFillerOrUnionFieldInit;
3680
3681public:
3682  InitListExpr(ASTContext &C, SourceLocation lbraceloc,
3683               ArrayRef<Expr*> initExprs, SourceLocation rbraceloc);
3684
3685  /// \brief Build an empty initializer list.
3686  explicit InitListExpr(EmptyShell Empty)
3687    : Expr(InitListExprClass, Empty) { }
3688
3689  unsigned getNumInits() const { return InitExprs.size(); }
3690
3691  /// \brief Retrieve the set of initializers.
3692  Expr **getInits() { return reinterpret_cast<Expr **>(InitExprs.data()); }
3693
3694  const Expr *getInit(unsigned Init) const {
3695    assert(Init < getNumInits() && "Initializer access out of range!");
3696    return cast_or_null<Expr>(InitExprs[Init]);
3697  }
3698
3699  Expr *getInit(unsigned Init) {
3700    assert(Init < getNumInits() && "Initializer access out of range!");
3701    return cast_or_null<Expr>(InitExprs[Init]);
3702  }
3703
3704  void setInit(unsigned Init, Expr *expr) {
3705    assert(Init < getNumInits() && "Initializer access out of range!");
3706    InitExprs[Init] = expr;
3707  }
3708
3709  /// \brief Reserve space for some number of initializers.
3710  void reserveInits(ASTContext &C, unsigned NumInits);
3711
3712  /// @brief Specify the number of initializers
3713  ///
3714  /// If there are more than @p NumInits initializers, the remaining
3715  /// initializers will be destroyed. If there are fewer than @p
3716  /// NumInits initializers, NULL expressions will be added for the
3717  /// unknown initializers.
3718  void resizeInits(ASTContext &Context, unsigned NumInits);
3719
3720  /// @brief Updates the initializer at index @p Init with the new
3721  /// expression @p expr, and returns the old expression at that
3722  /// location.
3723  ///
3724  /// When @p Init is out of range for this initializer list, the
3725  /// initializer list will be extended with NULL expressions to
3726  /// accommodate the new entry.
3727  Expr *updateInit(ASTContext &C, unsigned Init, Expr *expr);
3728
3729  /// \brief If this initializer list initializes an array with more elements
3730  /// than there are initializers in the list, specifies an expression to be
3731  /// used for value initialization of the rest of the elements.
3732  Expr *getArrayFiller() {
3733    return ArrayFillerOrUnionFieldInit.dyn_cast<Expr *>();
3734  }
3735  const Expr *getArrayFiller() const {
3736    return const_cast<InitListExpr *>(this)->getArrayFiller();
3737  }
3738  void setArrayFiller(Expr *filler);
3739
3740  /// \brief Return true if this is an array initializer and its array "filler"
3741  /// has been set.
3742  bool hasArrayFiller() const { return getArrayFiller(); }
3743
3744  /// \brief If this initializes a union, specifies which field in the
3745  /// union to initialize.
3746  ///
3747  /// Typically, this field is the first named field within the
3748  /// union. However, a designated initializer can specify the
3749  /// initialization of a different field within the union.
3750  FieldDecl *getInitializedFieldInUnion() {
3751    return ArrayFillerOrUnionFieldInit.dyn_cast<FieldDecl *>();
3752  }
3753  const FieldDecl *getInitializedFieldInUnion() const {
3754    return const_cast<InitListExpr *>(this)->getInitializedFieldInUnion();
3755  }
3756  void setInitializedFieldInUnion(FieldDecl *FD) {
3757    ArrayFillerOrUnionFieldInit = FD;
3758  }
3759
3760  // Explicit InitListExpr's originate from source code (and have valid source
3761  // locations). Implicit InitListExpr's are created by the semantic analyzer.
3762  bool isExplicit() {
3763    return LBraceLoc.isValid() && RBraceLoc.isValid();
3764  }
3765
3766  // Is this an initializer for an array of characters, initialized by a string
3767  // literal or an @encode?
3768  bool isStringLiteralInit() const;
3769
3770  SourceLocation getLBraceLoc() const { return LBraceLoc; }
3771  void setLBraceLoc(SourceLocation Loc) { LBraceLoc = Loc; }
3772  SourceLocation getRBraceLoc() const { return RBraceLoc; }
3773  void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; }
3774
3775  bool isSemanticForm() const { return AltForm.getInt(); }
3776  InitListExpr *getSemanticForm() const {
3777    return isSemanticForm() ? 0 : AltForm.getPointer();
3778  }
3779  InitListExpr *getSyntacticForm() const {
3780    return isSemanticForm() ? AltForm.getPointer() : 0;
3781  }
3782
3783  void setSyntacticForm(InitListExpr *Init) {
3784    AltForm.setPointer(Init);
3785    AltForm.setInt(true);
3786    Init->AltForm.setPointer(this);
3787    Init->AltForm.setInt(false);
3788  }
3789
3790  bool hadArrayRangeDesignator() const {
3791    return InitListExprBits.HadArrayRangeDesignator != 0;
3792  }
3793  void sawArrayRangeDesignator(bool ARD = true) {
3794    InitListExprBits.HadArrayRangeDesignator = ARD;
3795  }
3796
3797  bool initializesStdInitializerList() const {
3798    return InitListExprBits.InitializesStdInitializerList != 0;
3799  }
3800  void setInitializesStdInitializerList(bool ISIL = true) {
3801    InitListExprBits.InitializesStdInitializerList = ISIL;
3802  }
3803
3804  SourceLocation getLocStart() const LLVM_READONLY;
3805  SourceLocation getLocEnd() const LLVM_READONLY;
3806
3807  static bool classof(const Stmt *T) {
3808    return T->getStmtClass() == InitListExprClass;
3809  }
3810
3811  // Iterators
3812  child_range children() {
3813    if (InitExprs.empty()) return child_range();
3814    return child_range(&InitExprs[0], &InitExprs[0] + InitExprs.size());
3815  }
3816
3817  typedef InitExprsTy::iterator iterator;
3818  typedef InitExprsTy::const_iterator const_iterator;
3819  typedef InitExprsTy::reverse_iterator reverse_iterator;
3820  typedef InitExprsTy::const_reverse_iterator const_reverse_iterator;
3821
3822  iterator begin() { return InitExprs.begin(); }
3823  const_iterator begin() const { return InitExprs.begin(); }
3824  iterator end() { return InitExprs.end(); }
3825  const_iterator end() const { return InitExprs.end(); }
3826  reverse_iterator rbegin() { return InitExprs.rbegin(); }
3827  const_reverse_iterator rbegin() const { return InitExprs.rbegin(); }
3828  reverse_iterator rend() { return InitExprs.rend(); }
3829  const_reverse_iterator rend() const { return InitExprs.rend(); }
3830
3831  friend class ASTStmtReader;
3832  friend class ASTStmtWriter;
3833};
3834
3835/// @brief Represents a C99 designated initializer expression.
3836///
3837/// A designated initializer expression (C99 6.7.8) contains one or
3838/// more designators (which can be field designators, array
3839/// designators, or GNU array-range designators) followed by an
3840/// expression that initializes the field or element(s) that the
3841/// designators refer to. For example, given:
3842///
3843/// @code
3844/// struct point {
3845///   double x;
3846///   double y;
3847/// };
3848/// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 };
3849/// @endcode
3850///
3851/// The InitListExpr contains three DesignatedInitExprs, the first of
3852/// which covers @c [2].y=1.0. This DesignatedInitExpr will have two
3853/// designators, one array designator for @c [2] followed by one field
3854/// designator for @c .y. The initalization expression will be 1.0.
3855class DesignatedInitExpr : public Expr {
3856public:
3857  /// \brief Forward declaration of the Designator class.
3858  class Designator;
3859
3860private:
3861  /// The location of the '=' or ':' prior to the actual initializer
3862  /// expression.
3863  SourceLocation EqualOrColonLoc;
3864
3865  /// Whether this designated initializer used the GNU deprecated
3866  /// syntax rather than the C99 '=' syntax.
3867  bool GNUSyntax : 1;
3868
3869  /// The number of designators in this initializer expression.
3870  unsigned NumDesignators : 15;
3871
3872  /// The number of subexpressions of this initializer expression,
3873  /// which contains both the initializer and any additional
3874  /// expressions used by array and array-range designators.
3875  unsigned NumSubExprs : 16;
3876
3877  /// \brief The designators in this designated initialization
3878  /// expression.
3879  Designator *Designators;
3880
3881
3882  DesignatedInitExpr(ASTContext &C, QualType Ty, unsigned NumDesignators,
3883                     const Designator *Designators,
3884                     SourceLocation EqualOrColonLoc, bool GNUSyntax,
3885                     ArrayRef<Expr*> IndexExprs, Expr *Init);
3886
3887  explicit DesignatedInitExpr(unsigned NumSubExprs)
3888    : Expr(DesignatedInitExprClass, EmptyShell()),
3889      NumDesignators(0), NumSubExprs(NumSubExprs), Designators(0) { }
3890
3891public:
3892  /// A field designator, e.g., ".x".
3893  struct FieldDesignator {
3894    /// Refers to the field that is being initialized. The low bit
3895    /// of this field determines whether this is actually a pointer
3896    /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When
3897    /// initially constructed, a field designator will store an
3898    /// IdentifierInfo*. After semantic analysis has resolved that
3899    /// name, the field designator will instead store a FieldDecl*.
3900    uintptr_t NameOrField;
3901
3902    /// The location of the '.' in the designated initializer.
3903    unsigned DotLoc;
3904
3905    /// The location of the field name in the designated initializer.
3906    unsigned FieldLoc;
3907  };
3908
3909  /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
3910  struct ArrayOrRangeDesignator {
3911    /// Location of the first index expression within the designated
3912    /// initializer expression's list of subexpressions.
3913    unsigned Index;
3914    /// The location of the '[' starting the array range designator.
3915    unsigned LBracketLoc;
3916    /// The location of the ellipsis separating the start and end
3917    /// indices. Only valid for GNU array-range designators.
3918    unsigned EllipsisLoc;
3919    /// The location of the ']' terminating the array range designator.
3920    unsigned RBracketLoc;
3921  };
3922
3923  /// @brief Represents a single C99 designator.
3924  ///
3925  /// @todo This class is infuriatingly similar to clang::Designator,
3926  /// but minor differences (storing indices vs. storing pointers)
3927  /// keep us from reusing it. Try harder, later, to rectify these
3928  /// differences.
3929  class Designator {
3930    /// @brief The kind of designator this describes.
3931    enum {
3932      FieldDesignator,
3933      ArrayDesignator,
3934      ArrayRangeDesignator
3935    } Kind;
3936
3937    union {
3938      /// A field designator, e.g., ".x".
3939      struct FieldDesignator Field;
3940      /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
3941      struct ArrayOrRangeDesignator ArrayOrRange;
3942    };
3943    friend class DesignatedInitExpr;
3944
3945  public:
3946    Designator() {}
3947
3948    /// @brief Initializes a field designator.
3949    Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc,
3950               SourceLocation FieldLoc)
3951      : Kind(FieldDesignator) {
3952      Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01;
3953      Field.DotLoc = DotLoc.getRawEncoding();
3954      Field.FieldLoc = FieldLoc.getRawEncoding();
3955    }
3956
3957    /// @brief Initializes an array designator.
3958    Designator(unsigned Index, SourceLocation LBracketLoc,
3959               SourceLocation RBracketLoc)
3960      : Kind(ArrayDesignator) {
3961      ArrayOrRange.Index = Index;
3962      ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
3963      ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding();
3964      ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
3965    }
3966
3967    /// @brief Initializes a GNU array-range designator.
3968    Designator(unsigned Index, SourceLocation LBracketLoc,
3969               SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
3970      : Kind(ArrayRangeDesignator) {
3971      ArrayOrRange.Index = Index;
3972      ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
3973      ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding();
3974      ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
3975    }
3976
3977    bool isFieldDesignator() const { return Kind == FieldDesignator; }
3978    bool isArrayDesignator() const { return Kind == ArrayDesignator; }
3979    bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; }
3980
3981    IdentifierInfo *getFieldName() const;
3982
3983    FieldDecl *getField() const {
3984      assert(Kind == FieldDesignator && "Only valid on a field designator");
3985      if (Field.NameOrField & 0x01)
3986        return 0;
3987      else
3988        return reinterpret_cast<FieldDecl *>(Field.NameOrField);
3989    }
3990
3991    void setField(FieldDecl *FD) {
3992      assert(Kind == FieldDesignator && "Only valid on a field designator");
3993      Field.NameOrField = reinterpret_cast<uintptr_t>(FD);
3994    }
3995
3996    SourceLocation getDotLoc() const {
3997      assert(Kind == FieldDesignator && "Only valid on a field designator");
3998      return SourceLocation::getFromRawEncoding(Field.DotLoc);
3999    }
4000
4001    SourceLocation getFieldLoc() const {
4002      assert(Kind == FieldDesignator && "Only valid on a field designator");
4003      return SourceLocation::getFromRawEncoding(Field.FieldLoc);
4004    }
4005
4006    SourceLocation getLBracketLoc() const {
4007      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
4008             "Only valid on an array or array-range designator");
4009      return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc);
4010    }
4011
4012    SourceLocation getRBracketLoc() const {
4013      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
4014             "Only valid on an array or array-range designator");
4015      return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc);
4016    }
4017
4018    SourceLocation getEllipsisLoc() const {
4019      assert(Kind == ArrayRangeDesignator &&
4020             "Only valid on an array-range designator");
4021      return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc);
4022    }
4023
4024    unsigned getFirstExprIndex() const {
4025      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
4026             "Only valid on an array or array-range designator");
4027      return ArrayOrRange.Index;
4028    }
4029
4030    SourceLocation getLocStart() const LLVM_READONLY {
4031      if (Kind == FieldDesignator)
4032        return getDotLoc().isInvalid()? getFieldLoc() : getDotLoc();
4033      else
4034        return getLBracketLoc();
4035    }
4036    SourceLocation getLocEnd() const LLVM_READONLY {
4037      return Kind == FieldDesignator ? getFieldLoc() : getRBracketLoc();
4038    }
4039    SourceRange getSourceRange() const LLVM_READONLY {
4040      return SourceRange(getLocStart(), getLocEnd());
4041    }
4042  };
4043
4044  static DesignatedInitExpr *Create(ASTContext &C, Designator *Designators,
4045                                    unsigned NumDesignators,
4046                                    ArrayRef<Expr*> IndexExprs,
4047                                    SourceLocation EqualOrColonLoc,
4048                                    bool GNUSyntax, Expr *Init);
4049
4050  static DesignatedInitExpr *CreateEmpty(ASTContext &C, unsigned NumIndexExprs);
4051
4052  /// @brief Returns the number of designators in this initializer.
4053  unsigned size() const { return NumDesignators; }
4054
4055  // Iterator access to the designators.
4056  typedef Designator *designators_iterator;
4057  designators_iterator designators_begin() { return Designators; }
4058  designators_iterator designators_end() {
4059    return Designators + NumDesignators;
4060  }
4061
4062  typedef const Designator *const_designators_iterator;
4063  const_designators_iterator designators_begin() const { return Designators; }
4064  const_designators_iterator designators_end() const {
4065    return Designators + NumDesignators;
4066  }
4067
4068  typedef std::reverse_iterator<designators_iterator>
4069          reverse_designators_iterator;
4070  reverse_designators_iterator designators_rbegin() {
4071    return reverse_designators_iterator(designators_end());
4072  }
4073  reverse_designators_iterator designators_rend() {
4074    return reverse_designators_iterator(designators_begin());
4075  }
4076
4077  typedef std::reverse_iterator<const_designators_iterator>
4078          const_reverse_designators_iterator;
4079  const_reverse_designators_iterator designators_rbegin() const {
4080    return const_reverse_designators_iterator(designators_end());
4081  }
4082  const_reverse_designators_iterator designators_rend() const {
4083    return const_reverse_designators_iterator(designators_begin());
4084  }
4085
4086  Designator *getDesignator(unsigned Idx) { return &designators_begin()[Idx]; }
4087
4088  void setDesignators(ASTContext &C, const Designator *Desigs,
4089                      unsigned NumDesigs);
4090
4091  Expr *getArrayIndex(const Designator &D) const;
4092  Expr *getArrayRangeStart(const Designator &D) const;
4093  Expr *getArrayRangeEnd(const Designator &D) const;
4094
4095  /// @brief Retrieve the location of the '=' that precedes the
4096  /// initializer value itself, if present.
4097  SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; }
4098  void setEqualOrColonLoc(SourceLocation L) { EqualOrColonLoc = L; }
4099
4100  /// @brief Determines whether this designated initializer used the
4101  /// deprecated GNU syntax for designated initializers.
4102  bool usesGNUSyntax() const { return GNUSyntax; }
4103  void setGNUSyntax(bool GNU) { GNUSyntax = GNU; }
4104
4105  /// @brief Retrieve the initializer value.
4106  Expr *getInit() const {
4107    return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin());
4108  }
4109
4110  void setInit(Expr *init) {
4111    *child_begin() = init;
4112  }
4113
4114  /// \brief Retrieve the total number of subexpressions in this
4115  /// designated initializer expression, including the actual
4116  /// initialized value and any expressions that occur within array
4117  /// and array-range designators.
4118  unsigned getNumSubExprs() const { return NumSubExprs; }
4119
4120  Expr *getSubExpr(unsigned Idx) {
4121    assert(Idx < NumSubExprs && "Subscript out of range");
4122    char* Ptr = static_cast<char*>(static_cast<void *>(this));
4123    Ptr += sizeof(DesignatedInitExpr);
4124    return reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx];
4125  }
4126
4127  void setSubExpr(unsigned Idx, Expr *E) {
4128    assert(Idx < NumSubExprs && "Subscript out of range");
4129    char* Ptr = static_cast<char*>(static_cast<void *>(this));
4130    Ptr += sizeof(DesignatedInitExpr);
4131    reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx] = E;
4132  }
4133
4134  /// \brief Replaces the designator at index @p Idx with the series
4135  /// of designators in [First, Last).
4136  void ExpandDesignator(ASTContext &C, unsigned Idx, const Designator *First,
4137                        const Designator *Last);
4138
4139  SourceRange getDesignatorsSourceRange() const;
4140
4141  SourceLocation getLocStart() const LLVM_READONLY;
4142  SourceLocation getLocEnd() const LLVM_READONLY;
4143
4144  static bool classof(const Stmt *T) {
4145    return T->getStmtClass() == DesignatedInitExprClass;
4146  }
4147
4148  // Iterators
4149  child_range children() {
4150    Stmt **begin = reinterpret_cast<Stmt**>(this + 1);
4151    return child_range(begin, begin + NumSubExprs);
4152  }
4153};
4154
4155/// \brief Represents an implicitly-generated value initialization of
4156/// an object of a given type.
4157///
4158/// Implicit value initializations occur within semantic initializer
4159/// list expressions (InitListExpr) as placeholders for subobject
4160/// initializations not explicitly specified by the user.
4161///
4162/// \see InitListExpr
4163class ImplicitValueInitExpr : public Expr {
4164public:
4165  explicit ImplicitValueInitExpr(QualType ty)
4166    : Expr(ImplicitValueInitExprClass, ty, VK_RValue, OK_Ordinary,
4167           false, false, ty->isInstantiationDependentType(), false) { }
4168
4169  /// \brief Construct an empty implicit value initialization.
4170  explicit ImplicitValueInitExpr(EmptyShell Empty)
4171    : Expr(ImplicitValueInitExprClass, Empty) { }
4172
4173  static bool classof(const Stmt *T) {
4174    return T->getStmtClass() == ImplicitValueInitExprClass;
4175  }
4176
4177  SourceLocation getLocStart() const LLVM_READONLY { return SourceLocation(); }
4178  SourceLocation getLocEnd() const LLVM_READONLY { return SourceLocation(); }
4179
4180  // Iterators
4181  child_range children() { return child_range(); }
4182};
4183
4184
4185class ParenListExpr : public Expr {
4186  Stmt **Exprs;
4187  unsigned NumExprs;
4188  SourceLocation LParenLoc, RParenLoc;
4189
4190public:
4191  ParenListExpr(ASTContext& C, SourceLocation lparenloc, ArrayRef<Expr*> exprs,
4192                SourceLocation rparenloc);
4193
4194  /// \brief Build an empty paren list.
4195  explicit ParenListExpr(EmptyShell Empty) : Expr(ParenListExprClass, Empty) { }
4196
4197  unsigned getNumExprs() const { return NumExprs; }
4198
4199  const Expr* getExpr(unsigned Init) const {
4200    assert(Init < getNumExprs() && "Initializer access out of range!");
4201    return cast_or_null<Expr>(Exprs[Init]);
4202  }
4203
4204  Expr* getExpr(unsigned Init) {
4205    assert(Init < getNumExprs() && "Initializer access out of range!");
4206    return cast_or_null<Expr>(Exprs[Init]);
4207  }
4208
4209  Expr **getExprs() { return reinterpret_cast<Expr **>(Exprs); }
4210
4211  SourceLocation getLParenLoc() const { return LParenLoc; }
4212  SourceLocation getRParenLoc() const { return RParenLoc; }
4213
4214  SourceLocation getLocStart() const LLVM_READONLY { return LParenLoc; }
4215  SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
4216
4217  static bool classof(const Stmt *T) {
4218    return T->getStmtClass() == ParenListExprClass;
4219  }
4220
4221  // Iterators
4222  child_range children() {
4223    return child_range(&Exprs[0], &Exprs[0]+NumExprs);
4224  }
4225
4226  friend class ASTStmtReader;
4227  friend class ASTStmtWriter;
4228};
4229
4230
4231/// \brief Represents a C11 generic selection.
4232///
4233/// A generic selection (C11 6.5.1.1) contains an unevaluated controlling
4234/// expression, followed by one or more generic associations.  Each generic
4235/// association specifies a type name and an expression, or "default" and an
4236/// expression (in which case it is known as a default generic association).
4237/// The type and value of the generic selection are identical to those of its
4238/// result expression, which is defined as the expression in the generic
4239/// association with a type name that is compatible with the type of the
4240/// controlling expression, or the expression in the default generic association
4241/// if no types are compatible.  For example:
4242///
4243/// @code
4244/// _Generic(X, double: 1, float: 2, default: 3)
4245/// @endcode
4246///
4247/// The above expression evaluates to 1 if 1.0 is substituted for X, 2 if 1.0f
4248/// or 3 if "hello".
4249///
4250/// As an extension, generic selections are allowed in C++, where the following
4251/// additional semantics apply:
4252///
4253/// Any generic selection whose controlling expression is type-dependent or
4254/// which names a dependent type in its association list is result-dependent,
4255/// which means that the choice of result expression is dependent.
4256/// Result-dependent generic associations are both type- and value-dependent.
4257class GenericSelectionExpr : public Expr {
4258  enum { CONTROLLING, END_EXPR };
4259  TypeSourceInfo **AssocTypes;
4260  Stmt **SubExprs;
4261  unsigned NumAssocs, ResultIndex;
4262  SourceLocation GenericLoc, DefaultLoc, RParenLoc;
4263
4264public:
4265  GenericSelectionExpr(ASTContext &Context,
4266                       SourceLocation GenericLoc, Expr *ControllingExpr,
4267                       ArrayRef<TypeSourceInfo*> AssocTypes,
4268                       ArrayRef<Expr*> AssocExprs,
4269                       SourceLocation DefaultLoc, SourceLocation RParenLoc,
4270                       bool ContainsUnexpandedParameterPack,
4271                       unsigned ResultIndex);
4272
4273  /// This constructor is used in the result-dependent case.
4274  GenericSelectionExpr(ASTContext &Context,
4275                       SourceLocation GenericLoc, Expr *ControllingExpr,
4276                       ArrayRef<TypeSourceInfo*> AssocTypes,
4277                       ArrayRef<Expr*> AssocExprs,
4278                       SourceLocation DefaultLoc, SourceLocation RParenLoc,
4279                       bool ContainsUnexpandedParameterPack);
4280
4281  explicit GenericSelectionExpr(EmptyShell Empty)
4282    : Expr(GenericSelectionExprClass, Empty) { }
4283
4284  unsigned getNumAssocs() const { return NumAssocs; }
4285
4286  SourceLocation getGenericLoc() const { return GenericLoc; }
4287  SourceLocation getDefaultLoc() const { return DefaultLoc; }
4288  SourceLocation getRParenLoc() const { return RParenLoc; }
4289
4290  const Expr *getAssocExpr(unsigned i) const {
4291    return cast<Expr>(SubExprs[END_EXPR+i]);
4292  }
4293  Expr *getAssocExpr(unsigned i) { return cast<Expr>(SubExprs[END_EXPR+i]); }
4294
4295  const TypeSourceInfo *getAssocTypeSourceInfo(unsigned i) const {
4296    return AssocTypes[i];
4297  }
4298  TypeSourceInfo *getAssocTypeSourceInfo(unsigned i) { return AssocTypes[i]; }
4299
4300  QualType getAssocType(unsigned i) const {
4301    if (const TypeSourceInfo *TS = getAssocTypeSourceInfo(i))
4302      return TS->getType();
4303    else
4304      return QualType();
4305  }
4306
4307  const Expr *getControllingExpr() const {
4308    return cast<Expr>(SubExprs[CONTROLLING]);
4309  }
4310  Expr *getControllingExpr() { return cast<Expr>(SubExprs[CONTROLLING]); }
4311
4312  /// Whether this generic selection is result-dependent.
4313  bool isResultDependent() const { return ResultIndex == -1U; }
4314
4315  /// The zero-based index of the result expression's generic association in
4316  /// the generic selection's association list.  Defined only if the
4317  /// generic selection is not result-dependent.
4318  unsigned getResultIndex() const {
4319    assert(!isResultDependent() && "Generic selection is result-dependent");
4320    return ResultIndex;
4321  }
4322
4323  /// The generic selection's result expression.  Defined only if the
4324  /// generic selection is not result-dependent.
4325  const Expr *getResultExpr() const { return getAssocExpr(getResultIndex()); }
4326  Expr *getResultExpr() { return getAssocExpr(getResultIndex()); }
4327
4328  SourceLocation getLocStart() const LLVM_READONLY { return GenericLoc; }
4329  SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
4330
4331  static bool classof(const Stmt *T) {
4332    return T->getStmtClass() == GenericSelectionExprClass;
4333  }
4334
4335  child_range children() {
4336    return child_range(SubExprs, SubExprs+END_EXPR+NumAssocs);
4337  }
4338
4339  friend class ASTStmtReader;
4340};
4341
4342//===----------------------------------------------------------------------===//
4343// Clang Extensions
4344//===----------------------------------------------------------------------===//
4345
4346
4347/// ExtVectorElementExpr - This represents access to specific elements of a
4348/// vector, and may occur on the left hand side or right hand side.  For example
4349/// the following is legal:  "V.xy = V.zw" if V is a 4 element extended vector.
4350///
4351/// Note that the base may have either vector or pointer to vector type, just
4352/// like a struct field reference.
4353///
4354class ExtVectorElementExpr : public Expr {
4355  Stmt *Base;
4356  IdentifierInfo *Accessor;
4357  SourceLocation AccessorLoc;
4358public:
4359  ExtVectorElementExpr(QualType ty, ExprValueKind VK, Expr *base,
4360                       IdentifierInfo &accessor, SourceLocation loc)
4361    : Expr(ExtVectorElementExprClass, ty, VK,
4362           (VK == VK_RValue ? OK_Ordinary : OK_VectorComponent),
4363           base->isTypeDependent(), base->isValueDependent(),
4364           base->isInstantiationDependent(),
4365           base->containsUnexpandedParameterPack()),
4366      Base(base), Accessor(&accessor), AccessorLoc(loc) {}
4367
4368  /// \brief Build an empty vector element expression.
4369  explicit ExtVectorElementExpr(EmptyShell Empty)
4370    : Expr(ExtVectorElementExprClass, Empty) { }
4371
4372  const Expr *getBase() const { return cast<Expr>(Base); }
4373  Expr *getBase() { return cast<Expr>(Base); }
4374  void setBase(Expr *E) { Base = E; }
4375
4376  IdentifierInfo &getAccessor() const { return *Accessor; }
4377  void setAccessor(IdentifierInfo *II) { Accessor = II; }
4378
4379  SourceLocation getAccessorLoc() const { return AccessorLoc; }
4380  void setAccessorLoc(SourceLocation L) { AccessorLoc = L; }
4381
4382  /// getNumElements - Get the number of components being selected.
4383  unsigned getNumElements() const;
4384
4385  /// containsDuplicateElements - Return true if any element access is
4386  /// repeated.
4387  bool containsDuplicateElements() const;
4388
4389  /// getEncodedElementAccess - Encode the elements accessed into an llvm
4390  /// aggregate Constant of ConstantInt(s).
4391  void getEncodedElementAccess(SmallVectorImpl<unsigned> &Elts) const;
4392
4393  SourceLocation getLocStart() const LLVM_READONLY {
4394    return getBase()->getLocStart();
4395  }
4396  SourceLocation getLocEnd() const LLVM_READONLY { return AccessorLoc; }
4397
4398  /// isArrow - Return true if the base expression is a pointer to vector,
4399  /// return false if the base expression is a vector.
4400  bool isArrow() const;
4401
4402  static bool classof(const Stmt *T) {
4403    return T->getStmtClass() == ExtVectorElementExprClass;
4404  }
4405
4406  // Iterators
4407  child_range children() { return child_range(&Base, &Base+1); }
4408};
4409
4410
4411/// BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
4412/// ^{ statement-body }   or   ^(int arg1, float arg2){ statement-body }
4413class BlockExpr : public Expr {
4414protected:
4415  BlockDecl *TheBlock;
4416public:
4417  BlockExpr(BlockDecl *BD, QualType ty)
4418    : Expr(BlockExprClass, ty, VK_RValue, OK_Ordinary,
4419           ty->isDependentType(), ty->isDependentType(),
4420           ty->isInstantiationDependentType() || BD->isDependentContext(),
4421           false),
4422      TheBlock(BD) {}
4423
4424  /// \brief Build an empty block expression.
4425  explicit BlockExpr(EmptyShell Empty) : Expr(BlockExprClass, Empty) { }
4426
4427  const BlockDecl *getBlockDecl() const { return TheBlock; }
4428  BlockDecl *getBlockDecl() { return TheBlock; }
4429  void setBlockDecl(BlockDecl *BD) { TheBlock = BD; }
4430
4431  // Convenience functions for probing the underlying BlockDecl.
4432  SourceLocation getCaretLocation() const;
4433  const Stmt *getBody() const;
4434  Stmt *getBody();
4435
4436  SourceLocation getLocStart() const LLVM_READONLY { return getCaretLocation(); }
4437  SourceLocation getLocEnd() const LLVM_READONLY { return getBody()->getLocEnd(); }
4438
4439  /// getFunctionType - Return the underlying function type for this block.
4440  const FunctionProtoType *getFunctionType() const;
4441
4442  static bool classof(const Stmt *T) {
4443    return T->getStmtClass() == BlockExprClass;
4444  }
4445
4446  // Iterators
4447  child_range children() { return child_range(); }
4448};
4449
4450/// AsTypeExpr - Clang builtin function __builtin_astype [OpenCL 6.2.4.2]
4451/// This AST node provides support for reinterpreting a type to another
4452/// type of the same size.
4453class AsTypeExpr : public Expr { // Should this be an ExplicitCastExpr?
4454private:
4455  Stmt *SrcExpr;
4456  SourceLocation BuiltinLoc, RParenLoc;
4457
4458  friend class ASTReader;
4459  friend class ASTStmtReader;
4460  explicit AsTypeExpr(EmptyShell Empty) : Expr(AsTypeExprClass, Empty) {}
4461
4462public:
4463  AsTypeExpr(Expr* SrcExpr, QualType DstType,
4464             ExprValueKind VK, ExprObjectKind OK,
4465             SourceLocation BuiltinLoc, SourceLocation RParenLoc)
4466    : Expr(AsTypeExprClass, DstType, VK, OK,
4467           DstType->isDependentType(),
4468           DstType->isDependentType() || SrcExpr->isValueDependent(),
4469           (DstType->isInstantiationDependentType() ||
4470            SrcExpr->isInstantiationDependent()),
4471           (DstType->containsUnexpandedParameterPack() ||
4472            SrcExpr->containsUnexpandedParameterPack())),
4473  SrcExpr(SrcExpr), BuiltinLoc(BuiltinLoc), RParenLoc(RParenLoc) {}
4474
4475  /// getSrcExpr - Return the Expr to be converted.
4476  Expr *getSrcExpr() const { return cast<Expr>(SrcExpr); }
4477
4478  /// getBuiltinLoc - Return the location of the __builtin_astype token.
4479  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
4480
4481  /// getRParenLoc - Return the location of final right parenthesis.
4482  SourceLocation getRParenLoc() const { return RParenLoc; }
4483
4484  SourceLocation getLocStart() const LLVM_READONLY { return BuiltinLoc; }
4485  SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
4486
4487  static bool classof(const Stmt *T) {
4488    return T->getStmtClass() == AsTypeExprClass;
4489  }
4490
4491  // Iterators
4492  child_range children() { return child_range(&SrcExpr, &SrcExpr+1); }
4493};
4494
4495/// PseudoObjectExpr - An expression which accesses a pseudo-object
4496/// l-value.  A pseudo-object is an abstract object, accesses to which
4497/// are translated to calls.  The pseudo-object expression has a
4498/// syntactic form, which shows how the expression was actually
4499/// written in the source code, and a semantic form, which is a series
4500/// of expressions to be executed in order which detail how the
4501/// operation is actually evaluated.  Optionally, one of the semantic
4502/// forms may also provide a result value for the expression.
4503///
4504/// If any of the semantic-form expressions is an OpaqueValueExpr,
4505/// that OVE is required to have a source expression, and it is bound
4506/// to the result of that source expression.  Such OVEs may appear
4507/// only in subsequent semantic-form expressions and as
4508/// sub-expressions of the syntactic form.
4509///
4510/// PseudoObjectExpr should be used only when an operation can be
4511/// usefully described in terms of fairly simple rewrite rules on
4512/// objects and functions that are meant to be used by end-developers.
4513/// For example, under the Itanium ABI, dynamic casts are implemented
4514/// as a call to a runtime function called __dynamic_cast; using this
4515/// class to describe that would be inappropriate because that call is
4516/// not really part of the user-visible semantics, and instead the
4517/// cast is properly reflected in the AST and IR-generation has been
4518/// taught to generate the call as necessary.  In contrast, an
4519/// Objective-C property access is semantically defined to be
4520/// equivalent to a particular message send, and this is very much
4521/// part of the user model.  The name of this class encourages this
4522/// modelling design.
4523class PseudoObjectExpr : public Expr {
4524  // PseudoObjectExprBits.NumSubExprs - The number of sub-expressions.
4525  // Always at least two, because the first sub-expression is the
4526  // syntactic form.
4527
4528  // PseudoObjectExprBits.ResultIndex - The index of the
4529  // sub-expression holding the result.  0 means the result is void,
4530  // which is unambiguous because it's the index of the syntactic
4531  // form.  Note that this is therefore 1 higher than the value passed
4532  // in to Create, which is an index within the semantic forms.
4533  // Note also that ASTStmtWriter assumes this encoding.
4534
4535  Expr **getSubExprsBuffer() { return reinterpret_cast<Expr**>(this + 1); }
4536  const Expr * const *getSubExprsBuffer() const {
4537    return reinterpret_cast<const Expr * const *>(this + 1);
4538  }
4539
4540  friend class ASTStmtReader;
4541
4542  PseudoObjectExpr(QualType type, ExprValueKind VK,
4543                   Expr *syntactic, ArrayRef<Expr*> semantic,
4544                   unsigned resultIndex);
4545
4546  PseudoObjectExpr(EmptyShell shell, unsigned numSemanticExprs);
4547
4548  unsigned getNumSubExprs() const {
4549    return PseudoObjectExprBits.NumSubExprs;
4550  }
4551
4552public:
4553  /// NoResult - A value for the result index indicating that there is
4554  /// no semantic result.
4555  enum { NoResult = ~0U };
4556
4557  static PseudoObjectExpr *Create(ASTContext &Context, Expr *syntactic,
4558                                  ArrayRef<Expr*> semantic,
4559                                  unsigned resultIndex);
4560
4561  static PseudoObjectExpr *Create(ASTContext &Context, EmptyShell shell,
4562                                  unsigned numSemanticExprs);
4563
4564  /// Return the syntactic form of this expression, i.e. the
4565  /// expression it actually looks like.  Likely to be expressed in
4566  /// terms of OpaqueValueExprs bound in the semantic form.
4567  Expr *getSyntacticForm() { return getSubExprsBuffer()[0]; }
4568  const Expr *getSyntacticForm() const { return getSubExprsBuffer()[0]; }
4569
4570  /// Return the index of the result-bearing expression into the semantics
4571  /// expressions, or PseudoObjectExpr::NoResult if there is none.
4572  unsigned getResultExprIndex() const {
4573    if (PseudoObjectExprBits.ResultIndex == 0) return NoResult;
4574    return PseudoObjectExprBits.ResultIndex - 1;
4575  }
4576
4577  /// Return the result-bearing expression, or null if there is none.
4578  Expr *getResultExpr() {
4579    if (PseudoObjectExprBits.ResultIndex == 0)
4580      return 0;
4581    return getSubExprsBuffer()[PseudoObjectExprBits.ResultIndex];
4582  }
4583  const Expr *getResultExpr() const {
4584    return const_cast<PseudoObjectExpr*>(this)->getResultExpr();
4585  }
4586
4587  unsigned getNumSemanticExprs() const { return getNumSubExprs() - 1; }
4588
4589  typedef Expr * const *semantics_iterator;
4590  typedef const Expr * const *const_semantics_iterator;
4591  semantics_iterator semantics_begin() {
4592    return getSubExprsBuffer() + 1;
4593  }
4594  const_semantics_iterator semantics_begin() const {
4595    return getSubExprsBuffer() + 1;
4596  }
4597  semantics_iterator semantics_end() {
4598    return getSubExprsBuffer() + getNumSubExprs();
4599  }
4600  const_semantics_iterator semantics_end() const {
4601    return getSubExprsBuffer() + getNumSubExprs();
4602  }
4603  Expr *getSemanticExpr(unsigned index) {
4604    assert(index + 1 < getNumSubExprs());
4605    return getSubExprsBuffer()[index + 1];
4606  }
4607  const Expr *getSemanticExpr(unsigned index) const {
4608    return const_cast<PseudoObjectExpr*>(this)->getSemanticExpr(index);
4609  }
4610
4611  SourceLocation getExprLoc() const LLVM_READONLY {
4612    return getSyntacticForm()->getExprLoc();
4613  }
4614
4615  SourceLocation getLocStart() const LLVM_READONLY {
4616    return getSyntacticForm()->getLocStart();
4617  }
4618  SourceLocation getLocEnd() const LLVM_READONLY {
4619    return getSyntacticForm()->getLocEnd();
4620  }
4621
4622  child_range children() {
4623    Stmt **cs = reinterpret_cast<Stmt**>(getSubExprsBuffer());
4624    return child_range(cs, cs + getNumSubExprs());
4625  }
4626
4627  static bool classof(const Stmt *T) {
4628    return T->getStmtClass() == PseudoObjectExprClass;
4629  }
4630};
4631
4632/// AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*,
4633/// __atomic_load, __atomic_store, and __atomic_compare_exchange_*, for the
4634/// similarly-named C++11 instructions, and __c11 variants for <stdatomic.h>.
4635/// All of these instructions take one primary pointer and at least one memory
4636/// order.
4637class AtomicExpr : public Expr {
4638public:
4639  enum AtomicOp {
4640#define BUILTIN(ID, TYPE, ATTRS)
4641#define ATOMIC_BUILTIN(ID, TYPE, ATTRS) AO ## ID,
4642#include "clang/Basic/Builtins.def"
4643    // Avoid trailing comma
4644    BI_First = 0
4645  };
4646
4647private:
4648  enum { PTR, ORDER, VAL1, ORDER_FAIL, VAL2, WEAK, END_EXPR };
4649  Stmt* SubExprs[END_EXPR];
4650  unsigned NumSubExprs;
4651  SourceLocation BuiltinLoc, RParenLoc;
4652  AtomicOp Op;
4653
4654  friend class ASTStmtReader;
4655
4656public:
4657  AtomicExpr(SourceLocation BLoc, ArrayRef<Expr*> args, QualType t,
4658             AtomicOp op, SourceLocation RP);
4659
4660  /// \brief Determine the number of arguments the specified atomic builtin
4661  /// should have.
4662  static unsigned getNumSubExprs(AtomicOp Op);
4663
4664  /// \brief Build an empty AtomicExpr.
4665  explicit AtomicExpr(EmptyShell Empty) : Expr(AtomicExprClass, Empty) { }
4666
4667  Expr *getPtr() const {
4668    return cast<Expr>(SubExprs[PTR]);
4669  }
4670  Expr *getOrder() const {
4671    return cast<Expr>(SubExprs[ORDER]);
4672  }
4673  Expr *getVal1() const {
4674    if (Op == AO__c11_atomic_init)
4675      return cast<Expr>(SubExprs[ORDER]);
4676    assert(NumSubExprs > VAL1);
4677    return cast<Expr>(SubExprs[VAL1]);
4678  }
4679  Expr *getOrderFail() const {
4680    assert(NumSubExprs > ORDER_FAIL);
4681    return cast<Expr>(SubExprs[ORDER_FAIL]);
4682  }
4683  Expr *getVal2() const {
4684    if (Op == AO__atomic_exchange)
4685      return cast<Expr>(SubExprs[ORDER_FAIL]);
4686    assert(NumSubExprs > VAL2);
4687    return cast<Expr>(SubExprs[VAL2]);
4688  }
4689  Expr *getWeak() const {
4690    assert(NumSubExprs > WEAK);
4691    return cast<Expr>(SubExprs[WEAK]);
4692  }
4693
4694  AtomicOp getOp() const { return Op; }
4695  unsigned getNumSubExprs() { return NumSubExprs; }
4696
4697  Expr **getSubExprs() { return reinterpret_cast<Expr **>(SubExprs); }
4698
4699  bool isVolatile() const {
4700    return getPtr()->getType()->getPointeeType().isVolatileQualified();
4701  }
4702
4703  bool isCmpXChg() const {
4704    return getOp() == AO__c11_atomic_compare_exchange_strong ||
4705           getOp() == AO__c11_atomic_compare_exchange_weak ||
4706           getOp() == AO__atomic_compare_exchange ||
4707           getOp() == AO__atomic_compare_exchange_n;
4708  }
4709
4710  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
4711  SourceLocation getRParenLoc() const { return RParenLoc; }
4712
4713  SourceLocation getLocStart() const LLVM_READONLY { return BuiltinLoc; }
4714  SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
4715
4716  static bool classof(const Stmt *T) {
4717    return T->getStmtClass() == AtomicExprClass;
4718  }
4719
4720  // Iterators
4721  child_range children() {
4722    return child_range(SubExprs, SubExprs+NumSubExprs);
4723  }
4724};
4725}  // end namespace clang
4726
4727#endif
4728