Expr.h revision 9852f58f50b4fc20914fbce5b4454135a42343f4
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" 18478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer#include "clang/AST/Decl.h" 195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Stmt.h" 205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Type.h" 21161755a09898c95d21bfff33707da9ca41cd53c5John McCall#include "clang/AST/DeclAccessPair.h" 225baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall#include "clang/AST/OperationKinds.h" 23709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek#include "clang/AST/ASTVector.h" 2471a7605977113c795edd44fcbd2302ad49506653Argyrios Kyrtzidis#include "clang/AST/TemplateBase.h" 25f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne#include "clang/Basic/TypeTraits.h" 265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/APSInt.h" 27525a05093a4816af961fe2bc6b8a81c17e2e26c2Chris Lattner#include "llvm/ADT/APFloat.h" 283b8d116703db8018f855cbb4733ace426422623bNate Begeman#include "llvm/ADT/SmallVector.h" 29b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar#include "llvm/ADT/StringRef.h" 30aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar#include "llvm/Support/Compiler.h" 31403ba3522d1b1c97ae5fad81c1a2c4b3a754e1c1Nick Lewycky#include <cctype> 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 union { 640a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola struct { 650a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola const CastExpr *BasePath; 660a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola const CXXRecordDecl *DerivedClass; 670a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola } DerivedToBase; 680a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola 690a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola FieldDecl *Field; 700a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola 710a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola struct { 720a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola const MemberPointerType *MPT; 730a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola Expr *RHS; 740a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola } Ptr; 750a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola }; 760a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola 770a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola SubobjectAdjustment(const CastExpr *BasePath, 780a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola const CXXRecordDecl *DerivedClass) 790a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola : Kind(DerivedToBaseAdjustment) { 800a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola DerivedToBase.BasePath = BasePath; 810a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola DerivedToBase.DerivedClass = DerivedClass; 820a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola } 830a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola 840a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola SubobjectAdjustment(FieldDecl *Field) 850a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola : Kind(FieldAdjustment) { 860a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola this->Field = Field; 870a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola } 880a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola 890a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola SubobjectAdjustment(const MemberPointerType *MPT, Expr *RHS) 900a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola : Kind(MemberPointerAdjustment) { 910a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola this->Ptr.MPT = MPT; 920a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola this->Ptr.RHS = RHS; 930a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola } 940a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola}; 950a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola 965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Expr - This represents one expression. Note that Expr's are subclasses of 975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Stmt. This allows an expression to be transparently used any place a Stmt 985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is required. 995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 1005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Expr : public Stmt { 1015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType TR; 102898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1038e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCallprotected: 104f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(StmtClass SC, QualType T, ExprValueKind VK, ExprObjectKind OK, 105ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie bool TD, bool VD, bool ID, bool ContainsUnexpandedParameterPack) 106ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie : Stmt(SC) 107561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor { 1088e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.TypeDependent = TD; 1098e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.ValueDependent = VD; 110561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = ID; 111f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprBits.ValueKind = VK; 112f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprBits.ObjectKind = OK; 113bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack; 114898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor setType(T); 115898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 116898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1170b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Construct an empty expression. 1180b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor explicit Expr(StmtClass SC, EmptyShell) : Stmt(SC) { } 1190b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 1201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 121f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor QualType getType() const { return TR; } 1221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setType(QualType t) { 1239d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // In C++, the type of an expression is always adjusted so that it 1249d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // will not have reference type an expression will never have 1259d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // reference type (C++ [expr]p6). Use 1269d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // QualType::getNonReferenceType() to retrieve the non-reference 1279d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // type. Additionally, inspect Expr::isLvalue to determine whether 1289d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // an expression that is adjusted in this manner should be 1299d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // considered an lvalue. 130905d11d53aeb6b26744f44fedc2b2820c7a62df6Douglas Gregor assert((t.isNull() || !t->isReferenceType()) && 1318320aaaa01d931aa234fc3bce05b399ef41898d5Daniel Dunbar "Expressions can't have reference type"); 132f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor 1331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TR = t; 1349d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor } 13577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 136898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isValueDependent - Determines whether this expression is 137898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// value-dependent (C++ [temp.dep.constexpr]). For example, the 138898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// array bound of "Chars" in the following example is 1391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// value-dependent. 140898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @code 141898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// template<int Size, char (&Chars)[Size]> struct meta_string; 142898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @endcode 1438e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall bool isValueDependent() const { return ExprBits.ValueDependent; } 144898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1450b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Set whether this expression is value-dependent or not. 146ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie void setValueDependent(bool VD) { 147ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie ExprBits.ValueDependent = VD; 148561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (VD) 149561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 150561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 1510b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 152898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isTypeDependent - Determines whether this expression is 153898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// type-dependent (C++ [temp.dep.expr]), which means that its type 154898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// could change from one template instantiation to the next. For 155898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// example, the expressions "x" and "x + y" are type-dependent in 156898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// the following code, but "y" is not type-dependent: 157898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @code 1581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// template<typename T> 159898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// void add(T x, int y) { 160898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// x + y; 161898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// } 162898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @endcode 1638e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall bool isTypeDependent() const { return ExprBits.TypeDependent; } 164898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1650b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Set whether this expression is type-dependent or not. 166ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie void setTypeDependent(bool TD) { 167ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie ExprBits.TypeDependent = TD; 168561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (TD) 169561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 170561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 171561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 172561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// \brief Whether this expression is instantiation-dependent, meaning that 173561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// it depends in some way on a template parameter, even if neither its type 174561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// nor (constant) value can change due to the template instantiation. 175561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// 176561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// In the following example, the expression \c sizeof(sizeof(T() + T())) is 177561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// instantiation-dependent (since it involves a template parameter \c T), but 178561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// is neither type- nor value-dependent, since the type of the inner 179561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// \c sizeof is known (\c std::size_t) and therefore the size of the outer 180561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// \c sizeof is known. 181561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// 182561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// \code 183561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// template<typename T> 184561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// void f(T x, T y) { 185561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// sizeof(sizeof(T() + T()); 186561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// } 187561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// \endcode 188561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// 189ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie bool isInstantiationDependent() const { 190ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return ExprBits.InstantiationDependent; 191561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 192ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 193561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// \brief Set whether this expression is instantiation-dependent or not. 194ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie void setInstantiationDependent(bool ID) { 195561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = ID; 196561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 1970b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 198d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \brief Whether this expression contains an unexpanded parameter 199d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// pack (for C++0x variadic templates). 200d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// 201d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// Given the following function template: 202d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// 203d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \code 204d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// template<typename F, typename ...Types> 205d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// void forward(const F &f, Types &&...args) { 206d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// f(static_cast<Types&&>(args)...); 207d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// } 208d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \endcode 209d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// 210d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// The expressions \c args and \c static_cast<Types&&>(args) both 211d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// contain parameter packs. 212ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie bool containsUnexpandedParameterPack() const { 213ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return ExprBits.ContainsUnexpandedParameterPack; 214d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor } 215d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 216bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /// \brief Set the bit that describes whether this expression 217bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /// contains an unexpanded parameter pack. 218bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor void setContainsUnexpandedParameterPack(bool PP = true) { 219bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = PP; 220bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor } 221bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 2225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getExprLoc - Return the preferred location for the arrow when diagnosing 2235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// a problem with a generic expression. 2244f311183be3d923da9fbe8702c453688b4c426a9Daniel Dunbar SourceLocation getExprLoc() const LLVM_READONLY; 2251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 226026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// isUnusedResultAWarning - Return true if this immediate expression should 227a6115068cde719142eb394db88612c185cabd05bEli Friedman /// be warned about if the result is unused. If so, fill in expr, location, 228a6115068cde719142eb394db88612c185cabd05bEli Friedman /// and ranges with expr to warn on and source locations/ranges appropriate 229a6115068cde719142eb394db88612c185cabd05bEli Friedman /// for a warning. 230a6115068cde719142eb394db88612c185cabd05bEli Friedman bool isUnusedResultAWarning(const Expr *&WarnExpr, SourceLocation &Loc, 231a6115068cde719142eb394db88612c185cabd05bEli Friedman SourceRange &R1, SourceRange &R2, 232a6115068cde719142eb394db88612c185cabd05bEli Friedman ASTContext &Ctx) const; 2331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2347eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// isLValue - True if this expression is an "l-value" according to 2357eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// the rules of the current language. C and C++ give somewhat 2367eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// different rules for this concept, but in general, the result of 2377eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// an l-value expression identifies a specific object whereas the 2387eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// result of an r-value expression is a value detached from any 2397eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// specific storage. 2405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 2417eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// C++0x divides the concept of "r-value" into pure r-values 2427eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// ("pr-values") and so-called expiring values ("x-values"), which 2437eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// identify specific objects that can be safely cannibalized for 2447eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// their resources. This is an unfortunate abuse of terminology on 2457eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// the part of the C++ committee. In Clang, when we say "r-value", 2467eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// we generally mean a pr-value. 2477eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall bool isLValue() const { return getValueKind() == VK_LValue; } 2487eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall bool isRValue() const { return getValueKind() == VK_RValue; } 2497eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall bool isXValue() const { return getValueKind() == VK_XValue; } 2507eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall bool isGLValue() const { return getValueKind() != VK_RValue; } 2517eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall 2527eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall enum LValueClassification { 2535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_Valid, 2545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_NotObjectType, 2555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_IncompleteVoidType, 256fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff LV_DuplicateVectorComponents, 25786f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor LV_InvalidExpression, 258077f490d0a514dcc448475f33f799934252b85a7Fariborz Jahanian LV_InvalidMessageExpression, 2592514a309204341798f96912ce7a90841bea59727Fariborz Jahanian LV_MemberFunction, 260e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian LV_SubObjCPropertySetting, 26136d02af300a207242f0486b4255420d8be796b21Richard Smith LV_ClassTemporary, 26236d02af300a207242f0486b4255420d8be796b21Richard Smith LV_ArrayTemporary 2635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 2647eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// Reasons why an expression might not be an l-value. 2657eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall LValueClassification ClassifyLValue(ASTContext &Ctx) const; 26653202857c60214d80950a975e6e52aebf30bd16aEli Friedman 2675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum isModifiableLvalueResult { 2685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_Valid, 2695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_NotObjectType, 2705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_IncompleteVoidType, 271fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff MLV_DuplicateVectorComponents, 2725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_InvalidExpression, 273ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner MLV_LValueCast, // Specialized form of MLV_InvalidExpression. 2745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_IncompleteType, 2755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_ConstQualified, 2764f6a7d7ead09b439216c32f2de806a998aeb222aSteve Naroff MLV_ArrayType, 277ba8d2d684e74a20bef03828c21c991d222c7e9e5Fariborz Jahanian MLV_ReadonlyProperty, 27886f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor MLV_NoSetterProperty, 2792514a309204341798f96912ce7a90841bea59727Fariborz Jahanian MLV_MemberFunction, 280e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian MLV_SubObjCPropertySetting, 281077f490d0a514dcc448475f33f799934252b85a7Fariborz Jahanian MLV_InvalidMessageExpression, 28236d02af300a207242f0486b4255420d8be796b21Richard Smith MLV_ClassTemporary, 28336d02af300a207242f0486b4255420d8be796b21Richard Smith MLV_ArrayTemporary 2845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 285ad0fe03b897f9486191e75c8d90c3ffa9b4fd6a5Ted Kremenek /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type, 286ad0fe03b897f9486191e75c8d90c3ffa9b4fd6a5Ted Kremenek /// does not have an incomplete type, does not have a const-qualified type, 287ad0fe03b897f9486191e75c8d90c3ffa9b4fd6a5Ted Kremenek /// and if it is a structure or union, does not have any member (including, 288ad0fe03b897f9486191e75c8d90c3ffa9b4fd6a5Ted Kremenek /// recursively, any member or element of all contained aggregates or unions) 289ad0fe03b897f9486191e75c8d90c3ffa9b4fd6a5Ted Kremenek /// with a const-qualified type. 290ad0fe03b897f9486191e75c8d90c3ffa9b4fd6a5Ted Kremenek /// 291ad0fe03b897f9486191e75c8d90c3ffa9b4fd6a5Ted Kremenek /// \param Loc [in,out] - A source location which *may* be filled 292ad0fe03b897f9486191e75c8d90c3ffa9b4fd6a5Ted Kremenek /// in with the location of the expression making this a 293ad0fe03b897f9486191e75c8d90c3ffa9b4fd6a5Ted Kremenek /// non-modifiable lvalue, if specified. 29444e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx, 29544e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar SourceLocation *Loc = 0) const; 2961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2972111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \brief The return type of classify(). Represents the C++0x expression 2982111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// taxonomy. 2992111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl class Classification { 3002111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl public: 3012111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \brief The various classification results. Most of these mean prvalue. 3022111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl enum Kinds { 3032111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_LValue, 3042111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_XValue, 3052111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_Function, // Functions cannot be lvalues in C. 3062111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_Void, // Void cannot be an lvalue in C. 3071c860d5640e8eebb11a5d515a761242b66761b0bPeter Collingbourne CL_AddressableVoid, // Void expression whose address can be taken in C. 3082111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_DuplicateVectorComponents, // A vector shuffle with dupes. 3092111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_MemberFunction, // An expression referring to a member function 3102111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_SubObjCPropertySetting, 31136d02af300a207242f0486b4255420d8be796b21Richard Smith CL_ClassTemporary, // A temporary of class type, or subobject thereof. 31236d02af300a207242f0486b4255420d8be796b21Richard Smith CL_ArrayTemporary, // A temporary of array type. 313077f490d0a514dcc448475f33f799934252b85a7Fariborz Jahanian CL_ObjCMessageRValue, // ObjC message is an rvalue 3142111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_PRValue // A prvalue for any other reason, of any other type 3152111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl }; 3162111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \brief The results of modification testing. 3172111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl enum ModifiableType { 3182111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_Untested, // testModifiable was false. 3192111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_Modifiable, 3202111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_RValue, // Not modifiable because it's an rvalue 3212111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_Function, // Not modifiable because it's a function; C++ only 3222111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_LValueCast, // Same as CM_RValue, but indicates GCC cast-as-lvalue ext 3232111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_NoSetterProperty,// Implicit assignment to ObjC property without setter 3242111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_ConstQualified, 3252111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_ArrayType, 3262111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_IncompleteType 3272111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl }; 3282111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 3292111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl private: 3302111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl friend class Expr; 3312111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 3322111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl unsigned short Kind; 3332111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl unsigned short Modifiable; 3342111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 3352111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl explicit Classification(Kinds k, ModifiableType m) 3362111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl : Kind(k), Modifiable(m) 3372111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl {} 3382111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 3392111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl public: 3402111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification() {} 3412111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 3422111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Kinds getKind() const { return static_cast<Kinds>(Kind); } 3432111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl ModifiableType getModifiable() const { 3442111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl assert(Modifiable != CM_Untested && "Did not test for modifiability."); 3452111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl return static_cast<ModifiableType>(Modifiable); 3462111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl } 3472111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isLValue() const { return Kind == CL_LValue; } 3482111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isXValue() const { return Kind == CL_XValue; } 3492111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isGLValue() const { return Kind <= CL_XValue; } 3502111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isPRValue() const { return Kind >= CL_Function; } 3512111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isRValue() const { return Kind >= CL_XValue; } 3522111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isModifiable() const { return getModifiable() == CM_Modifiable; } 353ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3542c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor /// \brief Create a simple, modifiably lvalue 3552c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor static Classification makeSimpleLValue() { 3562c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor return Classification(CL_LValue, CM_Modifiable); 3572c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor } 358ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3592111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl }; 360369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// \brief Classify - Classify this expression according to the C++0x 3612111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// expression taxonomy. 3622111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// 3632111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// C++0x defines ([basic.lval]) a new taxonomy of expressions to replace the 3642111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// old lvalue vs rvalue. This function determines the type of expression this 3652111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// is. There are three expression types: 3662111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// - lvalues are classical lvalues as in C++03. 3672111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// - prvalues are equivalent to rvalues in C++03. 3682111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// - xvalues are expressions yielding unnamed rvalue references, e.g. a 3692111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// function returning an rvalue reference. 3702111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// lvalues and xvalues are collectively referred to as glvalues, while 3712111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// prvalues and xvalues together form rvalues. 3722111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification Classify(ASTContext &Ctx) const { 3732111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl return ClassifyImpl(Ctx, 0); 3742111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl } 3752111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 376369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// \brief ClassifyModifiable - Classify this expression according to the 3772111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// C++0x expression taxonomy, and see if it is valid on the left side 3782111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// of an assignment. 3792111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// 3802111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// This function extends classify in that it also tests whether the 3812111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// expression is modifiable (C99 6.3.2.1p1). 3822111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \param Loc A source location that might be filled with a relevant location 3832111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// if the expression is not modifiable. 3842111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification ClassifyModifiable(ASTContext &Ctx, SourceLocation &Loc) const{ 3852111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl return ClassifyImpl(Ctx, &Loc); 3862111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl } 3872111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 388f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// getValueKindForType - Given a formal return or parameter type, 389f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// give its value kind. 390f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall static ExprValueKind getValueKindForType(QualType T) { 391f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall if (const ReferenceType *RT = T->getAs<ReferenceType>()) 3920943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall return (isa<LValueReferenceType>(RT) 3930943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall ? VK_LValue 3940943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall : (RT->getPointeeType()->isFunctionType() 3950943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall ? VK_LValue : VK_XValue)); 396f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall return VK_RValue; 397f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall } 398f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 399f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// getValueKind - The value kind that this expression produces. 400f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind getValueKind() const { 401f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall return static_cast<ExprValueKind>(ExprBits.ValueKind); 402f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall } 403f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 404f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// getObjectKind - The object kind that this expression produces. 405f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// Object kinds are meaningful only for expressions that yield an 406f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// l-value or x-value. 407f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprObjectKind getObjectKind() const { 408f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall return static_cast<ExprObjectKind>(ExprBits.ObjectKind); 409f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall } 410f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 41156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall bool isOrdinaryOrBitFieldObject() const { 41256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall ExprObjectKind OK = getObjectKind(); 41356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return (OK == OK_Ordinary || OK == OK_BitField); 41456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 41556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 416f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// setValueKind - Set the value kind produced by this expression. 417f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall void setValueKind(ExprValueKind Cat) { ExprBits.ValueKind = Cat; } 418f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 419f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// setObjectKind - Set the object kind produced by this expression. 420f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall void setObjectKind(ExprObjectKind Cat) { ExprBits.ObjectKind = Cat; } 421f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 4222111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redlprivate: 4232111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification ClassifyImpl(ASTContext &Ctx, SourceLocation *Loc) const; 4242111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 4252111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redlpublic: 4262111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 42733bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor /// \brief If this expression refers to a bit-field, retrieve the 42833bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor /// declaration of that bit-field. 42933bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor FieldDecl *getBitField(); 4305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 43138d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson const FieldDecl *getBitField() const { 43238d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson return const_cast<Expr*>(this)->getBitField(); 43338d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson } 4341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 435f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall /// \brief If this expression is an l-value for an Objective C 436f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall /// property, find the underlying property reference expression. 437f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall const ObjCPropertyRefExpr *getObjCProperty() const; 438f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall 439bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks /// \brief Check if this expression is the ObjC 'self' implicit parameter. 440bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks bool isObjCSelfExpr() const; 441bbff82f302a1dd67589f65912351978905f0c5a7Anna Zaks 442093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson /// \brief Returns whether this expression refers to a vector element. 443093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson bool refersToVectorElement() const; 4444919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall 4454919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall /// \brief Returns whether this expression has a placeholder type. 4464919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall bool hasPlaceholderType() const { 4474919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall return getType()->isPlaceholderType(); 4484919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall } 4494919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall 4504919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall /// \brief Returns whether this expression has a specific placeholder type. 4514919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall bool hasPlaceholderType(BuiltinType::Kind K) const { 45285def357129b6cdfd69a66ad0e6994506418a2a9John McCall assert(BuiltinType::isPlaceholderTypeKind(K)); 4534919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall if (const BuiltinType *BT = dyn_cast<BuiltinType>(getType())) 4544919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall return BT->getKind() == K; 4554919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall return false; 4564919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall } 457ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 4582b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// isKnownToHaveBooleanValue - Return true if this is an integer expression 4592b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// that is known to return 0 or 1. This happens for _Bool/bool expressions 4602b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// but also int expressions which are produced by things like comparisons in 4612b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// C. 4622b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner bool isKnownToHaveBooleanValue() const; 463ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 4645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isIntegerConstantExpr - Return true if this expression is a valid integer 4655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// constant expression, and, if so, return its value in Result. If not a 4665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// valid i-c-e, return false and fill in Loc (if specified) with the location 4675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// of the invalid expression. 468282e7e66748cc6dd14d6f7f2cb52e5373c531e61Richard Smith /// 469282e7e66748cc6dd14d6f7f2cb52e5373c531e61Richard Smith /// Note: This does not perform the implicit conversions required by C++11 470282e7e66748cc6dd14d6f7f2cb52e5373c531e61Richard Smith /// [expr.const]p5. 471590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx, 472590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner SourceLocation *Loc = 0, 4735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isEvaluated = true) const; 474f48fdb0937e67f691393f9ffdf75653e5128ea13Richard Smith bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const; 4750e35b4ecee380c2b4c33d75da6bc2fb6f6bc7df3Richard Smith 47670488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith /// isCXX98IntegralConstantExpr - Return true if this expression is an 47770488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith /// integral constant expression in C++98. Can only be used in C++. 47870488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith bool isCXX98IntegralConstantExpr(ASTContext &Ctx) const; 47970488e201ccd94d4bb1ef0868cc13cca2b7d4ff6Richard Smith 4804c3fc9b38d3723f73e4ded594cebf38c76f91d93Richard Smith /// isCXX11ConstantExpr - Return true if this expression is a constant 4814c3fc9b38d3723f73e4ded594cebf38c76f91d93Richard Smith /// expression in C++11. Can only be used in C++. 482282e7e66748cc6dd14d6f7f2cb52e5373c531e61Richard Smith /// 483282e7e66748cc6dd14d6f7f2cb52e5373c531e61Richard Smith /// Note: This does not perform the implicit conversions required by C++11 484282e7e66748cc6dd14d6f7f2cb52e5373c531e61Richard Smith /// [expr.const]p5. 4854c3fc9b38d3723f73e4ded594cebf38c76f91d93Richard Smith bool isCXX11ConstantExpr(ASTContext &Ctx, APValue *Result = 0, 4864c3fc9b38d3723f73e4ded594cebf38c76f91d93Richard Smith SourceLocation *Loc = 0) const; 4874c3fc9b38d3723f73e4ded594cebf38c76f91d93Richard Smith 488745f5147e065900267c85a5568785a1991d4838fRichard Smith /// isPotentialConstantExpr - Return true if this function's definition 489745f5147e065900267c85a5568785a1991d4838fRichard Smith /// might be usable in a constant expression in C++11, if it were marked 490745f5147e065900267c85a5568785a1991d4838fRichard Smith /// constexpr. Return false if the function can never produce a constant 491745f5147e065900267c85a5568785a1991d4838fRichard Smith /// expression, along with diagnostics describing why not. 492745f5147e065900267c85a5568785a1991d4838fRichard Smith static bool isPotentialConstantExpr(const FunctionDecl *FD, 493745f5147e065900267c85a5568785a1991d4838fRichard Smith llvm::SmallVectorImpl< 494745f5147e065900267c85a5568785a1991d4838fRichard Smith PartialDiagnosticAt> &Diags); 495745f5147e065900267c85a5568785a1991d4838fRichard Smith 4960e35b4ecee380c2b4c33d75da6bc2fb6f6bc7df3Richard Smith /// isConstantInitializer - Returns true if this expression can be emitted to 4970e35b4ecee380c2b4c33d75da6bc2fb6f6bc7df3Richard Smith /// IR as a constant, and thus can be used as a constant initializer in C. 4984204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall bool isConstantInitializer(ASTContext &Ctx, bool ForRef) const; 4991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5001e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith /// EvalStatus is a struct with detailed info about an evaluation in progress. 5011e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith struct EvalStatus { 50294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// HasSideEffects - Whether the evaluated expression has side effects. 50394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// For example, (f() && 0) can be folded, but it still has side effects. 50494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson bool HasSideEffects; 5051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 506dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith /// Diag - If this is non-null, it will be filled in with a stack of notes 507dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith /// indicating why evaluation failed (or why it failed to produce a constant 508dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith /// expression). 509dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith /// If the expression is unfoldable, the notes will indicate why it's not 510dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith /// foldable. If the expression is foldable, but not a constant expression, 511dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith /// the notes will describes why it isn't a constant expression. If the 512dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith /// expression *is* a constant expression, no notes will be produced. 513dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith llvm::SmallVectorImpl<PartialDiagnosticAt> *Diag; 514dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith 515dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith EvalStatus() : HasSideEffects(false), Diag(0) {} 516e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara 517e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara // hasSideEffects - Return true if the evaluated expression has 518e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara // side effects. 519e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara bool hasSideEffects() const { 520e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara return HasSideEffects; 521e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara } 52294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson }; 52394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson 5241e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith /// EvalResult is a struct with detailed info about an evaluated expression. 5251e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith struct EvalResult : EvalStatus { 5261e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith /// Val - This is the value the expression can be folded to. 5271e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith APValue Val; 5281e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith 5291e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith // isGlobalLValue - Return true if the evaluated lvalue expression 5301e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith // is global. 5311e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith bool isGlobalLValue() const; 5321e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith }; 5331e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith 53451f4708c00110940ca3f337961915f2ca1668375Richard Smith /// EvaluateAsRValue - Return true if this is a constant which we can fold to 53551f4708c00110940ca3f337961915f2ca1668375Richard Smith /// an rvalue using any crazy technique (that has nothing to do with language 53651f4708c00110940ca3f337961915f2ca1668375Richard Smith /// standards) that we want to, even if the expression has side-effects. If 53751f4708c00110940ca3f337961915f2ca1668375Richard Smith /// this function returns true, it returns the folded constant in Result. If 53851f4708c00110940ca3f337961915f2ca1668375Richard Smith /// the expression is a glvalue, an lvalue-to-rvalue conversion will be 53951f4708c00110940ca3f337961915f2ca1668375Richard Smith /// applied. 54051f4708c00110940ca3f337961915f2ca1668375Richard Smith bool EvaluateAsRValue(EvalResult &Result, const ASTContext &Ctx) const; 5415b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson 542cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall /// EvaluateAsBooleanCondition - Return true if this is a constant 543cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall /// which we we can fold and convert to a boolean condition using 544a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith /// any crazy technique that we want to, even if the expression has 545a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith /// side-effects. 5464ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool EvaluateAsBooleanCondition(bool &Result, const ASTContext &Ctx) const; 547cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall 54880d4b55db94db2172a04617d1a80feca6bbcea5cRichard Smith enum SideEffectsKind { SE_NoSideEffects, SE_AllowSideEffects }; 54980d4b55db94db2172a04617d1a80feca6bbcea5cRichard Smith 550a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith /// EvaluateAsInt - Return true if this is a constant which we can fold and 55180d4b55db94db2172a04617d1a80feca6bbcea5cRichard Smith /// convert to an integer, using any crazy technique that we want to. 55280d4b55db94db2172a04617d1a80feca6bbcea5cRichard Smith bool EvaluateAsInt(llvm::APSInt &Result, const ASTContext &Ctx, 55380d4b55db94db2172a04617d1a80feca6bbcea5cRichard Smith SideEffectsKind AllowSideEffects = SE_NoSideEffects) const; 554a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith 55551f4708c00110940ca3f337961915f2ca1668375Richard Smith /// isEvaluatable - Call EvaluateAsRValue to see if this expression can be 55651f4708c00110940ca3f337961915f2ca1668375Richard Smith /// constant folded without side-effects, but discard the result. 5574ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool isEvaluatable(const ASTContext &Ctx) const; 558c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson 5596ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian /// HasSideEffects - This routine returns true for all those expressions 56060b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith /// which have any effect other than producing a value. Example is a function 56160b70388e43d146d968a1cc0705b30cb2d7263feRichard Smith /// call, volatile variable read, or throwing an exception. 5624ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool HasSideEffects(const ASTContext &Ctx) const; 56351f4708c00110940ca3f337961915f2ca1668375Richard Smith 56425d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor /// \brief Determine whether this expression involves a call to any function 56525d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor /// that is not trivial. 56625d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor bool hasNonTrivialCall(ASTContext &Ctx); 56725d0a0f67d9e949ffbfc57bf487012f5cbfd886eDouglas Gregor 56851f4708c00110940ca3f337961915f2ca1668375Richard Smith /// EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded 56951f4708c00110940ca3f337961915f2ca1668375Richard Smith /// integer. This must be called on an expression that constant folds to an 57051f4708c00110940ca3f337961915f2ca1668375Richard Smith /// integer. 571a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx) const; 57251fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson 57351f4708c00110940ca3f337961915f2ca1668375Richard Smith /// EvaluateAsLValue - Evaluate an expression to see if we can fold it to an 57451f4708c00110940ca3f337961915f2ca1668375Richard Smith /// lvalue with link time known address, with no side-effects. 5754ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx) const; 5761b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson 577099e7f647ccda915513f2b2ec53352dc756082d3Richard Smith /// EvaluateAsInitializer - Evaluate an expression as if it were the 578099e7f647ccda915513f2b2ec53352dc756082d3Richard Smith /// initializer of the given declaration. Returns true if the initializer 579099e7f647ccda915513f2b2ec53352dc756082d3Richard Smith /// can be folded to a constant, and produces any relevant notes. In C++11, 580099e7f647ccda915513f2b2ec53352dc756082d3Richard Smith /// notes will be produced if the expression is not a constant expression. 581099e7f647ccda915513f2b2ec53352dc756082d3Richard Smith bool EvaluateAsInitializer(APValue &Result, const ASTContext &Ctx, 582099e7f647ccda915513f2b2ec53352dc756082d3Richard Smith const VarDecl *VD, 583099e7f647ccda915513f2b2ec53352dc756082d3Richard Smith llvm::SmallVectorImpl<PartialDiagnosticAt> &Notes) const; 584099e7f647ccda915513f2b2ec53352dc756082d3Richard Smith 58582214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Enumeration used to describe the kind of Null pointer constant 58682214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// returned from \c isNullPointerConstant(). 58782214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth enum NullPointerConstantKind { 58882214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Expression is not a Null pointer constant. 58982214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NPCK_NotNull = 0, 59082214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 59150800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie /// \brief Expression is a Null pointer constant built from a zero integer 59250800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie /// expression that is not a simple, possibly parenthesized, zero literal. 59350800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie /// C++ Core Issue 903 will classify these expressions as "not pointers" 59450800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie /// once it is adopted. 59550800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie /// http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#903 59650800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie NPCK_ZeroExpression, 59750800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie 59850800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie /// \brief Expression is a Null pointer constant built from a literal zero. 59950800fc551ac6b8a95cca662223e7f061bbd169aDavid Blaikie NPCK_ZeroLiteral, 60082214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 60182214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Expression is a C++0X nullptr. 60282214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NPCK_CXX0X_nullptr, 60382214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 60482214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Expression is a GNU-style __null constant. 60582214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NPCK_GNUNull 60682214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth }; 60782214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 608ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Enumeration used to describe how \c isNullPointerConstant() 609ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// should cope with value-dependent expressions. 610ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor enum NullPointerConstantValueDependence { 611ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that the expression should never be value-dependent. 612ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_NeverValueDependent = 0, 613ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 614ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that a value-dependent expression of integral or 615ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// dependent type should be considered a null pointer constant. 616ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_ValueDependentIsNull, 617ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 618ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that a value-dependent expression should be considered 619ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// to never be a null pointer constant. 620ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_ValueDependentIsNotNull 621ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor }; 622ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 62382214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to 62482214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// a Null pointer constant. The return value can further distinguish the 62582214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// kind of NULL pointer constant that was detected. 62682214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NullPointerConstantKind isNullPointerConstant( 62782214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth ASTContext &Ctx, 62882214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NullPointerConstantValueDependence NPC) const; 629efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson 63044baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian /// isOBJCGCCandidate - Return true if this expression may be used in a read/ 6311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// write barrier. 632102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian bool isOBJCGCCandidate(ASTContext &Ctx) const; 6331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 63411ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis /// \brief Returns true if this expression is a bound member function. 63511ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis bool isBoundMemberFunction(ASTContext &Ctx) const; 63611ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis 637864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// \brief Given an expression of bound-member type, find the type 638864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// of the member. Returns null if this is an *overloaded* bound 639864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// member expression. 640864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall static QualType findBoundMemberType(const Expr *expr); 641864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 64291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall /// IgnoreImpCasts - Skip past any implicit casts which might 64391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall /// surround this expression. Only skips ImplicitCastExprs. 644f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar Expr *IgnoreImpCasts() LLVM_READONLY; 64591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 6467e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall /// IgnoreImplicit - Skip past any implicit AST nodes which might 6477e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall /// surround this expression. 648f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar Expr *IgnoreImplicit() LLVM_READONLY { 649f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar return cast<Expr>(Stmt::IgnoreImplicit()); 650f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar } 6517e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall 652132283beb1b032e0acd09bdfb45dceadeea0026eJordan Rose const Expr *IgnoreImplicit() const LLVM_READONLY { 653132283beb1b032e0acd09bdfb45dceadeea0026eJordan Rose return const_cast<Expr*>(this)->IgnoreImplicit(); 654132283beb1b032e0acd09bdfb45dceadeea0026eJordan Rose } 655132283beb1b032e0acd09bdfb45dceadeea0026eJordan Rose 6564e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// IgnoreParens - Ignore parentheses. If this Expr is a ParenExpr, return 6571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// its subexpression. If that subexpression is also a ParenExpr, 6584e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// then this method recursively returns its subexpression, and so forth. 6594e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// Otherwise, the method returns the current Expr. 660f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar Expr *IgnoreParens() LLVM_READONLY; 66156f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner 66256f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner /// IgnoreParenCasts - Ignore parentheses and casts. Strip off any ParenExpr 66327c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor /// or CastExprs, returning their operand. 664f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar Expr *IgnoreParenCasts() LLVM_READONLY; 6651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 666ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// IgnoreParenImpCasts - Ignore parentheses and implicit casts. Strip off 667ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// any ParenExpr or ImplicitCastExprs, returning their operand. 668f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar Expr *IgnoreParenImpCasts() LLVM_READONLY; 6692fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall 6702f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg /// IgnoreConversionOperator - Ignore conversion operator. If this Expr is a 6712f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg /// call to a conversion operator, return the argument. 672f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar Expr *IgnoreConversionOperator() LLVM_READONLY; 6732f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg 674f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar const Expr *IgnoreConversionOperator() const LLVM_READONLY { 6752f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg return const_cast<Expr*>(this)->IgnoreConversionOperator(); 6762f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg } 6772f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg 678f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar const Expr *IgnoreParenImpCasts() const LLVM_READONLY { 6794d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek return const_cast<Expr*>(this)->IgnoreParenImpCasts(); 6804d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek } 681ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 682f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall /// Ignore parentheses and lvalue casts. Strip off any ParenExpr and 683f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall /// CastExprs that represent lvalue casts, returning their operand. 684f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar Expr *IgnoreParenLValueCasts() LLVM_READONLY; 685ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 686f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar const Expr *IgnoreParenLValueCasts() const LLVM_READONLY { 687f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall return const_cast<Expr*>(this)->IgnoreParenLValueCasts(); 688f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 6894d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek 690ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the 691ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// value (including ptr->int casts of the same size). Strip off any 692ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// ParenExpr or CastExprs, returning their operand. 693f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar Expr *IgnoreParenNoopCasts(ASTContext &Ctx) LLVM_READONLY; 6941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 695632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola /// Ignore parentheses and derived-to-base casts. 696632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola Expr *ignoreParenBaseCasts() LLVM_READONLY; 697632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola 698632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola const Expr *ignoreParenBaseCasts() const LLVM_READONLY { 699632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola return const_cast<Expr*>(this)->ignoreParenBaseCasts(); 700632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola } 701632fbaa22fbed7c090eb83775731bfff786c2198Rafael Espindola 7026eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// \brief Determine whether this expression is a default function argument. 7036eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// 7046eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// Default arguments are implicitly generated in the abstract syntax tree 705ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// by semantic analysis for function calls, object constructions, etc. in 7066eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// C++. Default arguments are represented by \c CXXDefaultArgExpr nodes; 7076eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// this routine also looks through any implicit casts to determine whether 7086eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// the expression is a default argument. 7096eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor bool isDefaultArgument() const; 710ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 711558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall /// \brief Determine whether the result of this expression is a 712558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall /// temporary object of the given class type. 713558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const; 7142f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 71575e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor /// \brief Whether this expression is an implicit reference to 'this' in C++. 71675e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor bool isImplicitCXXThis() const; 71791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 718f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar const Expr *IgnoreImpCasts() const LLVM_READONLY { 71991a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall return const_cast<Expr*>(this)->IgnoreImpCasts(); 72091a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall } 721f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar const Expr *IgnoreParens() const LLVM_READONLY { 7224e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek return const_cast<Expr*>(this)->IgnoreParens(); 7234e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek } 724f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar const Expr *IgnoreParenCasts() const LLVM_READONLY { 72556f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner return const_cast<Expr*>(this)->IgnoreParenCasts(); 72656f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner } 727f9ff5876289d5228c299b57416a62c8c3b848287Daniel Dunbar const Expr *IgnoreParenNoopCasts(ASTContext &Ctx) const LLVM_READONLY { 728ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner return const_cast<Expr*>(this)->IgnoreParenNoopCasts(Ctx); 729ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 7301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 73113a140caba448a66ffcc5ff0d32a87d6e4f4ad3fAhmed Charles static bool hasAnyTypeDependentArguments(llvm::ArrayRef<Expr *> Exprs); 732898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 7338d852e35adb46e0799538dfc9c80d44f27cd3597Rafael Espindola /// \brief For an expression of class type or pointer to class type, 7348d852e35adb46e0799538dfc9c80d44f27cd3597Rafael Espindola /// return the most derived class decl the expression is known to refer to. 7350b4fe503ef00d9f8ea330850d3e3b303e9c7c876Rafael Espindola /// 7360b4fe503ef00d9f8ea330850d3e3b303e9c7c876Rafael Espindola /// If this expression is a cast, this method looks through it to find the 7378d852e35adb46e0799538dfc9c80d44f27cd3597Rafael Espindola /// most derived decl that can be inferred from the expression. 7388d852e35adb46e0799538dfc9c80d44f27cd3597Rafael Espindola /// This is valid because derived-to-base conversions have undefined 7398d852e35adb46e0799538dfc9c80d44f27cd3597Rafael Espindola /// behavior if the object isn't dynamically of the derived type. 7408d852e35adb46e0799538dfc9c80d44f27cd3597Rafael Espindola const CXXRecordDecl *getBestDynamicClassType() const; 7410b4fe503ef00d9f8ea330850d3e3b303e9c7c876Rafael Espindola 7420a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola /// Walk outwards from an expression we want to bind a reference to and 7430a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola /// find the expression whose lifetime needs to be extended. Record 7440a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola /// the adjustments needed along the path. 7450a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola const Expr * 7460a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola skipRValueSubobjectAdjustments( 7470a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola SmallVectorImpl<SubobjectAdjustment> &Adjustments) const; 7480a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola 7490a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola /// Skip irrelevant expressions to find what should be materialize for 7500a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola /// binding with a reference. 7510a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola const Expr * 7520a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola findMaterializedTemporary(const MaterializeTemporaryExpr *&MTE) const; 7530a7dd835184343ec9149277b668ecdc5d49fe8b0Rafael Espindola 7541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 7555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() >= firstExprConstant && 7561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump T->getStmtClass() <= lastExprConstant; 7575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7615549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek//===----------------------------------------------------------------------===// 7625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Primary Expressions. 7635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 7645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 76556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// OpaqueValueExpr - An expression referring to an opaque object of a 76656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// fixed type and value class. These don't correspond to concrete 76756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// syntax; instead they're used to express operations (usually copy 76856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// operations) on values whose source is generally obvious from 76956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// context. 77056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass OpaqueValueExpr : public Expr { 77156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall friend class ASTStmtReader; 77256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *SourceExpr; 77356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation Loc; 774ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 77556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallpublic: 776ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie OpaqueValueExpr(SourceLocation Loc, QualType T, ExprValueKind VK, 77797df54e0c075bc8d6a869597e771dad0c11a2180Douglas Gregor ExprObjectKind OK = OK_Ordinary, 77897df54e0c075bc8d6a869597e771dad0c11a2180Douglas Gregor Expr *SourceExpr = 0) 77956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : Expr(OpaqueValueExprClass, T, VK, OK, 78097df54e0c075bc8d6a869597e771dad0c11a2180Douglas Gregor T->isDependentType(), 78197df54e0c075bc8d6a869597e771dad0c11a2180Douglas Gregor T->isDependentType() || 78297df54e0c075bc8d6a869597e771dad0c11a2180Douglas Gregor (SourceExpr && SourceExpr->isValueDependent()), 783561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor T->isInstantiationDependentType(), 784ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie false), 78597df54e0c075bc8d6a869597e771dad0c11a2180Douglas Gregor SourceExpr(SourceExpr), Loc(Loc) { 78656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 78756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 78856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// Given an expression which invokes a copy constructor --- i.e. a 78956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// CXXConstructExpr, possibly wrapped in an ExprWithCleanups --- 79056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// find the OpaqueValueExpr that's the source of the construction. 79156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static const OpaqueValueExpr *findInCopyConstruct(const Expr *expr); 79256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 79356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall explicit OpaqueValueExpr(EmptyShell Empty) 79456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : Expr(OpaqueValueExprClass, Empty) { } 79556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 79656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief Retrieve the location of this expression. 79756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation getLocation() const { return Loc; } 798ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 799aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 80056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (SourceExpr) return SourceExpr->getSourceRange(); 80156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return Loc; 80256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 8034f311183be3d923da9fbe8702c453688b4c426a9Daniel Dunbar SourceLocation getExprLoc() const LLVM_READONLY { 80456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (SourceExpr) return SourceExpr->getExprLoc(); 80556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return Loc; 80656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 80756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 80856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall child_range children() { return child_range(); } 80956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 81056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// The source expression of an opaque value expression is the 81156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// expression which originally generated the value. This is 81256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// provided as a convenience for analyses that don't wish to 81356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// precisely model the execution behavior of the program. 81456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// 81556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// The source expression is typically set when building the 81656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// expression which binds the opaque value expression in the first 81756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// place. 81856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getSourceExpr() const { return SourceExpr; } 81956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 82056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const Stmt *T) { 82156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return T->getStmtClass() == OpaqueValueExprClass; 82256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 82356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall}; 82456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 825cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// \brief A reference to a declared variable, function, enum, etc. 826cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// [C99 6.5.1p2] 827cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// 828cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// This encodes all the information about how a declaration is referenced 829cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// within an expression. 830cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// 831cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// There are several optional constructs attached to DeclRefExprs only when 832cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// they apply in order to conserve memory. These are laid out past the end of 833cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// the object, and flags in the DeclRefExprBitfield track whether they exist: 834cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// 835cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// DeclRefExprBits.HasQualifier: 836cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// Specifies when this declaration reference expression has a C++ 837cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// nested-name-specifier. 8383aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth/// DeclRefExprBits.HasFoundDecl: 8393aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth/// Specifies when this declaration reference expression has a record of 8403aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth/// a NamedDecl (different from the referenced ValueDecl) which was found 8413aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth/// during name lookup and/or overload resolution. 842e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara/// DeclRefExprBits.HasTemplateKWAndArgsInfo: 843cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// Specifies when this declaration reference expression has an explicit 844e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara/// C++ template keyword and/or template argument list. 845f4b88a45902af1802a1cb42ba48b1c474474f228John McCall/// DeclRefExprBits.RefersToEnclosingLocal 846f4b88a45902af1802a1cb42ba48b1c474474f228John McCall/// Specifies when this declaration reference expression (validly) 847f4b88a45902af1802a1cb42ba48b1c474474f228John McCall/// refers to a local variable from a different function. 8485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclRefExpr : public Expr { 849cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth /// \brief The declaration that we are referencing. 850cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth ValueDecl *D; 8512577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 852cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth /// \brief The location of the declaration name itself. 8535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 8549e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis 855cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth /// \brief Provides source/type location info for the declaration name 856cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth /// embedded in D. 8572577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameLoc DNLoc; 8582577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 8596857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// \brief Helper to retrieve the optional NestedNameSpecifierLoc. 8606857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth NestedNameSpecifierLoc &getInternalQualifierLoc() { 8617e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth assert(hasQualifier()); 8626857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth return *reinterpret_cast<NestedNameSpecifierLoc *>(this + 1); 863a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 864cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth 8656857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// \brief Helper to retrieve the optional NestedNameSpecifierLoc. 8666857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth const NestedNameSpecifierLoc &getInternalQualifierLoc() const { 8676857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth return const_cast<DeclRefExpr *>(this)->getInternalQualifierLoc(); 868a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 869096832c5ed5b9106fa177ebc148489760c3bc496John McCall 8703aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// \brief Test whether there is a distinct FoundDecl attached to the end of 8713aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// this DRE. 8723aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth bool hasFoundDecl() const { return DeclRefExprBits.HasFoundDecl; } 8733aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 8743aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// \brief Helper to retrieve the optional NamedDecl through which this 8753aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// reference occured. 8763aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *&getInternalFoundDecl() { 8773aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth assert(hasFoundDecl()); 8783aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth if (hasQualifier()) 8793aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return *reinterpret_cast<NamedDecl **>(&getInternalQualifierLoc() + 1); 8803aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return *reinterpret_cast<NamedDecl **>(this + 1); 8813aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth } 8823aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 8833aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// \brief Helper to retrieve the optional NamedDecl through which this 8843aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// reference occured. 8853aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *getInternalFoundDecl() const { 8863aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return const_cast<DeclRefExpr *>(this)->getInternalFoundDecl(); 8873aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth } 8883aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 8893d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel Dunbar DeclRefExpr(ASTContext &Ctx, 8903d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel Dunbar NestedNameSpecifierLoc QualifierLoc, 891e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 892f4b88a45902af1802a1cb42ba48b1c474474f228John McCall ValueDecl *D, bool refersToEnclosingLocal, 893f4b88a45902af1802a1cb42ba48b1c474474f228John McCall const DeclarationNameInfo &NameInfo, 8943aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *FoundD, 8952577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const TemplateArgumentListInfo *TemplateArgs, 896f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK); 8972577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 898663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis /// \brief Construct an empty declaration reference expression. 899663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis explicit DeclRefExpr(EmptyShell Empty) 900663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis : Expr(DeclRefExprClass, Empty) { } 9017e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 9020da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor /// \brief Computes the type- and value-dependence flags for this 9030da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor /// declaration reference expression. 9043d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel Dunbar void computeDependence(ASTContext &C); 9059e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis 9065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 907f4b88a45902af1802a1cb42ba48b1c474474f228John McCall DeclRefExpr(ValueDecl *D, bool refersToEnclosingLocal, QualType T, 908f4b88a45902af1802a1cb42ba48b1c474474f228John McCall ExprValueKind VK, SourceLocation L, 9095b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor const DeclarationNameLoc &LocInfo = DeclarationNameLoc()) 910561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Expr(DeclRefExprClass, T, VK, OK_Ordinary, false, false, false, false), 9115b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor D(D), Loc(L), DNLoc(LocInfo) { 912cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth DeclRefExprBits.HasQualifier = 0; 913e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara DeclRefExprBits.HasTemplateKWAndArgsInfo = 0; 9143aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth DeclRefExprBits.HasFoundDecl = 0; 9157cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara DeclRefExprBits.HadMultipleCandidates = 0; 916f4b88a45902af1802a1cb42ba48b1c474474f228John McCall DeclRefExprBits.RefersToEnclosingLocal = refersToEnclosingLocal; 9173d13c5a1e72ed8f8be9c083791d30643d1b1ec43Daniel Dunbar computeDependence(D->getASTContext()); 9180da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor } 9191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 920a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor static DeclRefExpr *Create(ASTContext &Context, 92140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 922e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 923dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *D, 924f4b88a45902af1802a1cb42ba48b1c474474f228John McCall bool isEnclosingLocal, 925a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation NameLoc, 926f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK, 9273aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *FoundD = 0, 9280da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor const TemplateArgumentListInfo *TemplateArgs = 0); 929663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis 9302577743c5650c646fb705df01403707e94f2df04Abramo Bagnara static DeclRefExpr *Create(ASTContext &Context, 93140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 932e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 9332577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ValueDecl *D, 934f4b88a45902af1802a1cb42ba48b1c474474f228John McCall bool isEnclosingLocal, 9352577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 936f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK, 9373aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *FoundD = 0, 9382577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const TemplateArgumentListInfo *TemplateArgs = 0); 9392577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 940663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis /// \brief Construct an empty declaration reference expression. 941663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis static DeclRefExpr *CreateEmpty(ASTContext &Context, 9423aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth bool HasQualifier, 9433aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth bool HasFoundDecl, 944e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool HasTemplateKWAndArgsInfo, 945def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor unsigned NumTemplateArgs); 9467e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 947cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth ValueDecl *getDecl() { return D; } 948cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth const ValueDecl *getDecl() const { return D; } 949cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth void setDecl(ValueDecl *NewD) { D = NewD; } 950904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor 9512577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo getNameInfo() const { 9522577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(getDecl()->getDeclName(), Loc, DNLoc); 9532577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 9542577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 9559e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis SourceLocation getLocation() const { return Loc; } 9560b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 957aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY; 958aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceLocation getLocStart() const LLVM_READONLY; 959aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceLocation getLocEnd() const LLVM_READONLY; 9601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 961a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Determine whether this declaration reference was preceded by a 962a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// C++ nested-name-specifier, e.g., \c N::foo. 963cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth bool hasQualifier() const { return DeclRefExprBits.HasQualifier; } 9647e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 9657e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth /// \brief If the name was qualified, retrieves the nested-name-specifier 966a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// that precedes the name. Otherwise, returns NULL. 967a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NestedNameSpecifier *getQualifier() const { 968a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (!hasQualifier()) 969a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 9707e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 9716857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth return getInternalQualifierLoc().getNestedNameSpecifier(); 972a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 97340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor 9747e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth /// \brief If the name was qualified, retrieves the nested-name-specifier 97540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor /// that precedes the name, with source-location information. 97640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc getQualifierLoc() const { 97740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (!hasQualifier()) 97840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return NestedNameSpecifierLoc(); 9797e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 9806857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth return getInternalQualifierLoc(); 98140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor } 98240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor 9833aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// \brief Get the NamedDecl through which this reference occured. 9843aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// 9853aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// This Decl may be different from the ValueDecl actually referred to in the 9863aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// presence of using declarations, etc. It always returns non-NULL, and may 9873aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// simple return the ValueDecl when appropriate. 9883aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *getFoundDecl() { 9893aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return hasFoundDecl() ? getInternalFoundDecl() : D; 9903aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth } 9913aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 9923aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// \brief Get the NamedDecl through which this reference occurred. 9933aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// See non-const variant. 9943aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth const NamedDecl *getFoundDecl() const { 9953aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return hasFoundDecl() ? getInternalFoundDecl() : D; 9963aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth } 9973aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 998e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool hasTemplateKWAndArgsInfo() const { 999e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return DeclRefExprBits.HasTemplateKWAndArgsInfo; 1000096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 10017e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 1002e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Return the optional template keyword and arguments info. 1003e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() { 1004e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!hasTemplateKWAndArgsInfo()) 1005e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return 0; 1006e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 10073aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth if (hasFoundDecl()) 1008e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return reinterpret_cast<ASTTemplateKWAndArgsInfo *>( 10093aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth &getInternalFoundDecl() + 1); 10103aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 10113aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth if (hasQualifier()) 1012e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return reinterpret_cast<ASTTemplateKWAndArgsInfo *>( 10133aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth &getInternalQualifierLoc() + 1); 10147e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 1015e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return reinterpret_cast<ASTTemplateKWAndArgsInfo *>(this + 1); 1016e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 1017e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 1018e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Return the optional template keyword and arguments info. 1019e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const { 1020e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return const_cast<DeclRefExpr*>(this)->getTemplateKWAndArgsInfo(); 1021e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 1022e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 1023e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the template keyword preceding 1024e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// this name, if any. 1025e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getTemplateKeywordLoc() const { 1026e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!hasTemplateKWAndArgsInfo()) return SourceLocation(); 1027e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc(); 1028e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 1029e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 1030e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the left angle bracket starting the 1031e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// explicit template argument list following the name, if any. 1032e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getLAngleLoc() const { 1033e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!hasTemplateKWAndArgsInfo()) return SourceLocation(); 1034e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->LAngleLoc; 1035e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 1036e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 1037e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the right angle bracket ending the 1038e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// explicit template argument list following the name, if any. 1039e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getRAngleLoc() const { 1040e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!hasTemplateKWAndArgsInfo()) return SourceLocation(); 1041e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->RAngleLoc; 1042e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 1043e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 1044e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Determines whether the name in this declaration reference 1045e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// was preceded by the template keyword. 1046e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } 1047e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 1048e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Determines whether this declaration reference was followed by an 1049e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// explicit template argument list. 1050e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } 1051e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 1052e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the explicit template argument list that followed the 1053e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// member template name. 1054e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 1055e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara assert(hasExplicitTemplateArgs()); 1056e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return *getTemplateKWAndArgsInfo(); 1057096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 10587e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 1059096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that followed the 1060096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// member template name. 1061b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 1062096832c5ed5b9106fa177ebc148489760c3bc496John McCall return const_cast<DeclRefExpr *>(this)->getExplicitTemplateArgs(); 1063a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 1064d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 1065096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieves the optional explicit template arguments. 1066096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// This points to the same data as getExplicitTemplateArgs(), but 1067096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// returns null if there are no explicit template arguments. 1068e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const { 1069096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) return 0; 1070096832c5ed5b9106fa177ebc148489760c3bc496John McCall return &getExplicitTemplateArgs(); 1071096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 10727e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 1073d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// \brief Copies the template arguments (if present) into the given 1074d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// structure. 1075d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 1076096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (hasExplicitTemplateArgs()) 1077096832c5ed5b9106fa177ebc148489760c3bc496John McCall getExplicitTemplateArgs().copyInto(List); 1078d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall } 10797e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 1080a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the template arguments provided as part of this 1081a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template-id. 1082833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc *getTemplateArgs() const { 1083096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 1084a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 10857e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 1086096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().getTemplateArgs(); 1087a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 10887e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 1089a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the number of template arguments provided as part of this 1090a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template-id. 1091a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor unsigned getNumTemplateArgs() const { 1092096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 1093a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 10947e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 1095096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().NumTemplateArgs; 1096a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 10977e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 10987cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// \brief Returns true if this expression refers to a function that 10997cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// was resolved from an overloaded set having size greater than 1. 11007cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool hadMultipleCandidates() const { 11017cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara return DeclRefExprBits.HadMultipleCandidates; 11027cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara } 11037cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// \brief Sets the flag telling whether this expression refers to 11047cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// a function that was resolved from an overloaded set having size 11057cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// greater than 1. 11067cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara void setHadMultipleCandidates(bool V = true) { 11077cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara DeclRefExprBits.HadMultipleCandidates = V; 11087cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara } 11097cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara 1110f4b88a45902af1802a1cb42ba48b1c474474f228John McCall /// Does this DeclRefExpr refer to a local declaration from an 1111f4b88a45902af1802a1cb42ba48b1c474474f228John McCall /// enclosing function scope? 1112f4b88a45902af1802a1cb42ba48b1c474474f228John McCall bool refersToEnclosingLocal() const { 1113f4b88a45902af1802a1cb42ba48b1c474474f228John McCall return DeclRefExprBits.RefersToEnclosingLocal; 1114f4b88a45902af1802a1cb42ba48b1c474474f228John McCall } 1115f4b88a45902af1802a1cb42ba48b1c474474f228John McCall 11161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 111799e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor return T->getStmtClass() == DeclRefExprClass; 11185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 112077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 112163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 11227e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 112360adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 11243397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl friend class ASTStmtWriter; 11255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1127d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner/// PredefinedExpr - [C99 6.4.2.2] - A predefined identifier such as __func__. 1128d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattnerclass PredefinedExpr : public Expr { 1129227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic: 1130227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson enum IdentType { 1131227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson Func, 1132227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson Function, 113328ad063b279378b19cb0704f977429df366a151eNico Weber LFunction, // Same as Function, but as wide string. 1134848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson PrettyFunction, 1135848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson /// PrettyFunctionNoVirtual - The same as PrettyFunction, except that the 1136848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson /// 'virtual' keyword is omitted for virtual member functions. 1137848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson PrettyFunctionNoVirtual 1138227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson }; 11391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1140227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonprivate: 1141227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson SourceLocation Loc; 1142227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson IdentType Type; 1143227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic: 11441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump PredefinedExpr(SourceLocation l, QualType type, IdentType IT) 1145f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(PredefinedExprClass, type, VK_LValue, OK_Ordinary, 1146ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie type->isDependentType(), type->isDependentType(), 1147561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor type->isInstantiationDependentType(), 1148bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 1149f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Loc(l), Type(IT) {} 11501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 115117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor /// \brief Construct an empty predefined expression. 11521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit PredefinedExpr(EmptyShell Empty) 115317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor : Expr(PredefinedExprClass, Empty) { } 115417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 1155227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson IdentType getIdentType() const { return Type; } 115617fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setIdentType(IdentType IT) { Type = IT; } 115717fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 115817fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor SourceLocation getLocation() const { return Loc; } 115917fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 116017fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 1161848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson static std::string ComputeName(IdentType IT, const Decl *CurrentDecl); 11623a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 1163aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc); } 1164227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 11651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 11661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == PredefinedExprClass; 1167227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson } 11681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 116977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 117063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 1171227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson}; 1172227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 11739996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// \brief Used by IntegerLiteral/FloatingLiteral to store the numeric without 11749996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// leaking memory. 11759996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// 11769996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// For large floats/integers, APFloat/APInt will allocate memory from the heap 11779996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// to represent these numbers. Unfortunately, when we use a BumpPtrAllocator 11789996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// to allocate IntegerLiteral/FloatingLiteral nodes the memory associated with 11799996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// the APFloat/APInt values will never get freed. APNumericStorage uses 11809996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// ASTContext's allocator for memory allocation. 11819996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisclass APNumericStorage { 11829996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis union { 11839996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis uint64_t VAL; ///< Used to store the <= 64 bits integer value. 11849996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis uint64_t *pVal; ///< Used to store the >64 bits integer value. 11859996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis }; 118691219326471798c7d3b02dc48691581580338969Benjamin Kramer unsigned BitWidth; 11879996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 11889996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis bool hasAllocation() const { return llvm::APInt::getNumWords(BitWidth) > 1; } 11899996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 1190f56faa01936b9cf909623d7f06e3c2569ca4a78eDmitri Gribenko APNumericStorage(const APNumericStorage &) LLVM_DELETED_FUNCTION; 1191f56faa01936b9cf909623d7f06e3c2569ca4a78eDmitri Gribenko void operator=(const APNumericStorage &) LLVM_DELETED_FUNCTION; 11929996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 11939996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisprotected: 119491219326471798c7d3b02dc48691581580338969Benjamin Kramer APNumericStorage() : VAL(0), BitWidth(0) { } 11959996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 11969996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APInt getIntValue() const { 11979996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis unsigned NumWords = llvm::APInt::getNumWords(BitWidth); 11989996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis if (NumWords > 1) 11999996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return llvm::APInt(BitWidth, NumWords, pVal); 12009996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis else 12019996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return llvm::APInt(BitWidth, VAL); 12029996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 12039996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setIntValue(ASTContext &C, const llvm::APInt &Val); 12049996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis}; 12059996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 120691219326471798c7d3b02dc48691581580338969Benjamin Kramerclass APIntStorage : private APNumericStorage { 1207ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikiepublic: 1208ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie llvm::APInt getValue() const { return getIntValue(); } 12099996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setValue(ASTContext &C, const llvm::APInt &Val) { setIntValue(C, Val); } 12109996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis}; 12119996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 1212bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramerclass APFloatStorage : private APNumericStorage { 1213ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikiepublic: 121431dfd642d5ac33c4ee0cfe1d7a1d4da455dcc7a4Akira Hatanaka llvm::APFloat getValue(bool IsIEEE) const { 121531dfd642d5ac33c4ee0cfe1d7a1d4da455dcc7a4Akira Hatanaka return llvm::APFloat(getIntValue(), IsIEEE); 121631dfd642d5ac33c4ee0cfe1d7a1d4da455dcc7a4Akira Hatanaka } 12179996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setValue(ASTContext &C, const llvm::APFloat &Val) { 12189996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis setIntValue(C, Val.bitcastToAPInt()); 12199996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 12209996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis}; 12219996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 122291219326471798c7d3b02dc48691581580338969Benjamin Kramerclass IntegerLiteral : public Expr, public APIntStorage { 12235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 12249996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 12259996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis /// \brief Construct an empty integer literal. 12269996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis explicit IntegerLiteral(EmptyShell Empty) 12279996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis : Expr(IntegerLiteralClass, Empty) { } 12289996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 12295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 12301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy, 12315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // or UnsignedLongLongTy 1232478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer IntegerLiteral(ASTContext &C, const llvm::APInt &V, QualType type, 1233478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer SourceLocation l); 1234a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson 12351dd986dff9ddfbec687975700770bb377988e9edRichard Trieu /// \brief Returns a new integer literal with value 'V' and type 'type'. 12361dd986dff9ddfbec687975700770bb377988e9edRichard Trieu /// \param type - either IntTy, LongTy, LongLongTy, UnsignedIntTy, 12371dd986dff9ddfbec687975700770bb377988e9edRichard Trieu /// UnsignedLongTy, or UnsignedLongLongTy which should match the size of V 12381dd986dff9ddfbec687975700770bb377988e9edRichard Trieu /// \param V - the value that the returned integer literal contains. 12399996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis static IntegerLiteral *Create(ASTContext &C, const llvm::APInt &V, 12409996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis QualType type, SourceLocation l); 12411dd986dff9ddfbec687975700770bb377988e9edRichard Trieu /// \brief Returns a new empty integer literal. 12429996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis static IntegerLiteral *Create(ASTContext &C, EmptyShell Empty); 12430b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 1244aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc); } 12455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1246313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Retrieve the location of the literal. 1247313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getLocation() const { return Loc; } 1248313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 12490b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation Location) { Loc = Location; } 12500b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 12511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 12521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == IntegerLiteralClass; 12535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 125577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 125663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 12575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 12585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CharacterLiteral : public Expr { 12605cee1195584fa8672253139c86e922daeda69b9eDouglas Gregorpublic: 12615cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor enum CharacterKind { 12625cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor Ascii, 12635cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor Wide, 12645cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor UTF16, 12655cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor UTF32 12665cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor }; 12675cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor 12685cee1195584fa8672253139c86e922daeda69b9eDouglas Gregorprivate: 12695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned Value; 12705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 12715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 12725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // type should be IntTy 12735cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor CharacterLiteral(unsigned value, CharacterKind kind, QualType type, 12745cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor SourceLocation l) 1275bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(CharacterLiteralClass, type, VK_RValue, OK_Ordinary, false, false, 1276561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false), 1277bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer Value(value), Loc(l) { 1278bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer CharacterLiteralBits.Kind = kind; 12795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12800b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 12810b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Construct an empty character literal. 12820b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { } 12830b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 1284018d8e0596dd57401eeddcf11ac84ff0a065fbbeChris Lattner SourceLocation getLocation() const { return Loc; } 1285bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer CharacterKind getKind() const { 1286bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer return static_cast<CharacterKind>(CharacterLiteralBits.Kind); 1287bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer } 12881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1289aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc); } 12901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getValue() const { return Value; } 12925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12930b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation Location) { Loc = Location; } 1294bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer void setKind(CharacterKind kind) { CharacterLiteralBits.Kind = kind; } 12950b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setValue(unsigned Val) { Value = Val; } 12960b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 12971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 12981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CharacterLiteralClass; 12995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 130077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 130177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 130263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 13035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 13045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1305bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramerclass FloatingLiteral : public Expr, private APFloatStorage { 13065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 13079996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 13089996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis FloatingLiteral(ASTContext &C, const llvm::APFloat &V, bool isexact, 1309478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer QualType Type, SourceLocation L); 13105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 131117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor /// \brief Construct an empty floating-point literal. 1312478851c3ed6bd784e7377dffd8e57b200c1b9ba9Benjamin Kramer explicit FloatingLiteral(ASTContext &C, EmptyShell Empty); 131317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 13149996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidispublic: 13159996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis static FloatingLiteral *Create(ASTContext &C, const llvm::APFloat &V, 13169996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis bool isexact, QualType Type, SourceLocation L); 13179996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis static FloatingLiteral *Create(ASTContext &C, EmptyShell Empty); 13189996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 1319bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer llvm::APFloat getValue() const { 1320bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer return APFloatStorage::getValue(FloatingLiteralBits.IsIEEE); 1321bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer } 13229996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setValue(ASTContext &C, const llvm::APFloat &Val) { 1323bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer APFloatStorage::setValue(C, Val); 13249996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 132517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 1326bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer bool isExact() const { return FloatingLiteralBits.IsExact; } 1327bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer void setExact(bool E) { FloatingLiteralBits.IsExact = E; } 1328c9bec4bfea9090a08dd83a7b213f0c8adf8d78ecChris Lattner 1329da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// getValueAsApproximateDouble - This returns the value as an inaccurate 1330da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// double. Note that this may cause loss of precision, but is useful for 1331da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// debugging dumps, etc. 1332da8249e57f3badecf925571881fe57243935c6c1Chris Lattner double getValueAsApproximateDouble() const; 13331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 133417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor SourceLocation getLocation() const { return Loc; } 133517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 133617fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 1337aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc); } 13385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 13401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == FloatingLiteralClass; 13415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 134377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 134463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 13455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 13465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13475d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// ImaginaryLiteral - We support imaginary integer and floating point literals, 13485d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// like "1.0i". We represent these as a wrapper around FloatingLiteral and 13495d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// IntegerLiteral classes. Instances of this class always have a Complex type 13505d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// whose element type matches the subexpression. 13515d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// 13525d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerclass ImaginaryLiteral : public Expr { 13535549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 13545d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerpublic: 13555d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner ImaginaryLiteral(Expr *val, QualType Ty) 1356bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(ImaginaryLiteralClass, Ty, VK_RValue, OK_Ordinary, false, false, 1357561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false), 1358f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Val(val) {} 13591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1360cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor /// \brief Build an empty imaginary literal. 13611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ImaginaryLiteral(EmptyShell Empty) 1362cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor : Expr(ImaginaryLiteralClass, Empty) { } 1363cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 13645549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 13655549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 1366cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 1367cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 1368aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { return Val->getSourceRange(); } 13691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 13701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ImaginaryLiteralClass; 13715d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner } 13721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13735d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner // Iterators 137463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Val, &Val+1); } 13755d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner}; 13765d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner 1377e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// StringLiteral - This represents a string literal expression, e.g. "foo" 1378e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// or L"bar" (wide strings). The actual string is returned by getStrData() 1379e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// is NOT null-terminated, and the length of the string is determined by 1380a7ad98ff0919d6a24ea7c46634ea29bea551c1a0Chris Lattner/// calling getByteLength(). The C type for a string is always a 1381c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// ConstantArrayType. In C++, the char type is const qualified, in C it is 1382c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// not. 1383690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// 1384690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// Note that strings in C can be formed by concatenation of multiple string 13858bea7c0ee44c71c817de7dc2be932b73bec90c9fChris Lattner/// literal pptokens in translation phase #6. This keeps track of the locations 1386690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// of each of these pieces. 1387c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// 1388c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// Strings in C can also be truncated and extended by assigning into arrays, 1389c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// e.g. with constructs like: 1390c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// char X[2] = "foobar"; 1391c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// In this case, getByteLength() will return 6, but the string literal will 1392c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// have type "char[2]". 13935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass StringLiteral : public Expr { 13945cee1195584fa8672253139c86e922daeda69b9eDouglas Gregorpublic: 13955cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor enum StringKind { 13965cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor Ascii, 13975cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor Wide, 13985cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor UTF8, 13995cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor UTF16, 14005cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor UTF32 14015cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor }; 14025cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor 14035cee1195584fa8672253139c86e922daeda69b9eDouglas Gregorprivate: 14043e2193ce5feb2feb092e5ae615e85148e06e9fd2Anders Carlsson friend class ASTStmtReader; 14053e2193ce5feb2feb092e5ae615e85148e06e9fd2Anders Carlsson 140664f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman union { 140764f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman const char *asChar; 140864f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman const uint16_t *asUInt16; 140964f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman const uint32_t *asUInt32; 141064f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman } StrData; 141164f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman unsigned Length; 14120840f2378e9b5764755c5dffd27d7878c7606a0cBenjamin Kramer unsigned CharByteWidth : 4; 14135cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor unsigned Kind : 3; 14140840f2378e9b5764755c5dffd27d7878c7606a0cBenjamin Kramer unsigned IsPascal : 1; 14150840f2378e9b5764755c5dffd27d7878c7606a0cBenjamin Kramer unsigned NumConcatenated; 1416726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner SourceLocation TokLocs[1]; 14172085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner 1418f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall StringLiteral(QualType Ty) : 1419561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Expr(StringLiteralClass, Ty, VK_LValue, OK_Ordinary, false, false, false, 1420561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false) {} 14211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 142264f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman static int mapCharByteWidth(TargetInfo const &target,StringKind k); 142364f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman 14245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 14252085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// This is the "fully general" constructor that allows representation of 14262085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// strings formed from multiple concatenated tokens. 14275cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor static StringLiteral *Create(ASTContext &C, StringRef Str, StringKind Kind, 142865aa6885818d4b4eea2e5a9d12085b2398148662Jay Foad bool Pascal, QualType Ty, 1429a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson const SourceLocation *Loc, unsigned NumStrs); 14302085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner 14312085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// Simple constructor for string literals made from one token. 14325cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor static StringLiteral *Create(ASTContext &C, StringRef Str, StringKind Kind, 14335cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor bool Pascal, QualType Ty, 14345cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor SourceLocation Loc) { 14355cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor return Create(C, Str, Kind, Pascal, Ty, &Loc, 1); 14362085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 1437a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson 1438673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor /// \brief Construct an empty string literal. 1439673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor static StringLiteral *CreateEmpty(ASTContext &C, unsigned NumStrs); 1440673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 1441686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef getString() const { 144264f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman assert(CharByteWidth==1 144364f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman && "This function is used in places that assume strings use char"); 144464f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman return StringRef(StrData.asChar, getByteLength()); 144564f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman } 144664f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman 14470982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// Allow access to clients that need the byte representation, such as 14480982205bade2fb4fc984c27b2ab401e683963b10James Dennett /// ASTWriterStmt::VisitStringLiteral(). 144964f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman StringRef getBytes() const { 1450e91e0ae772004912285ccc3848b27208da8c045bChris Lattner // FIXME: StringRef may not be the right type to use as a result for this. 1451e91e0ae772004912285ccc3848b27208da8c045bChris Lattner if (CharByteWidth == 1) 1452e91e0ae772004912285ccc3848b27208da8c045bChris Lattner return StringRef(StrData.asChar, getByteLength()); 1453e91e0ae772004912285ccc3848b27208da8c045bChris Lattner if (CharByteWidth == 4) 145464f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman return StringRef(reinterpret_cast<const char*>(StrData.asUInt32), 145564f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman getByteLength()); 1456e91e0ae772004912285ccc3848b27208da8c045bChris Lattner assert(CharByteWidth == 2 && "unsupported CharByteWidth"); 1457e91e0ae772004912285ccc3848b27208da8c045bChris Lattner return StringRef(reinterpret_cast<const char*>(StrData.asUInt16), 1458e91e0ae772004912285ccc3848b27208da8c045bChris Lattner getByteLength()); 1459b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar } 14602f4eaef37476ae6891ede8ba215d0f6fd093629bBenjamin Kramer 14618ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu void outputString(raw_ostream &OS); 14628ab09da1faaa33b9fa78de59cc4e191bfe9907b5Richard Trieu 146364f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman uint32_t getCodeUnit(size_t i) const { 1464e91e0ae772004912285ccc3848b27208da8c045bChris Lattner assert(i < Length && "out of bounds access"); 1465e91e0ae772004912285ccc3848b27208da8c045bChris Lattner if (CharByteWidth == 1) 146664f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman return static_cast<unsigned char>(StrData.asChar[i]); 1467e91e0ae772004912285ccc3848b27208da8c045bChris Lattner if (CharByteWidth == 4) 1468e91e0ae772004912285ccc3848b27208da8c045bChris Lattner return StrData.asUInt32[i]; 1469e91e0ae772004912285ccc3848b27208da8c045bChris Lattner assert(CharByteWidth == 2 && "unsupported CharByteWidth"); 1470e91e0ae772004912285ccc3848b27208da8c045bChris Lattner return StrData.asUInt16[i]; 147164f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman } 147264f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman 147364f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman unsigned getByteLength() const { return CharByteWidth*Length; } 147464f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman unsigned getLength() const { return Length; } 147564f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman unsigned getCharByteWidth() const { return CharByteWidth; } 1476673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 1477673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor /// \brief Sets the string data to the given string data. 147864f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman void setString(ASTContext &C, StringRef Str, 147964f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman StringKind Kind, bool IsPascal); 1480673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 14815cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor StringKind getKind() const { return static_cast<StringKind>(Kind); } 1482ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1483ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 14845cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor bool isAscii() const { return Kind == Ascii; } 14855cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor bool isWide() const { return Kind == Wide; } 14865cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor bool isUTF8() const { return Kind == UTF8; } 14875cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor bool isUTF16() const { return Kind == UTF16; } 14885cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor bool isUTF32() const { return Kind == UTF32; } 14893e2193ce5feb2feb092e5ae615e85148e06e9fd2Anders Carlsson bool isPascal() const { return IsPascal; } 14905cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor 14918d4141f83d9de379547cf05bd75d4c6cf894b189Steve Naroff bool containsNonAsciiOrNull() const { 1492686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef Str = getString(); 1493b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar for (unsigned i = 0, e = Str.size(); i != e; ++i) 1494b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar if (!isascii(Str[i]) || !Str[i]) 149533fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff return true; 149633fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff return false; 149733fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff } 1498ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1499726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner /// getNumConcatenated - Get the number of string literal tokens that were 1500726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner /// concatenated in translation phase #6 to form this string literal. 1501726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner unsigned getNumConcatenated() const { return NumConcatenated; } 15021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1503726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner SourceLocation getStrTokenLoc(unsigned TokNum) const { 1504726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner assert(TokNum < NumConcatenated && "Invalid tok number"); 1505726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner return TokLocs[TokNum]; 1506726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner } 15071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setStrTokenLoc(unsigned TokNum, SourceLocation L) { 1508673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor assert(TokNum < NumConcatenated && "Invalid tok number"); 1509673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor TokLocs[TokNum] = L; 1510673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor } 1511ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 151208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// getLocationOfByte - Return a source location that points to the specified 151308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// byte of this string literal. 151408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// 151508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// Strings are amazingly complex. They can be formed from multiple tokens 151608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// and can have escape sequences in them in addition to the usual trigraph 151708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// and escaped newline business. This routine handles this complexity. 151808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// 151908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner SourceLocation getLocationOfByte(unsigned ByteNo, const SourceManager &SM, 152008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner const LangOptions &Features, 152108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner const TargetInfo &Target) const; 1522673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 1523b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner typedef const SourceLocation *tokloc_iterator; 1524b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner tokloc_iterator tokloc_begin() const { return TokLocs; } 1525b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner tokloc_iterator tokloc_end() const { return TokLocs+NumConcatenated; } 15265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1527aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 15281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(TokLocs[0], TokLocs[NumConcatenated-1]); 15295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 15301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 15311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == StringLiteralClass; 15325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 15331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 153477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 153563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 15365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 15375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ParenExpr - This represents a parethesized expression, e.g. "(1)". This 15395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// AST node is only formed if full location information is requested. 15405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ParenExpr : public Expr { 15415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation L, R; 15425549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 15435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 15445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ParenExpr(SourceLocation l, SourceLocation r, Expr *val) 1545898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Expr(ParenExprClass, val->getType(), 1546f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall val->getValueKind(), val->getObjectKind(), 1547bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor val->isTypeDependent(), val->isValueDependent(), 1548561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor val->isInstantiationDependent(), 1549bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor val->containsUnexpandedParameterPack()), 1550898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor L(l), R(r), Val(val) {} 15511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1552c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor /// \brief Construct an empty parenthesized expression. 15531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ParenExpr(EmptyShell Empty) 1554c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor : Expr(ParenExprClass, Empty) { } 1555c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor 15565549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 15575549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 1558c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 1559c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor 1560aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(L, R); } 15615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1562313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Get the location of the left parentheses '('. 1563313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getLParen() const { return L; } 1564c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setLParen(SourceLocation Loc) { L = Loc; } 1565313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 1566313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Get the location of the right parentheses ')'. 1567313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getRParen() const { return R; } 1568c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setRParen(SourceLocation Loc) { R = Loc; } 1569313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 15701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 15711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ParenExprClass; 15725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 15731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 157477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 157563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Val, &Val+1); } 15765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 15775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15790518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// UnaryOperator - This represents the unary-expression's (except sizeof and 15800518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// alignof), the postinc/postdec operators from postfix-expression, and various 15815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// extensions. 1582dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 1583dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Notes on various nodes: 1584dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 1585dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Real/Imag - These return the real/imag part of a complex operand. If 1586dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// applied to a non-complex value, the former returns its operand and the 1587dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// later returns zero in the type of the operand. 1588dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 15895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass UnaryOperator : public Expr { 15905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 15915baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall typedef UnaryOperatorKind Opcode; 15925baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 15935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 15940799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall unsigned Opc : 5; 15955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 15960799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Stmt *Val; 15971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 15985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1599f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall UnaryOperator(Expr *input, Opcode opc, QualType type, 1600f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, SourceLocation l) 1601f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(UnaryOperatorClass, type, VK, OK, 1602de7e66256b1bdfcf6526994825a8c8fced52a31cEli Friedman input->isTypeDependent() || type->isDependentType(), 1603bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor input->isValueDependent(), 1604ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie (input->isInstantiationDependent() || 1605561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor type->isInstantiationDependentType()), 1606bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor input->containsUnexpandedParameterPack()), 16070799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Opc(opc), Loc(l), Val(input) {} 16085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 16090b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor /// \brief Build an empty unary operator. 16101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit UnaryOperator(EmptyShell Empty) 16112de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall : Expr(UnaryOperatorClass, Empty), Opc(UO_AddrOf) { } 16120b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 16130799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Opcode getOpcode() const { return static_cast<Opcode>(Opc); } 16140b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOpcode(Opcode O) { Opc = O; } 16150b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 16165549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() const { return cast<Expr>(Val); } 16170b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setSubExpr(Expr *E) { Val = E; } 16180b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 16195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOperatorLoc - Return the location of the operator. 16205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getOperatorLoc() const { return Loc; } 16210b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOperatorLoc(SourceLocation L) { Loc = L; } 16220b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 16235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isPostfix - Return true if this is a postfix operation, like x++. 16242085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static bool isPostfix(Opcode Op) { 16252de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Op == UO_PostInc || Op == UO_PostDec; 16262085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 16275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1628cc7bd10c0de9449b795bda3c5dcc6d83cc48436bZhanyong Wan /// isPrefix - Return true if this is a prefix operation, like --x. 16292085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static bool isPrefix(Opcode Op) { 16302de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Op == UO_PreInc || Op == UO_PreDec; 16312085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 16325a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek 16330799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isPrefix() const { return isPrefix(getOpcode()); } 16340799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isPostfix() const { return isPostfix(getOpcode()); } 16353c3b7f90a863af43fa63043d396553ecf205351cJohn McCall 16363c3b7f90a863af43fa63043d396553ecf205351cJohn McCall static bool isIncrementOp(Opcode Op) { 16373c3b7f90a863af43fa63043d396553ecf205351cJohn McCall return Op == UO_PreInc || Op == UO_PostInc; 16383c3b7f90a863af43fa63043d396553ecf205351cJohn McCall } 16392de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall bool isIncrementOp() const { 16403c3b7f90a863af43fa63043d396553ecf205351cJohn McCall return isIncrementOp(getOpcode()); 16413c3b7f90a863af43fa63043d396553ecf205351cJohn McCall } 16423c3b7f90a863af43fa63043d396553ecf205351cJohn McCall 16433c3b7f90a863af43fa63043d396553ecf205351cJohn McCall static bool isDecrementOp(Opcode Op) { 16443c3b7f90a863af43fa63043d396553ecf205351cJohn McCall return Op == UO_PreDec || Op == UO_PostDec; 16452de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 16463c3b7f90a863af43fa63043d396553ecf205351cJohn McCall bool isDecrementOp() const { 16473c3b7f90a863af43fa63043d396553ecf205351cJohn McCall return isDecrementOp(getOpcode()); 16483c3b7f90a863af43fa63043d396553ecf205351cJohn McCall } 16493c3b7f90a863af43fa63043d396553ecf205351cJohn McCall 16503c3b7f90a863af43fa63043d396553ecf205351cJohn McCall static bool isIncrementDecrementOp(Opcode Op) { return Op <= UO_PreDec; } 16512de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall bool isIncrementDecrementOp() const { 16523c3b7f90a863af43fa63043d396553ecf205351cJohn McCall return isIncrementDecrementOp(getOpcode()); 16532de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 16543c3b7f90a863af43fa63043d396553ecf205351cJohn McCall 16552de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isArithmeticOp(Opcode Op) { 16562de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Op >= UO_Plus && Op <= UO_LNot; 16572de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 16580799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isArithmeticOp() const { return isArithmeticOp(getOpcode()); } 16591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 16615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// corresponds to, e.g. "sizeof" or "[pre]++" 16620bea86307eb8c16339315a1e261fc490eb505c5bDavid Blaikie static StringRef getOpcodeStr(Opcode Op); 16635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1664bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// \brief Retrieve the unary opcode that corresponds to the given 1665bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// overloaded operator. 1666bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix); 1667bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 1668bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// \brief Retrieve the overloaded operator kind that corresponds to 1669bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// the given unary opcode. 1670bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); 1671bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 1672aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 16735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (isPostfix()) 16745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(Val->getLocStart(), Loc); 16755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else 16765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(Loc, Val->getLocEnd()); 16775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 16784f311183be3d923da9fbe8702c453688b4c426a9Daniel Dunbar SourceLocation getExprLoc() const LLVM_READONLY { return Loc; } 16791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 16811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == UnaryOperatorClass; 16825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 16831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 168477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 168563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Val, &Val+1); } 16865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 16875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 16888ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// OffsetOfExpr - [C99 7.17] - This represents an expression of the form 16898ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// offsetof(record-type, member-designator). For example, given: 16908ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// @code 16918ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct S { 16928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// float f; 1693ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// double d; 16948ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// }; 16958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct T { 16968ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// int i; 16978ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct S s[10]; 16988ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// }; 16998ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// @endcode 1700ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// we can represent and evaluate the expression @c offsetof(struct T, s[2].d). 17018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 17028ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorclass OffsetOfExpr : public Expr { 17038ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorpublic: 17048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // __builtin_offsetof(type, identifier(.identifier|[expr])*) 17058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor class OffsetOfNode { 17068ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor public: 17078ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief The kind of offsetof node we have. 17088ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor enum Kind { 1709cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief An index into an array. 17108ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Array = 0x00, 1711cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief A field. 17128ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Field = 0x01, 1713cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief A field in a dependent type, known only by its name. 1714cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor Identifier = 0x02, 1715cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief An implicit indirection through a C++ base class, when the 1716cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// field found is in a base class. 1717cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor Base = 0x03 17188ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor }; 17198ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 17208ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor private: 17218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor enum { MaskBits = 2, Mask = 0x03 }; 1722ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 17238ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief The source range that covers this part of the designator. 17248ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceRange Range; 1725ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 17268ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief The data describing the designator, which comes in three 17278ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// different forms, depending on the lower two bits. 1728ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// - An unsigned index into the array of Expr*'s stored after this node 17298ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// in memory, for [constant-expression] designators. 17308ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// - A FieldDecl*, for references to a known field. 17318ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// - An IdentifierInfo*, for references to a field with a given name 17328ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// when the class type is dependent. 1733ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// - A CXXBaseSpecifier*, for references that look at a field in a 1734cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// base class. 17358ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor uintptr_t Data; 1736ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 17378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor public: 17388ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Create an offsetof node that refers to an array element. 1739ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie OffsetOfNode(SourceLocation LBracketLoc, unsigned Index, 17408ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RBracketLoc) 17418ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor : Range(LBracketLoc, RBracketLoc), Data((Index << 2) | Array) { } 1742ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 17438ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Create an offsetof node that refers to a field. 1744ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie OffsetOfNode(SourceLocation DotLoc, FieldDecl *Field, 17458ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation NameLoc) 1746ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc), 17478ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Data(reinterpret_cast<uintptr_t>(Field) | OffsetOfNode::Field) { } 1748ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 17498ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Create an offsetof node that refers to an identifier. 17508ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor OffsetOfNode(SourceLocation DotLoc, IdentifierInfo *Name, 17518ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation NameLoc) 1752ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc), 17538ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Data(reinterpret_cast<uintptr_t>(Name) | Identifier) { } 1754cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor 1755cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief Create an offsetof node that refers into a C++ base class. 1756cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor explicit OffsetOfNode(const CXXBaseSpecifier *Base) 1757cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor : Range(), Data(reinterpret_cast<uintptr_t>(Base) | OffsetOfNode::Base) {} 1758ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 17598ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Determine what kind of offsetof node this is. 1760ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie Kind getKind() const { 17618ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return static_cast<Kind>(Data & Mask); 17628ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1763ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 17648ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief For an array element node, returns the index into the array 17658ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// of expressions. 17668ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned getArrayExprIndex() const { 17678ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(getKind() == Array); 17688ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return Data >> 2; 17698ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 17708ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 17718ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief For a field offsetof node, returns the field. 17728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor FieldDecl *getField() const { 17738ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(getKind() == Field); 1774cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor return reinterpret_cast<FieldDecl *>(Data & ~(uintptr_t)Mask); 17758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1776ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 17778ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief For a field or identifier offsetof node, returns the name of 17788ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// the field. 17798ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor IdentifierInfo *getFieldName() const; 1780ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1781cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief For a base class node, returns the base specifier. 1782cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor CXXBaseSpecifier *getBase() const { 1783cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor assert(getKind() == Base); 1784ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return reinterpret_cast<CXXBaseSpecifier *>(Data & ~(uintptr_t)Mask); 1785cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor } 1786ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 17878ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Retrieve the source range that covers this offsetof node. 17888ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// 17898ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// For an array element node, the source range contains the locations of 17908ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// the square brackets. For a field or identifier node, the source range 1791ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// contains the location of the period (if there is one) and the 17928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// identifier. 1793aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { return Range; } 17948ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor }; 17958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 17968ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorprivate: 1797ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 17988ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation OperatorLoc, RParenLoc; 17998ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Base type; 18008ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TypeSourceInfo *TSInfo; 18018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Number of sub-components (i.e. instances of OffsetOfNode). 18028ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumComps; 18038ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Number of sub-expressions (i.e. array subscript expressions). 18048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumExprs; 1805ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1806ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie OffsetOfExpr(ASTContext &C, QualType type, 18078ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation OperatorLoc, TypeSourceInfo *tsi, 18083b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<OffsetOfNode> comps, ArrayRef<Expr*> exprs, 18098ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc); 18108ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 18118ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor explicit OffsetOfExpr(unsigned numComps, unsigned numExprs) 18128ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor : Expr(OffsetOfExprClass, EmptyShell()), 1813ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie TSInfo(0), NumComps(numComps), NumExprs(numExprs) {} 18148ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 18158ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorpublic: 1816ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1817ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie static OffsetOfExpr *Create(ASTContext &C, QualType type, 1818ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie SourceLocation OperatorLoc, TypeSourceInfo *tsi, 18193b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<OffsetOfNode> comps, 18203b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> exprs, SourceLocation RParenLoc); 18218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 1822ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie static OffsetOfExpr *CreateEmpty(ASTContext &C, 18238ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumComps, unsigned NumExprs); 18248ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 18258ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// getOperatorLoc - Return the location of the operator. 18268ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation getOperatorLoc() const { return OperatorLoc; } 18278ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setOperatorLoc(SourceLocation L) { OperatorLoc = L; } 18288ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 18298ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Return the location of the right parentheses. 18308ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 18318ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setRParenLoc(SourceLocation R) { RParenLoc = R; } 1832ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 18338ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TypeSourceInfo *getTypeSourceInfo() const { 18348ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return TSInfo; 18358ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 18368ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setTypeSourceInfo(TypeSourceInfo *tsi) { 18378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TSInfo = tsi; 18388ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1839ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 18408cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne const OffsetOfNode &getComponent(unsigned Idx) const { 18418ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumComps && "Subscript out of range"); 18428cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne return reinterpret_cast<const OffsetOfNode *> (this + 1)[Idx]; 18438ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 18448ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 18458ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setComponent(unsigned Idx, OffsetOfNode ON) { 18468ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumComps && "Subscript out of range"); 18478ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<OffsetOfNode *> (this + 1)[Idx] = ON; 18488ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1849ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 18508ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned getNumComponents() const { 18518ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return NumComps; 18528ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 18538ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 18548ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr* getIndexExpr(unsigned Idx) { 18558ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumExprs && "Subscript out of range"); 18568ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return reinterpret_cast<Expr **>( 18578ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx]; 18588ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 18598cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne const Expr *getIndexExpr(unsigned Idx) const { 18608cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne return const_cast<OffsetOfExpr*>(this)->getIndexExpr(Idx); 18618cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne } 18628ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 18638ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setIndexExpr(unsigned Idx, Expr* E) { 18648ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumComps && "Subscript out of range"); 18658ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<Expr **>( 18668ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx] = E; 18678ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1868ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 18698ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned getNumExpressions() const { 18708ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return NumExprs; 18718ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 18728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 1873aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 18748ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return SourceRange(OperatorLoc, RParenLoc); 18758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 18768ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 18778ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor static bool classof(const Stmt *T) { 18788ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return T->getStmtClass() == OffsetOfExprClass; 18798ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 18808ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 18818ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Iterators 188263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 188363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt **begin = 188463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall reinterpret_cast<Stmt**>(reinterpret_cast<OffsetOfNode*>(this + 1) 188563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall + NumComps); 188663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(begin, begin + NumExprs); 188763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 18888ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor}; 18898ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 1890f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne/// UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) 1891f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne/// expression operand. Used for sizeof/alignof (C99 6.5.3.4) and 1892f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne/// vec_step (OpenCL 1.1 6.11.12). 1893f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourneclass UnaryExprOrTypeTraitExpr : public Expr { 1894d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl union { 1895a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *Ty; 1896d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl Stmt *Ex; 1897d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl } Argument; 18985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation OpLoc, RParenLoc; 189942602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor 19005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1901f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, TypeSourceInfo *TInfo, 1902f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne QualType resultType, SourceLocation op, 1903f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne SourceLocation rp) : 1904f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_RValue, OK_Ordinary, 1905ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor false, // Never type-dependent (C++ [temp.dep.expr]p3). 19062850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl // Value-dependent if the argument is type-dependent. 1907bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor TInfo->getType()->isDependentType(), 1908561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor TInfo->getType()->isInstantiationDependentType(), 1909bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor TInfo->getType()->containsUnexpandedParameterPack()), 1910bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer OpLoc(op), RParenLoc(rp) { 1911bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer UnaryExprOrTypeTraitExprBits.Kind = ExprKind; 1912bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer UnaryExprOrTypeTraitExprBits.IsType = true; 1913a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall Argument.Ty = TInfo; 1914ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor } 1915ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor 1916f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, Expr *E, 1917f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne QualType resultType, SourceLocation op, 1918f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne SourceLocation rp) : 1919f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_RValue, OK_Ordinary, 1920ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor false, // Never type-dependent (C++ [temp.dep.expr]p3). 1921ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor // Value-dependent if the argument is type-dependent. 1922bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor E->isTypeDependent(), 1923561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor E->isInstantiationDependent(), 1924bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor E->containsUnexpandedParameterPack()), 1925bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer OpLoc(op), RParenLoc(rp) { 1926bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer UnaryExprOrTypeTraitExprBits.Kind = ExprKind; 1927bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer UnaryExprOrTypeTraitExprBits.IsType = false; 1928ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor Argument.Ex = E; 1929d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl } 19300518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl 19310b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor /// \brief Construct an empty sizeof/alignof expression. 1932f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne explicit UnaryExprOrTypeTraitExpr(EmptyShell Empty) 1933f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne : Expr(UnaryExprOrTypeTraitExprClass, Empty) { } 19340b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 1935f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne UnaryExprOrTypeTrait getKind() const { 1936bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer return static_cast<UnaryExprOrTypeTrait>(UnaryExprOrTypeTraitExprBits.Kind); 1937f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne } 1938bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer void setKind(UnaryExprOrTypeTrait K) { UnaryExprOrTypeTraitExprBits.Kind = K;} 19390b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 1940bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer bool isArgumentType() const { return UnaryExprOrTypeTraitExprBits.IsType; } 19410518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType getArgumentType() const { 19425ab75172051a6d2ea71a80a79e81c65519fd3462John McCall return getArgumentTypeInfo()->getType(); 19435ab75172051a6d2ea71a80a79e81c65519fd3462John McCall } 1944a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *getArgumentTypeInfo() const { 19450518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl assert(isArgumentType() && "calling getArgumentType() when arg is expr"); 19465ab75172051a6d2ea71a80a79e81c65519fd3462John McCall return Argument.Ty; 19470518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 1948caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner Expr *getArgumentExpr() { 19490518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl assert(!isArgumentType() && "calling getArgumentExpr() when arg is type"); 1950d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl return static_cast<Expr*>(Argument.Ex); 19510518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 1952caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner const Expr *getArgumentExpr() const { 1953f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne return const_cast<UnaryExprOrTypeTraitExpr*>(this)->getArgumentExpr(); 1954caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner } 19550b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 1956bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer void setArgument(Expr *E) { 1957bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer Argument.Ex = E; 1958bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer UnaryExprOrTypeTraitExprBits.IsType = false; 1959bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer } 1960a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall void setArgument(TypeSourceInfo *TInfo) { 1961a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall Argument.Ty = TInfo; 1962bb8a897f350f46475f36140480e82289f6baa020Benjamin Kramer UnaryExprOrTypeTraitExprBits.IsType = true; 19630b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor } 19640b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 19650518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl /// Gets the argument type, or the type of the argument expression, whichever 19660518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl /// is appropriate. 19670518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType getTypeOfArgument() const { 19680518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl return isArgumentType() ? getArgumentType() : getArgumentExpr()->getType(); 19690518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 19700518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl 197176e773a443be9f006610f46529e07d4c8d857680Chris Lattner SourceLocation getOperatorLoc() const { return OpLoc; } 19720b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOperatorLoc(SourceLocation L) { OpLoc = L; } 19730b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 19740b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 19750b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1976866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek 1977aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 1978866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek return SourceRange(OpLoc, RParenLoc); 1979866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek } 19805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 19811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 1982f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne return T->getStmtClass() == UnaryExprOrTypeTraitExprClass; 19835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 19841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 198577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 198663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children(); 19875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 19885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 19895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 19905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Postfix Operators. 19915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 19925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 19935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting. 19945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ArraySubscriptExpr : public Expr { 199577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek enum { LHS, RHS, END_EXPR=2 }; 19961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Stmt* SubExprs[END_EXPR]; 19975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation RBracketLoc; 19985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 19992324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t, 2000f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 200173d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SourceLocation rbracketloc) 2002f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ArraySubscriptExprClass, t, VK, OK, 20032850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl lhs->isTypeDependent() || rhs->isTypeDependent(), 2004bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor lhs->isValueDependent() || rhs->isValueDependent(), 2005561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (lhs->isInstantiationDependent() || 2006561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhs->isInstantiationDependent()), 2007bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (lhs->containsUnexpandedParameterPack() || 2008bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhs->containsUnexpandedParameterPack())), 20092850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl RBracketLoc(rbracketloc) { 201073d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SubExprs[LHS] = lhs; 201173d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SubExprs[RHS] = rhs; 201273d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner } 20131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2014cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor /// \brief Create an empty array subscript expression. 2015cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor explicit ArraySubscriptExpr(EmptyShell Shell) 2016cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor : Expr(ArraySubscriptExprClass, Shell) { } 2017cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 20182324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// An array access can be written A[4] or 4[A] (both are equivalent). 20192324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// - getBase() and getIdx() always present the normalized view: A[4]. 20202324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// In this case getBase() returns "A" and getIdx() returns "4". 20212324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// - getLHS() and getRHS() present the syntactic view. e.g. for 20222324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// 4[A] getLHS() returns "4". 202333fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// Note: Because vector element access is also written A[4] we must 202433fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// predicate the format conversion in getBase and getIdx only on the 202533fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// the type of the RHS, as it is possible for the LHS to be a vector of 202633fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// integer type 20275549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); } 20285549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 2029cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 2030cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 20315549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); } 20325549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 2033cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 20341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getBase() { 20365549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS()); 203777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek } 20381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr *getBase() const { 20405549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS()); 20412324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek } 20421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getIdx() { 20445549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS()); 20452324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek } 20461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 204777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek const Expr *getIdx() const { 20485549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS()); 20491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 20501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2051aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 205277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek return SourceRange(getLHS()->getLocStart(), RBracketLoc); 20535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 20541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2055026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getRBracketLoc() const { return RBracketLoc; } 2056cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setRBracketLoc(SourceLocation L) { RBracketLoc = L; } 2057cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 20584f311183be3d923da9fbe8702c453688b4c426a9Daniel Dunbar SourceLocation getExprLoc() const LLVM_READONLY { return getBase()->getExprLoc(); } 20595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 20601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 20611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ArraySubscriptExprClass; 20625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 20631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 206477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 206563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 206663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 206763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 20685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 20695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 20705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2071b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]). 20721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CallExpr itself represents a normal function call, e.g., "f(x, 2)", 2073b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// while its subclasses may represent alternative syntax that (semantically) 20741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// results in a function call. For example, CXXOperatorCallExpr is 2075b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// a subclass for overloaded operator calls that use operator syntax, e.g., 2076b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// "str1 + str2" to resolve to a function call. 20775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CallExpr : public Expr { 2078cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne enum { FN=0, PREARGS_START=1 }; 20795549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt **SubExprs; 20805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned NumArgs; 20815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation RParenLoc; 20821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2083b4609806e9232593ece09ce08b630836e825865cDouglas Gregorprotected: 2084cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne // These versions of the constructor are for derived classes. 2085cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExpr(ASTContext& C, StmtClass SC, Expr *fn, unsigned NumPreArgs, 20863b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> args, QualType t, ExprValueKind VK, 2087cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SourceLocation rparenloc); 2088cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExpr(ASTContext &C, StmtClass SC, unsigned NumPreArgs, EmptyShell Empty); 2089cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne 2090cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne Stmt *getPreArg(unsigned i) { 2091cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne assert(i < getNumPreArgs() && "Prearg access out of range!"); 2092cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs[PREARGS_START+i]; 2093cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 2094cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne const Stmt *getPreArg(unsigned i) const { 2095cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne assert(i < getNumPreArgs() && "Prearg access out of range!"); 2096cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs[PREARGS_START+i]; 2097cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 2098cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne void setPreArg(unsigned i, Stmt *PreArg) { 2099cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne assert(i < getNumPreArgs() && "Prearg access out of range!"); 2100cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs[PREARGS_START+i] = PreArg; 2101cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 2102cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne 2103cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne unsigned getNumPreArgs() const { return CallExprBits.NumPreArgs; } 210442602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor 21055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 21063b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer CallExpr(ASTContext& C, Expr *fn, ArrayRef<Expr*> args, QualType t, 2107f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, SourceLocation rparenloc); 21081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21091f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor /// \brief Build an empty call expression. 2110ba0a9006dbc4814e1e35f82812cb5a1dad65e8b8Argyrios Kyrtzidis CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty); 21111f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 21125549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); } 21135549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCallee() { return cast<Expr>(SubExprs[FN]); } 211418b2515e1bf8c86a4900792692e42fe1296be28dChris Lattner void setCallee(Expr *F) { SubExprs[FN] = F; } 2115a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 2116d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes Decl *getCalleeDecl(); 2117d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes const Decl *getCalleeDecl() const { 2118d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes return const_cast<CallExpr*>(this)->getCalleeDecl(); 2119d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes } 2120d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes 2121a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu /// \brief If the callee is a FunctionDecl, return it. Otherwise return 0. 2122a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu FunctionDecl *getDirectCallee(); 2123bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner const FunctionDecl *getDirectCallee() const { 2124bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner return const_cast<CallExpr*>(this)->getDirectCallee(); 2125bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner } 2126a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 21275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getNumArgs - Return the number of actual arguments to this call. 21285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 21295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumArgs() const { return NumArgs; } 21301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2131aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \brief Retrieve the call arguments. 2132cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne Expr **getArgs() { 2133cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return reinterpret_cast<Expr **>(SubExprs+getNumPreArgs()+PREARGS_START); 2134cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 2135d0dcceae2a8ca0e37b5dd471a704de8583d49c95Richard Smith const Expr *const *getArgs() const { 2136d0dcceae2a8ca0e37b5dd471a704de8583d49c95Richard Smith return const_cast<CallExpr*>(this)->getArgs(); 2137d0dcceae2a8ca0e37b5dd471a704de8583d49c95Richard Smith } 2138ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 21395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getArg - Return the specified argument. 21405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Expr *getArg(unsigned Arg) { 21415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(Arg < NumArgs && "Arg access out of range!"); 2142cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return cast<Expr>(SubExprs[Arg+getNumPreArgs()+PREARGS_START]); 21435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 21445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const Expr *getArg(unsigned Arg) const { 21455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(Arg < NumArgs && "Arg access out of range!"); 2146cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return cast<Expr>(SubExprs[Arg+getNumPreArgs()+PREARGS_START]); 21475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 21481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2149934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff /// setArg - Set the specified argument. 2150934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff void setArg(unsigned Arg, Expr *ArgExpr) { 2151934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff assert(Arg < NumArgs && "Arg access out of range!"); 2152cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs[Arg+getNumPreArgs()+PREARGS_START] = ArgExpr; 2153934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff } 21541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2155d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// setNumArgs - This changes the number of arguments present in this call. 2156d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// Any orphaned expressions are deleted by this, and any new operands are set 2157d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// to null. 21588189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek void setNumArgs(ASTContext& C, unsigned NumArgs); 21591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21605549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek typedef ExprIterator arg_iterator; 21615549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek typedef ConstExprIterator const_arg_iterator; 21621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2163cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne arg_iterator arg_begin() { return SubExprs+PREARGS_START+getNumPreArgs(); } 2164cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne arg_iterator arg_end() { 2165cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs+PREARGS_START+getNumPreArgs()+getNumArgs(); 2166cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 2167cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne const_arg_iterator arg_begin() const { 2168cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs+PREARGS_START+getNumPreArgs(); 2169cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 2170cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne const_arg_iterator arg_end() const { 2171cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs+PREARGS_START+getNumPreArgs()+getNumArgs(); 2172cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 21731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getNumCommas - Return the number of commas that must have been present in 21755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// this function call. 21765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; } 21775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2178cb888967400a03504c88acedd5248d6778a82f46Chris Lattner /// isBuiltinCall - If this is a call to a builtin, return the builtin ID. If 2179cb888967400a03504c88acedd5248d6778a82f46Chris Lattner /// not, return 0. 2180180f47959a066795cc0f409433023af448bb0328Richard Smith unsigned isBuiltinCall() const; 21811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// getCallReturnType - Get the return type of the call expr. This is not 21831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// always the type of the expr itself, if the return type is a reference 21846dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson /// type. 21856dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson QualType getCallReturnType() const; 21861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2187d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner SourceLocation getRParenLoc() const { return RParenLoc; } 21881f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 2189866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek 2190aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY; 2191aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceLocation getLocStart() const LLVM_READONLY; 2192aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceLocation getLocEnd() const LLVM_READONLY; 21931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 21954bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return T->getStmtClass() >= firstCallExprConstant && 21964bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt T->getStmtClass() <= lastCallExprConstant; 21975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 219888a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 219977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 220063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 220163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], 220263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall &SubExprs[0]+NumArgs+getNumPreArgs()+PREARGS_START); 220363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 22045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 22055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2206ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner/// MemberExpr - [C99 6.5.2.3] Structure and Union Members. X->F and X.F. 22075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 22085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass MemberExpr : public Expr { 22096bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// Extra data stored in some member expressions. 22106857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth struct MemberNameQualifier { 22116857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// \brief The nested-name-specifier that qualifies the name, including 22126857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// source-location information. 22136857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth NestedNameSpecifierLoc QualifierLoc; 22146857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth 22156857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// \brief The DeclAccessPair through which the MemberDecl was found due to 22166857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// name qualifiers. 2217161755a09898c95d21bfff33707da9ca41cd53c5John McCall DeclAccessPair FoundDecl; 22186bb8017bb9e828d118e15e59d71c66bba323c364John McCall }; 22196bb8017bb9e828d118e15e59d71c66bba323c364John McCall 2220ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// Base - the expression for the base pointer or structure references. In 2221ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// X.F, this is "X". 22225549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Base; 22231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2224ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// MemberDecl - This is the decl being referenced by the field/member name. 2225ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// In X.F, this is the decl referenced by F. 2226f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *MemberDecl; 22271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22282577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// MemberDNLoc - Provides source/type location info for the 22292577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// declaration name embedded in MemberDecl. 22302577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameLoc MemberDNLoc; 22312577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 2232bbf4b22b3166e5065f4475006d83678e3e1d00a3Benjamin Kramer /// MemberLoc - This is the location of the member name. 2233bbf4b22b3166e5065f4475006d83678e3e1d00a3Benjamin Kramer SourceLocation MemberLoc; 2234bbf4b22b3166e5065f4475006d83678e3e1d00a3Benjamin Kramer 2235ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// IsArrow - True if this is "X->F", false if this is "X.F". 223683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor bool IsArrow : 1; 22371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 223883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief True if this member expression used a nested-name-specifier to 22396bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// refer to the member, e.g., "x->Base::f", or found its member via a using 22406bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// declaration. When true, a MemberNameQualifier 2241c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// structure is allocated immediately after the MemberExpr. 22426bb8017bb9e828d118e15e59d71c66bba323c364John McCall bool HasQualifierOrFoundDecl : 1; 22431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2244e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief True if this member expression specified a template keyword 2245e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// and/or a template argument list explicitly, e.g., x->f<int>, 2246e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// x->template f, x->template f<int>. 2247e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// When true, an ASTTemplateKWAndArgsInfo structure and its 2248e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// TemplateArguments (if any) are allocated immediately after 2249e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// the MemberExpr or, if the member expression also has a qualifier, 2250e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// after the MemberNameQualifier structure. 2251e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool HasTemplateKWAndArgsInfo : 1; 22521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22537cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// \brief True if this member expression refers to a method that 22547cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// was resolved from an overloaded set having size greater than 1. 22557cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool HadMultipleCandidates : 1; 22567cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara 225783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief Retrieve the qualifier that preceded the member name, if any. 22586bb8017bb9e828d118e15e59d71c66bba323c364John McCall MemberNameQualifier *getMemberQualifier() { 22596bb8017bb9e828d118e15e59d71c66bba323c364John McCall assert(HasQualifierOrFoundDecl); 22606bb8017bb9e828d118e15e59d71c66bba323c364John McCall return reinterpret_cast<MemberNameQualifier *> (this + 1); 226183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 226283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor 226383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief Retrieve the qualifier that preceded the member name, if any. 22646bb8017bb9e828d118e15e59d71c66bba323c364John McCall const MemberNameQualifier *getMemberQualifier() const { 2265c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return const_cast<MemberExpr *>(this)->getMemberQualifier(); 2266c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 22671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 2269f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl, 2270f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall const DeclarationNameInfo &NameInfo, QualType ty, 2271f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK) 2272f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(MemberExprClass, ty, VK, OK, 2273ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie base->isTypeDependent(), 2274561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor base->isValueDependent(), 2275561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor base->isInstantiationDependent(), 2276bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->containsUnexpandedParameterPack()), 2277bbf4b22b3166e5065f4475006d83678e3e1d00a3Benjamin Kramer Base(base), MemberDecl(memberdecl), MemberDNLoc(NameInfo.getInfo()), 2278bbf4b22b3166e5065f4475006d83678e3e1d00a3Benjamin Kramer MemberLoc(NameInfo.getLoc()), IsArrow(isarrow), 2279e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara HasQualifierOrFoundDecl(false), HasTemplateKWAndArgsInfo(false), 22807cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara HadMultipleCandidates(false) { 22812577743c5650c646fb705df01403707e94f2df04Abramo Bagnara assert(memberdecl->getDeclName() == NameInfo.getName()); 22822577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 22832577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 22842577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // NOTE: this constructor should be used only when it is known that 22852577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // the member name can not provide additional syntactic info 22862577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // (i.e., source locations for C++ operator names or type source info 2287e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara // for constructors, destructors and conversion operators). 22882577743c5650c646fb705df01403707e94f2df04Abramo Bagnara MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl, 2289f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall SourceLocation l, QualType ty, 2290f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK) 2291f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(MemberExprClass, ty, VK, OK, 2292bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->isTypeDependent(), base->isValueDependent(), 2293561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor base->isInstantiationDependent(), 2294bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->containsUnexpandedParameterPack()), 2295bbf4b22b3166e5065f4475006d83678e3e1d00a3Benjamin Kramer Base(base), MemberDecl(memberdecl), MemberDNLoc(), MemberLoc(l), 22962577743c5650c646fb705df01403707e94f2df04Abramo Bagnara IsArrow(isarrow), 2297e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara HasQualifierOrFoundDecl(false), HasTemplateKWAndArgsInfo(false), 22987cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara HadMultipleCandidates(false) {} 2299510190777c4bd53e960eea4665b204778fec1b64Eli Friedman 23001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static MemberExpr *Create(ASTContext &C, Expr *base, bool isarrow, 230140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 2302e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 2303161755a09898c95d21bfff33707da9ca41cd53c5John McCall ValueDecl *memberdecl, DeclAccessPair founddecl, 23042577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo MemberNameInfo, 2305d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *targs, 2306f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType ty, ExprValueKind VK, ExprObjectKind OK); 23071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 230888a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor void setBase(Expr *E) { Base = E; } 23095549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getBase() const { return cast<Expr>(Base); } 231057e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor 231157e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// \brief Retrieve the member declaration to which this expression refers. 231257e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// 231357e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// The returned declaration will either be a FieldDecl or (in C++) 231457e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// a CXXMethodDecl. 2315f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *getMemberDecl() const { return MemberDecl; } 2316f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman void setMemberDecl(ValueDecl *D) { MemberDecl = D; } 23171f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 23186bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// \brief Retrieves the declaration found by lookup. 2319161755a09898c95d21bfff33707da9ca41cd53c5John McCall DeclAccessPair getFoundDecl() const { 23206bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (!HasQualifierOrFoundDecl) 2321161755a09898c95d21bfff33707da9ca41cd53c5John McCall return DeclAccessPair::make(getMemberDecl(), 2322161755a09898c95d21bfff33707da9ca41cd53c5John McCall getMemberDecl()->getAccess()); 23236bb8017bb9e828d118e15e59d71c66bba323c364John McCall return getMemberQualifier()->FoundDecl; 23246bb8017bb9e828d118e15e59d71c66bba323c364John McCall } 23256bb8017bb9e828d118e15e59d71c66bba323c364John McCall 23261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Determines whether this member expression actually had 23270979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor /// a C++ nested-name-specifier prior to the name of the member, e.g., 23280979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor /// x->Base::foo. 23296bb8017bb9e828d118e15e59d71c66bba323c364John McCall bool hasQualifier() const { return getQualifier() != 0; } 23301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief If the member name was qualified, retrieves the 233283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// nested-name-specifier that precedes the member name. Otherwise, returns 233383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// NULL. 23341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump NestedNameSpecifier *getQualifier() const { 23356bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (!HasQualifierOrFoundDecl) 233683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return 0; 23371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 233840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return getMemberQualifier()->QualifierLoc.getNestedNameSpecifier(); 233940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor } 234040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor 2341ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief If the member name was qualified, retrieves the 234240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor /// nested-name-specifier that precedes the member name, with source-location 234340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor /// information. 234440d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc getQualifierLoc() const { 234540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (!hasQualifier()) 234640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return NestedNameSpecifierLoc(); 2347ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 234840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return getMemberQualifier()->QualifierLoc; 234983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 2350c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor 2351e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Return the optional template keyword and arguments info. 2352e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() { 2353e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) 2354e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return 0; 2355e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2356e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasQualifierOrFoundDecl) 2357e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return reinterpret_cast<ASTTemplateKWAndArgsInfo *>(this + 1); 2358e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2359e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return reinterpret_cast<ASTTemplateKWAndArgsInfo *>( 2360e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara getMemberQualifier() + 1); 2361e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2362e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2363e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Return the optional template keyword and arguments info. 2364e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const { 2365e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return const_cast<MemberExpr*>(this)->getTemplateKWAndArgsInfo(); 2366e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2367e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2368e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the template keyword preceding 2369e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// the member name, if any. 2370e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getTemplateKeywordLoc() const { 2371e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2372e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc(); 2373e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2374e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2375e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the left angle bracket starting the 2376e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// explicit template argument list following the member name, if any. 2377e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getLAngleLoc() const { 2378e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2379e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->LAngleLoc; 2380e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara } 2381e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2382e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Retrieve the location of the right angle bracket ending the 2383e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// explicit template argument list following the member name, if any. 2384e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation getRAngleLoc() const { 2385e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!HasTemplateKWAndArgsInfo) return SourceLocation(); 2386e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getTemplateKWAndArgsInfo()->RAngleLoc; 2387c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 23881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2389e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// Determines whether the member name was preceded by the template keyword. 2390e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } 2391e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2392e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// \brief Determines whether the member name was followed by an 2393e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /// explicit template argument list. 2394e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } 2395e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 2396d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// \brief Copies the template arguments (if present) into the given 2397d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// structure. 2398d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 2399096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (hasExplicitTemplateArgs()) 2400096832c5ed5b9106fa177ebc148489760c3bc496John McCall getExplicitTemplateArgs().copyInto(List); 2401096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 2402096832c5ed5b9106fa177ebc148489760c3bc496John McCall 2403096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that 2404096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// follow the member template name. This must only be called on an 2405096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// expression with explicit template arguments. 2406b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 2407e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara assert(hasExplicitTemplateArgs()); 2408e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return *getTemplateKWAndArgsInfo(); 2409096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 2410096832c5ed5b9106fa177ebc148489760c3bc496John McCall 2411096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that 2412096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// followed the member template name. This must only be called on 2413096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// an expression with explicit template arguments. 2414b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 2415096832c5ed5b9106fa177ebc148489760c3bc496John McCall return const_cast<MemberExpr *>(this)->getExplicitTemplateArgs(); 2416096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 2417096832c5ed5b9106fa177ebc148489760c3bc496John McCall 2418096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieves the optional explicit template arguments. 2419096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// This points to the same data as getExplicitTemplateArgs(), but 2420096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// returns null if there are no explicit template arguments. 2421b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const { 2422096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) return 0; 2423096832c5ed5b9106fa177ebc148489760c3bc496John McCall return &getExplicitTemplateArgs(); 2424d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall } 2425ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 2426c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Retrieve the template arguments provided as part of this 2427c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template-id. 2428833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc *getTemplateArgs() const { 2429e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!hasExplicitTemplateArgs()) 24301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return 0; 24311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2432096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().getTemplateArgs(); 2433c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 24341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2435c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Retrieve the number of template arguments provided as part of this 2436c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template-id. 24371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned getNumTemplateArgs() const { 2438e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara if (!hasExplicitTemplateArgs()) 24391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return 0; 24401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2441096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().NumTemplateArgs; 2442c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 24431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24442577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// \brief Retrieve the member declaration name info. 24452577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo getMemberNameInfo() const { 24462577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(MemberDecl->getDeclName(), 24472577743c5650c646fb705df01403707e94f2df04Abramo Bagnara MemberLoc, MemberDNLoc); 24482577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 24492577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 24505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isArrow() const { return IsArrow; } 24511f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setArrow(bool A) { IsArrow = A; } 24521f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 2453ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// getMemberLoc - Return the location of the "member", in X->F, it is the 2454ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// location of 'F'. 2455026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getMemberLoc() const { return MemberLoc; } 24561f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setMemberLoc(SourceLocation L) { MemberLoc = L; } 24575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2458aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY; 2459aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceLocation getLocStart() const LLVM_READONLY; 2460aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceLocation getLocEnd() const LLVM_READONLY; 2461ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 24624f311183be3d923da9fbe8702c453688b4c426a9Daniel Dunbar SourceLocation getExprLoc() const LLVM_READONLY { return MemberLoc; } 24635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 246475e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor /// \brief Determine whether the base of this explicit is implicit. 246575e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor bool isImplicitAccess() const { 246675e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor return getBase() && getBase()->isImplicitCXXThis(); 246775e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } 24687cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara 24697cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// \brief Returns true if this member expression refers to a method that 24707cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// was resolved from an overloaded set having size greater than 1. 24717cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool hadMultipleCandidates() const { 24727cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara return HadMultipleCandidates; 24737cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara } 24747cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// \brief Sets the flag telling whether this expression refers to 24757cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// a method that was resolved from an overloaded set having size 24767cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// greater than 1. 24777cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara void setHadMultipleCandidates(bool V = true) { 24787cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara HadMultipleCandidates = V; 24797cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara } 24807cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara 24811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 248283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return T->getStmtClass() == MemberExprClass; 24835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 24841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24851237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 248663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Base, &Base+1); } 24874045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis 24884045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTReader; 24894045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTStmtWriter; 24905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 24915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 24921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CompoundLiteralExpr - [C99 6.5.2.5] 2493aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff/// 2494aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffclass CompoundLiteralExpr : public Expr { 24950fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// LParenLoc - If non-null, this is the location of the left paren in a 24960fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// compound literal like "(int){4}". This can be null if this is a 24970fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// synthesized compound expression. 24980fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner SourceLocation LParenLoc; 24991d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall 25001d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall /// The type as written. This can be an incomplete array type, in 25011d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall /// which case the actual expression type will be different. 25023654c6993697a30af0c5a472963fe8c03e622b98Benjamin Kramer /// The int part of the pair stores whether this expr is file scope. 25033654c6993697a30af0c5a472963fe8c03e622b98Benjamin Kramer llvm::PointerIntPair<TypeSourceInfo *, 1, bool> TInfoAndScope; 25045549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Init; 2505aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffpublic: 250642f56b50062cd3b3c6b23fdb9053578ae9145664John McCall CompoundLiteralExpr(SourceLocation lparenloc, TypeSourceInfo *tinfo, 2507f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK, Expr *init, bool fileScope) 2508f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CompoundLiteralExprClass, T, VK, OK_Ordinary, 2509ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie tinfo->getType()->isDependentType(), 2510bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor init->isValueDependent(), 2511561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (init->isInstantiationDependent() || 2512561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor tinfo->getType()->isInstantiationDependentType()), 2513bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor init->containsUnexpandedParameterPack()), 25143654c6993697a30af0c5a472963fe8c03e622b98Benjamin Kramer LParenLoc(lparenloc), TInfoAndScope(tinfo, fileScope), Init(init) {} 25151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2516ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor /// \brief Construct an empty compound literal. 2517ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor explicit CompoundLiteralExpr(EmptyShell Empty) 2518ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor : Expr(CompoundLiteralExprClass, Empty) { } 2519ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 25205549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getInitializer() const { return cast<Expr>(Init); } 25215549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getInitializer() { return cast<Expr>(Init); } 2522ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setInitializer(Expr *E) { Init = E; } 2523e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff 25243654c6993697a30af0c5a472963fe8c03e622b98Benjamin Kramer bool isFileScope() const { return TInfoAndScope.getInt(); } 25253654c6993697a30af0c5a472963fe8c03e622b98Benjamin Kramer void setFileScope(bool FS) { TInfoAndScope.setInt(FS); } 2526ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 25270fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner SourceLocation getLParenLoc() const { return LParenLoc; } 2528ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setLParenLoc(SourceLocation L) { LParenLoc = L; } 2529ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 25303654c6993697a30af0c5a472963fe8c03e622b98Benjamin Kramer TypeSourceInfo *getTypeSourceInfo() const { 25313654c6993697a30af0c5a472963fe8c03e622b98Benjamin Kramer return TInfoAndScope.getPointer(); 25323654c6993697a30af0c5a472963fe8c03e622b98Benjamin Kramer } 25333654c6993697a30af0c5a472963fe8c03e622b98Benjamin Kramer void setTypeSourceInfo(TypeSourceInfo *tinfo) { 25343654c6993697a30af0c5a472963fe8c03e622b98Benjamin Kramer TInfoAndScope.setPointer(tinfo); 25353654c6993697a30af0c5a472963fe8c03e622b98Benjamin Kramer } 253642f56b50062cd3b3c6b23fdb9053578ae9145664John McCall 2537aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 25380fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner // FIXME: Init should never be null. 25390fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner if (!Init) 25400fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner return SourceRange(); 25410fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner if (LParenLoc.isInvalid()) 254273d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner return Init->getSourceRange(); 25430fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner return SourceRange(LParenLoc, Init->getLocEnd()); 254473d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner } 2545aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff 25461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 25471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CompoundLiteralExprClass; 2548aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff } 25491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25501237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 255163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Init, &Init+1); } 2552aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff}; 2553aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff 255449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CastExpr - Base class for type casts, including both implicit 255549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// casts (ImplicitCastExpr) and explicit casts that have some 255649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// representation in the source code (ExplicitCastExpr's derived 255749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// classes). 25580835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass CastExpr : public Expr { 2559cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlssonpublic: 25605baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall typedef clang::CastKind CastKind; 25611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2562cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlssonprivate: 25630835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis Stmt *Op; 2564409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson 25651d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall void CheckCastConsistency() const; 2566409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson 2567f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXBaseSpecifier * const *path_buffer() const { 2568f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return const_cast<CastExpr*>(this)->path_buffer(); 2569f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall } 2570f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CXXBaseSpecifier **path_buffer(); 2571f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2572654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis void setBasePathSize(unsigned basePathSize) { 2573654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis CastExprBits.BasePathSize = basePathSize; 2574654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis assert(CastExprBits.BasePathSize == basePathSize && 2575654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis "basePathSize doesn't fit in bits of CastExprBits.BasePathSize!"); 2576654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis } 2577654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis 25780835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisprotected: 2579f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CastExpr(StmtClass SC, QualType ty, ExprValueKind VK, 2580f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall const CastKind kind, Expr *op, unsigned BasePathSize) : 2581f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(SC, ty, VK, OK_Ordinary, 2582898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Cast expressions are type-dependent if the type is 2583898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // dependent (C++ [temp.dep.expr]p3). 2584898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ty->isDependentType(), 2585898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Cast expressions are value-dependent if the type is 2586898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // dependent or if the subexpression is value-dependent. 2587bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ty->isDependentType() || (op && op->isValueDependent()), 2588ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie (ty->isInstantiationDependentType() || 2589561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (op && op->isInstantiationDependent())), 2590bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (ty->containsUnexpandedParameterPack() || 2591bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor op->containsUnexpandedParameterPack())), 25928e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall Op(op) { 2593daa8e4e888758d55a7a759dd4a91b83921cef222John McCall assert(kind != CK_Invalid && "creating cast with invalid cast kind"); 25948e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CastExprBits.Kind = kind; 2595654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis setBasePathSize(BasePathSize); 25961d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall#ifndef NDEBUG 2597daa8e4e888758d55a7a759dd4a91b83921cef222John McCall CheckCastConsistency(); 25981d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall#endif 2599f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall } 26001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2601087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor /// \brief Construct an empty cast. 2602f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastExpr(StmtClass SC, EmptyShell Empty, unsigned BasePathSize) 26038e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall : Expr(SC, Empty) { 2604654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis setBasePathSize(BasePathSize); 26058e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall } 26061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 26070835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidispublic: 26088e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CastKind getCastKind() const { return (CastKind) CastExprBits.Kind; } 26098e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall void setCastKind(CastKind K) { CastExprBits.Kind = K; } 2610f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson const char *getCastKindName() const; 2611f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson 26120835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis Expr *getSubExpr() { return cast<Expr>(Op); } 26130835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis const Expr *getSubExpr() const { return cast<Expr>(Op); } 2614087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor void setSubExpr(Expr *E) { Op = E; } 2615087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor 26166eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// \brief Retrieve the cast subexpression as it was written in the source 26176eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// code, looking through any implicit casts or other intermediate nodes 26186eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// introduced by semantic analysis. 26196eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor Expr *getSubExprAsWritten(); 26206eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor const Expr *getSubExprAsWritten() const { 26216eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return const_cast<CastExpr *>(this)->getSubExprAsWritten(); 26226eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor } 262341b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson 2624f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall typedef CXXBaseSpecifier **path_iterator; 2625f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall typedef const CXXBaseSpecifier * const *path_const_iterator; 26268e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall bool path_empty() const { return CastExprBits.BasePathSize == 0; } 26278e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned path_size() const { return CastExprBits.BasePathSize; } 2628f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_iterator path_begin() { return path_buffer(); } 2629f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_iterator path_end() { return path_buffer() + path_size(); } 2630f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_const_iterator path_begin() const { return path_buffer(); } 2631f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_const_iterator path_end() const { return path_buffer() + path_size(); } 2632f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2633f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall void setCastPath(const CXXCastPath &Path); 263441b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson 26351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 26364bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return T->getStmtClass() >= firstCastExprConstant && 26374bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt T->getStmtClass() <= lastCastExprConstant; 26380835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis } 26391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 26400835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis // Iterators 264163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Op, &Op+1); } 26420835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis}; 26430835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis 264449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ImplicitCastExpr - Allows us to explicitly represent implicit type 264549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// conversions, which have no direct representation in the original 264649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// source code. For example: converting T[]->T*, void f()->void 264749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (*f)(), float->double, short->int, etc. 264849b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff/// 2649bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// In C, implicit casts always produce rvalues. However, in C++, an 2650bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// implicit cast whose result is being bound to a reference will be 2651906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// an lvalue or xvalue. For example: 2652bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// 2653bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @code 2654bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Base { }; 2655bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Derived : public Base { }; 2656906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// Derived &&ref(); 26571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// void f(Derived d) { 2658906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// Base& b = d; // initializer is an ImplicitCastExpr 2659906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// // to an lvalue of type Base 2660906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// Base&& r = ref(); // initializer is an ImplicitCastExpr 2661906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// // to an xvalue of type Base 2662bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// } 2663bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @endcode 26640835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ImplicitCastExpr : public CastExpr { 2665906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redlprivate: 2666f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ImplicitCastExpr(QualType ty, CastKind kind, Expr *op, 26675baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall unsigned BasePathLength, ExprValueKind VK) 2668f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, BasePathLength) { 26695baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall } 267090045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff 2671087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor /// \brief Construct an empty implicit cast. 2672f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall explicit ImplicitCastExpr(EmptyShell Shell, unsigned PathSize) 2673f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : CastExpr(ImplicitCastExprClass, Shell, PathSize) { } 2674f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2675f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 2676f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall enum OnStack_t { OnStack }; 2677f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ImplicitCastExpr(OnStack_t _, QualType ty, CastKind kind, Expr *op, 26785baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall ExprValueKind VK) 2679f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, 0) { 26805baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall } 2681f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2682f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static ImplicitCastExpr *Create(ASTContext &Context, QualType T, 2683f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastKind Kind, Expr *Operand, 2684f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXCastPath *BasePath, 26855baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall ExprValueKind Cat); 2686f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2687f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static ImplicitCastExpr *CreateEmpty(ASTContext &Context, unsigned PathSize); 2688087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor 2689aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 26900835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis return getSubExpr()->getSourceRange(); 26910835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis } 2692aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceLocation getLocStart() const LLVM_READONLY { 2693396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar return getSubExpr()->getLocStart(); 2694396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar } 2695aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceLocation getLocEnd() const LLVM_READONLY { 2696396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar return getSubExpr()->getLocEnd(); 2697396ec676b7a39665fa3a3f86f8e0520f8d7e93a8Daniel Dunbar } 269890045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff 26991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 27001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ImplicitCastExprClass; 270149b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff } 270249b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff}; 270349b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff 270491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCallinline Expr *Expr::IgnoreImpCasts() { 270591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall Expr *e = this; 270691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall while (ImplicitCastExpr *ice = dyn_cast<ImplicitCastExpr>(e)) 270791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall e = ice->getSubExpr(); 270891a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall return e; 270991a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall} 271091a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 271149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ExplicitCastExpr - An explicit cast written in the source 27121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// code. 271349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// 271449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This class is effectively an abstract class, because it provides 271549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// the basic representation of an explicitly-written cast without 271649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// specifying which kind of cast (C cast, functional cast, static 271749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast, etc.) was written; specific derived classes represent the 271849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// particular style of cast and its location information. 27195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 272049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// Unlike implicit casts, explicit cast nodes have two different 272149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// types: the type that was written into the source code, and the 272249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// actual type of the expression as determined by semantic 272349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// analysis. These types may differ slightly. For example, in C++ one 272449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// can cast to a reference type, which indicates that the resulting 2725906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// expression will be an lvalue or xvalue. The reference type, however, 2726906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// will not be used as the type of the expression. 27270835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ExplicitCastExpr : public CastExpr { 27289d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// TInfo - Source type info for the (written) type 27299d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// this expression is casting to. 27309d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo; 273149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 273249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorprotected: 2733f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExplicitCastExpr(StmtClass SC, QualType exprTy, ExprValueKind VK, 2734f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CastKind kind, Expr *op, unsigned PathSize, 2735f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall TypeSourceInfo *writtenTy) 2736f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : CastExpr(SC, exprTy, VK, kind, op, PathSize), TInfo(writtenTy) {} 273749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 2738db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty explicit cast. 2739f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ExplicitCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize) 2740f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : CastExpr(SC, Shell, PathSize) { } 2741db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 274249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorpublic: 27439d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// getTypeInfoAsWritten - Returns the type source info for the type 27449d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// that this expression is casting to. 27459d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *getTypeInfoAsWritten() const { return TInfo; } 27469d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall void setTypeInfoAsWritten(TypeSourceInfo *writtenTy) { TInfo = writtenTy; } 27479d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall 274849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// getTypeAsWritten - Returns the type that this expression is 274949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// casting to, as written in the source code. 27509d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall QualType getTypeAsWritten() const { return TInfo->getType(); } 275149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 27521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 27534bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return T->getStmtClass() >= firstExplicitCastExprConstant && 27544bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt T->getStmtClass() <= lastExplicitCastExprConstant; 275549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor } 275649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor}; 275749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 27586eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor/// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style 275949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast in C++ (C++ [expr.cast]), which uses the syntax 276049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (Type)expr. For example: @c (int)f. 27616eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregorclass CStyleCastExpr : public ExplicitCastExpr { 2762b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation LPLoc; // the location of the left paren 2763b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation RPLoc; // the location of the right paren 2764f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2765f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CStyleCastExpr(QualType exprTy, ExprValueKind vk, CastKind kind, Expr *op, 2766f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned PathSize, TypeSourceInfo *writtenTy, 276741b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson SourceLocation l, SourceLocation r) 2768f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : ExplicitCastExpr(CStyleCastExprClass, exprTy, vk, kind, op, PathSize, 276941b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson writtenTy), LPLoc(l), RPLoc(r) {} 277049b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff 2771db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty C-style explicit cast. 2772f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall explicit CStyleCastExpr(EmptyShell Shell, unsigned PathSize) 2773f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : ExplicitCastExpr(CStyleCastExprClass, Shell, PathSize) { } 2774f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2775f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 2776f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall static CStyleCastExpr *Create(ASTContext &Context, QualType T, 2777f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, CastKind K, 2778f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall Expr *Op, const CXXCastPath *BasePath, 2779f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall TypeSourceInfo *WrittenTy, SourceLocation L, 2780f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall SourceLocation R); 2781f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2782f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CStyleCastExpr *CreateEmpty(ASTContext &Context, unsigned PathSize); 2783db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 2784b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation getLParenLoc() const { return LPLoc; } 2785db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setLParenLoc(SourceLocation L) { LPLoc = L; } 2786db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 2787b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation getRParenLoc() const { return RPLoc; } 2788db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setRParenLoc(SourceLocation L) { RPLoc = L; } 2789db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 2790aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 2791b2f9e516327310d95840d442416084508f80c183Steve Naroff return SourceRange(LPLoc, getSubExpr()->getSourceRange().getEnd()); 27925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 27931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 27941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CStyleCastExprClass; 27955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 27965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 27975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 27983fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// \brief A builtin binary operation expression such as "x + y" or "x <= y". 27993fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 28003fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// This expression node kind describes a builtin binary operation, 28013fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// such as "x + y" for integer values "x" and "y". The operands will 28023fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// already have been converted to appropriate types (e.g., by 28033fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// performing promotions or conversions). 28043fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 28053fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// In C++, where operators may be overloaded, a different kind of 28063fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// expression node (CXXOperatorCallExpr) is used to express the 28073fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// invocation of an overloaded operator with operator syntax. Within 28083fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is 28093fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to store an expression "x + y" depends on the subexpressions 28103fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// for x and y. If neither x or y is type-dependent, and the "+" 28113fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// operator resolves to a built-in operation, BinaryOperator will be 28123fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to express the computation (x and y may still be 28133fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// value-dependent). If either x or y is type-dependent, or if the 28143fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// "+" resolves to an overloaded operator, CXXOperatorCallExpr will 28153fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// be used to express the computation. 28165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BinaryOperator : public Expr { 28175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 28185baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall typedef BinaryOperatorKind Opcode; 28195baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 282017d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattnerprivate: 28210799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall unsigned Opc : 6; 2822be9af1288881110e406b87914162eaa59f1e5918Lang Hames 2823be9af1288881110e406b87914162eaa59f1e5918Lang Hames // Records the FP_CONTRACT pragma status at the point that this binary 2824be9af1288881110e406b87914162eaa59f1e5918Lang Hames // operator was parsed. This bit is only meaningful for operations on 2825be9af1288881110e406b87914162eaa59f1e5918Lang Hames // floating point types. For all other types it should default to 2826be9af1288881110e406b87914162eaa59f1e5918Lang Hames // false. 2827be9af1288881110e406b87914162eaa59f1e5918Lang Hames unsigned FPContractable : 1; 28280799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall SourceLocation OpLoc; 28290799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall 283017d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner enum { LHS, RHS, END_EXPR }; 28315549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; 28321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 28331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 283417d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 2835f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 2836be9af1288881110e406b87914162eaa59f1e5918Lang Hames SourceLocation opLoc, bool fpContractable) 2837f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(BinaryOperatorClass, ResTy, VK, OK, 2838898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor lhs->isTypeDependent() || rhs->isTypeDependent(), 2839bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor lhs->isValueDependent() || rhs->isValueDependent(), 2840561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (lhs->isInstantiationDependent() || 2841561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhs->isInstantiationDependent()), 2842bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (lhs->containsUnexpandedParameterPack() || 2843bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhs->containsUnexpandedParameterPack())), 2844be9af1288881110e406b87914162eaa59f1e5918Lang Hames Opc(opc), FPContractable(fpContractable), OpLoc(opLoc) { 28451237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 28461237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 28471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(!isCompoundAssignmentOp() && 28485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Use ArithAssignBinaryOperator for compound assignments"); 28495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 28505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2851db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty binary operator. 28521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit BinaryOperator(EmptyShell Empty) 28532de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall : Expr(BinaryOperatorClass, Empty), Opc(BO_Comma) { } 2854db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 28554f311183be3d923da9fbe8702c453688b4c426a9Daniel Dunbar SourceLocation getExprLoc() const LLVM_READONLY { return OpLoc; } 285617d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation getOperatorLoc() const { return OpLoc; } 2857db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setOperatorLoc(SourceLocation L) { OpLoc = L; } 2858db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 28590799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Opcode getOpcode() const { return static_cast<Opcode>(Opc); } 2860db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setOpcode(Opcode O) { Opc = O; } 2861db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 28625549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 2863db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 28645549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 2865db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 2866db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 2867aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 28685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd()); 28695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 28701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 28725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// corresponds to, e.g. "<<=". 28730bea86307eb8c16339315a1e261fc490eb505c5bDavid Blaikie static StringRef getOpcodeStr(Opcode Op); 28745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 28750bea86307eb8c16339315a1e261fc490eb505c5bDavid Blaikie StringRef getOpcodeStr() const { return getOpcodeStr(getOpcode()); } 2876a84c02d0f4d63975a1c52b9bb8308d88e9d79352Ted Kremenek 2877063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// \brief Retrieve the binary opcode that corresponds to the given 2878063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// overloaded operator. 2879063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static Opcode getOverloadedOpcode(OverloadedOperatorKind OO); 2880063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 2881063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// \brief Retrieve the overloaded operator kind that corresponds to 2882063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// the given binary opcode. 2883063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); 2884063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 28855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// predicates to categorize the respective opcodes. 2886200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl bool isPtrMemOp() const { return Opc == BO_PtrMemD || Opc == BO_PtrMemI; } 28872de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall bool isMultiplicativeOp() const { return Opc >= BO_Mul && Opc <= BO_Rem; } 28882de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isAdditiveOp(Opcode Opc) { return Opc == BO_Add || Opc==BO_Sub; } 28890799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isAdditiveOp() const { return isAdditiveOp(getOpcode()); } 28902de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isShiftOp(Opcode Opc) { return Opc == BO_Shl || Opc == BO_Shr; } 28910799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isShiftOp() const { return isShiftOp(getOpcode()); } 2892aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl 28932de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isBitwiseOp(Opcode Opc) { return Opc >= BO_And && Opc <= BO_Or; } 28940799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isBitwiseOp() const { return isBitwiseOp(getOpcode()); } 2895f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 28962de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isRelationalOp(Opcode Opc) { return Opc >= BO_LT && Opc<=BO_GE; } 28970799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isRelationalOp() const { return isRelationalOp(getOpcode()); } 2898f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 28992de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isEqualityOp(Opcode Opc) { return Opc == BO_EQ || Opc == BO_NE; } 29000799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isEqualityOp() const { return isEqualityOp(getOpcode()); } 29011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29022de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isComparisonOp(Opcode Opc) { return Opc >= BO_LT && Opc<=BO_NE; } 29030799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isComparisonOp() const { return isComparisonOp(getOpcode()); } 2904aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl 29052de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isLogicalOp(Opcode Opc) { return Opc == BO_LAnd || Opc==BO_LOr; } 29060799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isLogicalOp() const { return isLogicalOp(getOpcode()); } 2907f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 29080e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall static bool isAssignmentOp(Opcode Opc) { 29090e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall return Opc >= BO_Assign && Opc <= BO_OrAssign; 29100e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall } 29110e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall bool isAssignmentOp() const { return isAssignmentOp(getOpcode()); } 29120e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall 29130e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall static bool isCompoundAssignmentOp(Opcode Opc) { 29142de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Opc > BO_Assign && Opc <= BO_OrAssign; 29152de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 29160e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall bool isCompoundAssignmentOp() const { 29170e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall return isCompoundAssignmentOp(getOpcode()); 29180e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall } 29194b9c2d235fb9449e249d74f48ecfec601650de93John McCall static Opcode getOpForCompoundAssignment(Opcode Opc) { 29204b9c2d235fb9449e249d74f48ecfec601650de93John McCall assert(isCompoundAssignmentOp(Opc)); 2921b92e5d0acbb21e57498fcc4157e108a50c82b857John McCall if (Opc >= BO_AndAssign) 2922b92e5d0acbb21e57498fcc4157e108a50c82b857John McCall return Opcode(unsigned(Opc) - BO_AndAssign + BO_And); 29234b9c2d235fb9449e249d74f48ecfec601650de93John McCall else 29244b9c2d235fb9449e249d74f48ecfec601650de93John McCall return Opcode(unsigned(Opc) - BO_MulAssign + BO_Mul); 29254b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 29260e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall 29270e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall static bool isShiftAssignOp(Opcode Opc) { 29282de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Opc == BO_ShlAssign || Opc == BO_ShrAssign; 29292de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 29300e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall bool isShiftAssignOp() const { 29310e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall return isShiftAssignOp(getOpcode()); 29320e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall } 29331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *S) { 29354bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return S->getStmtClass() >= firstBinaryOperatorConstant && 29364bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt S->getStmtClass() <= lastBinaryOperatorConstant; 29375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 29381237c673c07f9d827129ba02720108816abde562Ted Kremenek 29391237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 294063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 294163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 294263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 29431237c673c07f9d827129ba02720108816abde562Ted Kremenek 2944be9af1288881110e406b87914162eaa59f1e5918Lang Hames // Set the FP contractability status of this operator. Only meaningful for 2945be9af1288881110e406b87914162eaa59f1e5918Lang Hames // operations on floating point types. 2946be9af1288881110e406b87914162eaa59f1e5918Lang Hames void setFPContractable(bool FPC) { FPContractable = FPC; } 2947be9af1288881110e406b87914162eaa59f1e5918Lang Hames 2948be9af1288881110e406b87914162eaa59f1e5918Lang Hames // Get the FP contractability status of this operator. Only meaningful for 2949be9af1288881110e406b87914162eaa59f1e5918Lang Hames // operations on floating point types. 2950be9af1288881110e406b87914162eaa59f1e5918Lang Hames bool isFPContractable() const { return FPContractable; } 2951be9af1288881110e406b87914162eaa59f1e5918Lang Hames 29525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 295317d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 2954f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 2955be9af1288881110e406b87914162eaa59f1e5918Lang Hames SourceLocation opLoc, bool fpContractable, bool dead2) 2956f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CompoundAssignOperatorClass, ResTy, VK, OK, 29572333f7727f97018d6742e1e0938133bcfad967abEli Friedman lhs->isTypeDependent() || rhs->isTypeDependent(), 2958bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor lhs->isValueDependent() || rhs->isValueDependent(), 2959561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (lhs->isInstantiationDependent() || 2960561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhs->isInstantiationDependent()), 2961bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (lhs->containsUnexpandedParameterPack() || 2962bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhs->containsUnexpandedParameterPack())), 2963be9af1288881110e406b87914162eaa59f1e5918Lang Hames Opc(opc), FPContractable(fpContractable), OpLoc(opLoc) { 29641237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 29651237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 29665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2967ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 29681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump BinaryOperator(StmtClass SC, EmptyShell Empty) 29692de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall : Expr(SC, Empty), Opc(BO_MulAssign) { } 29705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 29715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 29725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep 29735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// track of the type the operation is performed in. Due to the semantics of 2974ec5bc81fd55bfcc26fc4bde6d5e33113d94c2209Zhongxing Xu/// these operators, the operands are promoted, the arithmetic performed, an 29755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// implicit conversion back to the result type done, then the assignment takes 29765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// place. This captures the intermediate type which the computation is done 29775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// in. 29785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CompoundAssignOperator : public BinaryOperator { 2979ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType ComputationLHSType; 2980ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType ComputationResultType; 29815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 2982f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResType, 2983f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 2984f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType CompLHSType, QualType CompResultType, 2985be9af1288881110e406b87914162eaa59f1e5918Lang Hames SourceLocation OpLoc, bool fpContractable) 2986be9af1288881110e406b87914162eaa59f1e5918Lang Hames : BinaryOperator(lhs, rhs, opc, ResType, VK, OK, OpLoc, fpContractable, 2987be9af1288881110e406b87914162eaa59f1e5918Lang Hames true), 2988ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman ComputationLHSType(CompLHSType), 2989ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman ComputationResultType(CompResultType) { 29901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(isCompoundAssignmentOp() && 29915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Only should be used for compound assignments"); 29925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 29935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2994ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor /// \brief Build an empty compound assignment operator expression. 2995ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor explicit CompoundAssignOperator(EmptyShell Empty) 2996ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor : BinaryOperator(CompoundAssignOperatorClass, Empty) { } 2997ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 2998ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // The two computation types are the type the LHS is converted 2999ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // to for the computation and the type of the result; the two are 3000ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // distinct in a few cases (specifically, int+=ptr and ptr-=ptr). 3001ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType getComputationLHSType() const { return ComputationLHSType; } 3002ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setComputationLHSType(QualType T) { ComputationLHSType = T; } 3003ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 3004ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType getComputationResultType() const { return ComputationResultType; } 3005ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setComputationResultType(QualType T) { ComputationResultType = T; } 3006ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 30071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *S) { 30081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return S->getStmtClass() == CompoundAssignOperatorClass; 30095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 30105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 30115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 301256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// AbstractConditionalOperator - An abstract base class for 301356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// ConditionalOperator and BinaryConditionalOperator. 301456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass AbstractConditionalOperator : public Expr { 301556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation QuestionLoc, ColonLoc; 301656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall friend class ASTStmtReader; 301756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 301856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallprotected: 301956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall AbstractConditionalOperator(StmtClass SC, QualType T, 302056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall ExprValueKind VK, ExprObjectKind OK, 3021561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool TD, bool VD, bool ID, 302256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall bool ContainsUnexpandedParameterPack, 302356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation qloc, 302456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation cloc) 3025561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Expr(SC, T, VK, OK, TD, VD, ID, ContainsUnexpandedParameterPack), 302656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall QuestionLoc(qloc), ColonLoc(cloc) {} 302756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 302856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall AbstractConditionalOperator(StmtClass SC, EmptyShell Empty) 302956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : Expr(SC, Empty) { } 303056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 303156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallpublic: 303256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getCond - Return the expression representing the condition for 303356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the ?: operator. 303456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getCond() const; 303556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 303656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getTrueExpr - Return the subexpression representing the value of 303756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the expression if the condition evaluates to true. 303856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getTrueExpr() const; 303956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 304056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getFalseExpr - Return the subexpression representing the value of 304156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the expression if the condition evaluates to false. This is 304256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the same as getRHS. 304356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getFalseExpr() const; 304456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 304556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation getQuestionLoc() const { return QuestionLoc; } 304656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation getColonLoc() const { return ColonLoc; } 304756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 304856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const Stmt *T) { 304956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return T->getStmtClass() == ConditionalOperatorClass || 305056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall T->getStmtClass() == BinaryConditionalOperatorClass; 305156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 305256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall}; 305356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 305456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// ConditionalOperator - The ?: ternary operator. The GNU "missing 305556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// middle" extension is a BinaryConditionalOperator. 305656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass ConditionalOperator : public AbstractConditionalOperator { 30571237c673c07f9d827129ba02720108816abde562Ted Kremenek enum { COND, LHS, RHS, END_EXPR }; 30585549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 305956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 306056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall friend class ASTStmtReader; 30615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 306247e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor ConditionalOperator(Expr *cond, SourceLocation QLoc, Expr *lhs, 306356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation CLoc, Expr *rhs, 30640943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall QualType t, ExprValueKind VK, ExprObjectKind OK) 306556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : AbstractConditionalOperator(ConditionalOperatorClass, t, VK, OK, 3066898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // FIXME: the type of the conditional operator doesn't 3067898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // depend on the type of the conditional, but the standard 3068898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // seems to imply that it could. File a bug! 306956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (lhs->isTypeDependent() || rhs->isTypeDependent()), 307056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (cond->isValueDependent() || lhs->isValueDependent() || 307156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall rhs->isValueDependent()), 3072561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (cond->isInstantiationDependent() || 3073561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor lhs->isInstantiationDependent() || 3074561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhs->isInstantiationDependent()), 3075bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (cond->containsUnexpandedParameterPack() || 307656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall lhs->containsUnexpandedParameterPack() || 307756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall rhs->containsUnexpandedParameterPack()), 307856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall QLoc, CLoc) { 30791237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[COND] = cond; 30801237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 30811237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 30821237c673c07f9d827129ba02720108816abde562Ted Kremenek } 30835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3084ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor /// \brief Build an empty conditional operator. 3085ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor explicit ConditionalOperator(EmptyShell Empty) 308656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : AbstractConditionalOperator(ConditionalOperatorClass, Empty) { } 3087ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 3088395a2abf0028968d85958610e393e067885dc14fTed Kremenek // getCond - Return the expression representing the condition for 308956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the ?: operator. 30905549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 3091395a2abf0028968d85958610e393e067885dc14fTed Kremenek 309256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getTrueExpr - Return the subexpression representing the value of 309356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the expression if the condition evaluates to true. 309456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getTrueExpr() const { return cast<Expr>(SubExprs[LHS]); } 30951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 309656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getFalseExpr - Return the subexpression representing the value of 309756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the expression if the condition evaluates to false. This is 309856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the same as getRHS. 30995549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); } 3100ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 310156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 31025549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 310347e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor 3104aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 31055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd()); 31065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 31071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 31081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ConditionalOperatorClass; 31095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 31101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 31111237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 311263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 311363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 311463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 31155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 31165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 311756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// BinaryConditionalOperator - The GNU extension to the conditional 311856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// operator which allows the middle operand to be omitted. 311956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// 312056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// This is a different expression kind on the assumption that almost 312156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// every client ends up needing to know that these are different. 312256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass BinaryConditionalOperator : public AbstractConditionalOperator { 312356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall enum { COMMON, COND, LHS, RHS, NUM_SUBEXPRS }; 312456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 312556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// - the common condition/left-hand-side expression, which will be 312656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// evaluated as the opaque value 312756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// - the condition, expressed in terms of the opaque value 312856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// - the left-hand-side, expressed in terms of the opaque value 312956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// - the right-hand-side 313056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Stmt *SubExprs[NUM_SUBEXPRS]; 313156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValueExpr *OpaqueValue; 313256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 313356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall friend class ASTStmtReader; 313456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallpublic: 313556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall BinaryConditionalOperator(Expr *common, OpaqueValueExpr *opaqueValue, 313656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *cond, Expr *lhs, Expr *rhs, 313756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation qloc, SourceLocation cloc, 313856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall QualType t, ExprValueKind VK, ExprObjectKind OK) 313956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : AbstractConditionalOperator(BinaryConditionalOperatorClass, t, VK, OK, 314056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (common->isTypeDependent() || rhs->isTypeDependent()), 314156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (common->isValueDependent() || rhs->isValueDependent()), 3142561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (common->isInstantiationDependent() || 3143561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhs->isInstantiationDependent()), 314456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (common->containsUnexpandedParameterPack() || 314556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall rhs->containsUnexpandedParameterPack()), 314656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall qloc, cloc), 314756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValue(opaqueValue) { 314856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SubExprs[COMMON] = common; 314956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SubExprs[COND] = cond; 315056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SubExprs[LHS] = lhs; 315156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SubExprs[RHS] = rhs; 315297df54e0c075bc8d6a869597e771dad0c11a2180Douglas Gregor assert(OpaqueValue->getSourceExpr() == common && "Wrong opaque value"); 315356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 315456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 315556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief Build an empty conditional operator. 315656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall explicit BinaryConditionalOperator(EmptyShell Empty) 315756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : AbstractConditionalOperator(BinaryConditionalOperatorClass, Empty) { } 315856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 315956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getCommon - Return the common expression, written to the 316056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// left of the condition. The opaque value will be bound to the 316156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// result of this expression. 316256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getCommon() const { return cast<Expr>(SubExprs[COMMON]); } 316356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 316456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getOpaqueValue - Return the opaque value placeholder. 316556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValueExpr *getOpaqueValue() const { return OpaqueValue; } 316656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 316756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getCond - Return the condition expression; this is defined 316856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// in terms of the opaque value. 316956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 317056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 317156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getTrueExpr - Return the subexpression which will be 317256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// evaluated if the condition evaluates to true; this is defined 317356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// in terms of the opaque value. 317456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getTrueExpr() const { 317556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<Expr>(SubExprs[LHS]); 317656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 317756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 317856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getFalseExpr - Return the subexpression which will be 317956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// evaluated if the condnition evaluates to false; this is 318056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// defined in terms of the opaque value. 318156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getFalseExpr() const { 318256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<Expr>(SubExprs[RHS]); 318356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 3184ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3185aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 318656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return SourceRange(getCommon()->getLocStart(), getFalseExpr()->getLocEnd()); 318756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 318856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const Stmt *T) { 318956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return T->getStmtClass() == BinaryConditionalOperatorClass; 319056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 319156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 319256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // Iterators 319356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall child_range children() { 319456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return child_range(SubExprs, SubExprs + NUM_SUBEXPRS); 319556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 319656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall}; 319756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 319856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallinline Expr *AbstractConditionalOperator::getCond() const { 319956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this)) 320056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return co->getCond(); 320156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<BinaryConditionalOperator>(this)->getCond(); 320256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall} 320356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 320456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallinline Expr *AbstractConditionalOperator::getTrueExpr() const { 320556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this)) 320656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return co->getTrueExpr(); 320756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<BinaryConditionalOperator>(this)->getTrueExpr(); 320856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall} 320956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 321056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallinline Expr *AbstractConditionalOperator::getFalseExpr() const { 321156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this)) 321256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return co->getFalseExpr(); 321356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<BinaryConditionalOperator>(this)->getFalseExpr(); 321456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall} 321556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 32166481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner/// AddrLabelExpr - The GNU address of label extension, representing &&label. 32176481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattnerclass AddrLabelExpr : public Expr { 32185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation AmpAmpLoc, LabelLoc; 3219ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *Label; 32205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 3221ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelDecl *L, 32226481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner QualType t) 3223561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Expr(AddrLabelExprClass, t, VK_RValue, OK_Ordinary, false, false, false, 3224561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false), 32252333f7727f97018d6742e1e0938133bcfad967abEli Friedman AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {} 32261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32277d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor /// \brief Build an empty address of a label expression. 32281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit AddrLabelExpr(EmptyShell Empty) 32297d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor : Expr(AddrLabelExprClass, Empty) { } 32307d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 32317d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; } 32327d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; } 32337d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor SourceLocation getLabelLoc() const { return LabelLoc; } 32347d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setLabelLoc(SourceLocation L) { LabelLoc = L; } 32357d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 3236aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 32375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(AmpAmpLoc, LabelLoc); 32385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 32391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3240ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *getLabel() const { return Label; } 3241ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner void setLabel(LabelDecl *L) { Label = L; } 32427d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 32435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 32441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == AddrLabelExprClass; 32455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 32461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32471237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 324863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 32495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 3250ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner 3251ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}). 3252ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// The StmtExpr contains a single CompoundStmt node, which it evaluates and 3253ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// takes the value of the last subexpression. 3254f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall/// 3255f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall/// A StmtExpr is always an r-value; values "returned" out of a 3256f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall/// StmtExpr will be copied. 3257ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerclass StmtExpr : public Expr { 32585549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *SubStmt; 3259ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner SourceLocation LParenLoc, RParenLoc; 3260ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerpublic: 32612333f7727f97018d6742e1e0938133bcfad967abEli Friedman // FIXME: Does type-dependence need to be computed differently? 3262561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor // FIXME: Do we need to compute instantiation instantiation-dependence for 3263561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor // statements? (ugh!) 3264d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff StmtExpr(CompoundStmt *substmt, QualType T, 3265d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff SourceLocation lp, SourceLocation rp) : 3266f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(StmtExprClass, T, VK_RValue, OK_Ordinary, 3267561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor T->isDependentType(), false, false, false), 32682333f7727f97018d6742e1e0938133bcfad967abEli Friedman SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) { } 32691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32706a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor /// \brief Build an empty statement expression. 32716a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { } 32726a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor 32735549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); } 32745549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); } 32756a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setSubStmt(CompoundStmt *S) { SubStmt = S; } 32766a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor 3277aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 3278ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner return SourceRange(LParenLoc, RParenLoc); 3279ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner } 32801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3281026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getLParenLoc() const { return LParenLoc; } 32826a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setLParenLoc(SourceLocation L) { LParenLoc = L; } 3283026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getRParenLoc() const { return RParenLoc; } 32846a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 32851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3286ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner static bool classof(const Stmt *T) { 32871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == StmtExprClass; 3288ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner } 32891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32901237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 329163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&SubStmt, &SubStmt+1); } 3292ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner}; 3293ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner 3294d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff 3295d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// ShuffleVectorExpr - clang-specific builtin-in function 3296d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// __builtin_shufflevector. 3297d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// This AST node represents a operator that does a constant 3298d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// shuffle, similar to LLVM's shufflevector instruction. It takes 3299d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// two vectors and a variable number of constant indices, 3300d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// and returns the appropriately shuffled vector. 3301d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanclass ShuffleVectorExpr : public Expr { 3302d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman SourceLocation BuiltinLoc, RParenLoc; 3303d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 3304d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // SubExprs - the list of values passed to the __builtin_shufflevector 3305d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // function. The first two are vectors, and the rest are constant 3306d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // indices. The number of values in this list is always 3307d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // 2+the number of indices in the vector type. 33085549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt **SubExprs; 3309d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman unsigned NumExprs; 3310d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 3311d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanpublic: 33123b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ShuffleVectorExpr(ASTContext &C, ArrayRef<Expr*> args, QualType Type, 33133b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer SourceLocation BLoc, SourceLocation RP); 331494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 331594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor /// \brief Build an empty vector-shuffle expression. 33161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ShuffleVectorExpr(EmptyShell Empty) 331794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor : Expr(ShuffleVectorExprClass, Empty), SubExprs(0) { } 331894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 331994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 332094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 33211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 332294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 332394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 332494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 3325aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 3326d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman return SourceRange(BuiltinLoc, RParenLoc); 3327d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 3328d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman static bool classof(const Stmt *T) { 33291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ShuffleVectorExprClass; 3330d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 33311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3332d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// getNumSubExprs - Return the size of the SubExprs array. This includes the 3333d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// constant expression, the actual arguments passed in, and the function 3334d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// pointers. 3335d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman unsigned getNumSubExprs() const { return NumExprs; } 33361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3337aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \brief Retrieve the array of expressions. 3338aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Expr **getSubExprs() { return reinterpret_cast<Expr **>(SubExprs); } 3339ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3340d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// getExpr - Return the Expr at the specified index. 3341d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman Expr *getExpr(unsigned Index) { 3342d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman assert((Index < NumExprs) && "Arg access out of range!"); 33435549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Index]); 3344d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 3345d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman const Expr *getExpr(unsigned Index) const { 3346d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman assert((Index < NumExprs) && "Arg access out of range!"); 33475549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Index]); 3348d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 33491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3350888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman void setExprs(ASTContext &C, Expr ** Exprs, unsigned NumExprs); 335194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 335288920d1a84dc63a3722b1f2b1fb5926c44bd81abRoman Divacky unsigned getShuffleMaskIdx(ASTContext &Ctx, unsigned N) const { 3353dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman assert((N < NumExprs - 2) && "Shuffle idx out of range!"); 3354a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith return getExpr(N+2)->EvaluateKnownConstInt(Ctx).getZExtValue(); 3355d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 33561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3357d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // Iterators 335863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 335963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+NumExprs); 336063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 3361d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman}; 3362d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 3363d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// ChooseExpr - GNU builtin-in function __builtin_choose_expr. 33641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// This AST node is similar to the conditional operator (?:) in C, with 3365d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// the following exceptions: 33667976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the test expression must be a integer constant expression. 33677976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the expression returned acts like the chosen subexpression in every 33687976932a1c256d447316ffac58e9821417725e34Eli Friedman/// visible way: the type is the same as that of the chosen subexpression, 33697976932a1c256d447316ffac58e9821417725e34Eli Friedman/// and all predicates (whether it's an l-value, whether it's an integer 33707976932a1c256d447316ffac58e9821417725e34Eli Friedman/// constant expression, etc.) return the same result as for the chosen 33717976932a1c256d447316ffac58e9821417725e34Eli Friedman/// sub-expression. 3372d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffclass ChooseExpr : public Expr { 33731237c673c07f9d827129ba02720108816abde562Ted Kremenek enum { COND, LHS, RHS, END_EXPR }; 33745549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 3375d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff SourceLocation BuiltinLoc, RParenLoc; 3376d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffpublic: 3377f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, 3378f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType t, ExprValueKind VK, ExprObjectKind OK, 3379ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor SourceLocation RP, bool TypeDependent, bool ValueDependent) 3380bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(ChooseExprClass, t, VK, OK, TypeDependent, ValueDependent, 3381561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (cond->isInstantiationDependent() || 3382561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor lhs->isInstantiationDependent() || 3383561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhs->isInstantiationDependent()), 3384bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (cond->containsUnexpandedParameterPack() || 3385bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor lhs->containsUnexpandedParameterPack() || 3386bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhs->containsUnexpandedParameterPack())), 33871237c673c07f9d827129ba02720108816abde562Ted Kremenek BuiltinLoc(BLoc), RParenLoc(RP) { 33881237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[COND] = cond; 33891237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 33901237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 33911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 33927976932a1c256d447316ffac58e9821417725e34Eli Friedman 339344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor /// \brief Build an empty __builtin_choose_expr. 339444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { } 339544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 33967976932a1c256d447316ffac58e9821417725e34Eli Friedman /// isConditionTrue - Return whether the condition is true (i.e. not 33977976932a1c256d447316ffac58e9821417725e34Eli Friedman /// equal to zero). 33984ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool isConditionTrue(const ASTContext &C) const; 33997976932a1c256d447316ffac58e9821417725e34Eli Friedman 34007976932a1c256d447316ffac58e9821417725e34Eli Friedman /// getChosenSubExpr - Return the subexpression chosen according to the 34017976932a1c256d447316ffac58e9821417725e34Eli Friedman /// condition. 34024ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad Expr *getChosenSubExpr(const ASTContext &C) const { 34037976932a1c256d447316ffac58e9821417725e34Eli Friedman return isConditionTrue(C) ? getLHS() : getRHS(); 34047976932a1c256d447316ffac58e9821417725e34Eli Friedman } 34057976932a1c256d447316ffac58e9821417725e34Eli Friedman 34065549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 340744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setCond(Expr *E) { SubExprs[COND] = E; } 34085549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 340944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 34105549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 341144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 341244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 341344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 341444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 34151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 341644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 341744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 34181237c673c07f9d827129ba02720108816abde562Ted Kremenek 3419aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 3420d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff return SourceRange(BuiltinLoc, RParenLoc); 3421d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff } 3422d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff static bool classof(const Stmt *T) { 34231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ChooseExprClass; 3424d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff } 34251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 34261237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 342763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 342863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 342963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 3430d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff}; 3431d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff 34322d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// GNUNullExpr - Implements the GNU __null extension, which is a name 34332d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// for a null pointer constant that has integral type (e.g., int or 34342d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// long) and is the same size and alignment as a pointer. The __null 34352d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// extension is typically only used by system headers, which define 34362d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// NULL as __null in C++ rather than using 0 (which is an integer 34372d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// that may not match the size of a pointer). 34382d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorclass GNUNullExpr : public Expr { 34392d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor /// TokenLoc - The location of the __null keyword. 34402d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor SourceLocation TokenLoc; 34412d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 34422d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorpublic: 34431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump GNUNullExpr(QualType Ty, SourceLocation Loc) 3444561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Expr(GNUNullExprClass, Ty, VK_RValue, OK_Ordinary, false, false, false, 3445561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false), 3446f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall TokenLoc(Loc) { } 34472d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 344844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor /// \brief Build an empty GNU __null expression. 344944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { } 345044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 34512d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor /// getTokenLocation - The location of the __null token. 34522d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor SourceLocation getTokenLocation() const { return TokenLoc; } 345344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setTokenLocation(SourceLocation L) { TokenLoc = L; } 34542d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 3455aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 34562d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor return SourceRange(TokenLoc); 34572d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } 34582d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor static bool classof(const Stmt *T) { 34591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == GNUNullExprClass; 34602d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } 34611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 34622d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor // Iterators 346363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 34642d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor}; 34652d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 346674626d6ef2e194fcc911e071556660ff331eb4a8Zhongxing Xu/// VAArgExpr, used for the builtin function __builtin_va_arg. 34677c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonclass VAArgExpr : public Expr { 34685549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 34692cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara TypeSourceInfo *TInfo; 34707c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson SourceLocation BuiltinLoc, RParenLoc; 34717c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonpublic: 34722cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara VAArgExpr(SourceLocation BLoc, Expr* e, TypeSourceInfo *TInfo, 34732cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara SourceLocation RPLoc, QualType t) 3474f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(VAArgExprClass, t, VK_RValue, OK_Ordinary, 3475bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor t->isDependentType(), false, 3476561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (TInfo->getType()->isInstantiationDependentType() || 3477561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor e->isInstantiationDependent()), 3478bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (TInfo->getType()->containsUnexpandedParameterPack() || 3479bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor e->containsUnexpandedParameterPack())), 34802cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara Val(e), TInfo(TInfo), 34817c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson BuiltinLoc(BLoc), 34827c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson RParenLoc(RPLoc) { } 34831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 348474626d6ef2e194fcc911e071556660ff331eb4a8Zhongxing Xu /// \brief Create an empty __builtin_va_arg expression. 3485d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor explicit VAArgExpr(EmptyShell Empty) : Expr(VAArgExprClass, Empty) { } 3486d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 34875549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 34885549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 3489d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 3490d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 34912cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara TypeSourceInfo *getWrittenTypeInfo() const { return TInfo; } 34922cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara void setWrittenTypeInfo(TypeSourceInfo *TI) { TInfo = TI; } 34932cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara 3494d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 3495d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 34961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3497d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 3498d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 3499d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 3500aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 35017c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson return SourceRange(BuiltinLoc, RParenLoc); 35021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 35037c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson static bool classof(const Stmt *T) { 35047c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson return T->getStmtClass() == VAArgExprClass; 35057c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson } 35061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 35077c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson // Iterators 350863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Val, &Val+1); } 35097c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson}; 35101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 35114c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @brief Describes an C or C++ initializer list. 35124c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// 35134c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// InitListExpr describes an initializer list, which can be used to 35144c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initialize objects of different types, including 35154c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct/class/union types, arrays, and vectors. For example: 35164c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// 35174c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @code 35184c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct foo x = { 1, { 2, 3 } }; 35194c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @endcode 3520196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 35214c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Prior to semantic analysis, an initializer list will represent the 35224c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer list as written by the user, but will have the 35234c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// placeholder type "void". This initializer list is called the 35244c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// syntactic form of the initializer, and may contain C99 designated 35254c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializers (represented as DesignatedInitExprs), initializations 35264c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// of subobject members without explicit braces, and so on. Clients 35274c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// interested in the original syntax of the initializer list should 35284c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// use the syntactic form of the initializer list. 3529196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 35304c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// After semantic analysis, the initializer list will represent the 35314c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// semantic form of the initializer, where the initializations of all 35324c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// subobjects are made explicit with nested InitListExpr nodes and 35334c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// C99 designators have been eliminated by placing the designated 35344c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializations into the subobject they initialize. Additionally, 35354c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// any "holes" in the initialization, where no initializer has been 35364c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// specified for a particular subobject, will be replaced with 35373498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// implicitly-generated ImplicitValueInitExpr expressions that 35384c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// value-initialize the subobjects. Note, however, that the 35394c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer lists may still have fewer initializers than there are 35404c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// elements to initialize within the object. 3541196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 354223700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara/// After semantic analysis has completed, given an initializer list, 354323700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara/// method isSemanticForm() returns true if and only if this is the 354423700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara/// semantic form of the initializer list (note: the same AST node 354523700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara/// may at the same time be the syntactic form). 35464c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Given the semantic form of the initializer list, one can retrieve 354723700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara/// the syntactic form of that initializer list (when different) 354823700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara/// using method getSyntacticForm(); the method returns null if applied 354923700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara/// to a initializer list which is already in syntactic form. 355023700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara/// Similarly, given the syntactic form (i.e., an initializer list such 355123700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara/// that isSemanticForm() returns false), one can retrieve the semantic 355223700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara/// form using method getSemanticForm(). 355323700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara/// Since many initializer lists have the same syntactic and semantic forms, 355423700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara/// getSyntacticForm() may return NULL, indicating that the current 355523700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara/// semantic initializer list also serves as its syntactic form. 355666b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonclass InitListExpr : public Expr { 3557ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek // FIXME: Eliminate this vector in favor of ASTContext allocation 3558709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek typedef ASTVector<Stmt *> InitExprsTy; 3559709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprsTy InitExprs; 356066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson SourceLocation LBraceLoc, RBraceLoc; 35611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 356223700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara /// The alternative form of the initializer list (if it exists). 356323700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara /// The int part of the pair stores whether this initalizer list is 356423700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara /// in semantic form. If not null, the pointer points to: 356523700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara /// - the syntactic form, if this is in semantic form; 356623700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara /// - the semantic form, if this is in syntactic form. 356723700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara llvm::PointerIntPair<InitListExpr *, 1, bool> AltForm; 35684c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 35694423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// \brief Either: 35704423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// If this initializer list initializes an array with more elements than 35714423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// there are initializers in the list, specifies an expression to be used 35724423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// for value initialization of the rest of the elements. 35734423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// Or 35744423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// If this initializer list initializes a union, specifies which 35754423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// field within the union will be initialized. 35764423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis llvm::PointerUnion<Expr *, FieldDecl *> ArrayFillerOrUnionFieldInit; 35770bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor 357866b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonpublic: 3579709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitListExpr(ASTContext &C, SourceLocation lbraceloc, 35803b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> initExprs, SourceLocation rbraceloc); 3581d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3582d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Build an empty initializer list. 35832a82ca255b0f99f6201a75ed52b91fc024f6e9cfArgyrios Kyrtzidis explicit InitListExpr(EmptyShell Empty) 35842a82ca255b0f99f6201a75ed52b91fc024f6e9cfArgyrios Kyrtzidis : Expr(InitListExprClass, Empty) { } 35851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3586ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek unsigned getNumInits() const { return InitExprs.size(); } 35871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3588aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \brief Retrieve the set of initializers. 3589aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Expr **getInits() { return reinterpret_cast<Expr **>(InitExprs.data()); } 3590ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 359116c5dea6c2d3e4cf529de9d9b37f6a40441acb2cChris Lattner const Expr *getInit(unsigned Init) const { 3592c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 35934c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return cast_or_null<Expr>(InitExprs[Init]); 359466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 35951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 359616c5dea6c2d3e4cf529de9d9b37f6a40441acb2cChris Lattner Expr *getInit(unsigned Init) { 3597c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 35984c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return cast_or_null<Expr>(InitExprs[Init]); 359966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 36001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 36011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setInit(unsigned Init, Expr *expr) { 3602c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 36039e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff InitExprs[Init] = expr; 36049e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff } 3605c5ae899b4bbf65488445316c63168079177db0edSteve Naroff 3606fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor /// \brief Reserve space for some number of initializers. 3607709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek void reserveInits(ASTContext &C, unsigned NumInits); 36081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 36094c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Specify the number of initializers 36104c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 36114c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// If there are more than @p NumInits initializers, the remaining 36124c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// initializers will be destroyed. If there are fewer than @p 36134c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// NumInits initializers, NULL expressions will be added for the 36144c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// unknown initializers. 36154c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor void resizeInits(ASTContext &Context, unsigned NumInits); 36164c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 36174c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Updates the initializer at index @p Init with the new 36184c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// expression @p expr, and returns the old expression at that 36194c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// location. 36204c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 36214c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// When @p Init is out of range for this initializer list, the 36224c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// initializer list will be extended with NULL expressions to 3623fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner /// accommodate the new entry. 3624709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek Expr *updateInit(ASTContext &C, unsigned Init, Expr *expr); 3625c5ae899b4bbf65488445316c63168079177db0edSteve Naroff 36264423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// \brief If this initializer list initializes an array with more elements 36274423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// than there are initializers in the list, specifies an expression to be 36284423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// used for value initialization of the rest of the elements. 36294423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis Expr *getArrayFiller() { 36304423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis return ArrayFillerOrUnionFieldInit.dyn_cast<Expr *>(); 36314423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis } 36328cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne const Expr *getArrayFiller() const { 36338cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne return const_cast<InitListExpr *>(this)->getArrayFiller(); 36348cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne } 36353e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis void setArrayFiller(Expr *filler); 36364423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis 363721f77cd0c3da8a1dbaf6245cae43baf4c0b80ea4Argyrios Kyrtzidis /// \brief Return true if this is an array initializer and its array "filler" 363821f77cd0c3da8a1dbaf6245cae43baf4c0b80ea4Argyrios Kyrtzidis /// has been set. 363921f77cd0c3da8a1dbaf6245cae43baf4c0b80ea4Argyrios Kyrtzidis bool hasArrayFiller() const { return getArrayFiller(); } 364021f77cd0c3da8a1dbaf6245cae43baf4c0b80ea4Argyrios Kyrtzidis 36410bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// \brief If this initializes a union, specifies which field in the 36420bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// union to initialize. 36430bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// 36440bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// Typically, this field is the first named field within the 36450bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// union. However, a designated initializer can specify the 36460bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// initialization of a different field within the union. 36474423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis FieldDecl *getInitializedFieldInUnion() { 36484423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis return ArrayFillerOrUnionFieldInit.dyn_cast<FieldDecl *>(); 36494423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis } 36508cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne const FieldDecl *getInitializedFieldInUnion() const { 36518cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne return const_cast<InitListExpr *>(this)->getInitializedFieldInUnion(); 36528cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne } 36534423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis void setInitializedFieldInUnion(FieldDecl *FD) { 36544423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis ArrayFillerOrUnionFieldInit = FD; 36554423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis } 36560bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor 3657c5ae899b4bbf65488445316c63168079177db0edSteve Naroff // Explicit InitListExpr's originate from source code (and have valid source 3658c5ae899b4bbf65488445316c63168079177db0edSteve Naroff // locations). Implicit InitListExpr's are created by the semantic analyzer. 3659b3eef68111ffc220e449be96da1747998c057790Douglas Gregor bool isExplicit() { 3660b3eef68111ffc220e449be96da1747998c057790Douglas Gregor return LBraceLoc.isValid() && RBraceLoc.isValid(); 3661b3eef68111ffc220e449be96da1747998c057790Douglas Gregor } 36621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3663fe587201feaebc69e6d18858bea85c77926b6ecfRichard Smith // Is this an initializer for an array of characters, initialized by a string 3664fe587201feaebc69e6d18858bea85c77926b6ecfRichard Smith // literal or an @encode? 3665fe587201feaebc69e6d18858bea85c77926b6ecfRichard Smith bool isStringLiteralInit() const; 3666fe587201feaebc69e6d18858bea85c77926b6ecfRichard Smith 3667d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor SourceLocation getLBraceLoc() const { return LBraceLoc; } 3668d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setLBraceLoc(SourceLocation Loc) { LBraceLoc = Loc; } 3669d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor SourceLocation getRBraceLoc() const { return RBraceLoc; } 367087fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; } 367187fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor 367223700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara bool isSemanticForm() const { return AltForm.getInt(); } 367323700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara InitListExpr *getSemanticForm() const { 367423700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara return isSemanticForm() ? 0 : AltForm.getPointer(); 367523700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara } 367623700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara InitListExpr *getSyntacticForm() const { 367723700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara return isSemanticForm() ? AltForm.getPointer() : 0; 367823700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara } 367923700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara 368023700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara void setSyntacticForm(InitListExpr *Init) { 368123700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara AltForm.setPointer(Init); 368223700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara AltForm.setInt(true); 368323700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara Init->AltForm.setPointer(this); 368423700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara Init->AltForm.setInt(false); 368523700f083fb72f5c6792e253f203a43aba3cef86Abramo Bagnara } 36864c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 368732cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl bool hadArrayRangeDesignator() const { 368832cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl return InitListExprBits.HadArrayRangeDesignator != 0; 368932cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl } 36901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void sawArrayRangeDesignator(bool ARD = true) { 369132cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl InitListExprBits.HadArrayRangeDesignator = ARD; 369232cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl } 369332cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl 369432cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl bool initializesStdInitializerList() const { 369532cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl return InitListExprBits.InitializesStdInitializerList != 0; 369632cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl } 369732cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl void setInitializesStdInitializerList(bool ISIL = true) { 369832cf1f27ae8620e7b79bb4e81a067187c0aab7aeSebastian Redl InitListExprBits.InitializesStdInitializerList = ISIL; 3699a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor } 3700a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor 3701aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY; 3702c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek 370366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson static bool classof(const Stmt *T) { 37041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == InitListExprClass; 370566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 37061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 370766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson // Iterators 370863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 370963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall if (InitExprs.empty()) return child_range(); 371063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&InitExprs[0], &InitExprs[0] + InitExprs.size()); 371163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 37121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3713709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek typedef InitExprsTy::iterator iterator; 37148111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu typedef InitExprsTy::const_iterator const_iterator; 3715709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek typedef InitExprsTy::reverse_iterator reverse_iterator; 37168111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu typedef InitExprsTy::const_reverse_iterator const_reverse_iterator; 37171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3718ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek iterator begin() { return InitExprs.begin(); } 37198111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_iterator begin() const { return InitExprs.begin(); } 3720ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek iterator end() { return InitExprs.end(); } 37218111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_iterator end() const { return InitExprs.end(); } 3722ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek reverse_iterator rbegin() { return InitExprs.rbegin(); } 37238111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_reverse_iterator rbegin() const { return InitExprs.rbegin(); } 3724ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek reverse_iterator rend() { return InitExprs.rend(); } 37258111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_reverse_iterator rend() const { return InitExprs.rend(); } 37264423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis 37274423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis friend class ASTStmtReader; 37284423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis friend class ASTStmtWriter; 372966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson}; 373066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson 373105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @brief Represents a C99 designated initializer expression. 373205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// 373305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// A designated initializer expression (C99 6.7.8) contains one or 373405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// more designators (which can be field designators, array 373505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, or GNU array-range designators) followed by an 373605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// expression that initializes the field or element(s) that the 373705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators refer to. For example, given: 37381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 373905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @code 374005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point { 374105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// double x; 374205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// double y; 374305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// }; 374405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 }; 374505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @endcode 374605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// 374705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// The InitListExpr contains three DesignatedInitExprs, the first of 374805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// which covers @c [2].y=1.0. This DesignatedInitExpr will have two 374905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, one array designator for @c [2] followed by one field 375005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designator for @c .y. The initalization expression will be 1.0. 375105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorclass DesignatedInitExpr : public Expr { 3752ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorpublic: 3753ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief Forward declaration of the Designator class. 3754ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor class Designator; 3755ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 3756ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorprivate: 375705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '=' or ':' prior to the actual initializer 375805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// expression. 375905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EqualOrColonLoc; 376005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3761eeae8f072748affce25ab4064982626361293390Douglas Gregor /// Whether this designated initializer used the GNU deprecated 376205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// syntax rather than the C99 '=' syntax. 3763eeae8f072748affce25ab4064982626361293390Douglas Gregor bool GNUSyntax : 1; 376405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 376505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The number of designators in this initializer expression. 376605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators : 15; 376705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 376805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The number of subexpressions of this initializer expression, 376905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// which contains both the initializer and any additional 377005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// expressions used by array and array-range designators. 377105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumSubExprs : 16; 377205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3773a72c352e4950cb487942427550777378b68dc078Benjamin Kramer /// \brief The designators in this designated initialization 3774a72c352e4950cb487942427550777378b68dc078Benjamin Kramer /// expression. 3775a72c352e4950cb487942427550777378b68dc078Benjamin Kramer Designator *Designators; 3776a72c352e4950cb487942427550777378b68dc078Benjamin Kramer 3777ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 3778319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor DesignatedInitExpr(ASTContext &C, QualType Ty, unsigned NumDesignators, 3779ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Designators, 3780eeae8f072748affce25ab4064982626361293390Douglas Gregor SourceLocation EqualOrColonLoc, bool GNUSyntax, 37813b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> IndexExprs, Expr *Init); 378205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3783d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor explicit DesignatedInitExpr(unsigned NumSubExprs) 3784d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor : Expr(DesignatedInitExprClass, EmptyShell()), 3785a72c352e4950cb487942427550777378b68dc078Benjamin Kramer NumDesignators(0), NumSubExprs(NumSubExprs), Designators(0) { } 3786d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 378705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorpublic: 378805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// A field designator, e.g., ".x". 378905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct FieldDesignator { 379005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// Refers to the field that is being initialized. The low bit 379105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// of this field determines whether this is actually a pointer 379205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When 379305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initially constructed, a field designator will store an 379405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// IdentifierInfo*. After semantic analysis has resolved that 379505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// name, the field designator will instead store a FieldDecl*. 379605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor uintptr_t NameOrField; 37971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 379805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '.' in the designated initializer. 379905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned DotLoc; 38001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 380105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the field name in the designated initializer. 380205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned FieldLoc; 380305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 380405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 380505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". 380605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct ArrayOrRangeDesignator { 380705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// Location of the first index expression within the designated 380805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initializer expression's list of subexpressions. 380905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned Index; 381005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '[' starting the array range designator. 381105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned LBracketLoc; 381205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the ellipsis separating the start and end 381305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// indices. Only valid for GNU array-range designators. 381405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned EllipsisLoc; 381505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the ']' terminating the array range designator. 38161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned RBracketLoc; 381705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 381805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 381905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Represents a single C99 designator. 382005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// 382105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @todo This class is infuriatingly similar to clang::Designator, 382205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// but minor differences (storing indices vs. storing pointers) 382305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// keep us from reusing it. Try harder, later, to rectify these 382405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// differences. 382505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor class Designator { 382605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief The kind of designator this describes. 382705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor enum { 382805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor FieldDesignator, 382905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayDesignator, 383005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayRangeDesignator 383105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } Kind; 383205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 383305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor union { 383405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// A field designator, e.g., ".x". 383505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct FieldDesignator Field; 383605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". 383705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct ArrayOrRangeDesignator ArrayOrRange; 383805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 383905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor friend class DesignatedInitExpr; 384005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 384105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor public: 3842ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designator() {} 3843ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 384405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes a field designator. 38451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc, 38461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation FieldLoc) 384705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(FieldDesignator) { 384805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01; 384905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.DotLoc = DotLoc.getRawEncoding(); 385005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.FieldLoc = FieldLoc.getRawEncoding(); 385105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 385205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 385305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes an array designator. 38541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(unsigned Index, SourceLocation LBracketLoc, 385505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation RBracketLoc) 385605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(ArrayDesignator) { 385705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.Index = Index; 385805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding(); 385905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding(); 386005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding(); 386105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 386205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 386305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes a GNU array-range designator. 38641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(unsigned Index, SourceLocation LBracketLoc, 386505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EllipsisLoc, SourceLocation RBracketLoc) 386605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(ArrayRangeDesignator) { 386705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.Index = Index; 386805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding(); 386905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding(); 387005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding(); 387105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 387205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 387305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isFieldDesignator() const { return Kind == FieldDesignator; } 387405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isArrayDesignator() const { return Kind == ArrayDesignator; } 387505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; } 387605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3877b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth IdentifierInfo *getFieldName() const; 387805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3879b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth FieldDecl *getField() const { 388005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 388105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor if (Field.NameOrField & 0x01) 388205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return 0; 388305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor else 388405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return reinterpret_cast<FieldDecl *>(Field.NameOrField); 388505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 388605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 388705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor void setField(FieldDecl *FD) { 388805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 388905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.NameOrField = reinterpret_cast<uintptr_t>(FD); 389005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 389105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 389287f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor SourceLocation getDotLoc() const { 389387f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 389487f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor return SourceLocation::getFromRawEncoding(Field.DotLoc); 389587f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor } 389687f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor 389705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getFieldLoc() const { 389805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 389905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(Field.FieldLoc); 390005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 390105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 390205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getLBracketLoc() const { 390305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 390405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array or array-range designator"); 390505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc); 390605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 390705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 390805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getRBracketLoc() const { 390905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 391005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array or array-range designator"); 391105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc); 391205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 391305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 391405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getEllipsisLoc() const { 391505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == ArrayRangeDesignator && 391605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array-range designator"); 391705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc); 391805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 39194c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 3920d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned getFirstExprIndex() const { 3921d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 3922d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor "Only valid on an array or array-range designator"); 3923d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor return ArrayOrRange.Index; 3924d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 3925d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 39264c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor SourceLocation getStartLocation() const { 39274c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor if (Kind == FieldDesignator) 39284c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return getDotLoc().isInvalid()? getFieldLoc() : getDotLoc(); 39294c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor else 39304c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return getLBracketLoc(); 39314c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor } 393224f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara SourceLocation getEndLocation() const { 393324f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara return Kind == FieldDesignator ? getFieldLoc() : getRBracketLoc(); 393424f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara } 3935aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 393624f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara return SourceRange(getStartLocation(), getEndLocation()); 393724f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara } 393805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 393905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 39401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static DesignatedInitExpr *Create(ASTContext &C, Designator *Designators, 394105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators, 39423b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> IndexExprs, 394305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EqualOrColonLoc, 3944eeae8f072748affce25ab4064982626361293390Douglas Gregor bool GNUSyntax, Expr *Init); 394505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3946d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor static DesignatedInitExpr *CreateEmpty(ASTContext &C, unsigned NumIndexExprs); 3947d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 394805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Returns the number of designators in this initializer. 394905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned size() const { return NumDesignators; } 395005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 395105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor // Iterator access to the designators. 3952b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth typedef Designator *designators_iterator; 3953ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor designators_iterator designators_begin() { return Designators; } 39541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump designators_iterator designators_end() { 39551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return Designators + NumDesignators; 3956ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor } 395705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3958b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth typedef const Designator *const_designators_iterator; 3959b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth const_designators_iterator designators_begin() const { return Designators; } 3960b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth const_designators_iterator designators_end() const { 3961b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth return Designators + NumDesignators; 3962b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth } 3963b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth 3964cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek typedef std::reverse_iterator<designators_iterator> 3965cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek reverse_designators_iterator; 3966cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek reverse_designators_iterator designators_rbegin() { 3967cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek return reverse_designators_iterator(designators_end()); 3968cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek } 3969cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek reverse_designators_iterator designators_rend() { 3970cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek return reverse_designators_iterator(designators_begin()); 3971cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek } 3972cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek 3973b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth typedef std::reverse_iterator<const_designators_iterator> 3974b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth const_reverse_designators_iterator; 3975b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth const_reverse_designators_iterator designators_rbegin() const { 3976b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth return const_reverse_designators_iterator(designators_end()); 3977b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth } 3978b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth const_reverse_designators_iterator designators_rend() const { 3979b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth return const_reverse_designators_iterator(designators_begin()); 3980b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth } 3981b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth 3982711997184366d584c9c437102cae1e9d9927b986Douglas Gregor Designator *getDesignator(unsigned Idx) { return &designators_begin()[Idx]; } 3983711997184366d584c9c437102cae1e9d9927b986Douglas Gregor 3984ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie void setDesignators(ASTContext &C, const Designator *Desigs, 3985319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor unsigned NumDesigs); 3986d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 398705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayIndex(const Designator& D); 398805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayRangeStart(const Designator& D); 398905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayRangeEnd(const Designator& D); 399005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 399105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Retrieve the location of the '=' that precedes the 399205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initializer value itself, if present. 399305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; } 3994d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setEqualOrColonLoc(SourceLocation L) { EqualOrColonLoc = L; } 399505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 399605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Determines whether this designated initializer used the 3997eeae8f072748affce25ab4064982626361293390Douglas Gregor /// deprecated GNU syntax for designated initializers. 3998eeae8f072748affce25ab4064982626361293390Douglas Gregor bool usesGNUSyntax() const { return GNUSyntax; } 3999d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setGNUSyntax(bool GNU) { GNUSyntax = GNU; } 400005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 400105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Retrieve the initializer value. 40021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getInit() const { 400305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin()); 400405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 400505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 400605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor void setInit(Expr *init) { 400705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor *child_begin() = init; 400805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 400905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 4010d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Retrieve the total number of subexpressions in this 4011d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// designated initializer expression, including the actual 4012d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// initialized value and any expressions that occur within array 4013d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// and array-range designators. 4014d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned getNumSubExprs() const { return NumSubExprs; } 4015d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 4016d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Expr *getSubExpr(unsigned Idx) { 4017d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert(Idx < NumSubExprs && "Subscript out of range"); 4018d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 4019d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 4020d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor return reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx]; 4021d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 4022d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 4023d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setSubExpr(unsigned Idx, Expr *E) { 4024d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert(Idx < NumSubExprs && "Subscript out of range"); 4025d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 4026d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 4027d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx] = E; 4028d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 4029d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 4030ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief Replaces the designator at index @p Idx with the series 4031ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// of designators in [First, Last). 4032319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor void ExpandDesignator(ASTContext &C, unsigned Idx, const Designator *First, 4033ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Last); 4034ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 403524f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara SourceRange getDesignatorsSourceRange() const; 403624f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara 4037aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY; 403805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 403905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor static bool classof(const Stmt *T) { 40401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == DesignatedInitExprClass; 404105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 404205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 404305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor // Iterators 404463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 404563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt **begin = reinterpret_cast<Stmt**>(this + 1); 404663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(begin, begin + NumSubExprs); 404763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 40483498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor}; 40493498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 40503498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// \brief Represents an implicitly-generated value initialization of 40513498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// an object of a given type. 40523498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// 40531a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// Implicit value initializations occur within semantic initializer 40541a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// list expressions (InitListExpr) as placeholders for subobject 40553498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// initializations not explicitly specified by the user. 40561a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// 40571a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// \see InitListExpr 40581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass ImplicitValueInitExpr : public Expr { 40593498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregorpublic: 40601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ImplicitValueInitExpr(QualType ty) 4061f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ImplicitValueInitExprClass, ty, VK_RValue, OK_Ordinary, 4062561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false, ty->isInstantiationDependentType(), false) { } 40633498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 4064d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Construct an empty implicit value initialization. 4065d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor explicit ImplicitValueInitExpr(EmptyShell Empty) 4066d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor : Expr(ImplicitValueInitExprClass, Empty) { } 4067d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 40681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 40693498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return T->getStmtClass() == ImplicitValueInitExprClass; 40703498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor } 40713498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 4072aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 40733498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return SourceRange(); 40743498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor } 40753498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 40763498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor // Iterators 407763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 407805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}; 407905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 40802ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 40812ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanclass ParenListExpr : public Expr { 40822ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman Stmt **Exprs; 40832ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman unsigned NumExprs; 40842ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation LParenLoc, RParenLoc; 40852ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 40862ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanpublic: 40873b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ParenListExpr(ASTContext& C, SourceLocation lparenloc, ArrayRef<Expr*> exprs, 40883b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer SourceLocation rparenloc); 40892ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 40902ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman /// \brief Build an empty paren list. 409137bdfe284ad365f753741d1d89c078c148b3f4afArgyrios Kyrtzidis explicit ParenListExpr(EmptyShell Empty) : Expr(ParenListExprClass, Empty) { } 40921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 40932ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman unsigned getNumExprs() const { return NumExprs; } 40941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 40951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr* getExpr(unsigned Init) const { 40962ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman assert(Init < getNumExprs() && "Initializer access out of range!"); 40972ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return cast_or_null<Expr>(Exprs[Init]); 40982ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 40991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 41001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr* getExpr(unsigned Init) { 41012ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman assert(Init < getNumExprs() && "Initializer access out of range!"); 41022ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return cast_or_null<Expr>(Exprs[Init]); 41032ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 41042ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 410583ddad3ab513f5d73698cf9fbeb4ed3f011bc3b9Douglas Gregor Expr **getExprs() { return reinterpret_cast<Expr **>(Exprs); } 41061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 41072ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation getLParenLoc() const { return LParenLoc; } 41082ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation getRParenLoc() const { return RParenLoc; } 41092ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 4110aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 41112ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return SourceRange(LParenLoc, RParenLoc); 41121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 41132ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman static bool classof(const Stmt *T) { 41141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ParenListExprClass; 41152ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 41161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 41172ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman // Iterators 411863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 411963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&Exprs[0], &Exprs[0]+NumExprs); 412063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 412137bdfe284ad365f753741d1d89c078c148b3f4afArgyrios Kyrtzidis 412260adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 41233397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl friend class ASTStmtWriter; 41242ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman}; 41252ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 41261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4127ffbe9b9c64ab2e94b9d48ec56e511f75826fc80aBenjamin Kramer/// \brief Represents a C11 generic selection. 4128f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// 4129ffbe9b9c64ab2e94b9d48ec56e511f75826fc80aBenjamin Kramer/// A generic selection (C11 6.5.1.1) contains an unevaluated controlling 4130f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// expression, followed by one or more generic associations. Each generic 4131f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// association specifies a type name and an expression, or "default" and an 4132f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// expression (in which case it is known as a default generic association). 4133f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// The type and value of the generic selection are identical to those of its 4134f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// result expression, which is defined as the expression in the generic 4135f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// association with a type name that is compatible with the type of the 4136f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// controlling expression, or the expression in the default generic association 4137f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// if no types are compatible. For example: 4138f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// 4139f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// @code 4140f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// _Generic(X, double: 1, float: 2, default: 3) 4141f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// @endcode 4142f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// 4143f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// The above expression evaluates to 1 if 1.0 is substituted for X, 2 if 1.0f 4144f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// or 3 if "hello". 4145f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// 4146f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// As an extension, generic selections are allowed in C++, where the following 4147f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// additional semantics apply: 4148f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// 4149f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// Any generic selection whose controlling expression is type-dependent or 4150f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// which names a dependent type in its association list is result-dependent, 4151f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// which means that the choice of result expression is dependent. 4152f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// Result-dependent generic associations are both type- and value-dependent. 4153f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourneclass GenericSelectionExpr : public Expr { 4154f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne enum { CONTROLLING, END_EXPR }; 4155f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo **AssocTypes; 4156f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Stmt **SubExprs; 4157f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned NumAssocs, ResultIndex; 4158f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation GenericLoc, DefaultLoc, RParenLoc; 4159f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4160f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbournepublic: 4161f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne GenericSelectionExpr(ASTContext &Context, 4162f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation GenericLoc, Expr *ControllingExpr, 41633b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<TypeSourceInfo*> AssocTypes, 41643b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> AssocExprs, 41653b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer SourceLocation DefaultLoc, SourceLocation RParenLoc, 4166f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne bool ContainsUnexpandedParameterPack, 4167f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned ResultIndex); 4168f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4169f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// This constructor is used in the result-dependent case. 4170f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne GenericSelectionExpr(ASTContext &Context, 4171f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation GenericLoc, Expr *ControllingExpr, 41723b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<TypeSourceInfo*> AssocTypes, 41733b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer ArrayRef<Expr*> AssocExprs, 41743b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer SourceLocation DefaultLoc, SourceLocation RParenLoc, 4175f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne bool ContainsUnexpandedParameterPack); 4176f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4177f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne explicit GenericSelectionExpr(EmptyShell Empty) 4178f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne : Expr(GenericSelectionExprClass, Empty) { } 4179f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4180f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned getNumAssocs() const { return NumAssocs; } 4181f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4182f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation getGenericLoc() const { return GenericLoc; } 4183f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation getDefaultLoc() const { return DefaultLoc; } 4184f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation getRParenLoc() const { return RParenLoc; } 4185f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4186f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const Expr *getAssocExpr(unsigned i) const { 4187f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<Expr>(SubExprs[END_EXPR+i]); 4188f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 4189f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Expr *getAssocExpr(unsigned i) { return cast<Expr>(SubExprs[END_EXPR+i]); } 4190f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4191f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const TypeSourceInfo *getAssocTypeSourceInfo(unsigned i) const { 4192f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return AssocTypes[i]; 4193f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 4194f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo *getAssocTypeSourceInfo(unsigned i) { return AssocTypes[i]; } 4195f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4196f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne QualType getAssocType(unsigned i) const { 4197f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (const TypeSourceInfo *TS = getAssocTypeSourceInfo(i)) 4198f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return TS->getType(); 4199f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne else 4200f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return QualType(); 4201f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 4202f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4203f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const Expr *getControllingExpr() const { 4204f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<Expr>(SubExprs[CONTROLLING]); 4205f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 4206f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Expr *getControllingExpr() { return cast<Expr>(SubExprs[CONTROLLING]); } 4207f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4208f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// Whether this generic selection is result-dependent. 4209f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne bool isResultDependent() const { return ResultIndex == -1U; } 4210f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4211f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// The zero-based index of the result expression's generic association in 4212f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// the generic selection's association list. Defined only if the 4213f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// generic selection is not result-dependent. 4214f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned getResultIndex() const { 4215f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne assert(!isResultDependent() && "Generic selection is result-dependent"); 4216f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return ResultIndex; 4217f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 4218f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4219f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// The generic selection's result expression. Defined only if the 4220f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// generic selection is not result-dependent. 4221f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const Expr *getResultExpr() const { return getAssocExpr(getResultIndex()); } 4222f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Expr *getResultExpr() { return getAssocExpr(getResultIndex()); } 4223f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4224aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 4225f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return SourceRange(GenericLoc, RParenLoc); 4226f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 4227f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne static bool classof(const Stmt *T) { 4228f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return T->getStmtClass() == GenericSelectionExprClass; 4229f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 4230f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4231f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne child_range children() { 4232f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return child_range(SubExprs, SubExprs+END_EXPR+NumAssocs); 4233f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 4234f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4235f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne friend class ASTStmtReader; 4236f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne}; 4237f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 42384eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===// 42394eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff// Clang Extensions 42404eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===// 42414eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 4242a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 4243a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// ExtVectorElementExpr - This represents access to specific elements of a 4244a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// vector, and may occur on the left hand side or right hand side. For example 4245a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// the following is legal: "V.xy = V.zw" if V is a 4 element extended vector. 4246a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// 424773525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// Note that the base may have either vector or pointer to vector type, just 424873525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// like a struct field reference. 424973525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// 4250a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerclass ExtVectorElementExpr : public Expr { 4251a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner Stmt *Base; 4252d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor IdentifierInfo *Accessor; 4253a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner SourceLocation AccessorLoc; 4254a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerpublic: 4255f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExtVectorElementExpr(QualType ty, ExprValueKind VK, Expr *base, 4256f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall IdentifierInfo &accessor, SourceLocation loc) 42570943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall : Expr(ExtVectorElementExprClass, ty, VK, 42580943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall (VK == VK_RValue ? OK_Ordinary : OK_VectorComponent), 4259bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->isTypeDependent(), base->isValueDependent(), 4260561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor base->isInstantiationDependent(), 4261bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->containsUnexpandedParameterPack()), 4262d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor Base(base), Accessor(&accessor), AccessorLoc(loc) {} 42631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4264d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor /// \brief Build an empty vector element expression. 4265d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor explicit ExtVectorElementExpr(EmptyShell Empty) 4266d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor : Expr(ExtVectorElementExprClass, Empty) { } 4267d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 4268a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner const Expr *getBase() const { return cast<Expr>(Base); } 4269a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner Expr *getBase() { return cast<Expr>(Base); } 4270d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setBase(Expr *E) { Base = E; } 4271d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 4272d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor IdentifierInfo &getAccessor() const { return *Accessor; } 4273d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setAccessor(IdentifierInfo *II) { Accessor = II; } 4274d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 4275d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getAccessorLoc() const { return AccessorLoc; } 4276d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setAccessorLoc(SourceLocation L) { AccessorLoc = L; } 4277d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 4278a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// getNumElements - Get the number of components being selected. 4279a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner unsigned getNumElements() const; 42801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4281a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// containsDuplicateElements - Return true if any element access is 4282a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// repeated. 4283a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner bool containsDuplicateElements() const; 42841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4285a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// getEncodedElementAccess - Encode the elements accessed into an llvm 4286a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// aggregate Constant of ConstantInt(s). 4287686775deca8b8685eb90801495880e3abdd844c2Chris Lattner void getEncodedElementAccess(SmallVectorImpl<unsigned> &Elts) const; 42881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4289aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 4290a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner return SourceRange(getBase()->getLocStart(), AccessorLoc); 4291a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner } 42921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42932140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner /// isArrow - Return true if the base expression is a pointer to vector, 42942140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner /// return false if the base expression is a vector. 42952140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner bool isArrow() const; 42961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 42981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ExtVectorElementExprClass; 4299a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner } 43001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4301a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner // Iterators 430263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Base, &Base+1); } 4303a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner}; 4304a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 4305a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 430656ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff/// BlockExpr - Adaptor class for mixing a BlockDecl with expressions. 43079c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff/// ^{ statement-body } or ^(int arg1, float arg2){ statement-body } 43084eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockExpr : public Expr { 430956ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroffprotected: 431056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff BlockDecl *TheBlock; 43114eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic: 4312469a1eb996e1cb0be54f9b210f836afbddcbb2ccJohn McCall BlockExpr(BlockDecl *BD, QualType ty) 4313f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(BlockExprClass, ty, VK_RValue, OK_Ordinary, 4314ec79d877c1998366480d97a7a6c94e15c053edd8Douglas Gregor ty->isDependentType(), ty->isDependentType(), 4315ec79d877c1998366480d97a7a6c94e15c053edd8Douglas Gregor ty->isInstantiationDependentType() || BD->isDependentContext(), 4316561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false), 4317469a1eb996e1cb0be54f9b210f836afbddcbb2ccJohn McCall TheBlock(BD) {} 43189c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 431984af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor /// \brief Build an empty block expression. 432084af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor explicit BlockExpr(EmptyShell Empty) : Expr(BlockExprClass, Empty) { } 432184af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor 4322d5cab5435371b8cc74a9e05ebd40b5995ebad149Anders Carlsson const BlockDecl *getBlockDecl() const { return TheBlock; } 432356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff BlockDecl *getBlockDecl() { return TheBlock; } 432484af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor void setBlockDecl(BlockDecl *BD) { TheBlock = BD; } 432584af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor 432656ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff // Convenience functions for probing the underlying BlockDecl. 432756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff SourceLocation getCaretLocation() const; 432856ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff const Stmt *getBody() const; 432956ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff Stmt *getBody(); 43309c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 4331aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 433256ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff return SourceRange(getCaretLocation(), getBody()->getLocEnd()); 43339c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff } 43349c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 433556ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff /// getFunctionType - Return the underlying function type for this block. 4336a345edb668380691fc92d4e4aa0a5ffec366ca6aJohn McCall const FunctionProtoType *getFunctionType() const; 433756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 43381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 43399c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff return T->getStmtClass() == BlockExprClass; 43404eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff } 43411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 43424eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff // Iterators 434363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 43444eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff}; 43451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 434661eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner/// AsTypeExpr - Clang builtin function __builtin_astype [OpenCL 6.2.4.2] 434761eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner/// This AST node provides support for reinterpreting a type to another 434861eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner/// type of the same size. 4349379010addb0e84fd0fbc37c829baf658958521bdJohn McCallclass AsTypeExpr : public Expr { // Should this be an ExplicitCastExpr? 435061eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattnerprivate: 4351379010addb0e84fd0fbc37c829baf658958521bdJohn McCall Stmt *SrcExpr; 435261eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner SourceLocation BuiltinLoc, RParenLoc; 4353379010addb0e84fd0fbc37c829baf658958521bdJohn McCall 4354379010addb0e84fd0fbc37c829baf658958521bdJohn McCall friend class ASTReader; 4355379010addb0e84fd0fbc37c829baf658958521bdJohn McCall friend class ASTStmtReader; 4356379010addb0e84fd0fbc37c829baf658958521bdJohn McCall explicit AsTypeExpr(EmptyShell Empty) : Expr(AsTypeExprClass, Empty) {} 4357ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 435861eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattnerpublic: 435961eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner AsTypeExpr(Expr* SrcExpr, QualType DstType, 436061eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner ExprValueKind VK, ExprObjectKind OK, 436161eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner SourceLocation BuiltinLoc, SourceLocation RParenLoc) 4362ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie : Expr(AsTypeExprClass, DstType, VK, OK, 4363561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor DstType->isDependentType(), 4364561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor DstType->isDependentType() || SrcExpr->isValueDependent(), 4365561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (DstType->isInstantiationDependentType() || 4366561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor SrcExpr->isInstantiationDependent()), 4367561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (DstType->containsUnexpandedParameterPack() || 4368561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor SrcExpr->containsUnexpandedParameterPack())), 4369379010addb0e84fd0fbc37c829baf658958521bdJohn McCall SrcExpr(SrcExpr), BuiltinLoc(BuiltinLoc), RParenLoc(RParenLoc) {} 4370ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 437161eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner /// getSrcExpr - Return the Expr to be converted. 4372379010addb0e84fd0fbc37c829baf658958521bdJohn McCall Expr *getSrcExpr() const { return cast<Expr>(SrcExpr); } 4373379010addb0e84fd0fbc37c829baf658958521bdJohn McCall 4374379010addb0e84fd0fbc37c829baf658958521bdJohn McCall /// getBuiltinLoc - Return the location of the __builtin_astype token. 4375379010addb0e84fd0fbc37c829baf658958521bdJohn McCall SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 4376379010addb0e84fd0fbc37c829baf658958521bdJohn McCall 4377379010addb0e84fd0fbc37c829baf658958521bdJohn McCall /// getRParenLoc - Return the location of final right parenthesis. 4378379010addb0e84fd0fbc37c829baf658958521bdJohn McCall SourceLocation getRParenLoc() const { return RParenLoc; } 4379ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 4380aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 438161eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner return SourceRange(BuiltinLoc, RParenLoc); 438261eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner } 4383ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 438461eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner static bool classof(const Stmt *T) { 4385ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return T->getStmtClass() == AsTypeExprClass; 438661eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner } 4387ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 438861eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner // Iterators 4389379010addb0e84fd0fbc37c829baf658958521bdJohn McCall child_range children() { return child_range(&SrcExpr, &SrcExpr+1); } 439061eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner}; 4391276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 43924b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// PseudoObjectExpr - An expression which accesses a pseudo-object 43934b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// l-value. A pseudo-object is an abstract object, accesses to which 43944b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// are translated to calls. The pseudo-object expression has a 43954b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// syntactic form, which shows how the expression was actually 43964b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// written in the source code, and a semantic form, which is a series 43974b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// of expressions to be executed in order which detail how the 43984b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// operation is actually evaluated. Optionally, one of the semantic 43994b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// forms may also provide a result value for the expression. 44004b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// 44014b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// If any of the semantic-form expressions is an OpaqueValueExpr, 44024b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// that OVE is required to have a source expression, and it is bound 44034b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// to the result of that source expression. Such OVEs may appear 44044b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// only in subsequent semantic-form expressions and as 44054b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// sub-expressions of the syntactic form. 44064b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// 44074b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// PseudoObjectExpr should be used only when an operation can be 44084b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// usefully described in terms of fairly simple rewrite rules on 44094b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// objects and functions that are meant to be used by end-developers. 44104b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// For example, under the Itanium ABI, dynamic casts are implemented 44114b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// as a call to a runtime function called __dynamic_cast; using this 44124b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// class to describe that would be inappropriate because that call is 44134b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// not really part of the user-visible semantics, and instead the 44144b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// cast is properly reflected in the AST and IR-generation has been 44154b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// taught to generate the call as necessary. In contrast, an 44164b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// Objective-C property access is semantically defined to be 44174b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// equivalent to a particular message send, and this is very much 44184b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// part of the user model. The name of this class encourages this 44194b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// modelling design. 44204b9c2d235fb9449e249d74f48ecfec601650de93John McCallclass PseudoObjectExpr : public Expr { 44214b9c2d235fb9449e249d74f48ecfec601650de93John McCall // PseudoObjectExprBits.NumSubExprs - The number of sub-expressions. 44224b9c2d235fb9449e249d74f48ecfec601650de93John McCall // Always at least two, because the first sub-expression is the 44234b9c2d235fb9449e249d74f48ecfec601650de93John McCall // syntactic form. 44244b9c2d235fb9449e249d74f48ecfec601650de93John McCall 44254b9c2d235fb9449e249d74f48ecfec601650de93John McCall // PseudoObjectExprBits.ResultIndex - The index of the 44264b9c2d235fb9449e249d74f48ecfec601650de93John McCall // sub-expression holding the result. 0 means the result is void, 44274b9c2d235fb9449e249d74f48ecfec601650de93John McCall // which is unambiguous because it's the index of the syntactic 44284b9c2d235fb9449e249d74f48ecfec601650de93John McCall // form. Note that this is therefore 1 higher than the value passed 44294b9c2d235fb9449e249d74f48ecfec601650de93John McCall // in to Create, which is an index within the semantic forms. 44304b9c2d235fb9449e249d74f48ecfec601650de93John McCall // Note also that ASTStmtWriter assumes this encoding. 44314b9c2d235fb9449e249d74f48ecfec601650de93John McCall 44324b9c2d235fb9449e249d74f48ecfec601650de93John McCall Expr **getSubExprsBuffer() { return reinterpret_cast<Expr**>(this + 1); } 44334b9c2d235fb9449e249d74f48ecfec601650de93John McCall const Expr * const *getSubExprsBuffer() const { 44344b9c2d235fb9449e249d74f48ecfec601650de93John McCall return reinterpret_cast<const Expr * const *>(this + 1); 44354b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 44364b9c2d235fb9449e249d74f48ecfec601650de93John McCall 44374b9c2d235fb9449e249d74f48ecfec601650de93John McCall friend class ASTStmtReader; 44384b9c2d235fb9449e249d74f48ecfec601650de93John McCall 44394b9c2d235fb9449e249d74f48ecfec601650de93John McCall PseudoObjectExpr(QualType type, ExprValueKind VK, 44404b9c2d235fb9449e249d74f48ecfec601650de93John McCall Expr *syntactic, ArrayRef<Expr*> semantic, 44414b9c2d235fb9449e249d74f48ecfec601650de93John McCall unsigned resultIndex); 44424b9c2d235fb9449e249d74f48ecfec601650de93John McCall 44434b9c2d235fb9449e249d74f48ecfec601650de93John McCall PseudoObjectExpr(EmptyShell shell, unsigned numSemanticExprs); 44444b9c2d235fb9449e249d74f48ecfec601650de93John McCall 44454b9c2d235fb9449e249d74f48ecfec601650de93John McCall unsigned getNumSubExprs() const { 44464b9c2d235fb9449e249d74f48ecfec601650de93John McCall return PseudoObjectExprBits.NumSubExprs; 44474b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 44484b9c2d235fb9449e249d74f48ecfec601650de93John McCall 44494b9c2d235fb9449e249d74f48ecfec601650de93John McCallpublic: 44504b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// NoResult - A value for the result index indicating that there is 44514b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// no semantic result. 44524b9c2d235fb9449e249d74f48ecfec601650de93John McCall enum { NoResult = ~0U }; 44534b9c2d235fb9449e249d74f48ecfec601650de93John McCall 44544b9c2d235fb9449e249d74f48ecfec601650de93John McCall static PseudoObjectExpr *Create(ASTContext &Context, Expr *syntactic, 44554b9c2d235fb9449e249d74f48ecfec601650de93John McCall ArrayRef<Expr*> semantic, 44564b9c2d235fb9449e249d74f48ecfec601650de93John McCall unsigned resultIndex); 44574b9c2d235fb9449e249d74f48ecfec601650de93John McCall 44584b9c2d235fb9449e249d74f48ecfec601650de93John McCall static PseudoObjectExpr *Create(ASTContext &Context, EmptyShell shell, 44594b9c2d235fb9449e249d74f48ecfec601650de93John McCall unsigned numSemanticExprs); 44604b9c2d235fb9449e249d74f48ecfec601650de93John McCall 44614b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// Return the syntactic form of this expression, i.e. the 44624b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// expression it actually looks like. Likely to be expressed in 44634b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// terms of OpaqueValueExprs bound in the semantic form. 44644b9c2d235fb9449e249d74f48ecfec601650de93John McCall Expr *getSyntacticForm() { return getSubExprsBuffer()[0]; } 44654b9c2d235fb9449e249d74f48ecfec601650de93John McCall const Expr *getSyntacticForm() const { return getSubExprsBuffer()[0]; } 44664b9c2d235fb9449e249d74f48ecfec601650de93John McCall 44674b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// Return the index of the result-bearing expression into the semantics 44684b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// expressions, or PseudoObjectExpr::NoResult if there is none. 44694b9c2d235fb9449e249d74f48ecfec601650de93John McCall unsigned getResultExprIndex() const { 44704b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (PseudoObjectExprBits.ResultIndex == 0) return NoResult; 44714b9c2d235fb9449e249d74f48ecfec601650de93John McCall return PseudoObjectExprBits.ResultIndex - 1; 44724b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 44734b9c2d235fb9449e249d74f48ecfec601650de93John McCall 44744b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// Return the result-bearing expression, or null if there is none. 44754b9c2d235fb9449e249d74f48ecfec601650de93John McCall Expr *getResultExpr() { 44764b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (PseudoObjectExprBits.ResultIndex == 0) 44774b9c2d235fb9449e249d74f48ecfec601650de93John McCall return 0; 44784b9c2d235fb9449e249d74f48ecfec601650de93John McCall return getSubExprsBuffer()[PseudoObjectExprBits.ResultIndex]; 44794b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 44804b9c2d235fb9449e249d74f48ecfec601650de93John McCall const Expr *getResultExpr() const { 44814b9c2d235fb9449e249d74f48ecfec601650de93John McCall return const_cast<PseudoObjectExpr*>(this)->getResultExpr(); 44824b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 44834b9c2d235fb9449e249d74f48ecfec601650de93John McCall 44844b9c2d235fb9449e249d74f48ecfec601650de93John McCall unsigned getNumSemanticExprs() const { return getNumSubExprs() - 1; } 44854b9c2d235fb9449e249d74f48ecfec601650de93John McCall 44864b9c2d235fb9449e249d74f48ecfec601650de93John McCall typedef Expr * const *semantics_iterator; 44874b9c2d235fb9449e249d74f48ecfec601650de93John McCall typedef const Expr * const *const_semantics_iterator; 44884b9c2d235fb9449e249d74f48ecfec601650de93John McCall semantics_iterator semantics_begin() { 44894b9c2d235fb9449e249d74f48ecfec601650de93John McCall return getSubExprsBuffer() + 1; 44904b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 44914b9c2d235fb9449e249d74f48ecfec601650de93John McCall const_semantics_iterator semantics_begin() const { 44924b9c2d235fb9449e249d74f48ecfec601650de93John McCall return getSubExprsBuffer() + 1; 44934b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 44944b9c2d235fb9449e249d74f48ecfec601650de93John McCall semantics_iterator semantics_end() { 44954b9c2d235fb9449e249d74f48ecfec601650de93John McCall return getSubExprsBuffer() + getNumSubExprs(); 44964b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 44974b9c2d235fb9449e249d74f48ecfec601650de93John McCall const_semantics_iterator semantics_end() const { 44984b9c2d235fb9449e249d74f48ecfec601650de93John McCall return getSubExprsBuffer() + getNumSubExprs(); 44994b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 45004b9c2d235fb9449e249d74f48ecfec601650de93John McCall Expr *getSemanticExpr(unsigned index) { 45014b9c2d235fb9449e249d74f48ecfec601650de93John McCall assert(index + 1 < getNumSubExprs()); 45024b9c2d235fb9449e249d74f48ecfec601650de93John McCall return getSubExprsBuffer()[index + 1]; 45034b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 45044b9c2d235fb9449e249d74f48ecfec601650de93John McCall const Expr *getSemanticExpr(unsigned index) const { 45054b9c2d235fb9449e249d74f48ecfec601650de93John McCall return const_cast<PseudoObjectExpr*>(this)->getSemanticExpr(index); 45064b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 45074b9c2d235fb9449e249d74f48ecfec601650de93John McCall 45084f311183be3d923da9fbe8702c453688b4c426a9Daniel Dunbar SourceLocation getExprLoc() const LLVM_READONLY { 45094b9c2d235fb9449e249d74f48ecfec601650de93John McCall return getSyntacticForm()->getExprLoc(); 45104b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 4511aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 45124b9c2d235fb9449e249d74f48ecfec601650de93John McCall return getSyntacticForm()->getSourceRange(); 45134b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 45144b9c2d235fb9449e249d74f48ecfec601650de93John McCall 45154b9c2d235fb9449e249d74f48ecfec601650de93John McCall child_range children() { 45164b9c2d235fb9449e249d74f48ecfec601650de93John McCall Stmt **cs = reinterpret_cast<Stmt**>(getSubExprsBuffer()); 45174b9c2d235fb9449e249d74f48ecfec601650de93John McCall return child_range(cs, cs + getNumSubExprs()); 45184b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 45194b9c2d235fb9449e249d74f48ecfec601650de93John McCall 45204b9c2d235fb9449e249d74f48ecfec601650de93John McCall static bool classof(const Stmt *T) { 45214b9c2d235fb9449e249d74f48ecfec601650de93John McCall return T->getStmtClass() == PseudoObjectExprClass; 45224b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 45234b9c2d235fb9449e249d74f48ecfec601650de93John McCall}; 45244b9c2d235fb9449e249d74f48ecfec601650de93John McCall 4525276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman/// AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, 4526276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman/// __atomic_load, __atomic_store, and __atomic_compare_exchange_*, for the 4527ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith/// similarly-named C++11 instructions, and __c11 variants for <stdatomic.h>. 4528ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith/// All of these instructions take one primary pointer and at least one memory 4529ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith/// order. 4530276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedmanclass AtomicExpr : public Expr { 4531276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedmanpublic: 4532ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith enum AtomicOp { 4533ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith#define BUILTIN(ID, TYPE, ATTRS) 4534ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith#define ATOMIC_BUILTIN(ID, TYPE, ATTRS) AO ## ID, 4535ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith#include "clang/Basic/Builtins.def" 4536ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith // Avoid trailing comma 4537ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith BI_First = 0 4538ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith }; 4539ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith 4540276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedmanprivate: 4541ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith enum { PTR, ORDER, VAL1, ORDER_FAIL, VAL2, WEAK, END_EXPR }; 4542276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman Stmt* SubExprs[END_EXPR]; 4543276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman unsigned NumSubExprs; 4544276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman SourceLocation BuiltinLoc, RParenLoc; 4545276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman AtomicOp Op; 4546276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4547e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith friend class ASTStmtReader; 4548e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith 4549276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedmanpublic: 45503b6bef9a213249c6ab6d67c07b1ac6380961be3eBenjamin Kramer AtomicExpr(SourceLocation BLoc, ArrayRef<Expr*> args, QualType t, 4551dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman AtomicOp op, SourceLocation RP); 4552276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4553e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith /// \brief Determine the number of arguments the specified atomic builtin 4554e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith /// should have. 4555e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith static unsigned getNumSubExprs(AtomicOp Op); 4556e1b2abc2ed3f2c98985b06b4ad01c977bd584020Richard Smith 4557276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman /// \brief Build an empty AtomicExpr. 4558276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman explicit AtomicExpr(EmptyShell Empty) : Expr(AtomicExprClass, Empty) { } 4559276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4560276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman Expr *getPtr() const { 4561276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return cast<Expr>(SubExprs[PTR]); 4562276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4563276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman Expr *getOrder() const { 4564276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return cast<Expr>(SubExprs[ORDER]); 4565276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4566276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman Expr *getVal1() const { 4567ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith if (Op == AO__c11_atomic_init) 45687a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall return cast<Expr>(SubExprs[ORDER]); 4569ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith assert(NumSubExprs > VAL1); 4570276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return cast<Expr>(SubExprs[VAL1]); 4571276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4572276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman Expr *getOrderFail() const { 4573ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith assert(NumSubExprs > ORDER_FAIL); 4574276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return cast<Expr>(SubExprs[ORDER_FAIL]); 4575276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4576276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman Expr *getVal2() const { 4577ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith if (Op == AO__atomic_exchange) 4578ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith return cast<Expr>(SubExprs[ORDER_FAIL]); 4579ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith assert(NumSubExprs > VAL2); 4580276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return cast<Expr>(SubExprs[VAL2]); 4581276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4582ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith Expr *getWeak() const { 4583ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith assert(NumSubExprs > WEAK); 4584ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith return cast<Expr>(SubExprs[WEAK]); 4585ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith } 4586276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4587276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman AtomicOp getOp() const { return Op; } 4588276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman unsigned getNumSubExprs() { return NumSubExprs; } 4589276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4590dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman Expr **getSubExprs() { return reinterpret_cast<Expr **>(SubExprs); } 4591dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman 4592276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman bool isVolatile() const { 4593276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return getPtr()->getType()->getPointeeType().isVolatileQualified(); 4594276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4595276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4596276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman bool isCmpXChg() const { 4597ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith return getOp() == AO__c11_atomic_compare_exchange_strong || 4598ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith getOp() == AO__c11_atomic_compare_exchange_weak || 4599ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith getOp() == AO__atomic_compare_exchange || 4600ff34d401ff385ef7173ca612432b4ea717fff690Richard Smith getOp() == AO__atomic_compare_exchange_n; 4601276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4602276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4603276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 4604276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman SourceLocation getRParenLoc() const { return RParenLoc; } 4605276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4606aa49a7d70e58dac2aeb40664ba16d2ea571b8c95Daniel Dunbar SourceRange getSourceRange() const LLVM_READONLY { 4607276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return SourceRange(BuiltinLoc, RParenLoc); 4608276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4609276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman static bool classof(const Stmt *T) { 4610276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return T->getStmtClass() == AtomicExprClass; 4611276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4612276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4613276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman // Iterators 4614276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman child_range children() { 4615276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return child_range(SubExprs, SubExprs+NumSubExprs); 4616276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4617276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman}; 46185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 46195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 46205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 4621