Expr.h revision 91a5755ad73c5dc1dfb167e448fdd74e75a6df56
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- Expr.h - Classes for representing expressions ----------*- C++ -*-===// 25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// The LLVM Compiler Infrastructure 45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source 60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details. 75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// This file defines the Expr interface and subclasses. 115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#ifndef LLVM_CLANG_AST_EXPR_H 155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#define LLVM_CLANG_AST_EXPR_H 165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson#include "clang/AST/APValue.h" 185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Stmt.h" 195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Type.h" 20161755a09898c95d21bfff33707da9ca41cd53c5John McCall#include "clang/AST/DeclAccessPair.h" 215baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall#include "clang/AST/OperationKinds.h" 22709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek#include "clang/AST/ASTVector.h" 23409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson#include "clang/AST/UsuallyTinyPtrVector.h" 24f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne#include "clang/Basic/TypeTraits.h" 255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/APSInt.h" 26525a05093a4816af961fe2bc6b8a81c17e2e26c2Chris Lattner#include "llvm/ADT/APFloat.h" 273b8d116703db8018f855cbb4733ace426422623bNate Begeman#include "llvm/ADT/SmallVector.h" 28b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar#include "llvm/ADT/StringRef.h" 29403ba3522d1b1c97ae5fad81c1a2c4b3a754e1c1Nick Lewycky#include <cctype> 305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 32590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner class ASTContext; 33c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson class APValue; 34c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class Decl; 35c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class IdentifierInfo; 36c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class ParmVarDecl; 378e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor class NamedDecl; 38c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class ValueDecl; 3956ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff class BlockDecl; 40409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson class CXXBaseSpecifier; 4188a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor class CXXOperatorCallExpr; 4288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor class CXXMemberCallExpr; 43f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall class ObjCPropertyRefExpr; 44833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall class TemplateArgumentLoc; 45d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall class TemplateArgumentListInfo; 4656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall class OpaqueValueExpr; 4788a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 487ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson/// \brief A simple array of base specifiers. 49f871d0cc377a1367b519a6cce26be74607566ebaJohn McCalltypedef llvm::SmallVector<CXXBaseSpecifier*, 4> CXXCastPath; 507ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson 515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Expr - This represents one expression. Note that Expr's are subclasses of 525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Stmt. This allows an expression to be transparently used any place a Stmt 535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is required. 545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Expr : public Stmt { 565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType TR; 57898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 588e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCallprotected: 59f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(StmtClass SC, QualType T, ExprValueKind VK, ExprObjectKind OK, 60561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool TD, bool VD, bool ID, bool ContainsUnexpandedParameterPack) 61561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Stmt(SC) 62561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor { 638e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.TypeDependent = TD; 648e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.ValueDependent = VD; 65561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = ID; 66f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprBits.ValueKind = VK; 67f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprBits.ObjectKind = OK; 68bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack; 69898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor setType(T); 70898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 71898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 720b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Construct an empty expression. 730b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor explicit Expr(StmtClass SC, EmptyShell) : Stmt(SC) { } 740b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 76f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor QualType getType() const { return TR; } 771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setType(QualType t) { 789d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // In C++, the type of an expression is always adjusted so that it 799d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // will not have reference type an expression will never have 809d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // reference type (C++ [expr]p6). Use 819d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // QualType::getNonReferenceType() to retrieve the non-reference 829d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // type. Additionally, inspect Expr::isLvalue to determine whether 839d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // an expression that is adjusted in this manner should be 849d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // considered an lvalue. 85905d11d53aeb6b26744f44fedc2b2820c7a62df6Douglas Gregor assert((t.isNull() || !t->isReferenceType()) && 868320aaaa01d931aa234fc3bce05b399ef41898d5Daniel Dunbar "Expressions can't have reference type"); 87f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor 881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TR = t; 899d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor } 9077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 91898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isValueDependent - Determines whether this expression is 92898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// value-dependent (C++ [temp.dep.constexpr]). For example, the 93898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// array bound of "Chars" in the following example is 941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// value-dependent. 95898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @code 96898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// template<int Size, char (&Chars)[Size]> struct meta_string; 97898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @endcode 988e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall bool isValueDependent() const { return ExprBits.ValueDependent; } 99898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1000b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Set whether this expression is value-dependent or not. 101561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor void setValueDependent(bool VD) { 102561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.ValueDependent = VD; 103561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (VD) 104561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 105561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 1060b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 107898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isTypeDependent - Determines whether this expression is 108898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// type-dependent (C++ [temp.dep.expr]), which means that its type 109898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// could change from one template instantiation to the next. For 110898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// example, the expressions "x" and "x + y" are type-dependent in 111898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// the following code, but "y" is not type-dependent: 112898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @code 1131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// template<typename T> 114898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// void add(T x, int y) { 115898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// x + y; 116898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// } 117898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @endcode 1188e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall bool isTypeDependent() const { return ExprBits.TypeDependent; } 119898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1200b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Set whether this expression is type-dependent or not. 121561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor void setTypeDependent(bool TD) { 122561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.TypeDependent = TD; 123561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (TD) 124561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 125561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 126561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 127561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// \brief Whether this expression is instantiation-dependent, meaning that 128561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// it depends in some way on a template parameter, even if neither its type 129561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// nor (constant) value can change due to the template instantiation. 130561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// 131561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// In the following example, the expression \c sizeof(sizeof(T() + T())) is 132561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// instantiation-dependent (since it involves a template parameter \c T), but 133561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// is neither type- nor value-dependent, since the type of the inner 134561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// \c sizeof is known (\c std::size_t) and therefore the size of the outer 135561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// \c sizeof is known. 136561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// 137561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// \code 138561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// template<typename T> 139561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// void f(T x, T y) { 140561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// sizeof(sizeof(T() + T()); 141561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// } 142561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// \endcode 143561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// 144561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool isInstantiationDependent() const { 145561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor return ExprBits.InstantiationDependent; 146561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 147561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 148561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// \brief Set whether this expression is instantiation-dependent or not. 149561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor void setInstantiationDependent(bool ID) { 150561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = ID; 151561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 1520b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 153d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \brief Whether this expression contains an unexpanded parameter 154d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// pack (for C++0x variadic templates). 155d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// 156d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// Given the following function template: 157d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// 158d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \code 159d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// template<typename F, typename ...Types> 160d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// void forward(const F &f, Types &&...args) { 161d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// f(static_cast<Types&&>(args)...); 162d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// } 163d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \endcode 164d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// 165d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// The expressions \c args and \c static_cast<Types&&>(args) both 166d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// contain parameter packs. 167d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor bool containsUnexpandedParameterPack() const { 168d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor return ExprBits.ContainsUnexpandedParameterPack; 169d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor } 170d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 171bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /// \brief Set the bit that describes whether this expression 172bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /// contains an unexpanded parameter pack. 173bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor void setContainsUnexpandedParameterPack(bool PP = true) { 174bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = PP; 175bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor } 176bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 1775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getExprLoc - Return the preferred location for the arrow when diagnosing 1785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// a problem with a generic expression. 17963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation getExprLoc() const; 1801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 181026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// isUnusedResultAWarning - Return true if this immediate expression should 182026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// be warned about if the result is unused. If so, fill in Loc and Ranges 183026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// with location to warn on and the source range[s] to report with the 184026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// warning. 185026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner bool isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1, 186df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump SourceRange &R2, ASTContext &Ctx) const; 1871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1887eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// isLValue - True if this expression is an "l-value" according to 1897eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// the rules of the current language. C and C++ give somewhat 1907eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// different rules for this concept, but in general, the result of 1917eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// an l-value expression identifies a specific object whereas the 1927eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// result of an r-value expression is a value detached from any 1937eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// specific storage. 1945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 1957eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// C++0x divides the concept of "r-value" into pure r-values 1967eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// ("pr-values") and so-called expiring values ("x-values"), which 1977eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// identify specific objects that can be safely cannibalized for 1987eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// their resources. This is an unfortunate abuse of terminology on 1997eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// the part of the C++ committee. In Clang, when we say "r-value", 2007eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// we generally mean a pr-value. 2017eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall bool isLValue() const { return getValueKind() == VK_LValue; } 2027eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall bool isRValue() const { return getValueKind() == VK_RValue; } 2037eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall bool isXValue() const { return getValueKind() == VK_XValue; } 2047eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall bool isGLValue() const { return getValueKind() != VK_RValue; } 2057eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall 2067eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall enum LValueClassification { 2075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_Valid, 2085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_NotObjectType, 2095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_IncompleteVoidType, 210fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff LV_DuplicateVectorComponents, 21186f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor LV_InvalidExpression, 212077f490d0a514dcc448475f33f799934252b85a7Fariborz Jahanian LV_InvalidMessageExpression, 2132514a309204341798f96912ce7a90841bea59727Fariborz Jahanian LV_MemberFunction, 214e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian LV_SubObjCPropertySetting, 215e873fb74219f48407ae0b8fa083aa7f0b6ff1427Douglas Gregor LV_ClassTemporary 2165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 2177eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// Reasons why an expression might not be an l-value. 2187eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall LValueClassification ClassifyLValue(ASTContext &Ctx) const; 21953202857c60214d80950a975e6e52aebf30bd16aEli Friedman 2205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type, 2215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// does not have an incomplete type, does not have a const-qualified type, 2221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// and if it is a structure or union, does not have any member (including, 2235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// recursively, any member or element of all contained aggregates or unions) 2245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// with a const-qualified type. 22544e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// 22644e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// \param Loc [in] [out] - A source location which *may* be filled 22744e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// in with the location of the expression making this a 22844e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// non-modifiable lvalue, if specified. 2295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum isModifiableLvalueResult { 2305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_Valid, 2315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_NotObjectType, 2325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_IncompleteVoidType, 233fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff MLV_DuplicateVectorComponents, 2345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_InvalidExpression, 235ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner MLV_LValueCast, // Specialized form of MLV_InvalidExpression. 2365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_IncompleteType, 2375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_ConstQualified, 2384f6a7d7ead09b439216c32f2de806a998aeb222aSteve Naroff MLV_ArrayType, 2395daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian MLV_NotBlockQualified, 240ba8d2d684e74a20bef03828c21c991d222c7e9e5Fariborz Jahanian MLV_ReadonlyProperty, 24186f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor MLV_NoSetterProperty, 2422514a309204341798f96912ce7a90841bea59727Fariborz Jahanian MLV_MemberFunction, 243e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian MLV_SubObjCPropertySetting, 244077f490d0a514dcc448475f33f799934252b85a7Fariborz Jahanian MLV_InvalidMessageExpression, 245e873fb74219f48407ae0b8fa083aa7f0b6ff1427Douglas Gregor MLV_ClassTemporary 2465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 24744e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx, 24844e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar SourceLocation *Loc = 0) const; 2491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2502111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \brief The return type of classify(). Represents the C++0x expression 2512111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// taxonomy. 2522111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl class Classification { 2532111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl public: 2542111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \brief The various classification results. Most of these mean prvalue. 2552111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl enum Kinds { 2562111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_LValue, 2572111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_XValue, 2582111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_Function, // Functions cannot be lvalues in C. 2592111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_Void, // Void cannot be an lvalue in C. 2601c860d5640e8eebb11a5d515a761242b66761b0bPeter Collingbourne CL_AddressableVoid, // Void expression whose address can be taken in C. 2612111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_DuplicateVectorComponents, // A vector shuffle with dupes. 2622111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_MemberFunction, // An expression referring to a member function 2632111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_SubObjCPropertySetting, 2642111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_ClassTemporary, // A prvalue of class type 265077f490d0a514dcc448475f33f799934252b85a7Fariborz Jahanian CL_ObjCMessageRValue, // ObjC message is an rvalue 2662111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_PRValue // A prvalue for any other reason, of any other type 2672111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl }; 2682111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \brief The results of modification testing. 2692111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl enum ModifiableType { 2702111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_Untested, // testModifiable was false. 2712111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_Modifiable, 2722111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_RValue, // Not modifiable because it's an rvalue 2732111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_Function, // Not modifiable because it's a function; C++ only 2742111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_LValueCast, // Same as CM_RValue, but indicates GCC cast-as-lvalue ext 2752111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_NotBlockQualified, // Not captured in the closure 2762111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_NoSetterProperty,// Implicit assignment to ObjC property without setter 2772111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_ConstQualified, 2782111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_ArrayType, 2792111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_IncompleteType 2802111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl }; 2812111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2822111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl private: 2832111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl friend class Expr; 2842111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2852111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl unsigned short Kind; 2862111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl unsigned short Modifiable; 2872111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2882111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl explicit Classification(Kinds k, ModifiableType m) 2892111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl : Kind(k), Modifiable(m) 2902111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl {} 2912111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2922111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl public: 2932111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification() {} 2942111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2952111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Kinds getKind() const { return static_cast<Kinds>(Kind); } 2962111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl ModifiableType getModifiable() const { 2972111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl assert(Modifiable != CM_Untested && "Did not test for modifiability."); 2982111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl return static_cast<ModifiableType>(Modifiable); 2992111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl } 3002111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isLValue() const { return Kind == CL_LValue; } 3012111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isXValue() const { return Kind == CL_XValue; } 3022111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isGLValue() const { return Kind <= CL_XValue; } 3032111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isPRValue() const { return Kind >= CL_Function; } 3042111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isRValue() const { return Kind >= CL_XValue; } 3052111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isModifiable() const { return getModifiable() == CM_Modifiable; } 3062c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor 3072c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor /// \brief Create a simple, modifiably lvalue 3082c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor static Classification makeSimpleLValue() { 3092c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor return Classification(CL_LValue, CM_Modifiable); 3102c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor } 3112c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor 3122111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl }; 313369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// \brief Classify - Classify this expression according to the C++0x 3142111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// expression taxonomy. 3152111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// 3162111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// C++0x defines ([basic.lval]) a new taxonomy of expressions to replace the 3172111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// old lvalue vs rvalue. This function determines the type of expression this 3182111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// is. There are three expression types: 3192111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// - lvalues are classical lvalues as in C++03. 3202111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// - prvalues are equivalent to rvalues in C++03. 3212111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// - xvalues are expressions yielding unnamed rvalue references, e.g. a 3222111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// function returning an rvalue reference. 3232111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// lvalues and xvalues are collectively referred to as glvalues, while 3242111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// prvalues and xvalues together form rvalues. 3252111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification Classify(ASTContext &Ctx) const { 3262111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl return ClassifyImpl(Ctx, 0); 3272111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl } 3282111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 329369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// \brief ClassifyModifiable - Classify this expression according to the 3302111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// C++0x expression taxonomy, and see if it is valid on the left side 3312111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// of an assignment. 3322111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// 3332111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// This function extends classify in that it also tests whether the 3342111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// expression is modifiable (C99 6.3.2.1p1). 3352111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \param Loc A source location that might be filled with a relevant location 3362111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// if the expression is not modifiable. 3372111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification ClassifyModifiable(ASTContext &Ctx, SourceLocation &Loc) const{ 3382111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl return ClassifyImpl(Ctx, &Loc); 3392111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl } 3402111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 341f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// getValueKindForType - Given a formal return or parameter type, 342f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// give its value kind. 343f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall static ExprValueKind getValueKindForType(QualType T) { 344f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall if (const ReferenceType *RT = T->getAs<ReferenceType>()) 3450943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall return (isa<LValueReferenceType>(RT) 3460943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall ? VK_LValue 3470943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall : (RT->getPointeeType()->isFunctionType() 3480943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall ? VK_LValue : VK_XValue)); 349f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall return VK_RValue; 350f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall } 351f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 352f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// getValueKind - The value kind that this expression produces. 353f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind getValueKind() const { 354f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall return static_cast<ExprValueKind>(ExprBits.ValueKind); 355f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall } 356f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 357f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// getObjectKind - The object kind that this expression produces. 358f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// Object kinds are meaningful only for expressions that yield an 359f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// l-value or x-value. 360f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprObjectKind getObjectKind() const { 361f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall return static_cast<ExprObjectKind>(ExprBits.ObjectKind); 362f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall } 363f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 36456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall bool isOrdinaryOrBitFieldObject() const { 36556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall ExprObjectKind OK = getObjectKind(); 36656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return (OK == OK_Ordinary || OK == OK_BitField); 36756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 36856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 369f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// setValueKind - Set the value kind produced by this expression. 370f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall void setValueKind(ExprValueKind Cat) { ExprBits.ValueKind = Cat; } 371f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 372f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// setObjectKind - Set the object kind produced by this expression. 373f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall void setObjectKind(ExprObjectKind Cat) { ExprBits.ObjectKind = Cat; } 374f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 3752111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redlprivate: 3762111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification ClassifyImpl(ASTContext &Ctx, SourceLocation *Loc) const; 3772111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 3782111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redlpublic: 3792111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 38033bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor /// \brief If this expression refers to a bit-field, retrieve the 38133bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor /// declaration of that bit-field. 38233bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor FieldDecl *getBitField(); 3835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 38438d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson const FieldDecl *getBitField() const { 38538d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson return const_cast<Expr*>(this)->getBitField(); 38638d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson } 3871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 388f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall /// \brief If this expression is an l-value for an Objective C 389f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall /// property, find the underlying property reference expression. 390f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall const ObjCPropertyRefExpr *getObjCProperty() const; 391f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall 392093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson /// \brief Returns whether this expression refers to a vector element. 393093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson bool refersToVectorElement() const; 394c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3952b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// isKnownToHaveBooleanValue - Return true if this is an integer expression 3962b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// that is known to return 0 or 1. This happens for _Bool/bool expressions 3972b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// but also int expressions which are produced by things like comparisons in 3982b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// C. 3992b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner bool isKnownToHaveBooleanValue() const; 400c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 4015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isIntegerConstantExpr - Return true if this expression is a valid integer 4025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// constant expression, and, if so, return its value in Result. If not a 4035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// valid i-c-e, return false and fill in Loc (if specified) with the location 4045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// of the invalid expression. 405590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx, 406590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner SourceLocation *Loc = 0, 4075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isEvaluated = true) const; 408590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const { 4098070a8497c0fb3e6f70a557f788405d8945b1208Daniel Dunbar llvm::APSInt X; 410590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner return isIntegerConstantExpr(X, Ctx, Loc); 4115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 412c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman /// isConstantInitializer - Returns true if this expression is a constant 413c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman /// initializer, which can be emitted at compile-time. 4144204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall bool isConstantInitializer(ASTContext &Ctx, bool ForRef) const; 4151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 41694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// EvalResult is a struct with detailed info about an evaluated expression. 41794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson struct EvalResult { 4182d6744ff04c1690a1485178d550d2fab84a0270bDaniel Dunbar /// Val - This is the value the expression can be folded to. 41994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson APValue Val; 4201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// HasSideEffects - Whether the evaluated expression has side effects. 42294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// For example, (f() && 0) can be folded, but it still has side effects. 42394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson bool HasSideEffects; 4241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// Diag - If the expression is unfoldable, then Diag contains a note 42694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// diagnostic indicating why it's not foldable. DiagLoc indicates a caret 42794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// position for the error, and DiagExpr is the expression that caused 42894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// the error. 42994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// If the expression is foldable, but not an integer constant expression, 43094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// Diag contains a note diagnostic that describes why it isn't an integer 43194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// constant expression. If the expression *is* an integer constant 43294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// expression, then Diag will be zero. 43394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson unsigned Diag; 43494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson const Expr *DiagExpr; 43594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson SourceLocation DiagLoc; 4361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 43794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson EvalResult() : HasSideEffects(false), Diag(0), DiagExpr(0) {} 438e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara 439e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara // isGlobalLValue - Return true if the evaluated lvalue expression 440e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara // is global. 441e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara bool isGlobalLValue() const; 442e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara // hasSideEffects - Return true if the evaluated expression has 443e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara // side effects. 444e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara bool hasSideEffects() const { 445e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara return HasSideEffects; 446e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara } 44794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson }; 44894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson 4496ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner /// Evaluate - Return true if this is a constant which we can fold using 450019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner /// any crazy technique (that has nothing to do with language standards) that 451019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner /// we want to. If this function returns true, it returns the folded constant 452019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner /// in Result. 4534ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool Evaluate(EvalResult &Result, const ASTContext &Ctx) const; 4545b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson 455cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall /// EvaluateAsBooleanCondition - Return true if this is a constant 456cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall /// which we we can fold and convert to a boolean condition using 457cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall /// any crazy technique that we want to. 4584ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool EvaluateAsBooleanCondition(bool &Result, const ASTContext &Ctx) const; 459cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall 4606ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner /// isEvaluatable - Call Evaluate to see if this expression can be constant 46145b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner /// folded, but discard the result. 4624ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool isEvaluatable(const ASTContext &Ctx) const; 463c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson 4646ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian /// HasSideEffects - This routine returns true for all those expressions 465138d6a6890c171068ac60430431eaadb3fcef9abGabor Greif /// which must be evaluated each time and must not be optimized away 4666ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian /// or evaluated at compile time. Example is a function call, volatile 4676ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian /// variable read. 4684ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool HasSideEffects(const ASTContext &Ctx) const; 469c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 47051fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson /// EvaluateAsInt - Call Evaluate and return the folded integer. This 47151fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson /// must be called on an expression that constant folds to an integer. 4724ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad llvm::APSInt EvaluateAsInt(const ASTContext &Ctx) const; 47351fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson 474b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman /// EvaluateAsLValue - Evaluate an expression to see if it's a lvalue 475b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman /// with link time known address. 4764ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx) const; 4771b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson 478e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara /// EvaluateAsLValue - Evaluate an expression to see if it's a lvalue. 4794ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool EvaluateAsAnyLValue(EvalResult &Result, const ASTContext &Ctx) const; 480e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara 48182214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Enumeration used to describe the kind of Null pointer constant 48282214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// returned from \c isNullPointerConstant(). 48382214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth enum NullPointerConstantKind { 48482214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Expression is not a Null pointer constant. 48582214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NPCK_NotNull = 0, 48682214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 48782214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Expression is a Null pointer constant built from a zero integer. 48882214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NPCK_ZeroInteger, 48982214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 49082214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Expression is a C++0X nullptr. 49182214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NPCK_CXX0X_nullptr, 49282214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 49382214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Expression is a GNU-style __null constant. 49482214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NPCK_GNUNull 49582214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth }; 49682214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 497ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Enumeration used to describe how \c isNullPointerConstant() 498ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// should cope with value-dependent expressions. 499ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor enum NullPointerConstantValueDependence { 500ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that the expression should never be value-dependent. 501ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_NeverValueDependent = 0, 502c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 503ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that a value-dependent expression of integral or 504ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// dependent type should be considered a null pointer constant. 505ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_ValueDependentIsNull, 506c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 507ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that a value-dependent expression should be considered 508ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// to never be a null pointer constant. 509ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_ValueDependentIsNotNull 510ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor }; 511c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 51282214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to 51382214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// a Null pointer constant. The return value can further distinguish the 51482214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// kind of NULL pointer constant that was detected. 51582214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NullPointerConstantKind isNullPointerConstant( 51682214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth ASTContext &Ctx, 51782214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NullPointerConstantValueDependence NPC) const; 518efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson 51944baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian /// isOBJCGCCandidate - Return true if this expression may be used in a read/ 5201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// write barrier. 521102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian bool isOBJCGCCandidate(ASTContext &Ctx) const; 5221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 52311ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis /// \brief Returns true if this expression is a bound member function. 52411ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis bool isBoundMemberFunction(ASTContext &Ctx) const; 52511ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis 526864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// \brief Given an expression of bound-member type, find the type 527864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// of the member. Returns null if this is an *overloaded* bound 528864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// member expression. 529864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall static QualType findBoundMemberType(const Expr *expr); 530864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 531369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// \brief Result type of CanThrow(). 532369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl enum CanThrowResult { 533369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CT_Cannot, 534369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CT_Dependent, 535369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CT_Can 536369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl }; 537369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// \brief Test if this expression, if evaluated, might throw, according to 538369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// the rules of C++ [expr.unary.noexcept]. 539369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CanThrowResult CanThrow(ASTContext &C) const; 540369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 54191a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall /// IgnoreImpCasts - Skip past any implicit casts which might 54291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall /// surround this expression. Only skips ImplicitCastExprs. 54391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall Expr *IgnoreImpCasts(); 54491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 5457e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall /// IgnoreImplicit - Skip past any implicit AST nodes which might 5467e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall /// surround this expression. 5477e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall Expr *IgnoreImplicit() { return cast<Expr>(Stmt::IgnoreImplicit()); } 5487e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall 5494e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// IgnoreParens - Ignore parentheses. If this Expr is a ParenExpr, return 5501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// its subexpression. If that subexpression is also a ParenExpr, 5514e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// then this method recursively returns its subexpression, and so forth. 5524e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// Otherwise, the method returns the current Expr. 5532b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner Expr *IgnoreParens(); 55456f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner 55556f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner /// IgnoreParenCasts - Ignore parentheses and casts. Strip off any ParenExpr 55627c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor /// or CastExprs, returning their operand. 55756f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner Expr *IgnoreParenCasts(); 5581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5592fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall /// IgnoreParenImpCasts - Ignore parentheses and implicit casts. Strip off any 5602fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall /// ParenExpr or ImplicitCastExprs, returning their operand. 5612fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall Expr *IgnoreParenImpCasts(); 5622fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall 5632f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg /// IgnoreConversionOperator - Ignore conversion operator. If this Expr is a 5642f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg /// call to a conversion operator, return the argument. 5652f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg Expr *IgnoreConversionOperator(); 5662f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg 5672f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg const Expr *IgnoreConversionOperator() const { 5682f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg return const_cast<Expr*>(this)->IgnoreConversionOperator(); 5692f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg } 5702f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg 5714d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek const Expr *IgnoreParenImpCasts() const { 5724d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek return const_cast<Expr*>(this)->IgnoreParenImpCasts(); 5734d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek } 574f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall 575f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall /// Ignore parentheses and lvalue casts. Strip off any ParenExpr and 576f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall /// CastExprs that represent lvalue casts, returning their operand. 577f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall Expr *IgnoreParenLValueCasts(); 578f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall 579f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall const Expr *IgnoreParenLValueCasts() const { 580f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall return const_cast<Expr*>(this)->IgnoreParenLValueCasts(); 581f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 5824d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek 583ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the 584ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// value (including ptr->int casts of the same size). Strip off any 585ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// ParenExpr or CastExprs, returning their operand. 586ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Expr *IgnoreParenNoopCasts(ASTContext &Ctx); 5871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5886eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// \brief Determine whether this expression is a default function argument. 5896eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// 5906eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// Default arguments are implicitly generated in the abstract syntax tree 591c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// by semantic analysis for function calls, object constructions, etc. in 5926eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// C++. Default arguments are represented by \c CXXDefaultArgExpr nodes; 5936eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// this routine also looks through any implicit casts to determine whether 5946eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// the expression is a default argument. 5956eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor bool isDefaultArgument() const; 596c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 597558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall /// \brief Determine whether the result of this expression is a 598558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall /// temporary object of the given class type. 599558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const; 6002f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 60175e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor /// \brief Whether this expression is an implicit reference to 'this' in C++. 60275e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor bool isImplicitCXXThis() const; 60391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 60491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall const Expr *IgnoreImpCasts() const { 60591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall return const_cast<Expr*>(this)->IgnoreImpCasts(); 60691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall } 6072b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner const Expr *IgnoreParens() const { 6084e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek return const_cast<Expr*>(this)->IgnoreParens(); 6094e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek } 61056f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner const Expr *IgnoreParenCasts() const { 61156f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner return const_cast<Expr*>(this)->IgnoreParenCasts(); 61256f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner } 613ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner const Expr *IgnoreParenNoopCasts(ASTContext &Ctx) const { 614ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner return const_cast<Expr*>(this)->IgnoreParenNoopCasts(Ctx); 615ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 6161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 617898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs); 618898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs); 619898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 6201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 6215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() >= firstExprConstant && 6221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump T->getStmtClass() <= lastExprConstant; 6235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Expr *) { return true; } 6255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 6265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6285549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek//===----------------------------------------------------------------------===// 6295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Primary Expressions. 6305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 6315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 63256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// OpaqueValueExpr - An expression referring to an opaque object of a 63356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// fixed type and value class. These don't correspond to concrete 63456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// syntax; instead they're used to express operations (usually copy 63556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// operations) on values whose source is generally obvious from 63656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// context. 63756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass OpaqueValueExpr : public Expr { 63856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall friend class ASTStmtReader; 63956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *SourceExpr; 64056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation Loc; 64156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 64256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallpublic: 64356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValueExpr(SourceLocation Loc, QualType T, ExprValueKind VK, 64456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall ExprObjectKind OK = OK_Ordinary) 64556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : Expr(OpaqueValueExprClass, T, VK, OK, 646561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor T->isDependentType(), T->isDependentType(), 647561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor T->isInstantiationDependentType(), 648561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false), 64956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceExpr(0), Loc(Loc) { 65056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 65156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 65256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// Given an expression which invokes a copy constructor --- i.e. a 65356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// CXXConstructExpr, possibly wrapped in an ExprWithCleanups --- 65456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// find the OpaqueValueExpr that's the source of the construction. 65556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static const OpaqueValueExpr *findInCopyConstruct(const Expr *expr); 65656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 65756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall explicit OpaqueValueExpr(EmptyShell Empty) 65856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : Expr(OpaqueValueExprClass, Empty) { } 65956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 66056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief Retrieve the location of this expression. 66156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation getLocation() const { return Loc; } 66256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 66356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceRange getSourceRange() const { 66456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (SourceExpr) return SourceExpr->getSourceRange(); 66556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return Loc; 66656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 66756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation getExprLoc() const { 66856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (SourceExpr) return SourceExpr->getExprLoc(); 66956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return Loc; 67056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 67156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 67256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall child_range children() { return child_range(); } 67356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 67456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// The source expression of an opaque value expression is the 67556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// expression which originally generated the value. This is 67656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// provided as a convenience for analyses that don't wish to 67756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// precisely model the execution behavior of the program. 67856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// 67956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// The source expression is typically set when building the 68056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// expression which binds the opaque value expression in the first 68156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// place. 68256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getSourceExpr() const { return SourceExpr; } 68356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall void setSourceExpr(Expr *e) { SourceExpr = e; } 68456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 68556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const Stmt *T) { 68656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return T->getStmtClass() == OpaqueValueExprClass; 68756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 68856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const OpaqueValueExpr *) { return true; } 68956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall}; 69056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 691a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// \brief Represents an explicit template argument list in C++, e.g., 692a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor/// the "<int>" in "sort<int>". 693a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregorstruct ExplicitTemplateArgumentList { 694a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief The source location of the left angle bracket ('<'); 695a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation LAngleLoc; 696c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 697a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief The source location of the right angle bracket ('>'); 698a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation RAngleLoc; 699c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 700a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief The number of template arguments in TemplateArgs. 701a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// The actual template arguments (if any) are stored after the 702a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// ExplicitTemplateArgumentList structure. 703a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor unsigned NumTemplateArgs; 704c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 705a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the template arguments 706833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateArgumentLoc *getTemplateArgs() { 707833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return reinterpret_cast<TemplateArgumentLoc *> (this + 1); 708a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 709c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 710a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the template arguments 711833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc *getTemplateArgs() const { 712833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return reinterpret_cast<const TemplateArgumentLoc *> (this + 1); 713a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 714d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 715d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void initializeFrom(const TemplateArgumentListInfo &List); 716bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor void initializeFrom(const TemplateArgumentListInfo &List, 717561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool &Dependent, bool &InstantiationDependent, 718561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool &ContainsUnexpandedParameterPack); 719d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void copyInto(TemplateArgumentListInfo &List) const; 7208dfbd8b252ba4e6cf4b7a3422f6ef0ca21312dfeArgyrios Kyrtzidis static std::size_t sizeFor(unsigned NumTemplateArgs); 721d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall static std::size_t sizeFor(const TemplateArgumentListInfo &List); 722a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor}; 723cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth 724cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// \brief A reference to a declared variable, function, enum, etc. 725cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// [C99 6.5.1p2] 726cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// 727cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// This encodes all the information about how a declaration is referenced 728cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// within an expression. 729cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// 730cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// There are several optional constructs attached to DeclRefExprs only when 731cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// they apply in order to conserve memory. These are laid out past the end of 732cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// the object, and flags in the DeclRefExprBitfield track whether they exist: 733cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// 734cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// DeclRefExprBits.HasQualifier: 735cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// Specifies when this declaration reference expression has a C++ 736cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// nested-name-specifier. 7373aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth/// DeclRefExprBits.HasFoundDecl: 7383aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth/// Specifies when this declaration reference expression has a record of 7393aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth/// a NamedDecl (different from the referenced ValueDecl) which was found 7403aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth/// during name lookup and/or overload resolution. 741cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// DeclRefExprBits.HasExplicitTemplateArgs: 742cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// Specifies when this declaration reference expression has an explicit 743cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// C++ template argument list. 7445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclRefExpr : public Expr { 745cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth /// \brief The declaration that we are referencing. 746cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth ValueDecl *D; 7472577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 748cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth /// \brief The location of the declaration name itself. 7495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 7509e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis 751cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth /// \brief Provides source/type location info for the declaration name 752cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth /// embedded in D. 7532577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameLoc DNLoc; 7542577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 7556857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// \brief Helper to retrieve the optional NestedNameSpecifierLoc. 7566857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth NestedNameSpecifierLoc &getInternalQualifierLoc() { 7577e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth assert(hasQualifier()); 7586857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth return *reinterpret_cast<NestedNameSpecifierLoc *>(this + 1); 759a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 760cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth 7616857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// \brief Helper to retrieve the optional NestedNameSpecifierLoc. 7626857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth const NestedNameSpecifierLoc &getInternalQualifierLoc() const { 7636857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth return const_cast<DeclRefExpr *>(this)->getInternalQualifierLoc(); 764a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 765096832c5ed5b9106fa177ebc148489760c3bc496John McCall 7663aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// \brief Test whether there is a distinct FoundDecl attached to the end of 7673aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// this DRE. 7683aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth bool hasFoundDecl() const { return DeclRefExprBits.HasFoundDecl; } 7693aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 7703aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// \brief Helper to retrieve the optional NamedDecl through which this 7713aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// reference occured. 7723aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *&getInternalFoundDecl() { 7733aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth assert(hasFoundDecl()); 7743aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth if (hasQualifier()) 7753aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return *reinterpret_cast<NamedDecl **>(&getInternalQualifierLoc() + 1); 7763aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return *reinterpret_cast<NamedDecl **>(this + 1); 7773aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth } 7783aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 7793aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// \brief Helper to retrieve the optional NamedDecl through which this 7803aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// reference occured. 7813aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *getInternalFoundDecl() const { 7823aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return const_cast<DeclRefExpr *>(this)->getInternalFoundDecl(); 7833aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth } 7843aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 7857e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth DeclRefExpr(NestedNameSpecifierLoc QualifierLoc, 7862577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ValueDecl *D, const DeclarationNameInfo &NameInfo, 7873aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *FoundD, 7882577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const TemplateArgumentListInfo *TemplateArgs, 789f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK); 7902577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 791663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis /// \brief Construct an empty declaration reference expression. 792663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis explicit DeclRefExpr(EmptyShell Empty) 793663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis : Expr(DeclRefExprClass, Empty) { } 7947e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 7950da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor /// \brief Computes the type- and value-dependence flags for this 7960da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor /// declaration reference expression. 7970da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor void computeDependence(); 7989e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis 7995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 800cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth DeclRefExpr(ValueDecl *D, QualType T, ExprValueKind VK, SourceLocation L) 801561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Expr(DeclRefExprClass, T, VK, OK_Ordinary, false, false, false, false), 802cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth D(D), Loc(L) { 803cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth DeclRefExprBits.HasQualifier = 0; 804cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth DeclRefExprBits.HasExplicitTemplateArgs = 0; 8053aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth DeclRefExprBits.HasFoundDecl = 0; 8060da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor computeDependence(); 8070da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor } 8081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 809a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor static DeclRefExpr *Create(ASTContext &Context, 81040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 811dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *D, 812a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation NameLoc, 813f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK, 8143aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *FoundD = 0, 8150da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor const TemplateArgumentListInfo *TemplateArgs = 0); 816663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis 8172577743c5650c646fb705df01403707e94f2df04Abramo Bagnara static DeclRefExpr *Create(ASTContext &Context, 81840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 8192577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ValueDecl *D, 8202577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 821f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK, 8223aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *FoundD = 0, 8232577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const TemplateArgumentListInfo *TemplateArgs = 0); 8242577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 825663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis /// \brief Construct an empty declaration reference expression. 826663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis static DeclRefExpr *CreateEmpty(ASTContext &Context, 8273aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth bool HasQualifier, 8283aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth bool HasFoundDecl, 829def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor bool HasExplicitTemplateArgs, 830def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor unsigned NumTemplateArgs); 8317e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 832cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth ValueDecl *getDecl() { return D; } 833cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth const ValueDecl *getDecl() const { return D; } 834cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth void setDecl(ValueDecl *NewD) { D = NewD; } 835904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor 8362577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo getNameInfo() const { 8372577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(getDecl()->getDeclName(), Loc, DNLoc); 8382577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 8392577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 8409e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis SourceLocation getLocation() const { return Loc; } 8410b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 84263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const; 8431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 844a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Determine whether this declaration reference was preceded by a 845a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// C++ nested-name-specifier, e.g., \c N::foo. 846cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth bool hasQualifier() const { return DeclRefExprBits.HasQualifier; } 8477e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 8487e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth /// \brief If the name was qualified, retrieves the nested-name-specifier 849a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// that precedes the name. Otherwise, returns NULL. 850a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NestedNameSpecifier *getQualifier() const { 851a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (!hasQualifier()) 852a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 8537e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 8546857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth return getInternalQualifierLoc().getNestedNameSpecifier(); 855a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 85640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor 8577e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth /// \brief If the name was qualified, retrieves the nested-name-specifier 85840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor /// that precedes the name, with source-location information. 85940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc getQualifierLoc() const { 86040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (!hasQualifier()) 86140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return NestedNameSpecifierLoc(); 8627e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 8636857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth return getInternalQualifierLoc(); 86440d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor } 86540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor 8663aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// \brief Get the NamedDecl through which this reference occured. 8673aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// 8683aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// This Decl may be different from the ValueDecl actually referred to in the 8693aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// presence of using declarations, etc. It always returns non-NULL, and may 8703aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// simple return the ValueDecl when appropriate. 8713aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *getFoundDecl() { 8723aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return hasFoundDecl() ? getInternalFoundDecl() : D; 8733aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth } 8743aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 8753aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// \brief Get the NamedDecl through which this reference occurred. 8763aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// See non-const variant. 8773aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth const NamedDecl *getFoundDecl() const { 8783aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return hasFoundDecl() ? getInternalFoundDecl() : D; 8793aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth } 8803aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 8817e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth /// \brief Determines whether this declaration reference was followed by an 8827e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth /// explict template argument list. 883096832c5ed5b9106fa177ebc148489760c3bc496John McCall bool hasExplicitTemplateArgs() const { 884cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth return DeclRefExprBits.HasExplicitTemplateArgs; 885096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 8867e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 887096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that followed the 888096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// member template name. 889096832c5ed5b9106fa177ebc148489760c3bc496John McCall ExplicitTemplateArgumentList &getExplicitTemplateArgs() { 890096832c5ed5b9106fa177ebc148489760c3bc496John McCall assert(hasExplicitTemplateArgs()); 8913aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth if (hasFoundDecl()) 8923aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return *reinterpret_cast<ExplicitTemplateArgumentList *>( 8933aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth &getInternalFoundDecl() + 1); 8943aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 8953aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth if (hasQualifier()) 8963aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return *reinterpret_cast<ExplicitTemplateArgumentList *>( 8973aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth &getInternalQualifierLoc() + 1); 8987e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 8993aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1); 900096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 9017e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 902096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that followed the 903096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// member template name. 904096832c5ed5b9106fa177ebc148489760c3bc496John McCall const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const { 905096832c5ed5b9106fa177ebc148489760c3bc496John McCall return const_cast<DeclRefExpr *>(this)->getExplicitTemplateArgs(); 906a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 907d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 908096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieves the optional explicit template arguments. 909096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// This points to the same data as getExplicitTemplateArgs(), but 910096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// returns null if there are no explicit template arguments. 911096832c5ed5b9106fa177ebc148489760c3bc496John McCall const ExplicitTemplateArgumentList *getExplicitTemplateArgsOpt() const { 912096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) return 0; 913096832c5ed5b9106fa177ebc148489760c3bc496John McCall return &getExplicitTemplateArgs(); 914096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 9157e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 916d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// \brief Copies the template arguments (if present) into the given 917d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// structure. 918d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 919096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (hasExplicitTemplateArgs()) 920096832c5ed5b9106fa177ebc148489760c3bc496John McCall getExplicitTemplateArgs().copyInto(List); 921d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall } 9227e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 923a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the location of the left angle bracket following the 924a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// member name ('<'), if any. 925a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation getLAngleLoc() const { 926096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 927a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return SourceLocation(); 9287e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 929096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().LAngleLoc; 930a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 9317e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 932a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the template arguments provided as part of this 933a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template-id. 934833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc *getTemplateArgs() const { 935096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 936a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 9377e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 938096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().getTemplateArgs(); 939a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 9407e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 941a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the number of template arguments provided as part of this 942a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template-id. 943a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor unsigned getNumTemplateArgs() const { 944096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 945a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 9467e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 947096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().NumTemplateArgs; 948a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 9497e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 950a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the location of the right angle bracket following the 951a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template arguments ('>'). 952a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation getRAngleLoc() const { 953096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 954a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return SourceLocation(); 9557e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 956096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().RAngleLoc; 957a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 9587e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 9591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 96099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor return T->getStmtClass() == DeclRefExprClass; 9615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const DeclRefExpr *) { return true; } 9631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 96477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 96563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 9667e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 96760adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 9683397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl friend class ASTStmtWriter; 9695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 9705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 971d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner/// PredefinedExpr - [C99 6.4.2.2] - A predefined identifier such as __func__. 972d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattnerclass PredefinedExpr : public Expr { 973227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic: 974227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson enum IdentType { 975227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson Func, 976227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson Function, 977848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson PrettyFunction, 978848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson /// PrettyFunctionNoVirtual - The same as PrettyFunction, except that the 979848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson /// 'virtual' keyword is omitted for virtual member functions. 980848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson PrettyFunctionNoVirtual 981227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson }; 9821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 983227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonprivate: 984227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson SourceLocation Loc; 985227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson IdentType Type; 986227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic: 9871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump PredefinedExpr(SourceLocation l, QualType type, IdentType IT) 988f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(PredefinedExprClass, type, VK_LValue, OK_Ordinary, 989bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor type->isDependentType(), type->isDependentType(), 990561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor type->isInstantiationDependentType(), 991bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 992f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Loc(l), Type(IT) {} 9931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 99417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor /// \brief Construct an empty predefined expression. 9951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit PredefinedExpr(EmptyShell Empty) 99617fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor : Expr(PredefinedExprClass, Empty) { } 99717fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 998227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson IdentType getIdentType() const { return Type; } 99917fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setIdentType(IdentType IT) { Type = IT; } 100017fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 100117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor SourceLocation getLocation() const { return Loc; } 100217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 100317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 1004848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson static std::string ComputeName(IdentType IT, const Decl *CurrentDecl); 10053a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 100663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 1007227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 10081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 10091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == PredefinedExprClass; 1010227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson } 1011d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner static bool classof(const PredefinedExpr *) { return true; } 10121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 101377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 101463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 1015227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson}; 1016227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 10179996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// \brief Used by IntegerLiteral/FloatingLiteral to store the numeric without 10189996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// leaking memory. 10199996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// 10209996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// For large floats/integers, APFloat/APInt will allocate memory from the heap 10219996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// to represent these numbers. Unfortunately, when we use a BumpPtrAllocator 10229996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// to allocate IntegerLiteral/FloatingLiteral nodes the memory associated with 10239996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// the APFloat/APInt values will never get freed. APNumericStorage uses 10249996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// ASTContext's allocator for memory allocation. 10259996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisclass APNumericStorage { 10269996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis unsigned BitWidth; 10279996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis union { 10289996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis uint64_t VAL; ///< Used to store the <= 64 bits integer value. 10299996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis uint64_t *pVal; ///< Used to store the >64 bits integer value. 10309996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis }; 10319996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10329996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis bool hasAllocation() const { return llvm::APInt::getNumWords(BitWidth) > 1; } 10339996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10349996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APNumericStorage(const APNumericStorage&); // do not implement 10359996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APNumericStorage& operator=(const APNumericStorage&); // do not implement 10369996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10379996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisprotected: 10389996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APNumericStorage() : BitWidth(0), VAL(0) { } 10399996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10409996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APInt getIntValue() const { 10419996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis unsigned NumWords = llvm::APInt::getNumWords(BitWidth); 10429996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis if (NumWords > 1) 10439996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return llvm::APInt(BitWidth, NumWords, pVal); 10449996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis else 10459996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return llvm::APInt(BitWidth, VAL); 10469996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 10479996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setIntValue(ASTContext &C, const llvm::APInt &Val); 10489996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis}; 10499996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10509996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisclass APIntStorage : public APNumericStorage { 10519996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidispublic: 10529996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APInt getValue() const { return getIntValue(); } 10539996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setValue(ASTContext &C, const llvm::APInt &Val) { setIntValue(C, Val); } 10549996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis}; 10559996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10569996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisclass APFloatStorage : public APNumericStorage { 10579996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidispublic: 10589996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APFloat getValue() const { return llvm::APFloat(getIntValue()); } 10599996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setValue(ASTContext &C, const llvm::APFloat &Val) { 10609996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis setIntValue(C, Val.bitcastToAPInt()); 10619996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 10629996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis}; 10639996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IntegerLiteral : public Expr { 10659996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APIntStorage Num; 10665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 10679996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10689996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis /// \brief Construct an empty integer literal. 10699996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis explicit IntegerLiteral(EmptyShell Empty) 10709996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis : Expr(IntegerLiteralClass, Empty) { } 10719996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 10731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy, 10745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // or UnsignedLongLongTy 10759996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis IntegerLiteral(ASTContext &C, const llvm::APInt &V, 10769996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis QualType type, SourceLocation l) 1077bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(IntegerLiteralClass, type, VK_RValue, OK_Ordinary, false, false, 1078561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false), 1079f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Loc(l) { 10805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(type->isIntegerType() && "Illegal type in IntegerLiteral"); 10811dd986dff9ddfbec687975700770bb377988e9edRichard Trieu assert(V.getBitWidth() == C.getIntWidth(type) && 10821dd986dff9ddfbec687975700770bb377988e9edRichard Trieu "Integer type is not the correct size for constant."); 10839996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis setValue(C, V); 10845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1085a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson 10861dd986dff9ddfbec687975700770bb377988e9edRichard Trieu /// \brief Returns a new integer literal with value 'V' and type 'type'. 10871dd986dff9ddfbec687975700770bb377988e9edRichard Trieu /// \param type - either IntTy, LongTy, LongLongTy, UnsignedIntTy, 10881dd986dff9ddfbec687975700770bb377988e9edRichard Trieu /// UnsignedLongTy, or UnsignedLongLongTy which should match the size of V 10891dd986dff9ddfbec687975700770bb377988e9edRichard Trieu /// \param V - the value that the returned integer literal contains. 10909996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis static IntegerLiteral *Create(ASTContext &C, const llvm::APInt &V, 10919996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis QualType type, SourceLocation l); 10921dd986dff9ddfbec687975700770bb377988e9edRichard Trieu /// \brief Returns a new empty integer literal. 10939996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis static IntegerLiteral *Create(ASTContext &C, EmptyShell Empty); 10940b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 10959996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APInt getValue() const { return Num.getValue(); } 109663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 10975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1098313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Retrieve the location of the literal. 1099313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getLocation() const { return Loc; } 1100313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 11019996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setValue(ASTContext &C, const llvm::APInt &Val) { Num.setValue(C, Val); } 11020b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation Location) { Loc = Location; } 11030b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 11041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 11051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == IntegerLiteralClass; 11065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const IntegerLiteral *) { return true; } 11081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 110977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 111063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 11115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CharacterLiteral : public Expr { 11145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned Value; 11155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 1116c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner bool IsWide; 11175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 11185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // type should be IntTy 1119c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner CharacterLiteral(unsigned value, bool iswide, QualType type, SourceLocation l) 1120bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(CharacterLiteralClass, type, VK_RValue, OK_Ordinary, false, false, 1121561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false), 1122f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Value(value), Loc(l), IsWide(iswide) { 11235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11240b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 11250b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Construct an empty character literal. 11260b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { } 11270b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 1128018d8e0596dd57401eeddcf11ac84ff0a065fbbeChris Lattner SourceLocation getLocation() const { return Loc; } 1129c250aae4f645833aed3a6321bc8598f7330dce8dChris Lattner bool isWide() const { return IsWide; } 11301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 113163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 11321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getValue() const { return Value; } 11345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11350b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation Location) { Loc = Location; } 11360b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setWide(bool W) { IsWide = W; } 11370b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setValue(unsigned Val) { Value = Val; } 11380b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 11391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 11401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CharacterLiteralClass; 11415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CharacterLiteral *) { return true; } 114377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 114477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 114563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 11465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FloatingLiteral : public Expr { 11499996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APFloatStorage Num; 1150720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek bool IsExact : 1; 11515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 11529996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 11539996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis FloatingLiteral(ASTContext &C, const llvm::APFloat &V, bool isexact, 1154720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek QualType Type, SourceLocation L) 1155bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(FloatingLiteralClass, Type, VK_RValue, OK_Ordinary, false, false, 1156561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false), 11579996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis IsExact(isexact), Loc(L) { 11589996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis setValue(C, V); 11599996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 11605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 116117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor /// \brief Construct an empty floating-point literal. 11621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit FloatingLiteral(EmptyShell Empty) 11639996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis : Expr(FloatingLiteralClass, Empty), IsExact(false) { } 116417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 11659996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidispublic: 11669996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis static FloatingLiteral *Create(ASTContext &C, const llvm::APFloat &V, 11679996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis bool isexact, QualType Type, SourceLocation L); 11689996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis static FloatingLiteral *Create(ASTContext &C, EmptyShell Empty); 11699996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 11709996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APFloat getValue() const { return Num.getValue(); } 11719996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setValue(ASTContext &C, const llvm::APFloat &Val) { 11729996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis Num.setValue(C, Val); 11739996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 117417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 1175720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek bool isExact() const { return IsExact; } 117617fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setExact(bool E) { IsExact = E; } 1177c9bec4bfea9090a08dd83a7b213f0c8adf8d78ecChris Lattner 1178da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// getValueAsApproximateDouble - This returns the value as an inaccurate 1179da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// double. Note that this may cause loss of precision, but is useful for 1180da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// debugging dumps, etc. 1181da8249e57f3badecf925571881fe57243935c6c1Chris Lattner double getValueAsApproximateDouble() const; 11821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 118317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor SourceLocation getLocation() const { return Loc; } 118417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 118517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 118663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 11875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 11891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == FloatingLiteralClass; 11905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const FloatingLiteral *) { return true; } 11921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 119377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 119463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 11955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11975d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// ImaginaryLiteral - We support imaginary integer and floating point literals, 11985d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// like "1.0i". We represent these as a wrapper around FloatingLiteral and 11995d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// IntegerLiteral classes. Instances of this class always have a Complex type 12005d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// whose element type matches the subexpression. 12015d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// 12025d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerclass ImaginaryLiteral : public Expr { 12035549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 12045d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerpublic: 12055d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner ImaginaryLiteral(Expr *val, QualType Ty) 1206bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(ImaginaryLiteralClass, Ty, VK_RValue, OK_Ordinary, false, false, 1207561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false), 1208f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Val(val) {} 12091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1210cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor /// \brief Build an empty imaginary literal. 12111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ImaginaryLiteral(EmptyShell Empty) 1212cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor : Expr(ImaginaryLiteralClass, Empty) { } 1213cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 12145549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 12155549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 1216cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 1217cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 121863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return Val->getSourceRange(); } 12191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 12201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ImaginaryLiteralClass; 12215d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner } 12225d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner static bool classof(const ImaginaryLiteral *) { return true; } 12231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12245d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner // Iterators 122563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Val, &Val+1); } 12265d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner}; 12275d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner 1228e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// StringLiteral - This represents a string literal expression, e.g. "foo" 1229e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// or L"bar" (wide strings). The actual string is returned by getStrData() 1230e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// is NOT null-terminated, and the length of the string is determined by 1231a7ad98ff0919d6a24ea7c46634ea29bea551c1a0Chris Lattner/// calling getByteLength(). The C type for a string is always a 1232c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// ConstantArrayType. In C++, the char type is const qualified, in C it is 1233c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// not. 1234690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// 1235690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// Note that strings in C can be formed by concatenation of multiple string 12368bea7c0ee44c71c817de7dc2be932b73bec90c9fChris Lattner/// literal pptokens in translation phase #6. This keeps track of the locations 1237690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// of each of these pieces. 1238c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// 1239c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// Strings in C can also be truncated and extended by assigning into arrays, 1240c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// e.g. with constructs like: 1241c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// char X[2] = "foobar"; 1242c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// In this case, getByteLength() will return 6, but the string literal will 1243c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// have type "char[2]". 12445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass StringLiteral : public Expr { 12453e2193ce5feb2feb092e5ae615e85148e06e9fd2Anders Carlsson friend class ASTStmtReader; 12463e2193ce5feb2feb092e5ae615e85148e06e9fd2Anders Carlsson 12475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *StrData; 12485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned ByteLength; 12495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool IsWide; 12503e2193ce5feb2feb092e5ae615e85148e06e9fd2Anders Carlsson bool IsPascal; 1251726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner unsigned NumConcatenated; 1252726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner SourceLocation TokLocs[1]; 12532085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner 1254f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall StringLiteral(QualType Ty) : 1255561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Expr(StringLiteralClass, Ty, VK_LValue, OK_Ordinary, false, false, false, 1256561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false) {} 12571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 12592085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// This is the "fully general" constructor that allows representation of 12602085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// strings formed from multiple concatenated tokens. 126165aa6885818d4b4eea2e5a9d12085b2398148662Jay Foad static StringLiteral *Create(ASTContext &C, llvm::StringRef Str, bool Wide, 126265aa6885818d4b4eea2e5a9d12085b2398148662Jay Foad bool Pascal, QualType Ty, 1263a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson const SourceLocation *Loc, unsigned NumStrs); 12642085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner 12652085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// Simple constructor for string literals made from one token. 126665aa6885818d4b4eea2e5a9d12085b2398148662Jay Foad static StringLiteral *Create(ASTContext &C, llvm::StringRef Str, bool Wide, 12673e2193ce5feb2feb092e5ae615e85148e06e9fd2Anders Carlsson bool Pascal, QualType Ty, SourceLocation Loc) { 126865aa6885818d4b4eea2e5a9d12085b2398148662Jay Foad return Create(C, Str, Wide, Pascal, Ty, &Loc, 1); 12692085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 1270a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson 1271673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor /// \brief Construct an empty string literal. 1272673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor static StringLiteral *CreateEmpty(ASTContext &C, unsigned NumStrs); 1273673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 1274b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar llvm::StringRef getString() const { 1275b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar return llvm::StringRef(StrData, ByteLength); 1276b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar } 12772f4eaef37476ae6891ede8ba215d0f6fd093629bBenjamin Kramer 12785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getByteLength() const { return ByteLength; } 1279673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 1280673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor /// \brief Sets the string data to the given string data. 1281b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar void setString(ASTContext &C, llvm::StringRef Str); 1282673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 12835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isWide() const { return IsWide; } 12843e2193ce5feb2feb092e5ae615e85148e06e9fd2Anders Carlsson bool isPascal() const { return IsPascal; } 12853e2193ce5feb2feb092e5ae615e85148e06e9fd2Anders Carlsson 12868d4141f83d9de379547cf05bd75d4c6cf894b189Steve Naroff bool containsNonAsciiOrNull() const { 1287b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar llvm::StringRef Str = getString(); 1288b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar for (unsigned i = 0, e = Str.size(); i != e; ++i) 1289b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar if (!isascii(Str[i]) || !Str[i]) 129033fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff return true; 129133fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff return false; 129233fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff } 1293726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner /// getNumConcatenated - Get the number of string literal tokens that were 1294726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner /// concatenated in translation phase #6 to form this string literal. 1295726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner unsigned getNumConcatenated() const { return NumConcatenated; } 12961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1297726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner SourceLocation getStrTokenLoc(unsigned TokNum) const { 1298726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner assert(TokNum < NumConcatenated && "Invalid tok number"); 1299726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner return TokLocs[TokNum]; 1300726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner } 13011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setStrTokenLoc(unsigned TokNum, SourceLocation L) { 1302673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor assert(TokNum < NumConcatenated && "Invalid tok number"); 1303673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor TokLocs[TokNum] = L; 1304673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor } 130508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 130608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// getLocationOfByte - Return a source location that points to the specified 130708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// byte of this string literal. 130808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// 130908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// Strings are amazingly complex. They can be formed from multiple tokens 131008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// and can have escape sequences in them in addition to the usual trigraph 131108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// and escaped newline business. This routine handles this complexity. 131208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// 131308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner SourceLocation getLocationOfByte(unsigned ByteNo, const SourceManager &SM, 131408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner const LangOptions &Features, 131508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner const TargetInfo &Target) const; 1316673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 1317b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner typedef const SourceLocation *tokloc_iterator; 1318b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner tokloc_iterator tokloc_begin() const { return TokLocs; } 1319b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner tokloc_iterator tokloc_end() const { return TokLocs+NumConcatenated; } 13205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 132163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 13221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(TokLocs[0], TokLocs[NumConcatenated-1]); 13235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 13251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == StringLiteralClass; 13265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const StringLiteral *) { return true; } 13281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 132977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 133063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 13315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 13325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ParenExpr - This represents a parethesized expression, e.g. "(1)". This 13345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// AST node is only formed if full location information is requested. 13355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ParenExpr : public Expr { 13365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation L, R; 13375549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 13385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 13395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ParenExpr(SourceLocation l, SourceLocation r, Expr *val) 1340898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Expr(ParenExprClass, val->getType(), 1341f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall val->getValueKind(), val->getObjectKind(), 1342bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor val->isTypeDependent(), val->isValueDependent(), 1343561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor val->isInstantiationDependent(), 1344bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor val->containsUnexpandedParameterPack()), 1345898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor L(l), R(r), Val(val) {} 13461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1347c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor /// \brief Construct an empty parenthesized expression. 13481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ParenExpr(EmptyShell Empty) 1349c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor : Expr(ParenExprClass, Empty) { } 1350c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor 13515549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 13525549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 1353c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 1354c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor 135563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(L, R); } 13565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1357313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Get the location of the left parentheses '('. 1358313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getLParen() const { return L; } 1359c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setLParen(SourceLocation Loc) { L = Loc; } 1360313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 1361313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Get the location of the right parentheses ')'. 1362313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getRParen() const { return R; } 1363c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setRParen(SourceLocation Loc) { R = Loc; } 1364313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 13651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 13661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ParenExprClass; 13675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ParenExpr *) { return true; } 13691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 137077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 137163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Val, &Val+1); } 13725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 13735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13750518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// UnaryOperator - This represents the unary-expression's (except sizeof and 13760518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// alignof), the postinc/postdec operators from postfix-expression, and various 13775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// extensions. 1378dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 1379dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Notes on various nodes: 1380dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 1381dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Real/Imag - These return the real/imag part of a complex operand. If 1382dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// applied to a non-complex value, the former returns its operand and the 1383dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// later returns zero in the type of the operand. 1384dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 13855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass UnaryOperator : public Expr { 13865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 13875baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall typedef UnaryOperatorKind Opcode; 13885baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 13895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 13900799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall unsigned Opc : 5; 13915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 13920799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Stmt *Val; 13931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 13945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1395f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall UnaryOperator(Expr *input, Opcode opc, QualType type, 1396f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, SourceLocation l) 1397f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(UnaryOperatorClass, type, VK, OK, 1398de7e66256b1bdfcf6526994825a8c8fced52a31cEli Friedman input->isTypeDependent() || type->isDependentType(), 1399bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor input->isValueDependent(), 1400561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (input->isInstantiationDependent() || 1401561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor type->isInstantiationDependentType()), 1402bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor input->containsUnexpandedParameterPack()), 14030799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Opc(opc), Loc(l), Val(input) {} 14045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14050b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor /// \brief Build an empty unary operator. 14061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit UnaryOperator(EmptyShell Empty) 14072de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall : Expr(UnaryOperatorClass, Empty), Opc(UO_AddrOf) { } 14080b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 14090799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Opcode getOpcode() const { return static_cast<Opcode>(Opc); } 14100b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOpcode(Opcode O) { Opc = O; } 14110b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 14125549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() const { return cast<Expr>(Val); } 14130b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setSubExpr(Expr *E) { Val = E; } 14140b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 14155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOperatorLoc - Return the location of the operator. 14165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getOperatorLoc() const { return Loc; } 14170b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOperatorLoc(SourceLocation L) { Loc = L; } 14180b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 14195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isPostfix - Return true if this is a postfix operation, like x++. 14202085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static bool isPostfix(Opcode Op) { 14212de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Op == UO_PostInc || Op == UO_PostDec; 14222085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 14235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1424cc7bd10c0de9449b795bda3c5dcc6d83cc48436bZhanyong Wan /// isPrefix - Return true if this is a prefix operation, like --x. 14252085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static bool isPrefix(Opcode Op) { 14262de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Op == UO_PreInc || Op == UO_PreDec; 14272085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 14285a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek 14290799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isPrefix() const { return isPrefix(getOpcode()); } 14300799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isPostfix() const { return isPostfix(getOpcode()); } 14312de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall bool isIncrementOp() const { 1432993cdca0fed7deb646e4654dfb2607227a497faaBenjamin Kramer return Opc == UO_PreInc || Opc == UO_PostInc; 14332de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 14342de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall bool isIncrementDecrementOp() const { 1435993cdca0fed7deb646e4654dfb2607227a497faaBenjamin Kramer return Opc <= UO_PreDec; 14362de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 14372de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isArithmeticOp(Opcode Op) { 14382de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Op >= UO_Plus && Op <= UO_LNot; 14392de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 14400799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isArithmeticOp() const { return isArithmeticOp(getOpcode()); } 14411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 14435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// corresponds to, e.g. "sizeof" or "[pre]++" 14445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static const char *getOpcodeStr(Opcode Op); 14455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1446bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// \brief Retrieve the unary opcode that corresponds to the given 1447bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// overloaded operator. 1448bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix); 1449bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 1450bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// \brief Retrieve the overloaded operator kind that corresponds to 1451bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// the given unary opcode. 1452bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); 1453bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 145463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 14555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (isPostfix()) 14565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(Val->getLocStart(), Loc); 14575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else 14585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(Loc, Val->getLocEnd()); 14595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 146063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation getExprLoc() const { return Loc; } 14611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 14631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == UnaryOperatorClass; 14645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 14655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const UnaryOperator *) { return true; } 14661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 146777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 146863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Val, &Val+1); } 14695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 14705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14718ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// OffsetOfExpr - [C99 7.17] - This represents an expression of the form 14728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// offsetof(record-type, member-designator). For example, given: 14738ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// @code 14748ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct S { 14758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// float f; 1476c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt/// double d; 14778ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// }; 14788ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct T { 14798ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// int i; 14808ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct S s[10]; 14818ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// }; 14828ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// @endcode 1483c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt/// we can represent and evaluate the expression @c offsetof(struct T, s[2].d). 14848ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 14858ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorclass OffsetOfExpr : public Expr { 14868ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorpublic: 14878ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // __builtin_offsetof(type, identifier(.identifier|[expr])*) 14888ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor class OffsetOfNode { 14898ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor public: 14908ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief The kind of offsetof node we have. 14918ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor enum Kind { 1492cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief An index into an array. 14938ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Array = 0x00, 1494cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief A field. 14958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Field = 0x01, 1496cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief A field in a dependent type, known only by its name. 1497cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor Identifier = 0x02, 1498cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief An implicit indirection through a C++ base class, when the 1499cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// field found is in a base class. 1500cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor Base = 0x03 15018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor }; 15028ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 15038ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor private: 15048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor enum { MaskBits = 2, Mask = 0x03 }; 1505c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15068ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief The source range that covers this part of the designator. 15078ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceRange Range; 1508c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15098ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief The data describing the designator, which comes in three 15108ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// different forms, depending on the lower two bits. 1511c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// - An unsigned index into the array of Expr*'s stored after this node 15128ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// in memory, for [constant-expression] designators. 15138ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// - A FieldDecl*, for references to a known field. 15148ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// - An IdentifierInfo*, for references to a field with a given name 15158ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// when the class type is dependent. 1516c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// - A CXXBaseSpecifier*, for references that look at a field in a 1517cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// base class. 15188ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor uintptr_t Data; 1519c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15208ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor public: 15218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Create an offsetof node that refers to an array element. 1522c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode(SourceLocation LBracketLoc, unsigned Index, 15238ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RBracketLoc) 15248ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor : Range(LBracketLoc, RBracketLoc), Data((Index << 2) | Array) { } 1525c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15268ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Create an offsetof node that refers to a field. 1527c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode(SourceLocation DotLoc, FieldDecl *Field, 15288ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation NameLoc) 1529c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc), 15308ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Data(reinterpret_cast<uintptr_t>(Field) | OffsetOfNode::Field) { } 1531c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15328ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Create an offsetof node that refers to an identifier. 15338ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor OffsetOfNode(SourceLocation DotLoc, IdentifierInfo *Name, 15348ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation NameLoc) 1535c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc), 15368ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Data(reinterpret_cast<uintptr_t>(Name) | Identifier) { } 1537cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor 1538cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief Create an offsetof node that refers into a C++ base class. 1539cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor explicit OffsetOfNode(const CXXBaseSpecifier *Base) 1540cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor : Range(), Data(reinterpret_cast<uintptr_t>(Base) | OffsetOfNode::Base) {} 1541c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15428ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Determine what kind of offsetof node this is. 1543c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Kind getKind() const { 15448ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return static_cast<Kind>(Data & Mask); 15458ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1546c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15478ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief For an array element node, returns the index into the array 15488ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// of expressions. 15498ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned getArrayExprIndex() const { 15508ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(getKind() == Array); 15518ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return Data >> 2; 15528ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 15538ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 15548ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief For a field offsetof node, returns the field. 15558ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor FieldDecl *getField() const { 15568ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(getKind() == Field); 1557cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor return reinterpret_cast<FieldDecl *>(Data & ~(uintptr_t)Mask); 15588ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1559c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15608ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief For a field or identifier offsetof node, returns the name of 15618ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// the field. 15628ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor IdentifierInfo *getFieldName() const; 1563c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1564cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief For a base class node, returns the base specifier. 1565cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor CXXBaseSpecifier *getBase() const { 1566cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor assert(getKind() == Base); 1567c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return reinterpret_cast<CXXBaseSpecifier *>(Data & ~(uintptr_t)Mask); 1568cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor } 1569c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15708ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Retrieve the source range that covers this offsetof node. 15718ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// 15728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// For an array element node, the source range contains the locations of 15738ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// the square brackets. For a field or identifier node, the source range 1574c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// contains the location of the period (if there is one) and the 15758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// identifier. 157606dec892b5300b43263d25c5476b506c9d6cfbadAbramo Bagnara SourceRange getSourceRange() const { return Range; } 15778ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor }; 15788ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 15798ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorprivate: 1580c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15818ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation OperatorLoc, RParenLoc; 15828ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Base type; 15838ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TypeSourceInfo *TSInfo; 15848ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Number of sub-components (i.e. instances of OffsetOfNode). 15858ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumComps; 15868ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Number of sub-expressions (i.e. array subscript expressions). 15878ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumExprs; 1588c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1589c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfExpr(ASTContext &C, QualType type, 15908ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation OperatorLoc, TypeSourceInfo *tsi, 1591c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode* compsPtr, unsigned numComps, 15928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr** exprsPtr, unsigned numExprs, 15938ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc); 15948ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 15958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor explicit OffsetOfExpr(unsigned numComps, unsigned numExprs) 15968ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor : Expr(OffsetOfExprClass, EmptyShell()), 1597c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt TSInfo(0), NumComps(numComps), NumExprs(numExprs) {} 15988ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 15998ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorpublic: 1600c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1601c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt static OffsetOfExpr *Create(ASTContext &C, QualType type, 1602c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt SourceLocation OperatorLoc, TypeSourceInfo *tsi, 1603c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode* compsPtr, unsigned numComps, 16048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr** exprsPtr, unsigned numExprs, 16058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc); 16068ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 1607c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt static OffsetOfExpr *CreateEmpty(ASTContext &C, 16088ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumComps, unsigned NumExprs); 16098ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 16108ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// getOperatorLoc - Return the location of the operator. 16118ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation getOperatorLoc() const { return OperatorLoc; } 16128ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setOperatorLoc(SourceLocation L) { OperatorLoc = L; } 16138ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 16148ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Return the location of the right parentheses. 16158ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 16168ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setRParenLoc(SourceLocation R) { RParenLoc = R; } 1617c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 16188ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TypeSourceInfo *getTypeSourceInfo() const { 16198ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return TSInfo; 16208ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 16218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setTypeSourceInfo(TypeSourceInfo *tsi) { 16228ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TSInfo = tsi; 16238ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1624c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 16258cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne const OffsetOfNode &getComponent(unsigned Idx) const { 16268ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumComps && "Subscript out of range"); 16278cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne return reinterpret_cast<const OffsetOfNode *> (this + 1)[Idx]; 16288ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 16298ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 16308ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setComponent(unsigned Idx, OffsetOfNode ON) { 16318ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumComps && "Subscript out of range"); 16328ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<OffsetOfNode *> (this + 1)[Idx] = ON; 16338ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1634c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 16358ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned getNumComponents() const { 16368ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return NumComps; 16378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 16388ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 16398ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr* getIndexExpr(unsigned Idx) { 16408ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumExprs && "Subscript out of range"); 16418ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return reinterpret_cast<Expr **>( 16428ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx]; 16438ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 16448cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne const Expr *getIndexExpr(unsigned Idx) const { 16458cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne return const_cast<OffsetOfExpr*>(this)->getIndexExpr(Idx); 16468cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne } 16478ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 16488ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setIndexExpr(unsigned Idx, Expr* E) { 16498ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumComps && "Subscript out of range"); 16508ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<Expr **>( 16518ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx] = E; 16528ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1653c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 16548ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned getNumExpressions() const { 16558ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return NumExprs; 16568ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 16578ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 165863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 16598ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return SourceRange(OperatorLoc, RParenLoc); 16608ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 16618ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 16628ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor static bool classof(const Stmt *T) { 16638ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return T->getStmtClass() == OffsetOfExprClass; 16648ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 16658ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 16668ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor static bool classof(const OffsetOfExpr *) { return true; } 16678ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 16688ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Iterators 166963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 167063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt **begin = 167163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall reinterpret_cast<Stmt**>(reinterpret_cast<OffsetOfNode*>(this + 1) 167263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall + NumComps); 167363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(begin, begin + NumExprs); 167463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 16758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor}; 16768ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 1677f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne/// UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) 1678f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne/// expression operand. Used for sizeof/alignof (C99 6.5.3.4) and 1679f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne/// vec_step (OpenCL 1.1 6.11.12). 1680f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourneclass UnaryExprOrTypeTraitExpr : public Expr { 1681f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne unsigned Kind : 2; 16820518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl bool isType : 1; // true if operand is a type, false if an expression 1683d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl union { 1684a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *Ty; 1685d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl Stmt *Ex; 1686d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl } Argument; 16875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation OpLoc, RParenLoc; 168842602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor 16895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1690f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, TypeSourceInfo *TInfo, 1691f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne QualType resultType, SourceLocation op, 1692f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne SourceLocation rp) : 1693f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_RValue, OK_Ordinary, 1694ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor false, // Never type-dependent (C++ [temp.dep.expr]p3). 16952850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl // Value-dependent if the argument is type-dependent. 1696bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor TInfo->getType()->isDependentType(), 1697561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor TInfo->getType()->isInstantiationDependentType(), 1698bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor TInfo->getType()->containsUnexpandedParameterPack()), 1699f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne Kind(ExprKind), isType(true), OpLoc(op), RParenLoc(rp) { 1700a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall Argument.Ty = TInfo; 1701ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor } 1702ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor 1703f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, Expr *E, 1704f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne QualType resultType, SourceLocation op, 1705f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne SourceLocation rp) : 1706f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_RValue, OK_Ordinary, 1707ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor false, // Never type-dependent (C++ [temp.dep.expr]p3). 1708ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor // Value-dependent if the argument is type-dependent. 1709bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor E->isTypeDependent(), 1710561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor E->isInstantiationDependent(), 1711bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor E->containsUnexpandedParameterPack()), 1712f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne Kind(ExprKind), isType(false), OpLoc(op), RParenLoc(rp) { 1713ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor Argument.Ex = E; 1714d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl } 17150518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl 17160b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor /// \brief Construct an empty sizeof/alignof expression. 1717f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne explicit UnaryExprOrTypeTraitExpr(EmptyShell Empty) 1718f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne : Expr(UnaryExprOrTypeTraitExprClass, Empty) { } 17190b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 1720f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne UnaryExprOrTypeTrait getKind() const { 1721f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne return static_cast<UnaryExprOrTypeTrait>(Kind); 1722f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne } 1723f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne void setKind(UnaryExprOrTypeTrait K) { Kind = K; } 17240b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 17250518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl bool isArgumentType() const { return isType; } 17260518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType getArgumentType() const { 17275ab75172051a6d2ea71a80a79e81c65519fd3462John McCall return getArgumentTypeInfo()->getType(); 17285ab75172051a6d2ea71a80a79e81c65519fd3462John McCall } 1729a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *getArgumentTypeInfo() const { 17300518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl assert(isArgumentType() && "calling getArgumentType() when arg is expr"); 17315ab75172051a6d2ea71a80a79e81c65519fd3462John McCall return Argument.Ty; 17320518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 1733caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner Expr *getArgumentExpr() { 17340518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl assert(!isArgumentType() && "calling getArgumentExpr() when arg is type"); 1735d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl return static_cast<Expr*>(Argument.Ex); 17360518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 1737caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner const Expr *getArgumentExpr() const { 1738f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne return const_cast<UnaryExprOrTypeTraitExpr*>(this)->getArgumentExpr(); 1739caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner } 17400b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 17410b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setArgument(Expr *E) { Argument.Ex = E; isType = false; } 1742a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall void setArgument(TypeSourceInfo *TInfo) { 1743a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall Argument.Ty = TInfo; 17441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump isType = true; 17450b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor } 17460b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 17470518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl /// Gets the argument type, or the type of the argument expression, whichever 17480518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl /// is appropriate. 17490518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType getTypeOfArgument() const { 17500518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl return isArgumentType() ? getArgumentType() : getArgumentExpr()->getType(); 17510518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 17520518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl 175376e773a443be9f006610f46529e07d4c8d857680Chris Lattner SourceLocation getOperatorLoc() const { return OpLoc; } 17540b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOperatorLoc(SourceLocation L) { OpLoc = L; } 17550b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 17560b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 17570b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1758866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek 175963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 1760866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek return SourceRange(OpLoc, RParenLoc); 1761866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek } 17625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 17631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 1764f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne return T->getStmtClass() == UnaryExprOrTypeTraitExprClass; 17655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1766f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne static bool classof(const UnaryExprOrTypeTraitExpr *) { return true; } 17671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 176877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 176963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children(); 17705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 17715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 17725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 17735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Postfix Operators. 17745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 17755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 17765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting. 17775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ArraySubscriptExpr : public Expr { 177877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek enum { LHS, RHS, END_EXPR=2 }; 17791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Stmt* SubExprs[END_EXPR]; 17805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation RBracketLoc; 17815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 17822324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t, 1783f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 178473d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SourceLocation rbracketloc) 1785f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ArraySubscriptExprClass, t, VK, OK, 17862850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl lhs->isTypeDependent() || rhs->isTypeDependent(), 1787bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor lhs->isValueDependent() || rhs->isValueDependent(), 1788561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (lhs->isInstantiationDependent() || 1789561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhs->isInstantiationDependent()), 1790bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (lhs->containsUnexpandedParameterPack() || 1791bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhs->containsUnexpandedParameterPack())), 17922850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl RBracketLoc(rbracketloc) { 179373d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SubExprs[LHS] = lhs; 179473d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SubExprs[RHS] = rhs; 179573d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner } 17961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1797cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor /// \brief Create an empty array subscript expression. 1798cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor explicit ArraySubscriptExpr(EmptyShell Shell) 1799cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor : Expr(ArraySubscriptExprClass, Shell) { } 1800cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 18012324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// An array access can be written A[4] or 4[A] (both are equivalent). 18022324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// - getBase() and getIdx() always present the normalized view: A[4]. 18032324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// In this case getBase() returns "A" and getIdx() returns "4". 18042324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// - getLHS() and getRHS() present the syntactic view. e.g. for 18052324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// 4[A] getLHS() returns "4". 180633fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// Note: Because vector element access is also written A[4] we must 180733fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// predicate the format conversion in getBase and getIdx only on the 180833fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// the type of the RHS, as it is possible for the LHS to be a vector of 180933fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// integer type 18105549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); } 18115549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 1812cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 1813cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 18145549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); } 18155549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 1816cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 18171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getBase() { 18195549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS()); 182077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek } 18211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr *getBase() const { 18235549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS()); 18242324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek } 18251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getIdx() { 18275549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS()); 18282324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek } 18291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 183077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek const Expr *getIdx() const { 18315549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS()); 18321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 18331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 183463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 183577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek return SourceRange(getLHS()->getLocStart(), RBracketLoc); 18365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 18371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1838026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getRBracketLoc() const { return RBracketLoc; } 1839cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setRBracketLoc(SourceLocation L) { RBracketLoc = L; } 1840cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 184163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation getExprLoc() const { return getBase()->getExprLoc(); } 18425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 18431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 18441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ArraySubscriptExprClass; 18455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 18465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ArraySubscriptExpr *) { return true; } 18471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 184877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 184963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 185063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 185163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 18525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 18535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 18545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1855b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]). 18561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CallExpr itself represents a normal function call, e.g., "f(x, 2)", 1857b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// while its subclasses may represent alternative syntax that (semantically) 18581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// results in a function call. For example, CXXOperatorCallExpr is 1859b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// a subclass for overloaded operator calls that use operator syntax, e.g., 1860b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// "str1 + str2" to resolve to a function call. 18615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CallExpr : public Expr { 1862cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne enum { FN=0, PREARGS_START=1 }; 18635549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt **SubExprs; 18645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned NumArgs; 18655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation RParenLoc; 18661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1867b4609806e9232593ece09ce08b630836e825865cDouglas Gregorprotected: 1868cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne // These versions of the constructor are for derived classes. 1869cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExpr(ASTContext& C, StmtClass SC, Expr *fn, unsigned NumPreArgs, 1870cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne Expr **args, unsigned numargs, QualType t, ExprValueKind VK, 1871cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SourceLocation rparenloc); 1872cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExpr(ASTContext &C, StmtClass SC, unsigned NumPreArgs, EmptyShell Empty); 1873cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne 1874cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne Stmt *getPreArg(unsigned i) { 1875cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne assert(i < getNumPreArgs() && "Prearg access out of range!"); 1876cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs[PREARGS_START+i]; 1877cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 1878cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne const Stmt *getPreArg(unsigned i) const { 1879cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne assert(i < getNumPreArgs() && "Prearg access out of range!"); 1880cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs[PREARGS_START+i]; 1881cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 1882cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne void setPreArg(unsigned i, Stmt *PreArg) { 1883cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne assert(i < getNumPreArgs() && "Prearg access out of range!"); 1884cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs[PREARGS_START+i] = PreArg; 1885cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 1886cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne 1887cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne unsigned getNumPreArgs() const { return CallExprBits.NumPreArgs; } 188842602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor 18895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 18901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, QualType t, 1891f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, SourceLocation rparenloc); 18921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18931f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor /// \brief Build an empty call expression. 1894ba0a9006dbc4814e1e35f82812cb5a1dad65e8b8Argyrios Kyrtzidis CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty); 18951f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 18965549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); } 18975549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCallee() { return cast<Expr>(SubExprs[FN]); } 189818b2515e1bf8c86a4900792692e42fe1296be28dChris Lattner void setCallee(Expr *F) { SubExprs[FN] = F; } 1899a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 1900d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes Decl *getCalleeDecl(); 1901d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes const Decl *getCalleeDecl() const { 1902d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes return const_cast<CallExpr*>(this)->getCalleeDecl(); 1903d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes } 1904d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes 1905a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu /// \brief If the callee is a FunctionDecl, return it. Otherwise return 0. 1906a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu FunctionDecl *getDirectCallee(); 1907bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner const FunctionDecl *getDirectCallee() const { 1908bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner return const_cast<CallExpr*>(this)->getDirectCallee(); 1909bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner } 1910a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 19115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getNumArgs - Return the number of actual arguments to this call. 19125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 19135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumArgs() const { return NumArgs; } 19141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1915aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \brief Retrieve the call arguments. 1916cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne Expr **getArgs() { 1917cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return reinterpret_cast<Expr **>(SubExprs+getNumPreArgs()+PREARGS_START); 1918cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 1919aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 19205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getArg - Return the specified argument. 19215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Expr *getArg(unsigned Arg) { 19225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(Arg < NumArgs && "Arg access out of range!"); 1923cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return cast<Expr>(SubExprs[Arg+getNumPreArgs()+PREARGS_START]); 19245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 19255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const Expr *getArg(unsigned Arg) const { 19265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(Arg < NumArgs && "Arg access out of range!"); 1927cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return cast<Expr>(SubExprs[Arg+getNumPreArgs()+PREARGS_START]); 19285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 19291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1930934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff /// setArg - Set the specified argument. 1931934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff void setArg(unsigned Arg, Expr *ArgExpr) { 1932934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff assert(Arg < NumArgs && "Arg access out of range!"); 1933cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs[Arg+getNumPreArgs()+PREARGS_START] = ArgExpr; 1934934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff } 19351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1936d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// setNumArgs - This changes the number of arguments present in this call. 1937d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// Any orphaned expressions are deleted by this, and any new operands are set 1938d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// to null. 19398189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek void setNumArgs(ASTContext& C, unsigned NumArgs); 19401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19415549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek typedef ExprIterator arg_iterator; 19425549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek typedef ConstExprIterator const_arg_iterator; 19431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1944cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne arg_iterator arg_begin() { return SubExprs+PREARGS_START+getNumPreArgs(); } 1945cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne arg_iterator arg_end() { 1946cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs+PREARGS_START+getNumPreArgs()+getNumArgs(); 1947cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 1948cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne const_arg_iterator arg_begin() const { 1949cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs+PREARGS_START+getNumPreArgs(); 1950cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 1951cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne const_arg_iterator arg_end() const { 1952cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs+PREARGS_START+getNumPreArgs()+getNumArgs(); 1953cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 19541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getNumCommas - Return the number of commas that must have been present in 19565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// this function call. 19575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; } 19585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1959cb888967400a03504c88acedd5248d6778a82f46Chris Lattner /// isBuiltinCall - If this is a call to a builtin, return the builtin ID. If 1960cb888967400a03504c88acedd5248d6778a82f46Chris Lattner /// not, return 0. 19614ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad unsigned isBuiltinCall(const ASTContext &Context) const; 19621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// getCallReturnType - Get the return type of the call expr. This is not 19641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// always the type of the expr itself, if the return type is a reference 19656dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson /// type. 19666dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson QualType getCallReturnType() const; 19671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1968d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner SourceLocation getRParenLoc() const { return RParenLoc; } 19691f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1970866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek 19712882eca5a184c78f793188083f6ce539740a5cf2John McCall SourceRange getSourceRange() const; 19721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 19744bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return T->getStmtClass() >= firstCallExprConstant && 19754bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt T->getStmtClass() <= lastCallExprConstant; 19765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 19775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CallExpr *) { return true; } 197888a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 197977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 198063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 198163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], 198263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall &SubExprs[0]+NumArgs+getNumPreArgs()+PREARGS_START); 198363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 19845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 19855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1986ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner/// MemberExpr - [C99 6.5.2.3] Structure and Union Members. X->F and X.F. 19875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 19885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass MemberExpr : public Expr { 19896bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// Extra data stored in some member expressions. 19906857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth struct MemberNameQualifier { 19916857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// \brief The nested-name-specifier that qualifies the name, including 19926857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// source-location information. 19936857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth NestedNameSpecifierLoc QualifierLoc; 19946857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth 19956857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// \brief The DeclAccessPair through which the MemberDecl was found due to 19966857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// name qualifiers. 1997161755a09898c95d21bfff33707da9ca41cd53c5John McCall DeclAccessPair FoundDecl; 19986bb8017bb9e828d118e15e59d71c66bba323c364John McCall }; 19996bb8017bb9e828d118e15e59d71c66bba323c364John McCall 2000ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// Base - the expression for the base pointer or structure references. In 2001ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// X.F, this is "X". 20025549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Base; 20031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2004ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// MemberDecl - This is the decl being referenced by the field/member name. 2005ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// In X.F, this is the decl referenced by F. 2006f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *MemberDecl; 20071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2008ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// MemberLoc - This is the location of the member name. 20095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation MemberLoc; 20101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20112577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// MemberDNLoc - Provides source/type location info for the 20122577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// declaration name embedded in MemberDecl. 20132577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameLoc MemberDNLoc; 20142577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 2015ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// IsArrow - True if this is "X->F", false if this is "X.F". 201683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor bool IsArrow : 1; 20171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 201883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief True if this member expression used a nested-name-specifier to 20196bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// refer to the member, e.g., "x->Base::f", or found its member via a using 20206bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// declaration. When true, a MemberNameQualifier 2021c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// structure is allocated immediately after the MemberExpr. 20226bb8017bb9e828d118e15e59d71c66bba323c364John McCall bool HasQualifierOrFoundDecl : 1; 20231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2024c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief True if this member expression specified a template argument list 2025c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// explicitly, e.g., x->f<int>. When true, an ExplicitTemplateArgumentList 2026c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// structure (and its TemplateArguments) are allocated immediately after 2027c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// the MemberExpr or, if the member expression also has a qualifier, after 20286bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// the MemberNameQualifier structure. 2029c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor bool HasExplicitTemplateArgumentList : 1; 20301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 203183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief Retrieve the qualifier that preceded the member name, if any. 20326bb8017bb9e828d118e15e59d71c66bba323c364John McCall MemberNameQualifier *getMemberQualifier() { 20336bb8017bb9e828d118e15e59d71c66bba323c364John McCall assert(HasQualifierOrFoundDecl); 20346bb8017bb9e828d118e15e59d71c66bba323c364John McCall return reinterpret_cast<MemberNameQualifier *> (this + 1); 203583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 203683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor 203783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief Retrieve the qualifier that preceded the member name, if any. 20386bb8017bb9e828d118e15e59d71c66bba323c364John McCall const MemberNameQualifier *getMemberQualifier() const { 2039c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return const_cast<MemberExpr *>(this)->getMemberQualifier(); 2040c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 20411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 2043f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl, 2044f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall const DeclarationNameInfo &NameInfo, QualType ty, 2045f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK) 2046f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(MemberExprClass, ty, VK, OK, 2047561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor base->isTypeDependent(), 2048561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor base->isValueDependent(), 2049561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor base->isInstantiationDependent(), 2050bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->containsUnexpandedParameterPack()), 20512577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Base(base), MemberDecl(memberdecl), MemberLoc(NameInfo.getLoc()), 20522577743c5650c646fb705df01403707e94f2df04Abramo Bagnara MemberDNLoc(NameInfo.getInfo()), IsArrow(isarrow), 20532577743c5650c646fb705df01403707e94f2df04Abramo Bagnara HasQualifierOrFoundDecl(false), HasExplicitTemplateArgumentList(false) { 20542577743c5650c646fb705df01403707e94f2df04Abramo Bagnara assert(memberdecl->getDeclName() == NameInfo.getName()); 20552577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 20562577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 20572577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // NOTE: this constructor should be used only when it is known that 20582577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // the member name can not provide additional syntactic info 20592577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // (i.e., source locations for C++ operator names or type source info 20602577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // for constructors, destructors and conversion oeprators). 20612577743c5650c646fb705df01403707e94f2df04Abramo Bagnara MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl, 2062f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall SourceLocation l, QualType ty, 2063f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK) 2064f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(MemberExprClass, ty, VK, OK, 2065bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->isTypeDependent(), base->isValueDependent(), 2066561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor base->isInstantiationDependent(), 2067bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->containsUnexpandedParameterPack()), 20682577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Base(base), MemberDecl(memberdecl), MemberLoc(l), MemberDNLoc(), 20692577743c5650c646fb705df01403707e94f2df04Abramo Bagnara IsArrow(isarrow), 20706bb8017bb9e828d118e15e59d71c66bba323c364John McCall HasQualifierOrFoundDecl(false), HasExplicitTemplateArgumentList(false) {} 2071510190777c4bd53e960eea4665b204778fec1b64Eli Friedman 20721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static MemberExpr *Create(ASTContext &C, Expr *base, bool isarrow, 207340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 2074161755a09898c95d21bfff33707da9ca41cd53c5John McCall ValueDecl *memberdecl, DeclAccessPair founddecl, 20752577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo MemberNameInfo, 2076d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *targs, 2077f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType ty, ExprValueKind VK, ExprObjectKind OK); 20781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 207988a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor void setBase(Expr *E) { Base = E; } 20805549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getBase() const { return cast<Expr>(Base); } 208157e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor 208257e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// \brief Retrieve the member declaration to which this expression refers. 208357e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// 208457e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// The returned declaration will either be a FieldDecl or (in C++) 208557e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// a CXXMethodDecl. 2086f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *getMemberDecl() const { return MemberDecl; } 2087f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman void setMemberDecl(ValueDecl *D) { MemberDecl = D; } 20881f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 20896bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// \brief Retrieves the declaration found by lookup. 2090161755a09898c95d21bfff33707da9ca41cd53c5John McCall DeclAccessPair getFoundDecl() const { 20916bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (!HasQualifierOrFoundDecl) 2092161755a09898c95d21bfff33707da9ca41cd53c5John McCall return DeclAccessPair::make(getMemberDecl(), 2093161755a09898c95d21bfff33707da9ca41cd53c5John McCall getMemberDecl()->getAccess()); 20946bb8017bb9e828d118e15e59d71c66bba323c364John McCall return getMemberQualifier()->FoundDecl; 20956bb8017bb9e828d118e15e59d71c66bba323c364John McCall } 20966bb8017bb9e828d118e15e59d71c66bba323c364John McCall 20971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Determines whether this member expression actually had 20980979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor /// a C++ nested-name-specifier prior to the name of the member, e.g., 20990979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor /// x->Base::foo. 21006bb8017bb9e828d118e15e59d71c66bba323c364John McCall bool hasQualifier() const { return getQualifier() != 0; } 21011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief If the member name was qualified, retrieves the 210383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// nested-name-specifier that precedes the member name. Otherwise, returns 210483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// NULL. 21051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump NestedNameSpecifier *getQualifier() const { 21066bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (!HasQualifierOrFoundDecl) 210783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return 0; 21081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 210940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return getMemberQualifier()->QualifierLoc.getNestedNameSpecifier(); 211040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor } 211140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor 211240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor /// \brief If the member name was qualified, retrieves the 211340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor /// nested-name-specifier that precedes the member name, with source-location 211440d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor /// information. 211540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc getQualifierLoc() const { 211640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (!hasQualifier()) 211740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return NestedNameSpecifierLoc(); 211840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor 211940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return getMemberQualifier()->QualifierLoc; 212083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 2121c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor 2122c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Determines whether this member expression actually had a C++ 2123c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template argument list explicitly specified, e.g., x.f<int>. 2124096832c5ed5b9106fa177ebc148489760c3bc496John McCall bool hasExplicitTemplateArgs() const { 21251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return HasExplicitTemplateArgumentList; 2126c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 21271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2128d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// \brief Copies the template arguments (if present) into the given 2129d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// structure. 2130d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 2131096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (hasExplicitTemplateArgs()) 2132096832c5ed5b9106fa177ebc148489760c3bc496John McCall getExplicitTemplateArgs().copyInto(List); 2133096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 2134096832c5ed5b9106fa177ebc148489760c3bc496John McCall 2135096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that 2136096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// follow the member template name. This must only be called on an 2137096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// expression with explicit template arguments. 2138096832c5ed5b9106fa177ebc148489760c3bc496John McCall ExplicitTemplateArgumentList &getExplicitTemplateArgs() { 2139096832c5ed5b9106fa177ebc148489760c3bc496John McCall assert(HasExplicitTemplateArgumentList); 2140096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!HasQualifierOrFoundDecl) 2141096832c5ed5b9106fa177ebc148489760c3bc496John McCall return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1); 2142096832c5ed5b9106fa177ebc148489760c3bc496John McCall 2143096832c5ed5b9106fa177ebc148489760c3bc496John McCall return *reinterpret_cast<ExplicitTemplateArgumentList *>( 2144096832c5ed5b9106fa177ebc148489760c3bc496John McCall getMemberQualifier() + 1); 2145096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 2146096832c5ed5b9106fa177ebc148489760c3bc496John McCall 2147096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that 2148096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// followed the member template name. This must only be called on 2149096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// an expression with explicit template arguments. 2150096832c5ed5b9106fa177ebc148489760c3bc496John McCall const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const { 2151096832c5ed5b9106fa177ebc148489760c3bc496John McCall return const_cast<MemberExpr *>(this)->getExplicitTemplateArgs(); 2152096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 2153096832c5ed5b9106fa177ebc148489760c3bc496John McCall 2154096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieves the optional explicit template arguments. 2155096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// This points to the same data as getExplicitTemplateArgs(), but 2156096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// returns null if there are no explicit template arguments. 2157096832c5ed5b9106fa177ebc148489760c3bc496John McCall const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() const { 2158096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) return 0; 2159096832c5ed5b9106fa177ebc148489760c3bc496John McCall return &getExplicitTemplateArgs(); 2160d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall } 2161c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 21621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Retrieve the location of the left angle bracket following the 2163c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// member name ('<'), if any. 21641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation getLAngleLoc() const { 2165c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 2166c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return SourceLocation(); 21671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2168096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().LAngleLoc; 2169c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 21701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2171c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Retrieve the template arguments provided as part of this 2172c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template-id. 2173833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc *getTemplateArgs() const { 2174c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 21751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return 0; 21761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2177096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().getTemplateArgs(); 2178c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 21791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2180c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Retrieve the number of template arguments provided as part of this 2181c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template-id. 21821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned getNumTemplateArgs() const { 2183c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 21841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return 0; 21851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2186096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().NumTemplateArgs; 2187c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 21881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Retrieve the location of the right angle bracket following the 2190c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template arguments ('>'). 21911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation getRAngleLoc() const { 2192c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 2193c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return SourceLocation(); 21941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2195096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().RAngleLoc; 2196c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 21971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21982577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// \brief Retrieve the member declaration name info. 21992577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo getMemberNameInfo() const { 22002577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(MemberDecl->getDeclName(), 22012577743c5650c646fb705df01403707e94f2df04Abramo Bagnara MemberLoc, MemberDNLoc); 22022577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 22032577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 22045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isArrow() const { return IsArrow; } 22051f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setArrow(bool A) { IsArrow = A; } 22061f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 2207ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// getMemberLoc - Return the location of the "member", in X->F, it is the 2208ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// location of 'F'. 2209026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getMemberLoc() const { return MemberLoc; } 22101f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setMemberLoc(SourceLocation L) { MemberLoc = L; } 22115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 221275e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor SourceRange getSourceRange() const; 221375e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 221463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation getExprLoc() const { return MemberLoc; } 22155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 221675e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor /// \brief Determine whether the base of this explicit is implicit. 221775e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor bool isImplicitAccess() const { 221875e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor return getBase() && getBase()->isImplicitCXXThis(); 221975e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } 222075e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 22211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 222283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return T->getStmtClass() == MemberExprClass; 22235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 22245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const MemberExpr *) { return true; } 22251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22261237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 222763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Base, &Base+1); } 22284045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis 22294045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTReader; 22304045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTStmtWriter; 22315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 22325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 22331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CompoundLiteralExpr - [C99 6.5.2.5] 2234aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff/// 2235aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffclass CompoundLiteralExpr : public Expr { 22360fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// LParenLoc - If non-null, this is the location of the left paren in a 22370fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// compound literal like "(int){4}". This can be null if this is a 22380fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// synthesized compound expression. 22390fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner SourceLocation LParenLoc; 22401d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall 22411d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall /// The type as written. This can be an incomplete array type, in 22421d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall /// which case the actual expression type will be different. 224342f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *TInfo; 22445549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Init; 2245e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff bool FileScope; 2246aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffpublic: 224742f56b50062cd3b3c6b23fdb9053578ae9145664John McCall CompoundLiteralExpr(SourceLocation lparenloc, TypeSourceInfo *tinfo, 2248f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK, Expr *init, bool fileScope) 2249f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CompoundLiteralExprClass, T, VK, OK_Ordinary, 2250bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor tinfo->getType()->isDependentType(), 2251bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor init->isValueDependent(), 2252561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (init->isInstantiationDependent() || 2253561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor tinfo->getType()->isInstantiationDependentType()), 2254bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor init->containsUnexpandedParameterPack()), 225542f56b50062cd3b3c6b23fdb9053578ae9145664John McCall LParenLoc(lparenloc), TInfo(tinfo), Init(init), FileScope(fileScope) {} 22561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2257ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor /// \brief Construct an empty compound literal. 2258ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor explicit CompoundLiteralExpr(EmptyShell Empty) 2259ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor : Expr(CompoundLiteralExprClass, Empty) { } 2260ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 22615549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getInitializer() const { return cast<Expr>(Init); } 22625549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getInitializer() { return cast<Expr>(Init); } 2263ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setInitializer(Expr *E) { Init = E; } 2264e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff 2265e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff bool isFileScope() const { return FileScope; } 2266ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setFileScope(bool FS) { FileScope = FS; } 2267ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 22680fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner SourceLocation getLParenLoc() const { return LParenLoc; } 2269ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setLParenLoc(SourceLocation L) { LParenLoc = L; } 2270ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 227142f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *getTypeSourceInfo() const { return TInfo; } 227242f56b50062cd3b3c6b23fdb9053578ae9145664John McCall void setTypeSourceInfo(TypeSourceInfo* tinfo) { TInfo = tinfo; } 227342f56b50062cd3b3c6b23fdb9053578ae9145664John McCall 227463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 22750fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner // FIXME: Init should never be null. 22760fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner if (!Init) 22770fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner return SourceRange(); 22780fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner if (LParenLoc.isInvalid()) 227973d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner return Init->getSourceRange(); 22800fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner return SourceRange(LParenLoc, Init->getLocEnd()); 228173d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner } 2282aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff 22831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 22841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CompoundLiteralExprClass; 2285aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff } 2286aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff static bool classof(const CompoundLiteralExpr *) { return true; } 22871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22881237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 228963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Init, &Init+1); } 2290aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff}; 2291aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff 229249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CastExpr - Base class for type casts, including both implicit 229349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// casts (ImplicitCastExpr) and explicit casts that have some 229449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// representation in the source code (ExplicitCastExpr's derived 229549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// classes). 22960835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass CastExpr : public Expr { 2297cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlssonpublic: 22985baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall typedef clang::CastKind CastKind; 22991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2300cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlssonprivate: 23010835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis Stmt *Op; 2302409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson 2303daa8e4e888758d55a7a759dd4a91b83921cef222John McCall void CheckCastConsistency() const { 2304409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson#ifndef NDEBUG 2305409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson switch (getCastKind()) { 23065cf86ba6b5a724bf91cb52feade1158f1fbeb605Anders Carlsson case CK_DerivedToBase: 2307cee22421929c91b481f4d1bb85cd48c0f6b7510bAnders Carlsson case CK_UncheckedDerivedToBase: 2308cee22421929c91b481f4d1bb85cd48c0f6b7510bAnders Carlsson case CK_DerivedToBaseMemberPointer: 2309409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_BaseToDerived: 2310409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_BaseToDerivedMemberPointer: 2311f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall assert(!path_empty() && "Cast kind should have a base path!"); 2312f9d68e1dd015972318b2448f75115ff4fc3d5008Anders Carlsson break; 2313409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson 2314409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson // These should not have an inheritance path. 2315409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_BitCast: 2316409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_Dynamic: 2317409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_ToUnion: 2318409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_ArrayToPointerDecay: 2319409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_FunctionToPointerDecay: 2320409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_NullToMemberPointer: 2321404cd1669c3ba138a9ae0a619bd689cce5aae271John McCall case CK_NullToPointer: 2322409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_ConstructorConversion: 2323409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_IntegralToPointer: 2324409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_PointerToIntegral: 2325409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_ToVoid: 2326409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_VectorSplat: 2327409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_IntegralCast: 2328409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_IntegralToFloating: 2329409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_FloatingToIntegral: 2330409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_FloatingCast: 2331409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_AnyPointerToObjCPointerCast: 2332409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson case CK_AnyPointerToBlockPointerCast: 2333569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor case CK_ObjCObjectLValueCast: 23342bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_FloatingRealToComplex: 2335f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_FloatingComplexToReal: 23362bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_FloatingComplexCast: 2337f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_FloatingComplexToIntegralComplex: 23382bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_IntegralRealToComplex: 2339f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_IntegralComplexToReal: 23402bb5d00fcf71a7b4d478d478be778fff0494aff6John McCall case CK_IntegralComplexCast: 2341f3ea8cfe6b1c2ef0702efe130561e9e66708d799John McCall case CK_IntegralComplexToFloatingComplex: 2342f85e193739c953358c865005855253af4f68a497John McCall case CK_ObjCProduceObject: 2343f85e193739c953358c865005855253af4f68a497John McCall case CK_ObjCConsumeObject: 23447e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall case CK_ObjCReclaimReturnedObject: 2345daa8e4e888758d55a7a759dd4a91b83921cef222John McCall assert(!getType()->isBooleanType() && "unheralded conversion to bool"); 2346daa8e4e888758d55a7a759dd4a91b83921cef222John McCall // fallthrough to check for null base path 2347daa8e4e888758d55a7a759dd4a91b83921cef222John McCall 2348daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_Dependent: 23490ae287a498b8cec2086fe6b7e753cbb3df63e74aJohn McCall case CK_LValueToRValue: 2350f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall case CK_GetObjCProperty: 2351daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_NoOp: 2352daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_PointerToBoolean: 2353daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_IntegralToBoolean: 2354daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_FloatingToBoolean: 2355daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_MemberPointerToBoolean: 2356daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_FloatingComplexToBoolean: 2357daa8e4e888758d55a7a759dd4a91b83921cef222John McCall case CK_IntegralComplexToBoolean: 23585082d34e4107a44ac7f07b62f7a6c917e0e6e71eJohn McCall case CK_LValueBitCast: // -> bool& 23595082d34e4107a44ac7f07b62f7a6c917e0e6e71eJohn McCall case CK_UserDefinedConversion: // operator bool() 2360f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall assert(path_empty() && "Cast kind should not have a base path!"); 2361409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson break; 2362409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson } 2363409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson#endif 2364409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson } 2365409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson 2366f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXBaseSpecifier * const *path_buffer() const { 2367f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return const_cast<CastExpr*>(this)->path_buffer(); 2368f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall } 2369f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CXXBaseSpecifier **path_buffer(); 2370f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2371654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis void setBasePathSize(unsigned basePathSize) { 2372654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis CastExprBits.BasePathSize = basePathSize; 2373654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis assert(CastExprBits.BasePathSize == basePathSize && 2374654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis "basePathSize doesn't fit in bits of CastExprBits.BasePathSize!"); 2375654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis } 2376654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis 23770835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisprotected: 2378f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CastExpr(StmtClass SC, QualType ty, ExprValueKind VK, 2379f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall const CastKind kind, Expr *op, unsigned BasePathSize) : 2380f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(SC, ty, VK, OK_Ordinary, 2381898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Cast expressions are type-dependent if the type is 2382898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // dependent (C++ [temp.dep.expr]p3). 2383898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ty->isDependentType(), 2384898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Cast expressions are value-dependent if the type is 2385898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // dependent or if the subexpression is value-dependent. 2386bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ty->isDependentType() || (op && op->isValueDependent()), 2387561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (ty->isInstantiationDependentType() || 2388561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (op && op->isInstantiationDependent())), 2389bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (ty->containsUnexpandedParameterPack() || 2390bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor op->containsUnexpandedParameterPack())), 23918e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall Op(op) { 2392daa8e4e888758d55a7a759dd4a91b83921cef222John McCall assert(kind != CK_Invalid && "creating cast with invalid cast kind"); 23938e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CastExprBits.Kind = kind; 2394654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis setBasePathSize(BasePathSize); 2395daa8e4e888758d55a7a759dd4a91b83921cef222John McCall CheckCastConsistency(); 2396f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall } 23971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2398087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor /// \brief Construct an empty cast. 2399f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastExpr(StmtClass SC, EmptyShell Empty, unsigned BasePathSize) 24008e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall : Expr(SC, Empty) { 2401654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis setBasePathSize(BasePathSize); 24028e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall } 24031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24040835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidispublic: 24058e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CastKind getCastKind() const { return (CastKind) CastExprBits.Kind; } 24068e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall void setCastKind(CastKind K) { CastExprBits.Kind = K; } 2407f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson const char *getCastKindName() const; 2408f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson 24090835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis Expr *getSubExpr() { return cast<Expr>(Op); } 24100835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis const Expr *getSubExpr() const { return cast<Expr>(Op); } 2411087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor void setSubExpr(Expr *E) { Op = E; } 2412087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor 24136eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// \brief Retrieve the cast subexpression as it was written in the source 24146eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// code, looking through any implicit casts or other intermediate nodes 24156eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// introduced by semantic analysis. 24166eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor Expr *getSubExprAsWritten(); 24176eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor const Expr *getSubExprAsWritten() const { 24186eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return const_cast<CastExpr *>(this)->getSubExprAsWritten(); 24196eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor } 242041b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson 2421f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall typedef CXXBaseSpecifier **path_iterator; 2422f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall typedef const CXXBaseSpecifier * const *path_const_iterator; 24238e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall bool path_empty() const { return CastExprBits.BasePathSize == 0; } 24248e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned path_size() const { return CastExprBits.BasePathSize; } 2425f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_iterator path_begin() { return path_buffer(); } 2426f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_iterator path_end() { return path_buffer() + path_size(); } 2427f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_const_iterator path_begin() const { return path_buffer(); } 2428f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_const_iterator path_end() const { return path_buffer() + path_size(); } 2429f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2430f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall void setCastPath(const CXXCastPath &Path); 243141b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson 24321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 24334bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return T->getStmtClass() >= firstCastExprConstant && 24344bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt T->getStmtClass() <= lastCastExprConstant; 24350835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis } 24360835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis static bool classof(const CastExpr *) { return true; } 24371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24380835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis // Iterators 243963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Op, &Op+1); } 24400835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis}; 24410835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis 244249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ImplicitCastExpr - Allows us to explicitly represent implicit type 244349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// conversions, which have no direct representation in the original 244449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// source code. For example: converting T[]->T*, void f()->void 244549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (*f)(), float->double, short->int, etc. 244649b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff/// 2447bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// In C, implicit casts always produce rvalues. However, in C++, an 2448bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// implicit cast whose result is being bound to a reference will be 2449906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// an lvalue or xvalue. For example: 2450bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// 2451bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @code 2452bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Base { }; 2453bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Derived : public Base { }; 2454906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// Derived &&ref(); 24551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// void f(Derived d) { 2456906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// Base& b = d; // initializer is an ImplicitCastExpr 2457906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// // to an lvalue of type Base 2458906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// Base&& r = ref(); // initializer is an ImplicitCastExpr 2459906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// // to an xvalue of type Base 2460bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// } 2461bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @endcode 24620835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ImplicitCastExpr : public CastExpr { 2463906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redlprivate: 2464f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ImplicitCastExpr(QualType ty, CastKind kind, Expr *op, 24655baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall unsigned BasePathLength, ExprValueKind VK) 2466f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, BasePathLength) { 24675baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall } 246890045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff 2469087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor /// \brief Construct an empty implicit cast. 2470f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall explicit ImplicitCastExpr(EmptyShell Shell, unsigned PathSize) 2471f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : CastExpr(ImplicitCastExprClass, Shell, PathSize) { } 2472f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2473f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 2474f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall enum OnStack_t { OnStack }; 2475f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ImplicitCastExpr(OnStack_t _, QualType ty, CastKind kind, Expr *op, 24765baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall ExprValueKind VK) 2477f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, 0) { 24785baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall } 2479f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2480f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static ImplicitCastExpr *Create(ASTContext &Context, QualType T, 2481f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastKind Kind, Expr *Operand, 2482f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXCastPath *BasePath, 24835baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall ExprValueKind Cat); 2484f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2485f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static ImplicitCastExpr *CreateEmpty(ASTContext &Context, unsigned PathSize); 2486087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor 248763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 24880835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis return getSubExpr()->getSourceRange(); 24890835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis } 249090045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff 24911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 24921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ImplicitCastExprClass; 249349b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff } 249449b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff static bool classof(const ImplicitCastExpr *) { return true; } 249549b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff}; 249649b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff 249791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCallinline Expr *Expr::IgnoreImpCasts() { 249891a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall Expr *e = this; 249991a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall while (ImplicitCastExpr *ice = dyn_cast<ImplicitCastExpr>(e)) 250091a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall e = ice->getSubExpr(); 250191a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall return e; 250291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall} 250391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 250449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ExplicitCastExpr - An explicit cast written in the source 25051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// code. 250649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// 250749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This class is effectively an abstract class, because it provides 250849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// the basic representation of an explicitly-written cast without 250949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// specifying which kind of cast (C cast, functional cast, static 251049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast, etc.) was written; specific derived classes represent the 251149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// particular style of cast and its location information. 25125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 251349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// Unlike implicit casts, explicit cast nodes have two different 251449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// types: the type that was written into the source code, and the 251549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// actual type of the expression as determined by semantic 251649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// analysis. These types may differ slightly. For example, in C++ one 251749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// can cast to a reference type, which indicates that the resulting 2518906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// expression will be an lvalue or xvalue. The reference type, however, 2519906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// will not be used as the type of the expression. 25200835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ExplicitCastExpr : public CastExpr { 25219d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// TInfo - Source type info for the (written) type 25229d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// this expression is casting to. 25239d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo; 252449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 252549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorprotected: 2526f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExplicitCastExpr(StmtClass SC, QualType exprTy, ExprValueKind VK, 2527f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CastKind kind, Expr *op, unsigned PathSize, 2528f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall TypeSourceInfo *writtenTy) 2529f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : CastExpr(SC, exprTy, VK, kind, op, PathSize), TInfo(writtenTy) {} 253049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 2531db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty explicit cast. 2532f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ExplicitCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize) 2533f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : CastExpr(SC, Shell, PathSize) { } 2534db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 253549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorpublic: 25369d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// getTypeInfoAsWritten - Returns the type source info for the type 25379d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// that this expression is casting to. 25389d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *getTypeInfoAsWritten() const { return TInfo; } 25399d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall void setTypeInfoAsWritten(TypeSourceInfo *writtenTy) { TInfo = writtenTy; } 25409d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall 254149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// getTypeAsWritten - Returns the type that this expression is 254249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// casting to, as written in the source code. 25439d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall QualType getTypeAsWritten() const { return TInfo->getType(); } 254449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 25451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 25464bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return T->getStmtClass() >= firstExplicitCastExprConstant && 25474bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt T->getStmtClass() <= lastExplicitCastExprConstant; 254849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor } 254949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor static bool classof(const ExplicitCastExpr *) { return true; } 255049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor}; 255149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 25526eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor/// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style 255349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast in C++ (C++ [expr.cast]), which uses the syntax 255449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (Type)expr. For example: @c (int)f. 25556eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregorclass CStyleCastExpr : public ExplicitCastExpr { 2556b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation LPLoc; // the location of the left paren 2557b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation RPLoc; // the location of the right paren 2558f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2559f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CStyleCastExpr(QualType exprTy, ExprValueKind vk, CastKind kind, Expr *op, 2560f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned PathSize, TypeSourceInfo *writtenTy, 256141b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson SourceLocation l, SourceLocation r) 2562f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : ExplicitCastExpr(CStyleCastExprClass, exprTy, vk, kind, op, PathSize, 256341b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson writtenTy), LPLoc(l), RPLoc(r) {} 256449b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff 2565db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty C-style explicit cast. 2566f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall explicit CStyleCastExpr(EmptyShell Shell, unsigned PathSize) 2567f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : ExplicitCastExpr(CStyleCastExprClass, Shell, PathSize) { } 2568f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2569f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 2570f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall static CStyleCastExpr *Create(ASTContext &Context, QualType T, 2571f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, CastKind K, 2572f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall Expr *Op, const CXXCastPath *BasePath, 2573f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall TypeSourceInfo *WrittenTy, SourceLocation L, 2574f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall SourceLocation R); 2575f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2576f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CStyleCastExpr *CreateEmpty(ASTContext &Context, unsigned PathSize); 2577db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 2578b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation getLParenLoc() const { return LPLoc; } 2579db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setLParenLoc(SourceLocation L) { LPLoc = L; } 2580db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 2581b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation getRParenLoc() const { return RPLoc; } 2582db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setRParenLoc(SourceLocation L) { RPLoc = L; } 2583db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 258463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 2585b2f9e516327310d95840d442416084508f80c183Steve Naroff return SourceRange(LPLoc, getSubExpr()->getSourceRange().getEnd()); 25865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 25871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 25881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CStyleCastExprClass; 25895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 25906eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor static bool classof(const CStyleCastExpr *) { return true; } 25915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 25925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 25933fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// \brief A builtin binary operation expression such as "x + y" or "x <= y". 25943fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 25953fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// This expression node kind describes a builtin binary operation, 25963fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// such as "x + y" for integer values "x" and "y". The operands will 25973fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// already have been converted to appropriate types (e.g., by 25983fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// performing promotions or conversions). 25993fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 26003fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// In C++, where operators may be overloaded, a different kind of 26013fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// expression node (CXXOperatorCallExpr) is used to express the 26023fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// invocation of an overloaded operator with operator syntax. Within 26033fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is 26043fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to store an expression "x + y" depends on the subexpressions 26053fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// for x and y. If neither x or y is type-dependent, and the "+" 26063fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// operator resolves to a built-in operation, BinaryOperator will be 26073fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to express the computation (x and y may still be 26083fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// value-dependent). If either x or y is type-dependent, or if the 26093fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// "+" resolves to an overloaded operator, CXXOperatorCallExpr will 26103fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// be used to express the computation. 26115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BinaryOperator : public Expr { 26125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 26135baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall typedef BinaryOperatorKind Opcode; 26145baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 261517d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattnerprivate: 26160799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall unsigned Opc : 6; 26170799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall SourceLocation OpLoc; 26180799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall 261917d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner enum { LHS, RHS, END_EXPR }; 26205549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; 26211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 26221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 262317d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 2624f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 262517d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation opLoc) 2626f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(BinaryOperatorClass, ResTy, VK, OK, 2627898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor lhs->isTypeDependent() || rhs->isTypeDependent(), 2628bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor lhs->isValueDependent() || rhs->isValueDependent(), 2629561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (lhs->isInstantiationDependent() || 2630561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhs->isInstantiationDependent()), 2631bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (lhs->containsUnexpandedParameterPack() || 2632bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhs->containsUnexpandedParameterPack())), 2633898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Opc(opc), OpLoc(opLoc) { 26341237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 26351237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 26361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(!isCompoundAssignmentOp() && 26375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Use ArithAssignBinaryOperator for compound assignments"); 26385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 26395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2640db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty binary operator. 26411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit BinaryOperator(EmptyShell Empty) 26422de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall : Expr(BinaryOperatorClass, Empty), Opc(BO_Comma) { } 2643db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 264417d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation getOperatorLoc() const { return OpLoc; } 2645db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setOperatorLoc(SourceLocation L) { OpLoc = L; } 2646db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 26470799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Opcode getOpcode() const { return static_cast<Opcode>(Opc); } 2648db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setOpcode(Opcode O) { Opc = O; } 2649db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 26505549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 2651db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 26525549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 2653db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 2654db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 265563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 26565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd()); 26575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 26581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 26595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 26605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// corresponds to, e.g. "<<=". 26615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static const char *getOpcodeStr(Opcode Op); 26625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 26630799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall const char *getOpcodeStr() const { return getOpcodeStr(getOpcode()); } 2664a84c02d0f4d63975a1c52b9bb8308d88e9d79352Ted Kremenek 2665063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// \brief Retrieve the binary opcode that corresponds to the given 2666063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// overloaded operator. 2667063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static Opcode getOverloadedOpcode(OverloadedOperatorKind OO); 2668063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 2669063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// \brief Retrieve the overloaded operator kind that corresponds to 2670063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// the given binary opcode. 2671063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); 2672063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 26735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// predicates to categorize the respective opcodes. 2674200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl bool isPtrMemOp() const { return Opc == BO_PtrMemD || Opc == BO_PtrMemI; } 26752de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall bool isMultiplicativeOp() const { return Opc >= BO_Mul && Opc <= BO_Rem; } 26762de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isAdditiveOp(Opcode Opc) { return Opc == BO_Add || Opc==BO_Sub; } 26770799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isAdditiveOp() const { return isAdditiveOp(getOpcode()); } 26782de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isShiftOp(Opcode Opc) { return Opc == BO_Shl || Opc == BO_Shr; } 26790799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isShiftOp() const { return isShiftOp(getOpcode()); } 2680aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl 26812de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isBitwiseOp(Opcode Opc) { return Opc >= BO_And && Opc <= BO_Or; } 26820799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isBitwiseOp() const { return isBitwiseOp(getOpcode()); } 2683f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 26842de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isRelationalOp(Opcode Opc) { return Opc >= BO_LT && Opc<=BO_GE; } 26850799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isRelationalOp() const { return isRelationalOp(getOpcode()); } 2686f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 26872de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isEqualityOp(Opcode Opc) { return Opc == BO_EQ || Opc == BO_NE; } 26880799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isEqualityOp() const { return isEqualityOp(getOpcode()); } 26891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 26902de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isComparisonOp(Opcode Opc) { return Opc >= BO_LT && Opc<=BO_NE; } 26910799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isComparisonOp() const { return isComparisonOp(getOpcode()); } 2692aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl 26932de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isLogicalOp(Opcode Opc) { return Opc == BO_LAnd || Opc==BO_LOr; } 26940799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isLogicalOp() const { return isLogicalOp(getOpcode()); } 2695f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 26960e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall static bool isAssignmentOp(Opcode Opc) { 26970e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall return Opc >= BO_Assign && Opc <= BO_OrAssign; 26980e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall } 26990e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall bool isAssignmentOp() const { return isAssignmentOp(getOpcode()); } 27000e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall 27010e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall static bool isCompoundAssignmentOp(Opcode Opc) { 27022de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Opc > BO_Assign && Opc <= BO_OrAssign; 27032de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 27040e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall bool isCompoundAssignmentOp() const { 27050e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall return isCompoundAssignmentOp(getOpcode()); 27060e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall } 27070e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall 27080e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall static bool isShiftAssignOp(Opcode Opc) { 27092de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Opc == BO_ShlAssign || Opc == BO_ShrAssign; 27102de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 27110e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall bool isShiftAssignOp() const { 27120e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall return isShiftAssignOp(getOpcode()); 27130e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall } 27141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *S) { 27164bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return S->getStmtClass() >= firstBinaryOperatorConstant && 27174bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt S->getStmtClass() <= lastBinaryOperatorConstant; 27185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 27195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const BinaryOperator *) { return true; } 27201237c673c07f9d827129ba02720108816abde562Ted Kremenek 27211237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 272263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 272363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 272463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 27251237c673c07f9d827129ba02720108816abde562Ted Kremenek 27265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 272717d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 2728f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 27292333f7727f97018d6742e1e0938133bcfad967abEli Friedman SourceLocation opLoc, bool dead) 2730f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CompoundAssignOperatorClass, ResTy, VK, OK, 27312333f7727f97018d6742e1e0938133bcfad967abEli Friedman lhs->isTypeDependent() || rhs->isTypeDependent(), 2732bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor lhs->isValueDependent() || rhs->isValueDependent(), 2733561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (lhs->isInstantiationDependent() || 2734561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhs->isInstantiationDependent()), 2735bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (lhs->containsUnexpandedParameterPack() || 2736bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhs->containsUnexpandedParameterPack())), 27372333f7727f97018d6742e1e0938133bcfad967abEli Friedman Opc(opc), OpLoc(opLoc) { 27381237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 27391237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 27405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2741ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 27421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump BinaryOperator(StmtClass SC, EmptyShell Empty) 27432de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall : Expr(SC, Empty), Opc(BO_MulAssign) { } 27445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 27455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 27465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep 27475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// track of the type the operation is performed in. Due to the semantics of 27485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// these operators, the operands are promoted, the aritmetic performed, an 27495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// implicit conversion back to the result type done, then the assignment takes 27505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// place. This captures the intermediate type which the computation is done 27515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// in. 27525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CompoundAssignOperator : public BinaryOperator { 2753ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType ComputationLHSType; 2754ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType ComputationResultType; 27555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 2756f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResType, 2757f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 2758f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType CompLHSType, QualType CompResultType, 275917d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation OpLoc) 2760f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : BinaryOperator(lhs, rhs, opc, ResType, VK, OK, OpLoc, true), 2761ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman ComputationLHSType(CompLHSType), 2762ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman ComputationResultType(CompResultType) { 27631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(isCompoundAssignmentOp() && 27645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Only should be used for compound assignments"); 27655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 27665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2767ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor /// \brief Build an empty compound assignment operator expression. 2768ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor explicit CompoundAssignOperator(EmptyShell Empty) 2769ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor : BinaryOperator(CompoundAssignOperatorClass, Empty) { } 2770ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 2771ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // The two computation types are the type the LHS is converted 2772ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // to for the computation and the type of the result; the two are 2773ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // distinct in a few cases (specifically, int+=ptr and ptr-=ptr). 2774ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType getComputationLHSType() const { return ComputationLHSType; } 2775ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setComputationLHSType(QualType T) { ComputationLHSType = T; } 2776ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 2777ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType getComputationResultType() const { return ComputationResultType; } 2778ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setComputationResultType(QualType T) { ComputationResultType = T; } 2779ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 27805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CompoundAssignOperator *) { return true; } 27811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *S) { 27821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return S->getStmtClass() == CompoundAssignOperatorClass; 27835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 27845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 27855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 278656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// AbstractConditionalOperator - An abstract base class for 278756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// ConditionalOperator and BinaryConditionalOperator. 278856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass AbstractConditionalOperator : public Expr { 278956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation QuestionLoc, ColonLoc; 279056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall friend class ASTStmtReader; 279156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 279256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallprotected: 279356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall AbstractConditionalOperator(StmtClass SC, QualType T, 279456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall ExprValueKind VK, ExprObjectKind OK, 2795561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool TD, bool VD, bool ID, 279656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall bool ContainsUnexpandedParameterPack, 279756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation qloc, 279856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation cloc) 2799561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Expr(SC, T, VK, OK, TD, VD, ID, ContainsUnexpandedParameterPack), 280056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall QuestionLoc(qloc), ColonLoc(cloc) {} 280156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 280256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall AbstractConditionalOperator(StmtClass SC, EmptyShell Empty) 280356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : Expr(SC, Empty) { } 280456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 280556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallpublic: 280656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getCond - Return the expression representing the condition for 280756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the ?: operator. 280856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getCond() const; 280956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 281056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getTrueExpr - Return the subexpression representing the value of 281156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the expression if the condition evaluates to true. 281256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getTrueExpr() const; 281356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 281456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getFalseExpr - Return the subexpression representing the value of 281556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the expression if the condition evaluates to false. This is 281656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the same as getRHS. 281756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getFalseExpr() const; 281856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 281956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation getQuestionLoc() const { return QuestionLoc; } 282056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation getColonLoc() const { return ColonLoc; } 282156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 282256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const Stmt *T) { 282356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return T->getStmtClass() == ConditionalOperatorClass || 282456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall T->getStmtClass() == BinaryConditionalOperatorClass; 282556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 282656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const AbstractConditionalOperator *) { return true; } 282756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall}; 282856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 282956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// ConditionalOperator - The ?: ternary operator. The GNU "missing 283056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// middle" extension is a BinaryConditionalOperator. 283156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass ConditionalOperator : public AbstractConditionalOperator { 28321237c673c07f9d827129ba02720108816abde562Ted Kremenek enum { COND, LHS, RHS, END_EXPR }; 28335549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 283456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 283556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall friend class ASTStmtReader; 28365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 283747e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor ConditionalOperator(Expr *cond, SourceLocation QLoc, Expr *lhs, 283856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation CLoc, Expr *rhs, 28390943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall QualType t, ExprValueKind VK, ExprObjectKind OK) 284056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : AbstractConditionalOperator(ConditionalOperatorClass, t, VK, OK, 2841898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // FIXME: the type of the conditional operator doesn't 2842898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // depend on the type of the conditional, but the standard 2843898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // seems to imply that it could. File a bug! 284456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (lhs->isTypeDependent() || rhs->isTypeDependent()), 284556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (cond->isValueDependent() || lhs->isValueDependent() || 284656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall rhs->isValueDependent()), 2847561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (cond->isInstantiationDependent() || 2848561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor lhs->isInstantiationDependent() || 2849561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhs->isInstantiationDependent()), 2850bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (cond->containsUnexpandedParameterPack() || 285156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall lhs->containsUnexpandedParameterPack() || 285256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall rhs->containsUnexpandedParameterPack()), 285356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall QLoc, CLoc) { 28541237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[COND] = cond; 28551237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 28561237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 28571237c673c07f9d827129ba02720108816abde562Ted Kremenek } 28585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2859ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor /// \brief Build an empty conditional operator. 2860ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor explicit ConditionalOperator(EmptyShell Empty) 286156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : AbstractConditionalOperator(ConditionalOperatorClass, Empty) { } 2862ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 2863395a2abf0028968d85958610e393e067885dc14fTed Kremenek // getCond - Return the expression representing the condition for 286456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the ?: operator. 28655549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 2866395a2abf0028968d85958610e393e067885dc14fTed Kremenek 286756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getTrueExpr - Return the subexpression representing the value of 286856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the expression if the condition evaluates to true. 286956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getTrueExpr() const { return cast<Expr>(SubExprs[LHS]); } 28701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 287156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getFalseExpr - Return the subexpression representing the value of 287256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the expression if the condition evaluates to false. This is 287356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the same as getRHS. 28745549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); } 2875f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian 287656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 28775549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 287847e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor 287963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 28805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd()); 28815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 28821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 28831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ConditionalOperatorClass; 28845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 28855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ConditionalOperator *) { return true; } 28861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28871237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 288863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 288963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 289063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 28915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 28925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 289356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// BinaryConditionalOperator - The GNU extension to the conditional 289456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// operator which allows the middle operand to be omitted. 289556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// 289656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// This is a different expression kind on the assumption that almost 289756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// every client ends up needing to know that these are different. 289856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass BinaryConditionalOperator : public AbstractConditionalOperator { 289956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall enum { COMMON, COND, LHS, RHS, NUM_SUBEXPRS }; 290056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 290156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// - the common condition/left-hand-side expression, which will be 290256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// evaluated as the opaque value 290356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// - the condition, expressed in terms of the opaque value 290456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// - the left-hand-side, expressed in terms of the opaque value 290556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// - the right-hand-side 290656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Stmt *SubExprs[NUM_SUBEXPRS]; 290756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValueExpr *OpaqueValue; 290856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 290956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall friend class ASTStmtReader; 291056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallpublic: 291156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall BinaryConditionalOperator(Expr *common, OpaqueValueExpr *opaqueValue, 291256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *cond, Expr *lhs, Expr *rhs, 291356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation qloc, SourceLocation cloc, 291456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall QualType t, ExprValueKind VK, ExprObjectKind OK) 291556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : AbstractConditionalOperator(BinaryConditionalOperatorClass, t, VK, OK, 291656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (common->isTypeDependent() || rhs->isTypeDependent()), 291756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (common->isValueDependent() || rhs->isValueDependent()), 2918561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (common->isInstantiationDependent() || 2919561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhs->isInstantiationDependent()), 292056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (common->containsUnexpandedParameterPack() || 292156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall rhs->containsUnexpandedParameterPack()), 292256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall qloc, cloc), 292356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValue(opaqueValue) { 292456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SubExprs[COMMON] = common; 292556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SubExprs[COND] = cond; 292656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SubExprs[LHS] = lhs; 292756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SubExprs[RHS] = rhs; 292856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 292956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValue->setSourceExpr(common); 293056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 293156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 293256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief Build an empty conditional operator. 293356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall explicit BinaryConditionalOperator(EmptyShell Empty) 293456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : AbstractConditionalOperator(BinaryConditionalOperatorClass, Empty) { } 293556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 293656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getCommon - Return the common expression, written to the 293756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// left of the condition. The opaque value will be bound to the 293856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// result of this expression. 293956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getCommon() const { return cast<Expr>(SubExprs[COMMON]); } 294056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 294156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getOpaqueValue - Return the opaque value placeholder. 294256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValueExpr *getOpaqueValue() const { return OpaqueValue; } 294356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 294456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getCond - Return the condition expression; this is defined 294556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// in terms of the opaque value. 294656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 294756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 294856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getTrueExpr - Return the subexpression which will be 294956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// evaluated if the condition evaluates to true; this is defined 295056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// in terms of the opaque value. 295156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getTrueExpr() const { 295256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<Expr>(SubExprs[LHS]); 295356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 295456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 295556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getFalseExpr - Return the subexpression which will be 295656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// evaluated if the condnition evaluates to false; this is 295756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// defined in terms of the opaque value. 295856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getFalseExpr() const { 295956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<Expr>(SubExprs[RHS]); 296056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 296156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 296256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceRange getSourceRange() const { 296356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return SourceRange(getCommon()->getLocStart(), getFalseExpr()->getLocEnd()); 296456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 296556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const Stmt *T) { 296656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return T->getStmtClass() == BinaryConditionalOperatorClass; 296756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 296856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const BinaryConditionalOperator *) { return true; } 296956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 297056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // Iterators 297156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall child_range children() { 297256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return child_range(SubExprs, SubExprs + NUM_SUBEXPRS); 297356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 297456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall}; 297556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 297656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallinline Expr *AbstractConditionalOperator::getCond() const { 297756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this)) 297856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return co->getCond(); 297956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<BinaryConditionalOperator>(this)->getCond(); 298056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall} 298156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 298256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallinline Expr *AbstractConditionalOperator::getTrueExpr() const { 298356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this)) 298456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return co->getTrueExpr(); 298556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<BinaryConditionalOperator>(this)->getTrueExpr(); 298656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall} 298756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 298856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallinline Expr *AbstractConditionalOperator::getFalseExpr() const { 298956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this)) 299056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return co->getFalseExpr(); 299156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<BinaryConditionalOperator>(this)->getFalseExpr(); 299256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall} 299356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 29946481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner/// AddrLabelExpr - The GNU address of label extension, representing &&label. 29956481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattnerclass AddrLabelExpr : public Expr { 29965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation AmpAmpLoc, LabelLoc; 2997ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *Label; 29985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 2999ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelDecl *L, 30006481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner QualType t) 3001561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Expr(AddrLabelExprClass, t, VK_RValue, OK_Ordinary, false, false, false, 3002561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false), 30032333f7727f97018d6742e1e0938133bcfad967abEli Friedman AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {} 30041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30057d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor /// \brief Build an empty address of a label expression. 30061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit AddrLabelExpr(EmptyShell Empty) 30077d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor : Expr(AddrLabelExprClass, Empty) { } 30087d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 30097d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; } 30107d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; } 30117d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor SourceLocation getLabelLoc() const { return LabelLoc; } 30127d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setLabelLoc(SourceLocation L) { LabelLoc = L; } 30137d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 301463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 30155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(AmpAmpLoc, LabelLoc); 30165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 30171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3018ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *getLabel() const { return Label; } 3019ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner void setLabel(LabelDecl *L) { Label = L; } 30207d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 30215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 30221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == AddrLabelExprClass; 30235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 30246481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner static bool classof(const AddrLabelExpr *) { return true; } 30251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30261237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 302763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 30285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 3029ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner 3030ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}). 3031ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// The StmtExpr contains a single CompoundStmt node, which it evaluates and 3032ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// takes the value of the last subexpression. 3033f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall/// 3034f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall/// A StmtExpr is always an r-value; values "returned" out of a 3035f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall/// StmtExpr will be copied. 3036ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerclass StmtExpr : public Expr { 30375549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *SubStmt; 3038ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner SourceLocation LParenLoc, RParenLoc; 3039ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerpublic: 30402333f7727f97018d6742e1e0938133bcfad967abEli Friedman // FIXME: Does type-dependence need to be computed differently? 3041561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor // FIXME: Do we need to compute instantiation instantiation-dependence for 3042561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor // statements? (ugh!) 3043d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff StmtExpr(CompoundStmt *substmt, QualType T, 3044d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff SourceLocation lp, SourceLocation rp) : 3045f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(StmtExprClass, T, VK_RValue, OK_Ordinary, 3046561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor T->isDependentType(), false, false, false), 30472333f7727f97018d6742e1e0938133bcfad967abEli Friedman SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) { } 30481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30496a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor /// \brief Build an empty statement expression. 30506a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { } 30516a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor 30525549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); } 30535549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); } 30546a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setSubStmt(CompoundStmt *S) { SubStmt = S; } 30556a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor 305663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 3057ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner return SourceRange(LParenLoc, RParenLoc); 3058ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner } 30591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3060026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getLParenLoc() const { return LParenLoc; } 30616a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setLParenLoc(SourceLocation L) { LParenLoc = L; } 3062026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getRParenLoc() const { return RParenLoc; } 30636a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 30641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3065ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner static bool classof(const Stmt *T) { 30661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == StmtExprClass; 3067ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner } 3068ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner static bool classof(const StmtExpr *) { return true; } 30691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30701237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 307163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&SubStmt, &SubStmt+1); } 3072ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner}; 3073ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner 3074d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff 3075d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// ShuffleVectorExpr - clang-specific builtin-in function 3076d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// __builtin_shufflevector. 3077d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// This AST node represents a operator that does a constant 3078d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// shuffle, similar to LLVM's shufflevector instruction. It takes 3079d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// two vectors and a variable number of constant indices, 3080d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// and returns the appropriately shuffled vector. 3081d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanclass ShuffleVectorExpr : public Expr { 3082d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman SourceLocation BuiltinLoc, RParenLoc; 3083d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 3084d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // SubExprs - the list of values passed to the __builtin_shufflevector 3085d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // function. The first two are vectors, and the rest are constant 3086d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // indices. The number of values in this list is always 3087d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // 2+the number of indices in the vector type. 30885549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt **SubExprs; 3089d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman unsigned NumExprs; 3090d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 3091d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanpublic: 3092a88dc3079bedf70a5cfc39791727e43a10383006Nate Begeman ShuffleVectorExpr(ASTContext &C, Expr **args, unsigned nexpr, 30931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType Type, SourceLocation BLoc, 3094bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor SourceLocation RP); 309594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 309694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor /// \brief Build an empty vector-shuffle expression. 30971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ShuffleVectorExpr(EmptyShell Empty) 309894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor : Expr(ShuffleVectorExprClass, Empty), SubExprs(0) { } 309994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 310094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 310194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 31021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 310394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 310494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 310594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 310663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 3107d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman return SourceRange(BuiltinLoc, RParenLoc); 3108d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 3109d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman static bool classof(const Stmt *T) { 31101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ShuffleVectorExprClass; 3111d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 3112d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman static bool classof(const ShuffleVectorExpr *) { return true; } 31131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3114d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// getNumSubExprs - Return the size of the SubExprs array. This includes the 3115d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// constant expression, the actual arguments passed in, and the function 3116d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// pointers. 3117d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman unsigned getNumSubExprs() const { return NumExprs; } 31181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3119aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \brief Retrieve the array of expressions. 3120aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Expr **getSubExprs() { return reinterpret_cast<Expr **>(SubExprs); } 3121aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 3122d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// getExpr - Return the Expr at the specified index. 3123d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman Expr *getExpr(unsigned Index) { 3124d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman assert((Index < NumExprs) && "Arg access out of range!"); 31255549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Index]); 3126d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 3127d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman const Expr *getExpr(unsigned Index) const { 3128d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman assert((Index < NumExprs) && "Arg access out of range!"); 31295549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Index]); 3130d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 31311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3132888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman void setExprs(ASTContext &C, Expr ** Exprs, unsigned NumExprs); 313394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 3134dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman unsigned getShuffleMaskIdx(ASTContext &Ctx, unsigned N) { 3135dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman assert((N < NumExprs - 2) && "Shuffle idx out of range!"); 31369a901bb63990574ff0bcc12ff851d7a71cff8ddbEli Friedman return getExpr(N+2)->EvaluateAsInt(Ctx).getZExtValue(); 3137d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 31381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3139d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // Iterators 314063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 314163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+NumExprs); 314263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 3143d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman}; 3144d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 3145d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// ChooseExpr - GNU builtin-in function __builtin_choose_expr. 31461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// This AST node is similar to the conditional operator (?:) in C, with 3147d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// the following exceptions: 31487976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the test expression must be a integer constant expression. 31497976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the expression returned acts like the chosen subexpression in every 31507976932a1c256d447316ffac58e9821417725e34Eli Friedman/// visible way: the type is the same as that of the chosen subexpression, 31517976932a1c256d447316ffac58e9821417725e34Eli Friedman/// and all predicates (whether it's an l-value, whether it's an integer 31527976932a1c256d447316ffac58e9821417725e34Eli Friedman/// constant expression, etc.) return the same result as for the chosen 31537976932a1c256d447316ffac58e9821417725e34Eli Friedman/// sub-expression. 3154d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffclass ChooseExpr : public Expr { 31551237c673c07f9d827129ba02720108816abde562Ted Kremenek enum { COND, LHS, RHS, END_EXPR }; 31565549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 3157d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff SourceLocation BuiltinLoc, RParenLoc; 3158d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffpublic: 3159f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, 3160f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType t, ExprValueKind VK, ExprObjectKind OK, 3161ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor SourceLocation RP, bool TypeDependent, bool ValueDependent) 3162bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(ChooseExprClass, t, VK, OK, TypeDependent, ValueDependent, 3163561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (cond->isInstantiationDependent() || 3164561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor lhs->isInstantiationDependent() || 3165561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhs->isInstantiationDependent()), 3166bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (cond->containsUnexpandedParameterPack() || 3167bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor lhs->containsUnexpandedParameterPack() || 3168bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhs->containsUnexpandedParameterPack())), 31691237c673c07f9d827129ba02720108816abde562Ted Kremenek BuiltinLoc(BLoc), RParenLoc(RP) { 31701237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[COND] = cond; 31711237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 31721237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 31731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 31747976932a1c256d447316ffac58e9821417725e34Eli Friedman 317544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor /// \brief Build an empty __builtin_choose_expr. 317644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { } 317744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 31787976932a1c256d447316ffac58e9821417725e34Eli Friedman /// isConditionTrue - Return whether the condition is true (i.e. not 31797976932a1c256d447316ffac58e9821417725e34Eli Friedman /// equal to zero). 31804ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool isConditionTrue(const ASTContext &C) const; 31817976932a1c256d447316ffac58e9821417725e34Eli Friedman 31827976932a1c256d447316ffac58e9821417725e34Eli Friedman /// getChosenSubExpr - Return the subexpression chosen according to the 31837976932a1c256d447316ffac58e9821417725e34Eli Friedman /// condition. 31844ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad Expr *getChosenSubExpr(const ASTContext &C) const { 31857976932a1c256d447316ffac58e9821417725e34Eli Friedman return isConditionTrue(C) ? getLHS() : getRHS(); 31867976932a1c256d447316ffac58e9821417725e34Eli Friedman } 31877976932a1c256d447316ffac58e9821417725e34Eli Friedman 31885549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 318944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setCond(Expr *E) { SubExprs[COND] = E; } 31905549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 319144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 31925549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 319344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 319444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 319544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 319644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 31971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 319844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 319944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 32001237c673c07f9d827129ba02720108816abde562Ted Kremenek 320163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 3202d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff return SourceRange(BuiltinLoc, RParenLoc); 3203d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff } 3204d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff static bool classof(const Stmt *T) { 32051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ChooseExprClass; 3206d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff } 3207d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff static bool classof(const ChooseExpr *) { return true; } 32081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32091237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 321063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 321163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 321263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 3213d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff}; 3214d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff 32152d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// GNUNullExpr - Implements the GNU __null extension, which is a name 32162d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// for a null pointer constant that has integral type (e.g., int or 32172d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// long) and is the same size and alignment as a pointer. The __null 32182d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// extension is typically only used by system headers, which define 32192d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// NULL as __null in C++ rather than using 0 (which is an integer 32202d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// that may not match the size of a pointer). 32212d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorclass GNUNullExpr : public Expr { 32222d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor /// TokenLoc - The location of the __null keyword. 32232d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor SourceLocation TokenLoc; 32242d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 32252d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorpublic: 32261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump GNUNullExpr(QualType Ty, SourceLocation Loc) 3227561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Expr(GNUNullExprClass, Ty, VK_RValue, OK_Ordinary, false, false, false, 3228561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false), 3229f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall TokenLoc(Loc) { } 32302d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 323144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor /// \brief Build an empty GNU __null expression. 323244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { } 323344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 32342d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor /// getTokenLocation - The location of the __null token. 32352d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor SourceLocation getTokenLocation() const { return TokenLoc; } 323644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setTokenLocation(SourceLocation L) { TokenLoc = L; } 32372d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 323863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 32392d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor return SourceRange(TokenLoc); 32402d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } 32412d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor static bool classof(const Stmt *T) { 32421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == GNUNullExprClass; 32432d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } 32442d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor static bool classof(const GNUNullExpr *) { return true; } 32451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32462d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor // Iterators 324763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 32482d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor}; 32492d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 325074626d6ef2e194fcc911e071556660ff331eb4a8Zhongxing Xu/// VAArgExpr, used for the builtin function __builtin_va_arg. 32517c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonclass VAArgExpr : public Expr { 32525549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 32532cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara TypeSourceInfo *TInfo; 32547c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson SourceLocation BuiltinLoc, RParenLoc; 32557c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonpublic: 32562cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara VAArgExpr(SourceLocation BLoc, Expr* e, TypeSourceInfo *TInfo, 32572cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara SourceLocation RPLoc, QualType t) 3258f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(VAArgExprClass, t, VK_RValue, OK_Ordinary, 3259bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor t->isDependentType(), false, 3260561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (TInfo->getType()->isInstantiationDependentType() || 3261561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor e->isInstantiationDependent()), 3262bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (TInfo->getType()->containsUnexpandedParameterPack() || 3263bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor e->containsUnexpandedParameterPack())), 32642cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara Val(e), TInfo(TInfo), 32657c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson BuiltinLoc(BLoc), 32667c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson RParenLoc(RPLoc) { } 32671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 326874626d6ef2e194fcc911e071556660ff331eb4a8Zhongxing Xu /// \brief Create an empty __builtin_va_arg expression. 3269d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor explicit VAArgExpr(EmptyShell Empty) : Expr(VAArgExprClass, Empty) { } 3270d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 32715549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 32725549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 3273d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 3274d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 32752cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara TypeSourceInfo *getWrittenTypeInfo() const { return TInfo; } 32762cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara void setWrittenTypeInfo(TypeSourceInfo *TI) { TInfo = TI; } 32772cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara 3278d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 3279d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 32801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3281d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 3282d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 3283d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 328463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 32857c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson return SourceRange(BuiltinLoc, RParenLoc); 32861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 32877c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson static bool classof(const Stmt *T) { 32887c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson return T->getStmtClass() == VAArgExprClass; 32897c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson } 32907c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson static bool classof(const VAArgExpr *) { return true; } 32911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32927c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson // Iterators 329363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Val, &Val+1); } 32947c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson}; 32951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32964c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @brief Describes an C or C++ initializer list. 32974c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// 32984c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// InitListExpr describes an initializer list, which can be used to 32994c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initialize objects of different types, including 33004c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct/class/union types, arrays, and vectors. For example: 33014c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// 33024c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @code 33034c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct foo x = { 1, { 2, 3 } }; 33044c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @endcode 3305196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 33064c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Prior to semantic analysis, an initializer list will represent the 33074c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer list as written by the user, but will have the 33084c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// placeholder type "void". This initializer list is called the 33094c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// syntactic form of the initializer, and may contain C99 designated 33104c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializers (represented as DesignatedInitExprs), initializations 33114c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// of subobject members without explicit braces, and so on. Clients 33124c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// interested in the original syntax of the initializer list should 33134c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// use the syntactic form of the initializer list. 3314196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 33154c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// After semantic analysis, the initializer list will represent the 33164c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// semantic form of the initializer, where the initializations of all 33174c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// subobjects are made explicit with nested InitListExpr nodes and 33184c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// C99 designators have been eliminated by placing the designated 33194c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializations into the subobject they initialize. Additionally, 33204c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// any "holes" in the initialization, where no initializer has been 33214c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// specified for a particular subobject, will be replaced with 33223498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// implicitly-generated ImplicitValueInitExpr expressions that 33234c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// value-initialize the subobjects. Note, however, that the 33244c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer lists may still have fewer initializers than there are 33254c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// elements to initialize within the object. 3326196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 33274c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Given the semantic form of the initializer list, one can retrieve 33284c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// the original syntactic form of that initializer list (if it 33294c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// exists) using getSyntacticForm(). Since many initializer lists 33304c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// have the same syntactic and semantic forms, getSyntacticForm() may 33314c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// return NULL, indicating that the current initializer list also 33324c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// serves as its syntactic form. 333366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonclass InitListExpr : public Expr { 3334ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek // FIXME: Eliminate this vector in favor of ASTContext allocation 3335709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek typedef ASTVector<Stmt *> InitExprsTy; 3336709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprsTy InitExprs; 333766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson SourceLocation LBraceLoc, RBraceLoc; 33381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 33394c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// Contains the initializer list that describes the syntactic form 33404c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// written in the source code. 33414c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitListExpr *SyntacticForm; 33424c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 33434423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// \brief Either: 33444423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// If this initializer list initializes an array with more elements than 33454423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// there are initializers in the list, specifies an expression to be used 33464423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// for value initialization of the rest of the elements. 33474423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// Or 33484423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// If this initializer list initializes a union, specifies which 33494423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// field within the union will be initialized. 33504423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis llvm::PointerUnion<Expr *, FieldDecl *> ArrayFillerOrUnionFieldInit; 33510bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor 3352a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor /// Whether this initializer list originally had a GNU array-range 3353a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor /// designator in it. This is a temporary marker used by CodeGen. 3354a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor bool HadArrayRangeDesignator; 3355a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor 335666b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonpublic: 3357709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitListExpr(ASTContext &C, SourceLocation lbraceloc, 3358709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek Expr **initexprs, unsigned numinits, 3359ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek SourceLocation rbraceloc); 3360d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3361d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Build an empty initializer list. 3362709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek explicit InitListExpr(ASTContext &C, EmptyShell Empty) 3363709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek : Expr(InitListExprClass, Empty), InitExprs(C) { } 33641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3365ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek unsigned getNumInits() const { return InitExprs.size(); } 33661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3367aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \brief Retrieve the set of initializers. 3368aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Expr **getInits() { return reinterpret_cast<Expr **>(InitExprs.data()); } 3369aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 337016c5dea6c2d3e4cf529de9d9b37f6a40441acb2cChris Lattner const Expr *getInit(unsigned Init) const { 3371c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 33724c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return cast_or_null<Expr>(InitExprs[Init]); 337366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 33741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 337516c5dea6c2d3e4cf529de9d9b37f6a40441acb2cChris Lattner Expr *getInit(unsigned Init) { 3376c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 33774c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return cast_or_null<Expr>(InitExprs[Init]); 337866b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 33791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 33801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setInit(unsigned Init, Expr *expr) { 3381c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 33829e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff InitExprs[Init] = expr; 33839e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff } 3384c5ae899b4bbf65488445316c63168079177db0edSteve Naroff 3385fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor /// \brief Reserve space for some number of initializers. 3386709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek void reserveInits(ASTContext &C, unsigned NumInits); 33871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 33884c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Specify the number of initializers 33894c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 33904c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// If there are more than @p NumInits initializers, the remaining 33914c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// initializers will be destroyed. If there are fewer than @p 33924c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// NumInits initializers, NULL expressions will be added for the 33934c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// unknown initializers. 33944c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor void resizeInits(ASTContext &Context, unsigned NumInits); 33954c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 33964c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Updates the initializer at index @p Init with the new 33974c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// expression @p expr, and returns the old expression at that 33984c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// location. 33994c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 34004c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// When @p Init is out of range for this initializer list, the 34014c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// initializer list will be extended with NULL expressions to 3402fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner /// accommodate the new entry. 3403709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek Expr *updateInit(ASTContext &C, unsigned Init, Expr *expr); 3404c5ae899b4bbf65488445316c63168079177db0edSteve Naroff 34054423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// \brief If this initializer list initializes an array with more elements 34064423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// than there are initializers in the list, specifies an expression to be 34074423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// used for value initialization of the rest of the elements. 34084423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis Expr *getArrayFiller() { 34094423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis return ArrayFillerOrUnionFieldInit.dyn_cast<Expr *>(); 34104423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis } 34118cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne const Expr *getArrayFiller() const { 34128cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne return const_cast<InitListExpr *>(this)->getArrayFiller(); 34138cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne } 34143e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis void setArrayFiller(Expr *filler); 34154423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis 34160bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// \brief If this initializes a union, specifies which field in the 34170bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// union to initialize. 34180bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// 34190bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// Typically, this field is the first named field within the 34200bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// union. However, a designated initializer can specify the 34210bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// initialization of a different field within the union. 34224423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis FieldDecl *getInitializedFieldInUnion() { 34234423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis return ArrayFillerOrUnionFieldInit.dyn_cast<FieldDecl *>(); 34244423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis } 34258cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne const FieldDecl *getInitializedFieldInUnion() const { 34268cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne return const_cast<InitListExpr *>(this)->getInitializedFieldInUnion(); 34278cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne } 34284423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis void setInitializedFieldInUnion(FieldDecl *FD) { 34294423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis ArrayFillerOrUnionFieldInit = FD; 34304423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis } 34310bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor 3432c5ae899b4bbf65488445316c63168079177db0edSteve Naroff // Explicit InitListExpr's originate from source code (and have valid source 3433c5ae899b4bbf65488445316c63168079177db0edSteve Naroff // locations). Implicit InitListExpr's are created by the semantic analyzer. 3434b3eef68111ffc220e449be96da1747998c057790Douglas Gregor bool isExplicit() { 3435b3eef68111ffc220e449be96da1747998c057790Douglas Gregor return LBraceLoc.isValid() && RBraceLoc.isValid(); 3436b3eef68111ffc220e449be96da1747998c057790Douglas Gregor } 34371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3438d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor SourceLocation getLBraceLoc() const { return LBraceLoc; } 3439d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setLBraceLoc(SourceLocation Loc) { LBraceLoc = Loc; } 3440d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor SourceLocation getRBraceLoc() const { return RBraceLoc; } 344187fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; } 344287fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor 34434c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Retrieve the initializer list that describes the 34444c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// syntactic form of the initializer. 34454c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 34461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 34474c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitListExpr *getSyntacticForm() const { return SyntacticForm; } 34484c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor void setSyntacticForm(InitListExpr *Init) { SyntacticForm = Init; } 34494c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 3450a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor bool hadArrayRangeDesignator() const { return HadArrayRangeDesignator; } 34511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void sawArrayRangeDesignator(bool ARD = true) { 3452d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor HadArrayRangeDesignator = ARD; 3453a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor } 3454a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor 345563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const; 3456c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek 345766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson static bool classof(const Stmt *T) { 34581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == InitListExprClass; 345966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 346066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson static bool classof(const InitListExpr *) { return true; } 34611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 346266b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson // Iterators 346363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 346463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall if (InitExprs.empty()) return child_range(); 346563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&InitExprs[0], &InitExprs[0] + InitExprs.size()); 346663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 34671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3468709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek typedef InitExprsTy::iterator iterator; 34698111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu typedef InitExprsTy::const_iterator const_iterator; 3470709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek typedef InitExprsTy::reverse_iterator reverse_iterator; 34718111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu typedef InitExprsTy::const_reverse_iterator const_reverse_iterator; 34721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3473ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek iterator begin() { return InitExprs.begin(); } 34748111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_iterator begin() const { return InitExprs.begin(); } 3475ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek iterator end() { return InitExprs.end(); } 34768111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_iterator end() const { return InitExprs.end(); } 3477ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek reverse_iterator rbegin() { return InitExprs.rbegin(); } 34788111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_reverse_iterator rbegin() const { return InitExprs.rbegin(); } 3479ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek reverse_iterator rend() { return InitExprs.rend(); } 34808111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_reverse_iterator rend() const { return InitExprs.rend(); } 34814423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis 34824423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis friend class ASTStmtReader; 34834423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis friend class ASTStmtWriter; 348466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson}; 348566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson 348605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @brief Represents a C99 designated initializer expression. 348705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// 348805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// A designated initializer expression (C99 6.7.8) contains one or 348905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// more designators (which can be field designators, array 349005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, or GNU array-range designators) followed by an 349105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// expression that initializes the field or element(s) that the 349205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators refer to. For example, given: 34931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 349405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @code 349505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point { 349605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// double x; 349705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// double y; 349805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// }; 349905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 }; 350005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @endcode 350105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// 350205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// The InitListExpr contains three DesignatedInitExprs, the first of 350305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// which covers @c [2].y=1.0. This DesignatedInitExpr will have two 350405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, one array designator for @c [2] followed by one field 350505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designator for @c .y. The initalization expression will be 1.0. 350605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorclass DesignatedInitExpr : public Expr { 3507ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorpublic: 3508ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief Forward declaration of the Designator class. 3509ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor class Designator; 3510ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 3511ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorprivate: 351205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '=' or ':' prior to the actual initializer 351305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// expression. 351405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EqualOrColonLoc; 351505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3516eeae8f072748affce25ab4064982626361293390Douglas Gregor /// Whether this designated initializer used the GNU deprecated 351705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// syntax rather than the C99 '=' syntax. 3518eeae8f072748affce25ab4064982626361293390Douglas Gregor bool GNUSyntax : 1; 351905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 352005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The number of designators in this initializer expression. 352105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators : 15; 352205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3523ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief The designators in this designated initialization 3524ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// expression. 3525ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designator *Designators; 3526ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 352705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The number of subexpressions of this initializer expression, 352805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// which contains both the initializer and any additional 352905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// expressions used by array and array-range designators. 353005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumSubExprs : 16; 353105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3532ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 3533319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor DesignatedInitExpr(ASTContext &C, QualType Ty, unsigned NumDesignators, 3534ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Designators, 3535eeae8f072748affce25ab4064982626361293390Douglas Gregor SourceLocation EqualOrColonLoc, bool GNUSyntax, 35369ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr **IndexExprs, unsigned NumIndexExprs, 35379ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *Init); 353805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3539d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor explicit DesignatedInitExpr(unsigned NumSubExprs) 3540d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor : Expr(DesignatedInitExprClass, EmptyShell()), 3541d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor NumDesignators(0), Designators(0), NumSubExprs(NumSubExprs) { } 3542d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 354305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorpublic: 354405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// A field designator, e.g., ".x". 354505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct FieldDesignator { 354605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// Refers to the field that is being initialized. The low bit 354705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// of this field determines whether this is actually a pointer 354805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When 354905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initially constructed, a field designator will store an 355005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// IdentifierInfo*. After semantic analysis has resolved that 355105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// name, the field designator will instead store a FieldDecl*. 355205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor uintptr_t NameOrField; 35531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 355405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '.' in the designated initializer. 355505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned DotLoc; 35561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 355705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the field name in the designated initializer. 355805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned FieldLoc; 355905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 356005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 356105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". 356205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct ArrayOrRangeDesignator { 356305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// Location of the first index expression within the designated 356405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initializer expression's list of subexpressions. 356505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned Index; 356605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '[' starting the array range designator. 356705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned LBracketLoc; 356805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the ellipsis separating the start and end 356905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// indices. Only valid for GNU array-range designators. 357005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned EllipsisLoc; 357105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the ']' terminating the array range designator. 35721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned RBracketLoc; 357305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 357405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 357505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Represents a single C99 designator. 357605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// 357705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @todo This class is infuriatingly similar to clang::Designator, 357805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// but minor differences (storing indices vs. storing pointers) 357905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// keep us from reusing it. Try harder, later, to rectify these 358005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// differences. 358105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor class Designator { 358205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief The kind of designator this describes. 358305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor enum { 358405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor FieldDesignator, 358505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayDesignator, 358605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayRangeDesignator 358705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } Kind; 358805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 358905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor union { 359005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// A field designator, e.g., ".x". 359105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct FieldDesignator Field; 359205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". 359305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct ArrayOrRangeDesignator ArrayOrRange; 359405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 359505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor friend class DesignatedInitExpr; 359605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 359705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor public: 3598ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designator() {} 3599ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 360005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes a field designator. 36011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc, 36021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation FieldLoc) 360305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(FieldDesignator) { 360405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01; 360505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.DotLoc = DotLoc.getRawEncoding(); 360605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.FieldLoc = FieldLoc.getRawEncoding(); 360705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 360805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 360905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes an array designator. 36101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(unsigned Index, SourceLocation LBracketLoc, 361105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation RBracketLoc) 361205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(ArrayDesignator) { 361305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.Index = Index; 361405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding(); 361505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding(); 361605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding(); 361705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 361805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 361905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes a GNU array-range designator. 36201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(unsigned Index, SourceLocation LBracketLoc, 362105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EllipsisLoc, SourceLocation RBracketLoc) 362205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(ArrayRangeDesignator) { 362305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.Index = Index; 362405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding(); 362505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding(); 362605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding(); 362705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 362805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 362905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isFieldDesignator() const { return Kind == FieldDesignator; } 363005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isArrayDesignator() const { return Kind == ArrayDesignator; } 363105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; } 363205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3633b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth IdentifierInfo *getFieldName() const; 363405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3635b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth FieldDecl *getField() const { 363605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 363705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor if (Field.NameOrField & 0x01) 363805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return 0; 363905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor else 364005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return reinterpret_cast<FieldDecl *>(Field.NameOrField); 364105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 364205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 364305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor void setField(FieldDecl *FD) { 364405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 364505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.NameOrField = reinterpret_cast<uintptr_t>(FD); 364605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 364705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 364887f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor SourceLocation getDotLoc() const { 364987f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 365087f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor return SourceLocation::getFromRawEncoding(Field.DotLoc); 365187f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor } 365287f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor 365305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getFieldLoc() const { 365405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 365505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(Field.FieldLoc); 365605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 365705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 365805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getLBracketLoc() const { 365905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 366005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array or array-range designator"); 366105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc); 366205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 366305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 366405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getRBracketLoc() const { 366505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 366605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array or array-range designator"); 366705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc); 366805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 366905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 367005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getEllipsisLoc() const { 367105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == ArrayRangeDesignator && 367205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array-range designator"); 367305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc); 367405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 36754c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 3676d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned getFirstExprIndex() const { 3677d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 3678d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor "Only valid on an array or array-range designator"); 3679d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor return ArrayOrRange.Index; 3680d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 3681d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 36824c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor SourceLocation getStartLocation() const { 36834c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor if (Kind == FieldDesignator) 36844c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return getDotLoc().isInvalid()? getFieldLoc() : getDotLoc(); 36854c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor else 36864c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return getLBracketLoc(); 36874c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor } 368824f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara SourceLocation getEndLocation() const { 368924f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara return Kind == FieldDesignator ? getFieldLoc() : getRBracketLoc(); 369024f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara } 369124f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara SourceRange getSourceRange() const { 369224f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara return SourceRange(getStartLocation(), getEndLocation()); 369324f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara } 369405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 369505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 36961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static DesignatedInitExpr *Create(ASTContext &C, Designator *Designators, 369705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators, 369805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr **IndexExprs, unsigned NumIndexExprs, 369905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EqualOrColonLoc, 3700eeae8f072748affce25ab4064982626361293390Douglas Gregor bool GNUSyntax, Expr *Init); 370105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3702d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor static DesignatedInitExpr *CreateEmpty(ASTContext &C, unsigned NumIndexExprs); 3703d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 370405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Returns the number of designators in this initializer. 370505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned size() const { return NumDesignators; } 370605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 370705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor // Iterator access to the designators. 3708b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth typedef Designator *designators_iterator; 3709ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor designators_iterator designators_begin() { return Designators; } 37101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump designators_iterator designators_end() { 37111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return Designators + NumDesignators; 3712ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor } 371305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3714b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth typedef const Designator *const_designators_iterator; 3715b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth const_designators_iterator designators_begin() const { return Designators; } 3716b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth const_designators_iterator designators_end() const { 3717b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth return Designators + NumDesignators; 3718b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth } 3719b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth 3720cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek typedef std::reverse_iterator<designators_iterator> 3721cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek reverse_designators_iterator; 3722cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek reverse_designators_iterator designators_rbegin() { 3723cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek return reverse_designators_iterator(designators_end()); 3724cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek } 3725cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek reverse_designators_iterator designators_rend() { 3726cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek return reverse_designators_iterator(designators_begin()); 3727cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek } 3728cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek 3729b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth typedef std::reverse_iterator<const_designators_iterator> 3730b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth const_reverse_designators_iterator; 3731b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth const_reverse_designators_iterator designators_rbegin() const { 3732b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth return const_reverse_designators_iterator(designators_end()); 3733b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth } 3734b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth const_reverse_designators_iterator designators_rend() const { 3735b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth return const_reverse_designators_iterator(designators_begin()); 3736b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth } 3737b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth 3738711997184366d584c9c437102cae1e9d9927b986Douglas Gregor Designator *getDesignator(unsigned Idx) { return &designators_begin()[Idx]; } 3739711997184366d584c9c437102cae1e9d9927b986Douglas Gregor 3740c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt void setDesignators(ASTContext &C, const Designator *Desigs, 3741319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor unsigned NumDesigs); 3742d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 374305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayIndex(const Designator& D); 374405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayRangeStart(const Designator& D); 374505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayRangeEnd(const Designator& D); 374605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 374705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Retrieve the location of the '=' that precedes the 374805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initializer value itself, if present. 374905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; } 3750d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setEqualOrColonLoc(SourceLocation L) { EqualOrColonLoc = L; } 375105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 375205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Determines whether this designated initializer used the 3753eeae8f072748affce25ab4064982626361293390Douglas Gregor /// deprecated GNU syntax for designated initializers. 3754eeae8f072748affce25ab4064982626361293390Douglas Gregor bool usesGNUSyntax() const { return GNUSyntax; } 3755d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setGNUSyntax(bool GNU) { GNUSyntax = GNU; } 375605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 375705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Retrieve the initializer value. 37581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getInit() const { 375905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin()); 376005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 376105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 376205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor void setInit(Expr *init) { 376305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor *child_begin() = init; 376405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 376505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3766d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Retrieve the total number of subexpressions in this 3767d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// designated initializer expression, including the actual 3768d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// initialized value and any expressions that occur within array 3769d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// and array-range designators. 3770d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned getNumSubExprs() const { return NumSubExprs; } 3771d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3772d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Expr *getSubExpr(unsigned Idx) { 3773d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert(Idx < NumSubExprs && "Subscript out of range"); 3774d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 3775d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 3776d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor return reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx]; 3777d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 3778d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3779d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setSubExpr(unsigned Idx, Expr *E) { 3780d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert(Idx < NumSubExprs && "Subscript out of range"); 3781d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 3782d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 3783d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx] = E; 3784d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 3785d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3786ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief Replaces the designator at index @p Idx with the series 3787ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// of designators in [First, Last). 3788319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor void ExpandDesignator(ASTContext &C, unsigned Idx, const Designator *First, 3789ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Last); 3790ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 379124f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara SourceRange getDesignatorsSourceRange() const; 379224f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara 379363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const; 379405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 379505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor static bool classof(const Stmt *T) { 37961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == DesignatedInitExprClass; 379705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 379805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor static bool classof(const DesignatedInitExpr *) { return true; } 379905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 380005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor // Iterators 380163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 380263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt **begin = reinterpret_cast<Stmt**>(this + 1); 380363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(begin, begin + NumSubExprs); 380463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 38053498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor}; 38063498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 38073498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// \brief Represents an implicitly-generated value initialization of 38083498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// an object of a given type. 38093498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// 38101a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// Implicit value initializations occur within semantic initializer 38111a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// list expressions (InitListExpr) as placeholders for subobject 38123498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// initializations not explicitly specified by the user. 38131a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// 38141a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// \see InitListExpr 38151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass ImplicitValueInitExpr : public Expr { 38163498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregorpublic: 38171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ImplicitValueInitExpr(QualType ty) 3818f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ImplicitValueInitExprClass, ty, VK_RValue, OK_Ordinary, 3819561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false, ty->isInstantiationDependentType(), false) { } 38203498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 3821d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Construct an empty implicit value initialization. 3822d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor explicit ImplicitValueInitExpr(EmptyShell Empty) 3823d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor : Expr(ImplicitValueInitExprClass, Empty) { } 3824d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 38251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 38263498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return T->getStmtClass() == ImplicitValueInitExprClass; 38273498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor } 38283498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor static bool classof(const ImplicitValueInitExpr *) { return true; } 38293498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 383063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 38313498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return SourceRange(); 38323498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor } 38333498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 38343498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor // Iterators 383563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 383605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}; 383705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 38382ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 38392ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanclass ParenListExpr : public Expr { 38402ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman Stmt **Exprs; 38412ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman unsigned NumExprs; 38422ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation LParenLoc, RParenLoc; 38432ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 38442ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanpublic: 38451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParenListExpr(ASTContext& C, SourceLocation lparenloc, Expr **exprs, 38460d9106fc97cde979a995e26b18bcd2643f8afb55Manuel Klimek unsigned numexprs, SourceLocation rparenloc, QualType T); 38472ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 38482ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman /// \brief Build an empty paren list. 384937bdfe284ad365f753741d1d89c078c148b3f4afArgyrios Kyrtzidis explicit ParenListExpr(EmptyShell Empty) : Expr(ParenListExprClass, Empty) { } 38501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 38512ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman unsigned getNumExprs() const { return NumExprs; } 38521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 38531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr* getExpr(unsigned Init) const { 38542ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman assert(Init < getNumExprs() && "Initializer access out of range!"); 38552ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return cast_or_null<Expr>(Exprs[Init]); 38562ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 38571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 38581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr* getExpr(unsigned Init) { 38592ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman assert(Init < getNumExprs() && "Initializer access out of range!"); 38602ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return cast_or_null<Expr>(Exprs[Init]); 38612ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 38622ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 386383ddad3ab513f5d73698cf9fbeb4ed3f011bc3b9Douglas Gregor Expr **getExprs() { return reinterpret_cast<Expr **>(Exprs); } 38641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 38652ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation getLParenLoc() const { return LParenLoc; } 38662ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation getRParenLoc() const { return RParenLoc; } 38672ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 386863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 38692ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return SourceRange(LParenLoc, RParenLoc); 38701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 38712ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman static bool classof(const Stmt *T) { 38721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ParenListExprClass; 38732ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 38742ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman static bool classof(const ParenListExpr *) { return true; } 38751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 38762ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman // Iterators 387763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 387863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&Exprs[0], &Exprs[0]+NumExprs); 387963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 388037bdfe284ad365f753741d1d89c078c148b3f4afArgyrios Kyrtzidis 388160adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 38823397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl friend class ASTStmtWriter; 38832ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman}; 38842ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 38851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3886f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// \brief Represents a C1X generic selection. 3887f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// 3888f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// A generic selection (C1X 6.5.1.1) contains an unevaluated controlling 3889f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// expression, followed by one or more generic associations. Each generic 3890f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// association specifies a type name and an expression, or "default" and an 3891f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// expression (in which case it is known as a default generic association). 3892f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// The type and value of the generic selection are identical to those of its 3893f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// result expression, which is defined as the expression in the generic 3894f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// association with a type name that is compatible with the type of the 3895f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// controlling expression, or the expression in the default generic association 3896f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// if no types are compatible. For example: 3897f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// 3898f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// @code 3899f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// _Generic(X, double: 1, float: 2, default: 3) 3900f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// @endcode 3901f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// 3902f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// The above expression evaluates to 1 if 1.0 is substituted for X, 2 if 1.0f 3903f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// or 3 if "hello". 3904f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// 3905f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// As an extension, generic selections are allowed in C++, where the following 3906f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// additional semantics apply: 3907f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// 3908f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// Any generic selection whose controlling expression is type-dependent or 3909f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// which names a dependent type in its association list is result-dependent, 3910f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// which means that the choice of result expression is dependent. 3911f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// Result-dependent generic associations are both type- and value-dependent. 3912f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourneclass GenericSelectionExpr : public Expr { 3913f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne enum { CONTROLLING, END_EXPR }; 3914f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo **AssocTypes; 3915f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Stmt **SubExprs; 3916f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned NumAssocs, ResultIndex; 3917f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation GenericLoc, DefaultLoc, RParenLoc; 3918f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3919f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbournepublic: 3920f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne GenericSelectionExpr(ASTContext &Context, 3921f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation GenericLoc, Expr *ControllingExpr, 3922f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo **AssocTypes, Expr **AssocExprs, 3923f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned NumAssocs, SourceLocation DefaultLoc, 3924f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation RParenLoc, 3925f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne bool ContainsUnexpandedParameterPack, 3926f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned ResultIndex); 3927f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3928f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// This constructor is used in the result-dependent case. 3929f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne GenericSelectionExpr(ASTContext &Context, 3930f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation GenericLoc, Expr *ControllingExpr, 3931f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo **AssocTypes, Expr **AssocExprs, 3932f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned NumAssocs, SourceLocation DefaultLoc, 3933f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation RParenLoc, 3934f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne bool ContainsUnexpandedParameterPack); 3935f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3936f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne explicit GenericSelectionExpr(EmptyShell Empty) 3937f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne : Expr(GenericSelectionExprClass, Empty) { } 3938f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3939f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned getNumAssocs() const { return NumAssocs; } 3940f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3941f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation getGenericLoc() const { return GenericLoc; } 3942f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation getDefaultLoc() const { return DefaultLoc; } 3943f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation getRParenLoc() const { return RParenLoc; } 3944f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3945f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const Expr *getAssocExpr(unsigned i) const { 3946f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<Expr>(SubExprs[END_EXPR+i]); 3947f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 3948f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Expr *getAssocExpr(unsigned i) { return cast<Expr>(SubExprs[END_EXPR+i]); } 3949f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3950f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const TypeSourceInfo *getAssocTypeSourceInfo(unsigned i) const { 3951f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return AssocTypes[i]; 3952f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 3953f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo *getAssocTypeSourceInfo(unsigned i) { return AssocTypes[i]; } 3954f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3955f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne QualType getAssocType(unsigned i) const { 3956f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (const TypeSourceInfo *TS = getAssocTypeSourceInfo(i)) 3957f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return TS->getType(); 3958f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne else 3959f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return QualType(); 3960f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 3961f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3962f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const Expr *getControllingExpr() const { 3963f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<Expr>(SubExprs[CONTROLLING]); 3964f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 3965f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Expr *getControllingExpr() { return cast<Expr>(SubExprs[CONTROLLING]); } 3966f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3967f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// Whether this generic selection is result-dependent. 3968f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne bool isResultDependent() const { return ResultIndex == -1U; } 3969f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3970f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// The zero-based index of the result expression's generic association in 3971f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// the generic selection's association list. Defined only if the 3972f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// generic selection is not result-dependent. 3973f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned getResultIndex() const { 3974f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne assert(!isResultDependent() && "Generic selection is result-dependent"); 3975f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return ResultIndex; 3976f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 3977f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3978f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// The generic selection's result expression. Defined only if the 3979f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// generic selection is not result-dependent. 3980f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const Expr *getResultExpr() const { return getAssocExpr(getResultIndex()); } 3981f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Expr *getResultExpr() { return getAssocExpr(getResultIndex()); } 3982f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3983f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceRange getSourceRange() const { 3984f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return SourceRange(GenericLoc, RParenLoc); 3985f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 3986f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne static bool classof(const Stmt *T) { 3987f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return T->getStmtClass() == GenericSelectionExprClass; 3988f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 3989f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne static bool classof(const GenericSelectionExpr *) { return true; } 3990f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3991f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne child_range children() { 3992f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return child_range(SubExprs, SubExprs+END_EXPR+NumAssocs); 3993f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 3994f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3995f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne friend class ASTStmtReader; 3996f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne}; 3997f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 39984eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===// 39994eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff// Clang Extensions 40004eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===// 40014eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 4002a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 4003a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// ExtVectorElementExpr - This represents access to specific elements of a 4004a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// vector, and may occur on the left hand side or right hand side. For example 4005a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// the following is legal: "V.xy = V.zw" if V is a 4 element extended vector. 4006a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// 400773525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// Note that the base may have either vector or pointer to vector type, just 400873525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// like a struct field reference. 400973525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// 4010a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerclass ExtVectorElementExpr : public Expr { 4011a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner Stmt *Base; 4012d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor IdentifierInfo *Accessor; 4013a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner SourceLocation AccessorLoc; 4014a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerpublic: 4015f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExtVectorElementExpr(QualType ty, ExprValueKind VK, Expr *base, 4016f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall IdentifierInfo &accessor, SourceLocation loc) 40170943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall : Expr(ExtVectorElementExprClass, ty, VK, 40180943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall (VK == VK_RValue ? OK_Ordinary : OK_VectorComponent), 4019bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->isTypeDependent(), base->isValueDependent(), 4020561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor base->isInstantiationDependent(), 4021bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->containsUnexpandedParameterPack()), 4022d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor Base(base), Accessor(&accessor), AccessorLoc(loc) {} 40231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4024d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor /// \brief Build an empty vector element expression. 4025d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor explicit ExtVectorElementExpr(EmptyShell Empty) 4026d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor : Expr(ExtVectorElementExprClass, Empty) { } 4027d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 4028a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner const Expr *getBase() const { return cast<Expr>(Base); } 4029a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner Expr *getBase() { return cast<Expr>(Base); } 4030d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setBase(Expr *E) { Base = E; } 4031d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 4032d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor IdentifierInfo &getAccessor() const { return *Accessor; } 4033d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setAccessor(IdentifierInfo *II) { Accessor = II; } 4034d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 4035d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getAccessorLoc() const { return AccessorLoc; } 4036d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setAccessorLoc(SourceLocation L) { AccessorLoc = L; } 4037d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 4038a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// getNumElements - Get the number of components being selected. 4039a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner unsigned getNumElements() const; 40401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4041a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// containsDuplicateElements - Return true if any element access is 4042a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// repeated. 4043a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner bool containsDuplicateElements() const; 40441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4045a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// getEncodedElementAccess - Encode the elements accessed into an llvm 4046a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// aggregate Constant of ConstantInt(s). 4047a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner void getEncodedElementAccess(llvm::SmallVectorImpl<unsigned> &Elts) const; 40481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 404963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 4050a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner return SourceRange(getBase()->getLocStart(), AccessorLoc); 4051a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner } 40521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 40532140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner /// isArrow - Return true if the base expression is a pointer to vector, 40542140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner /// return false if the base expression is a vector. 40552140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner bool isArrow() const; 40561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 40571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 40581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ExtVectorElementExprClass; 4059a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner } 4060a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner static bool classof(const ExtVectorElementExpr *) { return true; } 40611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4062a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner // Iterators 406363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Base, &Base+1); } 4064a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner}; 4065a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 4066a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 406756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff/// BlockExpr - Adaptor class for mixing a BlockDecl with expressions. 40689c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff/// ^{ statement-body } or ^(int arg1, float arg2){ statement-body } 40694eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockExpr : public Expr { 407056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroffprotected: 407156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff BlockDecl *TheBlock; 40724eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic: 4073469a1eb996e1cb0be54f9b210f836afbddcbb2ccJohn McCall BlockExpr(BlockDecl *BD, QualType ty) 4074f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(BlockExprClass, ty, VK_RValue, OK_Ordinary, 4075561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ty->isDependentType(), false, 4076561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor // FIXME: Check for instantiate-dependence in the statement? 4077561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ty->isInstantiationDependentType(), 4078561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false), 4079469a1eb996e1cb0be54f9b210f836afbddcbb2ccJohn McCall TheBlock(BD) {} 40809c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 408184af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor /// \brief Build an empty block expression. 408284af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor explicit BlockExpr(EmptyShell Empty) : Expr(BlockExprClass, Empty) { } 408384af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor 4084d5cab5435371b8cc74a9e05ebd40b5995ebad149Anders Carlsson const BlockDecl *getBlockDecl() const { return TheBlock; } 408556ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff BlockDecl *getBlockDecl() { return TheBlock; } 408684af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor void setBlockDecl(BlockDecl *BD) { TheBlock = BD; } 408784af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor 408856ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff // Convenience functions for probing the underlying BlockDecl. 408956ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff SourceLocation getCaretLocation() const; 409056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff const Stmt *getBody() const; 409156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff Stmt *getBody(); 40929c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 409363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 409456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff return SourceRange(getCaretLocation(), getBody()->getLocEnd()); 40959c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff } 40969c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 409756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff /// getFunctionType - Return the underlying function type for this block. 409856ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff const FunctionType *getFunctionType() const; 409956ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 41001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 41019c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff return T->getStmtClass() == BlockExprClass; 41024eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff } 41034eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff static bool classof(const BlockExpr *) { return true; } 41041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 41054eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff // Iterators 410663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 41074eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff}; 41081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 41096b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall/// BlockDeclRefExpr - A reference to a local variable declared in an 41106b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall/// enclosing scope. 41114eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockDeclRefExpr : public Expr { 41126b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall VarDecl *D; 41134eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff SourceLocation Loc; 41147d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool IsByRef : 1; 41157d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool ConstQualAdded : 1; 41164eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic: 41176b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall BlockDeclRefExpr(VarDecl *d, QualType t, ExprValueKind VK, 41186b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall SourceLocation l, bool ByRef, bool constAdded = false); 411994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 412094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor // \brief Build an empty reference to a declared variable in a 412194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor // block. 412294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor explicit BlockDeclRefExpr(EmptyShell Empty) 412394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor : Expr(BlockDeclRefExprClass, Empty) { } 41241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 41256b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall VarDecl *getDecl() { return D; } 41266b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall const VarDecl *getDecl() const { return D; } 41276b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall void setDecl(VarDecl *VD) { D = VD; } 412894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 412994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getLocation() const { return Loc; } 413094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setLocation(SourceLocation L) { Loc = L; } 413194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 413263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 41331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 41344eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff bool isByRef() const { return IsByRef; } 413594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setByRef(bool BR) { IsByRef = BR; } 41361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 41377d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool isConstQualAdded() const { return ConstQualAdded; } 41387d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian void setConstQualAdded(bool C) { ConstQualAdded = C; } 413989f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian 41401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 41411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == BlockDeclRefExprClass; 41424eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff } 41434eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff static bool classof(const BlockDeclRefExpr *) { return true; } 41441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 41454eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff // Iterators 414663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 41474eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff}; 41484eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 414961eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner/// AsTypeExpr - Clang builtin function __builtin_astype [OpenCL 6.2.4.2] 415061eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner/// This AST node provides support for reinterpreting a type to another 415161eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner/// type of the same size. 415261eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattnerclass AsTypeExpr : public Expr { 415361eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattnerprivate: 415461eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner Expr* SrcExpr; 415561eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner QualType DstType; 415661eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner SourceLocation BuiltinLoc, RParenLoc; 415761eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner 415861eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattnerpublic: 415961eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner AsTypeExpr(Expr* SrcExpr, QualType DstType, 416061eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner ExprValueKind VK, ExprObjectKind OK, 416161eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner SourceLocation BuiltinLoc, SourceLocation RParenLoc) 4162561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Expr(AsTypeExprClass, DstType, VK, OK, 4163561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor DstType->isDependentType(), 4164561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor DstType->isDependentType() || SrcExpr->isValueDependent(), 4165561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (DstType->isInstantiationDependentType() || 4166561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor SrcExpr->isInstantiationDependent()), 4167561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (DstType->containsUnexpandedParameterPack() || 4168561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor SrcExpr->containsUnexpandedParameterPack())), 416961eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner SrcExpr(SrcExpr), DstType(DstType), 417061eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner BuiltinLoc(BuiltinLoc), RParenLoc(RParenLoc) {} 417161eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner 417261eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner /// \brief Build an empty __builtin_astype 417361eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner explicit AsTypeExpr(EmptyShell Empty) : Expr(AsTypeExprClass, Empty) {} 417461eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner 417561eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner /// getSrcExpr - Return the Expr to be converted. 417661eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner Expr *getSrcExpr() const { return SrcExpr; } 417761eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner QualType getDstType() const { return DstType; } 417861eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner 41797b33c2b3908b178511ccaace8cacb5e5b14552a9Nick Lewycky SourceRange getSourceRange() const { 418061eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner return SourceRange(BuiltinLoc, RParenLoc); 418161eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner } 418261eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner 418361eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner static bool classof(const Stmt *T) { 418461eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner return T->getStmtClass() == AsTypeExprClass; 418561eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner } 418661eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner static bool classof(const AsTypeExpr *) { return true; } 418761eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner 418861eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner // Iterators 418961eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner child_range children() { return child_range(); } 419061eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner}; 41915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 41925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 41935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 4194