Expr.h revision 0004329758b99d2b92096b353e35c427ebbee622
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" 1830a2e16f6c27f888dd11eba6bbbae1e980078fcbChandler Carruth#include "clang/AST/ASTVector.h" 19478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer#include "clang/AST/Decl.h" 20161755a09898c95d21bfff33707da9ca41cd53c5John McCall#include "clang/AST/DeclAccessPair.h" 215baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall#include "clang/AST/OperationKinds.h" 2230a2e16f6c27f888dd11eba6bbbae1e980078fcbChandler Carruth#include "clang/AST/Stmt.h" 2371a7605977113c795edd44fcbd2302ad49506653Argyrios Kyrtzidis#include "clang/AST/TemplateBase.h" 2430a2e16f6c27f888dd11eba6bbbae1e980078fcbChandler Carruth#include "clang/AST/Type.h" 25223f0ff6a9a5d0eaf63b98b3aa92888b4c088868Jordan Rose#include "clang/Basic/CharInfo.h" 26f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne#include "clang/Basic/TypeTraits.h" 27525a05093a4816af961fe2bc6b8a81c17e2e26c2Chris Lattner#include "llvm/ADT/APFloat.h" 2830a2e16f6c27f888dd11eba6bbbae1e980078fcbChandler Carruth#include "llvm/ADT/APSInt.h" 293b8d116703db8018f855cbb4733ace426422623bNate Begeman#include "llvm/ADT/SmallVector.h" 30b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar#include "llvm/ADT/StringRef.h" 31aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar#include "llvm/Support/Compiler.h" 325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 34c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson class APValue; 359852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramer class ASTContext; 3656ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff class BlockDecl; 37409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson class CXXBaseSpecifier; 389852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramer class CXXMemberCallExpr; 3988a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor class CXXOperatorCallExpr; 409852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramer class CastExpr; 419852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramer class Decl; 429852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramer class IdentifierInfo; 430a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola class MaterializeTemporaryExpr; 449852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramer class NamedDecl; 45f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall class ObjCPropertyRefExpr; 4656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall class OpaqueValueExpr; 479852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramer class ParmVarDecl; 489852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramer class TargetInfo; 499852f58f50b4fc20914fbce5b4454135a42343f4Benjamin Kramer class ValueDecl; 5088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 517ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson/// \brief A simple array of base specifiers. 52686775deca8b8685eb90801495880e3abdd844c2Chris Lattnertypedef SmallVector<CXXBaseSpecifier*, 4> CXXCastPath; 537ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson 540a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola/// \brief An adjustment to be made to the temporary created when emitting a 550a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola/// reference binding, which accesses a particular subobject of that temporary. 560a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindolastruct SubobjectAdjustment { 570a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola enum { 580a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola DerivedToBaseAdjustment, 590a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola FieldAdjustment, 600a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola MemberPointerAdjustment 610a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola } Kind; 620a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola 630a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola 64e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher struct DTB { 65e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher const CastExpr *BasePath; 66e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher const CXXRecordDecl *DerivedClass; 67e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher }; 680a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola 69e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher struct P { 70e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher const MemberPointerType *MPT; 71e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher Expr *RHS; 72e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher }; 73e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher 74e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher union { 75e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher struct DTB DerivedToBase; 76e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher FieldDecl *Field; 77e462c60ac3365d3302b7d0a566c5cb7dbe0e5ae3Eric Christopher struct P Ptr; 780a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola }; 790a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola 800a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola SubobjectAdjustment(const CastExpr *BasePath, 810a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola const CXXRecordDecl *DerivedClass) 820a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola : Kind(DerivedToBaseAdjustment) { 830a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola DerivedToBase.BasePath = BasePath; 840a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola DerivedToBase.DerivedClass = DerivedClass; 850a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola } 860a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola 870a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola SubobjectAdjustment(FieldDecl *Field) 880a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola : Kind(FieldAdjustment) { 890a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola this->Field = Field; 900a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola } 910a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola 920a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola SubobjectAdjustment(const MemberPointerType *MPT, Expr *RHS) 930a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola : Kind(MemberPointerAdjustment) { 940a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola this->Ptr.MPT = MPT; 950a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola this->Ptr.RHS = RHS; 960a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola } 970a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola}; 980a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola 995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Expr - This represents one expression. Note that Expr's are subclasses of 1005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Stmt. This allows an expression to be transparently used any place a Stmt 1015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is required. 1025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 1035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Expr : public Stmt { 1045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType TR; 105898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1068e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCallprotected: 107f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(StmtClass SC, QualType T, ExprValueKind VK, ExprObjectKind OK, 108ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie bool TD, bool VD, bool ID, bool ContainsUnexpandedParameterPack) 109ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie : Stmt(SC) 110561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor { 1118e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.TypeDependent = TD; 1128e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.ValueDependent = VD; 113561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = ID; 114f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprBits.ValueKind = VK; 115f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprBits.ObjectKind = OK; 116bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack; 117898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor setType(T); 118898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 119898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1200b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Construct an empty expression. 1210b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor explicit Expr(StmtClass SC, EmptyShell) : Stmt(SC) { } 1220b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 1231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 124f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor QualType getType() const { return TR; } 1251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setType(QualType t) { 1269d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // In C++, the type of an expression is always adjusted so that it 1279d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // will not have reference type an expression will never have 1289d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // reference type (C++ [expr]p6). Use 1299d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // QualType::getNonReferenceType() to retrieve the non-reference 1309d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // type. Additionally, inspect Expr::isLvalue to determine whether 1319d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // an expression that is adjusted in this manner should be 1329d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // considered an lvalue. 133905d11d53aeb6b26744f44fedc2b2820c7a62df6Douglas Gregor assert((t.isNull() || !t->isReferenceType()) && 1348320aaaa01d931aa234fc3bce05b399ef41898d5Daniel Dunbar "Expressions can't have reference type"); 135f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor 1361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TR = t; 1379d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor } 13877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 139898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isValueDependent - Determines whether this expression is 140898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// value-dependent (C++ [temp.dep.constexpr]). For example, the 141898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// array bound of "Chars" in the following example is 1421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// value-dependent. 143898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @code 144898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// template<int Size, char (&Chars)[Size]> struct meta_string; 145898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @endcode 1468e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall bool isValueDependent() const { return ExprBits.ValueDependent; } 147898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1480b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Set whether this expression is value-dependent or not. 149ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie void setValueDependent(bool VD) { 150ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie ExprBits.ValueDependent = VD; 151561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (VD) 152561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 153561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 1540b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 155898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isTypeDependent - Determines whether this expression is 156898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// type-dependent (C++ [temp.dep.expr]), which means that its type 157898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// could change from one template instantiation to the next. For 158898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// example, the expressions "x" and "x + y" are type-dependent in 159898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// the following code, but "y" is not type-dependent: 160898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @code 1611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// template<typename T> 162898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// void add(T x, int y) { 163898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// x + y; 164898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// } 165898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @endcode 1668e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall bool isTypeDependent() const { return ExprBits.TypeDependent; } 167898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1680b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Set whether this expression is type-dependent or not. 169ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie void setTypeDependent(bool TD) { 170ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie ExprBits.TypeDependent = TD; 171561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (TD) 172561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 173561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 174561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 175561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// \brief Whether this expression is instantiation-dependent, meaning that 176561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// it depends in some way on a template parameter, even if neither its type 177561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// nor (constant) value can change due to the template instantiation. 178561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// 179561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// In the following example, the expression \c sizeof(sizeof(T() + T())) is 180561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// instantiation-dependent (since it involves a template parameter \c T), but 181561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// is neither type- nor value-dependent, since the type of the inner 182561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// \c sizeof is known (\c std::size_t) and therefore the size of the outer 183561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// \c sizeof is known. 184561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// 185561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// \code 186561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// template<typename T> 187561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// void f(T x, T y) { 188561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// sizeof(sizeof(T() + T()); 189561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// } 190561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// \endcode 191561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// 192ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie bool isInstantiationDependent() const { 193ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return ExprBits.InstantiationDependent; 194561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 195ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 196561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// \brief Set whether this expression is instantiation-dependent or not. 197ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie void setInstantiationDependent(bool ID) { 198561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = ID; 199561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 2000b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 201d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \brief Whether this expression contains an unexpanded parameter 2024e24f0f711e2c9fde79f19fa1c80deaab3f3b356Richard Smith /// pack (for C++11 variadic templates). 203d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// 204d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// Given the following function template: 205d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// 206d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \code 207d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// template<typename F, typename ...Types> 208d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// void forward(const F &f, Types &&...args) { 209d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// f(static_cast<Types&&>(args)...); 210d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// } 211d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \endcode 212d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// 213d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// The expressions \c args and \c static_cast<Types&&>(args) both 214d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// contain parameter packs. 215ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie bool containsUnexpandedParameterPack() const { 216ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return ExprBits.ContainsUnexpandedParameterPack; 217d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor } 218d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 219bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /// \brief Set the bit that describes whether this expression 220bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /// contains an unexpanded parameter pack. 221bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor void setContainsUnexpandedParameterPack(bool PP = true) { 222bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = PP; 223bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor } 224bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 2255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getExprLoc - Return the preferred location for the arrow when diagnosing 2265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// a problem with a generic expression. 2274f311183be3d923da9fbe8702c453688b4c426a9Daniel Dunbar SourceLocation getExprLoc() const LLVM_READONLY; 2281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 229026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// isUnusedResultAWarning - Return true if this immediate expression should 230a6115068cde719142eb394db88612c185cabd05bEli Friedman /// be warned about if the result is unused. If so, fill in expr, location, 231a6115068cde719142eb394db88612c185cabd05bEli Friedman /// and ranges with expr to warn on and source locations/ranges appropriate 232a6115068cde719142eb394db88612c185cabd05bEli Friedman /// for a warning. 233a6115068cde719142eb394db88612c185cabd05bEli Friedman bool isUnusedResultAWarning(const Expr *&WarnExpr, SourceLocation &Loc, 234a6115068cde719142eb394db88612c185cabd05bEli Friedman SourceRange &R1, SourceRange &R2, 235a6115068cde719142eb394db88612c185cabd05bEli Friedman ASTContext &Ctx) const; 2361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2377eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// isLValue - True if this expression is an "l-value" according to 2387eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// the rules of the current language. C and C++ give somewhat 2397eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// different rules for this concept, but in general, the result of 2407eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// an l-value expression identifies a specific object whereas the 2417eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// result of an r-value expression is a value detached from any 2427eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// specific storage. 2435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 2444e24f0f711e2c9fde79f19fa1c80deaab3f3b356Richard Smith /// C++11 divides the concept of "r-value" into pure r-values 2457eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// ("pr-values") and so-called expiring values ("x-values"), which 2467eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// identify specific objects that can be safely cannibalized for 2477eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// their resources. This is an unfortunate abuse of terminology on 2487eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// the part of the C++ committee. In Clang, when we say "r-value", 2497eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// we generally mean a pr-value. 2507eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall bool isLValue() const { return getValueKind() == VK_LValue; } 2517eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall bool isRValue() const { return getValueKind() == VK_RValue; } 2527eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall bool isXValue() const { return getValueKind() == VK_XValue; } 2537eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall bool isGLValue() const { return getValueKind() != VK_RValue; } 2547eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall 2557eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall enum LValueClassification { 2565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_Valid, 2575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_NotObjectType, 2585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_IncompleteVoidType, 259fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff LV_DuplicateVectorComponents, 26086f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor LV_InvalidExpression, 261077f490d0a514dcc448475f33f799934252b85a7Fariborz Jahanian LV_InvalidMessageExpression, 2622514a309204341798f96912ce7a90841bea59727Fariborz Jahanian LV_MemberFunction, 263e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian LV_SubObjCPropertySetting, 26436d02af300a207242f0486b4255420d8be796b21Richard Smith LV_ClassTemporary, 26536d02af300a207242f0486b4255420d8be796b21Richard Smith LV_ArrayTemporary 2665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 2677eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// Reasons why an expression might not be an l-value. 2687eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall LValueClassification ClassifyLValue(ASTContext &Ctx) const; 26953202857c60214d80950a975e6e52aebf30bd16aEli Friedman 2705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum isModifiableLvalueResult { 2715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_Valid, 2725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_NotObjectType, 2735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_IncompleteVoidType, 274fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff MLV_DuplicateVectorComponents, 2755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_InvalidExpression, 276ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner MLV_LValueCast, // Specialized form of MLV_InvalidExpression. 2775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_IncompleteType, 2785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_ConstQualified, 2794f6a7d7ead09b439216c32f2de806a998aeb222aSteve Naroff MLV_ArrayType, 28086f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor MLV_NoSetterProperty, 2812514a309204341798f96912ce7a90841bea59727Fariborz Jahanian MLV_MemberFunction, 282e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian MLV_SubObjCPropertySetting, 283077f490d0a514dcc448475f33f799934252b85a7Fariborz Jahanian MLV_InvalidMessageExpression, 28436d02af300a207242f0486b4255420d8be796b21Richard Smith MLV_ClassTemporary, 28536d02af300a207242f0486b4255420d8be796b21Richard Smith MLV_ArrayTemporary 2865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 287ad0fe03b897f9486191e75c8d90c3ffa9b4fd6a5Ted Kremenek /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type, 288ad0fe03b897f9486191e75c8d90c3ffa9b4fd6a5Ted Kremenek /// does not have an incomplete type, does not have a const-qualified type, 289ad0fe03b897f9486191e75c8d90c3ffa9b4fd6a5Ted Kremenek /// and if it is a structure or union, does not have any member (including, 290ad0fe03b897f9486191e75c8d90c3ffa9b4fd6a5Ted Kremenek /// recursively, any member or element of all contained aggregates or unions) 291ad0fe03b897f9486191e75c8d90c3ffa9b4fd6a5Ted Kremenek /// with a const-qualified type. 292ad0fe03b897f9486191e75c8d90c3ffa9b4fd6a5Ted Kremenek /// 293ad0fe03b897f9486191e75c8d90c3ffa9b4fd6a5Ted Kremenek /// \param Loc [in,out] - A source location which *may* be filled 294ad0fe03b897f9486191e75c8d90c3ffa9b4fd6a5Ted Kremenek /// in with the location of the expression making this a 295ad0fe03b897f9486191e75c8d90c3ffa9b4fd6a5Ted Kremenek /// non-modifiable lvalue, if specified. 29644e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx, 29744e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar SourceLocation *Loc = 0) const; 2981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2994e24f0f711e2c9fde79f19fa1c80deaab3f3b356Richard Smith /// \brief The return type of classify(). Represents the C++11 expression 3002111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// taxonomy. 3012111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl class Classification { 3022111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl public: 3032111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \brief The various classification results. Most of these mean prvalue. 3042111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl enum Kinds { 3052111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_LValue, 3062111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_XValue, 3072111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_Function, // Functions cannot be lvalues in C. 3082111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_Void, // Void cannot be an lvalue in C. 3091c860d5640e8eebb11a5d515a761242b66761b0bPeter Collingbourne CL_AddressableVoid, // Void expression whose address can be taken in C. 3102111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_DuplicateVectorComponents, // A vector shuffle with dupes. 3112111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_MemberFunction, // An expression referring to a member function 3122111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_SubObjCPropertySetting, 31336d02af300a207242f0486b4255420d8be796b21Richard Smith CL_ClassTemporary, // A temporary of class type, or subobject thereof. 31436d02af300a207242f0486b4255420d8be796b21Richard Smith CL_ArrayTemporary, // A temporary of array type. 315077f490d0a514dcc448475f33f799934252b85a7Fariborz Jahanian CL_ObjCMessageRValue, // ObjC message is an rvalue 3162111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_PRValue // A prvalue for any other reason, of any other type 3172111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl }; 3182111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \brief The results of modification testing. 3192111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl enum ModifiableType { 3202111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_Untested, // testModifiable was false. 3212111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_Modifiable, 3222111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_RValue, // Not modifiable because it's an rvalue 3232111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_Function, // Not modifiable because it's a function; C++ only 3242111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_LValueCast, // Same as CM_RValue, but indicates GCC cast-as-lvalue ext 3252111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_NoSetterProperty,// Implicit assignment to ObjC property without setter 3262111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_ConstQualified, 3272111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_ArrayType, 3282111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_IncompleteType 3292111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl }; 3302111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 3312111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl private: 3322111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl friend class Expr; 3332111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 3342111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl unsigned short Kind; 3352111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl unsigned short Modifiable; 3362111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 3372111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl explicit Classification(Kinds k, ModifiableType m) 3382111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl : Kind(k), Modifiable(m) 3392111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl {} 3402111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 3412111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl public: 3422111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification() {} 3432111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 3442111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Kinds getKind() const { return static_cast<Kinds>(Kind); } 3452111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl ModifiableType getModifiable() const { 3462111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl assert(Modifiable != CM_Untested && "Did not test for modifiability."); 3472111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl return static_cast<ModifiableType>(Modifiable); 3482111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl } 3492111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isLValue() const { return Kind == CL_LValue; } 3502111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isXValue() const { return Kind == CL_XValue; } 3512111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isGLValue() const { return Kind <= CL_XValue; } 3522111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isPRValue() const { return Kind >= CL_Function; } 3532111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isRValue() const { return Kind >= CL_XValue; } 3542111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isModifiable() const { return getModifiable() == CM_Modifiable; } 355ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3562c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor /// \brief Create a simple, modifiably lvalue 3572c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor static Classification makeSimpleLValue() { 3582c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor return Classification(CL_LValue, CM_Modifiable); 3592c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor } 360ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3612111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl }; 3624e24f0f711e2c9fde79f19fa1c80deaab3f3b356Richard Smith /// \brief Classify - Classify this expression according to the C++11 3632111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// expression taxonomy. 3642111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// 3654e24f0f711e2c9fde79f19fa1c80deaab3f3b356Richard Smith /// C++11 defines ([basic.lval]) a new taxonomy of expressions to replace the 3662111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// old lvalue vs rvalue. This function determines the type of expression this 3672111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// is. There are three expression types: 3682111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// - lvalues are classical lvalues as in C++03. 3692111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// - prvalues are equivalent to rvalues in C++03. 3702111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// - xvalues are expressions yielding unnamed rvalue references, e.g. a 3712111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// function returning an rvalue reference. 3722111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// lvalues and xvalues are collectively referred to as glvalues, while 3732111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// prvalues and xvalues together form rvalues. 3742111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification Classify(ASTContext &Ctx) const { 3752111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl return ClassifyImpl(Ctx, 0); 3762111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl } 3772111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 378369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// \brief ClassifyModifiable - Classify this expression according to the 3794e24f0f711e2c9fde79f19fa1c80deaab3f3b356Richard Smith /// C++11 expression taxonomy, and see if it is valid on the left side 3802111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// of an assignment. 3812111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// 3822111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// This function extends classify in that it also tests whether the 3832111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// expression is modifiable (C99 6.3.2.1p1). 3842111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \param Loc A source location that might be filled with a relevant location 3852111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// if the expression is not modifiable. 3862111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification ClassifyModifiable(ASTContext &Ctx, SourceLocation &Loc) const{ 3872111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl return ClassifyImpl(Ctx, &Loc); 3882111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl } 3892111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 390f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// getValueKindForType - Given a formal return or parameter type, 391f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// give its value kind. 392f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall static ExprValueKind getValueKindForType(QualType T) { 393f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall if (const ReferenceType *RT = T->getAs<ReferenceType>()) 3940943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall return (isa<LValueReferenceType>(RT) 3950943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall ? VK_LValue 3960943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall : (RT->getPointeeType()->isFunctionType() 3970943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall ? VK_LValue : VK_XValue)); 398f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall return VK_RValue; 399f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall } 400f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 401f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// getValueKind - The value kind that this expression produces. 402f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind getValueKind() const { 403f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall return static_cast<ExprValueKind>(ExprBits.ValueKind); 404f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall } 405f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 406f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// getObjectKind - The object kind that this expression produces. 407f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// Object kinds are meaningful only for expressions that yield an 408f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// l-value or x-value. 409f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprObjectKind getObjectKind() const { 410f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall return static_cast<ExprObjectKind>(ExprBits.ObjectKind); 411f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall } 412f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 41356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall bool isOrdinaryOrBitFieldObject() const { 41456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall ExprObjectKind OK = getObjectKind(); 41556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return (OK == OK_Ordinary || OK == OK_BitField); 41656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 41756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 418f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// setValueKind - Set the value kind produced by this expression. 419f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall void setValueKind(ExprValueKind Cat) { ExprBits.ValueKind = Cat; } 420f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 421f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// setObjectKind - Set the object kind produced by this expression. 422f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall void setObjectKind(ExprObjectKind Cat) { ExprBits.ObjectKind = Cat; } 423f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 4242111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redlprivate: 4252111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification ClassifyImpl(ASTContext &Ctx, SourceLocation *Loc) const; 4262111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 4272111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redlpublic: 4282111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 429993f43f24d7a45a5cd4678a3316b0852261fc5d4John McCall /// \brief Returns true if this expression is a gl-value that 430993f43f24d7a45a5cd4678a3316b0852261fc5d4John McCall /// potentially refers to a bit-field. 431993f43f24d7a45a5cd4678a3316b0852261fc5d4John McCall /// 432993f43f24d7a45a5cd4678a3316b0852261fc5d4John McCall /// In C++, whether a gl-value refers to a bitfield is essentially 433993f43f24d7a45a5cd4678a3316b0852261fc5d4John McCall /// an aspect of the value-kind type system. 434993f43f24d7a45a5cd4678a3316b0852261fc5d4John McCall bool refersToBitField() const { return getObjectKind() == OK_BitField; } 435993f43f24d7a45a5cd4678a3316b0852261fc5d4John McCall 43633bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor /// \brief If this expression refers to a bit-field, retrieve the 43733bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor /// declaration of that bit-field. 438993f43f24d7a45a5cd4678a3316b0852261fc5d4John McCall /// 439993f43f24d7a45a5cd4678a3316b0852261fc5d4John McCall /// Note that this returns a non-null pointer in subtly different 440993f43f24d7a45a5cd4678a3316b0852261fc5d4John McCall /// places than refersToBitField returns true. In particular, this can 441993f43f24d7a45a5cd4678a3316b0852261fc5d4John McCall /// return a non-null pointer even for r-values loaded from 442993f43f24d7a45a5cd4678a3316b0852261fc5d4John McCall /// bit-fields, but it will return null for a conditional bit-field. 443993f43f24d7a45a5cd4678a3316b0852261fc5d4John McCall FieldDecl *getSourceBitField(); 444993f43f24d7a45a5cd4678a3316b0852261fc5d4John McCall 445993f43f24d7a45a5cd4678a3316b0852261fc5d4John McCall const FieldDecl *getSourceBitField() const { 446993f43f24d7a45a5cd4678a3316b0852261fc5d4John McCall return const_cast<Expr*>(this)->getSourceBitField(); 44738d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson } 4481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 449f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall /// \brief If this expression is an l-value for an Objective C 450f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall /// property, find the underlying property reference expression. 451f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall const ObjCPropertyRefExpr *getObjCProperty() const; 452f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall 453bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks /// \brief Check if this expression is the ObjC 'self' implicit parameter. 454bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks bool isObjCSelfExpr() const; 455bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks 456093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson /// \brief Returns whether this expression refers to a vector element. 457093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson bool refersToVectorElement() const; 4584919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall 4594919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall /// \brief Returns whether this expression has a placeholder type. 4604919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall bool hasPlaceholderType() const { 4614919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall return getType()->isPlaceholderType(); 4624919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall } 4634919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall 4644919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall /// \brief Returns whether this expression has a specific placeholder type. 4654919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall bool hasPlaceholderType(BuiltinType::Kind K) const { 46685def357129b6cdfd69a66ad0e6994506418a2a9John McCall assert(BuiltinType::isPlaceholderTypeKind(K)); 4674919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall if (const BuiltinType *BT = dyn_cast<BuiltinType>(getType())) 4684919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall return BT->getKind() == K; 4694919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall return false; 4704919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall } 471ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 4722b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// isKnownToHaveBooleanValue - Return true if this is an integer expression 4732b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// that is known to return 0 or 1. This happens for _Bool/bool expressions 4742b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// but also int expressions which are produced by things like comparisons in 4752b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// C. 4762b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner bool isKnownToHaveBooleanValue() const; 477ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 4785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isIntegerConstantExpr - Return true if this expression is a valid integer 4795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// constant expression, and, if so, return its value in Result. If not a 4805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// valid i-c-e, return false and fill in Loc (if specified) with the location 4815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// of the invalid expression. 482282e7e66748cc6dd14d6f7f2cb52e5373c531e61Richard Smith /// 483282e7e66748cc6dd14d6f7f2cb52e5373c531e61Richard Smith /// Note: This does not perform the implicit conversions required by C++11 484282e7e66748cc6dd14d6f7f2cb52e5373c531e61Richard Smith /// [expr.const]p5. 48532b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper bool isIntegerConstantExpr(llvm::APSInt &Result, const ASTContext &Ctx, 486590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner SourceLocation *Loc = 0, 4875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isEvaluated = true) const; 48832b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper bool isIntegerConstantExpr(const ASTContext &Ctx, 48932b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper SourceLocation *Loc = 0) const; 4900e35b4ecee380c2b4c33d75da6bc2fb6f6bc7df3Richard Smith 49170488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith /// isCXX98IntegralConstantExpr - Return true if this expression is an 49270488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith /// integral constant expression in C++98. Can only be used in C++. 49332b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper bool isCXX98IntegralConstantExpr(const ASTContext &Ctx) const; 49470488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith 4954c3fc9b38d3723f73e4ded594cebf38c76f91d93Richard Smith /// isCXX11ConstantExpr - Return true if this expression is a constant 4964c3fc9b38d3723f73e4ded594cebf38c76f91d93Richard Smith /// expression in C++11. Can only be used in C++. 497282e7e66748cc6dd14d6f7f2cb52e5373c531e61Richard Smith /// 498282e7e66748cc6dd14d6f7f2cb52e5373c531e61Richard Smith /// Note: This does not perform the implicit conversions required by C++11 499282e7e66748cc6dd14d6f7f2cb52e5373c531e61Richard Smith /// [expr.const]p5. 50032b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper bool isCXX11ConstantExpr(const ASTContext &Ctx, APValue *Result = 0, 5014c3fc9b38d3723f73e4ded594cebf38c76f91d93Richard Smith SourceLocation *Loc = 0) const; 5024c3fc9b38d3723f73e4ded594cebf38c76f91d93Richard Smith 503745f5147e065900267c85a5568785a1991d4838fRichard Smith /// isPotentialConstantExpr - Return true if this function's definition 504745f5147e065900267c85a5568785a1991d4838fRichard Smith /// might be usable in a constant expression in C++11, if it were marked 505745f5147e065900267c85a5568785a1991d4838fRichard Smith /// constexpr. Return false if the function can never produce a constant 506745f5147e065900267c85a5568785a1991d4838fRichard Smith /// expression, along with diagnostics describing why not. 507745f5147e065900267c85a5568785a1991d4838fRichard Smith static bool isPotentialConstantExpr(const FunctionDecl *FD, 508cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko SmallVectorImpl< 509745f5147e065900267c85a5568785a1991d4838fRichard Smith PartialDiagnosticAt> &Diags); 510745f5147e065900267c85a5568785a1991d4838fRichard Smith 5110e35b4ecee380c2b4c33d75da6bc2fb6f6bc7df3Richard Smith /// isConstantInitializer - Returns true if this expression can be emitted to 5120e35b4ecee380c2b4c33d75da6bc2fb6f6bc7df3Richard Smith /// IR as a constant, and thus can be used as a constant initializer in C. 5134204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall bool isConstantInitializer(ASTContext &Ctx, bool ForRef) const; 5141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5151e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith /// EvalStatus is a struct with detailed info about an evaluation in progress. 5161e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith struct EvalStatus { 51794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// HasSideEffects - Whether the evaluated expression has side effects. 51894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// For example, (f() && 0) can be folded, but it still has side effects. 51994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson bool HasSideEffects; 5201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 521dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith /// Diag - If this is non-null, it will be filled in with a stack of notes 522dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith /// indicating why evaluation failed (or why it failed to produce a constant 523dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith /// expression). 524dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith /// If the expression is unfoldable, the notes will indicate why it's not 525dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith /// foldable. If the expression is foldable, but not a constant expression, 526dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith /// the notes will describes why it isn't a constant expression. If the 527dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith /// expression *is* a constant expression, no notes will be produced. 528cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko SmallVectorImpl<PartialDiagnosticAt> *Diag; 529dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith 530dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith EvalStatus() : HasSideEffects(false), Diag(0) {} 531e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara 532e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara // hasSideEffects - Return true if the evaluated expression has 533e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara // side effects. 534e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara bool hasSideEffects() const { 535e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara return HasSideEffects; 536e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara } 53794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson }; 53894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson 5391e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith /// EvalResult is a struct with detailed info about an evaluated expression. 5401e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith struct EvalResult : EvalStatus { 5411e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith /// Val - This is the value the expression can be folded to. 5421e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith APValue Val; 5431e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith 5441e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith // isGlobalLValue - Return true if the evaluated lvalue expression 5451e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith // is global. 5461e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith bool isGlobalLValue() const; 5471e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith }; 5481e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith 54951f4708c00110940ca3f337961915f2ca1668375Richard Smith /// EvaluateAsRValue - Return true if this is a constant which we can fold to 55051f4708c00110940ca3f337961915f2ca1668375Richard Smith /// an rvalue using any crazy technique (that has nothing to do with language 55151f4708c00110940ca3f337961915f2ca1668375Richard Smith /// standards) that we want to, even if the expression has side-effects. If 55251f4708c00110940ca3f337961915f2ca1668375Richard Smith /// this function returns true, it returns the folded constant in Result. If 55351f4708c00110940ca3f337961915f2ca1668375Richard Smith /// the expression is a glvalue, an lvalue-to-rvalue conversion will be 55451f4708c00110940ca3f337961915f2ca1668375Richard Smith /// applied. 55551f4708c00110940ca3f337961915f2ca1668375Richard Smith bool EvaluateAsRValue(EvalResult &Result, const ASTContext &Ctx) const; 5565b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson 557cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall /// EvaluateAsBooleanCondition - Return true if this is a constant 558cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall /// which we we can fold and convert to a boolean condition using 559a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith /// any crazy technique that we want to, even if the expression has 560a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith /// side-effects. 5614ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool EvaluateAsBooleanCondition(bool &Result, const ASTContext &Ctx) const; 562cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall 56380d4b55db94db2172a04617d1a80feca6bbcea5cRichard Smith enum SideEffectsKind { SE_NoSideEffects, SE_AllowSideEffects }; 56480d4b55db94db2172a04617d1a80feca6bbcea5cRichard Smith 565a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith /// EvaluateAsInt - Return true if this is a constant which we can fold and 56680d4b55db94db2172a04617d1a80feca6bbcea5cRichard Smith /// convert to an integer, using any crazy technique that we want to. 56780d4b55db94db2172a04617d1a80feca6bbcea5cRichard Smith bool EvaluateAsInt(llvm::APSInt &Result, const ASTContext &Ctx, 56880d4b55db94db2172a04617d1a80feca6bbcea5cRichard Smith SideEffectsKind AllowSideEffects = SE_NoSideEffects) const; 569a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith 57051f4708c00110940ca3f337961915f2ca1668375Richard Smith /// isEvaluatable - Call EvaluateAsRValue to see if this expression can be 57151f4708c00110940ca3f337961915f2ca1668375Richard Smith /// constant folded without side-effects, but discard the result. 5724ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool isEvaluatable(const ASTContext &Ctx) const; 573c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson 5746ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian /// HasSideEffects - This routine returns true for all those expressions 57560b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith /// which have any effect other than producing a value. Example is a function 57660b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith /// call, volatile variable read, or throwing an exception. 5774ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool HasSideEffects(const ASTContext &Ctx) const; 57851f4708c00110940ca3f337961915f2ca1668375Richard Smith 57925d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor /// \brief Determine whether this expression involves a call to any function 58025d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor /// that is not trivial. 58125d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor bool hasNonTrivialCall(ASTContext &Ctx); 5820004329758b99d2b92096b353e35c427ebbee622Richard Smith 58351f4708c00110940ca3f337961915f2ca1668375Richard Smith /// EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded 58451f4708c00110940ca3f337961915f2ca1668375Richard Smith /// integer. This must be called on an expression that constant folds to an 58551f4708c00110940ca3f337961915f2ca1668375Richard Smith /// integer. 586a18e70b25c85d7e653e642b5e6e58d6063af3d83Fariborz Jahanian llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx, 587cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko SmallVectorImpl<PartialDiagnosticAt> *Diag=0) const; 5880004329758b99d2b92096b353e35c427ebbee622Richard Smith 5890004329758b99d2b92096b353e35c427ebbee622Richard Smith void EvaluateForOverflow(const ASTContext &Ctx) const; 59051fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson 59151f4708c00110940ca3f337961915f2ca1668375Richard Smith /// EvaluateAsLValue - Evaluate an expression to see if we can fold it to an 59251f4708c00110940ca3f337961915f2ca1668375Richard Smith /// lvalue with link time known address, with no side-effects. 5934ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx) const; 5941b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson 595099e7f647ccda915513f2b2ec53352dc756082d3Richard Smith /// EvaluateAsInitializer - Evaluate an expression as if it were the 596099e7f647ccda915513f2b2ec53352dc756082d3Richard Smith /// initializer of the given declaration. Returns true if the initializer 597099e7f647ccda915513f2b2ec53352dc756082d3Richard Smith /// can be folded to a constant, and produces any relevant notes. In C++11, 598099e7f647ccda915513f2b2ec53352dc756082d3Richard Smith /// notes will be produced if the expression is not a constant expression. 599099e7f647ccda915513f2b2ec53352dc756082d3Richard Smith bool EvaluateAsInitializer(APValue &Result, const ASTContext &Ctx, 600099e7f647ccda915513f2b2ec53352dc756082d3Richard Smith const VarDecl *VD, 601cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko SmallVectorImpl<PartialDiagnosticAt> &Notes) const; 602099e7f647ccda915513f2b2ec53352dc756082d3Richard Smith 60382214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Enumeration used to describe the kind of Null pointer constant 60482214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// returned from \c isNullPointerConstant(). 60582214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth enum NullPointerConstantKind { 60682214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Expression is not a Null pointer constant. 60782214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NPCK_NotNull = 0, 60882214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 60950800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie /// \brief Expression is a Null pointer constant built from a zero integer 61050800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie /// expression that is not a simple, possibly parenthesized, zero literal. 61150800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie /// C++ Core Issue 903 will classify these expressions as "not pointers" 61250800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie /// once it is adopted. 61350800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie /// http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#903 61450800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie NPCK_ZeroExpression, 61550800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie 61650800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie /// \brief Expression is a Null pointer constant built from a literal zero. 61750800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie NPCK_ZeroLiteral, 61882214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 6194e24f0f711e2c9fde79f19fa1c80deaab3f3b356Richard Smith /// \brief Expression is a C++11 nullptr. 6204e24f0f711e2c9fde79f19fa1c80deaab3f3b356Richard Smith NPCK_CXX11_nullptr, 62182214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 62282214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Expression is a GNU-style __null constant. 62382214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NPCK_GNUNull 62482214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth }; 62582214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 626ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Enumeration used to describe how \c isNullPointerConstant() 627ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// should cope with value-dependent expressions. 628ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor enum NullPointerConstantValueDependence { 629ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that the expression should never be value-dependent. 630ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_NeverValueDependent = 0, 631ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 632ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that a value-dependent expression of integral or 633ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// dependent type should be considered a null pointer constant. 634ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_ValueDependentIsNull, 635ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 636ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that a value-dependent expression should be considered 637ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// to never be a null pointer constant. 638ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_ValueDependentIsNotNull 639ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor }; 640ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 64182214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to 64282214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// a Null pointer constant. The return value can further distinguish the 64382214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// kind of NULL pointer constant that was detected. 64482214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NullPointerConstantKind isNullPointerConstant( 64582214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth ASTContext &Ctx, 64682214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NullPointerConstantValueDependence NPC) const; 647efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson 64844baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian /// isOBJCGCCandidate - Return true if this expression may be used in a read/ 6491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// write barrier. 650102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian bool isOBJCGCCandidate(ASTContext &Ctx) const; 6511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 65211ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis /// \brief Returns true if this expression is a bound member function. 65311ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis bool isBoundMemberFunction(ASTContext &Ctx) const; 65411ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis 655864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// \brief Given an expression of bound-member type, find the type 656864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// of the member. Returns null if this is an *overloaded* bound 657864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// member expression. 658864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall static QualType findBoundMemberType(const Expr *expr); 659864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 66091a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall /// IgnoreImpCasts - Skip past any implicit casts which might 66191a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall /// surround this expression. Only skips ImplicitCastExprs. 662f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar Expr *IgnoreImpCasts() LLVM_READONLY; 66391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 6647e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall /// IgnoreImplicit - Skip past any implicit AST nodes which might 6657e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall /// surround this expression. 666f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar Expr *IgnoreImplicit() LLVM_READONLY { 667f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar return cast<Expr>(Stmt::IgnoreImplicit()); 668f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar } 6697e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall 670132283beb1b032e0acd09bdfb45dceadeea0026eJordan Rose const Expr *IgnoreImplicit() const LLVM_READONLY { 671132283beb1b032e0acd09bdfb45dceadeea0026eJordan Rose return const_cast<Expr*>(this)->IgnoreImplicit(); 672132283beb1b032e0acd09bdfb45dceadeea0026eJordan Rose } 673132283beb1b032e0acd09bdfb45dceadeea0026eJordan Rose 6744e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// IgnoreParens - Ignore parentheses. If this Expr is a ParenExpr, return 6751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// its subexpression. If that subexpression is also a ParenExpr, 6764e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// then this method recursively returns its subexpression, and so forth. 6774e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// Otherwise, the method returns the current Expr. 678f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar Expr *IgnoreParens() LLVM_READONLY; 67956f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner 68056f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner /// IgnoreParenCasts - Ignore parentheses and casts. Strip off any ParenExpr 68127c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor /// or CastExprs, returning their operand. 682f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar Expr *IgnoreParenCasts() LLVM_READONLY; 6831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 684ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// IgnoreParenImpCasts - Ignore parentheses and implicit casts. Strip off 685ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// any ParenExpr or ImplicitCastExprs, returning their operand. 686f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar Expr *IgnoreParenImpCasts() LLVM_READONLY; 6872fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall 6882f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg /// IgnoreConversionOperator - Ignore conversion operator. If this Expr is a 6892f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg /// call to a conversion operator, return the argument. 690f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar Expr *IgnoreConversionOperator() LLVM_READONLY; 6912f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg 692f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar const Expr *IgnoreConversionOperator() const LLVM_READONLY { 6932f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg return const_cast<Expr*>(this)->IgnoreConversionOperator(); 6942f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg } 6952f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg 696f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar const Expr *IgnoreParenImpCasts() const LLVM_READONLY { 6974d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek return const_cast<Expr*>(this)->IgnoreParenImpCasts(); 6984d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek } 699ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 700f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall /// Ignore parentheses and lvalue casts. Strip off any ParenExpr and 701f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall /// CastExprs that represent lvalue casts, returning their operand. 702f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar Expr *IgnoreParenLValueCasts() LLVM_READONLY; 703ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 704f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar const Expr *IgnoreParenLValueCasts() const LLVM_READONLY { 705f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall return const_cast<Expr*>(this)->IgnoreParenLValueCasts(); 706f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 7074d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek 708ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the 709ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// value (including ptr->int casts of the same size). Strip off any 710ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// ParenExpr or CastExprs, returning their operand. 711f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar Expr *IgnoreParenNoopCasts(ASTContext &Ctx) LLVM_READONLY; 7121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 713632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola /// Ignore parentheses and derived-to-base casts. 714632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola Expr *ignoreParenBaseCasts() LLVM_READONLY; 715632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola 716632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola const Expr *ignoreParenBaseCasts() const LLVM_READONLY { 717632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola return const_cast<Expr*>(this)->ignoreParenBaseCasts(); 718632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola } 719632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola 7206eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// \brief Determine whether this expression is a default function argument. 7216eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// 7226eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// Default arguments are implicitly generated in the abstract syntax tree 723ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// by semantic analysis for function calls, object constructions, etc. in 7246eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// C++. Default arguments are represented by \c CXXDefaultArgExpr nodes; 7256eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// this routine also looks through any implicit casts to determine whether 7266eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// the expression is a default argument. 7276eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor bool isDefaultArgument() const; 728ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 729558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall /// \brief Determine whether the result of this expression is a 730558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall /// temporary object of the given class type. 731558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const; 7322f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 73375e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor /// \brief Whether this expression is an implicit reference to 'this' in C++. 73475e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor bool isImplicitCXXThis() const; 73591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 736f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar const Expr *IgnoreImpCasts() const LLVM_READONLY { 73791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall return const_cast<Expr*>(this)->IgnoreImpCasts(); 73891a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall } 739f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar const Expr *IgnoreParens() const LLVM_READONLY { 7404e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek return const_cast<Expr*>(this)->IgnoreParens(); 7414e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek } 742f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar const Expr *IgnoreParenCasts() const LLVM_READONLY { 74356f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner return const_cast<Expr*>(this)->IgnoreParenCasts(); 74456f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner } 745f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar const Expr *IgnoreParenNoopCasts(ASTContext &Ctx) const LLVM_READONLY { 746ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner return const_cast<Expr*>(this)->IgnoreParenNoopCasts(Ctx); 747ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 7481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 749cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko static bool hasAnyTypeDependentArguments(ArrayRef<Expr *> Exprs); 750898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 7518d852e35adb46e0799538dfc9c80d44f27cd3597Rafael Espindola /// \brief For an expression of class type or pointer to class type, 7528d852e35adb46e0799538dfc9c80d44f27cd3597Rafael Espindola /// return the most derived class decl the expression is known to refer to. 7530b4fe503ef00d9f8ea330850d3e3b303e9c7c876Rafael Espindola /// 7540b4fe503ef00d9f8ea330850d3e3b303e9c7c876Rafael Espindola /// If this expression is a cast, this method looks through it to find the 7558d852e35adb46e0799538dfc9c80d44f27cd3597Rafael Espindola /// most derived decl that can be inferred from the expression. 7568d852e35adb46e0799538dfc9c80d44f27cd3597Rafael Espindola /// This is valid because derived-to-base conversions have undefined 7578d852e35adb46e0799538dfc9c80d44f27cd3597Rafael Espindola /// behavior if the object isn't dynamically of the derived type. 7588d852e35adb46e0799538dfc9c80d44f27cd3597Rafael Espindola const CXXRecordDecl *getBestDynamicClassType() const; 7590b4fe503ef00d9f8ea330850d3e3b303e9c7c876Rafael Espindola 7600a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola /// Walk outwards from an expression we want to bind a reference to and 7610a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola /// find the expression whose lifetime needs to be extended. Record 7624e43dec4df9d7dd8e07b47bb15967f1b733a9bc6Richard Smith /// the LHSs of comma expressions and adjustments needed along the path. 7634e43dec4df9d7dd8e07b47bb15967f1b733a9bc6Richard Smith const Expr *skipRValueSubobjectAdjustments( 7644e43dec4df9d7dd8e07b47bb15967f1b733a9bc6Richard Smith SmallVectorImpl<const Expr *> &CommaLHS, 7654e43dec4df9d7dd8e07b47bb15967f1b733a9bc6Richard Smith SmallVectorImpl<SubobjectAdjustment> &Adjustments) const; 7660a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola 7670a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola /// Skip irrelevant expressions to find what should be materialize for 7680a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola /// binding with a reference. 7690a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola const Expr * 7700a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola findMaterializedTemporary(const MaterializeTemporaryExpr *&MTE) const; 7710a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola 7721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 7735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() >= firstExprConstant && 7741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump T->getStmtClass() <= lastExprConstant; 7755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7795549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek//===----------------------------------------------------------------------===// 7805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Primary Expressions. 7815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 7825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 78356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// OpaqueValueExpr - An expression referring to an opaque object of a 78456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// fixed type and value class. These don't correspond to concrete 78556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// syntax; instead they're used to express operations (usually copy 78656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// operations) on values whose source is generally obvious from 78756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// context. 78856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass OpaqueValueExpr : public Expr { 78956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall friend class ASTStmtReader; 79056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *SourceExpr; 79156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation Loc; 792ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 79356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallpublic: 794ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie OpaqueValueExpr(SourceLocation Loc, QualType T, ExprValueKind VK, 79597df54e0c075bc8d6a869597e771dad0c11a2180Douglas Gregor ExprObjectKind OK = OK_Ordinary, 79697df54e0c075bc8d6a869597e771dad0c11a2180Douglas Gregor Expr *SourceExpr = 0) 79756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : Expr(OpaqueValueExprClass, T, VK, OK, 79897df54e0c075bc8d6a869597e771dad0c11a2180Douglas Gregor T->isDependentType(), 79997df54e0c075bc8d6a869597e771dad0c11a2180Douglas Gregor T->isDependentType() || 80097df54e0c075bc8d6a869597e771dad0c11a2180Douglas Gregor (SourceExpr && SourceExpr->isValueDependent()), 801561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor T->isInstantiationDependentType(), 802ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie false), 80397df54e0c075bc8d6a869597e771dad0c11a2180Douglas Gregor SourceExpr(SourceExpr), Loc(Loc) { 80456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 80556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 80656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// Given an expression which invokes a copy constructor --- i.e. a 80756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// CXXConstructExpr, possibly wrapped in an ExprWithCleanups --- 80856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// find the OpaqueValueExpr that's the source of the construction. 80956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static const OpaqueValueExpr *findInCopyConstruct(const Expr *expr); 81056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 81156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall explicit OpaqueValueExpr(EmptyShell Empty) 81256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : Expr(OpaqueValueExprClass, Empty) { } 81356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 81456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief Retrieve the location of this expression. 81556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation getLocation() const { return Loc; } 816ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 81765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { 81865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return SourceExpr ? SourceExpr->getLocStart() : Loc; 81965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen } 82065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { 82165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return SourceExpr ? SourceExpr->getLocEnd() : Loc; 82256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 8234f311183be3d923da9fbe8702c453688b4c426a9Daniel Dunbar SourceLocation getExprLoc() const LLVM_READONLY { 82456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (SourceExpr) return SourceExpr->getExprLoc(); 82556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return Loc; 82656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 82756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 82856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall child_range children() { return child_range(); } 82956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 83056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// The source expression of an opaque value expression is the 83156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// expression which originally generated the value. This is 83256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// provided as a convenience for analyses that don't wish to 83356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// precisely model the execution behavior of the program. 83456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// 83556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// The source expression is typically set when building the 83656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// expression which binds the opaque value expression in the first 83756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// place. 83856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getSourceExpr() const { return SourceExpr; } 83956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 84056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const Stmt *T) { 84156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return T->getStmtClass() == OpaqueValueExprClass; 84256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 84356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall}; 84456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 845cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// \brief A reference to a declared variable, function, enum, etc. 846cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// [C99 6.5.1p2] 847cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// 848cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// This encodes all the information about how a declaration is referenced 849cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// within an expression. 850cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// 851cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// There are several optional constructs attached to DeclRefExprs only when 852cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// they apply in order to conserve memory. These are laid out past the end of 853cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// the object, and flags in the DeclRefExprBitfield track whether they exist: 854cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// 855cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// DeclRefExprBits.HasQualifier: 856cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// Specifies when this declaration reference expression has a C++ 857cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// nested-name-specifier. 8583aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth/// DeclRefExprBits.HasFoundDecl: 8593aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth/// Specifies when this declaration reference expression has a record of 8603aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth/// a NamedDecl (different from the referenced ValueDecl) which was found 8613aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth/// during name lookup and/or overload resolution. 862e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara/// DeclRefExprBits.HasTemplateKWAndArgsInfo: 863cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// Specifies when this declaration reference expression has an explicit 864e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara/// C++ template keyword and/or template argument list. 865f4b88a45902af1802a1cb42ba48b1c474474f228John McCall/// DeclRefExprBits.RefersToEnclosingLocal 866f4b88a45902af1802a1cb42ba48b1c474474f228John McCall/// Specifies when this declaration reference expression (validly) 867f4b88a45902af1802a1cb42ba48b1c474474f228John McCall/// refers to a local variable from a different function. 8685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclRefExpr : public Expr { 869cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth /// \brief The declaration that we are referencing. 870cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth ValueDecl *D; 8712577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 872cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth /// \brief The location of the declaration name itself. 8735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 8749e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis 875cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth /// \brief Provides source/type location info for the declaration name 876cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth /// embedded in D. 8772577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameLoc DNLoc; 8782577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 8796857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// \brief Helper to retrieve the optional NestedNameSpecifierLoc. 8806857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth NestedNameSpecifierLoc &getInternalQualifierLoc() { 8817e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth assert(hasQualifier()); 8826857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth return *reinterpret_cast<NestedNameSpecifierLoc *>(this + 1); 883a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 884cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth 8856857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// \brief Helper to retrieve the optional NestedNameSpecifierLoc. 8866857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth const NestedNameSpecifierLoc &getInternalQualifierLoc() const { 8876857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth return const_cast<DeclRefExpr *>(this)->getInternalQualifierLoc(); 888a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 889096832c5ed5b9106fa177ebc148489760c3bc496John McCall 8903aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// \brief Test whether there is a distinct FoundDecl attached to the end of 8913aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// this DRE. 8923aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth bool hasFoundDecl() const { return DeclRefExprBits.HasFoundDecl; } 8933aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 8943aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// \brief Helper to retrieve the optional NamedDecl through which this 895063820655db8121f0022a7c51458463c7250324cBenjamin Kramer /// reference occurred. 8963aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *&getInternalFoundDecl() { 8973aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth assert(hasFoundDecl()); 8983aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth if (hasQualifier()) 8993aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return *reinterpret_cast<NamedDecl **>(&getInternalQualifierLoc() + 1); 9003aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return *reinterpret_cast<NamedDecl **>(this + 1); 9013aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth } 9023aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 9033aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// \brief Helper to retrieve the optional NamedDecl through which this 904063820655db8121f0022a7c51458463c7250324cBenjamin Kramer /// reference occurred. 9053aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *getInternalFoundDecl() const { 9063aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return const_cast<DeclRefExpr *>(this)->getInternalFoundDecl(); 9073aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth } 9083aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 9099db7a7eb4e23758e041752c9c0c0ec1663d5a0afCraig Topper DeclRefExpr(const ASTContext &Ctx, 9103d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel Dunbar NestedNameSpecifierLoc QualifierLoc, 911e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 912f4b88a45902af1802a1cb42ba48b1c474474f228John McCall ValueDecl *D, bool refersToEnclosingLocal, 913f4b88a45902af1802a1cb42ba48b1c474474f228John McCall const DeclarationNameInfo &NameInfo, 9143aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *FoundD, 9152577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const TemplateArgumentListInfo *TemplateArgs, 916f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK); 9172577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 918663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis /// \brief Construct an empty declaration reference expression. 919663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis explicit DeclRefExpr(EmptyShell Empty) 920663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis : Expr(DeclRefExprClass, Empty) { } 9217e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 9220da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor /// \brief Computes the type- and value-dependence flags for this 9230da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor /// declaration reference expression. 9249db7a7eb4e23758e041752c9c0c0ec1663d5a0afCraig Topper void computeDependence(const ASTContext &C); 9259e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis 9265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 927f4b88a45902af1802a1cb42ba48b1c474474f228John McCall DeclRefExpr(ValueDecl *D, bool refersToEnclosingLocal, QualType T, 928f4b88a45902af1802a1cb42ba48b1c474474f228John McCall ExprValueKind VK, SourceLocation L, 9295b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor const DeclarationNameLoc &LocInfo = DeclarationNameLoc()) 930561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Expr(DeclRefExprClass, T, VK, OK_Ordinary, false, false, false, false), 9315b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor D(D), Loc(L), DNLoc(LocInfo) { 932cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth DeclRefExprBits.HasQualifier = 0; 933e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara DeclRefExprBits.HasTemplateKWAndArgsInfo = 0; 9343aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth DeclRefExprBits.HasFoundDecl = 0; 9357cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara DeclRefExprBits.HadMultipleCandidates = 0; 936f4b88a45902af1802a1cb42ba48b1c474474f228John McCall DeclRefExprBits.RefersToEnclosingLocal = refersToEnclosingLocal; 9373d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel Dunbar computeDependence(D->getASTContext()); 9380da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor } 9391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9409db7a7eb4e23758e041752c9c0c0ec1663d5a0afCraig Topper static DeclRefExpr *Create(const ASTContext &Context, 94140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 942e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 943dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *D, 944f4b88a45902af1802a1cb42ba48b1c474474f228John McCall bool isEnclosingLocal, 945a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation NameLoc, 946f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK, 9473aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *FoundD = 0, 9480da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor const TemplateArgumentListInfo *TemplateArgs = 0); 949663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis 9509db7a7eb4e23758e041752c9c0c0ec1663d5a0afCraig Topper static DeclRefExpr *Create(const ASTContext &Context, 95140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 952e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 9532577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ValueDecl *D, 954f4b88a45902af1802a1cb42ba48b1c474474f228John McCall bool isEnclosingLocal, 9552577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 956f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK, 9573aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *FoundD = 0, 9582577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const TemplateArgumentListInfo *TemplateArgs = 0); 9592577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 960663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis /// \brief Construct an empty declaration reference expression. 9619db7a7eb4e23758e041752c9c0c0ec1663d5a0afCraig Topper static DeclRefExpr *CreateEmpty(const ASTContext &Context, 9623aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth bool HasQualifier, 9633aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth bool HasFoundDecl, 964e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool HasTemplateKWAndArgsInfo, 965def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor unsigned NumTemplateArgs); 9667e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 967cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth ValueDecl *getDecl() { return D; } 968cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth const ValueDecl *getDecl() const { return D; } 969cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth void setDecl(ValueDecl *NewD) { D = NewD; } 970904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor 9712577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo getNameInfo() const { 9722577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(getDecl()->getDeclName(), Loc, DNLoc); 9732577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 9742577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 9759e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis SourceLocation getLocation() const { return Loc; } 9760b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 977aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceLocation getLocStart() const LLVM_READONLY; 978aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceLocation getLocEnd() const LLVM_READONLY; 9791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 980a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Determine whether this declaration reference was preceded by a 981a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// C++ nested-name-specifier, e.g., \c N::foo. 982cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth bool hasQualifier() const { return DeclRefExprBits.HasQualifier; } 9837e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 9847e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth /// \brief If the name was qualified, retrieves the nested-name-specifier 985a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// that precedes the name. Otherwise, returns NULL. 986a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NestedNameSpecifier *getQualifier() const { 987a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (!hasQualifier()) 988a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 9897e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 9906857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth return getInternalQualifierLoc().getNestedNameSpecifier(); 991a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 99240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor 9937e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth /// \brief If the name was qualified, retrieves the nested-name-specifier 99440d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor /// that precedes the name, with source-location information. 99540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc getQualifierLoc() const { 99640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (!hasQualifier()) 99740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return NestedNameSpecifierLoc(); 9987e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 9996857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth return getInternalQualifierLoc(); 100040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor } 100140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor 1002063820655db8121f0022a7c51458463c7250324cBenjamin Kramer /// \brief Get the NamedDecl through which this reference occurred. 10033aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// 10043aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// This Decl may be different from the ValueDecl actually referred to in the 10053aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// presence of using declarations, etc. It always returns non-NULL, and may 10063aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// simple return the ValueDecl when appropriate. 10073aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *getFoundDecl() { 10083aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return hasFoundDecl() ? getInternalFoundDecl() : D; 10093aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth } 10103aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 10113aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// \brief Get the NamedDecl through which this reference occurred. 10123aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// See non-const variant. 10133aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth const NamedDecl *getFoundDecl() const { 10143aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return hasFoundDecl() ? getInternalFoundDecl() : D; 10153aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth } 10163aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 1017e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool hasTemplateKWAndArgsInfo() const { 1018e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return DeclRefExprBits.HasTemplateKWAndArgsInfo; 1019096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 10207e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 1021e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Return the optional template keyword and arguments info. 1022e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() { 1023e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!hasTemplateKWAndArgsInfo()) 1024e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return 0; 1025e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 10263aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth if (hasFoundDecl()) 1027e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return reinterpret_cast<ASTTemplateKWAndArgsInfo *>( 10283aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth &getInternalFoundDecl() + 1); 10293aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 10303aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth if (hasQualifier()) 1031e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return reinterpret_cast<ASTTemplateKWAndArgsInfo *>( 10323aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth &getInternalQualifierLoc() + 1); 10337e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 1034e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return reinterpret_cast<ASTTemplateKWAndArgsInfo *>(this + 1); 1035e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 1036e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 1037e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Return the optional template keyword and arguments info. 1038e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const { 1039e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return const_cast<DeclRefExpr*>(this)->getTemplateKWAndArgsInfo(); 1040e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 1041e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 1042e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the template keyword preceding 1043e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// this name, if any. 1044e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getTemplateKeywordLoc() const { 1045e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!hasTemplateKWAndArgsInfo()) return SourceLocation(); 1046e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc(); 1047e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 1048e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 1049e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the left angle bracket starting the 1050e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// explicit template argument list following the name, if any. 1051e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getLAngleLoc() const { 1052e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!hasTemplateKWAndArgsInfo()) return SourceLocation(); 1053e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->LAngleLoc; 1054e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 1055e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 1056e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the right angle bracket ending the 1057e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// explicit template argument list following the name, if any. 1058e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getRAngleLoc() const { 1059e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!hasTemplateKWAndArgsInfo()) return SourceLocation(); 1060e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->RAngleLoc; 1061e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 1062e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 1063e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Determines whether the name in this declaration reference 1064e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// was preceded by the template keyword. 1065e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } 1066e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 1067e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Determines whether this declaration reference was followed by an 1068e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// explicit template argument list. 1069e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } 1070e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 1071e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the explicit template argument list that followed the 1072e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// member template name. 1073e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 1074e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara assert(hasExplicitTemplateArgs()); 1075e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return *getTemplateKWAndArgsInfo(); 1076096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 10777e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 1078096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that followed the 1079096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// member template name. 1080b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 1081096832c5ed5b9106fa177ebc148489760c3bc496John McCall return const_cast<DeclRefExpr *>(this)->getExplicitTemplateArgs(); 1082a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 1083d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 1084096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieves the optional explicit template arguments. 1085096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// This points to the same data as getExplicitTemplateArgs(), but 1086096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// returns null if there are no explicit template arguments. 1087e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const { 1088096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) return 0; 1089096832c5ed5b9106fa177ebc148489760c3bc496John McCall return &getExplicitTemplateArgs(); 1090096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 10917e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 1092d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// \brief Copies the template arguments (if present) into the given 1093d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// structure. 1094d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 1095096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (hasExplicitTemplateArgs()) 1096096832c5ed5b9106fa177ebc148489760c3bc496John McCall getExplicitTemplateArgs().copyInto(List); 1097d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall } 10987e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 1099a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the template arguments provided as part of this 1100a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template-id. 1101833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc *getTemplateArgs() const { 1102096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 1103a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 11047e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 1105096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().getTemplateArgs(); 1106a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 11077e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 1108a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the number of template arguments provided as part of this 1109a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template-id. 1110a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor unsigned getNumTemplateArgs() const { 1111096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 1112a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 11137e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 1114096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().NumTemplateArgs; 1115a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 11167e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 11177cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// \brief Returns true if this expression refers to a function that 11187cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// was resolved from an overloaded set having size greater than 1. 11197cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool hadMultipleCandidates() const { 11207cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara return DeclRefExprBits.HadMultipleCandidates; 11217cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara } 11227cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// \brief Sets the flag telling whether this expression refers to 11237cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// a function that was resolved from an overloaded set having size 11247cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// greater than 1. 11257cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara void setHadMultipleCandidates(bool V = true) { 11267cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara DeclRefExprBits.HadMultipleCandidates = V; 11277cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara } 11287cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara 1129f4b88a45902af1802a1cb42ba48b1c474474f228John McCall /// Does this DeclRefExpr refer to a local declaration from an 1130f4b88a45902af1802a1cb42ba48b1c474474f228John McCall /// enclosing function scope? 1131f4b88a45902af1802a1cb42ba48b1c474474f228John McCall bool refersToEnclosingLocal() const { 1132f4b88a45902af1802a1cb42ba48b1c474474f228John McCall return DeclRefExprBits.RefersToEnclosingLocal; 1133f4b88a45902af1802a1cb42ba48b1c474474f228John McCall } 1134f4b88a45902af1802a1cb42ba48b1c474474f228John McCall 11351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 113699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor return T->getStmtClass() == DeclRefExprClass; 11375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 113977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 114063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 11417e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 114260adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 11433397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl friend class ASTStmtWriter; 11445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1146d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner/// PredefinedExpr - [C99 6.4.2.2] - A predefined identifier such as __func__. 1147d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattnerclass PredefinedExpr : public Expr { 1148227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic: 1149227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson enum IdentType { 1150227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson Func, 1151227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson Function, 115228ad063b279378b19cb0704f977429df366a151eNico Weber LFunction, // Same as Function, but as wide string. 1153848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson PrettyFunction, 1154848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson /// PrettyFunctionNoVirtual - The same as PrettyFunction, except that the 1155848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson /// 'virtual' keyword is omitted for virtual member functions. 1156848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson PrettyFunctionNoVirtual 1157227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson }; 11581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1159227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonprivate: 1160227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson SourceLocation Loc; 1161227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson IdentType Type; 1162227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic: 11631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump PredefinedExpr(SourceLocation l, QualType type, IdentType IT) 1164f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(PredefinedExprClass, type, VK_LValue, OK_Ordinary, 1165ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie type->isDependentType(), type->isDependentType(), 1166561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor type->isInstantiationDependentType(), 1167bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 1168f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Loc(l), Type(IT) {} 11691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 117017fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor /// \brief Construct an empty predefined expression. 11711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit PredefinedExpr(EmptyShell Empty) 117217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor : Expr(PredefinedExprClass, Empty) { } 117317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 1174227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson IdentType getIdentType() const { return Type; } 117517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setIdentType(IdentType IT) { Type = IT; } 117617fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 117717fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor SourceLocation getLocation() const { return Loc; } 117817fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 117917fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 1180848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson static std::string ComputeName(IdentType IT, const Decl *CurrentDecl); 11813a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 118265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 118365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return Loc; } 1184227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 11851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 11861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == PredefinedExprClass; 1187227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson } 11881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 118977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 119063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 1191227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson}; 1192227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 11939996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// \brief Used by IntegerLiteral/FloatingLiteral to store the numeric without 11949996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// leaking memory. 11959996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// 11969996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// For large floats/integers, APFloat/APInt will allocate memory from the heap 11979996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// to represent these numbers. Unfortunately, when we use a BumpPtrAllocator 11989996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// to allocate IntegerLiteral/FloatingLiteral nodes the memory associated with 11999996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// the APFloat/APInt values will never get freed. APNumericStorage uses 12009996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// ASTContext's allocator for memory allocation. 12019996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisclass APNumericStorage { 12029996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis union { 12039996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis uint64_t VAL; ///< Used to store the <= 64 bits integer value. 12049996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis uint64_t *pVal; ///< Used to store the >64 bits integer value. 12059996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis }; 120691219326471798c7d3b02dc48691581580338969Benjamin Kramer unsigned BitWidth; 12079996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 12089996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis bool hasAllocation() const { return llvm::APInt::getNumWords(BitWidth) > 1; } 12099996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 1210f56faa01936b9cf909623d7f06e3c2569ca4a78eDmitri Gribenko APNumericStorage(const APNumericStorage &) LLVM_DELETED_FUNCTION; 1211f56faa01936b9cf909623d7f06e3c2569ca4a78eDmitri Gribenko void operator=(const APNumericStorage &) LLVM_DELETED_FUNCTION; 12129996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 12139996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisprotected: 121491219326471798c7d3b02dc48691581580338969Benjamin Kramer APNumericStorage() : VAL(0), BitWidth(0) { } 12159996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 12169996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APInt getIntValue() const { 12179996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis unsigned NumWords = llvm::APInt::getNumWords(BitWidth); 12189996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis if (NumWords > 1) 12199996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return llvm::APInt(BitWidth, NumWords, pVal); 12209996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis else 12219996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return llvm::APInt(BitWidth, VAL); 12229996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 122305ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper void setIntValue(const ASTContext &C, const llvm::APInt &Val); 12249996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis}; 12259996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 122691219326471798c7d3b02dc48691581580338969Benjamin Kramerclass APIntStorage : private APNumericStorage { 1227ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikiepublic: 1228ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie llvm::APInt getValue() const { return getIntValue(); } 122905ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper void setValue(const ASTContext &C, const llvm::APInt &Val) { 123005ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper setIntValue(C, Val); 123105ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper } 12329996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis}; 12339996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 1234bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramerclass APFloatStorage : private APNumericStorage { 1235ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikiepublic: 12369ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover llvm::APFloat getValue(const llvm::fltSemantics &Semantics) const { 12379ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover return llvm::APFloat(Semantics, getIntValue()); 123831dfd642d5ac33c4ee0cfe1d7a1d4da455dcc7a4Akira Hatanaka } 123905ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper void setValue(const ASTContext &C, const llvm::APFloat &Val) { 12409996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis setIntValue(C, Val.bitcastToAPInt()); 12419996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 12429996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis}; 12439996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 124491219326471798c7d3b02dc48691581580338969Benjamin Kramerclass IntegerLiteral : public Expr, public APIntStorage { 12455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 12469996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 12479996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis /// \brief Construct an empty integer literal. 12489996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis explicit IntegerLiteral(EmptyShell Empty) 12499996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis : Expr(IntegerLiteralClass, Empty) { } 12509996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 12515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 12521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy, 12535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // or UnsignedLongLongTy 125405ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper IntegerLiteral(const ASTContext &C, const llvm::APInt &V, QualType type, 1255478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer SourceLocation l); 1256a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson 12571dd986dff9ddfbec687975700770bb377988e9edRichard Trieu /// \brief Returns a new integer literal with value 'V' and type 'type'. 12581dd986dff9ddfbec687975700770bb377988e9edRichard Trieu /// \param type - either IntTy, LongTy, LongLongTy, UnsignedIntTy, 12591dd986dff9ddfbec687975700770bb377988e9edRichard Trieu /// UnsignedLongTy, or UnsignedLongLongTy which should match the size of V 12601dd986dff9ddfbec687975700770bb377988e9edRichard Trieu /// \param V - the value that the returned integer literal contains. 126105ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper static IntegerLiteral *Create(const ASTContext &C, const llvm::APInt &V, 12629996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis QualType type, SourceLocation l); 12631dd986dff9ddfbec687975700770bb377988e9edRichard Trieu /// \brief Returns a new empty integer literal. 126405ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper static IntegerLiteral *Create(const ASTContext &C, EmptyShell Empty); 12650b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 126665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 126765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return Loc; } 12685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1269313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Retrieve the location of the literal. 1270313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getLocation() const { return Loc; } 1271313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 12720b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation Location) { Loc = Location; } 12730b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 12741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 12751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == IntegerLiteralClass; 12765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 127877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 127963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 12805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 12815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CharacterLiteral : public Expr { 12835cee1195584fa8672253139c86e922daeda69b9eDouglas Gregorpublic: 12845cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor enum CharacterKind { 12855cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor Ascii, 12865cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor Wide, 12875cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor UTF16, 12885cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor UTF32 12895cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor }; 12905cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor 12915cee1195584fa8672253139c86e922daeda69b9eDouglas Gregorprivate: 12925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned Value; 12935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 12945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 12955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // type should be IntTy 12965cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor CharacterLiteral(unsigned value, CharacterKind kind, QualType type, 12975cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor SourceLocation l) 1298bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(CharacterLiteralClass, type, VK_RValue, OK_Ordinary, false, false, 1299561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false), 1300bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer Value(value), Loc(l) { 1301bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer CharacterLiteralBits.Kind = kind; 13025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13030b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 13040b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Construct an empty character literal. 13050b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { } 13060b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 1307018d8e0596dd57401eeddcf11ac84ff0a065fbbeChris Lattner SourceLocation getLocation() const { return Loc; } 1308bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer CharacterKind getKind() const { 1309bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer return static_cast<CharacterKind>(CharacterLiteralBits.Kind); 1310bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer } 13111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 131265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 131365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return Loc; } 13141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getValue() const { return Value; } 13165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13170b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation Location) { Loc = Location; } 1318bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer void setKind(CharacterKind kind) { CharacterLiteralBits.Kind = kind; } 13190b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setValue(unsigned Val) { Value = Val; } 13200b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 13211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 13221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CharacterLiteralClass; 13235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 132477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 132577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 132663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 13275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 13285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1329bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramerclass FloatingLiteral : public Expr, private APFloatStorage { 13305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 13319996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 133205ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper FloatingLiteral(const ASTContext &C, const llvm::APFloat &V, bool isexact, 1333478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer QualType Type, SourceLocation L); 13345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 133517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor /// \brief Construct an empty floating-point literal. 133605ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper explicit FloatingLiteral(const ASTContext &C, EmptyShell Empty); 133717fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 13389996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidispublic: 133905ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper static FloatingLiteral *Create(const ASTContext &C, const llvm::APFloat &V, 13409996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis bool isexact, QualType Type, SourceLocation L); 134105ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper static FloatingLiteral *Create(const ASTContext &C, EmptyShell Empty); 13429996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 1343bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer llvm::APFloat getValue() const { 13449ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover return APFloatStorage::getValue(getSemantics()); 1345bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer } 134605ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper void setValue(const ASTContext &C, const llvm::APFloat &Val) { 13479ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover assert(&getSemantics() == &Val.getSemantics() && "Inconsistent semantics"); 1348bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer APFloatStorage::setValue(C, Val); 13499996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 135017fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 13519ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover /// Get a raw enumeration value representing the floating-point semantics of 13529ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover /// this literal (32-bit IEEE, x87, ...), suitable for serialisation. 13539ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover APFloatSemantics getRawSemantics() const { 13549ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover return static_cast<APFloatSemantics>(FloatingLiteralBits.Semantics); 13559ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover } 13569ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover 13579ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover /// Set the raw enumeration value representing the floating-point semantics of 13589ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover /// this literal (32-bit IEEE, x87, ...), suitable for serialisation. 13599ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover void setRawSemantics(APFloatSemantics Sem) { 13609ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover FloatingLiteralBits.Semantics = Sem; 13619ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover } 13629ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover 13639ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover /// Return the APFloat semantics this literal uses. 13649ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover const llvm::fltSemantics &getSemantics() const; 13659ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover 13669ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover /// Set the APFloat semantics this literal uses. 13679ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover void setSemantics(const llvm::fltSemantics &Sem); 13689ec55f24b8f848bb37a9971100cf2fca379d5572Tim Northover 1369bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer bool isExact() const { return FloatingLiteralBits.IsExact; } 1370bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer void setExact(bool E) { FloatingLiteralBits.IsExact = E; } 1371c9bec4bfea9090a08dd83a7b213f0c8adf8d78ecChris Lattner 1372da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// getValueAsApproximateDouble - This returns the value as an inaccurate 1373da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// double. Note that this may cause loss of precision, but is useful for 1374da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// debugging dumps, etc. 1375da8249e57f3badecf925571881fe57243935c6c1Chris Lattner double getValueAsApproximateDouble() const; 13761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 137717fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor SourceLocation getLocation() const { return Loc; } 137817fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 137917fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 138065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return Loc; } 138165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return Loc; } 13825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 13841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == FloatingLiteralClass; 13855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 138777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 138863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 13895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 13905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13915d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// ImaginaryLiteral - We support imaginary integer and floating point literals, 13925d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// like "1.0i". We represent these as a wrapper around FloatingLiteral and 13935d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// IntegerLiteral classes. Instances of this class always have a Complex type 13945d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// whose element type matches the subexpression. 13955d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// 13965d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerclass ImaginaryLiteral : public Expr { 13975549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 13985d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerpublic: 13995d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner ImaginaryLiteral(Expr *val, QualType Ty) 1400bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(ImaginaryLiteralClass, Ty, VK_RValue, OK_Ordinary, false, false, 1401561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false), 1402f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Val(val) {} 14031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1404cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor /// \brief Build an empty imaginary literal. 14051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ImaginaryLiteral(EmptyShell Empty) 1406cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor : Expr(ImaginaryLiteralClass, Empty) { } 1407cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 14085549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 14095549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 1410cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 1411cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 141265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return Val->getLocStart(); } 141365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return Val->getLocEnd(); } 141465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 14151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 14161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ImaginaryLiteralClass; 14175d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner } 14181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14195d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner // Iterators 142063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Val, &Val+1); } 14215d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner}; 14225d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner 1423e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// StringLiteral - This represents a string literal expression, e.g. "foo" 1424a1ec2b0dbfd33cc3b4b7ac003a390995fc2305c6Jordan Rose/// or L"bar" (wide strings). The actual string is returned by getBytes() 1425e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// is NOT null-terminated, and the length of the string is determined by 1426a7ad98ff0919d6a24ea7c46634ea29bea551c1a0Chris Lattner/// calling getByteLength(). The C type for a string is always a 1427c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// ConstantArrayType. In C++, the char type is const qualified, in C it is 1428c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// not. 1429690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// 1430690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// Note that strings in C can be formed by concatenation of multiple string 14318bea7c0ee44c71c817de7dc2be932b73bec90c9fChris Lattner/// literal pptokens in translation phase #6. This keeps track of the locations 1432690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// of each of these pieces. 1433c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// 1434c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// Strings in C can also be truncated and extended by assigning into arrays, 1435c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// e.g. with constructs like: 1436c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// char X[2] = "foobar"; 1437c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// In this case, getByteLength() will return 6, but the string literal will 1438c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// have type "char[2]". 14395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass StringLiteral : public Expr { 14405cee1195584fa8672253139c86e922daeda69b9eDouglas Gregorpublic: 14415cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor enum StringKind { 14425cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor Ascii, 14435cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor Wide, 14445cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor UTF8, 14455cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor UTF16, 14465cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor UTF32 14475cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor }; 14485cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor 14495cee1195584fa8672253139c86e922daeda69b9eDouglas Gregorprivate: 14503e2193ce5feb2feb092e5ae615e85148e06e9fd2Anders Carlsson friend class ASTStmtReader; 14513e2193ce5feb2feb092e5ae615e85148e06e9fd2Anders Carlsson 145264f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman union { 145364f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman const char *asChar; 145464f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman const uint16_t *asUInt16; 145564f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman const uint32_t *asUInt32; 145664f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman } StrData; 145764f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman unsigned Length; 14580840f2378e9b5764755c5dffd27d7878c7606a0cBenjamin Kramer unsigned CharByteWidth : 4; 14595cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor unsigned Kind : 3; 14600840f2378e9b5764755c5dffd27d7878c7606a0cBenjamin Kramer unsigned IsPascal : 1; 14610840f2378e9b5764755c5dffd27d7878c7606a0cBenjamin Kramer unsigned NumConcatenated; 1462726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner SourceLocation TokLocs[1]; 14632085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner 1464f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall StringLiteral(QualType Ty) : 1465561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Expr(StringLiteralClass, Ty, VK_LValue, OK_Ordinary, false, false, false, 1466561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false) {} 14671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 146864f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman static int mapCharByteWidth(TargetInfo const &target,StringKind k); 146964f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman 14705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 14712085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// This is the "fully general" constructor that allows representation of 14722085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// strings formed from multiple concatenated tokens. 147305ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper static StringLiteral *Create(const ASTContext &C, StringRef Str, 147405ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper StringKind Kind, bool Pascal, QualType Ty, 1475a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson const SourceLocation *Loc, unsigned NumStrs); 14762085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner 14772085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// Simple constructor for string literals made from one token. 147805ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper static StringLiteral *Create(const ASTContext &C, StringRef Str, 147905ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper StringKind Kind, bool Pascal, QualType Ty, 14805cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor SourceLocation Loc) { 14815cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor return Create(C, Str, Kind, Pascal, Ty, &Loc, 1); 14822085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 1483a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson 1484673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor /// \brief Construct an empty string literal. 148505ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper static StringLiteral *CreateEmpty(const ASTContext &C, unsigned NumStrs); 1486673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 1487686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef getString() const { 148864f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman assert(CharByteWidth==1 148964f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman && "This function is used in places that assume strings use char"); 149064f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman return StringRef(StrData.asChar, getByteLength()); 149164f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman } 149264f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman 14930982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// Allow access to clients that need the byte representation, such as 14940982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// ASTWriterStmt::VisitStringLiteral(). 149564f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman StringRef getBytes() const { 1496e91e0ae772004912285ccc3848b27208da8c045bChris Lattner // FIXME: StringRef may not be the right type to use as a result for this. 1497e91e0ae772004912285ccc3848b27208da8c045bChris Lattner if (CharByteWidth == 1) 1498e91e0ae772004912285ccc3848b27208da8c045bChris Lattner return StringRef(StrData.asChar, getByteLength()); 1499e91e0ae772004912285ccc3848b27208da8c045bChris Lattner if (CharByteWidth == 4) 150064f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman return StringRef(reinterpret_cast<const char*>(StrData.asUInt32), 150164f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman getByteLength()); 1502e91e0ae772004912285ccc3848b27208da8c045bChris Lattner assert(CharByteWidth == 2 && "unsupported CharByteWidth"); 1503e91e0ae772004912285ccc3848b27208da8c045bChris Lattner return StringRef(reinterpret_cast<const char*>(StrData.asUInt16), 1504e91e0ae772004912285ccc3848b27208da8c045bChris Lattner getByteLength()); 1505b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar } 15062f4eaef37476ae6891ede8ba215d0f6fd093629bBenjamin Kramer 1507ae54121c15cdd38f415f6fdda48215ab5e4dcee1Alexander Kornienko void outputString(raw_ostream &OS) const; 15088ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu 150964f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman uint32_t getCodeUnit(size_t i) const { 1510e91e0ae772004912285ccc3848b27208da8c045bChris Lattner assert(i < Length && "out of bounds access"); 1511e91e0ae772004912285ccc3848b27208da8c045bChris Lattner if (CharByteWidth == 1) 151264f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman return static_cast<unsigned char>(StrData.asChar[i]); 1513e91e0ae772004912285ccc3848b27208da8c045bChris Lattner if (CharByteWidth == 4) 1514e91e0ae772004912285ccc3848b27208da8c045bChris Lattner return StrData.asUInt32[i]; 1515e91e0ae772004912285ccc3848b27208da8c045bChris Lattner assert(CharByteWidth == 2 && "unsupported CharByteWidth"); 1516e91e0ae772004912285ccc3848b27208da8c045bChris Lattner return StrData.asUInt16[i]; 151764f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman } 151864f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman 151964f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman unsigned getByteLength() const { return CharByteWidth*Length; } 152064f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman unsigned getLength() const { return Length; } 152164f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman unsigned getCharByteWidth() const { return CharByteWidth; } 1522673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 1523673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor /// \brief Sets the string data to the given string data. 152405ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper void setString(const ASTContext &C, StringRef Str, 152564f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman StringKind Kind, bool IsPascal); 1526673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 15275cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor StringKind getKind() const { return static_cast<StringKind>(Kind); } 1528ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1529ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 15305cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor bool isAscii() const { return Kind == Ascii; } 15315cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor bool isWide() const { return Kind == Wide; } 15325cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor bool isUTF8() const { return Kind == UTF8; } 15335cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor bool isUTF16() const { return Kind == UTF16; } 15345cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor bool isUTF32() const { return Kind == UTF32; } 15353e2193ce5feb2feb092e5ae615e85148e06e9fd2Anders Carlsson bool isPascal() const { return IsPascal; } 15365cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor 15378d4141f83d9de379547cf05bd75d4c6cf894b189Steve Naroff bool containsNonAsciiOrNull() const { 1538686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef Str = getString(); 1539b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar for (unsigned i = 0, e = Str.size(); i != e; ++i) 1540223f0ff6a9a5d0eaf63b98b3aa92888b4c088868Jordan Rose if (!isASCII(Str[i]) || !Str[i]) 154133fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff return true; 154233fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff return false; 154333fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff } 1544ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1545726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner /// getNumConcatenated - Get the number of string literal tokens that were 1546726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner /// concatenated in translation phase #6 to form this string literal. 1547726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner unsigned getNumConcatenated() const { return NumConcatenated; } 15481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1549726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner SourceLocation getStrTokenLoc(unsigned TokNum) const { 1550726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner assert(TokNum < NumConcatenated && "Invalid tok number"); 1551726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner return TokLocs[TokNum]; 1552726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner } 15531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setStrTokenLoc(unsigned TokNum, SourceLocation L) { 1554673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor assert(TokNum < NumConcatenated && "Invalid tok number"); 1555673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor TokLocs[TokNum] = L; 1556673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor } 1557ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 155808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// getLocationOfByte - Return a source location that points to the specified 155908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// byte of this string literal. 156008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// 156108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// Strings are amazingly complex. They can be formed from multiple tokens 156208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// and can have escape sequences in them in addition to the usual trigraph 156308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// and escaped newline business. This routine handles this complexity. 156408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// 156508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner SourceLocation getLocationOfByte(unsigned ByteNo, const SourceManager &SM, 156608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner const LangOptions &Features, 156708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner const TargetInfo &Target) const; 1568673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 1569b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner typedef const SourceLocation *tokloc_iterator; 1570b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner tokloc_iterator tokloc_begin() const { return TokLocs; } 1571b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner tokloc_iterator tokloc_end() const { return TokLocs+NumConcatenated; } 15725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 157365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return TokLocs[0]; } 157465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { 157565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return TokLocs[NumConcatenated - 1]; 15765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 157765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 15781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 15791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == StringLiteralClass; 15805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 15811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 158277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 158363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 15845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 15855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ParenExpr - This represents a parethesized expression, e.g. "(1)". This 15875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// AST node is only formed if full location information is requested. 15885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ParenExpr : public Expr { 15895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation L, R; 15905549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 15915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 15925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ParenExpr(SourceLocation l, SourceLocation r, Expr *val) 1593898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Expr(ParenExprClass, val->getType(), 1594f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall val->getValueKind(), val->getObjectKind(), 1595bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor val->isTypeDependent(), val->isValueDependent(), 1596561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor val->isInstantiationDependent(), 1597bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor val->containsUnexpandedParameterPack()), 1598898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor L(l), R(r), Val(val) {} 15991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1600c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor /// \brief Construct an empty parenthesized expression. 16011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ParenExpr(EmptyShell Empty) 1602c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor : Expr(ParenExprClass, Empty) { } 1603c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor 16045549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 16055549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 1606c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 1607c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor 160865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return L; } 160965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return R; } 16105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1611313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Get the location of the left parentheses '('. 1612313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getLParen() const { return L; } 1613c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setLParen(SourceLocation Loc) { L = Loc; } 1614313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 1615313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Get the location of the right parentheses ')'. 1616313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getRParen() const { return R; } 1617c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setRParen(SourceLocation Loc) { R = Loc; } 1618313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 16191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 16201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ParenExprClass; 16215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 16221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 162377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 162463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Val, &Val+1); } 16255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 16265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 16275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 16280518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// UnaryOperator - This represents the unary-expression's (except sizeof and 16290518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// alignof), the postinc/postdec operators from postfix-expression, and various 16305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// extensions. 1631dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 1632dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Notes on various nodes: 1633dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 1634dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Real/Imag - These return the real/imag part of a complex operand. If 1635dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// applied to a non-complex value, the former returns its operand and the 1636dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// later returns zero in the type of the operand. 1637dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 16385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass UnaryOperator : public Expr { 16395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 16405baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall typedef UnaryOperatorKind Opcode; 16415baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 16425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 16430799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall unsigned Opc : 5; 16445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 16450799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Stmt *Val; 16461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 16475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1648f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall UnaryOperator(Expr *input, Opcode opc, QualType type, 1649f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, SourceLocation l) 1650f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(UnaryOperatorClass, type, VK, OK, 1651de7e66256b1bdfcf6526994825a8c8fced52a31cEli Friedman input->isTypeDependent() || type->isDependentType(), 1652bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor input->isValueDependent(), 1653ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie (input->isInstantiationDependent() || 1654561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor type->isInstantiationDependentType()), 1655bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor input->containsUnexpandedParameterPack()), 16560799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Opc(opc), Loc(l), Val(input) {} 16575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 16580b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor /// \brief Build an empty unary operator. 16591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit UnaryOperator(EmptyShell Empty) 16602de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall : Expr(UnaryOperatorClass, Empty), Opc(UO_AddrOf) { } 16610b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 16620799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Opcode getOpcode() const { return static_cast<Opcode>(Opc); } 16630b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOpcode(Opcode O) { Opc = O; } 16640b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 16655549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() const { return cast<Expr>(Val); } 16660b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setSubExpr(Expr *E) { Val = E; } 16670b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 16685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOperatorLoc - Return the location of the operator. 16695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getOperatorLoc() const { return Loc; } 16700b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOperatorLoc(SourceLocation L) { Loc = L; } 16710b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 16725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isPostfix - Return true if this is a postfix operation, like x++. 16732085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static bool isPostfix(Opcode Op) { 16742de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Op == UO_PostInc || Op == UO_PostDec; 16752085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 16765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1677cc7bd10c0de9449b795bda3c5dcc6d83cc48436bZhanyong Wan /// isPrefix - Return true if this is a prefix operation, like --x. 16782085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static bool isPrefix(Opcode Op) { 16792de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Op == UO_PreInc || Op == UO_PreDec; 16802085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 16815a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek 16820799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isPrefix() const { return isPrefix(getOpcode()); } 16830799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isPostfix() const { return isPostfix(getOpcode()); } 16843c3b7f90a863af43fa63043d396553ecf205351cJohn McCall 16853c3b7f90a863af43fa63043d396553ecf205351cJohn McCall static bool isIncrementOp(Opcode Op) { 16863c3b7f90a863af43fa63043d396553ecf205351cJohn McCall return Op == UO_PreInc || Op == UO_PostInc; 16873c3b7f90a863af43fa63043d396553ecf205351cJohn McCall } 16882de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall bool isIncrementOp() const { 16893c3b7f90a863af43fa63043d396553ecf205351cJohn McCall return isIncrementOp(getOpcode()); 16903c3b7f90a863af43fa63043d396553ecf205351cJohn McCall } 16913c3b7f90a863af43fa63043d396553ecf205351cJohn McCall 16923c3b7f90a863af43fa63043d396553ecf205351cJohn McCall static bool isDecrementOp(Opcode Op) { 16933c3b7f90a863af43fa63043d396553ecf205351cJohn McCall return Op == UO_PreDec || Op == UO_PostDec; 16942de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 16953c3b7f90a863af43fa63043d396553ecf205351cJohn McCall bool isDecrementOp() const { 16963c3b7f90a863af43fa63043d396553ecf205351cJohn McCall return isDecrementOp(getOpcode()); 16973c3b7f90a863af43fa63043d396553ecf205351cJohn McCall } 16983c3b7f90a863af43fa63043d396553ecf205351cJohn McCall 16993c3b7f90a863af43fa63043d396553ecf205351cJohn McCall static bool isIncrementDecrementOp(Opcode Op) { return Op <= UO_PreDec; } 17002de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall bool isIncrementDecrementOp() const { 17013c3b7f90a863af43fa63043d396553ecf205351cJohn McCall return isIncrementDecrementOp(getOpcode()); 17022de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 17033c3b7f90a863af43fa63043d396553ecf205351cJohn McCall 17042de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isArithmeticOp(Opcode Op) { 17052de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Op >= UO_Plus && Op <= UO_LNot; 17062de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 17070799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isArithmeticOp() const { return isArithmeticOp(getOpcode()); } 17081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 17105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// corresponds to, e.g. "sizeof" or "[pre]++" 17110bea86307eb8c16339315a1e261fc490eb505c5bDavid Blaikie static StringRef getOpcodeStr(Opcode Op); 17125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1713bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// \brief Retrieve the unary opcode that corresponds to the given 1714bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// overloaded operator. 1715bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix); 1716bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 1717bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// \brief Retrieve the overloaded operator kind that corresponds to 1718bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// the given unary opcode. 1719bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); 1720bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 172165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { 172265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return isPostfix() ? Val->getLocStart() : Loc; 172365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen } 172465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { 172565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return isPostfix() ? Loc : Val->getLocEnd(); 17265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 17274f311183be3d923da9fbe8702c453688b4c426a9Daniel Dunbar SourceLocation getExprLoc() const LLVM_READONLY { return Loc; } 17281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 17301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == UnaryOperatorClass; 17315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 17321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 173377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 173463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Val, &Val+1); } 17355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 17365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 17378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// OffsetOfExpr - [C99 7.17] - This represents an expression of the form 17388ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// offsetof(record-type, member-designator). For example, given: 17398ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// @code 17408ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct S { 17418ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// float f; 1742ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// double d; 17438ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// }; 17448ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct T { 17458ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// int i; 17468ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct S s[10]; 17478ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// }; 17488ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// @endcode 1749ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// we can represent and evaluate the expression @c offsetof(struct T, s[2].d). 17508ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 17518ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorclass OffsetOfExpr : public Expr { 17528ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorpublic: 17538ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // __builtin_offsetof(type, identifier(.identifier|[expr])*) 17548ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor class OffsetOfNode { 17558ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor public: 17568ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief The kind of offsetof node we have. 17578ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor enum Kind { 1758cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief An index into an array. 17598ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Array = 0x00, 1760cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief A field. 17618ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Field = 0x01, 1762cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief A field in a dependent type, known only by its name. 1763cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor Identifier = 0x02, 1764cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief An implicit indirection through a C++ base class, when the 1765cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// field found is in a base class. 1766cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor Base = 0x03 17678ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor }; 17688ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 17698ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor private: 17708ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor enum { MaskBits = 2, Mask = 0x03 }; 1771ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 17728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief The source range that covers this part of the designator. 17738ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceRange Range; 1774ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 17758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief The data describing the designator, which comes in three 17768ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// different forms, depending on the lower two bits. 1777ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// - An unsigned index into the array of Expr*'s stored after this node 17788ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// in memory, for [constant-expression] designators. 17798ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// - A FieldDecl*, for references to a known field. 17808ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// - An IdentifierInfo*, for references to a field with a given name 17818ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// when the class type is dependent. 1782ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// - A CXXBaseSpecifier*, for references that look at a field in a 1783cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// base class. 17848ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor uintptr_t Data; 1785ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 17868ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor public: 17878ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Create an offsetof node that refers to an array element. 1788ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie OffsetOfNode(SourceLocation LBracketLoc, unsigned Index, 17898ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RBracketLoc) 17908ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor : Range(LBracketLoc, RBracketLoc), Data((Index << 2) | Array) { } 1791ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 17928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Create an offsetof node that refers to a field. 1793ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie OffsetOfNode(SourceLocation DotLoc, FieldDecl *Field, 17948ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation NameLoc) 1795ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc), 17968ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Data(reinterpret_cast<uintptr_t>(Field) | OffsetOfNode::Field) { } 1797ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 17988ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Create an offsetof node that refers to an identifier. 17998ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor OffsetOfNode(SourceLocation DotLoc, IdentifierInfo *Name, 18008ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation NameLoc) 1801ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc), 18028ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Data(reinterpret_cast<uintptr_t>(Name) | Identifier) { } 1803cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor 1804cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief Create an offsetof node that refers into a C++ base class. 1805cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor explicit OffsetOfNode(const CXXBaseSpecifier *Base) 1806cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor : Range(), Data(reinterpret_cast<uintptr_t>(Base) | OffsetOfNode::Base) {} 1807ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 18088ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Determine what kind of offsetof node this is. 1809ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie Kind getKind() const { 18108ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return static_cast<Kind>(Data & Mask); 18118ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1812ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 18138ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief For an array element node, returns the index into the array 18148ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// of expressions. 18158ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned getArrayExprIndex() const { 18168ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(getKind() == Array); 18178ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return Data >> 2; 18188ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 18198ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 18208ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief For a field offsetof node, returns the field. 18218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor FieldDecl *getField() const { 18228ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(getKind() == Field); 1823cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor return reinterpret_cast<FieldDecl *>(Data & ~(uintptr_t)Mask); 18248ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1825ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 18268ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief For a field or identifier offsetof node, returns the name of 18278ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// the field. 18288ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor IdentifierInfo *getFieldName() const; 1829ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1830cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief For a base class node, returns the base specifier. 1831cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor CXXBaseSpecifier *getBase() const { 1832cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor assert(getKind() == Base); 1833ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return reinterpret_cast<CXXBaseSpecifier *>(Data & ~(uintptr_t)Mask); 1834cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor } 1835ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 18368ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Retrieve the source range that covers this offsetof node. 18378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// 18388ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// For an array element node, the source range contains the locations of 18398ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// the square brackets. For a field or identifier node, the source range 1840ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// contains the location of the period (if there is one) and the 18418ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// identifier. 1842aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { return Range; } 184365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); } 184465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); } 18458ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor }; 18468ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 18478ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorprivate: 1848ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 18498ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation OperatorLoc, RParenLoc; 18508ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Base type; 18518ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TypeSourceInfo *TSInfo; 18528ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Number of sub-components (i.e. instances of OffsetOfNode). 18538ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumComps; 18548ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Number of sub-expressions (i.e. array subscript expressions). 18558ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumExprs; 1856ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 185705ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper OffsetOfExpr(const ASTContext &C, QualType type, 18588ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation OperatorLoc, TypeSourceInfo *tsi, 18593b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<OffsetOfNode> comps, ArrayRef<Expr*> exprs, 18608ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc); 18618ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 18628ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor explicit OffsetOfExpr(unsigned numComps, unsigned numExprs) 18638ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor : Expr(OffsetOfExprClass, EmptyShell()), 1864ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie TSInfo(0), NumComps(numComps), NumExprs(numExprs) {} 18658ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 18668ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorpublic: 1867ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 186805ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper static OffsetOfExpr *Create(const ASTContext &C, QualType type, 1869ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie SourceLocation OperatorLoc, TypeSourceInfo *tsi, 18703b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<OffsetOfNode> comps, 18713b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> exprs, SourceLocation RParenLoc); 18728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 187305ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper static OffsetOfExpr *CreateEmpty(const ASTContext &C, 18748ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumComps, unsigned NumExprs); 18758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 18768ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// getOperatorLoc - Return the location of the operator. 18778ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation getOperatorLoc() const { return OperatorLoc; } 18788ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setOperatorLoc(SourceLocation L) { OperatorLoc = L; } 18798ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 18808ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Return the location of the right parentheses. 18818ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 18828ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setRParenLoc(SourceLocation R) { RParenLoc = R; } 1883ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 18848ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TypeSourceInfo *getTypeSourceInfo() const { 18858ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return TSInfo; 18868ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 18878ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setTypeSourceInfo(TypeSourceInfo *tsi) { 18888ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TSInfo = tsi; 18898ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1890ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 18918cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne const OffsetOfNode &getComponent(unsigned Idx) const { 18928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumComps && "Subscript out of range"); 18938cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne return reinterpret_cast<const OffsetOfNode *> (this + 1)[Idx]; 18948ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 18958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 18968ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setComponent(unsigned Idx, OffsetOfNode ON) { 18978ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumComps && "Subscript out of range"); 18988ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<OffsetOfNode *> (this + 1)[Idx] = ON; 18998ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1900ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 19018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned getNumComponents() const { 19028ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return NumComps; 19038ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 19048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 19058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr* getIndexExpr(unsigned Idx) { 19068ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumExprs && "Subscript out of range"); 19078ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return reinterpret_cast<Expr **>( 19088ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx]; 19098ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 19108cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne const Expr *getIndexExpr(unsigned Idx) const { 19118cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne return const_cast<OffsetOfExpr*>(this)->getIndexExpr(Idx); 19128cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne } 19138ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 19148ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setIndexExpr(unsigned Idx, Expr* E) { 19158ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumComps && "Subscript out of range"); 19168ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<Expr **>( 19178ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx] = E; 19188ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1919ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 19208ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned getNumExpressions() const { 19218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return NumExprs; 19228ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 19238ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 192465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return OperatorLoc; } 192565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 19268ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 19278ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor static bool classof(const Stmt *T) { 19288ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return T->getStmtClass() == OffsetOfExprClass; 19298ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 19308ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 19318ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Iterators 193263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 193363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt **begin = 193463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall reinterpret_cast<Stmt**>(reinterpret_cast<OffsetOfNode*>(this + 1) 193563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall + NumComps); 193663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(begin, begin + NumExprs); 193763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 19388ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor}; 19398ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 1940f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne/// UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) 1941f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne/// expression operand. Used for sizeof/alignof (C99 6.5.3.4) and 1942f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne/// vec_step (OpenCL 1.1 6.11.12). 1943f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourneclass UnaryExprOrTypeTraitExpr : public Expr { 1944d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl union { 1945a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *Ty; 1946d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl Stmt *Ex; 1947d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl } Argument; 19485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation OpLoc, RParenLoc; 194942602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor 19505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1951f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, TypeSourceInfo *TInfo, 1952f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne QualType resultType, SourceLocation op, 1953f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne SourceLocation rp) : 1954f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_RValue, OK_Ordinary, 1955ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor false, // Never type-dependent (C++ [temp.dep.expr]p3). 19562850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl // Value-dependent if the argument is type-dependent. 1957bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor TInfo->getType()->isDependentType(), 1958561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor TInfo->getType()->isInstantiationDependentType(), 1959bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor TInfo->getType()->containsUnexpandedParameterPack()), 1960bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer OpLoc(op), RParenLoc(rp) { 1961bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer UnaryExprOrTypeTraitExprBits.Kind = ExprKind; 1962bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer UnaryExprOrTypeTraitExprBits.IsType = true; 1963a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall Argument.Ty = TInfo; 1964ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor } 1965ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor 1966f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, Expr *E, 1967f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne QualType resultType, SourceLocation op, 1968f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne SourceLocation rp) : 1969f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_RValue, OK_Ordinary, 1970ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor false, // Never type-dependent (C++ [temp.dep.expr]p3). 1971ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor // Value-dependent if the argument is type-dependent. 1972bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor E->isTypeDependent(), 1973561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor E->isInstantiationDependent(), 1974bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor E->containsUnexpandedParameterPack()), 1975bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer OpLoc(op), RParenLoc(rp) { 1976bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer UnaryExprOrTypeTraitExprBits.Kind = ExprKind; 1977bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer UnaryExprOrTypeTraitExprBits.IsType = false; 1978ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor Argument.Ex = E; 1979d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl } 19800518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl 19810b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor /// \brief Construct an empty sizeof/alignof expression. 1982f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne explicit UnaryExprOrTypeTraitExpr(EmptyShell Empty) 1983f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne : Expr(UnaryExprOrTypeTraitExprClass, Empty) { } 19840b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 1985f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne UnaryExprOrTypeTrait getKind() const { 1986bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer return static_cast<UnaryExprOrTypeTrait>(UnaryExprOrTypeTraitExprBits.Kind); 1987f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne } 1988bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer void setKind(UnaryExprOrTypeTrait K) { UnaryExprOrTypeTraitExprBits.Kind = K;} 19890b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 1990bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer bool isArgumentType() const { return UnaryExprOrTypeTraitExprBits.IsType; } 19910518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType getArgumentType() const { 19925ab75172051a6d2ea71a80a79e81c65519fd3462John McCall return getArgumentTypeInfo()->getType(); 19935ab75172051a6d2ea71a80a79e81c65519fd3462John McCall } 1994a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *getArgumentTypeInfo() const { 19950518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl assert(isArgumentType() && "calling getArgumentType() when arg is expr"); 19965ab75172051a6d2ea71a80a79e81c65519fd3462John McCall return Argument.Ty; 19970518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 1998caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner Expr *getArgumentExpr() { 19990518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl assert(!isArgumentType() && "calling getArgumentExpr() when arg is type"); 2000d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl return static_cast<Expr*>(Argument.Ex); 20010518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 2002caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner const Expr *getArgumentExpr() const { 2003f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne return const_cast<UnaryExprOrTypeTraitExpr*>(this)->getArgumentExpr(); 2004caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner } 20050b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 2006bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer void setArgument(Expr *E) { 2007bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer Argument.Ex = E; 2008bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer UnaryExprOrTypeTraitExprBits.IsType = false; 2009bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer } 2010a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall void setArgument(TypeSourceInfo *TInfo) { 2011a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall Argument.Ty = TInfo; 2012bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer UnaryExprOrTypeTraitExprBits.IsType = true; 20130b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor } 20140b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 20150518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl /// Gets the argument type, or the type of the argument expression, whichever 20160518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl /// is appropriate. 20170518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType getTypeOfArgument() const { 20180518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl return isArgumentType() ? getArgumentType() : getArgumentExpr()->getType(); 20190518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 20200518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl 202176e773a443be9f006610f46529e07d4c8d857680Chris Lattner SourceLocation getOperatorLoc() const { return OpLoc; } 20220b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOperatorLoc(SourceLocation L) { OpLoc = L; } 20230b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 20240b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 20250b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 2026866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek 202765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return OpLoc; } 202865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 20295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 20301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 2031f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne return T->getStmtClass() == UnaryExprOrTypeTraitExprClass; 20325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 20331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 203477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 203563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children(); 20365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 20375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 20385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 20395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Postfix Operators. 20405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 20415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 20425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting. 20435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ArraySubscriptExpr : public Expr { 204477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek enum { LHS, RHS, END_EXPR=2 }; 20451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Stmt* SubExprs[END_EXPR]; 20465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation RBracketLoc; 20475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 20482324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t, 2049f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 205073d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SourceLocation rbracketloc) 2051f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ArraySubscriptExprClass, t, VK, OK, 20522850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl lhs->isTypeDependent() || rhs->isTypeDependent(), 2053bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor lhs->isValueDependent() || rhs->isValueDependent(), 2054561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (lhs->isInstantiationDependent() || 2055561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhs->isInstantiationDependent()), 2056bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (lhs->containsUnexpandedParameterPack() || 2057bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhs->containsUnexpandedParameterPack())), 20582850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl RBracketLoc(rbracketloc) { 205973d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SubExprs[LHS] = lhs; 206073d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SubExprs[RHS] = rhs; 206173d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner } 20621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2063cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor /// \brief Create an empty array subscript expression. 2064cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor explicit ArraySubscriptExpr(EmptyShell Shell) 2065cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor : Expr(ArraySubscriptExprClass, Shell) { } 2066cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 20672324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// An array access can be written A[4] or 4[A] (both are equivalent). 20682324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// - getBase() and getIdx() always present the normalized view: A[4]. 20692324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// In this case getBase() returns "A" and getIdx() returns "4". 20702324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// - getLHS() and getRHS() present the syntactic view. e.g. for 20712324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// 4[A] getLHS() returns "4". 207233fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// Note: Because vector element access is also written A[4] we must 207333fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// predicate the format conversion in getBase and getIdx only on the 207433fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// the type of the RHS, as it is possible for the LHS to be a vector of 207533fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// integer type 20765549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); } 20775549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 2078cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 2079cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 20805549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); } 20815549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 2082cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 20831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getBase() { 20855549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS()); 208677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek } 20871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr *getBase() const { 20895549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS()); 20902324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek } 20911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getIdx() { 20935549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS()); 20942324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek } 20951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 209677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek const Expr *getIdx() const { 20975549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS()); 20981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 20991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 210065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { 210165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return getLHS()->getLocStart(); 21025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 210365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return RBracketLoc; } 21041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2105026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getRBracketLoc() const { return RBracketLoc; } 2106cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setRBracketLoc(SourceLocation L) { RBracketLoc = L; } 2107cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 210865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getExprLoc() const LLVM_READONLY { 210965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return getBase()->getExprLoc(); 211065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen } 21115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 21121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 21131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ArraySubscriptExprClass; 21145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 21151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 211677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 211763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 211863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 211963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 21205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 21215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 21225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2123b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]). 21241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CallExpr itself represents a normal function call, e.g., "f(x, 2)", 2125b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// while its subclasses may represent alternative syntax that (semantically) 21261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// results in a function call. For example, CXXOperatorCallExpr is 2127b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// a subclass for overloaded operator calls that use operator syntax, e.g., 2128b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// "str1 + str2" to resolve to a function call. 21295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CallExpr : public Expr { 2130cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne enum { FN=0, PREARGS_START=1 }; 21315549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt **SubExprs; 21325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned NumArgs; 21335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation RParenLoc; 21341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2135b4609806e9232593ece09ce08b630836e825865cDouglas Gregorprotected: 2136cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne // These versions of the constructor are for derived classes. 213705ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper CallExpr(const ASTContext& C, StmtClass SC, Expr *fn, unsigned NumPreArgs, 21383b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> args, QualType t, ExprValueKind VK, 2139cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SourceLocation rparenloc); 214005ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper CallExpr(const ASTContext &C, StmtClass SC, unsigned NumPreArgs, 214105ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper EmptyShell Empty); 2142cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne 2143cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne Stmt *getPreArg(unsigned i) { 2144cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne assert(i < getNumPreArgs() && "Prearg access out of range!"); 2145cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs[PREARGS_START+i]; 2146cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 2147cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne const Stmt *getPreArg(unsigned i) const { 2148cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne assert(i < getNumPreArgs() && "Prearg access out of range!"); 2149cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs[PREARGS_START+i]; 2150cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 2151cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne void setPreArg(unsigned i, Stmt *PreArg) { 2152cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne assert(i < getNumPreArgs() && "Prearg access out of range!"); 2153cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs[PREARGS_START+i] = PreArg; 2154cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 2155cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne 2156cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne unsigned getNumPreArgs() const { return CallExprBits.NumPreArgs; } 215742602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor 21585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 215905ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper CallExpr(const ASTContext& C, Expr *fn, ArrayRef<Expr*> args, QualType t, 2160f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, SourceLocation rparenloc); 21611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21621f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor /// \brief Build an empty call expression. 216305ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper CallExpr(const ASTContext &C, StmtClass SC, EmptyShell Empty); 21641f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 21655549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); } 21665549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCallee() { return cast<Expr>(SubExprs[FN]); } 216718b2515e1bf8c86a4900792692e42fe1296be28dChris Lattner void setCallee(Expr *F) { SubExprs[FN] = F; } 2168a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 2169d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes Decl *getCalleeDecl(); 2170d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes const Decl *getCalleeDecl() const { 2171d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes return const_cast<CallExpr*>(this)->getCalleeDecl(); 2172d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes } 2173d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes 2174a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu /// \brief If the callee is a FunctionDecl, return it. Otherwise return 0. 2175a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu FunctionDecl *getDirectCallee(); 2176bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner const FunctionDecl *getDirectCallee() const { 2177bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner return const_cast<CallExpr*>(this)->getDirectCallee(); 2178bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner } 2179a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 21805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getNumArgs - Return the number of actual arguments to this call. 21815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 21825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumArgs() const { return NumArgs; } 21831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2184aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \brief Retrieve the call arguments. 2185cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne Expr **getArgs() { 2186cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return reinterpret_cast<Expr **>(SubExprs+getNumPreArgs()+PREARGS_START); 2187cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 2188d0dcceae2a8ca0e37b5dd471a704de8583d49c95Richard Smith const Expr *const *getArgs() const { 2189d0dcceae2a8ca0e37b5dd471a704de8583d49c95Richard Smith return const_cast<CallExpr*>(this)->getArgs(); 2190d0dcceae2a8ca0e37b5dd471a704de8583d49c95Richard Smith } 2191ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 21925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getArg - Return the specified argument. 21935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Expr *getArg(unsigned Arg) { 21945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(Arg < NumArgs && "Arg access out of range!"); 2195cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return cast<Expr>(SubExprs[Arg+getNumPreArgs()+PREARGS_START]); 21965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 21975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const Expr *getArg(unsigned Arg) const { 21985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(Arg < NumArgs && "Arg access out of range!"); 2199cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return cast<Expr>(SubExprs[Arg+getNumPreArgs()+PREARGS_START]); 22005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 22011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2202934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff /// setArg - Set the specified argument. 2203934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff void setArg(unsigned Arg, Expr *ArgExpr) { 2204934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff assert(Arg < NumArgs && "Arg access out of range!"); 2205cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs[Arg+getNumPreArgs()+PREARGS_START] = ArgExpr; 2206934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff } 22071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2208d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// setNumArgs - This changes the number of arguments present in this call. 2209d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// Any orphaned expressions are deleted by this, and any new operands are set 2210d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// to null. 221105ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper void setNumArgs(const ASTContext& C, unsigned NumArgs); 22121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22135549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek typedef ExprIterator arg_iterator; 22145549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek typedef ConstExprIterator const_arg_iterator; 22151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2216cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne arg_iterator arg_begin() { return SubExprs+PREARGS_START+getNumPreArgs(); } 2217cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne arg_iterator arg_end() { 2218cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs+PREARGS_START+getNumPreArgs()+getNumArgs(); 2219cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 2220cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne const_arg_iterator arg_begin() const { 2221cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs+PREARGS_START+getNumPreArgs(); 2222cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 2223cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne const_arg_iterator arg_end() const { 2224cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs+PREARGS_START+getNumPreArgs()+getNumArgs(); 2225cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 22261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22275846720f08a6b225484bfe663599c2b057a99bc8Ted Kremenek /// This method provides fast access to all the subexpressions of 22285846720f08a6b225484bfe663599c2b057a99bc8Ted Kremenek /// a CallExpr without going through the slower virtual child_iterator 22295846720f08a6b225484bfe663599c2b057a99bc8Ted Kremenek /// interface. This provides efficient reverse iteration of the 22305846720f08a6b225484bfe663599c2b057a99bc8Ted Kremenek /// subexpressions. This is currently used for CFG construction. 22315846720f08a6b225484bfe663599c2b057a99bc8Ted Kremenek ArrayRef<Stmt*> getRawSubExprs() { 22325846720f08a6b225484bfe663599c2b057a99bc8Ted Kremenek return ArrayRef<Stmt*>(SubExprs, 22335846720f08a6b225484bfe663599c2b057a99bc8Ted Kremenek getNumPreArgs() + PREARGS_START + getNumArgs()); 22345846720f08a6b225484bfe663599c2b057a99bc8Ted Kremenek } 22355846720f08a6b225484bfe663599c2b057a99bc8Ted Kremenek 22365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getNumCommas - Return the number of commas that must have been present in 22375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// this function call. 22385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; } 22395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2240cb888967400a03504c88acedd5248d6778a82f46Chris Lattner /// isBuiltinCall - If this is a call to a builtin, return the builtin ID. If 2241cb888967400a03504c88acedd5248d6778a82f46Chris Lattner /// not, return 0. 2242180f47959a066795cc0f409433023af448bb0328Richard Smith unsigned isBuiltinCall() const; 22431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2244ba57183965f117279342903edec19766e478c9a8Richard Smith /// \brief Returns \c true if this is a call to a builtin which does not 2245ba57183965f117279342903edec19766e478c9a8Richard Smith /// evaluate side-effects within its arguments. 2246ba57183965f117279342903edec19766e478c9a8Richard Smith bool isUnevaluatedBuiltinCall(ASTContext &Ctx) const; 2247ba57183965f117279342903edec19766e478c9a8Richard Smith 22481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// getCallReturnType - Get the return type of the call expr. This is not 22491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// always the type of the expr itself, if the return type is a reference 22506dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson /// type. 22516dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson QualType getCallReturnType() const; 22521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2253d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner SourceLocation getRParenLoc() const { return RParenLoc; } 22541f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 2255866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek 2256aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceLocation getLocStart() const LLVM_READONLY; 2257aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceLocation getLocEnd() const LLVM_READONLY; 22581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 22604bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return T->getStmtClass() >= firstCallExprConstant && 22614bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt T->getStmtClass() <= lastCallExprConstant; 22625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 226388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 226477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 226563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 226663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], 226763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall &SubExprs[0]+NumArgs+getNumPreArgs()+PREARGS_START); 226863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 22695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 22705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2271ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner/// MemberExpr - [C99 6.5.2.3] Structure and Union Members. X->F and X.F. 22725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 22735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass MemberExpr : public Expr { 22746bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// Extra data stored in some member expressions. 22756857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth struct MemberNameQualifier { 22766857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// \brief The nested-name-specifier that qualifies the name, including 22776857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// source-location information. 22786857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth NestedNameSpecifierLoc QualifierLoc; 22796857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth 22806857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// \brief The DeclAccessPair through which the MemberDecl was found due to 22816857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// name qualifiers. 2282161755a09898c95d21bfff33707da9ca41cd53c5John McCall DeclAccessPair FoundDecl; 22836bb8017bb9e828d118e15e59d71c66bba323c364John McCall }; 22846bb8017bb9e828d118e15e59d71c66bba323c364John McCall 2285ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// Base - the expression for the base pointer or structure references. In 2286ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// X.F, this is "X". 22875549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Base; 22881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2289ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// MemberDecl - This is the decl being referenced by the field/member name. 2290ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// In X.F, this is the decl referenced by F. 2291f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *MemberDecl; 22921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22932577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// MemberDNLoc - Provides source/type location info for the 22942577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// declaration name embedded in MemberDecl. 22952577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameLoc MemberDNLoc; 22962577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 2297bbf4b22b3166e5065f4475006d83678e3e1d00a3Benjamin Kramer /// MemberLoc - This is the location of the member name. 2298bbf4b22b3166e5065f4475006d83678e3e1d00a3Benjamin Kramer SourceLocation MemberLoc; 2299bbf4b22b3166e5065f4475006d83678e3e1d00a3Benjamin Kramer 2300ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// IsArrow - True if this is "X->F", false if this is "X.F". 230183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor bool IsArrow : 1; 23021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 230383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief True if this member expression used a nested-name-specifier to 23046bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// refer to the member, e.g., "x->Base::f", or found its member via a using 23056bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// declaration. When true, a MemberNameQualifier 2306c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// structure is allocated immediately after the MemberExpr. 23076bb8017bb9e828d118e15e59d71c66bba323c364John McCall bool HasQualifierOrFoundDecl : 1; 23081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2309e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief True if this member expression specified a template keyword 2310e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// and/or a template argument list explicitly, e.g., x->f<int>, 2311e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// x->template f, x->template f<int>. 2312e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// When true, an ASTTemplateKWAndArgsInfo structure and its 2313e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// TemplateArguments (if any) are allocated immediately after 2314e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// the MemberExpr or, if the member expression also has a qualifier, 2315e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// after the MemberNameQualifier structure. 2316e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool HasTemplateKWAndArgsInfo : 1; 23171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23187cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// \brief True if this member expression refers to a method that 23197cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// was resolved from an overloaded set having size greater than 1. 23207cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool HadMultipleCandidates : 1; 23217cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara 232283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief Retrieve the qualifier that preceded the member name, if any. 23236bb8017bb9e828d118e15e59d71c66bba323c364John McCall MemberNameQualifier *getMemberQualifier() { 23246bb8017bb9e828d118e15e59d71c66bba323c364John McCall assert(HasQualifierOrFoundDecl); 23256bb8017bb9e828d118e15e59d71c66bba323c364John McCall return reinterpret_cast<MemberNameQualifier *> (this + 1); 232683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 232783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor 232883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief Retrieve the qualifier that preceded the member name, if any. 23296bb8017bb9e828d118e15e59d71c66bba323c364John McCall const MemberNameQualifier *getMemberQualifier() const { 2330c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return const_cast<MemberExpr *>(this)->getMemberQualifier(); 2331c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 23321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 2334f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl, 2335f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall const DeclarationNameInfo &NameInfo, QualType ty, 2336f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK) 2337f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(MemberExprClass, ty, VK, OK, 2338ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie base->isTypeDependent(), 2339561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor base->isValueDependent(), 2340561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor base->isInstantiationDependent(), 2341bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->containsUnexpandedParameterPack()), 2342bbf4b22b3166e5065f4475006d83678e3e1d00a3Benjamin Kramer Base(base), MemberDecl(memberdecl), MemberDNLoc(NameInfo.getInfo()), 2343bbf4b22b3166e5065f4475006d83678e3e1d00a3Benjamin Kramer MemberLoc(NameInfo.getLoc()), IsArrow(isarrow), 2344e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara HasQualifierOrFoundDecl(false), HasTemplateKWAndArgsInfo(false), 23457cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara HadMultipleCandidates(false) { 23462577743c5650c646fb705df01403707e94f2df04Abramo Bagnara assert(memberdecl->getDeclName() == NameInfo.getName()); 23472577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 23482577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 23492577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // NOTE: this constructor should be used only when it is known that 23502577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // the member name can not provide additional syntactic info 23512577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // (i.e., source locations for C++ operator names or type source info 2352e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara // for constructors, destructors and conversion operators). 23532577743c5650c646fb705df01403707e94f2df04Abramo Bagnara MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl, 2354f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall SourceLocation l, QualType ty, 2355f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK) 2356f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(MemberExprClass, ty, VK, OK, 2357bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->isTypeDependent(), base->isValueDependent(), 2358561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor base->isInstantiationDependent(), 2359bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->containsUnexpandedParameterPack()), 2360bbf4b22b3166e5065f4475006d83678e3e1d00a3Benjamin Kramer Base(base), MemberDecl(memberdecl), MemberDNLoc(), MemberLoc(l), 23612577743c5650c646fb705df01403707e94f2df04Abramo Bagnara IsArrow(isarrow), 2362e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara HasQualifierOrFoundDecl(false), HasTemplateKWAndArgsInfo(false), 23637cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara HadMultipleCandidates(false) {} 2364510190777c4bd53e960eea4665b204778fec1b64Eli Friedman 236505ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper static MemberExpr *Create(const ASTContext &C, Expr *base, bool isarrow, 236640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 2367e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 2368161755a09898c95d21bfff33707da9ca41cd53c5John McCall ValueDecl *memberdecl, DeclAccessPair founddecl, 23692577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo MemberNameInfo, 2370d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *targs, 2371f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType ty, ExprValueKind VK, ExprObjectKind OK); 23721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 237388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor void setBase(Expr *E) { Base = E; } 23745549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getBase() const { return cast<Expr>(Base); } 237557e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor 237657e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// \brief Retrieve the member declaration to which this expression refers. 237757e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// 237857e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// The returned declaration will either be a FieldDecl or (in C++) 237957e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// a CXXMethodDecl. 2380f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *getMemberDecl() const { return MemberDecl; } 2381f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman void setMemberDecl(ValueDecl *D) { MemberDecl = D; } 23821f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 23836bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// \brief Retrieves the declaration found by lookup. 2384161755a09898c95d21bfff33707da9ca41cd53c5John McCall DeclAccessPair getFoundDecl() const { 23856bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (!HasQualifierOrFoundDecl) 2386161755a09898c95d21bfff33707da9ca41cd53c5John McCall return DeclAccessPair::make(getMemberDecl(), 2387161755a09898c95d21bfff33707da9ca41cd53c5John McCall getMemberDecl()->getAccess()); 23886bb8017bb9e828d118e15e59d71c66bba323c364John McCall return getMemberQualifier()->FoundDecl; 23896bb8017bb9e828d118e15e59d71c66bba323c364John McCall } 23906bb8017bb9e828d118e15e59d71c66bba323c364John McCall 23911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Determines whether this member expression actually had 23920979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor /// a C++ nested-name-specifier prior to the name of the member, e.g., 23930979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor /// x->Base::foo. 23946bb8017bb9e828d118e15e59d71c66bba323c364John McCall bool hasQualifier() const { return getQualifier() != 0; } 23951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief If the member name was qualified, retrieves the 239783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// nested-name-specifier that precedes the member name. Otherwise, returns 239883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// NULL. 23991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump NestedNameSpecifier *getQualifier() const { 24006bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (!HasQualifierOrFoundDecl) 240183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return 0; 24021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 240340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return getMemberQualifier()->QualifierLoc.getNestedNameSpecifier(); 240440d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor } 240540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor 2406ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief If the member name was qualified, retrieves the 240740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor /// nested-name-specifier that precedes the member name, with source-location 240840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor /// information. 240940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc getQualifierLoc() const { 241040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (!hasQualifier()) 241140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return NestedNameSpecifierLoc(); 2412ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 241340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return getMemberQualifier()->QualifierLoc; 241483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 2415c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor 2416e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Return the optional template keyword and arguments info. 2417e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() { 2418e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) 2419e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return 0; 2420e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2421e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasQualifierOrFoundDecl) 2422e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return reinterpret_cast<ASTTemplateKWAndArgsInfo *>(this + 1); 2423e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2424e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return reinterpret_cast<ASTTemplateKWAndArgsInfo *>( 2425e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara getMemberQualifier() + 1); 2426e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2427e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2428e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Return the optional template keyword and arguments info. 2429e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const { 2430e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return const_cast<MemberExpr*>(this)->getTemplateKWAndArgsInfo(); 2431e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2432e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2433e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the template keyword preceding 2434e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// the member name, if any. 2435e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getTemplateKeywordLoc() const { 2436e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2437e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc(); 2438e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2439e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2440e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the left angle bracket starting the 2441e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// explicit template argument list following the member name, if any. 2442e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getLAngleLoc() const { 2443e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2444e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->LAngleLoc; 2445e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2446e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2447e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the right angle bracket ending the 2448e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// explicit template argument list following the member name, if any. 2449e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getRAngleLoc() const { 2450e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2451e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->RAngleLoc; 2452c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 24531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2454e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// Determines whether the member name was preceded by the template keyword. 2455e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } 2456e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2457e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Determines whether the member name was followed by an 2458e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// explicit template argument list. 2459e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } 2460e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2461d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// \brief Copies the template arguments (if present) into the given 2462d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// structure. 2463d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 2464096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (hasExplicitTemplateArgs()) 2465096832c5ed5b9106fa177ebc148489760c3bc496John McCall getExplicitTemplateArgs().copyInto(List); 2466096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 2467096832c5ed5b9106fa177ebc148489760c3bc496John McCall 2468096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that 2469096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// follow the member template name. This must only be called on an 2470096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// expression with explicit template arguments. 2471b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 2472e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara assert(hasExplicitTemplateArgs()); 2473e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return *getTemplateKWAndArgsInfo(); 2474096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 2475096832c5ed5b9106fa177ebc148489760c3bc496John McCall 2476096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that 2477096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// followed the member template name. This must only be called on 2478096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// an expression with explicit template arguments. 2479b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 2480096832c5ed5b9106fa177ebc148489760c3bc496John McCall return const_cast<MemberExpr *>(this)->getExplicitTemplateArgs(); 2481096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 2482096832c5ed5b9106fa177ebc148489760c3bc496John McCall 2483096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieves the optional explicit template arguments. 2484096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// This points to the same data as getExplicitTemplateArgs(), but 2485096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// returns null if there are no explicit template arguments. 2486b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const { 2487096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) return 0; 2488096832c5ed5b9106fa177ebc148489760c3bc496John McCall return &getExplicitTemplateArgs(); 2489d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall } 2490ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2491c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Retrieve the template arguments provided as part of this 2492c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template-id. 2493833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc *getTemplateArgs() const { 2494e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!hasExplicitTemplateArgs()) 24951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return 0; 24961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2497096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().getTemplateArgs(); 2498c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 24991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2500c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Retrieve the number of template arguments provided as part of this 2501c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template-id. 25021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned getNumTemplateArgs() const { 2503e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!hasExplicitTemplateArgs()) 25041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return 0; 25051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2506096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().NumTemplateArgs; 2507c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 25081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25092577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// \brief Retrieve the member declaration name info. 25102577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo getMemberNameInfo() const { 25112577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(MemberDecl->getDeclName(), 25122577743c5650c646fb705df01403707e94f2df04Abramo Bagnara MemberLoc, MemberDNLoc); 25132577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 25142577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 25155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isArrow() const { return IsArrow; } 25161f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setArrow(bool A) { IsArrow = A; } 25171f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 2518ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// getMemberLoc - Return the location of the "member", in X->F, it is the 2519ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// location of 'F'. 2520026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getMemberLoc() const { return MemberLoc; } 25211f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setMemberLoc(SourceLocation L) { MemberLoc = L; } 25225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2523aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceLocation getLocStart() const LLVM_READONLY; 2524aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceLocation getLocEnd() const LLVM_READONLY; 2525ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 25264f311183be3d923da9fbe8702c453688b4c426a9Daniel Dunbar SourceLocation getExprLoc() const LLVM_READONLY { return MemberLoc; } 25275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 252875e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor /// \brief Determine whether the base of this explicit is implicit. 252975e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor bool isImplicitAccess() const { 253075e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor return getBase() && getBase()->isImplicitCXXThis(); 253175e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } 25327cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara 25337cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// \brief Returns true if this member expression refers to a method that 25347cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// was resolved from an overloaded set having size greater than 1. 25357cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool hadMultipleCandidates() const { 25367cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara return HadMultipleCandidates; 25377cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara } 25387cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// \brief Sets the flag telling whether this expression refers to 25397cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// a method that was resolved from an overloaded set having size 25407cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// greater than 1. 25417cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara void setHadMultipleCandidates(bool V = true) { 25427cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara HadMultipleCandidates = V; 25437cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara } 25447cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara 25451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 254683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return T->getStmtClass() == MemberExprClass; 25475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 25481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25491237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 255063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Base, &Base+1); } 25514045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis 25524045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTReader; 25534045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTStmtWriter; 25545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 25555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 25561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CompoundLiteralExpr - [C99 6.5.2.5] 2557aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff/// 2558aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffclass CompoundLiteralExpr : public Expr { 25590fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// LParenLoc - If non-null, this is the location of the left paren in a 25600fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// compound literal like "(int){4}". This can be null if this is a 25610fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// synthesized compound expression. 25620fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner SourceLocation LParenLoc; 25631d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall 25641d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall /// The type as written. This can be an incomplete array type, in 25651d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall /// which case the actual expression type will be different. 25663654c6993697a30af0c5a472963fe8c03e622b98Benjamin Kramer /// The int part of the pair stores whether this expr is file scope. 25673654c6993697a30af0c5a472963fe8c03e622b98Benjamin Kramer llvm::PointerIntPair<TypeSourceInfo *, 1, bool> TInfoAndScope; 25685549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Init; 2569aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffpublic: 257042f56b50062cd3b3c6b23fdb9053578ae9145664John McCall CompoundLiteralExpr(SourceLocation lparenloc, TypeSourceInfo *tinfo, 2571f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK, Expr *init, bool fileScope) 2572f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CompoundLiteralExprClass, T, VK, OK_Ordinary, 2573ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie tinfo->getType()->isDependentType(), 2574bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor init->isValueDependent(), 2575561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (init->isInstantiationDependent() || 2576561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor tinfo->getType()->isInstantiationDependentType()), 2577bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor init->containsUnexpandedParameterPack()), 25783654c6993697a30af0c5a472963fe8c03e622b98Benjamin Kramer LParenLoc(lparenloc), TInfoAndScope(tinfo, fileScope), Init(init) {} 25791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2580ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor /// \brief Construct an empty compound literal. 2581ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor explicit CompoundLiteralExpr(EmptyShell Empty) 2582ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor : Expr(CompoundLiteralExprClass, Empty) { } 2583ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 25845549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getInitializer() const { return cast<Expr>(Init); } 25855549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getInitializer() { return cast<Expr>(Init); } 2586ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setInitializer(Expr *E) { Init = E; } 2587e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff 25883654c6993697a30af0c5a472963fe8c03e622b98Benjamin Kramer bool isFileScope() const { return TInfoAndScope.getInt(); } 25893654c6993697a30af0c5a472963fe8c03e622b98Benjamin Kramer void setFileScope(bool FS) { TInfoAndScope.setInt(FS); } 2590ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 25910fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner SourceLocation getLParenLoc() const { return LParenLoc; } 2592ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setLParenLoc(SourceLocation L) { LParenLoc = L; } 2593ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 25943654c6993697a30af0c5a472963fe8c03e622b98Benjamin Kramer TypeSourceInfo *getTypeSourceInfo() const { 25953654c6993697a30af0c5a472963fe8c03e622b98Benjamin Kramer return TInfoAndScope.getPointer(); 25963654c6993697a30af0c5a472963fe8c03e622b98Benjamin Kramer } 25973654c6993697a30af0c5a472963fe8c03e622b98Benjamin Kramer void setTypeSourceInfo(TypeSourceInfo *tinfo) { 25983654c6993697a30af0c5a472963fe8c03e622b98Benjamin Kramer TInfoAndScope.setPointer(tinfo); 25993654c6993697a30af0c5a472963fe8c03e622b98Benjamin Kramer } 260042f56b50062cd3b3c6b23fdb9053578ae9145664John McCall 260165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { 26020fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner // FIXME: Init should never be null. 26030fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner if (!Init) 260465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return SourceLocation(); 26050fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner if (LParenLoc.isInvalid()) 260665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return Init->getLocStart(); 260765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return LParenLoc; 260865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen } 260965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { 261065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen // FIXME: Init should never be null. 261165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen if (!Init) 261265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return SourceLocation(); 261365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return Init->getLocEnd(); 261473d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner } 2615aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff 26161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 26171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CompoundLiteralExprClass; 2618aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff } 26191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 26201237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 262163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Init, &Init+1); } 2622aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff}; 2623aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff 262449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CastExpr - Base class for type casts, including both implicit 262549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// casts (ImplicitCastExpr) and explicit casts that have some 262649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// representation in the source code (ExplicitCastExpr's derived 262749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// classes). 26280835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass CastExpr : public Expr { 2629cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlssonpublic: 26305baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall typedef clang::CastKind CastKind; 26311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2632cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlssonprivate: 26330835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis Stmt *Op; 2634409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson 26351d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall void CheckCastConsistency() const; 2636409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson 2637f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXBaseSpecifier * const *path_buffer() const { 2638f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return const_cast<CastExpr*>(this)->path_buffer(); 2639f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall } 2640f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CXXBaseSpecifier **path_buffer(); 2641f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2642654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis void setBasePathSize(unsigned basePathSize) { 2643654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis CastExprBits.BasePathSize = basePathSize; 2644654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis assert(CastExprBits.BasePathSize == basePathSize && 2645654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis "basePathSize doesn't fit in bits of CastExprBits.BasePathSize!"); 2646654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis } 2647654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis 26480835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisprotected: 2649f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CastExpr(StmtClass SC, QualType ty, ExprValueKind VK, 2650f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall const CastKind kind, Expr *op, unsigned BasePathSize) : 2651f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(SC, ty, VK, OK_Ordinary, 2652898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Cast expressions are type-dependent if the type is 2653898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // dependent (C++ [temp.dep.expr]p3). 2654898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ty->isDependentType(), 2655898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Cast expressions are value-dependent if the type is 2656898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // dependent or if the subexpression is value-dependent. 2657bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ty->isDependentType() || (op && op->isValueDependent()), 2658ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie (ty->isInstantiationDependentType() || 2659561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (op && op->isInstantiationDependent())), 2660bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (ty->containsUnexpandedParameterPack() || 2661a2338bc4c2887937478d302901fb41a53e14e6d6Anna Zaks (op && op->containsUnexpandedParameterPack()))), 26628e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall Op(op) { 2663daa8e4e888758d55a7a759dd4a91b83921cef222John McCall assert(kind != CK_Invalid && "creating cast with invalid cast kind"); 26648e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CastExprBits.Kind = kind; 2665654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis setBasePathSize(BasePathSize); 26661d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall#ifndef NDEBUG 2667daa8e4e888758d55a7a759dd4a91b83921cef222John McCall CheckCastConsistency(); 26681d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall#endif 2669f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall } 26701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2671087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor /// \brief Construct an empty cast. 2672f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastExpr(StmtClass SC, EmptyShell Empty, unsigned BasePathSize) 26738e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall : Expr(SC, Empty) { 2674654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis setBasePathSize(BasePathSize); 26758e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall } 26761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 26770835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidispublic: 26788e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CastKind getCastKind() const { return (CastKind) CastExprBits.Kind; } 26798e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall void setCastKind(CastKind K) { CastExprBits.Kind = K; } 2680f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson const char *getCastKindName() const; 2681f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson 26820835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis Expr *getSubExpr() { return cast<Expr>(Op); } 26830835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis const Expr *getSubExpr() const { return cast<Expr>(Op); } 2684087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor void setSubExpr(Expr *E) { Op = E; } 2685087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor 26866eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// \brief Retrieve the cast subexpression as it was written in the source 26876eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// code, looking through any implicit casts or other intermediate nodes 26886eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// introduced by semantic analysis. 26896eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor Expr *getSubExprAsWritten(); 26906eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor const Expr *getSubExprAsWritten() const { 26916eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return const_cast<CastExpr *>(this)->getSubExprAsWritten(); 26926eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor } 269341b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson 2694f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall typedef CXXBaseSpecifier **path_iterator; 2695f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall typedef const CXXBaseSpecifier * const *path_const_iterator; 26968e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall bool path_empty() const { return CastExprBits.BasePathSize == 0; } 26978e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned path_size() const { return CastExprBits.BasePathSize; } 2698f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_iterator path_begin() { return path_buffer(); } 2699f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_iterator path_end() { return path_buffer() + path_size(); } 2700f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_const_iterator path_begin() const { return path_buffer(); } 2701f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_const_iterator path_end() const { return path_buffer() + path_size(); } 2702f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2703f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall void setCastPath(const CXXCastPath &Path); 270441b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson 27051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 27064bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return T->getStmtClass() >= firstCastExprConstant && 27074bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt T->getStmtClass() <= lastCastExprConstant; 27080835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis } 27091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27100835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis // Iterators 271163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Op, &Op+1); } 27120835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis}; 27130835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis 271449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ImplicitCastExpr - Allows us to explicitly represent implicit type 271549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// conversions, which have no direct representation in the original 271649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// source code. For example: converting T[]->T*, void f()->void 271749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (*f)(), float->double, short->int, etc. 271849b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff/// 2719bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// In C, implicit casts always produce rvalues. However, in C++, an 2720bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// implicit cast whose result is being bound to a reference will be 2721906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// an lvalue or xvalue. For example: 2722bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// 2723bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @code 2724bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Base { }; 2725bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Derived : public Base { }; 2726906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// Derived &&ref(); 27271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// void f(Derived d) { 2728906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// Base& b = d; // initializer is an ImplicitCastExpr 2729906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// // to an lvalue of type Base 2730906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// Base&& r = ref(); // initializer is an ImplicitCastExpr 2731906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// // to an xvalue of type Base 2732bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// } 2733bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @endcode 27340835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ImplicitCastExpr : public CastExpr { 2735906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redlprivate: 2736f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ImplicitCastExpr(QualType ty, CastKind kind, Expr *op, 27375baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall unsigned BasePathLength, ExprValueKind VK) 2738f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, BasePathLength) { 27395baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall } 274090045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff 2741087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor /// \brief Construct an empty implicit cast. 2742f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall explicit ImplicitCastExpr(EmptyShell Shell, unsigned PathSize) 2743f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : CastExpr(ImplicitCastExprClass, Shell, PathSize) { } 2744f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2745f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 2746f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall enum OnStack_t { OnStack }; 2747f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ImplicitCastExpr(OnStack_t _, QualType ty, CastKind kind, Expr *op, 27485baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall ExprValueKind VK) 2749f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, 0) { 27505baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall } 2751f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 275205ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper static ImplicitCastExpr *Create(const ASTContext &Context, QualType T, 2753f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastKind Kind, Expr *Operand, 2754f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXCastPath *BasePath, 27555baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall ExprValueKind Cat); 2756f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 275705ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper static ImplicitCastExpr *CreateEmpty(const ASTContext &Context, 275805ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper unsigned PathSize); 2759087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor 2760aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceLocation getLocStart() const LLVM_READONLY { 2761396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar return getSubExpr()->getLocStart(); 2762396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar } 2763aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceLocation getLocEnd() const LLVM_READONLY { 2764396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar return getSubExpr()->getLocEnd(); 2765396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar } 276690045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff 27671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 27681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ImplicitCastExprClass; 276949b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff } 277049b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff}; 277149b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff 277291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCallinline Expr *Expr::IgnoreImpCasts() { 277391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall Expr *e = this; 277491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall while (ImplicitCastExpr *ice = dyn_cast<ImplicitCastExpr>(e)) 277591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall e = ice->getSubExpr(); 277691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall return e; 277791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall} 277891a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 277949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ExplicitCastExpr - An explicit cast written in the source 27801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// code. 278149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// 278249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This class is effectively an abstract class, because it provides 278349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// the basic representation of an explicitly-written cast without 278449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// specifying which kind of cast (C cast, functional cast, static 278549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast, etc.) was written; specific derived classes represent the 278649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// particular style of cast and its location information. 27875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 278849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// Unlike implicit casts, explicit cast nodes have two different 278949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// types: the type that was written into the source code, and the 279049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// actual type of the expression as determined by semantic 279149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// analysis. These types may differ slightly. For example, in C++ one 279249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// can cast to a reference type, which indicates that the resulting 2793906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// expression will be an lvalue or xvalue. The reference type, however, 2794906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// will not be used as the type of the expression. 27950835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ExplicitCastExpr : public CastExpr { 27969d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// TInfo - Source type info for the (written) type 27979d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// this expression is casting to. 27989d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo; 279949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 280049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorprotected: 2801f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExplicitCastExpr(StmtClass SC, QualType exprTy, ExprValueKind VK, 2802f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CastKind kind, Expr *op, unsigned PathSize, 2803f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall TypeSourceInfo *writtenTy) 2804f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : CastExpr(SC, exprTy, VK, kind, op, PathSize), TInfo(writtenTy) {} 280549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 2806db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty explicit cast. 2807f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ExplicitCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize) 2808f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : CastExpr(SC, Shell, PathSize) { } 2809db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 281049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorpublic: 28119d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// getTypeInfoAsWritten - Returns the type source info for the type 28129d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// that this expression is casting to. 28139d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *getTypeInfoAsWritten() const { return TInfo; } 28149d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall void setTypeInfoAsWritten(TypeSourceInfo *writtenTy) { TInfo = writtenTy; } 28159d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall 281649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// getTypeAsWritten - Returns the type that this expression is 281749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// casting to, as written in the source code. 28189d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall QualType getTypeAsWritten() const { return TInfo->getType(); } 281949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 28201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 28214bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return T->getStmtClass() >= firstExplicitCastExprConstant && 28224bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt T->getStmtClass() <= lastExplicitCastExprConstant; 282349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor } 282449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor}; 282549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 28266eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor/// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style 282749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast in C++ (C++ [expr.cast]), which uses the syntax 282849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (Type)expr. For example: @c (int)f. 28296eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregorclass CStyleCastExpr : public ExplicitCastExpr { 2830b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation LPLoc; // the location of the left paren 2831b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation RPLoc; // the location of the right paren 2832f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2833f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CStyleCastExpr(QualType exprTy, ExprValueKind vk, CastKind kind, Expr *op, 2834f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned PathSize, TypeSourceInfo *writtenTy, 283541b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson SourceLocation l, SourceLocation r) 2836f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : ExplicitCastExpr(CStyleCastExprClass, exprTy, vk, kind, op, PathSize, 283741b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson writtenTy), LPLoc(l), RPLoc(r) {} 283849b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff 2839db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty C-style explicit cast. 2840f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall explicit CStyleCastExpr(EmptyShell Shell, unsigned PathSize) 2841f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : ExplicitCastExpr(CStyleCastExprClass, Shell, PathSize) { } 2842f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2843f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 284405ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper static CStyleCastExpr *Create(const ASTContext &Context, QualType T, 2845f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, CastKind K, 2846f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall Expr *Op, const CXXCastPath *BasePath, 2847f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall TypeSourceInfo *WrittenTy, SourceLocation L, 2848f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall SourceLocation R); 2849f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 285005ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper static CStyleCastExpr *CreateEmpty(const ASTContext &Context, 285105ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper unsigned PathSize); 2852db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 2853b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation getLParenLoc() const { return LPLoc; } 2854db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setLParenLoc(SourceLocation L) { LPLoc = L; } 2855db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 2856b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation getRParenLoc() const { return RPLoc; } 2857db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setRParenLoc(SourceLocation L) { RPLoc = L; } 2858db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 285965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return LPLoc; } 286065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { 286165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return getSubExpr()->getLocEnd(); 28625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 286365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 28641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 28651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CStyleCastExprClass; 28665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 28675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 28685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 28693fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// \brief A builtin binary operation expression such as "x + y" or "x <= y". 28703fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 28713fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// This expression node kind describes a builtin binary operation, 28723fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// such as "x + y" for integer values "x" and "y". The operands will 28733fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// already have been converted to appropriate types (e.g., by 28743fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// performing promotions or conversions). 28753fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 28763fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// In C++, where operators may be overloaded, a different kind of 28773fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// expression node (CXXOperatorCallExpr) is used to express the 28783fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// invocation of an overloaded operator with operator syntax. Within 28793fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is 28803fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to store an expression "x + y" depends on the subexpressions 28813fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// for x and y. If neither x or y is type-dependent, and the "+" 28823fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// operator resolves to a built-in operation, BinaryOperator will be 28833fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to express the computation (x and y may still be 28843fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// value-dependent). If either x or y is type-dependent, or if the 28853fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// "+" resolves to an overloaded operator, CXXOperatorCallExpr will 28863fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// be used to express the computation. 28875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BinaryOperator : public Expr { 28885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 28895baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall typedef BinaryOperatorKind Opcode; 28905baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 289117d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattnerprivate: 28920799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall unsigned Opc : 6; 2893be9af1288881110e406b87914162eaa59f1e5918Lang Hames 2894be9af1288881110e406b87914162eaa59f1e5918Lang Hames // Records the FP_CONTRACT pragma status at the point that this binary 2895be9af1288881110e406b87914162eaa59f1e5918Lang Hames // operator was parsed. This bit is only meaningful for operations on 2896be9af1288881110e406b87914162eaa59f1e5918Lang Hames // floating point types. For all other types it should default to 2897be9af1288881110e406b87914162eaa59f1e5918Lang Hames // false. 2898be9af1288881110e406b87914162eaa59f1e5918Lang Hames unsigned FPContractable : 1; 28990799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall SourceLocation OpLoc; 29000799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall 290117d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner enum { LHS, RHS, END_EXPR }; 29025549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; 29031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 29041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 290517d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 2906f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 2907be9af1288881110e406b87914162eaa59f1e5918Lang Hames SourceLocation opLoc, bool fpContractable) 2908f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(BinaryOperatorClass, ResTy, VK, OK, 2909898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor lhs->isTypeDependent() || rhs->isTypeDependent(), 2910bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor lhs->isValueDependent() || rhs->isValueDependent(), 2911561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (lhs->isInstantiationDependent() || 2912561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhs->isInstantiationDependent()), 2913bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (lhs->containsUnexpandedParameterPack() || 2914bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhs->containsUnexpandedParameterPack())), 2915be9af1288881110e406b87914162eaa59f1e5918Lang Hames Opc(opc), FPContractable(fpContractable), OpLoc(opLoc) { 29161237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 29171237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 29181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(!isCompoundAssignmentOp() && 291958b65d953e67251bfce28a5251bb3b496490f343Stefanus Du Toit "Use CompoundAssignOperator for compound assignments"); 29205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 29215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2922db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty binary operator. 29231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit BinaryOperator(EmptyShell Empty) 29242de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall : Expr(BinaryOperatorClass, Empty), Opc(BO_Comma) { } 2925db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 29264f311183be3d923da9fbe8702c453688b4c426a9Daniel Dunbar SourceLocation getExprLoc() const LLVM_READONLY { return OpLoc; } 292717d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation getOperatorLoc() const { return OpLoc; } 2928db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setOperatorLoc(SourceLocation L) { OpLoc = L; } 2929db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 29300799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Opcode getOpcode() const { return static_cast<Opcode>(Opc); } 2931db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setOpcode(Opcode O) { Opc = O; } 2932db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 29335549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 2934db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 29355549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 2936db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 2937db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 293865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { 293965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return getLHS()->getLocStart(); 294065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen } 294165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { 294265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return getRHS()->getLocEnd(); 29435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 29441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 29465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// corresponds to, e.g. "<<=". 29470bea86307eb8c16339315a1e261fc490eb505c5bDavid Blaikie static StringRef getOpcodeStr(Opcode Op); 29485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 29490bea86307eb8c16339315a1e261fc490eb505c5bDavid Blaikie StringRef getOpcodeStr() const { return getOpcodeStr(getOpcode()); } 2950a84c02d0f4d63975a1c52b9bb8308d88e9d79352Ted Kremenek 2951063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// \brief Retrieve the binary opcode that corresponds to the given 2952063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// overloaded operator. 2953063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static Opcode getOverloadedOpcode(OverloadedOperatorKind OO); 2954063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 2955063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// \brief Retrieve the overloaded operator kind that corresponds to 2956063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// the given binary opcode. 2957063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); 2958063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 29595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// predicates to categorize the respective opcodes. 2960200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl bool isPtrMemOp() const { return Opc == BO_PtrMemD || Opc == BO_PtrMemI; } 29612de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall bool isMultiplicativeOp() const { return Opc >= BO_Mul && Opc <= BO_Rem; } 29622de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isAdditiveOp(Opcode Opc) { return Opc == BO_Add || Opc==BO_Sub; } 29630799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isAdditiveOp() const { return isAdditiveOp(getOpcode()); } 29642de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isShiftOp(Opcode Opc) { return Opc == BO_Shl || Opc == BO_Shr; } 29650799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isShiftOp() const { return isShiftOp(getOpcode()); } 2966aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl 29672de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isBitwiseOp(Opcode Opc) { return Opc >= BO_And && Opc <= BO_Or; } 29680799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isBitwiseOp() const { return isBitwiseOp(getOpcode()); } 2969f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 29702de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isRelationalOp(Opcode Opc) { return Opc >= BO_LT && Opc<=BO_GE; } 29710799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isRelationalOp() const { return isRelationalOp(getOpcode()); } 2972f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 29732de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isEqualityOp(Opcode Opc) { return Opc == BO_EQ || Opc == BO_NE; } 29740799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isEqualityOp() const { return isEqualityOp(getOpcode()); } 29751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29762de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isComparisonOp(Opcode Opc) { return Opc >= BO_LT && Opc<=BO_NE; } 29770799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isComparisonOp() const { return isComparisonOp(getOpcode()); } 2978aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl 29798569281fb7ce9b5ca164a0528b876acbb45eb989Jordan Rose static Opcode negateComparisonOp(Opcode Opc) { 29808569281fb7ce9b5ca164a0528b876acbb45eb989Jordan Rose switch (Opc) { 29818569281fb7ce9b5ca164a0528b876acbb45eb989Jordan Rose default: 29828569281fb7ce9b5ca164a0528b876acbb45eb989Jordan Rose llvm_unreachable("Not a comparsion operator."); 29838569281fb7ce9b5ca164a0528b876acbb45eb989Jordan Rose case BO_LT: return BO_GE; 29848569281fb7ce9b5ca164a0528b876acbb45eb989Jordan Rose case BO_GT: return BO_LE; 29858569281fb7ce9b5ca164a0528b876acbb45eb989Jordan Rose case BO_LE: return BO_GT; 29868569281fb7ce9b5ca164a0528b876acbb45eb989Jordan Rose case BO_GE: return BO_LT; 29878569281fb7ce9b5ca164a0528b876acbb45eb989Jordan Rose case BO_EQ: return BO_NE; 29888569281fb7ce9b5ca164a0528b876acbb45eb989Jordan Rose case BO_NE: return BO_EQ; 29898569281fb7ce9b5ca164a0528b876acbb45eb989Jordan Rose } 29908569281fb7ce9b5ca164a0528b876acbb45eb989Jordan Rose } 29918569281fb7ce9b5ca164a0528b876acbb45eb989Jordan Rose 29928569281fb7ce9b5ca164a0528b876acbb45eb989Jordan Rose static Opcode reverseComparisonOp(Opcode Opc) { 29938569281fb7ce9b5ca164a0528b876acbb45eb989Jordan Rose switch (Opc) { 29948569281fb7ce9b5ca164a0528b876acbb45eb989Jordan Rose default: 29958569281fb7ce9b5ca164a0528b876acbb45eb989Jordan Rose llvm_unreachable("Not a comparsion operator."); 29968569281fb7ce9b5ca164a0528b876acbb45eb989Jordan Rose case BO_LT: return BO_GT; 29978569281fb7ce9b5ca164a0528b876acbb45eb989Jordan Rose case BO_GT: return BO_LT; 29988569281fb7ce9b5ca164a0528b876acbb45eb989Jordan Rose case BO_LE: return BO_GE; 29998569281fb7ce9b5ca164a0528b876acbb45eb989Jordan Rose case BO_GE: return BO_LE; 30008569281fb7ce9b5ca164a0528b876acbb45eb989Jordan Rose case BO_EQ: 30018569281fb7ce9b5ca164a0528b876acbb45eb989Jordan Rose case BO_NE: 30028569281fb7ce9b5ca164a0528b876acbb45eb989Jordan Rose return Opc; 30038569281fb7ce9b5ca164a0528b876acbb45eb989Jordan Rose } 30048569281fb7ce9b5ca164a0528b876acbb45eb989Jordan Rose } 30058569281fb7ce9b5ca164a0528b876acbb45eb989Jordan Rose 30062de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isLogicalOp(Opcode Opc) { return Opc == BO_LAnd || Opc==BO_LOr; } 30070799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isLogicalOp() const { return isLogicalOp(getOpcode()); } 3008f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 30090e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall static bool isAssignmentOp(Opcode Opc) { 30100e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall return Opc >= BO_Assign && Opc <= BO_OrAssign; 30110e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall } 30120e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall bool isAssignmentOp() const { return isAssignmentOp(getOpcode()); } 30130e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall 30140e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall static bool isCompoundAssignmentOp(Opcode Opc) { 30152de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Opc > BO_Assign && Opc <= BO_OrAssign; 30162de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 30170e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall bool isCompoundAssignmentOp() const { 30180e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall return isCompoundAssignmentOp(getOpcode()); 30190e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall } 30204b9c2d235fb9449e249d74f48ecfec601650de93John McCall static Opcode getOpForCompoundAssignment(Opcode Opc) { 30214b9c2d235fb9449e249d74f48ecfec601650de93John McCall assert(isCompoundAssignmentOp(Opc)); 3022b92e5d0acbb21e57498fcc4157e108a50c82b857John McCall if (Opc >= BO_AndAssign) 3023b92e5d0acbb21e57498fcc4157e108a50c82b857John McCall return Opcode(unsigned(Opc) - BO_AndAssign + BO_And); 30244b9c2d235fb9449e249d74f48ecfec601650de93John McCall else 30254b9c2d235fb9449e249d74f48ecfec601650de93John McCall return Opcode(unsigned(Opc) - BO_MulAssign + BO_Mul); 30264b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 30270e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall 30280e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall static bool isShiftAssignOp(Opcode Opc) { 30292de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Opc == BO_ShlAssign || Opc == BO_ShrAssign; 30302de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 30310e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall bool isShiftAssignOp() const { 30320e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall return isShiftAssignOp(getOpcode()); 30330e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall } 30341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *S) { 30364bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return S->getStmtClass() >= firstBinaryOperatorConstant && 30374bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt S->getStmtClass() <= lastBinaryOperatorConstant; 30385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 30391237c673c07f9d827129ba02720108816abde562Ted Kremenek 30401237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 304163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 304263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 304363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 30441237c673c07f9d827129ba02720108816abde562Ted Kremenek 3045be9af1288881110e406b87914162eaa59f1e5918Lang Hames // Set the FP contractability status of this operator. Only meaningful for 3046be9af1288881110e406b87914162eaa59f1e5918Lang Hames // operations on floating point types. 3047be9af1288881110e406b87914162eaa59f1e5918Lang Hames void setFPContractable(bool FPC) { FPContractable = FPC; } 3048be9af1288881110e406b87914162eaa59f1e5918Lang Hames 3049be9af1288881110e406b87914162eaa59f1e5918Lang Hames // Get the FP contractability status of this operator. Only meaningful for 3050be9af1288881110e406b87914162eaa59f1e5918Lang Hames // operations on floating point types. 3051be9af1288881110e406b87914162eaa59f1e5918Lang Hames bool isFPContractable() const { return FPContractable; } 3052be9af1288881110e406b87914162eaa59f1e5918Lang Hames 30535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 305417d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 3055f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 3056be9af1288881110e406b87914162eaa59f1e5918Lang Hames SourceLocation opLoc, bool fpContractable, bool dead2) 3057f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CompoundAssignOperatorClass, ResTy, VK, OK, 30582333f7727f97018d6742e1e0938133bcfad967abEli Friedman lhs->isTypeDependent() || rhs->isTypeDependent(), 3059bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor lhs->isValueDependent() || rhs->isValueDependent(), 3060561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (lhs->isInstantiationDependent() || 3061561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhs->isInstantiationDependent()), 3062bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (lhs->containsUnexpandedParameterPack() || 3063bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhs->containsUnexpandedParameterPack())), 3064be9af1288881110e406b87914162eaa59f1e5918Lang Hames Opc(opc), FPContractable(fpContractable), OpLoc(opLoc) { 30651237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 30661237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 30675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3068ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 30691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump BinaryOperator(StmtClass SC, EmptyShell Empty) 30702de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall : Expr(SC, Empty), Opc(BO_MulAssign) { } 30715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 30725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 30735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep 30745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// track of the type the operation is performed in. Due to the semantics of 3075ec5bc81fd55bfcc26fc4bde6d5e33113d94c2209Zhongxing Xu/// these operators, the operands are promoted, the arithmetic performed, an 30765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// implicit conversion back to the result type done, then the assignment takes 30775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// place. This captures the intermediate type which the computation is done 30785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// in. 30795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CompoundAssignOperator : public BinaryOperator { 3080ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType ComputationLHSType; 3081ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType ComputationResultType; 30825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 3083f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResType, 3084f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 3085f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType CompLHSType, QualType CompResultType, 3086be9af1288881110e406b87914162eaa59f1e5918Lang Hames SourceLocation OpLoc, bool fpContractable) 3087be9af1288881110e406b87914162eaa59f1e5918Lang Hames : BinaryOperator(lhs, rhs, opc, ResType, VK, OK, OpLoc, fpContractable, 3088be9af1288881110e406b87914162eaa59f1e5918Lang Hames true), 3089ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman ComputationLHSType(CompLHSType), 3090ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman ComputationResultType(CompResultType) { 30911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(isCompoundAssignmentOp() && 30925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Only should be used for compound assignments"); 30935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 30945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3095ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor /// \brief Build an empty compound assignment operator expression. 3096ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor explicit CompoundAssignOperator(EmptyShell Empty) 3097ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor : BinaryOperator(CompoundAssignOperatorClass, Empty) { } 3098ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 3099ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // The two computation types are the type the LHS is converted 3100ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // to for the computation and the type of the result; the two are 3101ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // distinct in a few cases (specifically, int+=ptr and ptr-=ptr). 3102ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType getComputationLHSType() const { return ComputationLHSType; } 3103ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setComputationLHSType(QualType T) { ComputationLHSType = T; } 3104ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 3105ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType getComputationResultType() const { return ComputationResultType; } 3106ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setComputationResultType(QualType T) { ComputationResultType = T; } 3107ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 31081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *S) { 31091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return S->getStmtClass() == CompoundAssignOperatorClass; 31105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 31115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 31125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 311356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// AbstractConditionalOperator - An abstract base class for 311456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// ConditionalOperator and BinaryConditionalOperator. 311556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass AbstractConditionalOperator : public Expr { 311656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation QuestionLoc, ColonLoc; 311756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall friend class ASTStmtReader; 311856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 311956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallprotected: 312056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall AbstractConditionalOperator(StmtClass SC, QualType T, 312156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall ExprValueKind VK, ExprObjectKind OK, 3122561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool TD, bool VD, bool ID, 312356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall bool ContainsUnexpandedParameterPack, 312456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation qloc, 312556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation cloc) 3126561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Expr(SC, T, VK, OK, TD, VD, ID, ContainsUnexpandedParameterPack), 312756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall QuestionLoc(qloc), ColonLoc(cloc) {} 312856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 312956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall AbstractConditionalOperator(StmtClass SC, EmptyShell Empty) 313056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : Expr(SC, Empty) { } 313156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 313256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallpublic: 313356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getCond - Return the expression representing the condition for 313456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the ?: operator. 313556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getCond() const; 313656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 313756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getTrueExpr - Return the subexpression representing the value of 313856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the expression if the condition evaluates to true. 313956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getTrueExpr() const; 314056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 314156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getFalseExpr - Return the subexpression representing the value of 314256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the expression if the condition evaluates to false. This is 314356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the same as getRHS. 314456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getFalseExpr() const; 314556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 314656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation getQuestionLoc() const { return QuestionLoc; } 314756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation getColonLoc() const { return ColonLoc; } 314856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 314956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const Stmt *T) { 315056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return T->getStmtClass() == ConditionalOperatorClass || 315156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall T->getStmtClass() == BinaryConditionalOperatorClass; 315256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 315356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall}; 315456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 315556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// ConditionalOperator - The ?: ternary operator. The GNU "missing 315656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// middle" extension is a BinaryConditionalOperator. 315756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass ConditionalOperator : public AbstractConditionalOperator { 31581237c673c07f9d827129ba02720108816abde562Ted Kremenek enum { COND, LHS, RHS, END_EXPR }; 31595549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 316056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 316156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall friend class ASTStmtReader; 31625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 316347e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor ConditionalOperator(Expr *cond, SourceLocation QLoc, Expr *lhs, 316456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation CLoc, Expr *rhs, 31650943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall QualType t, ExprValueKind VK, ExprObjectKind OK) 316656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : AbstractConditionalOperator(ConditionalOperatorClass, t, VK, OK, 3167898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // FIXME: the type of the conditional operator doesn't 3168898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // depend on the type of the conditional, but the standard 3169898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // seems to imply that it could. File a bug! 317056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (lhs->isTypeDependent() || rhs->isTypeDependent()), 317156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (cond->isValueDependent() || lhs->isValueDependent() || 317256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall rhs->isValueDependent()), 3173561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (cond->isInstantiationDependent() || 3174561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor lhs->isInstantiationDependent() || 3175561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhs->isInstantiationDependent()), 3176bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (cond->containsUnexpandedParameterPack() || 317756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall lhs->containsUnexpandedParameterPack() || 317856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall rhs->containsUnexpandedParameterPack()), 317956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall QLoc, CLoc) { 31801237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[COND] = cond; 31811237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 31821237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 31831237c673c07f9d827129ba02720108816abde562Ted Kremenek } 31845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3185ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor /// \brief Build an empty conditional operator. 3186ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor explicit ConditionalOperator(EmptyShell Empty) 318756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : AbstractConditionalOperator(ConditionalOperatorClass, Empty) { } 3188ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 3189395a2abf0028968d85958610e393e067885dc14fTed Kremenek // getCond - Return the expression representing the condition for 319056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the ?: operator. 31915549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 3192395a2abf0028968d85958610e393e067885dc14fTed Kremenek 319356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getTrueExpr - Return the subexpression representing the value of 319456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the expression if the condition evaluates to true. 319556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getTrueExpr() const { return cast<Expr>(SubExprs[LHS]); } 31961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 319756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getFalseExpr - Return the subexpression representing the value of 319856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the expression if the condition evaluates to false. This is 319956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the same as getRHS. 32005549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); } 3201ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 320256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 32035549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 320447e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor 320565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { 320665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return getCond()->getLocStart(); 320765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen } 320865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { 320965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return getRHS()->getLocEnd(); 32105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 321165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 32121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 32131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ConditionalOperatorClass; 32145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 32151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32161237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 321763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 321863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 321963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 32205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 32215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 322256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// BinaryConditionalOperator - The GNU extension to the conditional 322356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// operator which allows the middle operand to be omitted. 322456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// 322556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// This is a different expression kind on the assumption that almost 322656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// every client ends up needing to know that these are different. 322756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass BinaryConditionalOperator : public AbstractConditionalOperator { 322856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall enum { COMMON, COND, LHS, RHS, NUM_SUBEXPRS }; 322956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 323056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// - the common condition/left-hand-side expression, which will be 323156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// evaluated as the opaque value 323256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// - the condition, expressed in terms of the opaque value 323356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// - the left-hand-side, expressed in terms of the opaque value 323456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// - the right-hand-side 323556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Stmt *SubExprs[NUM_SUBEXPRS]; 323656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValueExpr *OpaqueValue; 323756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 323856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall friend class ASTStmtReader; 323956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallpublic: 324056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall BinaryConditionalOperator(Expr *common, OpaqueValueExpr *opaqueValue, 324156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *cond, Expr *lhs, Expr *rhs, 324256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation qloc, SourceLocation cloc, 324356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall QualType t, ExprValueKind VK, ExprObjectKind OK) 324456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : AbstractConditionalOperator(BinaryConditionalOperatorClass, t, VK, OK, 324556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (common->isTypeDependent() || rhs->isTypeDependent()), 324656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (common->isValueDependent() || rhs->isValueDependent()), 3247561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (common->isInstantiationDependent() || 3248561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhs->isInstantiationDependent()), 324956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (common->containsUnexpandedParameterPack() || 325056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall rhs->containsUnexpandedParameterPack()), 325156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall qloc, cloc), 325256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValue(opaqueValue) { 325356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SubExprs[COMMON] = common; 325456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SubExprs[COND] = cond; 325556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SubExprs[LHS] = lhs; 325656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SubExprs[RHS] = rhs; 325797df54e0c075bc8d6a869597e771dad0c11a2180Douglas Gregor assert(OpaqueValue->getSourceExpr() == common && "Wrong opaque value"); 325856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 325956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 326056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief Build an empty conditional operator. 326156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall explicit BinaryConditionalOperator(EmptyShell Empty) 326256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : AbstractConditionalOperator(BinaryConditionalOperatorClass, Empty) { } 326356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 326456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getCommon - Return the common expression, written to the 326556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// left of the condition. The opaque value will be bound to the 326656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// result of this expression. 326756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getCommon() const { return cast<Expr>(SubExprs[COMMON]); } 326856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 326956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getOpaqueValue - Return the opaque value placeholder. 327056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValueExpr *getOpaqueValue() const { return OpaqueValue; } 327156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 327256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getCond - Return the condition expression; this is defined 327356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// in terms of the opaque value. 327456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 327556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 327656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getTrueExpr - Return the subexpression which will be 327756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// evaluated if the condition evaluates to true; this is defined 327856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// in terms of the opaque value. 327956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getTrueExpr() const { 328056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<Expr>(SubExprs[LHS]); 328156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 328256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 328356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getFalseExpr - Return the subexpression which will be 328456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// evaluated if the condnition evaluates to false; this is 328556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// defined in terms of the opaque value. 328656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getFalseExpr() const { 328756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<Expr>(SubExprs[RHS]); 328856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 3289ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 329065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { 329165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return getCommon()->getLocStart(); 329265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen } 329365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { 329465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return getFalseExpr()->getLocEnd(); 329556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 329665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 329756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const Stmt *T) { 329856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return T->getStmtClass() == BinaryConditionalOperatorClass; 329956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 330056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 330156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // Iterators 330256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall child_range children() { 330356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return child_range(SubExprs, SubExprs + NUM_SUBEXPRS); 330456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 330556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall}; 330656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 330756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallinline Expr *AbstractConditionalOperator::getCond() const { 330856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this)) 330956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return co->getCond(); 331056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<BinaryConditionalOperator>(this)->getCond(); 331156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall} 331256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 331356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallinline Expr *AbstractConditionalOperator::getTrueExpr() const { 331456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this)) 331556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return co->getTrueExpr(); 331656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<BinaryConditionalOperator>(this)->getTrueExpr(); 331756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall} 331856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 331956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallinline Expr *AbstractConditionalOperator::getFalseExpr() const { 332056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this)) 332156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return co->getFalseExpr(); 332256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<BinaryConditionalOperator>(this)->getFalseExpr(); 332356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall} 332456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 33256481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner/// AddrLabelExpr - The GNU address of label extension, representing &&label. 33266481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattnerclass AddrLabelExpr : public Expr { 33275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation AmpAmpLoc, LabelLoc; 3328ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *Label; 33295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 3330ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelDecl *L, 33316481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner QualType t) 3332561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Expr(AddrLabelExprClass, t, VK_RValue, OK_Ordinary, false, false, false, 3333561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false), 33342333f7727f97018d6742e1e0938133bcfad967abEli Friedman AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {} 33351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 33367d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor /// \brief Build an empty address of a label expression. 33371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit AddrLabelExpr(EmptyShell Empty) 33387d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor : Expr(AddrLabelExprClass, Empty) { } 33397d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 33407d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; } 33417d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; } 33427d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor SourceLocation getLabelLoc() const { return LabelLoc; } 33437d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setLabelLoc(SourceLocation L) { LabelLoc = L; } 33447d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 334565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return AmpAmpLoc; } 334665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return LabelLoc; } 33471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3348ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *getLabel() const { return Label; } 3349ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner void setLabel(LabelDecl *L) { Label = L; } 33507d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 33515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 33521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == AddrLabelExprClass; 33535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 33541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 33551237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 335663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 33575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 3358ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner 3359ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}). 3360ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// The StmtExpr contains a single CompoundStmt node, which it evaluates and 3361ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// takes the value of the last subexpression. 3362f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall/// 3363f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall/// A StmtExpr is always an r-value; values "returned" out of a 3364f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall/// StmtExpr will be copied. 3365ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerclass StmtExpr : public Expr { 33665549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *SubStmt; 3367ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner SourceLocation LParenLoc, RParenLoc; 3368ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerpublic: 33692333f7727f97018d6742e1e0938133bcfad967abEli Friedman // FIXME: Does type-dependence need to be computed differently? 3370561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor // FIXME: Do we need to compute instantiation instantiation-dependence for 3371561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor // statements? (ugh!) 3372d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff StmtExpr(CompoundStmt *substmt, QualType T, 3373d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff SourceLocation lp, SourceLocation rp) : 3374f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(StmtExprClass, T, VK_RValue, OK_Ordinary, 3375561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor T->isDependentType(), false, false, false), 33762333f7727f97018d6742e1e0938133bcfad967abEli Friedman SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) { } 33771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 33786a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor /// \brief Build an empty statement expression. 33796a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { } 33806a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor 33815549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); } 33825549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); } 33836a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setSubStmt(CompoundStmt *S) { SubStmt = S; } 33846a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor 338565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return LParenLoc; } 338665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 33871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3388026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getLParenLoc() const { return LParenLoc; } 33896a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setLParenLoc(SourceLocation L) { LParenLoc = L; } 3390026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getRParenLoc() const { return RParenLoc; } 33916a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 33921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3393ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner static bool classof(const Stmt *T) { 33941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == StmtExprClass; 3395ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner } 33961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 33971237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 339863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&SubStmt, &SubStmt+1); } 3399ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner}; 3400ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner 3401d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff 3402d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// ShuffleVectorExpr - clang-specific builtin-in function 3403d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// __builtin_shufflevector. 3404d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// This AST node represents a operator that does a constant 3405d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// shuffle, similar to LLVM's shufflevector instruction. It takes 3406d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// two vectors and a variable number of constant indices, 3407d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// and returns the appropriately shuffled vector. 3408d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanclass ShuffleVectorExpr : public Expr { 3409d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman SourceLocation BuiltinLoc, RParenLoc; 3410d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 3411d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // SubExprs - the list of values passed to the __builtin_shufflevector 3412d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // function. The first two are vectors, and the rest are constant 3413d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // indices. The number of values in this list is always 3414d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // 2+the number of indices in the vector type. 34155549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt **SubExprs; 3416d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman unsigned NumExprs; 3417d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 3418d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanpublic: 341905ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper ShuffleVectorExpr(const ASTContext &C, ArrayRef<Expr*> args, QualType Type, 34203b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer SourceLocation BLoc, SourceLocation RP); 342194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 342294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor /// \brief Build an empty vector-shuffle expression. 34231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ShuffleVectorExpr(EmptyShell Empty) 342494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor : Expr(ShuffleVectorExprClass, Empty), SubExprs(0) { } 342594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 342694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 342794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 34281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 342994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 343094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 343194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 343265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return BuiltinLoc; } 343365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 343465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 3435d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman static bool classof(const Stmt *T) { 34361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ShuffleVectorExprClass; 3437d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 34381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3439d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// getNumSubExprs - Return the size of the SubExprs array. This includes the 3440d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// constant expression, the actual arguments passed in, and the function 3441d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// pointers. 3442d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman unsigned getNumSubExprs() const { return NumExprs; } 34431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3444aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \brief Retrieve the array of expressions. 3445aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Expr **getSubExprs() { return reinterpret_cast<Expr **>(SubExprs); } 3446ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3447d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// getExpr - Return the Expr at the specified index. 3448d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman Expr *getExpr(unsigned Index) { 3449d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman assert((Index < NumExprs) && "Arg access out of range!"); 34505549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Index]); 3451d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 3452d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman const Expr *getExpr(unsigned Index) const { 3453d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman assert((Index < NumExprs) && "Arg access out of range!"); 34545549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Index]); 3455d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 34561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 345705ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper void setExprs(const ASTContext &C, ArrayRef<Expr *> Exprs); 345894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 345905ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper llvm::APSInt getShuffleMaskIdx(const ASTContext &Ctx, unsigned N) const { 3460dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman assert((N < NumExprs - 2) && "Shuffle idx out of range!"); 34616f4f8083931a92f9959168d4430da7ddf9183100Craig Topper return getExpr(N+2)->EvaluateKnownConstInt(Ctx); 3462d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 34631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3464d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // Iterators 346563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 346663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+NumExprs); 346763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 3468d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman}; 3469d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 3470414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel/// ConvertVectorExpr - Clang builtin function __builtin_convertvector 3471414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel/// This AST node provides support for converting a vector type to another 3472414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel/// vector type of the same arity. 3473414a1bdbdaf250e0488589f12865c8961831b65dHal Finkelclass ConvertVectorExpr : public Expr { 3474414a1bdbdaf250e0488589f12865c8961831b65dHal Finkelprivate: 3475414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel Stmt *SrcExpr; 3476414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel TypeSourceInfo *TInfo; 3477414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel SourceLocation BuiltinLoc, RParenLoc; 3478414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel 3479414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel friend class ASTReader; 3480414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel friend class ASTStmtReader; 3481414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel explicit ConvertVectorExpr(EmptyShell Empty) : Expr(ConvertVectorExprClass, Empty) {} 3482414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel 3483414a1bdbdaf250e0488589f12865c8961831b65dHal Finkelpublic: 3484414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel ConvertVectorExpr(Expr* SrcExpr, TypeSourceInfo *TI, QualType DstType, 3485414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel ExprValueKind VK, ExprObjectKind OK, 3486414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel SourceLocation BuiltinLoc, SourceLocation RParenLoc) 3487414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel : Expr(ConvertVectorExprClass, DstType, VK, OK, 3488414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel DstType->isDependentType(), 3489414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel DstType->isDependentType() || SrcExpr->isValueDependent(), 3490414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel (DstType->isInstantiationDependentType() || 3491414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel SrcExpr->isInstantiationDependent()), 3492414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel (DstType->containsUnexpandedParameterPack() || 3493414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel SrcExpr->containsUnexpandedParameterPack())), 3494414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel SrcExpr(SrcExpr), TInfo(TI), BuiltinLoc(BuiltinLoc), RParenLoc(RParenLoc) {} 3495414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel 3496414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel /// getSrcExpr - Return the Expr to be converted. 3497414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel Expr *getSrcExpr() const { return cast<Expr>(SrcExpr); } 3498414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel 3499414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel /// getTypeSourceInfo - Return the destination type. 3500414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel TypeSourceInfo *getTypeSourceInfo() const { 3501414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel return TInfo; 3502414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel } 3503414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel void setTypeSourceInfo(TypeSourceInfo *ti) { 3504414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel TInfo = ti; 3505414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel } 3506414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel 3507414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel /// getBuiltinLoc - Return the location of the __builtin_convertvector token. 3508414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 3509414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel 3510414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel /// getRParenLoc - Return the location of final right parenthesis. 3511414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel SourceLocation getRParenLoc() const { return RParenLoc; } 3512414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel 3513414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel SourceLocation getLocStart() const LLVM_READONLY { return BuiltinLoc; } 3514414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 3515414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel 3516414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel static bool classof(const Stmt *T) { 3517414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel return T->getStmtClass() == ConvertVectorExprClass; 3518414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel } 3519414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel 3520414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel // Iterators 3521414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel child_range children() { return child_range(&SrcExpr, &SrcExpr+1); } 3522414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel}; 3523414a1bdbdaf250e0488589f12865c8961831b65dHal Finkel 3524d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// ChooseExpr - GNU builtin-in function __builtin_choose_expr. 35251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// This AST node is similar to the conditional operator (?:) in C, with 3526d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// the following exceptions: 35277976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the test expression must be a integer constant expression. 35287976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the expression returned acts like the chosen subexpression in every 35297976932a1c256d447316ffac58e9821417725e34Eli Friedman/// visible way: the type is the same as that of the chosen subexpression, 35307976932a1c256d447316ffac58e9821417725e34Eli Friedman/// and all predicates (whether it's an l-value, whether it's an integer 35317976932a1c256d447316ffac58e9821417725e34Eli Friedman/// constant expression, etc.) return the same result as for the chosen 35327976932a1c256d447316ffac58e9821417725e34Eli Friedman/// sub-expression. 3533d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffclass ChooseExpr : public Expr { 35341237c673c07f9d827129ba02720108816abde562Ted Kremenek enum { COND, LHS, RHS, END_EXPR }; 35355549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 3536d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff SourceLocation BuiltinLoc, RParenLoc; 3537a5e660188a3c654cf0c88ed1093b28207e870b2bEli Friedman bool CondIsTrue; 3538d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffpublic: 3539f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, 3540f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType t, ExprValueKind VK, ExprObjectKind OK, 3541a5e660188a3c654cf0c88ed1093b28207e870b2bEli Friedman SourceLocation RP, bool condIsTrue, 3542a5e660188a3c654cf0c88ed1093b28207e870b2bEli Friedman bool TypeDependent, bool ValueDependent) 3543bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(ChooseExprClass, t, VK, OK, TypeDependent, ValueDependent, 3544561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (cond->isInstantiationDependent() || 3545561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor lhs->isInstantiationDependent() || 3546561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhs->isInstantiationDependent()), 3547bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (cond->containsUnexpandedParameterPack() || 3548bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor lhs->containsUnexpandedParameterPack() || 3549bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhs->containsUnexpandedParameterPack())), 3550a5e660188a3c654cf0c88ed1093b28207e870b2bEli Friedman BuiltinLoc(BLoc), RParenLoc(RP), CondIsTrue(condIsTrue) { 35511237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[COND] = cond; 35521237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 35531237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 35541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 35557976932a1c256d447316ffac58e9821417725e34Eli Friedman 355644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor /// \brief Build an empty __builtin_choose_expr. 355744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { } 355844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 35597976932a1c256d447316ffac58e9821417725e34Eli Friedman /// isConditionTrue - Return whether the condition is true (i.e. not 35607976932a1c256d447316ffac58e9821417725e34Eli Friedman /// equal to zero). 3561a5e660188a3c654cf0c88ed1093b28207e870b2bEli Friedman bool isConditionTrue() const { 3562a5e660188a3c654cf0c88ed1093b28207e870b2bEli Friedman assert(!isConditionDependent() && 3563a5e660188a3c654cf0c88ed1093b28207e870b2bEli Friedman "Dependent condition isn't true or false"); 3564a5e660188a3c654cf0c88ed1093b28207e870b2bEli Friedman return CondIsTrue; 3565a5e660188a3c654cf0c88ed1093b28207e870b2bEli Friedman } 3566a5e660188a3c654cf0c88ed1093b28207e870b2bEli Friedman void setIsConditionTrue(bool isTrue) { CondIsTrue = isTrue; } 3567a5e660188a3c654cf0c88ed1093b28207e870b2bEli Friedman 3568a5e660188a3c654cf0c88ed1093b28207e870b2bEli Friedman bool isConditionDependent() const { 3569a5e660188a3c654cf0c88ed1093b28207e870b2bEli Friedman return getCond()->isTypeDependent() || getCond()->isValueDependent(); 3570a5e660188a3c654cf0c88ed1093b28207e870b2bEli Friedman } 35717976932a1c256d447316ffac58e9821417725e34Eli Friedman 35727976932a1c256d447316ffac58e9821417725e34Eli Friedman /// getChosenSubExpr - Return the subexpression chosen according to the 35737976932a1c256d447316ffac58e9821417725e34Eli Friedman /// condition. 3574a5e660188a3c654cf0c88ed1093b28207e870b2bEli Friedman Expr *getChosenSubExpr() const { 3575a5e660188a3c654cf0c88ed1093b28207e870b2bEli Friedman return isConditionTrue() ? getLHS() : getRHS(); 35767976932a1c256d447316ffac58e9821417725e34Eli Friedman } 35777976932a1c256d447316ffac58e9821417725e34Eli Friedman 35785549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 357944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setCond(Expr *E) { SubExprs[COND] = E; } 35805549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 358144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 35825549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 358344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 358444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 358544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 358644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 35871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 358844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 358944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 35901237c673c07f9d827129ba02720108816abde562Ted Kremenek 359165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return BuiltinLoc; } 359265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 359365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 3594d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff static bool classof(const Stmt *T) { 35951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ChooseExprClass; 3596d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff } 35971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 35981237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 359963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 360063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 360163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 3602d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff}; 3603d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff 36042d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// GNUNullExpr - Implements the GNU __null extension, which is a name 36052d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// for a null pointer constant that has integral type (e.g., int or 36062d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// long) and is the same size and alignment as a pointer. The __null 36072d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// extension is typically only used by system headers, which define 36082d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// NULL as __null in C++ rather than using 0 (which is an integer 36092d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// that may not match the size of a pointer). 36102d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorclass GNUNullExpr : public Expr { 36112d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor /// TokenLoc - The location of the __null keyword. 36122d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor SourceLocation TokenLoc; 36132d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 36142d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorpublic: 36151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump GNUNullExpr(QualType Ty, SourceLocation Loc) 3616561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Expr(GNUNullExprClass, Ty, VK_RValue, OK_Ordinary, false, false, false, 3617561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false), 3618f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall TokenLoc(Loc) { } 36192d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 362044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor /// \brief Build an empty GNU __null expression. 362144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { } 362244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 36232d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor /// getTokenLocation - The location of the __null token. 36242d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor SourceLocation getTokenLocation() const { return TokenLoc; } 362544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setTokenLocation(SourceLocation L) { TokenLoc = L; } 36262d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 362765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return TokenLoc; } 362865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return TokenLoc; } 362965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 36302d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor static bool classof(const Stmt *T) { 36311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == GNUNullExprClass; 36322d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } 36331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 36342d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor // Iterators 363563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 36362d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor}; 36372d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 363874626d6ef2e194fcc911e071556660ff331eb4a8Zhongxing Xu/// VAArgExpr, used for the builtin function __builtin_va_arg. 36397c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonclass VAArgExpr : public Expr { 36405549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 36412cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara TypeSourceInfo *TInfo; 36427c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson SourceLocation BuiltinLoc, RParenLoc; 36437c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonpublic: 36442cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara VAArgExpr(SourceLocation BLoc, Expr* e, TypeSourceInfo *TInfo, 36452cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara SourceLocation RPLoc, QualType t) 3646f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(VAArgExprClass, t, VK_RValue, OK_Ordinary, 3647bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor t->isDependentType(), false, 3648561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (TInfo->getType()->isInstantiationDependentType() || 3649561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor e->isInstantiationDependent()), 3650bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (TInfo->getType()->containsUnexpandedParameterPack() || 3651bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor e->containsUnexpandedParameterPack())), 36522cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara Val(e), TInfo(TInfo), 36537c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson BuiltinLoc(BLoc), 36547c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson RParenLoc(RPLoc) { } 36551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 365674626d6ef2e194fcc911e071556660ff331eb4a8Zhongxing Xu /// \brief Create an empty __builtin_va_arg expression. 3657d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor explicit VAArgExpr(EmptyShell Empty) : Expr(VAArgExprClass, Empty) { } 3658d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 36595549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 36605549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 3661d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 3662d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 36632cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara TypeSourceInfo *getWrittenTypeInfo() const { return TInfo; } 36642cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara void setWrittenTypeInfo(TypeSourceInfo *TI) { TInfo = TI; } 36652cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara 3666d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 3667d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 36681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3669d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 3670d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 3671d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 367265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return BuiltinLoc; } 367365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 367465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 36757c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson static bool classof(const Stmt *T) { 36767c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson return T->getStmtClass() == VAArgExprClass; 36777c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson } 36781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 36797c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson // Iterators 368063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Val, &Val+1); } 36817c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson}; 36821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 36834c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @brief Describes an C or C++ initializer list. 36844c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// 36854c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// InitListExpr describes an initializer list, which can be used to 36864c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initialize objects of different types, including 36874c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct/class/union types, arrays, and vectors. For example: 36884c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// 36894c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @code 36904c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct foo x = { 1, { 2, 3 } }; 36914c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @endcode 3692196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 36934c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Prior to semantic analysis, an initializer list will represent the 36944c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer list as written by the user, but will have the 36954c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// placeholder type "void". This initializer list is called the 36964c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// syntactic form of the initializer, and may contain C99 designated 36974c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializers (represented as DesignatedInitExprs), initializations 36984c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// of subobject members without explicit braces, and so on. Clients 36994c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// interested in the original syntax of the initializer list should 37004c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// use the syntactic form of the initializer list. 3701196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 37024c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// After semantic analysis, the initializer list will represent the 37034c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// semantic form of the initializer, where the initializations of all 37044c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// subobjects are made explicit with nested InitListExpr nodes and 37054c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// C99 designators have been eliminated by placing the designated 37064c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializations into the subobject they initialize. Additionally, 37074c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// any "holes" in the initialization, where no initializer has been 37084c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// specified for a particular subobject, will be replaced with 37093498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// implicitly-generated ImplicitValueInitExpr expressions that 37104c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// value-initialize the subobjects. Note, however, that the 37114c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer lists may still have fewer initializers than there are 37124c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// elements to initialize within the object. 3713196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 371423700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara/// After semantic analysis has completed, given an initializer list, 371523700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara/// method isSemanticForm() returns true if and only if this is the 371623700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara/// semantic form of the initializer list (note: the same AST node 371723700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara/// may at the same time be the syntactic form). 37184c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Given the semantic form of the initializer list, one can retrieve 371923700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara/// the syntactic form of that initializer list (when different) 372023700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara/// using method getSyntacticForm(); the method returns null if applied 372123700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara/// to a initializer list which is already in syntactic form. 372223700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara/// Similarly, given the syntactic form (i.e., an initializer list such 372323700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara/// that isSemanticForm() returns false), one can retrieve the semantic 372423700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara/// form using method getSemanticForm(). 372523700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara/// Since many initializer lists have the same syntactic and semantic forms, 372623700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara/// getSyntacticForm() may return NULL, indicating that the current 372723700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara/// semantic initializer list also serves as its syntactic form. 372866b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonclass InitListExpr : public Expr { 3729ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek // FIXME: Eliminate this vector in favor of ASTContext allocation 3730709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek typedef ASTVector<Stmt *> InitExprsTy; 3731709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprsTy InitExprs; 373266b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson SourceLocation LBraceLoc, RBraceLoc; 37331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 373423700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara /// The alternative form of the initializer list (if it exists). 3735063820655db8121f0022a7c51458463c7250324cBenjamin Kramer /// The int part of the pair stores whether this initializer list is 373623700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara /// in semantic form. If not null, the pointer points to: 373723700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara /// - the syntactic form, if this is in semantic form; 373823700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara /// - the semantic form, if this is in syntactic form. 373923700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara llvm::PointerIntPair<InitListExpr *, 1, bool> AltForm; 37404c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 37414423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// \brief Either: 37424423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// If this initializer list initializes an array with more elements than 37434423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// there are initializers in the list, specifies an expression to be used 37444423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// for value initialization of the rest of the elements. 37454423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// Or 37464423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// If this initializer list initializes a union, specifies which 37474423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// field within the union will be initialized. 37484423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis llvm::PointerUnion<Expr *, FieldDecl *> ArrayFillerOrUnionFieldInit; 37490bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor 375066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonpublic: 375105ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper InitListExpr(const ASTContext &C, SourceLocation lbraceloc, 37523b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> initExprs, SourceLocation rbraceloc); 3753d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3754d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Build an empty initializer list. 37552a82ca255b0f99f6201a75ed52b91fc024f6e9cfArgyrios Kyrtzidis explicit InitListExpr(EmptyShell Empty) 37562a82ca255b0f99f6201a75ed52b91fc024f6e9cfArgyrios Kyrtzidis : Expr(InitListExprClass, Empty) { } 37571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3758ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek unsigned getNumInits() const { return InitExprs.size(); } 37591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3760aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \brief Retrieve the set of initializers. 3761aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Expr **getInits() { return reinterpret_cast<Expr **>(InitExprs.data()); } 3762ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 376316c5dea6c2d3e4cf529de9d9b37f6a40441acb2cChris Lattner const Expr *getInit(unsigned Init) const { 3764c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 37654c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return cast_or_null<Expr>(InitExprs[Init]); 376666b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 37671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 376816c5dea6c2d3e4cf529de9d9b37f6a40441acb2cChris Lattner Expr *getInit(unsigned Init) { 3769c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 37704c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return cast_or_null<Expr>(InitExprs[Init]); 377166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 37721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setInit(unsigned Init, Expr *expr) { 3774c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 37759e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff InitExprs[Init] = expr; 37769e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff } 3777c5ae899b4bbf65488445316c63168079177db0edSteve Naroff 3778fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor /// \brief Reserve space for some number of initializers. 377905ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper void reserveInits(const ASTContext &C, unsigned NumInits); 37801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37814c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Specify the number of initializers 37824c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 37834c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// If there are more than @p NumInits initializers, the remaining 37844c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// initializers will be destroyed. If there are fewer than @p 37854c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// NumInits initializers, NULL expressions will be added for the 37864c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// unknown initializers. 378705ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper void resizeInits(const ASTContext &Context, unsigned NumInits); 37884c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 37894c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Updates the initializer at index @p Init with the new 37904c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// expression @p expr, and returns the old expression at that 37914c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// location. 37924c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 37934c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// When @p Init is out of range for this initializer list, the 37944c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// initializer list will be extended with NULL expressions to 3795fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner /// accommodate the new entry. 379605ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper Expr *updateInit(const ASTContext &C, unsigned Init, Expr *expr); 3797c5ae899b4bbf65488445316c63168079177db0edSteve Naroff 37984423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// \brief If this initializer list initializes an array with more elements 37994423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// than there are initializers in the list, specifies an expression to be 38004423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// used for value initialization of the rest of the elements. 38014423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis Expr *getArrayFiller() { 38024423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis return ArrayFillerOrUnionFieldInit.dyn_cast<Expr *>(); 38034423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis } 38048cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne const Expr *getArrayFiller() const { 38058cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne return const_cast<InitListExpr *>(this)->getArrayFiller(); 38068cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne } 38073e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis void setArrayFiller(Expr *filler); 38084423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis 380921f77cd0c3da8a1dbaf6245cae43baf4c0b80ea4Argyrios Kyrtzidis /// \brief Return true if this is an array initializer and its array "filler" 381021f77cd0c3da8a1dbaf6245cae43baf4c0b80ea4Argyrios Kyrtzidis /// has been set. 381121f77cd0c3da8a1dbaf6245cae43baf4c0b80ea4Argyrios Kyrtzidis bool hasArrayFiller() const { return getArrayFiller(); } 381221f77cd0c3da8a1dbaf6245cae43baf4c0b80ea4Argyrios Kyrtzidis 38130bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// \brief If this initializes a union, specifies which field in the 38140bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// union to initialize. 38150bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// 38160bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// Typically, this field is the first named field within the 38170bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// union. However, a designated initializer can specify the 38180bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// initialization of a different field within the union. 38194423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis FieldDecl *getInitializedFieldInUnion() { 38204423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis return ArrayFillerOrUnionFieldInit.dyn_cast<FieldDecl *>(); 38214423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis } 38228cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne const FieldDecl *getInitializedFieldInUnion() const { 38238cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne return const_cast<InitListExpr *>(this)->getInitializedFieldInUnion(); 38248cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne } 38254423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis void setInitializedFieldInUnion(FieldDecl *FD) { 38264e49952712ff9b1b1696cb07580b2b24a3ca99e1Matthew Curtis assert((FD == 0 38274e49952712ff9b1b1696cb07580b2b24a3ca99e1Matthew Curtis || getInitializedFieldInUnion() == 0 38284e49952712ff9b1b1696cb07580b2b24a3ca99e1Matthew Curtis || getInitializedFieldInUnion() == FD) 38294e49952712ff9b1b1696cb07580b2b24a3ca99e1Matthew Curtis && "Only one field of a union may be initialized at a time!"); 38304423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis ArrayFillerOrUnionFieldInit = FD; 38314423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis } 38320bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor 3833c5ae899b4bbf65488445316c63168079177db0edSteve Naroff // Explicit InitListExpr's originate from source code (and have valid source 3834c5ae899b4bbf65488445316c63168079177db0edSteve Naroff // locations). Implicit InitListExpr's are created by the semantic analyzer. 3835b3eef68111ffc220e449be96da1747998c057790Douglas Gregor bool isExplicit() { 3836b3eef68111ffc220e449be96da1747998c057790Douglas Gregor return LBraceLoc.isValid() && RBraceLoc.isValid(); 3837b3eef68111ffc220e449be96da1747998c057790Douglas Gregor } 38381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3839fe587201feaebc69e6d18858bea85c77926b6ecfRichard Smith // Is this an initializer for an array of characters, initialized by a string 3840fe587201feaebc69e6d18858bea85c77926b6ecfRichard Smith // literal or an @encode? 3841fe587201feaebc69e6d18858bea85c77926b6ecfRichard Smith bool isStringLiteralInit() const; 3842fe587201feaebc69e6d18858bea85c77926b6ecfRichard Smith 3843d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor SourceLocation getLBraceLoc() const { return LBraceLoc; } 3844d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setLBraceLoc(SourceLocation Loc) { LBraceLoc = Loc; } 3845d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor SourceLocation getRBraceLoc() const { return RBraceLoc; } 384687fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; } 384787fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor 384823700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara bool isSemanticForm() const { return AltForm.getInt(); } 384923700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara InitListExpr *getSemanticForm() const { 385023700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara return isSemanticForm() ? 0 : AltForm.getPointer(); 385123700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara } 385223700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara InitListExpr *getSyntacticForm() const { 385323700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara return isSemanticForm() ? AltForm.getPointer() : 0; 385423700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara } 385523700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara 385623700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara void setSyntacticForm(InitListExpr *Init) { 385723700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara AltForm.setPointer(Init); 385823700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara AltForm.setInt(true); 385923700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara Init->AltForm.setPointer(this); 386023700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara Init->AltForm.setInt(false); 386123700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara } 38624c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 386332cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl bool hadArrayRangeDesignator() const { 386432cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl return InitListExprBits.HadArrayRangeDesignator != 0; 386532cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl } 38661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void sawArrayRangeDesignator(bool ARD = true) { 386732cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl InitListExprBits.HadArrayRangeDesignator = ARD; 386832cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl } 386932cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl 387065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY; 387165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY; 3872c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek 387366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson static bool classof(const Stmt *T) { 38741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == InitListExprClass; 387566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 38761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 387766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson // Iterators 387863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 387963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall if (InitExprs.empty()) return child_range(); 388063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&InitExprs[0], &InitExprs[0] + InitExprs.size()); 388163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 38821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3883709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek typedef InitExprsTy::iterator iterator; 38848111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu typedef InitExprsTy::const_iterator const_iterator; 3885709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek typedef InitExprsTy::reverse_iterator reverse_iterator; 38868111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu typedef InitExprsTy::const_reverse_iterator const_reverse_iterator; 38871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3888ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek iterator begin() { return InitExprs.begin(); } 38898111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_iterator begin() const { return InitExprs.begin(); } 3890ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek iterator end() { return InitExprs.end(); } 38918111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_iterator end() const { return InitExprs.end(); } 3892ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek reverse_iterator rbegin() { return InitExprs.rbegin(); } 38938111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_reverse_iterator rbegin() const { return InitExprs.rbegin(); } 3894ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek reverse_iterator rend() { return InitExprs.rend(); } 38958111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_reverse_iterator rend() const { return InitExprs.rend(); } 38964423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis 38974423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis friend class ASTStmtReader; 38984423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis friend class ASTStmtWriter; 389966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson}; 390066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson 390105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @brief Represents a C99 designated initializer expression. 390205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// 390305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// A designated initializer expression (C99 6.7.8) contains one or 390405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// more designators (which can be field designators, array 390505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, or GNU array-range designators) followed by an 390605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// expression that initializes the field or element(s) that the 390705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators refer to. For example, given: 39081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 390905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @code 391005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point { 391105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// double x; 391205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// double y; 391305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// }; 391405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 }; 391505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @endcode 391605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// 391705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// The InitListExpr contains three DesignatedInitExprs, the first of 391805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// which covers @c [2].y=1.0. This DesignatedInitExpr will have two 391905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, one array designator for @c [2] followed by one field 3920063820655db8121f0022a7c51458463c7250324cBenjamin Kramer/// designator for @c .y. The initialization expression will be 1.0. 392105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorclass DesignatedInitExpr : public Expr { 3922ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorpublic: 3923ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief Forward declaration of the Designator class. 3924ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor class Designator; 3925ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 3926ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorprivate: 392705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '=' or ':' prior to the actual initializer 392805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// expression. 392905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EqualOrColonLoc; 393005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3931eeae8f072748affce25ab4064982626361293390Douglas Gregor /// Whether this designated initializer used the GNU deprecated 393205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// syntax rather than the C99 '=' syntax. 3933eeae8f072748affce25ab4064982626361293390Douglas Gregor bool GNUSyntax : 1; 393405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 393505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The number of designators in this initializer expression. 393605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators : 15; 393705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 393805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The number of subexpressions of this initializer expression, 393905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// which contains both the initializer and any additional 394005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// expressions used by array and array-range designators. 394105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumSubExprs : 16; 394205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3943a72c352e4950cb487942427550777378b68dc078Benjamin Kramer /// \brief The designators in this designated initialization 3944a72c352e4950cb487942427550777378b68dc078Benjamin Kramer /// expression. 3945a72c352e4950cb487942427550777378b68dc078Benjamin Kramer Designator *Designators; 3946a72c352e4950cb487942427550777378b68dc078Benjamin Kramer 3947ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 394805ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper DesignatedInitExpr(const ASTContext &C, QualType Ty, unsigned NumDesignators, 3949ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Designators, 3950eeae8f072748affce25ab4064982626361293390Douglas Gregor SourceLocation EqualOrColonLoc, bool GNUSyntax, 39513b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> IndexExprs, Expr *Init); 395205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3953d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor explicit DesignatedInitExpr(unsigned NumSubExprs) 3954d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor : Expr(DesignatedInitExprClass, EmptyShell()), 3955a72c352e4950cb487942427550777378b68dc078Benjamin Kramer NumDesignators(0), NumSubExprs(NumSubExprs), Designators(0) { } 3956d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 395705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorpublic: 395805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// A field designator, e.g., ".x". 395905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct FieldDesignator { 396005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// Refers to the field that is being initialized. The low bit 396105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// of this field determines whether this is actually a pointer 396205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When 396305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initially constructed, a field designator will store an 396405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// IdentifierInfo*. After semantic analysis has resolved that 396505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// name, the field designator will instead store a FieldDecl*. 396605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor uintptr_t NameOrField; 39671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 396805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '.' in the designated initializer. 396905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned DotLoc; 39701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 397105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the field name in the designated initializer. 397205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned FieldLoc; 397305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 397405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 397505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". 397605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct ArrayOrRangeDesignator { 397705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// Location of the first index expression within the designated 397805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initializer expression's list of subexpressions. 397905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned Index; 398005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '[' starting the array range designator. 398105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned LBracketLoc; 398205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the ellipsis separating the start and end 398305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// indices. Only valid for GNU array-range designators. 398405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned EllipsisLoc; 398505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the ']' terminating the array range designator. 39861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned RBracketLoc; 398705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 398805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 398905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Represents a single C99 designator. 399005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// 399105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @todo This class is infuriatingly similar to clang::Designator, 399205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// but minor differences (storing indices vs. storing pointers) 399305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// keep us from reusing it. Try harder, later, to rectify these 399405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// differences. 399505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor class Designator { 399605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief The kind of designator this describes. 399705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor enum { 399805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor FieldDesignator, 399905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayDesignator, 400005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayRangeDesignator 400105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } Kind; 400205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 400305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor union { 400405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// A field designator, e.g., ".x". 400505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct FieldDesignator Field; 400605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". 400705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct ArrayOrRangeDesignator ArrayOrRange; 400805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 400905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor friend class DesignatedInitExpr; 401005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 401105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor public: 4012ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designator() {} 4013ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 401405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes a field designator. 40151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc, 40161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation FieldLoc) 401705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(FieldDesignator) { 401805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01; 401905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.DotLoc = DotLoc.getRawEncoding(); 402005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.FieldLoc = FieldLoc.getRawEncoding(); 402105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 402205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 402305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes an array designator. 40241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(unsigned Index, SourceLocation LBracketLoc, 402505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation RBracketLoc) 402605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(ArrayDesignator) { 402705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.Index = Index; 402805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding(); 402905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding(); 403005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding(); 403105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 403205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 403305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes a GNU array-range designator. 40341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(unsigned Index, SourceLocation LBracketLoc, 403505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EllipsisLoc, SourceLocation RBracketLoc) 403605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(ArrayRangeDesignator) { 403705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.Index = Index; 403805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding(); 403905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding(); 404005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding(); 404105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 404205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 404305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isFieldDesignator() const { return Kind == FieldDesignator; } 404405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isArrayDesignator() const { return Kind == ArrayDesignator; } 404505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; } 404605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 4047b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth IdentifierInfo *getFieldName() const; 404805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 4049b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth FieldDecl *getField() const { 405005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 405105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor if (Field.NameOrField & 0x01) 405205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return 0; 405305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor else 405405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return reinterpret_cast<FieldDecl *>(Field.NameOrField); 405505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 405605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 405705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor void setField(FieldDecl *FD) { 405805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 405905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.NameOrField = reinterpret_cast<uintptr_t>(FD); 406005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 406105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 406287f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor SourceLocation getDotLoc() const { 406387f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 406487f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor return SourceLocation::getFromRawEncoding(Field.DotLoc); 406587f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor } 406687f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor 406705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getFieldLoc() const { 406805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 406905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(Field.FieldLoc); 407005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 407105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 407205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getLBracketLoc() const { 407305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 407405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array or array-range designator"); 407505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc); 407605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 407705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 407805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getRBracketLoc() const { 407905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 408005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array or array-range designator"); 408105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc); 408205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 408305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 408405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getEllipsisLoc() const { 408505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == ArrayRangeDesignator && 408605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array-range designator"); 408705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc); 408805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 40894c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 4090d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned getFirstExprIndex() const { 4091d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 4092d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor "Only valid on an array or array-range designator"); 4093d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor return ArrayOrRange.Index; 4094d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 4095d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 409665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { 40974c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor if (Kind == FieldDesignator) 40984c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return getDotLoc().isInvalid()? getFieldLoc() : getDotLoc(); 40994c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor else 41004c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return getLBracketLoc(); 41014c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor } 410265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { 410324f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara return Kind == FieldDesignator ? getFieldLoc() : getRBracketLoc(); 410424f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara } 4105aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 410665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return SourceRange(getLocStart(), getLocEnd()); 410724f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara } 410805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 410905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 411005ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper static DesignatedInitExpr *Create(const ASTContext &C, 411105ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper Designator *Designators, 411205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators, 41133b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> IndexExprs, 411405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EqualOrColonLoc, 4115eeae8f072748affce25ab4064982626361293390Douglas Gregor bool GNUSyntax, Expr *Init); 411605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 411705ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper static DesignatedInitExpr *CreateEmpty(const ASTContext &C, 411805ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper unsigned NumIndexExprs); 4119d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 412005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Returns the number of designators in this initializer. 412105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned size() const { return NumDesignators; } 412205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 412305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor // Iterator access to the designators. 4124b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth typedef Designator *designators_iterator; 4125ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor designators_iterator designators_begin() { return Designators; } 41261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump designators_iterator designators_end() { 41271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return Designators + NumDesignators; 4128ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor } 412905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 4130b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth typedef const Designator *const_designators_iterator; 4131b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth const_designators_iterator designators_begin() const { return Designators; } 4132b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth const_designators_iterator designators_end() const { 4133b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth return Designators + NumDesignators; 4134b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth } 4135b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth 4136cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek typedef std::reverse_iterator<designators_iterator> 4137cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek reverse_designators_iterator; 4138cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek reverse_designators_iterator designators_rbegin() { 4139cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek return reverse_designators_iterator(designators_end()); 4140cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek } 4141cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek reverse_designators_iterator designators_rend() { 4142cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek return reverse_designators_iterator(designators_begin()); 4143cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek } 4144cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek 4145b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth typedef std::reverse_iterator<const_designators_iterator> 4146b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth const_reverse_designators_iterator; 4147b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth const_reverse_designators_iterator designators_rbegin() const { 4148b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth return const_reverse_designators_iterator(designators_end()); 4149b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth } 4150b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth const_reverse_designators_iterator designators_rend() const { 4151b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth return const_reverse_designators_iterator(designators_begin()); 4152b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth } 4153b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth 4154711997184366d584c9c437102cae1e9d9927b986Douglas Gregor Designator *getDesignator(unsigned Idx) { return &designators_begin()[Idx]; } 4155711997184366d584c9c437102cae1e9d9927b986Douglas Gregor 415605ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper void setDesignators(const ASTContext &C, const Designator *Desigs, 4157319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor unsigned NumDesigs); 4158d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 4159d615f88e3c24f91a65c25a4f7e66e0f97b18cc15Dmitri Gribenko Expr *getArrayIndex(const Designator &D) const; 4160d615f88e3c24f91a65c25a4f7e66e0f97b18cc15Dmitri Gribenko Expr *getArrayRangeStart(const Designator &D) const; 4161d615f88e3c24f91a65c25a4f7e66e0f97b18cc15Dmitri Gribenko Expr *getArrayRangeEnd(const Designator &D) const; 416205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 416305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Retrieve the location of the '=' that precedes the 416405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initializer value itself, if present. 416505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; } 4166d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setEqualOrColonLoc(SourceLocation L) { EqualOrColonLoc = L; } 416705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 416805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Determines whether this designated initializer used the 4169eeae8f072748affce25ab4064982626361293390Douglas Gregor /// deprecated GNU syntax for designated initializers. 4170eeae8f072748affce25ab4064982626361293390Douglas Gregor bool usesGNUSyntax() const { return GNUSyntax; } 4171d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setGNUSyntax(bool GNU) { GNUSyntax = GNU; } 417205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 417305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Retrieve the initializer value. 41741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getInit() const { 417505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin()); 417605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 417705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 417805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor void setInit(Expr *init) { 417905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor *child_begin() = init; 418005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 418105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 4182d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Retrieve the total number of subexpressions in this 4183d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// designated initializer expression, including the actual 4184d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// initialized value and any expressions that occur within array 4185d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// and array-range designators. 4186d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned getNumSubExprs() const { return NumSubExprs; } 4187d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 4188d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Expr *getSubExpr(unsigned Idx) { 4189d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert(Idx < NumSubExprs && "Subscript out of range"); 4190d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 4191d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 4192d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor return reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx]; 4193d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 4194d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 4195d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setSubExpr(unsigned Idx, Expr *E) { 4196d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert(Idx < NumSubExprs && "Subscript out of range"); 4197d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 4198d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 4199d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx] = E; 4200d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 4201d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 4202ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief Replaces the designator at index @p Idx with the series 4203ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// of designators in [First, Last). 420405ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper void ExpandDesignator(const ASTContext &C, unsigned Idx, 420505ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper const Designator *First, const Designator *Last); 4206ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 420724f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara SourceRange getDesignatorsSourceRange() const; 420824f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara 420965d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY; 421065d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY; 421105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 421205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor static bool classof(const Stmt *T) { 42131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == DesignatedInitExprClass; 421405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 421505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 421605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor // Iterators 421763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 421863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt **begin = reinterpret_cast<Stmt**>(this + 1); 421963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(begin, begin + NumSubExprs); 422063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 42213498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor}; 42223498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 42233498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// \brief Represents an implicitly-generated value initialization of 42243498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// an object of a given type. 42253498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// 42261a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// Implicit value initializations occur within semantic initializer 42271a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// list expressions (InitListExpr) as placeholders for subobject 42283498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// initializations not explicitly specified by the user. 42291a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// 42301a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// \see InitListExpr 42311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass ImplicitValueInitExpr : public Expr { 42323498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregorpublic: 42331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ImplicitValueInitExpr(QualType ty) 4234f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ImplicitValueInitExprClass, ty, VK_RValue, OK_Ordinary, 4235561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false, ty->isInstantiationDependentType(), false) { } 42363498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 4237d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Construct an empty implicit value initialization. 4238d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor explicit ImplicitValueInitExpr(EmptyShell Empty) 4239d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor : Expr(ImplicitValueInitExprClass, Empty) { } 4240d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 42411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 42423498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return T->getStmtClass() == ImplicitValueInitExprClass; 42433498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor } 42443498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 424565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return SourceLocation(); } 424665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return SourceLocation(); } 42473498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 42483498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor // Iterators 424963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 425005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}; 425105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 42522ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 42532ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanclass ParenListExpr : public Expr { 42542ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman Stmt **Exprs; 42552ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman unsigned NumExprs; 42562ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation LParenLoc, RParenLoc; 42572ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 42582ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanpublic: 425905ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper ParenListExpr(const ASTContext& C, SourceLocation lparenloc, 426005ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper ArrayRef<Expr*> exprs, SourceLocation rparenloc); 42612ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 42622ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman /// \brief Build an empty paren list. 426337bdfe284ad365f753741d1d89c078c148b3f4afArgyrios Kyrtzidis explicit ParenListExpr(EmptyShell Empty) : Expr(ParenListExprClass, Empty) { } 42641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42652ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman unsigned getNumExprs() const { return NumExprs; } 42661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr* getExpr(unsigned Init) const { 42682ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman assert(Init < getNumExprs() && "Initializer access out of range!"); 42692ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return cast_or_null<Expr>(Exprs[Init]); 42702ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 42711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr* getExpr(unsigned Init) { 42732ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman assert(Init < getNumExprs() && "Initializer access out of range!"); 42742ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return cast_or_null<Expr>(Exprs[Init]); 42752ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 42762ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 427783ddad3ab513f5d73698cf9fbeb4ed3f011bc3b9Douglas Gregor Expr **getExprs() { return reinterpret_cast<Expr **>(Exprs); } 42781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42792ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation getLParenLoc() const { return LParenLoc; } 42802ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation getRParenLoc() const { return RParenLoc; } 42812ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 428265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return LParenLoc; } 428365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 428465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 42852ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman static bool classof(const Stmt *T) { 42861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ParenListExprClass; 42872ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 42881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42892ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman // Iterators 429063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 429163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&Exprs[0], &Exprs[0]+NumExprs); 429263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 429337bdfe284ad365f753741d1d89c078c148b3f4afArgyrios Kyrtzidis 429460adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 42953397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl friend class ASTStmtWriter; 42962ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman}; 42972ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 42981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4299ffbe9b9c64ab2e94b9d48ec56e511f75826fc80aBenjamin Kramer/// \brief Represents a C11 generic selection. 4300f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// 4301ffbe9b9c64ab2e94b9d48ec56e511f75826fc80aBenjamin Kramer/// A generic selection (C11 6.5.1.1) contains an unevaluated controlling 4302f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// expression, followed by one or more generic associations. Each generic 4303f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// association specifies a type name and an expression, or "default" and an 4304f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// expression (in which case it is known as a default generic association). 4305f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// The type and value of the generic selection are identical to those of its 4306f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// result expression, which is defined as the expression in the generic 4307f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// association with a type name that is compatible with the type of the 4308f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// controlling expression, or the expression in the default generic association 4309f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// if no types are compatible. For example: 4310f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// 4311f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// @code 4312f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// _Generic(X, double: 1, float: 2, default: 3) 4313f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// @endcode 4314f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// 4315f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// The above expression evaluates to 1 if 1.0 is substituted for X, 2 if 1.0f 4316f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// or 3 if "hello". 4317f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// 4318f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// As an extension, generic selections are allowed in C++, where the following 4319f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// additional semantics apply: 4320f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// 4321f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// Any generic selection whose controlling expression is type-dependent or 4322f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// which names a dependent type in its association list is result-dependent, 4323f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// which means that the choice of result expression is dependent. 4324f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// Result-dependent generic associations are both type- and value-dependent. 4325f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourneclass GenericSelectionExpr : public Expr { 4326f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne enum { CONTROLLING, END_EXPR }; 4327f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo **AssocTypes; 4328f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Stmt **SubExprs; 4329f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned NumAssocs, ResultIndex; 4330f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation GenericLoc, DefaultLoc, RParenLoc; 4331f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4332f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbournepublic: 433305ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper GenericSelectionExpr(const ASTContext &Context, 4334f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation GenericLoc, Expr *ControllingExpr, 43353b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<TypeSourceInfo*> AssocTypes, 43363b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> AssocExprs, 43373b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer SourceLocation DefaultLoc, SourceLocation RParenLoc, 4338f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne bool ContainsUnexpandedParameterPack, 4339f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned ResultIndex); 4340f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4341f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// This constructor is used in the result-dependent case. 434205ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper GenericSelectionExpr(const ASTContext &Context, 4343f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation GenericLoc, Expr *ControllingExpr, 43443b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<TypeSourceInfo*> AssocTypes, 43453b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> AssocExprs, 43463b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer SourceLocation DefaultLoc, SourceLocation RParenLoc, 4347f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne bool ContainsUnexpandedParameterPack); 4348f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4349f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne explicit GenericSelectionExpr(EmptyShell Empty) 4350f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne : Expr(GenericSelectionExprClass, Empty) { } 4351f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4352f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned getNumAssocs() const { return NumAssocs; } 4353f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4354f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation getGenericLoc() const { return GenericLoc; } 4355f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation getDefaultLoc() const { return DefaultLoc; } 4356f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation getRParenLoc() const { return RParenLoc; } 4357f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4358f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const Expr *getAssocExpr(unsigned i) const { 4359f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<Expr>(SubExprs[END_EXPR+i]); 4360f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 4361f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Expr *getAssocExpr(unsigned i) { return cast<Expr>(SubExprs[END_EXPR+i]); } 4362f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4363f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const TypeSourceInfo *getAssocTypeSourceInfo(unsigned i) const { 4364f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return AssocTypes[i]; 4365f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 4366f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo *getAssocTypeSourceInfo(unsigned i) { return AssocTypes[i]; } 4367f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4368f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne QualType getAssocType(unsigned i) const { 4369f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (const TypeSourceInfo *TS = getAssocTypeSourceInfo(i)) 4370f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return TS->getType(); 4371f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne else 4372f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return QualType(); 4373f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 4374f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4375f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const Expr *getControllingExpr() const { 4376f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<Expr>(SubExprs[CONTROLLING]); 4377f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 4378f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Expr *getControllingExpr() { return cast<Expr>(SubExprs[CONTROLLING]); } 4379f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4380f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// Whether this generic selection is result-dependent. 4381f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne bool isResultDependent() const { return ResultIndex == -1U; } 4382f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4383f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// The zero-based index of the result expression's generic association in 4384f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// the generic selection's association list. Defined only if the 4385f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// generic selection is not result-dependent. 4386f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned getResultIndex() const { 4387f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne assert(!isResultDependent() && "Generic selection is result-dependent"); 4388f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return ResultIndex; 4389f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 4390f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4391f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// The generic selection's result expression. Defined only if the 4392f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// generic selection is not result-dependent. 4393f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const Expr *getResultExpr() const { return getAssocExpr(getResultIndex()); } 4394f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Expr *getResultExpr() { return getAssocExpr(getResultIndex()); } 4395f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 439665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return GenericLoc; } 439765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 439865d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 4399f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne static bool classof(const Stmt *T) { 4400f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return T->getStmtClass() == GenericSelectionExprClass; 4401f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 4402f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4403f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne child_range children() { 4404f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return child_range(SubExprs, SubExprs+END_EXPR+NumAssocs); 4405f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 4406f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4407f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne friend class ASTStmtReader; 4408f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne}; 4409f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 44104eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===// 44114eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff// Clang Extensions 44124eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===// 44134eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 4414a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 4415a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// ExtVectorElementExpr - This represents access to specific elements of a 4416a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// vector, and may occur on the left hand side or right hand side. For example 4417a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// the following is legal: "V.xy = V.zw" if V is a 4 element extended vector. 4418a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// 441973525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// Note that the base may have either vector or pointer to vector type, just 442073525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// like a struct field reference. 442173525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// 4422a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerclass ExtVectorElementExpr : public Expr { 4423a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner Stmt *Base; 4424d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor IdentifierInfo *Accessor; 4425a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner SourceLocation AccessorLoc; 4426a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerpublic: 4427f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExtVectorElementExpr(QualType ty, ExprValueKind VK, Expr *base, 4428f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall IdentifierInfo &accessor, SourceLocation loc) 44290943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall : Expr(ExtVectorElementExprClass, ty, VK, 44300943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall (VK == VK_RValue ? OK_Ordinary : OK_VectorComponent), 4431bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->isTypeDependent(), base->isValueDependent(), 4432561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor base->isInstantiationDependent(), 4433bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->containsUnexpandedParameterPack()), 4434d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor Base(base), Accessor(&accessor), AccessorLoc(loc) {} 44351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4436d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor /// \brief Build an empty vector element expression. 4437d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor explicit ExtVectorElementExpr(EmptyShell Empty) 4438d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor : Expr(ExtVectorElementExprClass, Empty) { } 4439d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 4440a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner const Expr *getBase() const { return cast<Expr>(Base); } 4441a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner Expr *getBase() { return cast<Expr>(Base); } 4442d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setBase(Expr *E) { Base = E; } 4443d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 4444d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor IdentifierInfo &getAccessor() const { return *Accessor; } 4445d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setAccessor(IdentifierInfo *II) { Accessor = II; } 4446d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 4447d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getAccessorLoc() const { return AccessorLoc; } 4448d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setAccessorLoc(SourceLocation L) { AccessorLoc = L; } 4449d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 4450a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// getNumElements - Get the number of components being selected. 4451a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner unsigned getNumElements() const; 44521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4453a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// containsDuplicateElements - Return true if any element access is 4454a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// repeated. 4455a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner bool containsDuplicateElements() const; 44561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4457a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// getEncodedElementAccess - Encode the elements accessed into an llvm 4458a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// aggregate Constant of ConstantInt(s). 4459686775deca8b8685eb90801495880e3abdd844c2Chris Lattner void getEncodedElementAccess(SmallVectorImpl<unsigned> &Elts) const; 44601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 446165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { 446265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return getBase()->getLocStart(); 4463a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner } 446465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return AccessorLoc; } 44651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 44662140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner /// isArrow - Return true if the base expression is a pointer to vector, 44672140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner /// return false if the base expression is a vector. 44682140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner bool isArrow() const; 44691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 44701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 44711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ExtVectorElementExprClass; 4472a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner } 44731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4474a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner // Iterators 447563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Base, &Base+1); } 4476a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner}; 4477a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 4478a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 447956ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff/// BlockExpr - Adaptor class for mixing a BlockDecl with expressions. 44809c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff/// ^{ statement-body } or ^(int arg1, float arg2){ statement-body } 44814eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockExpr : public Expr { 448256ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroffprotected: 448356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff BlockDecl *TheBlock; 44844eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic: 4485469a1eb996e1cb0be54f9b210f836afbddcbb2ccJohn McCall BlockExpr(BlockDecl *BD, QualType ty) 4486f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(BlockExprClass, ty, VK_RValue, OK_Ordinary, 4487ec79d877c1998366480d97a7a6c94e15c053edd8Douglas Gregor ty->isDependentType(), ty->isDependentType(), 4488ec79d877c1998366480d97a7a6c94e15c053edd8Douglas Gregor ty->isInstantiationDependentType() || BD->isDependentContext(), 4489561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false), 4490469a1eb996e1cb0be54f9b210f836afbddcbb2ccJohn McCall TheBlock(BD) {} 44919c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 449284af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor /// \brief Build an empty block expression. 449384af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor explicit BlockExpr(EmptyShell Empty) : Expr(BlockExprClass, Empty) { } 449484af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor 4495d5cab5435371b8cc74a9e05ebd40b5995ebad149Anders Carlsson const BlockDecl *getBlockDecl() const { return TheBlock; } 449656ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff BlockDecl *getBlockDecl() { return TheBlock; } 449784af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor void setBlockDecl(BlockDecl *BD) { TheBlock = BD; } 449884af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor 449956ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff // Convenience functions for probing the underlying BlockDecl. 450056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff SourceLocation getCaretLocation() const; 450156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff const Stmt *getBody() const; 450256ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff Stmt *getBody(); 45039c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 450465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return getCaretLocation(); } 450565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return getBody()->getLocEnd(); } 45069c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 450756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff /// getFunctionType - Return the underlying function type for this block. 4508a345edb668380691fc92d4e4aa0a5ffec366ca6aJohn McCall const FunctionProtoType *getFunctionType() const; 450956ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 45101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 45119c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff return T->getStmtClass() == BlockExprClass; 45124eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff } 45131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 45144eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff // Iterators 451563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 45164eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff}; 45171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 451861eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner/// AsTypeExpr - Clang builtin function __builtin_astype [OpenCL 6.2.4.2] 451961eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner/// This AST node provides support for reinterpreting a type to another 452061eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner/// type of the same size. 452160288600131c3f91bfc8ba512df9f2dd588e3308Hal Finkelclass AsTypeExpr : public Expr { 452261eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattnerprivate: 4523379010addb0e84fd0fbc37c829baf658958521bdJohn McCall Stmt *SrcExpr; 452461eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner SourceLocation BuiltinLoc, RParenLoc; 4525379010addb0e84fd0fbc37c829baf658958521bdJohn McCall 4526379010addb0e84fd0fbc37c829baf658958521bdJohn McCall friend class ASTReader; 4527379010addb0e84fd0fbc37c829baf658958521bdJohn McCall friend class ASTStmtReader; 4528379010addb0e84fd0fbc37c829baf658958521bdJohn McCall explicit AsTypeExpr(EmptyShell Empty) : Expr(AsTypeExprClass, Empty) {} 4529ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 453061eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattnerpublic: 453161eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner AsTypeExpr(Expr* SrcExpr, QualType DstType, 453261eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner ExprValueKind VK, ExprObjectKind OK, 453361eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner SourceLocation BuiltinLoc, SourceLocation RParenLoc) 4534ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie : Expr(AsTypeExprClass, DstType, VK, OK, 4535561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor DstType->isDependentType(), 4536561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor DstType->isDependentType() || SrcExpr->isValueDependent(), 4537561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (DstType->isInstantiationDependentType() || 4538561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor SrcExpr->isInstantiationDependent()), 4539561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (DstType->containsUnexpandedParameterPack() || 4540561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor SrcExpr->containsUnexpandedParameterPack())), 4541379010addb0e84fd0fbc37c829baf658958521bdJohn McCall SrcExpr(SrcExpr), BuiltinLoc(BuiltinLoc), RParenLoc(RParenLoc) {} 4542ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 454361eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner /// getSrcExpr - Return the Expr to be converted. 4544379010addb0e84fd0fbc37c829baf658958521bdJohn McCall Expr *getSrcExpr() const { return cast<Expr>(SrcExpr); } 4545379010addb0e84fd0fbc37c829baf658958521bdJohn McCall 4546379010addb0e84fd0fbc37c829baf658958521bdJohn McCall /// getBuiltinLoc - Return the location of the __builtin_astype token. 4547379010addb0e84fd0fbc37c829baf658958521bdJohn McCall SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 4548379010addb0e84fd0fbc37c829baf658958521bdJohn McCall 4549379010addb0e84fd0fbc37c829baf658958521bdJohn McCall /// getRParenLoc - Return the location of final right parenthesis. 4550379010addb0e84fd0fbc37c829baf658958521bdJohn McCall SourceLocation getRParenLoc() const { return RParenLoc; } 4551ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 455265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return BuiltinLoc; } 455365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 4554ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 455561eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner static bool classof(const Stmt *T) { 4556ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return T->getStmtClass() == AsTypeExprClass; 455761eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner } 4558ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 455961eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner // Iterators 4560379010addb0e84fd0fbc37c829baf658958521bdJohn McCall child_range children() { return child_range(&SrcExpr, &SrcExpr+1); } 456161eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner}; 4562276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 45634b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// PseudoObjectExpr - An expression which accesses a pseudo-object 45644b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// l-value. A pseudo-object is an abstract object, accesses to which 45654b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// are translated to calls. The pseudo-object expression has a 45664b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// syntactic form, which shows how the expression was actually 45674b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// written in the source code, and a semantic form, which is a series 45684b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// of expressions to be executed in order which detail how the 45694b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// operation is actually evaluated. Optionally, one of the semantic 45704b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// forms may also provide a result value for the expression. 45714b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// 45724b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// If any of the semantic-form expressions is an OpaqueValueExpr, 45734b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// that OVE is required to have a source expression, and it is bound 45744b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// to the result of that source expression. Such OVEs may appear 45754b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// only in subsequent semantic-form expressions and as 45764b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// sub-expressions of the syntactic form. 45774b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// 45784b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// PseudoObjectExpr should be used only when an operation can be 45794b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// usefully described in terms of fairly simple rewrite rules on 45804b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// objects and functions that are meant to be used by end-developers. 45814b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// For example, under the Itanium ABI, dynamic casts are implemented 45824b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// as a call to a runtime function called __dynamic_cast; using this 45834b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// class to describe that would be inappropriate because that call is 45844b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// not really part of the user-visible semantics, and instead the 45854b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// cast is properly reflected in the AST and IR-generation has been 45864b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// taught to generate the call as necessary. In contrast, an 45874b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// Objective-C property access is semantically defined to be 45884b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// equivalent to a particular message send, and this is very much 45894b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// part of the user model. The name of this class encourages this 45904b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// modelling design. 45914b9c2d235fb9449e249d74f48ecfec601650de93John McCallclass PseudoObjectExpr : public Expr { 45924b9c2d235fb9449e249d74f48ecfec601650de93John McCall // PseudoObjectExprBits.NumSubExprs - The number of sub-expressions. 45934b9c2d235fb9449e249d74f48ecfec601650de93John McCall // Always at least two, because the first sub-expression is the 45944b9c2d235fb9449e249d74f48ecfec601650de93John McCall // syntactic form. 45954b9c2d235fb9449e249d74f48ecfec601650de93John McCall 45964b9c2d235fb9449e249d74f48ecfec601650de93John McCall // PseudoObjectExprBits.ResultIndex - The index of the 45974b9c2d235fb9449e249d74f48ecfec601650de93John McCall // sub-expression holding the result. 0 means the result is void, 45984b9c2d235fb9449e249d74f48ecfec601650de93John McCall // which is unambiguous because it's the index of the syntactic 45994b9c2d235fb9449e249d74f48ecfec601650de93John McCall // form. Note that this is therefore 1 higher than the value passed 46004b9c2d235fb9449e249d74f48ecfec601650de93John McCall // in to Create, which is an index within the semantic forms. 46014b9c2d235fb9449e249d74f48ecfec601650de93John McCall // Note also that ASTStmtWriter assumes this encoding. 46024b9c2d235fb9449e249d74f48ecfec601650de93John McCall 46034b9c2d235fb9449e249d74f48ecfec601650de93John McCall Expr **getSubExprsBuffer() { return reinterpret_cast<Expr**>(this + 1); } 46044b9c2d235fb9449e249d74f48ecfec601650de93John McCall const Expr * const *getSubExprsBuffer() const { 46054b9c2d235fb9449e249d74f48ecfec601650de93John McCall return reinterpret_cast<const Expr * const *>(this + 1); 46064b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 46074b9c2d235fb9449e249d74f48ecfec601650de93John McCall 46084b9c2d235fb9449e249d74f48ecfec601650de93John McCall friend class ASTStmtReader; 46094b9c2d235fb9449e249d74f48ecfec601650de93John McCall 46104b9c2d235fb9449e249d74f48ecfec601650de93John McCall PseudoObjectExpr(QualType type, ExprValueKind VK, 46114b9c2d235fb9449e249d74f48ecfec601650de93John McCall Expr *syntactic, ArrayRef<Expr*> semantic, 46124b9c2d235fb9449e249d74f48ecfec601650de93John McCall unsigned resultIndex); 46134b9c2d235fb9449e249d74f48ecfec601650de93John McCall 46144b9c2d235fb9449e249d74f48ecfec601650de93John McCall PseudoObjectExpr(EmptyShell shell, unsigned numSemanticExprs); 46154b9c2d235fb9449e249d74f48ecfec601650de93John McCall 46164b9c2d235fb9449e249d74f48ecfec601650de93John McCall unsigned getNumSubExprs() const { 46174b9c2d235fb9449e249d74f48ecfec601650de93John McCall return PseudoObjectExprBits.NumSubExprs; 46184b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 46194b9c2d235fb9449e249d74f48ecfec601650de93John McCall 46204b9c2d235fb9449e249d74f48ecfec601650de93John McCallpublic: 46214b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// NoResult - A value for the result index indicating that there is 46224b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// no semantic result. 4623877e6a6fb05660a3cc3fc24bcbef4df5e4702423Reid Kleckner enum LLVM_ENUM_INT_TYPE(unsigned) { NoResult = ~0U }; 46244b9c2d235fb9449e249d74f48ecfec601650de93John McCall 462505ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper static PseudoObjectExpr *Create(const ASTContext &Context, Expr *syntactic, 46264b9c2d235fb9449e249d74f48ecfec601650de93John McCall ArrayRef<Expr*> semantic, 46274b9c2d235fb9449e249d74f48ecfec601650de93John McCall unsigned resultIndex); 46284b9c2d235fb9449e249d74f48ecfec601650de93John McCall 462905ed1a0587edcf3b8ee84a67d8c8ca76753d1fc1Craig Topper static PseudoObjectExpr *Create(const ASTContext &Context, EmptyShell shell, 46304b9c2d235fb9449e249d74f48ecfec601650de93John McCall unsigned numSemanticExprs); 46314b9c2d235fb9449e249d74f48ecfec601650de93John McCall 46324b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// Return the syntactic form of this expression, i.e. the 46334b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// expression it actually looks like. Likely to be expressed in 46344b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// terms of OpaqueValueExprs bound in the semantic form. 46354b9c2d235fb9449e249d74f48ecfec601650de93John McCall Expr *getSyntacticForm() { return getSubExprsBuffer()[0]; } 46364b9c2d235fb9449e249d74f48ecfec601650de93John McCall const Expr *getSyntacticForm() const { return getSubExprsBuffer()[0]; } 46374b9c2d235fb9449e249d74f48ecfec601650de93John McCall 46384b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// Return the index of the result-bearing expression into the semantics 46394b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// expressions, or PseudoObjectExpr::NoResult if there is none. 46404b9c2d235fb9449e249d74f48ecfec601650de93John McCall unsigned getResultExprIndex() const { 46414b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (PseudoObjectExprBits.ResultIndex == 0) return NoResult; 46424b9c2d235fb9449e249d74f48ecfec601650de93John McCall return PseudoObjectExprBits.ResultIndex - 1; 46434b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 46444b9c2d235fb9449e249d74f48ecfec601650de93John McCall 46454b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// Return the result-bearing expression, or null if there is none. 46464b9c2d235fb9449e249d74f48ecfec601650de93John McCall Expr *getResultExpr() { 46474b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (PseudoObjectExprBits.ResultIndex == 0) 46484b9c2d235fb9449e249d74f48ecfec601650de93John McCall return 0; 46494b9c2d235fb9449e249d74f48ecfec601650de93John McCall return getSubExprsBuffer()[PseudoObjectExprBits.ResultIndex]; 46504b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 46514b9c2d235fb9449e249d74f48ecfec601650de93John McCall const Expr *getResultExpr() const { 46524b9c2d235fb9449e249d74f48ecfec601650de93John McCall return const_cast<PseudoObjectExpr*>(this)->getResultExpr(); 46534b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 46544b9c2d235fb9449e249d74f48ecfec601650de93John McCall 46554b9c2d235fb9449e249d74f48ecfec601650de93John McCall unsigned getNumSemanticExprs() const { return getNumSubExprs() - 1; } 46564b9c2d235fb9449e249d74f48ecfec601650de93John McCall 46574b9c2d235fb9449e249d74f48ecfec601650de93John McCall typedef Expr * const *semantics_iterator; 46584b9c2d235fb9449e249d74f48ecfec601650de93John McCall typedef const Expr * const *const_semantics_iterator; 46594b9c2d235fb9449e249d74f48ecfec601650de93John McCall semantics_iterator semantics_begin() { 46604b9c2d235fb9449e249d74f48ecfec601650de93John McCall return getSubExprsBuffer() + 1; 46614b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 46624b9c2d235fb9449e249d74f48ecfec601650de93John McCall const_semantics_iterator semantics_begin() const { 46634b9c2d235fb9449e249d74f48ecfec601650de93John McCall return getSubExprsBuffer() + 1; 46644b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 46654b9c2d235fb9449e249d74f48ecfec601650de93John McCall semantics_iterator semantics_end() { 46664b9c2d235fb9449e249d74f48ecfec601650de93John McCall return getSubExprsBuffer() + getNumSubExprs(); 46674b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 46684b9c2d235fb9449e249d74f48ecfec601650de93John McCall const_semantics_iterator semantics_end() const { 46694b9c2d235fb9449e249d74f48ecfec601650de93John McCall return getSubExprsBuffer() + getNumSubExprs(); 46704b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 46714b9c2d235fb9449e249d74f48ecfec601650de93John McCall Expr *getSemanticExpr(unsigned index) { 46724b9c2d235fb9449e249d74f48ecfec601650de93John McCall assert(index + 1 < getNumSubExprs()); 46734b9c2d235fb9449e249d74f48ecfec601650de93John McCall return getSubExprsBuffer()[index + 1]; 46744b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 46754b9c2d235fb9449e249d74f48ecfec601650de93John McCall const Expr *getSemanticExpr(unsigned index) const { 46764b9c2d235fb9449e249d74f48ecfec601650de93John McCall return const_cast<PseudoObjectExpr*>(this)->getSemanticExpr(index); 46774b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 46784b9c2d235fb9449e249d74f48ecfec601650de93John McCall 46794f311183be3d923da9fbe8702c453688b4c426a9Daniel Dunbar SourceLocation getExprLoc() const LLVM_READONLY { 46804b9c2d235fb9449e249d74f48ecfec601650de93John McCall return getSyntacticForm()->getExprLoc(); 46814b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 468265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 468365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { 468465d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return getSyntacticForm()->getLocStart(); 468565d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen } 468665d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { 468765d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen return getSyntacticForm()->getLocEnd(); 46884b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 46894b9c2d235fb9449e249d74f48ecfec601650de93John McCall 46904b9c2d235fb9449e249d74f48ecfec601650de93John McCall child_range children() { 46914b9c2d235fb9449e249d74f48ecfec601650de93John McCall Stmt **cs = reinterpret_cast<Stmt**>(getSubExprsBuffer()); 46924b9c2d235fb9449e249d74f48ecfec601650de93John McCall return child_range(cs, cs + getNumSubExprs()); 46934b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 46944b9c2d235fb9449e249d74f48ecfec601650de93John McCall 46954b9c2d235fb9449e249d74f48ecfec601650de93John McCall static bool classof(const Stmt *T) { 46964b9c2d235fb9449e249d74f48ecfec601650de93John McCall return T->getStmtClass() == PseudoObjectExprClass; 46974b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 46984b9c2d235fb9449e249d74f48ecfec601650de93John McCall}; 46994b9c2d235fb9449e249d74f48ecfec601650de93John McCall 4700276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman/// AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, 4701276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman/// __atomic_load, __atomic_store, and __atomic_compare_exchange_*, for the 4702ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith/// similarly-named C++11 instructions, and __c11 variants for <stdatomic.h>. 4703ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith/// All of these instructions take one primary pointer and at least one memory 4704ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith/// order. 4705276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedmanclass AtomicExpr : public Expr { 4706276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedmanpublic: 4707ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith enum AtomicOp { 4708ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith#define BUILTIN(ID, TYPE, ATTRS) 4709ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith#define ATOMIC_BUILTIN(ID, TYPE, ATTRS) AO ## ID, 4710ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith#include "clang/Basic/Builtins.def" 4711ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith // Avoid trailing comma 4712ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith BI_First = 0 4713ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith }; 4714ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith 4715276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedmanprivate: 4716ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith enum { PTR, ORDER, VAL1, ORDER_FAIL, VAL2, WEAK, END_EXPR }; 4717276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman Stmt* SubExprs[END_EXPR]; 4718276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman unsigned NumSubExprs; 4719276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman SourceLocation BuiltinLoc, RParenLoc; 4720276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman AtomicOp Op; 4721276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4722e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith friend class ASTStmtReader; 4723e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith 4724276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedmanpublic: 47253b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer AtomicExpr(SourceLocation BLoc, ArrayRef<Expr*> args, QualType t, 4726dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman AtomicOp op, SourceLocation RP); 4727276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4728e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith /// \brief Determine the number of arguments the specified atomic builtin 4729e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith /// should have. 4730e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith static unsigned getNumSubExprs(AtomicOp Op); 4731e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith 4732276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman /// \brief Build an empty AtomicExpr. 4733276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman explicit AtomicExpr(EmptyShell Empty) : Expr(AtomicExprClass, Empty) { } 4734276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4735276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman Expr *getPtr() const { 4736276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return cast<Expr>(SubExprs[PTR]); 4737276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4738276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman Expr *getOrder() const { 4739276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return cast<Expr>(SubExprs[ORDER]); 4740276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4741276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman Expr *getVal1() const { 4742ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith if (Op == AO__c11_atomic_init) 47437a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall return cast<Expr>(SubExprs[ORDER]); 4744ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith assert(NumSubExprs > VAL1); 4745276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return cast<Expr>(SubExprs[VAL1]); 4746276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4747276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman Expr *getOrderFail() const { 4748ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith assert(NumSubExprs > ORDER_FAIL); 4749276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return cast<Expr>(SubExprs[ORDER_FAIL]); 4750276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4751276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman Expr *getVal2() const { 4752ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith if (Op == AO__atomic_exchange) 4753ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith return cast<Expr>(SubExprs[ORDER_FAIL]); 4754ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith assert(NumSubExprs > VAL2); 4755276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return cast<Expr>(SubExprs[VAL2]); 4756276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4757ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith Expr *getWeak() const { 4758ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith assert(NumSubExprs > WEAK); 4759ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith return cast<Expr>(SubExprs[WEAK]); 4760ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith } 4761276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4762276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman AtomicOp getOp() const { return Op; } 4763276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman unsigned getNumSubExprs() { return NumSubExprs; } 4764276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4765dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman Expr **getSubExprs() { return reinterpret_cast<Expr **>(SubExprs); } 4766dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman 4767276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman bool isVolatile() const { 4768276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return getPtr()->getType()->getPointeeType().isVolatileQualified(); 4769276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4770276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4771276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman bool isCmpXChg() const { 4772ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith return getOp() == AO__c11_atomic_compare_exchange_strong || 4773ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith getOp() == AO__c11_atomic_compare_exchange_weak || 4774ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith getOp() == AO__atomic_compare_exchange || 4775ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith getOp() == AO__atomic_compare_exchange_n; 4776276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4777276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4778276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 4779276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman SourceLocation getRParenLoc() const { return RParenLoc; } 4780276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 478165d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocStart() const LLVM_READONLY { return BuiltinLoc; } 478265d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } 478365d78312ce026092cb6e7b1d4d06f05e18d02aa0Erik Verbruggen 4784276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman static bool classof(const Stmt *T) { 4785276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return T->getStmtClass() == AtomicExprClass; 4786276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4787276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4788276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman // Iterators 4789276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman child_range children() { 4790276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return child_range(SubExprs, SubExprs+NumSubExprs); 4791276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4792276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman}; 47935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 47945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 47955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 4796