Expr.h revision 85def357129b6cdfd69a66ad0e6994506418a2a9
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" 2371a7605977113c795edd44fcbd2302ad49506653Argyrios Kyrtzidis#include "clang/AST/TemplateBase.h" 24409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson#include "clang/AST/UsuallyTinyPtrVector.h" 25f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne#include "clang/Basic/TypeTraits.h" 265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/APSInt.h" 27525a05093a4816af961fe2bc6b8a81c17e2e26c2Chris Lattner#include "llvm/ADT/APFloat.h" 283b8d116703db8018f855cbb4733ace426422623bNate Begeman#include "llvm/ADT/SmallVector.h" 29b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar#include "llvm/ADT/StringRef.h" 30403ba3522d1b1c97ae5fad81c1a2c4b3a754e1c1Nick Lewycky#include <cctype> 315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 33590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner class ASTContext; 34c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson class APValue; 35c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class Decl; 36c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class IdentifierInfo; 37c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class ParmVarDecl; 388e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor class NamedDecl; 39c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class ValueDecl; 4056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff class BlockDecl; 41409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson class CXXBaseSpecifier; 4288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor class CXXOperatorCallExpr; 4388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor class CXXMemberCallExpr; 44f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall class ObjCPropertyRefExpr; 4556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall class OpaqueValueExpr; 4688a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 477ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson/// \brief A simple array of base specifiers. 48686775deca8b8685eb90801495880e3abdd844c2Chris Lattnertypedef SmallVector<CXXBaseSpecifier*, 4> CXXCastPath; 497ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson 505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Expr - This represents one expression. Note that Expr's are subclasses of 515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Stmt. This allows an expression to be transparently used any place a Stmt 525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is required. 535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Expr : public Stmt { 555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType TR; 56898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 578e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCallprotected: 58f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(StmtClass SC, QualType T, ExprValueKind VK, ExprObjectKind OK, 59561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool TD, bool VD, bool ID, bool ContainsUnexpandedParameterPack) 60561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Stmt(SC) 61561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor { 628e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.TypeDependent = TD; 638e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.ValueDependent = VD; 64561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = ID; 65f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprBits.ValueKind = VK; 66f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprBits.ObjectKind = OK; 67bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack; 68898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor setType(T); 69898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 70898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 710b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Construct an empty expression. 720b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor explicit Expr(StmtClass SC, EmptyShell) : Stmt(SC) { } 730b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 75f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor QualType getType() const { return TR; } 761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setType(QualType t) { 779d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // In C++, the type of an expression is always adjusted so that it 789d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // will not have reference type an expression will never have 799d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // reference type (C++ [expr]p6). Use 809d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // QualType::getNonReferenceType() to retrieve the non-reference 819d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // type. Additionally, inspect Expr::isLvalue to determine whether 829d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // an expression that is adjusted in this manner should be 839d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // considered an lvalue. 84905d11d53aeb6b26744f44fedc2b2820c7a62df6Douglas Gregor assert((t.isNull() || !t->isReferenceType()) && 858320aaaa01d931aa234fc3bce05b399ef41898d5Daniel Dunbar "Expressions can't have reference type"); 86f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor 871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TR = t; 889d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor } 8977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 90898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isValueDependent - Determines whether this expression is 91898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// value-dependent (C++ [temp.dep.constexpr]). For example, the 92898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// array bound of "Chars" in the following example is 931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// value-dependent. 94898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @code 95898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// template<int Size, char (&Chars)[Size]> struct meta_string; 96898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @endcode 978e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall bool isValueDependent() const { return ExprBits.ValueDependent; } 98898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 990b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Set whether this expression is value-dependent or not. 100561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor void setValueDependent(bool VD) { 101561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.ValueDependent = VD; 102561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (VD) 103561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 104561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 1050b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 106898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isTypeDependent - Determines whether this expression is 107898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// type-dependent (C++ [temp.dep.expr]), which means that its type 108898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// could change from one template instantiation to the next. For 109898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// example, the expressions "x" and "x + y" are type-dependent in 110898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// the following code, but "y" is not type-dependent: 111898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @code 1121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// template<typename T> 113898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// void add(T x, int y) { 114898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// x + y; 115898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// } 116898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @endcode 1178e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall bool isTypeDependent() const { return ExprBits.TypeDependent; } 118898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1190b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Set whether this expression is type-dependent or not. 120561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor void setTypeDependent(bool TD) { 121561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.TypeDependent = TD; 122561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (TD) 123561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 124561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 125561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 126561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// \brief Whether this expression is instantiation-dependent, meaning that 127561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// it depends in some way on a template parameter, even if neither its type 128561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// nor (constant) value can change due to the template instantiation. 129561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// 130561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// In the following example, the expression \c sizeof(sizeof(T() + T())) is 131561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// instantiation-dependent (since it involves a template parameter \c T), but 132561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// is neither type- nor value-dependent, since the type of the inner 133561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// \c sizeof is known (\c std::size_t) and therefore the size of the outer 134561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// \c sizeof is known. 135561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// 136561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// \code 137561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// template<typename T> 138561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// void f(T x, T y) { 139561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// sizeof(sizeof(T() + T()); 140561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// } 141561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// \endcode 142561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// 143561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool isInstantiationDependent() const { 144561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor return ExprBits.InstantiationDependent; 145561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 146561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 147561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// \brief Set whether this expression is instantiation-dependent or not. 148561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor void setInstantiationDependent(bool ID) { 149561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = ID; 150561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 1510b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 152d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \brief Whether this expression contains an unexpanded parameter 153d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// pack (for C++0x variadic templates). 154d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// 155d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// Given the following function template: 156d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// 157d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \code 158d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// template<typename F, typename ...Types> 159d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// void forward(const F &f, Types &&...args) { 160d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// f(static_cast<Types&&>(args)...); 161d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// } 162d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \endcode 163d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// 164d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// The expressions \c args and \c static_cast<Types&&>(args) both 165d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// contain parameter packs. 166d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor bool containsUnexpandedParameterPack() const { 167d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor return ExprBits.ContainsUnexpandedParameterPack; 168d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor } 169d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 170bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /// \brief Set the bit that describes whether this expression 171bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /// contains an unexpanded parameter pack. 172bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor void setContainsUnexpandedParameterPack(bool PP = true) { 173bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = PP; 174bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor } 175bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 1765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getExprLoc - Return the preferred location for the arrow when diagnosing 1775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// a problem with a generic expression. 17863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation getExprLoc() const; 1791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 180026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// isUnusedResultAWarning - Return true if this immediate expression should 181026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// be warned about if the result is unused. If so, fill in Loc and Ranges 182026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// with location to warn on and the source range[s] to report with the 183026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// warning. 184026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner bool isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1, 185df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump SourceRange &R2, ASTContext &Ctx) const; 1861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1877eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// isLValue - True if this expression is an "l-value" according to 1887eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// the rules of the current language. C and C++ give somewhat 1897eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// different rules for this concept, but in general, the result of 1907eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// an l-value expression identifies a specific object whereas the 1917eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// result of an r-value expression is a value detached from any 1927eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// specific storage. 1935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 1947eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// C++0x divides the concept of "r-value" into pure r-values 1957eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// ("pr-values") and so-called expiring values ("x-values"), which 1967eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// identify specific objects that can be safely cannibalized for 1977eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// their resources. This is an unfortunate abuse of terminology on 1987eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// the part of the C++ committee. In Clang, when we say "r-value", 1997eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// we generally mean a pr-value. 2007eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall bool isLValue() const { return getValueKind() == VK_LValue; } 2017eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall bool isRValue() const { return getValueKind() == VK_RValue; } 2027eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall bool isXValue() const { return getValueKind() == VK_XValue; } 2037eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall bool isGLValue() const { return getValueKind() != VK_RValue; } 2047eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall 2057eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall enum LValueClassification { 2065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_Valid, 2075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_NotObjectType, 2085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_IncompleteVoidType, 209fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff LV_DuplicateVectorComponents, 21086f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor LV_InvalidExpression, 211077f490d0a514dcc448475f33f799934252b85a7Fariborz Jahanian LV_InvalidMessageExpression, 2122514a309204341798f96912ce7a90841bea59727Fariborz Jahanian LV_MemberFunction, 213e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian LV_SubObjCPropertySetting, 214e873fb74219f48407ae0b8fa083aa7f0b6ff1427Douglas Gregor LV_ClassTemporary 2155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 2167eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// Reasons why an expression might not be an l-value. 2177eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall LValueClassification ClassifyLValue(ASTContext &Ctx) const; 21853202857c60214d80950a975e6e52aebf30bd16aEli Friedman 2195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type, 2205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// does not have an incomplete type, does not have a const-qualified type, 2211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// and if it is a structure or union, does not have any member (including, 2225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// recursively, any member or element of all contained aggregates or unions) 2235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// with a const-qualified type. 22444e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// 22544e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// \param Loc [in] [out] - A source location which *may* be filled 22644e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// in with the location of the expression making this a 22744e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// non-modifiable lvalue, if specified. 2285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum isModifiableLvalueResult { 2295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_Valid, 2305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_NotObjectType, 2315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_IncompleteVoidType, 232fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff MLV_DuplicateVectorComponents, 2335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_InvalidExpression, 234ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner MLV_LValueCast, // Specialized form of MLV_InvalidExpression. 2355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_IncompleteType, 2365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_ConstQualified, 2374f6a7d7ead09b439216c32f2de806a998aeb222aSteve Naroff MLV_ArrayType, 2385daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian MLV_NotBlockQualified, 239ba8d2d684e74a20bef03828c21c991d222c7e9e5Fariborz Jahanian MLV_ReadonlyProperty, 24086f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor MLV_NoSetterProperty, 2412514a309204341798f96912ce7a90841bea59727Fariborz Jahanian MLV_MemberFunction, 242e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian MLV_SubObjCPropertySetting, 243077f490d0a514dcc448475f33f799934252b85a7Fariborz Jahanian MLV_InvalidMessageExpression, 244e873fb74219f48407ae0b8fa083aa7f0b6ff1427Douglas Gregor MLV_ClassTemporary 2455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 24644e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx, 24744e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar SourceLocation *Loc = 0) const; 2481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2492111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \brief The return type of classify(). Represents the C++0x expression 2502111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// taxonomy. 2512111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl class Classification { 2522111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl public: 2532111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \brief The various classification results. Most of these mean prvalue. 2542111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl enum Kinds { 2552111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_LValue, 2562111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_XValue, 2572111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_Function, // Functions cannot be lvalues in C. 2582111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_Void, // Void cannot be an lvalue in C. 2591c860d5640e8eebb11a5d515a761242b66761b0bPeter Collingbourne CL_AddressableVoid, // Void expression whose address can be taken in C. 2602111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_DuplicateVectorComponents, // A vector shuffle with dupes. 2612111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_MemberFunction, // An expression referring to a member function 2622111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_SubObjCPropertySetting, 2632111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_ClassTemporary, // A prvalue of class type 264077f490d0a514dcc448475f33f799934252b85a7Fariborz Jahanian CL_ObjCMessageRValue, // ObjC message is an rvalue 2652111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_PRValue // A prvalue for any other reason, of any other type 2662111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl }; 2672111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \brief The results of modification testing. 2682111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl enum ModifiableType { 2692111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_Untested, // testModifiable was false. 2702111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_Modifiable, 2712111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_RValue, // Not modifiable because it's an rvalue 2722111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_Function, // Not modifiable because it's a function; C++ only 2732111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_LValueCast, // Same as CM_RValue, but indicates GCC cast-as-lvalue ext 2742111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_NotBlockQualified, // Not captured in the closure 2752111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_NoSetterProperty,// Implicit assignment to ObjC property without setter 2762111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_ConstQualified, 2772111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_ArrayType, 2782111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_IncompleteType 2792111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl }; 2802111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2812111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl private: 2822111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl friend class Expr; 2832111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2842111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl unsigned short Kind; 2852111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl unsigned short Modifiable; 2862111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2872111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl explicit Classification(Kinds k, ModifiableType m) 2882111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl : Kind(k), Modifiable(m) 2892111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl {} 2902111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2912111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl public: 2922111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification() {} 2932111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2942111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Kinds getKind() const { return static_cast<Kinds>(Kind); } 2952111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl ModifiableType getModifiable() const { 2962111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl assert(Modifiable != CM_Untested && "Did not test for modifiability."); 2972111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl return static_cast<ModifiableType>(Modifiable); 2982111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl } 2992111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isLValue() const { return Kind == CL_LValue; } 3002111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isXValue() const { return Kind == CL_XValue; } 3012111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isGLValue() const { return Kind <= CL_XValue; } 3022111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isPRValue() const { return Kind >= CL_Function; } 3032111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isRValue() const { return Kind >= CL_XValue; } 3042111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isModifiable() const { return getModifiable() == CM_Modifiable; } 3052c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor 3062c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor /// \brief Create a simple, modifiably lvalue 3072c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor static Classification makeSimpleLValue() { 3082c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor return Classification(CL_LValue, CM_Modifiable); 3092c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor } 3102c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor 3112111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl }; 312369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// \brief Classify - Classify this expression according to the C++0x 3132111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// expression taxonomy. 3142111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// 3152111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// C++0x defines ([basic.lval]) a new taxonomy of expressions to replace the 3162111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// old lvalue vs rvalue. This function determines the type of expression this 3172111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// is. There are three expression types: 3182111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// - lvalues are classical lvalues as in C++03. 3192111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// - prvalues are equivalent to rvalues in C++03. 3202111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// - xvalues are expressions yielding unnamed rvalue references, e.g. a 3212111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// function returning an rvalue reference. 3222111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// lvalues and xvalues are collectively referred to as glvalues, while 3232111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// prvalues and xvalues together form rvalues. 3242111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification Classify(ASTContext &Ctx) const { 3252111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl return ClassifyImpl(Ctx, 0); 3262111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl } 3272111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 328369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// \brief ClassifyModifiable - Classify this expression according to the 3292111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// C++0x expression taxonomy, and see if it is valid on the left side 3302111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// of an assignment. 3312111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// 3322111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// This function extends classify in that it also tests whether the 3332111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// expression is modifiable (C99 6.3.2.1p1). 3342111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \param Loc A source location that might be filled with a relevant location 3352111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// if the expression is not modifiable. 3362111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification ClassifyModifiable(ASTContext &Ctx, SourceLocation &Loc) const{ 3372111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl return ClassifyImpl(Ctx, &Loc); 3382111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl } 3392111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 340f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// getValueKindForType - Given a formal return or parameter type, 341f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// give its value kind. 342f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall static ExprValueKind getValueKindForType(QualType T) { 343f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall if (const ReferenceType *RT = T->getAs<ReferenceType>()) 3440943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall return (isa<LValueReferenceType>(RT) 3450943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall ? VK_LValue 3460943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall : (RT->getPointeeType()->isFunctionType() 3470943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall ? VK_LValue : VK_XValue)); 348f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall return VK_RValue; 349f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall } 350f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 351f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// getValueKind - The value kind that this expression produces. 352f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind getValueKind() const { 353f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall return static_cast<ExprValueKind>(ExprBits.ValueKind); 354f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall } 355f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 356f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// getObjectKind - The object kind that this expression produces. 357f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// Object kinds are meaningful only for expressions that yield an 358f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// l-value or x-value. 359f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprObjectKind getObjectKind() const { 360f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall return static_cast<ExprObjectKind>(ExprBits.ObjectKind); 361f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall } 362f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 36356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall bool isOrdinaryOrBitFieldObject() const { 36456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall ExprObjectKind OK = getObjectKind(); 36556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return (OK == OK_Ordinary || OK == OK_BitField); 36656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 36756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 368f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// setValueKind - Set the value kind produced by this expression. 369f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall void setValueKind(ExprValueKind Cat) { ExprBits.ValueKind = Cat; } 370f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 371f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// setObjectKind - Set the object kind produced by this expression. 372f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall void setObjectKind(ExprObjectKind Cat) { ExprBits.ObjectKind = Cat; } 373f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 3742111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redlprivate: 3752111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification ClassifyImpl(ASTContext &Ctx, SourceLocation *Loc) const; 3762111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 3772111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redlpublic: 3782111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 37933bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor /// \brief If this expression refers to a bit-field, retrieve the 38033bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor /// declaration of that bit-field. 38133bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor FieldDecl *getBitField(); 3825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 38338d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson const FieldDecl *getBitField() const { 38438d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson return const_cast<Expr*>(this)->getBitField(); 38538d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson } 3861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 387f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall /// \brief If this expression is an l-value for an Objective C 388f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall /// property, find the underlying property reference expression. 389f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall const ObjCPropertyRefExpr *getObjCProperty() const; 390f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall 391093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson /// \brief Returns whether this expression refers to a vector element. 392093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson bool refersToVectorElement() const; 3934919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall 3944919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall /// \brief Returns whether this expression has a placeholder type. 3954919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall bool hasPlaceholderType() const { 3964919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall return getType()->isPlaceholderType(); 3974919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall } 3984919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall 3994919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall /// \brief Returns whether this expression has a specific placeholder type. 4004919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall bool hasPlaceholderType(BuiltinType::Kind K) const { 40185def357129b6cdfd69a66ad0e6994506418a2a9John McCall assert(BuiltinType::isPlaceholderTypeKind(K)); 4024919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall if (const BuiltinType *BT = dyn_cast<BuiltinType>(getType())) 4034919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall return BT->getKind() == K; 4044919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall return false; 4054919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall } 406c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 4072b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// isKnownToHaveBooleanValue - Return true if this is an integer expression 4082b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// that is known to return 0 or 1. This happens for _Bool/bool expressions 4092b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// but also int expressions which are produced by things like comparisons in 4102b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// C. 4112b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner bool isKnownToHaveBooleanValue() const; 412c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 4135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isIntegerConstantExpr - Return true if this expression is a valid integer 4145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// constant expression, and, if so, return its value in Result. If not a 4155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// valid i-c-e, return false and fill in Loc (if specified) with the location 4165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// of the invalid expression. 417590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx, 418590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner SourceLocation *Loc = 0, 4195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isEvaluated = true) const; 420590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const { 4218070a8497c0fb3e6f70a557f788405d8945b1208Daniel Dunbar llvm::APSInt X; 422590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner return isIntegerConstantExpr(X, Ctx, Loc); 4235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 424c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman /// isConstantInitializer - Returns true if this expression is a constant 425c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman /// initializer, which can be emitted at compile-time. 4264204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall bool isConstantInitializer(ASTContext &Ctx, bool ForRef) const; 4271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4281e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith /// EvalStatus is a struct with detailed info about an evaluation in progress. 4291e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith struct EvalStatus { 43094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// HasSideEffects - Whether the evaluated expression has side effects. 43194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// For example, (f() && 0) can be folded, but it still has side effects. 43294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson bool HasSideEffects; 4331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 43494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// Diag - If the expression is unfoldable, then Diag contains a note 43594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// diagnostic indicating why it's not foldable. DiagLoc indicates a caret 43694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// position for the error, and DiagExpr is the expression that caused 43794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// the error. 43894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// If the expression is foldable, but not an integer constant expression, 43994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// Diag contains a note diagnostic that describes why it isn't an integer 44094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// constant expression. If the expression *is* an integer constant 44194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// expression, then Diag will be zero. 44294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson unsigned Diag; 44394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson const Expr *DiagExpr; 44494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson SourceLocation DiagLoc; 4451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4461e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith EvalStatus() : HasSideEffects(false), Diag(0), DiagExpr(0) {} 447e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara 448e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara // hasSideEffects - Return true if the evaluated expression has 449e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara // side effects. 450e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara bool hasSideEffects() const { 451e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara return HasSideEffects; 452e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara } 45394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson }; 45494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson 4551e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith /// EvalResult is a struct with detailed info about an evaluated expression. 4561e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith struct EvalResult : EvalStatus { 4571e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith /// Val - This is the value the expression can be folded to. 4581e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith APValue Val; 4591e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith 4601e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith // isGlobalLValue - Return true if the evaluated lvalue expression 4611e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith // is global. 4621e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith bool isGlobalLValue() const; 4631e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith }; 4641e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith 4656ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner /// Evaluate - Return true if this is a constant which we can fold using 466019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner /// any crazy technique (that has nothing to do with language standards) that 467019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner /// we want to. If this function returns true, it returns the folded constant 468019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner /// in Result. 4694ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool Evaluate(EvalResult &Result, const ASTContext &Ctx) const; 4705b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson 471cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall /// EvaluateAsBooleanCondition - Return true if this is a constant 472cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall /// which we we can fold and convert to a boolean condition using 473a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith /// any crazy technique that we want to, even if the expression has 474a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith /// side-effects. 4754ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool EvaluateAsBooleanCondition(bool &Result, const ASTContext &Ctx) const; 476cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall 477a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith /// EvaluateAsInt - Return true if this is a constant which we can fold and 478a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith /// convert to an integer using any crazy technique that we want to. 479a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith bool EvaluateAsInt(llvm::APSInt &Result, const ASTContext &Ctx) const; 480a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith 4816ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner /// isEvaluatable - Call Evaluate to see if this expression can be constant 48245b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner /// folded, but discard the result. 4834ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool isEvaluatable(const ASTContext &Ctx) const; 484c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson 4856ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian /// HasSideEffects - This routine returns true for all those expressions 486138d6a6890c171068ac60430431eaadb3fcef9abGabor Greif /// which must be evaluated each time and must not be optimized away 4876ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian /// or evaluated at compile time. Example is a function call, volatile 4886ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian /// variable read. 4894ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool HasSideEffects(const ASTContext &Ctx) const; 490c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 491a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith /// EvaluateKnownConstInt - Call Evaluate and return the folded integer. This 49251fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson /// must be called on an expression that constant folds to an integer. 493a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx) const; 49451fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson 495b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman /// EvaluateAsLValue - Evaluate an expression to see if it's a lvalue 496b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman /// with link time known address. 4974ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx) const; 4981b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson 499e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara /// EvaluateAsLValue - Evaluate an expression to see if it's a lvalue. 5004ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool EvaluateAsAnyLValue(EvalResult &Result, const ASTContext &Ctx) const; 501e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara 50282214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Enumeration used to describe the kind of Null pointer constant 50382214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// returned from \c isNullPointerConstant(). 50482214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth enum NullPointerConstantKind { 50582214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Expression is not a Null pointer constant. 50682214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NPCK_NotNull = 0, 50782214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 50882214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Expression is a Null pointer constant built from a zero integer. 50982214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NPCK_ZeroInteger, 51082214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 51182214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Expression is a C++0X nullptr. 51282214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NPCK_CXX0X_nullptr, 51382214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 51482214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Expression is a GNU-style __null constant. 51582214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NPCK_GNUNull 51682214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth }; 51782214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 518ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Enumeration used to describe how \c isNullPointerConstant() 519ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// should cope with value-dependent expressions. 520ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor enum NullPointerConstantValueDependence { 521ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that the expression should never be value-dependent. 522ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_NeverValueDependent = 0, 523c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 524ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that a value-dependent expression of integral or 525ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// dependent type should be considered a null pointer constant. 526ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_ValueDependentIsNull, 527c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 528ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that a value-dependent expression should be considered 529ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// to never be a null pointer constant. 530ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_ValueDependentIsNotNull 531ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor }; 532c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 53382214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to 53482214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// a Null pointer constant. The return value can further distinguish the 53582214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// kind of NULL pointer constant that was detected. 53682214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NullPointerConstantKind isNullPointerConstant( 53782214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth ASTContext &Ctx, 53882214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NullPointerConstantValueDependence NPC) const; 539efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson 54044baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian /// isOBJCGCCandidate - Return true if this expression may be used in a read/ 5411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// write barrier. 542102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian bool isOBJCGCCandidate(ASTContext &Ctx) const; 5431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 54411ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis /// \brief Returns true if this expression is a bound member function. 54511ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis bool isBoundMemberFunction(ASTContext &Ctx) const; 54611ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis 547864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// \brief Given an expression of bound-member type, find the type 548864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// of the member. Returns null if this is an *overloaded* bound 549864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// member expression. 550864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall static QualType findBoundMemberType(const Expr *expr); 551864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 552369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// \brief Result type of CanThrow(). 553369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl enum CanThrowResult { 554369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CT_Cannot, 555369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CT_Dependent, 556369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CT_Can 557369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl }; 558369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// \brief Test if this expression, if evaluated, might throw, according to 559369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// the rules of C++ [expr.unary.noexcept]. 560369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CanThrowResult CanThrow(ASTContext &C) const; 561369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 56291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall /// IgnoreImpCasts - Skip past any implicit casts which might 56391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall /// surround this expression. Only skips ImplicitCastExprs. 56491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall Expr *IgnoreImpCasts(); 56591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 5667e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall /// IgnoreImplicit - Skip past any implicit AST nodes which might 5677e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall /// surround this expression. 5687e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall Expr *IgnoreImplicit() { return cast<Expr>(Stmt::IgnoreImplicit()); } 5697e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall 5704e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// IgnoreParens - Ignore parentheses. If this Expr is a ParenExpr, return 5711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// its subexpression. If that subexpression is also a ParenExpr, 5724e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// then this method recursively returns its subexpression, and so forth. 5734e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// Otherwise, the method returns the current Expr. 5742b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner Expr *IgnoreParens(); 57556f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner 57656f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner /// IgnoreParenCasts - Ignore parentheses and casts. Strip off any ParenExpr 57727c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor /// or CastExprs, returning their operand. 57856f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner Expr *IgnoreParenCasts(); 5791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5802fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall /// IgnoreParenImpCasts - Ignore parentheses and implicit casts. Strip off any 5812fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall /// ParenExpr or ImplicitCastExprs, returning their operand. 5822fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall Expr *IgnoreParenImpCasts(); 5832fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall 5842f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg /// IgnoreConversionOperator - Ignore conversion operator. If this Expr is a 5852f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg /// call to a conversion operator, return the argument. 5862f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg Expr *IgnoreConversionOperator(); 5872f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg 5882f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg const Expr *IgnoreConversionOperator() const { 5892f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg return const_cast<Expr*>(this)->IgnoreConversionOperator(); 5902f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg } 5912f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg 5924d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek const Expr *IgnoreParenImpCasts() const { 5934d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek return const_cast<Expr*>(this)->IgnoreParenImpCasts(); 5944d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek } 595f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall 596f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall /// Ignore parentheses and lvalue casts. Strip off any ParenExpr and 597f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall /// CastExprs that represent lvalue casts, returning their operand. 598f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall Expr *IgnoreParenLValueCasts(); 599f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall 600f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall const Expr *IgnoreParenLValueCasts() const { 601f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall return const_cast<Expr*>(this)->IgnoreParenLValueCasts(); 602f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 6034d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek 604ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the 605ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// value (including ptr->int casts of the same size). Strip off any 606ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// ParenExpr or CastExprs, returning their operand. 607ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Expr *IgnoreParenNoopCasts(ASTContext &Ctx); 6081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6096eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// \brief Determine whether this expression is a default function argument. 6106eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// 6116eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// Default arguments are implicitly generated in the abstract syntax tree 612c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// by semantic analysis for function calls, object constructions, etc. in 6136eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// C++. Default arguments are represented by \c CXXDefaultArgExpr nodes; 6146eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// this routine also looks through any implicit casts to determine whether 6156eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// the expression is a default argument. 6166eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor bool isDefaultArgument() const; 617c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 618558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall /// \brief Determine whether the result of this expression is a 619558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall /// temporary object of the given class type. 620558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const; 6212f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 62275e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor /// \brief Whether this expression is an implicit reference to 'this' in C++. 62375e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor bool isImplicitCXXThis() const; 62491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 62591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall const Expr *IgnoreImpCasts() const { 62691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall return const_cast<Expr*>(this)->IgnoreImpCasts(); 62791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall } 6282b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner const Expr *IgnoreParens() const { 6294e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek return const_cast<Expr*>(this)->IgnoreParens(); 6304e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek } 63156f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner const Expr *IgnoreParenCasts() const { 63256f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner return const_cast<Expr*>(this)->IgnoreParenCasts(); 63356f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner } 634ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner const Expr *IgnoreParenNoopCasts(ASTContext &Ctx) const { 635ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner return const_cast<Expr*>(this)->IgnoreParenNoopCasts(Ctx); 636ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 6371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 638898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs); 639898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs); 640898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 6411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 6425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() >= firstExprConstant && 6431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump T->getStmtClass() <= lastExprConstant; 6445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Expr *) { return true; } 6465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 6475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6495549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek//===----------------------------------------------------------------------===// 6505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Primary Expressions. 6515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 6525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 65356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// OpaqueValueExpr - An expression referring to an opaque object of a 65456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// fixed type and value class. These don't correspond to concrete 65556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// syntax; instead they're used to express operations (usually copy 65656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// operations) on values whose source is generally obvious from 65756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// context. 65856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass OpaqueValueExpr : public Expr { 65956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall friend class ASTStmtReader; 66056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *SourceExpr; 66156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation Loc; 66256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 66356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallpublic: 66456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValueExpr(SourceLocation Loc, QualType T, ExprValueKind VK, 66556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall ExprObjectKind OK = OK_Ordinary) 66656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : Expr(OpaqueValueExprClass, T, VK, OK, 667561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor T->isDependentType(), T->isDependentType(), 668561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor T->isInstantiationDependentType(), 669561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false), 67056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceExpr(0), Loc(Loc) { 67156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 67256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 67356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// Given an expression which invokes a copy constructor --- i.e. a 67456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// CXXConstructExpr, possibly wrapped in an ExprWithCleanups --- 67556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// find the OpaqueValueExpr that's the source of the construction. 67656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static const OpaqueValueExpr *findInCopyConstruct(const Expr *expr); 67756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 67856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall explicit OpaqueValueExpr(EmptyShell Empty) 67956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : Expr(OpaqueValueExprClass, Empty) { } 68056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 68156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief Retrieve the location of this expression. 68256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation getLocation() const { return Loc; } 68356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 68456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceRange getSourceRange() const { 68556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (SourceExpr) return SourceExpr->getSourceRange(); 68656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return Loc; 68756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 68856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation getExprLoc() const { 68956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (SourceExpr) return SourceExpr->getExprLoc(); 69056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return Loc; 69156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 69256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 69356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall child_range children() { return child_range(); } 69456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 69556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// The source expression of an opaque value expression is the 69656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// expression which originally generated the value. This is 69756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// provided as a convenience for analyses that don't wish to 69856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// precisely model the execution behavior of the program. 69956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// 70056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// The source expression is typically set when building the 70156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// expression which binds the opaque value expression in the first 70256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// place. 70356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getSourceExpr() const { return SourceExpr; } 70456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall void setSourceExpr(Expr *e) { SourceExpr = e; } 70556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 70656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const Stmt *T) { 70756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return T->getStmtClass() == OpaqueValueExprClass; 70856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 70956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const OpaqueValueExpr *) { return true; } 71056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall}; 71156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 712cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// \brief A reference to a declared variable, function, enum, etc. 713cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// [C99 6.5.1p2] 714cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// 715cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// This encodes all the information about how a declaration is referenced 716cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// within an expression. 717cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// 718cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// There are several optional constructs attached to DeclRefExprs only when 719cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// they apply in order to conserve memory. These are laid out past the end of 720cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// the object, and flags in the DeclRefExprBitfield track whether they exist: 721cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// 722cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// DeclRefExprBits.HasQualifier: 723cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// Specifies when this declaration reference expression has a C++ 724cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// nested-name-specifier. 7253aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth/// DeclRefExprBits.HasFoundDecl: 7263aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth/// Specifies when this declaration reference expression has a record of 7273aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth/// a NamedDecl (different from the referenced ValueDecl) which was found 7283aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth/// during name lookup and/or overload resolution. 729cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// DeclRefExprBits.HasExplicitTemplateArgs: 730cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// Specifies when this declaration reference expression has an explicit 731cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// C++ template argument list. 7325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclRefExpr : public Expr { 733cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth /// \brief The declaration that we are referencing. 734cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth ValueDecl *D; 7352577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 736cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth /// \brief The location of the declaration name itself. 7375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 7389e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis 739cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth /// \brief Provides source/type location info for the declaration name 740cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth /// embedded in D. 7412577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameLoc DNLoc; 7422577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 7436857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// \brief Helper to retrieve the optional NestedNameSpecifierLoc. 7446857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth NestedNameSpecifierLoc &getInternalQualifierLoc() { 7457e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth assert(hasQualifier()); 7466857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth return *reinterpret_cast<NestedNameSpecifierLoc *>(this + 1); 747a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 748cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth 7496857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// \brief Helper to retrieve the optional NestedNameSpecifierLoc. 7506857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth const NestedNameSpecifierLoc &getInternalQualifierLoc() const { 7516857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth return const_cast<DeclRefExpr *>(this)->getInternalQualifierLoc(); 752a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 753096832c5ed5b9106fa177ebc148489760c3bc496John McCall 7543aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// \brief Test whether there is a distinct FoundDecl attached to the end of 7553aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// this DRE. 7563aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth bool hasFoundDecl() const { return DeclRefExprBits.HasFoundDecl; } 7573aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 7583aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// \brief Helper to retrieve the optional NamedDecl through which this 7593aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// reference occured. 7603aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *&getInternalFoundDecl() { 7613aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth assert(hasFoundDecl()); 7623aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth if (hasQualifier()) 7633aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return *reinterpret_cast<NamedDecl **>(&getInternalQualifierLoc() + 1); 7643aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return *reinterpret_cast<NamedDecl **>(this + 1); 7653aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth } 7663aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 7673aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// \brief Helper to retrieve the optional NamedDecl through which this 7683aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// reference occured. 7693aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *getInternalFoundDecl() const { 7703aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return const_cast<DeclRefExpr *>(this)->getInternalFoundDecl(); 7713aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth } 7723aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 7737e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth DeclRefExpr(NestedNameSpecifierLoc QualifierLoc, 7742577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ValueDecl *D, const DeclarationNameInfo &NameInfo, 7753aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *FoundD, 7762577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const TemplateArgumentListInfo *TemplateArgs, 777f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK); 7782577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 779663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis /// \brief Construct an empty declaration reference expression. 780663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis explicit DeclRefExpr(EmptyShell Empty) 781663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis : Expr(DeclRefExprClass, Empty) { } 7827e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 7830da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor /// \brief Computes the type- and value-dependence flags for this 7840da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor /// declaration reference expression. 7850da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor void computeDependence(); 7869e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis 7875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 7885b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor DeclRefExpr(ValueDecl *D, QualType T, ExprValueKind VK, SourceLocation L, 7895b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor const DeclarationNameLoc &LocInfo = DeclarationNameLoc()) 790561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Expr(DeclRefExprClass, T, VK, OK_Ordinary, false, false, false, false), 7915b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor D(D), Loc(L), DNLoc(LocInfo) { 792cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth DeclRefExprBits.HasQualifier = 0; 793cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth DeclRefExprBits.HasExplicitTemplateArgs = 0; 7943aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth DeclRefExprBits.HasFoundDecl = 0; 7957cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara DeclRefExprBits.HadMultipleCandidates = 0; 7960da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor computeDependence(); 7970da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor } 7981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 799a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor static DeclRefExpr *Create(ASTContext &Context, 80040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 801dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *D, 802a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation NameLoc, 803f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK, 8043aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *FoundD = 0, 8050da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor const TemplateArgumentListInfo *TemplateArgs = 0); 806663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis 8072577743c5650c646fb705df01403707e94f2df04Abramo Bagnara static DeclRefExpr *Create(ASTContext &Context, 80840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 8092577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ValueDecl *D, 8102577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 811f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK, 8123aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *FoundD = 0, 8132577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const TemplateArgumentListInfo *TemplateArgs = 0); 8142577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 815663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis /// \brief Construct an empty declaration reference expression. 816663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis static DeclRefExpr *CreateEmpty(ASTContext &Context, 8173aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth bool HasQualifier, 8183aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth bool HasFoundDecl, 819def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor bool HasExplicitTemplateArgs, 820def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor unsigned NumTemplateArgs); 8217e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 822cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth ValueDecl *getDecl() { return D; } 823cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth const ValueDecl *getDecl() const { return D; } 824cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth void setDecl(ValueDecl *NewD) { D = NewD; } 825904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor 8262577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo getNameInfo() const { 8272577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(getDecl()->getDeclName(), Loc, DNLoc); 8282577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 8292577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 8309e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis SourceLocation getLocation() const { return Loc; } 8310b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 83263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const; 8331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 834a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Determine whether this declaration reference was preceded by a 835a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// C++ nested-name-specifier, e.g., \c N::foo. 836cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth bool hasQualifier() const { return DeclRefExprBits.HasQualifier; } 8377e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 8387e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth /// \brief If the name was qualified, retrieves the nested-name-specifier 839a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// that precedes the name. Otherwise, returns NULL. 840a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NestedNameSpecifier *getQualifier() const { 841a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (!hasQualifier()) 842a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 8437e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 8446857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth return getInternalQualifierLoc().getNestedNameSpecifier(); 845a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 84640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor 8477e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth /// \brief If the name was qualified, retrieves the nested-name-specifier 84840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor /// that precedes the name, with source-location information. 84940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc getQualifierLoc() const { 85040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (!hasQualifier()) 85140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return NestedNameSpecifierLoc(); 8527e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 8536857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth return getInternalQualifierLoc(); 85440d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor } 85540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor 8563aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// \brief Get the NamedDecl through which this reference occured. 8573aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// 8583aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// This Decl may be different from the ValueDecl actually referred to in the 8593aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// presence of using declarations, etc. It always returns non-NULL, and may 8603aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// simple return the ValueDecl when appropriate. 8613aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *getFoundDecl() { 8623aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return hasFoundDecl() ? getInternalFoundDecl() : D; 8633aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth } 8643aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 8653aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// \brief Get the NamedDecl through which this reference occurred. 8663aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// See non-const variant. 8673aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth const NamedDecl *getFoundDecl() const { 8683aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return hasFoundDecl() ? getInternalFoundDecl() : D; 8693aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth } 8703aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 8717e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth /// \brief Determines whether this declaration reference was followed by an 8727e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth /// explict template argument list. 873096832c5ed5b9106fa177ebc148489760c3bc496John McCall bool hasExplicitTemplateArgs() const { 874cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth return DeclRefExprBits.HasExplicitTemplateArgs; 875096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 8767e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 877096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that followed the 878096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// member template name. 879b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 880096832c5ed5b9106fa177ebc148489760c3bc496John McCall assert(hasExplicitTemplateArgs()); 8813aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth if (hasFoundDecl()) 882b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis return *reinterpret_cast<ASTTemplateArgumentListInfo *>( 8833aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth &getInternalFoundDecl() + 1); 8843aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 8853aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth if (hasQualifier()) 886b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis return *reinterpret_cast<ASTTemplateArgumentListInfo *>( 8873aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth &getInternalQualifierLoc() + 1); 8887e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 889b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis return *reinterpret_cast<ASTTemplateArgumentListInfo *>(this + 1); 890096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 8917e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 892096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that followed the 893096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// member template name. 894b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 895096832c5ed5b9106fa177ebc148489760c3bc496John McCall return const_cast<DeclRefExpr *>(this)->getExplicitTemplateArgs(); 896a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 897d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 898096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieves the optional explicit template arguments. 899096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// This points to the same data as getExplicitTemplateArgs(), but 900096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// returns null if there are no explicit template arguments. 901b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis const ASTTemplateArgumentListInfo *getExplicitTemplateArgsOpt() const { 902096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) return 0; 903096832c5ed5b9106fa177ebc148489760c3bc496John McCall return &getExplicitTemplateArgs(); 904096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 9057e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 906d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// \brief Copies the template arguments (if present) into the given 907d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// structure. 908d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 909096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (hasExplicitTemplateArgs()) 910096832c5ed5b9106fa177ebc148489760c3bc496John McCall getExplicitTemplateArgs().copyInto(List); 911d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall } 9127e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 913a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the location of the left angle bracket following the 914a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// member name ('<'), if any. 915a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation getLAngleLoc() const { 916096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 917a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return SourceLocation(); 9187e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 919096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().LAngleLoc; 920a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 9217e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 922a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the template arguments provided as part of this 923a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template-id. 924833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc *getTemplateArgs() const { 925096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 926a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 9277e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 928096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().getTemplateArgs(); 929a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 9307e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 931a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the number of template arguments provided as part of this 932a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template-id. 933a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor unsigned getNumTemplateArgs() const { 934096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 935a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 9367e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 937096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().NumTemplateArgs; 938a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 9397e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 940a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the location of the right angle bracket following the 941a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template arguments ('>'). 942a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation getRAngleLoc() const { 943096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 944a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return SourceLocation(); 9457e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 946096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().RAngleLoc; 947a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 9487e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 9497cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// \brief Returns true if this expression refers to a function that 9507cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// was resolved from an overloaded set having size greater than 1. 9517cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool hadMultipleCandidates() const { 9527cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara return DeclRefExprBits.HadMultipleCandidates; 9537cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara } 9547cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// \brief Sets the flag telling whether this expression refers to 9557cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// a function that was resolved from an overloaded set having size 9567cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// greater than 1. 9577cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara void setHadMultipleCandidates(bool V = true) { 9587cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara DeclRefExprBits.HadMultipleCandidates = V; 9597cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara } 9607cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara 9611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 96299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor return T->getStmtClass() == DeclRefExprClass; 9635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const DeclRefExpr *) { return true; } 9651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 96677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 96763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 9687e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 96960adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 9703397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl friend class ASTStmtWriter; 9715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 9725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 973d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner/// PredefinedExpr - [C99 6.4.2.2] - A predefined identifier such as __func__. 974d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattnerclass PredefinedExpr : public Expr { 975227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic: 976227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson enum IdentType { 977227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson Func, 978227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson Function, 979848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson PrettyFunction, 980848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson /// PrettyFunctionNoVirtual - The same as PrettyFunction, except that the 981848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson /// 'virtual' keyword is omitted for virtual member functions. 982848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson PrettyFunctionNoVirtual 983227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson }; 9841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 985227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonprivate: 986227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson SourceLocation Loc; 987227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson IdentType Type; 988227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic: 9891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump PredefinedExpr(SourceLocation l, QualType type, IdentType IT) 990f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(PredefinedExprClass, type, VK_LValue, OK_Ordinary, 991bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor type->isDependentType(), type->isDependentType(), 992561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor type->isInstantiationDependentType(), 993bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 994f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Loc(l), Type(IT) {} 9951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 99617fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor /// \brief Construct an empty predefined expression. 9971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit PredefinedExpr(EmptyShell Empty) 99817fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor : Expr(PredefinedExprClass, Empty) { } 99917fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 1000227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson IdentType getIdentType() const { return Type; } 100117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setIdentType(IdentType IT) { Type = IT; } 100217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 100317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor SourceLocation getLocation() const { return Loc; } 100417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 100517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 1006848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson static std::string ComputeName(IdentType IT, const Decl *CurrentDecl); 10073a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 100863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 1009227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 10101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 10111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == PredefinedExprClass; 1012227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson } 1013d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner static bool classof(const PredefinedExpr *) { return true; } 10141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 101577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 101663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 1017227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson}; 1018227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 10199996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// \brief Used by IntegerLiteral/FloatingLiteral to store the numeric without 10209996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// leaking memory. 10219996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// 10229996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// For large floats/integers, APFloat/APInt will allocate memory from the heap 10239996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// to represent these numbers. Unfortunately, when we use a BumpPtrAllocator 10249996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// to allocate IntegerLiteral/FloatingLiteral nodes the memory associated with 10259996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// the APFloat/APInt values will never get freed. APNumericStorage uses 10269996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// ASTContext's allocator for memory allocation. 10279996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisclass APNumericStorage { 10289996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis unsigned BitWidth; 10299996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis union { 10309996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis uint64_t VAL; ///< Used to store the <= 64 bits integer value. 10319996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis uint64_t *pVal; ///< Used to store the >64 bits integer value. 10329996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis }; 10339996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10349996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis bool hasAllocation() const { return llvm::APInt::getNumWords(BitWidth) > 1; } 10359996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10369996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APNumericStorage(const APNumericStorage&); // do not implement 10379996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APNumericStorage& operator=(const APNumericStorage&); // do not implement 10389996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10399996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisprotected: 10409996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APNumericStorage() : BitWidth(0), VAL(0) { } 10419996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10429996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APInt getIntValue() const { 10439996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis unsigned NumWords = llvm::APInt::getNumWords(BitWidth); 10449996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis if (NumWords > 1) 10459996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return llvm::APInt(BitWidth, NumWords, pVal); 10469996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis else 10479996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return llvm::APInt(BitWidth, VAL); 10489996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 10499996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setIntValue(ASTContext &C, const llvm::APInt &Val); 10509996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis}; 10519996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10529996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisclass APIntStorage : public APNumericStorage { 10539996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidispublic: 10549996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APInt getValue() const { return getIntValue(); } 10559996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setValue(ASTContext &C, const llvm::APInt &Val) { setIntValue(C, Val); } 10569996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis}; 10579996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10589996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisclass APFloatStorage : public APNumericStorage { 10599996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidispublic: 10609996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APFloat getValue() const { return llvm::APFloat(getIntValue()); } 10619996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setValue(ASTContext &C, const llvm::APFloat &Val) { 10629996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis setIntValue(C, Val.bitcastToAPInt()); 10639996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 10649996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis}; 10659996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IntegerLiteral : public Expr { 10679996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APIntStorage Num; 10685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 10699996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10709996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis /// \brief Construct an empty integer literal. 10719996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis explicit IntegerLiteral(EmptyShell Empty) 10729996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis : Expr(IntegerLiteralClass, Empty) { } 10739996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 10751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy, 10765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // or UnsignedLongLongTy 10779996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis IntegerLiteral(ASTContext &C, const llvm::APInt &V, 10789996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis QualType type, SourceLocation l) 1079bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(IntegerLiteralClass, type, VK_RValue, OK_Ordinary, false, false, 1080561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false), 1081f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Loc(l) { 10825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(type->isIntegerType() && "Illegal type in IntegerLiteral"); 10831dd986dff9ddfbec687975700770bb377988e9edRichard Trieu assert(V.getBitWidth() == C.getIntWidth(type) && 10841dd986dff9ddfbec687975700770bb377988e9edRichard Trieu "Integer type is not the correct size for constant."); 10859996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis setValue(C, V); 10865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1087a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson 10881dd986dff9ddfbec687975700770bb377988e9edRichard Trieu /// \brief Returns a new integer literal with value 'V' and type 'type'. 10891dd986dff9ddfbec687975700770bb377988e9edRichard Trieu /// \param type - either IntTy, LongTy, LongLongTy, UnsignedIntTy, 10901dd986dff9ddfbec687975700770bb377988e9edRichard Trieu /// UnsignedLongTy, or UnsignedLongLongTy which should match the size of V 10911dd986dff9ddfbec687975700770bb377988e9edRichard Trieu /// \param V - the value that the returned integer literal contains. 10929996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis static IntegerLiteral *Create(ASTContext &C, const llvm::APInt &V, 10939996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis QualType type, SourceLocation l); 10941dd986dff9ddfbec687975700770bb377988e9edRichard Trieu /// \brief Returns a new empty integer literal. 10959996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis static IntegerLiteral *Create(ASTContext &C, EmptyShell Empty); 10960b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 10979996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APInt getValue() const { return Num.getValue(); } 109863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 10995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1100313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Retrieve the location of the literal. 1101313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getLocation() const { return Loc; } 1102313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 11039996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setValue(ASTContext &C, const llvm::APInt &Val) { Num.setValue(C, Val); } 11040b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation Location) { Loc = Location; } 11050b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 11061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 11071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == IntegerLiteralClass; 11085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const IntegerLiteral *) { return true; } 11101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 111177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 111263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 11135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CharacterLiteral : public Expr { 11165cee1195584fa8672253139c86e922daeda69b9eDouglas Gregorpublic: 11175cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor enum CharacterKind { 11185cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor Ascii, 11195cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor Wide, 11205cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor UTF16, 11215cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor UTF32 11225cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor }; 11235cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor 11245cee1195584fa8672253139c86e922daeda69b9eDouglas Gregorprivate: 11255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned Value; 11265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 11275cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor unsigned Kind : 2; 11285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 11295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // type should be IntTy 11305cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor CharacterLiteral(unsigned value, CharacterKind kind, QualType type, 11315cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor SourceLocation l) 1132bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(CharacterLiteralClass, type, VK_RValue, OK_Ordinary, false, false, 1133561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false), 11345cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor Value(value), Loc(l), Kind(kind) { 11355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11360b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 11370b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Construct an empty character literal. 11380b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { } 11390b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 1140018d8e0596dd57401eeddcf11ac84ff0a065fbbeChris Lattner SourceLocation getLocation() const { return Loc; } 11415cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor CharacterKind getKind() const { return static_cast<CharacterKind>(Kind); } 11421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 114363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 11441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getValue() const { return Value; } 11465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11470b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation Location) { Loc = Location; } 11485cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor void setKind(CharacterKind kind) { Kind = kind; } 11490b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setValue(unsigned Val) { Value = Val; } 11500b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 11511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 11521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CharacterLiteralClass; 11535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CharacterLiteral *) { return true; } 115577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 115677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 115763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 11585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FloatingLiteral : public Expr { 11619996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APFloatStorage Num; 1162720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek bool IsExact : 1; 11635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 11649996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 11659996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis FloatingLiteral(ASTContext &C, const llvm::APFloat &V, bool isexact, 1166720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek QualType Type, SourceLocation L) 1167bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(FloatingLiteralClass, Type, VK_RValue, OK_Ordinary, false, false, 1168561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false), 11699996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis IsExact(isexact), Loc(L) { 11709996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis setValue(C, V); 11719996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 11725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 117317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor /// \brief Construct an empty floating-point literal. 11741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit FloatingLiteral(EmptyShell Empty) 11759996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis : Expr(FloatingLiteralClass, Empty), IsExact(false) { } 117617fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 11779996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidispublic: 11789996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis static FloatingLiteral *Create(ASTContext &C, const llvm::APFloat &V, 11799996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis bool isexact, QualType Type, SourceLocation L); 11809996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis static FloatingLiteral *Create(ASTContext &C, EmptyShell Empty); 11819996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 11829996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APFloat getValue() const { return Num.getValue(); } 11839996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setValue(ASTContext &C, const llvm::APFloat &Val) { 11849996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis Num.setValue(C, Val); 11859996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 118617fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 1187720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek bool isExact() const { return IsExact; } 118817fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setExact(bool E) { IsExact = E; } 1189c9bec4bfea9090a08dd83a7b213f0c8adf8d78ecChris Lattner 1190da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// getValueAsApproximateDouble - This returns the value as an inaccurate 1191da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// double. Note that this may cause loss of precision, but is useful for 1192da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// debugging dumps, etc. 1193da8249e57f3badecf925571881fe57243935c6c1Chris Lattner double getValueAsApproximateDouble() const; 11941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 119517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor SourceLocation getLocation() const { return Loc; } 119617fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 119717fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 119863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 11995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 12011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == FloatingLiteralClass; 12025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const FloatingLiteral *) { return true; } 12041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 120577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 120663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 12075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 12085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12095d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// ImaginaryLiteral - We support imaginary integer and floating point literals, 12105d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// like "1.0i". We represent these as a wrapper around FloatingLiteral and 12115d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// IntegerLiteral classes. Instances of this class always have a Complex type 12125d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// whose element type matches the subexpression. 12135d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// 12145d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerclass ImaginaryLiteral : public Expr { 12155549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 12165d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerpublic: 12175d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner ImaginaryLiteral(Expr *val, QualType Ty) 1218bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(ImaginaryLiteralClass, Ty, VK_RValue, OK_Ordinary, false, false, 1219561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false), 1220f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Val(val) {} 12211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1222cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor /// \brief Build an empty imaginary literal. 12231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ImaginaryLiteral(EmptyShell Empty) 1224cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor : Expr(ImaginaryLiteralClass, Empty) { } 1225cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 12265549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 12275549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 1228cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 1229cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 123063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return Val->getSourceRange(); } 12311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 12321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ImaginaryLiteralClass; 12335d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner } 12345d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner static bool classof(const ImaginaryLiteral *) { return true; } 12351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12365d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner // Iterators 123763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Val, &Val+1); } 12385d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner}; 12395d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner 1240e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// StringLiteral - This represents a string literal expression, e.g. "foo" 1241e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// or L"bar" (wide strings). The actual string is returned by getStrData() 1242e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// is NOT null-terminated, and the length of the string is determined by 1243a7ad98ff0919d6a24ea7c46634ea29bea551c1a0Chris Lattner/// calling getByteLength(). The C type for a string is always a 1244c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// ConstantArrayType. In C++, the char type is const qualified, in C it is 1245c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// not. 1246690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// 1247690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// Note that strings in C can be formed by concatenation of multiple string 12488bea7c0ee44c71c817de7dc2be932b73bec90c9fChris Lattner/// literal pptokens in translation phase #6. This keeps track of the locations 1249690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// of each of these pieces. 1250c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// 1251c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// Strings in C can also be truncated and extended by assigning into arrays, 1252c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// e.g. with constructs like: 1253c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// char X[2] = "foobar"; 1254c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// In this case, getByteLength() will return 6, but the string literal will 1255c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// have type "char[2]". 12565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass StringLiteral : public Expr { 12575cee1195584fa8672253139c86e922daeda69b9eDouglas Gregorpublic: 12585cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor enum StringKind { 12595cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor Ascii, 12605cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor Wide, 12615cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor UTF8, 12625cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor UTF16, 12635cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor UTF32 12645cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor }; 12655cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor 12665cee1195584fa8672253139c86e922daeda69b9eDouglas Gregorprivate: 12673e2193ce5feb2feb092e5ae615e85148e06e9fd2Anders Carlsson friend class ASTStmtReader; 12683e2193ce5feb2feb092e5ae615e85148e06e9fd2Anders Carlsson 12695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *StrData; 12705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned ByteLength; 1271726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner unsigned NumConcatenated; 12725cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor unsigned Kind : 3; 12735cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor bool IsPascal : 1; 1274726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner SourceLocation TokLocs[1]; 12752085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner 1276f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall StringLiteral(QualType Ty) : 1277561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Expr(StringLiteralClass, Ty, VK_LValue, OK_Ordinary, false, false, false, 1278561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false) {} 12791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 12812085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// This is the "fully general" constructor that allows representation of 12822085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// strings formed from multiple concatenated tokens. 12835cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor static StringLiteral *Create(ASTContext &C, StringRef Str, StringKind Kind, 128465aa6885818d4b4eea2e5a9d12085b2398148662Jay Foad bool Pascal, QualType Ty, 1285a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson const SourceLocation *Loc, unsigned NumStrs); 12862085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner 12872085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// Simple constructor for string literals made from one token. 12885cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor static StringLiteral *Create(ASTContext &C, StringRef Str, StringKind Kind, 12895cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor bool Pascal, QualType Ty, 12905cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor SourceLocation Loc) { 12915cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor return Create(C, Str, Kind, Pascal, Ty, &Loc, 1); 12922085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 1293a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson 1294673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor /// \brief Construct an empty string literal. 1295673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor static StringLiteral *CreateEmpty(ASTContext &C, unsigned NumStrs); 1296673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 1297686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef getString() const { 1298686775deca8b8685eb90801495880e3abdd844c2Chris Lattner return StringRef(StrData, ByteLength); 1299b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar } 13002f4eaef37476ae6891ede8ba215d0f6fd093629bBenjamin Kramer 13015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getByteLength() const { return ByteLength; } 1302673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 1303673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor /// \brief Sets the string data to the given string data. 1304686775deca8b8685eb90801495880e3abdd844c2Chris Lattner void setString(ASTContext &C, StringRef Str); 1305673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 13065cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor StringKind getKind() const { return static_cast<StringKind>(Kind); } 13075cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor bool isAscii() const { return Kind == Ascii; } 13085cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor bool isWide() const { return Kind == Wide; } 13095cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor bool isUTF8() const { return Kind == UTF8; } 13105cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor bool isUTF16() const { return Kind == UTF16; } 13115cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor bool isUTF32() const { return Kind == UTF32; } 13123e2193ce5feb2feb092e5ae615e85148e06e9fd2Anders Carlsson bool isPascal() const { return IsPascal; } 13135cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor 13148d4141f83d9de379547cf05bd75d4c6cf894b189Steve Naroff bool containsNonAsciiOrNull() const { 1315686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef Str = getString(); 1316b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar for (unsigned i = 0, e = Str.size(); i != e; ++i) 1317b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar if (!isascii(Str[i]) || !Str[i]) 131833fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff return true; 131933fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff return false; 132033fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff } 1321726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner /// getNumConcatenated - Get the number of string literal tokens that were 1322726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner /// concatenated in translation phase #6 to form this string literal. 1323726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner unsigned getNumConcatenated() const { return NumConcatenated; } 13241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1325726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner SourceLocation getStrTokenLoc(unsigned TokNum) const { 1326726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner assert(TokNum < NumConcatenated && "Invalid tok number"); 1327726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner return TokLocs[TokNum]; 1328726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner } 13291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setStrTokenLoc(unsigned TokNum, SourceLocation L) { 1330673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor assert(TokNum < NumConcatenated && "Invalid tok number"); 1331673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor TokLocs[TokNum] = L; 1332673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor } 133308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 133408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// getLocationOfByte - Return a source location that points to the specified 133508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// byte of this string literal. 133608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// 133708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// Strings are amazingly complex. They can be formed from multiple tokens 133808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// and can have escape sequences in them in addition to the usual trigraph 133908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// and escaped newline business. This routine handles this complexity. 134008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// 134108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner SourceLocation getLocationOfByte(unsigned ByteNo, const SourceManager &SM, 134208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner const LangOptions &Features, 134308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner const TargetInfo &Target) const; 1344673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 1345b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner typedef const SourceLocation *tokloc_iterator; 1346b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner tokloc_iterator tokloc_begin() const { return TokLocs; } 1347b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner tokloc_iterator tokloc_end() const { return TokLocs+NumConcatenated; } 13485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 134963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 13501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(TokLocs[0], TokLocs[NumConcatenated-1]); 13515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 13531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == StringLiteralClass; 13545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const StringLiteral *) { return true; } 13561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 135777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 135863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 13595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 13605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ParenExpr - This represents a parethesized expression, e.g. "(1)". This 13625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// AST node is only formed if full location information is requested. 13635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ParenExpr : public Expr { 13645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation L, R; 13655549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 13665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 13675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ParenExpr(SourceLocation l, SourceLocation r, Expr *val) 1368898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Expr(ParenExprClass, val->getType(), 1369f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall val->getValueKind(), val->getObjectKind(), 1370bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor val->isTypeDependent(), val->isValueDependent(), 1371561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor val->isInstantiationDependent(), 1372bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor val->containsUnexpandedParameterPack()), 1373898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor L(l), R(r), Val(val) {} 13741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1375c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor /// \brief Construct an empty parenthesized expression. 13761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ParenExpr(EmptyShell Empty) 1377c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor : Expr(ParenExprClass, Empty) { } 1378c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor 13795549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 13805549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 1381c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 1382c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor 138363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(L, R); } 13845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1385313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Get the location of the left parentheses '('. 1386313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getLParen() const { return L; } 1387c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setLParen(SourceLocation Loc) { L = Loc; } 1388313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 1389313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Get the location of the right parentheses ')'. 1390313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getRParen() const { return R; } 1391c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setRParen(SourceLocation Loc) { R = Loc; } 1392313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 13931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 13941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ParenExprClass; 13955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ParenExpr *) { return true; } 13971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 139877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 139963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Val, &Val+1); } 14005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 14015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14030518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// UnaryOperator - This represents the unary-expression's (except sizeof and 14040518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// alignof), the postinc/postdec operators from postfix-expression, and various 14055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// extensions. 1406dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 1407dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Notes on various nodes: 1408dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 1409dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Real/Imag - These return the real/imag part of a complex operand. If 1410dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// applied to a non-complex value, the former returns its operand and the 1411dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// later returns zero in the type of the operand. 1412dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 14135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass UnaryOperator : public Expr { 14145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 14155baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall typedef UnaryOperatorKind Opcode; 14165baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 14175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 14180799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall unsigned Opc : 5; 14195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 14200799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Stmt *Val; 14211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 14225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1423f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall UnaryOperator(Expr *input, Opcode opc, QualType type, 1424f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, SourceLocation l) 1425f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(UnaryOperatorClass, type, VK, OK, 1426de7e66256b1bdfcf6526994825a8c8fced52a31cEli Friedman input->isTypeDependent() || type->isDependentType(), 1427bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor input->isValueDependent(), 1428561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (input->isInstantiationDependent() || 1429561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor type->isInstantiationDependentType()), 1430bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor input->containsUnexpandedParameterPack()), 14310799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Opc(opc), Loc(l), Val(input) {} 14325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14330b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor /// \brief Build an empty unary operator. 14341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit UnaryOperator(EmptyShell Empty) 14352de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall : Expr(UnaryOperatorClass, Empty), Opc(UO_AddrOf) { } 14360b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 14370799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Opcode getOpcode() const { return static_cast<Opcode>(Opc); } 14380b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOpcode(Opcode O) { Opc = O; } 14390b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 14405549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() const { return cast<Expr>(Val); } 14410b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setSubExpr(Expr *E) { Val = E; } 14420b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 14435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOperatorLoc - Return the location of the operator. 14445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getOperatorLoc() const { return Loc; } 14450b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOperatorLoc(SourceLocation L) { Loc = L; } 14460b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 14475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isPostfix - Return true if this is a postfix operation, like x++. 14482085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static bool isPostfix(Opcode Op) { 14492de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Op == UO_PostInc || Op == UO_PostDec; 14502085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 14515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1452cc7bd10c0de9449b795bda3c5dcc6d83cc48436bZhanyong Wan /// isPrefix - Return true if this is a prefix operation, like --x. 14532085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static bool isPrefix(Opcode Op) { 14542de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Op == UO_PreInc || Op == UO_PreDec; 14552085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 14565a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek 14570799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isPrefix() const { return isPrefix(getOpcode()); } 14580799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isPostfix() const { return isPostfix(getOpcode()); } 14592de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall bool isIncrementOp() const { 1460993cdca0fed7deb646e4654dfb2607227a497faaBenjamin Kramer return Opc == UO_PreInc || Opc == UO_PostInc; 14612de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 14622de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall bool isIncrementDecrementOp() const { 1463993cdca0fed7deb646e4654dfb2607227a497faaBenjamin Kramer return Opc <= UO_PreDec; 14642de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 14652de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isArithmeticOp(Opcode Op) { 14662de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Op >= UO_Plus && Op <= UO_LNot; 14672de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 14680799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isArithmeticOp() const { return isArithmeticOp(getOpcode()); } 14691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 14715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// corresponds to, e.g. "sizeof" or "[pre]++" 14725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static const char *getOpcodeStr(Opcode Op); 14735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1474bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// \brief Retrieve the unary opcode that corresponds to the given 1475bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// overloaded operator. 1476bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix); 1477bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 1478bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// \brief Retrieve the overloaded operator kind that corresponds to 1479bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// the given unary opcode. 1480bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); 1481bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 148263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 14835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (isPostfix()) 14845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(Val->getLocStart(), Loc); 14855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else 14865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(Loc, Val->getLocEnd()); 14875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 148863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation getExprLoc() const { return Loc; } 14891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 14911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == UnaryOperatorClass; 14925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 14935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const UnaryOperator *) { return true; } 14941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 149577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 149663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Val, &Val+1); } 14975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 14985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14998ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// OffsetOfExpr - [C99 7.17] - This represents an expression of the form 15008ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// offsetof(record-type, member-designator). For example, given: 15018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// @code 15028ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct S { 15038ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// float f; 1504c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt/// double d; 15058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// }; 15068ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct T { 15078ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// int i; 15088ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct S s[10]; 15098ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// }; 15108ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// @endcode 1511c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt/// we can represent and evaluate the expression @c offsetof(struct T, s[2].d). 15128ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 15138ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorclass OffsetOfExpr : public Expr { 15148ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorpublic: 15158ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // __builtin_offsetof(type, identifier(.identifier|[expr])*) 15168ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor class OffsetOfNode { 15178ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor public: 15188ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief The kind of offsetof node we have. 15198ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor enum Kind { 1520cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief An index into an array. 15218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Array = 0x00, 1522cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief A field. 15238ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Field = 0x01, 1524cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief A field in a dependent type, known only by its name. 1525cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor Identifier = 0x02, 1526cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief An implicit indirection through a C++ base class, when the 1527cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// field found is in a base class. 1528cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor Base = 0x03 15298ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor }; 15308ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 15318ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor private: 15328ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor enum { MaskBits = 2, Mask = 0x03 }; 1533c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15348ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief The source range that covers this part of the designator. 15358ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceRange Range; 1536c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief The data describing the designator, which comes in three 15388ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// different forms, depending on the lower two bits. 1539c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// - An unsigned index into the array of Expr*'s stored after this node 15408ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// in memory, for [constant-expression] designators. 15418ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// - A FieldDecl*, for references to a known field. 15428ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// - An IdentifierInfo*, for references to a field with a given name 15438ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// when the class type is dependent. 1544c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// - A CXXBaseSpecifier*, for references that look at a field in a 1545cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// base class. 15468ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor uintptr_t Data; 1547c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15488ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor public: 15498ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Create an offsetof node that refers to an array element. 1550c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode(SourceLocation LBracketLoc, unsigned Index, 15518ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RBracketLoc) 15528ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor : Range(LBracketLoc, RBracketLoc), Data((Index << 2) | Array) { } 1553c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15548ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Create an offsetof node that refers to a field. 1555c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode(SourceLocation DotLoc, FieldDecl *Field, 15568ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation NameLoc) 1557c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc), 15588ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Data(reinterpret_cast<uintptr_t>(Field) | OffsetOfNode::Field) { } 1559c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15608ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Create an offsetof node that refers to an identifier. 15618ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor OffsetOfNode(SourceLocation DotLoc, IdentifierInfo *Name, 15628ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation NameLoc) 1563c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc), 15648ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Data(reinterpret_cast<uintptr_t>(Name) | Identifier) { } 1565cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor 1566cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief Create an offsetof node that refers into a C++ base class. 1567cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor explicit OffsetOfNode(const CXXBaseSpecifier *Base) 1568cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor : Range(), Data(reinterpret_cast<uintptr_t>(Base) | OffsetOfNode::Base) {} 1569c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15708ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Determine what kind of offsetof node this is. 1571c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Kind getKind() const { 15728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return static_cast<Kind>(Data & Mask); 15738ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1574c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief For an array element node, returns the index into the array 15768ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// of expressions. 15778ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned getArrayExprIndex() const { 15788ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(getKind() == Array); 15798ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return Data >> 2; 15808ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 15818ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 15828ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief For a field offsetof node, returns the field. 15838ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor FieldDecl *getField() const { 15848ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(getKind() == Field); 1585cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor return reinterpret_cast<FieldDecl *>(Data & ~(uintptr_t)Mask); 15868ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1587c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15888ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief For a field or identifier offsetof node, returns the name of 15898ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// the field. 15908ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor IdentifierInfo *getFieldName() const; 1591c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1592cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief For a base class node, returns the base specifier. 1593cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor CXXBaseSpecifier *getBase() const { 1594cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor assert(getKind() == Base); 1595c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return reinterpret_cast<CXXBaseSpecifier *>(Data & ~(uintptr_t)Mask); 1596cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor } 1597c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15988ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Retrieve the source range that covers this offsetof node. 15998ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// 16008ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// For an array element node, the source range contains the locations of 16018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// the square brackets. For a field or identifier node, the source range 1602c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// contains the location of the period (if there is one) and the 16038ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// identifier. 160406dec892b5300b43263d25c5476b506c9d6cfbadAbramo Bagnara SourceRange getSourceRange() const { return Range; } 16058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor }; 16068ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 16078ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorprivate: 1608c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 16098ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation OperatorLoc, RParenLoc; 16108ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Base type; 16118ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TypeSourceInfo *TSInfo; 16128ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Number of sub-components (i.e. instances of OffsetOfNode). 16138ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumComps; 16148ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Number of sub-expressions (i.e. array subscript expressions). 16158ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumExprs; 1616c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1617c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfExpr(ASTContext &C, QualType type, 16188ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation OperatorLoc, TypeSourceInfo *tsi, 1619c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode* compsPtr, unsigned numComps, 16208ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr** exprsPtr, unsigned numExprs, 16218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc); 16228ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 16238ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor explicit OffsetOfExpr(unsigned numComps, unsigned numExprs) 16248ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor : Expr(OffsetOfExprClass, EmptyShell()), 1625c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt TSInfo(0), NumComps(numComps), NumExprs(numExprs) {} 16268ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 16278ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorpublic: 1628c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1629c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt static OffsetOfExpr *Create(ASTContext &C, QualType type, 1630c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt SourceLocation OperatorLoc, TypeSourceInfo *tsi, 1631c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode* compsPtr, unsigned numComps, 16328ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr** exprsPtr, unsigned numExprs, 16338ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc); 16348ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 1635c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt static OffsetOfExpr *CreateEmpty(ASTContext &C, 16368ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumComps, unsigned NumExprs); 16378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 16388ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// getOperatorLoc - Return the location of the operator. 16398ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation getOperatorLoc() const { return OperatorLoc; } 16408ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setOperatorLoc(SourceLocation L) { OperatorLoc = L; } 16418ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 16428ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Return the location of the right parentheses. 16438ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 16448ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setRParenLoc(SourceLocation R) { RParenLoc = R; } 1645c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 16468ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TypeSourceInfo *getTypeSourceInfo() const { 16478ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return TSInfo; 16488ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 16498ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setTypeSourceInfo(TypeSourceInfo *tsi) { 16508ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TSInfo = tsi; 16518ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1652c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 16538cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne const OffsetOfNode &getComponent(unsigned Idx) const { 16548ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumComps && "Subscript out of range"); 16558cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne return reinterpret_cast<const OffsetOfNode *> (this + 1)[Idx]; 16568ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 16578ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 16588ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setComponent(unsigned Idx, OffsetOfNode ON) { 16598ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumComps && "Subscript out of range"); 16608ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<OffsetOfNode *> (this + 1)[Idx] = ON; 16618ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1662c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 16638ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned getNumComponents() const { 16648ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return NumComps; 16658ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 16668ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 16678ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr* getIndexExpr(unsigned Idx) { 16688ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumExprs && "Subscript out of range"); 16698ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return reinterpret_cast<Expr **>( 16708ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx]; 16718ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 16728cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne const Expr *getIndexExpr(unsigned Idx) const { 16738cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne return const_cast<OffsetOfExpr*>(this)->getIndexExpr(Idx); 16748cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne } 16758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 16768ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setIndexExpr(unsigned Idx, Expr* E) { 16778ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumComps && "Subscript out of range"); 16788ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<Expr **>( 16798ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx] = E; 16808ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1681c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 16828ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned getNumExpressions() const { 16838ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return NumExprs; 16848ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 16858ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 168663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 16878ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return SourceRange(OperatorLoc, RParenLoc); 16888ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 16898ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 16908ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor static bool classof(const Stmt *T) { 16918ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return T->getStmtClass() == OffsetOfExprClass; 16928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 16938ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 16948ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor static bool classof(const OffsetOfExpr *) { return true; } 16958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 16968ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Iterators 169763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 169863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt **begin = 169963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall reinterpret_cast<Stmt**>(reinterpret_cast<OffsetOfNode*>(this + 1) 170063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall + NumComps); 170163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(begin, begin + NumExprs); 170263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 17038ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor}; 17048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 1705f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne/// UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) 1706f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne/// expression operand. Used for sizeof/alignof (C99 6.5.3.4) and 1707f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne/// vec_step (OpenCL 1.1 6.11.12). 1708f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourneclass UnaryExprOrTypeTraitExpr : public Expr { 1709f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne unsigned Kind : 2; 17100518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl bool isType : 1; // true if operand is a type, false if an expression 1711d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl union { 1712a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *Ty; 1713d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl Stmt *Ex; 1714d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl } Argument; 17155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation OpLoc, RParenLoc; 171642602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor 17175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1718f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, TypeSourceInfo *TInfo, 1719f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne QualType resultType, SourceLocation op, 1720f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne SourceLocation rp) : 1721f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_RValue, OK_Ordinary, 1722ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor false, // Never type-dependent (C++ [temp.dep.expr]p3). 17232850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl // Value-dependent if the argument is type-dependent. 1724bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor TInfo->getType()->isDependentType(), 1725561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor TInfo->getType()->isInstantiationDependentType(), 1726bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor TInfo->getType()->containsUnexpandedParameterPack()), 1727f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne Kind(ExprKind), isType(true), OpLoc(op), RParenLoc(rp) { 1728a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall Argument.Ty = TInfo; 1729ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor } 1730ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor 1731f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, Expr *E, 1732f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne QualType resultType, SourceLocation op, 1733f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne SourceLocation rp) : 1734f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_RValue, OK_Ordinary, 1735ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor false, // Never type-dependent (C++ [temp.dep.expr]p3). 1736ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor // Value-dependent if the argument is type-dependent. 1737bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor E->isTypeDependent(), 1738561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor E->isInstantiationDependent(), 1739bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor E->containsUnexpandedParameterPack()), 1740f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne Kind(ExprKind), isType(false), OpLoc(op), RParenLoc(rp) { 1741ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor Argument.Ex = E; 1742d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl } 17430518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl 17440b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor /// \brief Construct an empty sizeof/alignof expression. 1745f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne explicit UnaryExprOrTypeTraitExpr(EmptyShell Empty) 1746f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne : Expr(UnaryExprOrTypeTraitExprClass, Empty) { } 17470b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 1748f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne UnaryExprOrTypeTrait getKind() const { 1749f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne return static_cast<UnaryExprOrTypeTrait>(Kind); 1750f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne } 1751f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne void setKind(UnaryExprOrTypeTrait K) { Kind = K; } 17520b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 17530518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl bool isArgumentType() const { return isType; } 17540518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType getArgumentType() const { 17555ab75172051a6d2ea71a80a79e81c65519fd3462John McCall return getArgumentTypeInfo()->getType(); 17565ab75172051a6d2ea71a80a79e81c65519fd3462John McCall } 1757a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *getArgumentTypeInfo() const { 17580518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl assert(isArgumentType() && "calling getArgumentType() when arg is expr"); 17595ab75172051a6d2ea71a80a79e81c65519fd3462John McCall return Argument.Ty; 17600518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 1761caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner Expr *getArgumentExpr() { 17620518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl assert(!isArgumentType() && "calling getArgumentExpr() when arg is type"); 1763d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl return static_cast<Expr*>(Argument.Ex); 17640518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 1765caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner const Expr *getArgumentExpr() const { 1766f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne return const_cast<UnaryExprOrTypeTraitExpr*>(this)->getArgumentExpr(); 1767caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner } 17680b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 17690b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setArgument(Expr *E) { Argument.Ex = E; isType = false; } 1770a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall void setArgument(TypeSourceInfo *TInfo) { 1771a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall Argument.Ty = TInfo; 17721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump isType = true; 17730b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor } 17740b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 17750518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl /// Gets the argument type, or the type of the argument expression, whichever 17760518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl /// is appropriate. 17770518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType getTypeOfArgument() const { 17780518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl return isArgumentType() ? getArgumentType() : getArgumentExpr()->getType(); 17790518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 17800518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl 178176e773a443be9f006610f46529e07d4c8d857680Chris Lattner SourceLocation getOperatorLoc() const { return OpLoc; } 17820b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOperatorLoc(SourceLocation L) { OpLoc = L; } 17830b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 17840b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 17850b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1786866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek 178763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 1788866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek return SourceRange(OpLoc, RParenLoc); 1789866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek } 17905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 17911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 1792f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne return T->getStmtClass() == UnaryExprOrTypeTraitExprClass; 17935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1794f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne static bool classof(const UnaryExprOrTypeTraitExpr *) { return true; } 17951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 179677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 179763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children(); 17985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 17995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 18005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 18015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Postfix Operators. 18025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 18035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 18045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting. 18055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ArraySubscriptExpr : public Expr { 180677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek enum { LHS, RHS, END_EXPR=2 }; 18071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Stmt* SubExprs[END_EXPR]; 18085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation RBracketLoc; 18095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 18102324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t, 1811f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 181273d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SourceLocation rbracketloc) 1813f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ArraySubscriptExprClass, t, VK, OK, 18142850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl lhs->isTypeDependent() || rhs->isTypeDependent(), 1815bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor lhs->isValueDependent() || rhs->isValueDependent(), 1816561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (lhs->isInstantiationDependent() || 1817561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhs->isInstantiationDependent()), 1818bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (lhs->containsUnexpandedParameterPack() || 1819bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhs->containsUnexpandedParameterPack())), 18202850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl RBracketLoc(rbracketloc) { 182173d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SubExprs[LHS] = lhs; 182273d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SubExprs[RHS] = rhs; 182373d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner } 18241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1825cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor /// \brief Create an empty array subscript expression. 1826cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor explicit ArraySubscriptExpr(EmptyShell Shell) 1827cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor : Expr(ArraySubscriptExprClass, Shell) { } 1828cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 18292324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// An array access can be written A[4] or 4[A] (both are equivalent). 18302324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// - getBase() and getIdx() always present the normalized view: A[4]. 18312324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// In this case getBase() returns "A" and getIdx() returns "4". 18322324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// - getLHS() and getRHS() present the syntactic view. e.g. for 18332324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// 4[A] getLHS() returns "4". 183433fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// Note: Because vector element access is also written A[4] we must 183533fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// predicate the format conversion in getBase and getIdx only on the 183633fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// the type of the RHS, as it is possible for the LHS to be a vector of 183733fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// integer type 18385549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); } 18395549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 1840cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 1841cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 18425549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); } 18435549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 1844cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 18451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getBase() { 18475549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS()); 184877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek } 18491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr *getBase() const { 18515549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS()); 18522324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek } 18531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getIdx() { 18555549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS()); 18562324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek } 18571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 185877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek const Expr *getIdx() const { 18595549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS()); 18601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 18611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 186263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 186377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek return SourceRange(getLHS()->getLocStart(), RBracketLoc); 18645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 18651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1866026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getRBracketLoc() const { return RBracketLoc; } 1867cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setRBracketLoc(SourceLocation L) { RBracketLoc = L; } 1868cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 186963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation getExprLoc() const { return getBase()->getExprLoc(); } 18705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 18711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 18721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ArraySubscriptExprClass; 18735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 18745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ArraySubscriptExpr *) { return true; } 18751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 187677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 187763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 187863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 187963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 18805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 18815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 18825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1883b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]). 18841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CallExpr itself represents a normal function call, e.g., "f(x, 2)", 1885b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// while its subclasses may represent alternative syntax that (semantically) 18861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// results in a function call. For example, CXXOperatorCallExpr is 1887b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// a subclass for overloaded operator calls that use operator syntax, e.g., 1888b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// "str1 + str2" to resolve to a function call. 18895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CallExpr : public Expr { 1890cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne enum { FN=0, PREARGS_START=1 }; 18915549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt **SubExprs; 18925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned NumArgs; 18935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation RParenLoc; 18941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1895b4609806e9232593ece09ce08b630836e825865cDouglas Gregorprotected: 1896cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne // These versions of the constructor are for derived classes. 1897cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExpr(ASTContext& C, StmtClass SC, Expr *fn, unsigned NumPreArgs, 1898cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne Expr **args, unsigned numargs, QualType t, ExprValueKind VK, 1899cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SourceLocation rparenloc); 1900cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExpr(ASTContext &C, StmtClass SC, unsigned NumPreArgs, EmptyShell Empty); 1901cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne 1902cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne Stmt *getPreArg(unsigned i) { 1903cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne assert(i < getNumPreArgs() && "Prearg access out of range!"); 1904cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs[PREARGS_START+i]; 1905cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 1906cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne const Stmt *getPreArg(unsigned i) const { 1907cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne assert(i < getNumPreArgs() && "Prearg access out of range!"); 1908cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs[PREARGS_START+i]; 1909cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 1910cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne void setPreArg(unsigned i, Stmt *PreArg) { 1911cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne assert(i < getNumPreArgs() && "Prearg access out of range!"); 1912cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs[PREARGS_START+i] = PreArg; 1913cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 1914cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne 1915cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne unsigned getNumPreArgs() const { return CallExprBits.NumPreArgs; } 191642602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor 19175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 19181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, QualType t, 1919f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, SourceLocation rparenloc); 19201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19211f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor /// \brief Build an empty call expression. 1922ba0a9006dbc4814e1e35f82812cb5a1dad65e8b8Argyrios Kyrtzidis CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty); 19231f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 19245549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); } 19255549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCallee() { return cast<Expr>(SubExprs[FN]); } 192618b2515e1bf8c86a4900792692e42fe1296be28dChris Lattner void setCallee(Expr *F) { SubExprs[FN] = F; } 1927a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 1928d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes Decl *getCalleeDecl(); 1929d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes const Decl *getCalleeDecl() const { 1930d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes return const_cast<CallExpr*>(this)->getCalleeDecl(); 1931d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes } 1932d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes 1933a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu /// \brief If the callee is a FunctionDecl, return it. Otherwise return 0. 1934a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu FunctionDecl *getDirectCallee(); 1935bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner const FunctionDecl *getDirectCallee() const { 1936bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner return const_cast<CallExpr*>(this)->getDirectCallee(); 1937bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner } 1938a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 19395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getNumArgs - Return the number of actual arguments to this call. 19405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 19415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumArgs() const { return NumArgs; } 19421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1943aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \brief Retrieve the call arguments. 1944cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne Expr **getArgs() { 1945cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return reinterpret_cast<Expr **>(SubExprs+getNumPreArgs()+PREARGS_START); 1946cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 1947aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 19485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getArg - Return the specified argument. 19495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Expr *getArg(unsigned Arg) { 19505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(Arg < NumArgs && "Arg access out of range!"); 1951cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return cast<Expr>(SubExprs[Arg+getNumPreArgs()+PREARGS_START]); 19525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 19535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const Expr *getArg(unsigned Arg) const { 19545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(Arg < NumArgs && "Arg access out of range!"); 1955cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return cast<Expr>(SubExprs[Arg+getNumPreArgs()+PREARGS_START]); 19565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 19571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1958934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff /// setArg - Set the specified argument. 1959934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff void setArg(unsigned Arg, Expr *ArgExpr) { 1960934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff assert(Arg < NumArgs && "Arg access out of range!"); 1961cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs[Arg+getNumPreArgs()+PREARGS_START] = ArgExpr; 1962934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff } 19631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1964d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// setNumArgs - This changes the number of arguments present in this call. 1965d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// Any orphaned expressions are deleted by this, and any new operands are set 1966d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// to null. 19678189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek void setNumArgs(ASTContext& C, unsigned NumArgs); 19681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19695549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek typedef ExprIterator arg_iterator; 19705549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek typedef ConstExprIterator const_arg_iterator; 19711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1972cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne arg_iterator arg_begin() { return SubExprs+PREARGS_START+getNumPreArgs(); } 1973cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne arg_iterator arg_end() { 1974cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs+PREARGS_START+getNumPreArgs()+getNumArgs(); 1975cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 1976cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne const_arg_iterator arg_begin() const { 1977cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs+PREARGS_START+getNumPreArgs(); 1978cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 1979cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne const_arg_iterator arg_end() const { 1980cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs+PREARGS_START+getNumPreArgs()+getNumArgs(); 1981cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 19821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getNumCommas - Return the number of commas that must have been present in 19845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// this function call. 19855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; } 19865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1987cb888967400a03504c88acedd5248d6778a82f46Chris Lattner /// isBuiltinCall - If this is a call to a builtin, return the builtin ID. If 1988cb888967400a03504c88acedd5248d6778a82f46Chris Lattner /// not, return 0. 19894ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad unsigned isBuiltinCall(const ASTContext &Context) const; 19901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// getCallReturnType - Get the return type of the call expr. This is not 19921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// always the type of the expr itself, if the return type is a reference 19936dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson /// type. 19946dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson QualType getCallReturnType() const; 19951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1996d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner SourceLocation getRParenLoc() const { return RParenLoc; } 19971f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1998866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek 19992882eca5a184c78f793188083f6ce539740a5cf2John McCall SourceRange getSourceRange() const; 20001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 20024bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return T->getStmtClass() >= firstCallExprConstant && 20034bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt T->getStmtClass() <= lastCallExprConstant; 20045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 20055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CallExpr *) { return true; } 200688a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 200777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 200863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 200963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], 201063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall &SubExprs[0]+NumArgs+getNumPreArgs()+PREARGS_START); 201163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 20125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 20135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2014ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner/// MemberExpr - [C99 6.5.2.3] Structure and Union Members. X->F and X.F. 20155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 20165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass MemberExpr : public Expr { 20176bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// Extra data stored in some member expressions. 20186857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth struct MemberNameQualifier { 20196857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// \brief The nested-name-specifier that qualifies the name, including 20206857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// source-location information. 20216857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth NestedNameSpecifierLoc QualifierLoc; 20226857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth 20236857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// \brief The DeclAccessPair through which the MemberDecl was found due to 20246857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// name qualifiers. 2025161755a09898c95d21bfff33707da9ca41cd53c5John McCall DeclAccessPair FoundDecl; 20266bb8017bb9e828d118e15e59d71c66bba323c364John McCall }; 20276bb8017bb9e828d118e15e59d71c66bba323c364John McCall 2028ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// Base - the expression for the base pointer or structure references. In 2029ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// X.F, this is "X". 20305549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Base; 20311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2032ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// MemberDecl - This is the decl being referenced by the field/member name. 2033ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// In X.F, this is the decl referenced by F. 2034f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *MemberDecl; 20351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2036ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// MemberLoc - This is the location of the member name. 20375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation MemberLoc; 20381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20392577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// MemberDNLoc - Provides source/type location info for the 20402577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// declaration name embedded in MemberDecl. 20412577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameLoc MemberDNLoc; 20422577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 2043ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// IsArrow - True if this is "X->F", false if this is "X.F". 204483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor bool IsArrow : 1; 20451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 204683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief True if this member expression used a nested-name-specifier to 20476bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// refer to the member, e.g., "x->Base::f", or found its member via a using 20486bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// declaration. When true, a MemberNameQualifier 2049c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// structure is allocated immediately after the MemberExpr. 20506bb8017bb9e828d118e15e59d71c66bba323c364John McCall bool HasQualifierOrFoundDecl : 1; 20511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2052c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief True if this member expression specified a template argument list 2053c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// explicitly, e.g., x->f<int>. When true, an ExplicitTemplateArgumentList 2054c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// structure (and its TemplateArguments) are allocated immediately after 2055c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// the MemberExpr or, if the member expression also has a qualifier, after 20566bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// the MemberNameQualifier structure. 2057c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor bool HasExplicitTemplateArgumentList : 1; 20581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20597cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// \brief True if this member expression refers to a method that 20607cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// was resolved from an overloaded set having size greater than 1. 20617cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool HadMultipleCandidates : 1; 20627cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara 206383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief Retrieve the qualifier that preceded the member name, if any. 20646bb8017bb9e828d118e15e59d71c66bba323c364John McCall MemberNameQualifier *getMemberQualifier() { 20656bb8017bb9e828d118e15e59d71c66bba323c364John McCall assert(HasQualifierOrFoundDecl); 20666bb8017bb9e828d118e15e59d71c66bba323c364John McCall return reinterpret_cast<MemberNameQualifier *> (this + 1); 206783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 206883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor 206983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief Retrieve the qualifier that preceded the member name, if any. 20706bb8017bb9e828d118e15e59d71c66bba323c364John McCall const MemberNameQualifier *getMemberQualifier() const { 2071c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return const_cast<MemberExpr *>(this)->getMemberQualifier(); 2072c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 20731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 2075f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl, 2076f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall const DeclarationNameInfo &NameInfo, QualType ty, 2077f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK) 2078f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(MemberExprClass, ty, VK, OK, 2079561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor base->isTypeDependent(), 2080561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor base->isValueDependent(), 2081561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor base->isInstantiationDependent(), 2082bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->containsUnexpandedParameterPack()), 20832577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Base(base), MemberDecl(memberdecl), MemberLoc(NameInfo.getLoc()), 20842577743c5650c646fb705df01403707e94f2df04Abramo Bagnara MemberDNLoc(NameInfo.getInfo()), IsArrow(isarrow), 20857cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara HasQualifierOrFoundDecl(false), HasExplicitTemplateArgumentList(false), 20867cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara HadMultipleCandidates(false) { 20872577743c5650c646fb705df01403707e94f2df04Abramo Bagnara assert(memberdecl->getDeclName() == NameInfo.getName()); 20882577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 20892577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 20902577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // NOTE: this constructor should be used only when it is known that 20912577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // the member name can not provide additional syntactic info 20922577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // (i.e., source locations for C++ operator names or type source info 20932577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // for constructors, destructors and conversion oeprators). 20942577743c5650c646fb705df01403707e94f2df04Abramo Bagnara MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl, 2095f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall SourceLocation l, QualType ty, 2096f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK) 2097f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(MemberExprClass, ty, VK, OK, 2098bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->isTypeDependent(), base->isValueDependent(), 2099561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor base->isInstantiationDependent(), 2100bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->containsUnexpandedParameterPack()), 21012577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Base(base), MemberDecl(memberdecl), MemberLoc(l), MemberDNLoc(), 21022577743c5650c646fb705df01403707e94f2df04Abramo Bagnara IsArrow(isarrow), 21037cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara HasQualifierOrFoundDecl(false), HasExplicitTemplateArgumentList(false), 21047cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara HadMultipleCandidates(false) {} 2105510190777c4bd53e960eea4665b204778fec1b64Eli Friedman 21061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static MemberExpr *Create(ASTContext &C, Expr *base, bool isarrow, 210740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 2108161755a09898c95d21bfff33707da9ca41cd53c5John McCall ValueDecl *memberdecl, DeclAccessPair founddecl, 21092577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo MemberNameInfo, 2110d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *targs, 2111f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType ty, ExprValueKind VK, ExprObjectKind OK); 21121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 211388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor void setBase(Expr *E) { Base = E; } 21145549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getBase() const { return cast<Expr>(Base); } 211557e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor 211657e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// \brief Retrieve the member declaration to which this expression refers. 211757e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// 211857e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// The returned declaration will either be a FieldDecl or (in C++) 211957e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// a CXXMethodDecl. 2120f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *getMemberDecl() const { return MemberDecl; } 2121f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman void setMemberDecl(ValueDecl *D) { MemberDecl = D; } 21221f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 21236bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// \brief Retrieves the declaration found by lookup. 2124161755a09898c95d21bfff33707da9ca41cd53c5John McCall DeclAccessPair getFoundDecl() const { 21256bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (!HasQualifierOrFoundDecl) 2126161755a09898c95d21bfff33707da9ca41cd53c5John McCall return DeclAccessPair::make(getMemberDecl(), 2127161755a09898c95d21bfff33707da9ca41cd53c5John McCall getMemberDecl()->getAccess()); 21286bb8017bb9e828d118e15e59d71c66bba323c364John McCall return getMemberQualifier()->FoundDecl; 21296bb8017bb9e828d118e15e59d71c66bba323c364John McCall } 21306bb8017bb9e828d118e15e59d71c66bba323c364John McCall 21311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Determines whether this member expression actually had 21320979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor /// a C++ nested-name-specifier prior to the name of the member, e.g., 21330979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor /// x->Base::foo. 21346bb8017bb9e828d118e15e59d71c66bba323c364John McCall bool hasQualifier() const { return getQualifier() != 0; } 21351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief If the member name was qualified, retrieves the 213783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// nested-name-specifier that precedes the member name. Otherwise, returns 213883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// NULL. 21391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump NestedNameSpecifier *getQualifier() const { 21406bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (!HasQualifierOrFoundDecl) 214183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return 0; 21421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 214340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return getMemberQualifier()->QualifierLoc.getNestedNameSpecifier(); 214440d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor } 214540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor 214640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor /// \brief If the member name was qualified, retrieves the 214740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor /// nested-name-specifier that precedes the member name, with source-location 214840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor /// information. 214940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc getQualifierLoc() const { 215040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (!hasQualifier()) 215140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return NestedNameSpecifierLoc(); 215240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor 215340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return getMemberQualifier()->QualifierLoc; 215483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 2155c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor 2156c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Determines whether this member expression actually had a C++ 2157c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template argument list explicitly specified, e.g., x.f<int>. 2158096832c5ed5b9106fa177ebc148489760c3bc496John McCall bool hasExplicitTemplateArgs() const { 21591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return HasExplicitTemplateArgumentList; 2160c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 21611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2162d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// \brief Copies the template arguments (if present) into the given 2163d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// structure. 2164d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 2165096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (hasExplicitTemplateArgs()) 2166096832c5ed5b9106fa177ebc148489760c3bc496John McCall getExplicitTemplateArgs().copyInto(List); 2167096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 2168096832c5ed5b9106fa177ebc148489760c3bc496John McCall 2169096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that 2170096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// follow the member template name. This must only be called on an 2171096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// expression with explicit template arguments. 2172b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 2173096832c5ed5b9106fa177ebc148489760c3bc496John McCall assert(HasExplicitTemplateArgumentList); 2174096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!HasQualifierOrFoundDecl) 2175b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis return *reinterpret_cast<ASTTemplateArgumentListInfo *>(this + 1); 2176096832c5ed5b9106fa177ebc148489760c3bc496John McCall 2177b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis return *reinterpret_cast<ASTTemplateArgumentListInfo *>( 2178096832c5ed5b9106fa177ebc148489760c3bc496John McCall getMemberQualifier() + 1); 2179096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 2180096832c5ed5b9106fa177ebc148489760c3bc496John McCall 2181096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that 2182096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// followed the member template name. This must only be called on 2183096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// an expression with explicit template arguments. 2184b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 2185096832c5ed5b9106fa177ebc148489760c3bc496John McCall return const_cast<MemberExpr *>(this)->getExplicitTemplateArgs(); 2186096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 2187096832c5ed5b9106fa177ebc148489760c3bc496John McCall 2188096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieves the optional explicit template arguments. 2189096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// This points to the same data as getExplicitTemplateArgs(), but 2190096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// returns null if there are no explicit template arguments. 2191b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const { 2192096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) return 0; 2193096832c5ed5b9106fa177ebc148489760c3bc496John McCall return &getExplicitTemplateArgs(); 2194d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall } 2195c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 21961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Retrieve the location of the left angle bracket following the 2197c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// member name ('<'), if any. 21981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation getLAngleLoc() const { 2199c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 2200c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return SourceLocation(); 22011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2202096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().LAngleLoc; 2203c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 22041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2205c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Retrieve the template arguments provided as part of this 2206c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template-id. 2207833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc *getTemplateArgs() const { 2208c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 22091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return 0; 22101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2211096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().getTemplateArgs(); 2212c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 22131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2214c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Retrieve the number of template arguments provided as part of this 2215c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template-id. 22161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned getNumTemplateArgs() const { 2217c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 22181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return 0; 22191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2220096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().NumTemplateArgs; 2221c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 22221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Retrieve the location of the right angle bracket following the 2224c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template arguments ('>'). 22251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation getRAngleLoc() const { 2226c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 2227c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return SourceLocation(); 22281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2229096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().RAngleLoc; 2230c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 22311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22322577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// \brief Retrieve the member declaration name info. 22332577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo getMemberNameInfo() const { 22342577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(MemberDecl->getDeclName(), 22352577743c5650c646fb705df01403707e94f2df04Abramo Bagnara MemberLoc, MemberDNLoc); 22362577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 22372577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 22385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isArrow() const { return IsArrow; } 22391f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setArrow(bool A) { IsArrow = A; } 22401f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 2241ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// getMemberLoc - Return the location of the "member", in X->F, it is the 2242ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// location of 'F'. 2243026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getMemberLoc() const { return MemberLoc; } 22441f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setMemberLoc(SourceLocation L) { MemberLoc = L; } 22455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 224675e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor SourceRange getSourceRange() const; 224775e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 224863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation getExprLoc() const { return MemberLoc; } 22495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 225075e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor /// \brief Determine whether the base of this explicit is implicit. 225175e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor bool isImplicitAccess() const { 225275e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor return getBase() && getBase()->isImplicitCXXThis(); 225375e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } 22547cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara 22557cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// \brief Returns true if this member expression refers to a method that 22567cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// was resolved from an overloaded set having size greater than 1. 22577cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool hadMultipleCandidates() const { 22587cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara return HadMultipleCandidates; 22597cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara } 22607cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// \brief Sets the flag telling whether this expression refers to 22617cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// a method that was resolved from an overloaded set having size 22627cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// greater than 1. 22637cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara void setHadMultipleCandidates(bool V = true) { 22647cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara HadMultipleCandidates = V; 22657cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara } 22667cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara 22671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 226883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return T->getStmtClass() == MemberExprClass; 22695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 22705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const MemberExpr *) { return true; } 22711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22721237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 227363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Base, &Base+1); } 22744045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis 22754045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTReader; 22764045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTStmtWriter; 22775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 22785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 22791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CompoundLiteralExpr - [C99 6.5.2.5] 2280aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff/// 2281aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffclass CompoundLiteralExpr : public Expr { 22820fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// LParenLoc - If non-null, this is the location of the left paren in a 22830fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// compound literal like "(int){4}". This can be null if this is a 22840fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// synthesized compound expression. 22850fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner SourceLocation LParenLoc; 22861d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall 22871d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall /// The type as written. This can be an incomplete array type, in 22881d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall /// which case the actual expression type will be different. 228942f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *TInfo; 22905549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Init; 2291e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff bool FileScope; 2292aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffpublic: 229342f56b50062cd3b3c6b23fdb9053578ae9145664John McCall CompoundLiteralExpr(SourceLocation lparenloc, TypeSourceInfo *tinfo, 2294f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK, Expr *init, bool fileScope) 2295f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CompoundLiteralExprClass, T, VK, OK_Ordinary, 2296bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor tinfo->getType()->isDependentType(), 2297bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor init->isValueDependent(), 2298561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (init->isInstantiationDependent() || 2299561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor tinfo->getType()->isInstantiationDependentType()), 2300bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor init->containsUnexpandedParameterPack()), 230142f56b50062cd3b3c6b23fdb9053578ae9145664John McCall LParenLoc(lparenloc), TInfo(tinfo), Init(init), FileScope(fileScope) {} 23021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2303ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor /// \brief Construct an empty compound literal. 2304ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor explicit CompoundLiteralExpr(EmptyShell Empty) 2305ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor : Expr(CompoundLiteralExprClass, Empty) { } 2306ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 23075549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getInitializer() const { return cast<Expr>(Init); } 23085549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getInitializer() { return cast<Expr>(Init); } 2309ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setInitializer(Expr *E) { Init = E; } 2310e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff 2311e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff bool isFileScope() const { return FileScope; } 2312ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setFileScope(bool FS) { FileScope = FS; } 2313ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 23140fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner SourceLocation getLParenLoc() const { return LParenLoc; } 2315ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setLParenLoc(SourceLocation L) { LParenLoc = L; } 2316ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 231742f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *getTypeSourceInfo() const { return TInfo; } 231842f56b50062cd3b3c6b23fdb9053578ae9145664John McCall void setTypeSourceInfo(TypeSourceInfo* tinfo) { TInfo = tinfo; } 231942f56b50062cd3b3c6b23fdb9053578ae9145664John McCall 232063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 23210fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner // FIXME: Init should never be null. 23220fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner if (!Init) 23230fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner return SourceRange(); 23240fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner if (LParenLoc.isInvalid()) 232573d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner return Init->getSourceRange(); 23260fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner return SourceRange(LParenLoc, Init->getLocEnd()); 232773d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner } 2328aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff 23291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 23301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CompoundLiteralExprClass; 2331aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff } 2332aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff static bool classof(const CompoundLiteralExpr *) { return true; } 23331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23341237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 233563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Init, &Init+1); } 2336aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff}; 2337aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff 233849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CastExpr - Base class for type casts, including both implicit 233949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// casts (ImplicitCastExpr) and explicit casts that have some 234049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// representation in the source code (ExplicitCastExpr's derived 234149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// classes). 23420835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass CastExpr : public Expr { 2343cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlssonpublic: 23445baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall typedef clang::CastKind CastKind; 23451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2346cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlssonprivate: 23470835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis Stmt *Op; 2348409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson 23491d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall void CheckCastConsistency() const; 2350409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson 2351f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXBaseSpecifier * const *path_buffer() const { 2352f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return const_cast<CastExpr*>(this)->path_buffer(); 2353f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall } 2354f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CXXBaseSpecifier **path_buffer(); 2355f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2356654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis void setBasePathSize(unsigned basePathSize) { 2357654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis CastExprBits.BasePathSize = basePathSize; 2358654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis assert(CastExprBits.BasePathSize == basePathSize && 2359654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis "basePathSize doesn't fit in bits of CastExprBits.BasePathSize!"); 2360654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis } 2361654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis 23620835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisprotected: 2363f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CastExpr(StmtClass SC, QualType ty, ExprValueKind VK, 2364f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall const CastKind kind, Expr *op, unsigned BasePathSize) : 2365f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(SC, ty, VK, OK_Ordinary, 2366898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Cast expressions are type-dependent if the type is 2367898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // dependent (C++ [temp.dep.expr]p3). 2368898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ty->isDependentType(), 2369898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Cast expressions are value-dependent if the type is 2370898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // dependent or if the subexpression is value-dependent. 2371bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ty->isDependentType() || (op && op->isValueDependent()), 2372561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (ty->isInstantiationDependentType() || 2373561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (op && op->isInstantiationDependent())), 2374bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (ty->containsUnexpandedParameterPack() || 2375bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor op->containsUnexpandedParameterPack())), 23768e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall Op(op) { 2377daa8e4e888758d55a7a759dd4a91b83921cef222John McCall assert(kind != CK_Invalid && "creating cast with invalid cast kind"); 23788e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CastExprBits.Kind = kind; 2379654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis setBasePathSize(BasePathSize); 23801d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall#ifndef NDEBUG 2381daa8e4e888758d55a7a759dd4a91b83921cef222John McCall CheckCastConsistency(); 23821d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall#endif 2383f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall } 23841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2385087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor /// \brief Construct an empty cast. 2386f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastExpr(StmtClass SC, EmptyShell Empty, unsigned BasePathSize) 23878e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall : Expr(SC, Empty) { 2388654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis setBasePathSize(BasePathSize); 23898e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall } 23901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23910835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidispublic: 23928e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CastKind getCastKind() const { return (CastKind) CastExprBits.Kind; } 23938e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall void setCastKind(CastKind K) { CastExprBits.Kind = K; } 2394f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson const char *getCastKindName() const; 2395f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson 23960835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis Expr *getSubExpr() { return cast<Expr>(Op); } 23970835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis const Expr *getSubExpr() const { return cast<Expr>(Op); } 2398087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor void setSubExpr(Expr *E) { Op = E; } 2399087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor 24006eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// \brief Retrieve the cast subexpression as it was written in the source 24016eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// code, looking through any implicit casts or other intermediate nodes 24026eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// introduced by semantic analysis. 24036eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor Expr *getSubExprAsWritten(); 24046eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor const Expr *getSubExprAsWritten() const { 24056eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return const_cast<CastExpr *>(this)->getSubExprAsWritten(); 24066eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor } 240741b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson 2408f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall typedef CXXBaseSpecifier **path_iterator; 2409f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall typedef const CXXBaseSpecifier * const *path_const_iterator; 24108e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall bool path_empty() const { return CastExprBits.BasePathSize == 0; } 24118e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned path_size() const { return CastExprBits.BasePathSize; } 2412f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_iterator path_begin() { return path_buffer(); } 2413f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_iterator path_end() { return path_buffer() + path_size(); } 2414f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_const_iterator path_begin() const { return path_buffer(); } 2415f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_const_iterator path_end() const { return path_buffer() + path_size(); } 2416f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2417f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall void setCastPath(const CXXCastPath &Path); 241841b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson 24191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 24204bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return T->getStmtClass() >= firstCastExprConstant && 24214bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt T->getStmtClass() <= lastCastExprConstant; 24220835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis } 24230835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis static bool classof(const CastExpr *) { return true; } 24241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24250835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis // Iterators 242663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Op, &Op+1); } 24270835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis}; 24280835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis 242949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ImplicitCastExpr - Allows us to explicitly represent implicit type 243049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// conversions, which have no direct representation in the original 243149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// source code. For example: converting T[]->T*, void f()->void 243249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (*f)(), float->double, short->int, etc. 243349b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff/// 2434bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// In C, implicit casts always produce rvalues. However, in C++, an 2435bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// implicit cast whose result is being bound to a reference will be 2436906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// an lvalue or xvalue. For example: 2437bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// 2438bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @code 2439bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Base { }; 2440bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Derived : public Base { }; 2441906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// Derived &&ref(); 24421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// void f(Derived d) { 2443906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// Base& b = d; // initializer is an ImplicitCastExpr 2444906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// // to an lvalue of type Base 2445906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// Base&& r = ref(); // initializer is an ImplicitCastExpr 2446906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// // to an xvalue of type Base 2447bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// } 2448bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @endcode 24490835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ImplicitCastExpr : public CastExpr { 2450906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redlprivate: 2451f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ImplicitCastExpr(QualType ty, CastKind kind, Expr *op, 24525baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall unsigned BasePathLength, ExprValueKind VK) 2453f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, BasePathLength) { 24545baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall } 245590045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff 2456087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor /// \brief Construct an empty implicit cast. 2457f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall explicit ImplicitCastExpr(EmptyShell Shell, unsigned PathSize) 2458f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : CastExpr(ImplicitCastExprClass, Shell, PathSize) { } 2459f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2460f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 2461f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall enum OnStack_t { OnStack }; 2462f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ImplicitCastExpr(OnStack_t _, QualType ty, CastKind kind, Expr *op, 24635baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall ExprValueKind VK) 2464f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, 0) { 24655baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall } 2466f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2467f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static ImplicitCastExpr *Create(ASTContext &Context, QualType T, 2468f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastKind Kind, Expr *Operand, 2469f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXCastPath *BasePath, 24705baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall ExprValueKind Cat); 2471f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2472f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static ImplicitCastExpr *CreateEmpty(ASTContext &Context, unsigned PathSize); 2473087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor 247463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 24750835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis return getSubExpr()->getSourceRange(); 24760835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis } 247790045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff 24781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 24791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ImplicitCastExprClass; 248049b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff } 248149b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff static bool classof(const ImplicitCastExpr *) { return true; } 248249b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff}; 248349b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff 248491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCallinline Expr *Expr::IgnoreImpCasts() { 248591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall Expr *e = this; 248691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall while (ImplicitCastExpr *ice = dyn_cast<ImplicitCastExpr>(e)) 248791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall e = ice->getSubExpr(); 248891a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall return e; 248991a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall} 249091a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 249149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ExplicitCastExpr - An explicit cast written in the source 24921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// code. 249349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// 249449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This class is effectively an abstract class, because it provides 249549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// the basic representation of an explicitly-written cast without 249649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// specifying which kind of cast (C cast, functional cast, static 249749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast, etc.) was written; specific derived classes represent the 249849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// particular style of cast and its location information. 24995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 250049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// Unlike implicit casts, explicit cast nodes have two different 250149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// types: the type that was written into the source code, and the 250249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// actual type of the expression as determined by semantic 250349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// analysis. These types may differ slightly. For example, in C++ one 250449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// can cast to a reference type, which indicates that the resulting 2505906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// expression will be an lvalue or xvalue. The reference type, however, 2506906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// will not be used as the type of the expression. 25070835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ExplicitCastExpr : public CastExpr { 25089d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// TInfo - Source type info for the (written) type 25099d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// this expression is casting to. 25109d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo; 251149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 251249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorprotected: 2513f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExplicitCastExpr(StmtClass SC, QualType exprTy, ExprValueKind VK, 2514f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CastKind kind, Expr *op, unsigned PathSize, 2515f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall TypeSourceInfo *writtenTy) 2516f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : CastExpr(SC, exprTy, VK, kind, op, PathSize), TInfo(writtenTy) {} 251749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 2518db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty explicit cast. 2519f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ExplicitCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize) 2520f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : CastExpr(SC, Shell, PathSize) { } 2521db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 252249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorpublic: 25239d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// getTypeInfoAsWritten - Returns the type source info for the type 25249d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// that this expression is casting to. 25259d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *getTypeInfoAsWritten() const { return TInfo; } 25269d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall void setTypeInfoAsWritten(TypeSourceInfo *writtenTy) { TInfo = writtenTy; } 25279d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall 252849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// getTypeAsWritten - Returns the type that this expression is 252949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// casting to, as written in the source code. 25309d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall QualType getTypeAsWritten() const { return TInfo->getType(); } 253149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 25321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 25334bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return T->getStmtClass() >= firstExplicitCastExprConstant && 25344bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt T->getStmtClass() <= lastExplicitCastExprConstant; 253549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor } 253649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor static bool classof(const ExplicitCastExpr *) { return true; } 253749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor}; 253849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 25396eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor/// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style 254049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast in C++ (C++ [expr.cast]), which uses the syntax 254149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (Type)expr. For example: @c (int)f. 25426eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregorclass CStyleCastExpr : public ExplicitCastExpr { 2543b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation LPLoc; // the location of the left paren 2544b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation RPLoc; // the location of the right paren 2545f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2546f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CStyleCastExpr(QualType exprTy, ExprValueKind vk, CastKind kind, Expr *op, 2547f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned PathSize, TypeSourceInfo *writtenTy, 254841b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson SourceLocation l, SourceLocation r) 2549f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : ExplicitCastExpr(CStyleCastExprClass, exprTy, vk, kind, op, PathSize, 255041b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson writtenTy), LPLoc(l), RPLoc(r) {} 255149b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff 2552db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty C-style explicit cast. 2553f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall explicit CStyleCastExpr(EmptyShell Shell, unsigned PathSize) 2554f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : ExplicitCastExpr(CStyleCastExprClass, Shell, PathSize) { } 2555f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2556f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 2557f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall static CStyleCastExpr *Create(ASTContext &Context, QualType T, 2558f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, CastKind K, 2559f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall Expr *Op, const CXXCastPath *BasePath, 2560f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall TypeSourceInfo *WrittenTy, SourceLocation L, 2561f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall SourceLocation R); 2562f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2563f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CStyleCastExpr *CreateEmpty(ASTContext &Context, unsigned PathSize); 2564db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 2565b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation getLParenLoc() const { return LPLoc; } 2566db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setLParenLoc(SourceLocation L) { LPLoc = L; } 2567db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 2568b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation getRParenLoc() const { return RPLoc; } 2569db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setRParenLoc(SourceLocation L) { RPLoc = L; } 2570db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 257163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 2572b2f9e516327310d95840d442416084508f80c183Steve Naroff return SourceRange(LPLoc, getSubExpr()->getSourceRange().getEnd()); 25735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 25741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 25751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CStyleCastExprClass; 25765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 25776eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor static bool classof(const CStyleCastExpr *) { return true; } 25785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 25795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 25803fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// \brief A builtin binary operation expression such as "x + y" or "x <= y". 25813fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 25823fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// This expression node kind describes a builtin binary operation, 25833fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// such as "x + y" for integer values "x" and "y". The operands will 25843fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// already have been converted to appropriate types (e.g., by 25853fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// performing promotions or conversions). 25863fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 25873fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// In C++, where operators may be overloaded, a different kind of 25883fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// expression node (CXXOperatorCallExpr) is used to express the 25893fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// invocation of an overloaded operator with operator syntax. Within 25903fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is 25913fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to store an expression "x + y" depends on the subexpressions 25923fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// for x and y. If neither x or y is type-dependent, and the "+" 25933fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// operator resolves to a built-in operation, BinaryOperator will be 25943fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to express the computation (x and y may still be 25953fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// value-dependent). If either x or y is type-dependent, or if the 25963fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// "+" resolves to an overloaded operator, CXXOperatorCallExpr will 25973fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// be used to express the computation. 25985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BinaryOperator : public Expr { 25995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 26005baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall typedef BinaryOperatorKind Opcode; 26015baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 260217d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattnerprivate: 26030799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall unsigned Opc : 6; 26040799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall SourceLocation OpLoc; 26050799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall 260617d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner enum { LHS, RHS, END_EXPR }; 26075549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; 26081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 26091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 261017d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 2611f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 261217d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation opLoc) 2613f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(BinaryOperatorClass, ResTy, VK, OK, 2614898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor lhs->isTypeDependent() || rhs->isTypeDependent(), 2615bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor lhs->isValueDependent() || rhs->isValueDependent(), 2616561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (lhs->isInstantiationDependent() || 2617561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhs->isInstantiationDependent()), 2618bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (lhs->containsUnexpandedParameterPack() || 2619bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhs->containsUnexpandedParameterPack())), 2620898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Opc(opc), OpLoc(opLoc) { 26211237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 26221237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 26231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(!isCompoundAssignmentOp() && 26245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Use ArithAssignBinaryOperator for compound assignments"); 26255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 26265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2627db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty binary operator. 26281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit BinaryOperator(EmptyShell Empty) 26292de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall : Expr(BinaryOperatorClass, Empty), Opc(BO_Comma) { } 2630db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 263117d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation getOperatorLoc() const { return OpLoc; } 2632db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setOperatorLoc(SourceLocation L) { OpLoc = L; } 2633db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 26340799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Opcode getOpcode() const { return static_cast<Opcode>(Opc); } 2635db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setOpcode(Opcode O) { Opc = O; } 2636db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 26375549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 2638db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 26395549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 2640db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 2641db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 264263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 26435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd()); 26445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 26451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 26465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 26475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// corresponds to, e.g. "<<=". 26485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static const char *getOpcodeStr(Opcode Op); 26495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 26500799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall const char *getOpcodeStr() const { return getOpcodeStr(getOpcode()); } 2651a84c02d0f4d63975a1c52b9bb8308d88e9d79352Ted Kremenek 2652063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// \brief Retrieve the binary opcode that corresponds to the given 2653063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// overloaded operator. 2654063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static Opcode getOverloadedOpcode(OverloadedOperatorKind OO); 2655063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 2656063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// \brief Retrieve the overloaded operator kind that corresponds to 2657063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// the given binary opcode. 2658063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); 2659063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 26605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// predicates to categorize the respective opcodes. 2661200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl bool isPtrMemOp() const { return Opc == BO_PtrMemD || Opc == BO_PtrMemI; } 26622de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall bool isMultiplicativeOp() const { return Opc >= BO_Mul && Opc <= BO_Rem; } 26632de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isAdditiveOp(Opcode Opc) { return Opc == BO_Add || Opc==BO_Sub; } 26640799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isAdditiveOp() const { return isAdditiveOp(getOpcode()); } 26652de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isShiftOp(Opcode Opc) { return Opc == BO_Shl || Opc == BO_Shr; } 26660799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isShiftOp() const { return isShiftOp(getOpcode()); } 2667aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl 26682de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isBitwiseOp(Opcode Opc) { return Opc >= BO_And && Opc <= BO_Or; } 26690799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isBitwiseOp() const { return isBitwiseOp(getOpcode()); } 2670f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 26712de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isRelationalOp(Opcode Opc) { return Opc >= BO_LT && Opc<=BO_GE; } 26720799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isRelationalOp() const { return isRelationalOp(getOpcode()); } 2673f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 26742de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isEqualityOp(Opcode Opc) { return Opc == BO_EQ || Opc == BO_NE; } 26750799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isEqualityOp() const { return isEqualityOp(getOpcode()); } 26761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 26772de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isComparisonOp(Opcode Opc) { return Opc >= BO_LT && Opc<=BO_NE; } 26780799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isComparisonOp() const { return isComparisonOp(getOpcode()); } 2679aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl 26802de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isLogicalOp(Opcode Opc) { return Opc == BO_LAnd || Opc==BO_LOr; } 26810799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isLogicalOp() const { return isLogicalOp(getOpcode()); } 2682f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 26830e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall static bool isAssignmentOp(Opcode Opc) { 26840e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall return Opc >= BO_Assign && Opc <= BO_OrAssign; 26850e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall } 26860e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall bool isAssignmentOp() const { return isAssignmentOp(getOpcode()); } 26870e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall 26880e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall static bool isCompoundAssignmentOp(Opcode Opc) { 26892de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Opc > BO_Assign && Opc <= BO_OrAssign; 26902de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 26910e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall bool isCompoundAssignmentOp() const { 26920e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall return isCompoundAssignmentOp(getOpcode()); 26930e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall } 26940e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall 26950e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall static bool isShiftAssignOp(Opcode Opc) { 26962de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Opc == BO_ShlAssign || Opc == BO_ShrAssign; 26972de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 26980e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall bool isShiftAssignOp() const { 26990e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall return isShiftAssignOp(getOpcode()); 27000e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall } 27011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *S) { 27034bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return S->getStmtClass() >= firstBinaryOperatorConstant && 27044bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt S->getStmtClass() <= lastBinaryOperatorConstant; 27055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 27065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const BinaryOperator *) { return true; } 27071237c673c07f9d827129ba02720108816abde562Ted Kremenek 27081237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 270963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 271063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 271163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 27121237c673c07f9d827129ba02720108816abde562Ted Kremenek 27135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 271417d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 2715f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 27162333f7727f97018d6742e1e0938133bcfad967abEli Friedman SourceLocation opLoc, bool dead) 2717f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CompoundAssignOperatorClass, ResTy, VK, OK, 27182333f7727f97018d6742e1e0938133bcfad967abEli Friedman lhs->isTypeDependent() || rhs->isTypeDependent(), 2719bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor lhs->isValueDependent() || rhs->isValueDependent(), 2720561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (lhs->isInstantiationDependent() || 2721561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhs->isInstantiationDependent()), 2722bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (lhs->containsUnexpandedParameterPack() || 2723bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhs->containsUnexpandedParameterPack())), 27242333f7727f97018d6742e1e0938133bcfad967abEli Friedman Opc(opc), OpLoc(opLoc) { 27251237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 27261237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 27275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2728ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 27291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump BinaryOperator(StmtClass SC, EmptyShell Empty) 27302de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall : Expr(SC, Empty), Opc(BO_MulAssign) { } 27315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 27325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 27335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep 27345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// track of the type the operation is performed in. Due to the semantics of 2735ec5bc81fd55bfcc26fc4bde6d5e33113d94c2209Zhongxing Xu/// these operators, the operands are promoted, the arithmetic performed, an 27365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// implicit conversion back to the result type done, then the assignment takes 27375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// place. This captures the intermediate type which the computation is done 27385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// in. 27395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CompoundAssignOperator : public BinaryOperator { 2740ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType ComputationLHSType; 2741ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType ComputationResultType; 27425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 2743f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResType, 2744f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 2745f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType CompLHSType, QualType CompResultType, 274617d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation OpLoc) 2747f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : BinaryOperator(lhs, rhs, opc, ResType, VK, OK, OpLoc, true), 2748ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman ComputationLHSType(CompLHSType), 2749ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman ComputationResultType(CompResultType) { 27501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(isCompoundAssignmentOp() && 27515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Only should be used for compound assignments"); 27525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 27535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2754ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor /// \brief Build an empty compound assignment operator expression. 2755ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor explicit CompoundAssignOperator(EmptyShell Empty) 2756ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor : BinaryOperator(CompoundAssignOperatorClass, Empty) { } 2757ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 2758ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // The two computation types are the type the LHS is converted 2759ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // to for the computation and the type of the result; the two are 2760ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // distinct in a few cases (specifically, int+=ptr and ptr-=ptr). 2761ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType getComputationLHSType() const { return ComputationLHSType; } 2762ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setComputationLHSType(QualType T) { ComputationLHSType = T; } 2763ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 2764ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType getComputationResultType() const { return ComputationResultType; } 2765ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setComputationResultType(QualType T) { ComputationResultType = T; } 2766ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 27675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CompoundAssignOperator *) { return true; } 27681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *S) { 27691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return S->getStmtClass() == CompoundAssignOperatorClass; 27705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 27715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 27725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 277356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// AbstractConditionalOperator - An abstract base class for 277456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// ConditionalOperator and BinaryConditionalOperator. 277556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass AbstractConditionalOperator : public Expr { 277656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation QuestionLoc, ColonLoc; 277756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall friend class ASTStmtReader; 277856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 277956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallprotected: 278056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall AbstractConditionalOperator(StmtClass SC, QualType T, 278156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall ExprValueKind VK, ExprObjectKind OK, 2782561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool TD, bool VD, bool ID, 278356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall bool ContainsUnexpandedParameterPack, 278456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation qloc, 278556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation cloc) 2786561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Expr(SC, T, VK, OK, TD, VD, ID, ContainsUnexpandedParameterPack), 278756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall QuestionLoc(qloc), ColonLoc(cloc) {} 278856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 278956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall AbstractConditionalOperator(StmtClass SC, EmptyShell Empty) 279056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : Expr(SC, Empty) { } 279156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 279256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallpublic: 279356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getCond - Return the expression representing the condition for 279456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the ?: operator. 279556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getCond() const; 279656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 279756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getTrueExpr - Return the subexpression representing the value of 279856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the expression if the condition evaluates to true. 279956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getTrueExpr() const; 280056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 280156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getFalseExpr - Return the subexpression representing the value of 280256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the expression if the condition evaluates to false. This is 280356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the same as getRHS. 280456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getFalseExpr() const; 280556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 280656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation getQuestionLoc() const { return QuestionLoc; } 280756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation getColonLoc() const { return ColonLoc; } 280856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 280956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const Stmt *T) { 281056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return T->getStmtClass() == ConditionalOperatorClass || 281156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall T->getStmtClass() == BinaryConditionalOperatorClass; 281256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 281356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const AbstractConditionalOperator *) { return true; } 281456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall}; 281556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 281656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// ConditionalOperator - The ?: ternary operator. The GNU "missing 281756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// middle" extension is a BinaryConditionalOperator. 281856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass ConditionalOperator : public AbstractConditionalOperator { 28191237c673c07f9d827129ba02720108816abde562Ted Kremenek enum { COND, LHS, RHS, END_EXPR }; 28205549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 282156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 282256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall friend class ASTStmtReader; 28235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 282447e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor ConditionalOperator(Expr *cond, SourceLocation QLoc, Expr *lhs, 282556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation CLoc, Expr *rhs, 28260943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall QualType t, ExprValueKind VK, ExprObjectKind OK) 282756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : AbstractConditionalOperator(ConditionalOperatorClass, t, VK, OK, 2828898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // FIXME: the type of the conditional operator doesn't 2829898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // depend on the type of the conditional, but the standard 2830898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // seems to imply that it could. File a bug! 283156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (lhs->isTypeDependent() || rhs->isTypeDependent()), 283256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (cond->isValueDependent() || lhs->isValueDependent() || 283356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall rhs->isValueDependent()), 2834561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (cond->isInstantiationDependent() || 2835561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor lhs->isInstantiationDependent() || 2836561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhs->isInstantiationDependent()), 2837bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (cond->containsUnexpandedParameterPack() || 283856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall lhs->containsUnexpandedParameterPack() || 283956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall rhs->containsUnexpandedParameterPack()), 284056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall QLoc, CLoc) { 28411237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[COND] = cond; 28421237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 28431237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 28441237c673c07f9d827129ba02720108816abde562Ted Kremenek } 28455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2846ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor /// \brief Build an empty conditional operator. 2847ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor explicit ConditionalOperator(EmptyShell Empty) 284856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : AbstractConditionalOperator(ConditionalOperatorClass, Empty) { } 2849ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 2850395a2abf0028968d85958610e393e067885dc14fTed Kremenek // getCond - Return the expression representing the condition for 285156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the ?: operator. 28525549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 2853395a2abf0028968d85958610e393e067885dc14fTed Kremenek 285456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getTrueExpr - Return the subexpression representing the value of 285556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the expression if the condition evaluates to true. 285656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getTrueExpr() const { return cast<Expr>(SubExprs[LHS]); } 28571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 285856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getFalseExpr - Return the subexpression representing the value of 285956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the expression if the condition evaluates to false. This is 286056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the same as getRHS. 28615549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); } 2862f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian 286356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 28645549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 286547e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor 286663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 28675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd()); 28685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 28691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 28701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ConditionalOperatorClass; 28715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 28725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ConditionalOperator *) { return true; } 28731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28741237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 287563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 287663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 287763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 28785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 28795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 288056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// BinaryConditionalOperator - The GNU extension to the conditional 288156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// operator which allows the middle operand to be omitted. 288256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// 288356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// This is a different expression kind on the assumption that almost 288456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// every client ends up needing to know that these are different. 288556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass BinaryConditionalOperator : public AbstractConditionalOperator { 288656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall enum { COMMON, COND, LHS, RHS, NUM_SUBEXPRS }; 288756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 288856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// - the common condition/left-hand-side expression, which will be 288956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// evaluated as the opaque value 289056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// - the condition, expressed in terms of the opaque value 289156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// - the left-hand-side, expressed in terms of the opaque value 289256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// - the right-hand-side 289356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Stmt *SubExprs[NUM_SUBEXPRS]; 289456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValueExpr *OpaqueValue; 289556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 289656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall friend class ASTStmtReader; 289756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallpublic: 289856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall BinaryConditionalOperator(Expr *common, OpaqueValueExpr *opaqueValue, 289956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *cond, Expr *lhs, Expr *rhs, 290056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation qloc, SourceLocation cloc, 290156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall QualType t, ExprValueKind VK, ExprObjectKind OK) 290256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : AbstractConditionalOperator(BinaryConditionalOperatorClass, t, VK, OK, 290356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (common->isTypeDependent() || rhs->isTypeDependent()), 290456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (common->isValueDependent() || rhs->isValueDependent()), 2905561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (common->isInstantiationDependent() || 2906561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhs->isInstantiationDependent()), 290756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (common->containsUnexpandedParameterPack() || 290856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall rhs->containsUnexpandedParameterPack()), 290956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall qloc, cloc), 291056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValue(opaqueValue) { 291156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SubExprs[COMMON] = common; 291256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SubExprs[COND] = cond; 291356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SubExprs[LHS] = lhs; 291456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SubExprs[RHS] = rhs; 291556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 291656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValue->setSourceExpr(common); 291756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 291856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 291956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief Build an empty conditional operator. 292056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall explicit BinaryConditionalOperator(EmptyShell Empty) 292156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : AbstractConditionalOperator(BinaryConditionalOperatorClass, Empty) { } 292256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 292356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getCommon - Return the common expression, written to the 292456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// left of the condition. The opaque value will be bound to the 292556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// result of this expression. 292656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getCommon() const { return cast<Expr>(SubExprs[COMMON]); } 292756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 292856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getOpaqueValue - Return the opaque value placeholder. 292956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValueExpr *getOpaqueValue() const { return OpaqueValue; } 293056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 293156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getCond - Return the condition expression; this is defined 293256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// in terms of the opaque value. 293356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 293456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 293556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getTrueExpr - Return the subexpression which will be 293656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// evaluated if the condition evaluates to true; this is defined 293756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// in terms of the opaque value. 293856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getTrueExpr() const { 293956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<Expr>(SubExprs[LHS]); 294056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 294156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 294256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getFalseExpr - Return the subexpression which will be 294356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// evaluated if the condnition evaluates to false; this is 294456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// defined in terms of the opaque value. 294556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getFalseExpr() const { 294656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<Expr>(SubExprs[RHS]); 294756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 294856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 294956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceRange getSourceRange() const { 295056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return SourceRange(getCommon()->getLocStart(), getFalseExpr()->getLocEnd()); 295156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 295256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const Stmt *T) { 295356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return T->getStmtClass() == BinaryConditionalOperatorClass; 295456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 295556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const BinaryConditionalOperator *) { return true; } 295656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 295756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // Iterators 295856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall child_range children() { 295956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return child_range(SubExprs, SubExprs + NUM_SUBEXPRS); 296056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 296156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall}; 296256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 296356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallinline Expr *AbstractConditionalOperator::getCond() const { 296456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this)) 296556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return co->getCond(); 296656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<BinaryConditionalOperator>(this)->getCond(); 296756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall} 296856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 296956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallinline Expr *AbstractConditionalOperator::getTrueExpr() const { 297056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this)) 297156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return co->getTrueExpr(); 297256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<BinaryConditionalOperator>(this)->getTrueExpr(); 297356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall} 297456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 297556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallinline Expr *AbstractConditionalOperator::getFalseExpr() const { 297656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this)) 297756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return co->getFalseExpr(); 297856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<BinaryConditionalOperator>(this)->getFalseExpr(); 297956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall} 298056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 29816481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner/// AddrLabelExpr - The GNU address of label extension, representing &&label. 29826481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattnerclass AddrLabelExpr : public Expr { 29835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation AmpAmpLoc, LabelLoc; 2984ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *Label; 29855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 2986ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelDecl *L, 29876481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner QualType t) 2988561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Expr(AddrLabelExprClass, t, VK_RValue, OK_Ordinary, false, false, false, 2989561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false), 29902333f7727f97018d6742e1e0938133bcfad967abEli Friedman AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {} 29911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29927d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor /// \brief Build an empty address of a label expression. 29931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit AddrLabelExpr(EmptyShell Empty) 29947d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor : Expr(AddrLabelExprClass, Empty) { } 29957d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 29967d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; } 29977d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; } 29987d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor SourceLocation getLabelLoc() const { return LabelLoc; } 29997d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setLabelLoc(SourceLocation L) { LabelLoc = L; } 30007d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 300163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 30025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(AmpAmpLoc, LabelLoc); 30035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 30041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3005ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *getLabel() const { return Label; } 3006ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner void setLabel(LabelDecl *L) { Label = L; } 30077d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 30085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 30091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == AddrLabelExprClass; 30105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 30116481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner static bool classof(const AddrLabelExpr *) { return true; } 30121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30131237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 301463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 30155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 3016ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner 3017ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}). 3018ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// The StmtExpr contains a single CompoundStmt node, which it evaluates and 3019ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// takes the value of the last subexpression. 3020f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall/// 3021f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall/// A StmtExpr is always an r-value; values "returned" out of a 3022f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall/// StmtExpr will be copied. 3023ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerclass StmtExpr : public Expr { 30245549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *SubStmt; 3025ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner SourceLocation LParenLoc, RParenLoc; 3026ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerpublic: 30272333f7727f97018d6742e1e0938133bcfad967abEli Friedman // FIXME: Does type-dependence need to be computed differently? 3028561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor // FIXME: Do we need to compute instantiation instantiation-dependence for 3029561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor // statements? (ugh!) 3030d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff StmtExpr(CompoundStmt *substmt, QualType T, 3031d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff SourceLocation lp, SourceLocation rp) : 3032f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(StmtExprClass, T, VK_RValue, OK_Ordinary, 3033561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor T->isDependentType(), false, false, false), 30342333f7727f97018d6742e1e0938133bcfad967abEli Friedman SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) { } 30351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30366a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor /// \brief Build an empty statement expression. 30376a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { } 30386a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor 30395549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); } 30405549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); } 30416a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setSubStmt(CompoundStmt *S) { SubStmt = S; } 30426a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor 304363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 3044ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner return SourceRange(LParenLoc, RParenLoc); 3045ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner } 30461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3047026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getLParenLoc() const { return LParenLoc; } 30486a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setLParenLoc(SourceLocation L) { LParenLoc = L; } 3049026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getRParenLoc() const { return RParenLoc; } 30506a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 30511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3052ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner static bool classof(const Stmt *T) { 30531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == StmtExprClass; 3054ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner } 3055ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner static bool classof(const StmtExpr *) { return true; } 30561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30571237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 305863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&SubStmt, &SubStmt+1); } 3059ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner}; 3060ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner 3061d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff 3062d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// ShuffleVectorExpr - clang-specific builtin-in function 3063d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// __builtin_shufflevector. 3064d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// This AST node represents a operator that does a constant 3065d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// shuffle, similar to LLVM's shufflevector instruction. It takes 3066d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// two vectors and a variable number of constant indices, 3067d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// and returns the appropriately shuffled vector. 3068d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanclass ShuffleVectorExpr : public Expr { 3069d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman SourceLocation BuiltinLoc, RParenLoc; 3070d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 3071d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // SubExprs - the list of values passed to the __builtin_shufflevector 3072d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // function. The first two are vectors, and the rest are constant 3073d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // indices. The number of values in this list is always 3074d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // 2+the number of indices in the vector type. 30755549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt **SubExprs; 3076d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman unsigned NumExprs; 3077d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 3078d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanpublic: 3079a88dc3079bedf70a5cfc39791727e43a10383006Nate Begeman ShuffleVectorExpr(ASTContext &C, Expr **args, unsigned nexpr, 30801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType Type, SourceLocation BLoc, 3081bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor SourceLocation RP); 308294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 308394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor /// \brief Build an empty vector-shuffle expression. 30841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ShuffleVectorExpr(EmptyShell Empty) 308594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor : Expr(ShuffleVectorExprClass, Empty), SubExprs(0) { } 308694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 308794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 308894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 30891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 309094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 309194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 309294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 309363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 3094d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman return SourceRange(BuiltinLoc, RParenLoc); 3095d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 3096d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman static bool classof(const Stmt *T) { 30971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ShuffleVectorExprClass; 3098d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 3099d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman static bool classof(const ShuffleVectorExpr *) { return true; } 31001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3101d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// getNumSubExprs - Return the size of the SubExprs array. This includes the 3102d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// constant expression, the actual arguments passed in, and the function 3103d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// pointers. 3104d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman unsigned getNumSubExprs() const { return NumExprs; } 31051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3106aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \brief Retrieve the array of expressions. 3107aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Expr **getSubExprs() { return reinterpret_cast<Expr **>(SubExprs); } 3108aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 3109d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// getExpr - Return the Expr at the specified index. 3110d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman Expr *getExpr(unsigned Index) { 3111d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman assert((Index < NumExprs) && "Arg access out of range!"); 31125549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Index]); 3113d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 3114d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman const Expr *getExpr(unsigned Index) const { 3115d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman assert((Index < NumExprs) && "Arg access out of range!"); 31165549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Index]); 3117d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 31181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3119888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman void setExprs(ASTContext &C, Expr ** Exprs, unsigned NumExprs); 312094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 3121dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman unsigned getShuffleMaskIdx(ASTContext &Ctx, unsigned N) { 3122dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman assert((N < NumExprs - 2) && "Shuffle idx out of range!"); 3123a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith return getExpr(N+2)->EvaluateKnownConstInt(Ctx).getZExtValue(); 3124d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 31251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3126d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // Iterators 312763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 312863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+NumExprs); 312963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 3130d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman}; 3131d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 3132d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// ChooseExpr - GNU builtin-in function __builtin_choose_expr. 31331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// This AST node is similar to the conditional operator (?:) in C, with 3134d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// the following exceptions: 31357976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the test expression must be a integer constant expression. 31367976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the expression returned acts like the chosen subexpression in every 31377976932a1c256d447316ffac58e9821417725e34Eli Friedman/// visible way: the type is the same as that of the chosen subexpression, 31387976932a1c256d447316ffac58e9821417725e34Eli Friedman/// and all predicates (whether it's an l-value, whether it's an integer 31397976932a1c256d447316ffac58e9821417725e34Eli Friedman/// constant expression, etc.) return the same result as for the chosen 31407976932a1c256d447316ffac58e9821417725e34Eli Friedman/// sub-expression. 3141d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffclass ChooseExpr : public Expr { 31421237c673c07f9d827129ba02720108816abde562Ted Kremenek enum { COND, LHS, RHS, END_EXPR }; 31435549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 3144d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff SourceLocation BuiltinLoc, RParenLoc; 3145d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffpublic: 3146f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, 3147f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType t, ExprValueKind VK, ExprObjectKind OK, 3148ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor SourceLocation RP, bool TypeDependent, bool ValueDependent) 3149bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(ChooseExprClass, t, VK, OK, TypeDependent, ValueDependent, 3150561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (cond->isInstantiationDependent() || 3151561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor lhs->isInstantiationDependent() || 3152561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhs->isInstantiationDependent()), 3153bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (cond->containsUnexpandedParameterPack() || 3154bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor lhs->containsUnexpandedParameterPack() || 3155bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhs->containsUnexpandedParameterPack())), 31561237c673c07f9d827129ba02720108816abde562Ted Kremenek BuiltinLoc(BLoc), RParenLoc(RP) { 31571237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[COND] = cond; 31581237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 31591237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 31601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 31617976932a1c256d447316ffac58e9821417725e34Eli Friedman 316244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor /// \brief Build an empty __builtin_choose_expr. 316344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { } 316444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 31657976932a1c256d447316ffac58e9821417725e34Eli Friedman /// isConditionTrue - Return whether the condition is true (i.e. not 31667976932a1c256d447316ffac58e9821417725e34Eli Friedman /// equal to zero). 31674ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool isConditionTrue(const ASTContext &C) const; 31687976932a1c256d447316ffac58e9821417725e34Eli Friedman 31697976932a1c256d447316ffac58e9821417725e34Eli Friedman /// getChosenSubExpr - Return the subexpression chosen according to the 31707976932a1c256d447316ffac58e9821417725e34Eli Friedman /// condition. 31714ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad Expr *getChosenSubExpr(const ASTContext &C) const { 31727976932a1c256d447316ffac58e9821417725e34Eli Friedman return isConditionTrue(C) ? getLHS() : getRHS(); 31737976932a1c256d447316ffac58e9821417725e34Eli Friedman } 31747976932a1c256d447316ffac58e9821417725e34Eli Friedman 31755549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 317644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setCond(Expr *E) { SubExprs[COND] = E; } 31775549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 317844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 31795549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 318044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 318144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 318244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 318344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 31841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 318544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 318644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 31871237c673c07f9d827129ba02720108816abde562Ted Kremenek 318863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 3189d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff return SourceRange(BuiltinLoc, RParenLoc); 3190d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff } 3191d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff static bool classof(const Stmt *T) { 31921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ChooseExprClass; 3193d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff } 3194d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff static bool classof(const ChooseExpr *) { return true; } 31951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 31961237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 319763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 319863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 319963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 3200d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff}; 3201d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff 32022d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// GNUNullExpr - Implements the GNU __null extension, which is a name 32032d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// for a null pointer constant that has integral type (e.g., int or 32042d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// long) and is the same size and alignment as a pointer. The __null 32052d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// extension is typically only used by system headers, which define 32062d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// NULL as __null in C++ rather than using 0 (which is an integer 32072d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// that may not match the size of a pointer). 32082d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorclass GNUNullExpr : public Expr { 32092d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor /// TokenLoc - The location of the __null keyword. 32102d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor SourceLocation TokenLoc; 32112d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 32122d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorpublic: 32131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump GNUNullExpr(QualType Ty, SourceLocation Loc) 3214561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Expr(GNUNullExprClass, Ty, VK_RValue, OK_Ordinary, false, false, false, 3215561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false), 3216f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall TokenLoc(Loc) { } 32172d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 321844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor /// \brief Build an empty GNU __null expression. 321944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { } 322044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 32212d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor /// getTokenLocation - The location of the __null token. 32222d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor SourceLocation getTokenLocation() const { return TokenLoc; } 322344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setTokenLocation(SourceLocation L) { TokenLoc = L; } 32242d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 322563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 32262d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor return SourceRange(TokenLoc); 32272d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } 32282d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor static bool classof(const Stmt *T) { 32291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == GNUNullExprClass; 32302d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } 32312d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor static bool classof(const GNUNullExpr *) { return true; } 32321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32332d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor // Iterators 323463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 32352d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor}; 32362d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 323774626d6ef2e194fcc911e071556660ff331eb4a8Zhongxing Xu/// VAArgExpr, used for the builtin function __builtin_va_arg. 32387c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonclass VAArgExpr : public Expr { 32395549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 32402cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara TypeSourceInfo *TInfo; 32417c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson SourceLocation BuiltinLoc, RParenLoc; 32427c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonpublic: 32432cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara VAArgExpr(SourceLocation BLoc, Expr* e, TypeSourceInfo *TInfo, 32442cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara SourceLocation RPLoc, QualType t) 3245f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(VAArgExprClass, t, VK_RValue, OK_Ordinary, 3246bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor t->isDependentType(), false, 3247561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (TInfo->getType()->isInstantiationDependentType() || 3248561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor e->isInstantiationDependent()), 3249bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (TInfo->getType()->containsUnexpandedParameterPack() || 3250bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor e->containsUnexpandedParameterPack())), 32512cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara Val(e), TInfo(TInfo), 32527c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson BuiltinLoc(BLoc), 32537c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson RParenLoc(RPLoc) { } 32541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 325574626d6ef2e194fcc911e071556660ff331eb4a8Zhongxing Xu /// \brief Create an empty __builtin_va_arg expression. 3256d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor explicit VAArgExpr(EmptyShell Empty) : Expr(VAArgExprClass, Empty) { } 3257d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 32585549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 32595549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 3260d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 3261d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 32622cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara TypeSourceInfo *getWrittenTypeInfo() const { return TInfo; } 32632cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara void setWrittenTypeInfo(TypeSourceInfo *TI) { TInfo = TI; } 32642cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara 3265d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 3266d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 32671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3268d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 3269d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 3270d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 327163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 32727c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson return SourceRange(BuiltinLoc, RParenLoc); 32731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 32747c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson static bool classof(const Stmt *T) { 32757c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson return T->getStmtClass() == VAArgExprClass; 32767c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson } 32777c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson static bool classof(const VAArgExpr *) { return true; } 32781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32797c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson // Iterators 328063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Val, &Val+1); } 32817c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson}; 32821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32834c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @brief Describes an C or C++ initializer list. 32844c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// 32854c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// InitListExpr describes an initializer list, which can be used to 32864c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initialize objects of different types, including 32874c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct/class/union types, arrays, and vectors. For example: 32884c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// 32894c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @code 32904c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct foo x = { 1, { 2, 3 } }; 32914c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @endcode 3292196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 32934c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Prior to semantic analysis, an initializer list will represent the 32944c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer list as written by the user, but will have the 32954c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// placeholder type "void". This initializer list is called the 32964c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// syntactic form of the initializer, and may contain C99 designated 32974c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializers (represented as DesignatedInitExprs), initializations 32984c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// of subobject members without explicit braces, and so on. Clients 32994c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// interested in the original syntax of the initializer list should 33004c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// use the syntactic form of the initializer list. 3301196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 33024c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// After semantic analysis, the initializer list will represent the 33034c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// semantic form of the initializer, where the initializations of all 33044c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// subobjects are made explicit with nested InitListExpr nodes and 33054c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// C99 designators have been eliminated by placing the designated 33064c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializations into the subobject they initialize. Additionally, 33074c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// any "holes" in the initialization, where no initializer has been 33084c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// specified for a particular subobject, will be replaced with 33093498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// implicitly-generated ImplicitValueInitExpr expressions that 33104c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// value-initialize the subobjects. Note, however, that the 33114c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer lists may still have fewer initializers than there are 33124c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// elements to initialize within the object. 3313196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 33144c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Given the semantic form of the initializer list, one can retrieve 33154c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// the original syntactic form of that initializer list (if it 33164c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// exists) using getSyntacticForm(). Since many initializer lists 33174c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// have the same syntactic and semantic forms, getSyntacticForm() may 33184c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// return NULL, indicating that the current initializer list also 33194c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// serves as its syntactic form. 332066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonclass InitListExpr : public Expr { 3321ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek // FIXME: Eliminate this vector in favor of ASTContext allocation 3322709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek typedef ASTVector<Stmt *> InitExprsTy; 3323709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprsTy InitExprs; 332466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson SourceLocation LBraceLoc, RBraceLoc; 33251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 33264c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// Contains the initializer list that describes the syntactic form 33274c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// written in the source code. 33284c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitListExpr *SyntacticForm; 33294c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 33304423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// \brief Either: 33314423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// If this initializer list initializes an array with more elements than 33324423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// there are initializers in the list, specifies an expression to be used 33334423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// for value initialization of the rest of the elements. 33344423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// Or 33354423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// If this initializer list initializes a union, specifies which 33364423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// field within the union will be initialized. 33374423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis llvm::PointerUnion<Expr *, FieldDecl *> ArrayFillerOrUnionFieldInit; 33380bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor 3339a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor /// Whether this initializer list originally had a GNU array-range 3340a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor /// designator in it. This is a temporary marker used by CodeGen. 3341a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor bool HadArrayRangeDesignator; 3342a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor 334366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonpublic: 3344709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitListExpr(ASTContext &C, SourceLocation lbraceloc, 3345709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek Expr **initexprs, unsigned numinits, 3346ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek SourceLocation rbraceloc); 3347d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3348d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Build an empty initializer list. 3349709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek explicit InitListExpr(ASTContext &C, EmptyShell Empty) 3350709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek : Expr(InitListExprClass, Empty), InitExprs(C) { } 33511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3352ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek unsigned getNumInits() const { return InitExprs.size(); } 33531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3354aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \brief Retrieve the set of initializers. 3355aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Expr **getInits() { return reinterpret_cast<Expr **>(InitExprs.data()); } 3356aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 335716c5dea6c2d3e4cf529de9d9b37f6a40441acb2cChris Lattner const Expr *getInit(unsigned Init) const { 3358c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 33594c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return cast_or_null<Expr>(InitExprs[Init]); 336066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 33611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 336216c5dea6c2d3e4cf529de9d9b37f6a40441acb2cChris Lattner Expr *getInit(unsigned Init) { 3363c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 33644c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return cast_or_null<Expr>(InitExprs[Init]); 336566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 33661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 33671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setInit(unsigned Init, Expr *expr) { 3368c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 33699e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff InitExprs[Init] = expr; 33709e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff } 3371c5ae899b4bbf65488445316c63168079177db0edSteve Naroff 3372fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor /// \brief Reserve space for some number of initializers. 3373709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek void reserveInits(ASTContext &C, unsigned NumInits); 33741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 33754c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Specify the number of initializers 33764c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 33774c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// If there are more than @p NumInits initializers, the remaining 33784c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// initializers will be destroyed. If there are fewer than @p 33794c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// NumInits initializers, NULL expressions will be added for the 33804c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// unknown initializers. 33814c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor void resizeInits(ASTContext &Context, unsigned NumInits); 33824c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 33834c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Updates the initializer at index @p Init with the new 33844c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// expression @p expr, and returns the old expression at that 33854c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// location. 33864c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 33874c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// When @p Init is out of range for this initializer list, the 33884c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// initializer list will be extended with NULL expressions to 3389fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner /// accommodate the new entry. 3390709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek Expr *updateInit(ASTContext &C, unsigned Init, Expr *expr); 3391c5ae899b4bbf65488445316c63168079177db0edSteve Naroff 33924423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// \brief If this initializer list initializes an array with more elements 33934423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// than there are initializers in the list, specifies an expression to be 33944423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// used for value initialization of the rest of the elements. 33954423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis Expr *getArrayFiller() { 33964423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis return ArrayFillerOrUnionFieldInit.dyn_cast<Expr *>(); 33974423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis } 33988cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne const Expr *getArrayFiller() const { 33998cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne return const_cast<InitListExpr *>(this)->getArrayFiller(); 34008cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne } 34013e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis void setArrayFiller(Expr *filler); 34024423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis 34030bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// \brief If this initializes a union, specifies which field in the 34040bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// union to initialize. 34050bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// 34060bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// Typically, this field is the first named field within the 34070bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// union. However, a designated initializer can specify the 34080bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// initialization of a different field within the union. 34094423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis FieldDecl *getInitializedFieldInUnion() { 34104423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis return ArrayFillerOrUnionFieldInit.dyn_cast<FieldDecl *>(); 34114423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis } 34128cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne const FieldDecl *getInitializedFieldInUnion() const { 34138cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne return const_cast<InitListExpr *>(this)->getInitializedFieldInUnion(); 34148cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne } 34154423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis void setInitializedFieldInUnion(FieldDecl *FD) { 34164423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis ArrayFillerOrUnionFieldInit = FD; 34174423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis } 34180bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor 3419c5ae899b4bbf65488445316c63168079177db0edSteve Naroff // Explicit InitListExpr's originate from source code (and have valid source 3420c5ae899b4bbf65488445316c63168079177db0edSteve Naroff // locations). Implicit InitListExpr's are created by the semantic analyzer. 3421b3eef68111ffc220e449be96da1747998c057790Douglas Gregor bool isExplicit() { 3422b3eef68111ffc220e449be96da1747998c057790Douglas Gregor return LBraceLoc.isValid() && RBraceLoc.isValid(); 3423b3eef68111ffc220e449be96da1747998c057790Douglas Gregor } 34241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3425d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor SourceLocation getLBraceLoc() const { return LBraceLoc; } 3426d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setLBraceLoc(SourceLocation Loc) { LBraceLoc = Loc; } 3427d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor SourceLocation getRBraceLoc() const { return RBraceLoc; } 342887fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; } 342987fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor 34304c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Retrieve the initializer list that describes the 34314c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// syntactic form of the initializer. 34324c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 34331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 34344c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitListExpr *getSyntacticForm() const { return SyntacticForm; } 34354c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor void setSyntacticForm(InitListExpr *Init) { SyntacticForm = Init; } 34364c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 3437a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor bool hadArrayRangeDesignator() const { return HadArrayRangeDesignator; } 34381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void sawArrayRangeDesignator(bool ARD = true) { 3439d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor HadArrayRangeDesignator = ARD; 3440a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor } 3441a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor 344263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const; 3443c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek 344466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson static bool classof(const Stmt *T) { 34451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == InitListExprClass; 344666b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 344766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson static bool classof(const InitListExpr *) { return true; } 34481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 344966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson // Iterators 345063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 345163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall if (InitExprs.empty()) return child_range(); 345263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&InitExprs[0], &InitExprs[0] + InitExprs.size()); 345363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 34541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3455709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek typedef InitExprsTy::iterator iterator; 34568111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu typedef InitExprsTy::const_iterator const_iterator; 3457709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek typedef InitExprsTy::reverse_iterator reverse_iterator; 34588111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu typedef InitExprsTy::const_reverse_iterator const_reverse_iterator; 34591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3460ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek iterator begin() { return InitExprs.begin(); } 34618111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_iterator begin() const { return InitExprs.begin(); } 3462ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek iterator end() { return InitExprs.end(); } 34638111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_iterator end() const { return InitExprs.end(); } 3464ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek reverse_iterator rbegin() { return InitExprs.rbegin(); } 34658111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_reverse_iterator rbegin() const { return InitExprs.rbegin(); } 3466ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek reverse_iterator rend() { return InitExprs.rend(); } 34678111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_reverse_iterator rend() const { return InitExprs.rend(); } 34684423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis 34694423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis friend class ASTStmtReader; 34704423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis friend class ASTStmtWriter; 347166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson}; 347266b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson 347305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @brief Represents a C99 designated initializer expression. 347405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// 347505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// A designated initializer expression (C99 6.7.8) contains one or 347605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// more designators (which can be field designators, array 347705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, or GNU array-range designators) followed by an 347805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// expression that initializes the field or element(s) that the 347905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators refer to. For example, given: 34801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 348105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @code 348205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point { 348305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// double x; 348405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// double y; 348505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// }; 348605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 }; 348705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @endcode 348805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// 348905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// The InitListExpr contains three DesignatedInitExprs, the first of 349005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// which covers @c [2].y=1.0. This DesignatedInitExpr will have two 349105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, one array designator for @c [2] followed by one field 349205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designator for @c .y. The initalization expression will be 1.0. 349305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorclass DesignatedInitExpr : public Expr { 3494ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorpublic: 3495ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief Forward declaration of the Designator class. 3496ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor class Designator; 3497ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 3498ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorprivate: 349905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '=' or ':' prior to the actual initializer 350005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// expression. 350105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EqualOrColonLoc; 350205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3503eeae8f072748affce25ab4064982626361293390Douglas Gregor /// Whether this designated initializer used the GNU deprecated 350405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// syntax rather than the C99 '=' syntax. 3505eeae8f072748affce25ab4064982626361293390Douglas Gregor bool GNUSyntax : 1; 350605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 350705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The number of designators in this initializer expression. 350805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators : 15; 350905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3510ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief The designators in this designated initialization 3511ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// expression. 3512ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designator *Designators; 3513ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 351405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The number of subexpressions of this initializer expression, 351505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// which contains both the initializer and any additional 351605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// expressions used by array and array-range designators. 351705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumSubExprs : 16; 351805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3519ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 3520319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor DesignatedInitExpr(ASTContext &C, QualType Ty, unsigned NumDesignators, 3521ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Designators, 3522eeae8f072748affce25ab4064982626361293390Douglas Gregor SourceLocation EqualOrColonLoc, bool GNUSyntax, 35239ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr **IndexExprs, unsigned NumIndexExprs, 35249ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *Init); 352505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3526d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor explicit DesignatedInitExpr(unsigned NumSubExprs) 3527d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor : Expr(DesignatedInitExprClass, EmptyShell()), 3528d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor NumDesignators(0), Designators(0), NumSubExprs(NumSubExprs) { } 3529d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 353005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorpublic: 353105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// A field designator, e.g., ".x". 353205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct FieldDesignator { 353305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// Refers to the field that is being initialized. The low bit 353405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// of this field determines whether this is actually a pointer 353505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When 353605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initially constructed, a field designator will store an 353705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// IdentifierInfo*. After semantic analysis has resolved that 353805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// name, the field designator will instead store a FieldDecl*. 353905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor uintptr_t NameOrField; 35401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 354105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '.' in the designated initializer. 354205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned DotLoc; 35431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 354405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the field name in the designated initializer. 354505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned FieldLoc; 354605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 354705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 354805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". 354905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct ArrayOrRangeDesignator { 355005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// Location of the first index expression within the designated 355105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initializer expression's list of subexpressions. 355205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned Index; 355305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '[' starting the array range designator. 355405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned LBracketLoc; 355505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the ellipsis separating the start and end 355605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// indices. Only valid for GNU array-range designators. 355705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned EllipsisLoc; 355805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the ']' terminating the array range designator. 35591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned RBracketLoc; 356005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 356105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 356205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Represents a single C99 designator. 356305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// 356405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @todo This class is infuriatingly similar to clang::Designator, 356505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// but minor differences (storing indices vs. storing pointers) 356605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// keep us from reusing it. Try harder, later, to rectify these 356705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// differences. 356805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor class Designator { 356905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief The kind of designator this describes. 357005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor enum { 357105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor FieldDesignator, 357205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayDesignator, 357305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayRangeDesignator 357405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } Kind; 357505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 357605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor union { 357705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// A field designator, e.g., ".x". 357805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct FieldDesignator Field; 357905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". 358005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct ArrayOrRangeDesignator ArrayOrRange; 358105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 358205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor friend class DesignatedInitExpr; 358305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 358405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor public: 3585ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designator() {} 3586ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 358705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes a field designator. 35881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc, 35891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation FieldLoc) 359005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(FieldDesignator) { 359105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01; 359205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.DotLoc = DotLoc.getRawEncoding(); 359305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.FieldLoc = FieldLoc.getRawEncoding(); 359405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 359505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 359605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes an array designator. 35971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(unsigned Index, SourceLocation LBracketLoc, 359805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation RBracketLoc) 359905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(ArrayDesignator) { 360005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.Index = Index; 360105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding(); 360205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding(); 360305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding(); 360405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 360505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 360605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes a GNU array-range designator. 36071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(unsigned Index, SourceLocation LBracketLoc, 360805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EllipsisLoc, SourceLocation RBracketLoc) 360905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(ArrayRangeDesignator) { 361005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.Index = Index; 361105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding(); 361205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding(); 361305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding(); 361405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 361505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 361605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isFieldDesignator() const { return Kind == FieldDesignator; } 361705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isArrayDesignator() const { return Kind == ArrayDesignator; } 361805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; } 361905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3620b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth IdentifierInfo *getFieldName() const; 362105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3622b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth FieldDecl *getField() const { 362305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 362405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor if (Field.NameOrField & 0x01) 362505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return 0; 362605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor else 362705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return reinterpret_cast<FieldDecl *>(Field.NameOrField); 362805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 362905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 363005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor void setField(FieldDecl *FD) { 363105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 363205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.NameOrField = reinterpret_cast<uintptr_t>(FD); 363305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 363405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 363587f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor SourceLocation getDotLoc() const { 363687f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 363787f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor return SourceLocation::getFromRawEncoding(Field.DotLoc); 363887f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor } 363987f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor 364005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getFieldLoc() const { 364105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 364205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(Field.FieldLoc); 364305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 364405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 364505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getLBracketLoc() const { 364605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 364705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array or array-range designator"); 364805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc); 364905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 365005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 365105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getRBracketLoc() const { 365205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 365305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array or array-range designator"); 365405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc); 365505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 365605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 365705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getEllipsisLoc() const { 365805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == ArrayRangeDesignator && 365905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array-range designator"); 366005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc); 366105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 36624c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 3663d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned getFirstExprIndex() const { 3664d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 3665d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor "Only valid on an array or array-range designator"); 3666d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor return ArrayOrRange.Index; 3667d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 3668d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 36694c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor SourceLocation getStartLocation() const { 36704c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor if (Kind == FieldDesignator) 36714c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return getDotLoc().isInvalid()? getFieldLoc() : getDotLoc(); 36724c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor else 36734c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return getLBracketLoc(); 36744c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor } 367524f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara SourceLocation getEndLocation() const { 367624f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara return Kind == FieldDesignator ? getFieldLoc() : getRBracketLoc(); 367724f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara } 367824f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara SourceRange getSourceRange() const { 367924f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara return SourceRange(getStartLocation(), getEndLocation()); 368024f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara } 368105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 368205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 36831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static DesignatedInitExpr *Create(ASTContext &C, Designator *Designators, 368405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators, 368505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr **IndexExprs, unsigned NumIndexExprs, 368605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EqualOrColonLoc, 3687eeae8f072748affce25ab4064982626361293390Douglas Gregor bool GNUSyntax, Expr *Init); 368805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3689d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor static DesignatedInitExpr *CreateEmpty(ASTContext &C, unsigned NumIndexExprs); 3690d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 369105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Returns the number of designators in this initializer. 369205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned size() const { return NumDesignators; } 369305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 369405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor // Iterator access to the designators. 3695b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth typedef Designator *designators_iterator; 3696ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor designators_iterator designators_begin() { return Designators; } 36971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump designators_iterator designators_end() { 36981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return Designators + NumDesignators; 3699ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor } 370005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3701b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth typedef const Designator *const_designators_iterator; 3702b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth const_designators_iterator designators_begin() const { return Designators; } 3703b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth const_designators_iterator designators_end() const { 3704b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth return Designators + NumDesignators; 3705b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth } 3706b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth 3707cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek typedef std::reverse_iterator<designators_iterator> 3708cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek reverse_designators_iterator; 3709cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek reverse_designators_iterator designators_rbegin() { 3710cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek return reverse_designators_iterator(designators_end()); 3711cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek } 3712cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek reverse_designators_iterator designators_rend() { 3713cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek return reverse_designators_iterator(designators_begin()); 3714cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek } 3715cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek 3716b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth typedef std::reverse_iterator<const_designators_iterator> 3717b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth const_reverse_designators_iterator; 3718b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth const_reverse_designators_iterator designators_rbegin() const { 3719b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth return const_reverse_designators_iterator(designators_end()); 3720b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth } 3721b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth const_reverse_designators_iterator designators_rend() const { 3722b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth return const_reverse_designators_iterator(designators_begin()); 3723b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth } 3724b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth 3725711997184366d584c9c437102cae1e9d9927b986Douglas Gregor Designator *getDesignator(unsigned Idx) { return &designators_begin()[Idx]; } 3726711997184366d584c9c437102cae1e9d9927b986Douglas Gregor 3727c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt void setDesignators(ASTContext &C, const Designator *Desigs, 3728319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor unsigned NumDesigs); 3729d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 373005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayIndex(const Designator& D); 373105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayRangeStart(const Designator& D); 373205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayRangeEnd(const Designator& D); 373305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 373405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Retrieve the location of the '=' that precedes the 373505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initializer value itself, if present. 373605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; } 3737d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setEqualOrColonLoc(SourceLocation L) { EqualOrColonLoc = L; } 373805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 373905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Determines whether this designated initializer used the 3740eeae8f072748affce25ab4064982626361293390Douglas Gregor /// deprecated GNU syntax for designated initializers. 3741eeae8f072748affce25ab4064982626361293390Douglas Gregor bool usesGNUSyntax() const { return GNUSyntax; } 3742d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setGNUSyntax(bool GNU) { GNUSyntax = GNU; } 374305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 374405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Retrieve the initializer value. 37451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getInit() const { 374605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin()); 374705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 374805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 374905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor void setInit(Expr *init) { 375005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor *child_begin() = init; 375105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 375205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3753d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Retrieve the total number of subexpressions in this 3754d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// designated initializer expression, including the actual 3755d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// initialized value and any expressions that occur within array 3756d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// and array-range designators. 3757d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned getNumSubExprs() const { return NumSubExprs; } 3758d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3759d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Expr *getSubExpr(unsigned Idx) { 3760d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert(Idx < NumSubExprs && "Subscript out of range"); 3761d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 3762d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 3763d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor return reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx]; 3764d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 3765d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3766d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setSubExpr(unsigned Idx, Expr *E) { 3767d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert(Idx < NumSubExprs && "Subscript out of range"); 3768d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 3769d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 3770d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx] = E; 3771d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 3772d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3773ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief Replaces the designator at index @p Idx with the series 3774ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// of designators in [First, Last). 3775319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor void ExpandDesignator(ASTContext &C, unsigned Idx, const Designator *First, 3776ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Last); 3777ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 377824f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara SourceRange getDesignatorsSourceRange() const; 377924f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara 378063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const; 378105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 378205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor static bool classof(const Stmt *T) { 37831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == DesignatedInitExprClass; 378405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 378505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor static bool classof(const DesignatedInitExpr *) { return true; } 378605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 378705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor // Iterators 378863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 378963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt **begin = reinterpret_cast<Stmt**>(this + 1); 379063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(begin, begin + NumSubExprs); 379163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 37923498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor}; 37933498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 37943498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// \brief Represents an implicitly-generated value initialization of 37953498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// an object of a given type. 37963498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// 37971a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// Implicit value initializations occur within semantic initializer 37981a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// list expressions (InitListExpr) as placeholders for subobject 37993498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// initializations not explicitly specified by the user. 38001a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// 38011a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// \see InitListExpr 38021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass ImplicitValueInitExpr : public Expr { 38033498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregorpublic: 38041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ImplicitValueInitExpr(QualType ty) 3805f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ImplicitValueInitExprClass, ty, VK_RValue, OK_Ordinary, 3806561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false, ty->isInstantiationDependentType(), false) { } 38073498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 3808d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Construct an empty implicit value initialization. 3809d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor explicit ImplicitValueInitExpr(EmptyShell Empty) 3810d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor : Expr(ImplicitValueInitExprClass, Empty) { } 3811d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 38121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 38133498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return T->getStmtClass() == ImplicitValueInitExprClass; 38143498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor } 38153498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor static bool classof(const ImplicitValueInitExpr *) { return true; } 38163498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 381763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 38183498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return SourceRange(); 38193498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor } 38203498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 38213498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor // Iterators 382263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 382305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}; 382405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 38252ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 38262ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanclass ParenListExpr : public Expr { 38272ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman Stmt **Exprs; 38282ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman unsigned NumExprs; 38292ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation LParenLoc, RParenLoc; 38302ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 38312ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanpublic: 38321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParenListExpr(ASTContext& C, SourceLocation lparenloc, Expr **exprs, 38330d9106fc97cde979a995e26b18bcd2643f8afb55Manuel Klimek unsigned numexprs, SourceLocation rparenloc, QualType T); 38342ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 38352ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman /// \brief Build an empty paren list. 383637bdfe284ad365f753741d1d89c078c148b3f4afArgyrios Kyrtzidis explicit ParenListExpr(EmptyShell Empty) : Expr(ParenListExprClass, Empty) { } 38371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 38382ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman unsigned getNumExprs() const { return NumExprs; } 38391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 38401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr* getExpr(unsigned Init) const { 38412ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman assert(Init < getNumExprs() && "Initializer access out of range!"); 38422ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return cast_or_null<Expr>(Exprs[Init]); 38432ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 38441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 38451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr* getExpr(unsigned Init) { 38462ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman assert(Init < getNumExprs() && "Initializer access out of range!"); 38472ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return cast_or_null<Expr>(Exprs[Init]); 38482ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 38492ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 385083ddad3ab513f5d73698cf9fbeb4ed3f011bc3b9Douglas Gregor Expr **getExprs() { return reinterpret_cast<Expr **>(Exprs); } 38511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 38522ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation getLParenLoc() const { return LParenLoc; } 38532ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation getRParenLoc() const { return RParenLoc; } 38542ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 385563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 38562ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return SourceRange(LParenLoc, RParenLoc); 38571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 38582ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman static bool classof(const Stmt *T) { 38591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ParenListExprClass; 38602ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 38612ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman static bool classof(const ParenListExpr *) { return true; } 38621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 38632ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman // Iterators 386463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 386563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&Exprs[0], &Exprs[0]+NumExprs); 386663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 386737bdfe284ad365f753741d1d89c078c148b3f4afArgyrios Kyrtzidis 386860adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 38693397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl friend class ASTStmtWriter; 38702ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman}; 38712ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 38721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3873f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// \brief Represents a C1X generic selection. 3874f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// 3875f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// A generic selection (C1X 6.5.1.1) contains an unevaluated controlling 3876f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// expression, followed by one or more generic associations. Each generic 3877f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// association specifies a type name and an expression, or "default" and an 3878f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// expression (in which case it is known as a default generic association). 3879f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// The type and value of the generic selection are identical to those of its 3880f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// result expression, which is defined as the expression in the generic 3881f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// association with a type name that is compatible with the type of the 3882f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// controlling expression, or the expression in the default generic association 3883f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// if no types are compatible. For example: 3884f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// 3885f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// @code 3886f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// _Generic(X, double: 1, float: 2, default: 3) 3887f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// @endcode 3888f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// 3889f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// The above expression evaluates to 1 if 1.0 is substituted for X, 2 if 1.0f 3890f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// or 3 if "hello". 3891f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// 3892f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// As an extension, generic selections are allowed in C++, where the following 3893f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// additional semantics apply: 3894f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// 3895f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// Any generic selection whose controlling expression is type-dependent or 3896f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// which names a dependent type in its association list is result-dependent, 3897f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// which means that the choice of result expression is dependent. 3898f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// Result-dependent generic associations are both type- and value-dependent. 3899f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourneclass GenericSelectionExpr : public Expr { 3900f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne enum { CONTROLLING, END_EXPR }; 3901f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo **AssocTypes; 3902f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Stmt **SubExprs; 3903f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned NumAssocs, ResultIndex; 3904f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation GenericLoc, DefaultLoc, RParenLoc; 3905f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3906f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbournepublic: 3907f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne GenericSelectionExpr(ASTContext &Context, 3908f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation GenericLoc, Expr *ControllingExpr, 3909f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo **AssocTypes, Expr **AssocExprs, 3910f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned NumAssocs, SourceLocation DefaultLoc, 3911f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation RParenLoc, 3912f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne bool ContainsUnexpandedParameterPack, 3913f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned ResultIndex); 3914f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3915f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// This constructor is used in the result-dependent case. 3916f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne GenericSelectionExpr(ASTContext &Context, 3917f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation GenericLoc, Expr *ControllingExpr, 3918f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo **AssocTypes, Expr **AssocExprs, 3919f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned NumAssocs, SourceLocation DefaultLoc, 3920f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation RParenLoc, 3921f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne bool ContainsUnexpandedParameterPack); 3922f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3923f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne explicit GenericSelectionExpr(EmptyShell Empty) 3924f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne : Expr(GenericSelectionExprClass, Empty) { } 3925f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3926f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned getNumAssocs() const { return NumAssocs; } 3927f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3928f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation getGenericLoc() const { return GenericLoc; } 3929f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation getDefaultLoc() const { return DefaultLoc; } 3930f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation getRParenLoc() const { return RParenLoc; } 3931f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3932f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const Expr *getAssocExpr(unsigned i) const { 3933f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<Expr>(SubExprs[END_EXPR+i]); 3934f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 3935f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Expr *getAssocExpr(unsigned i) { return cast<Expr>(SubExprs[END_EXPR+i]); } 3936f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3937f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const TypeSourceInfo *getAssocTypeSourceInfo(unsigned i) const { 3938f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return AssocTypes[i]; 3939f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 3940f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo *getAssocTypeSourceInfo(unsigned i) { return AssocTypes[i]; } 3941f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3942f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne QualType getAssocType(unsigned i) const { 3943f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (const TypeSourceInfo *TS = getAssocTypeSourceInfo(i)) 3944f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return TS->getType(); 3945f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne else 3946f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return QualType(); 3947f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 3948f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3949f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const Expr *getControllingExpr() const { 3950f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<Expr>(SubExprs[CONTROLLING]); 3951f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 3952f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Expr *getControllingExpr() { return cast<Expr>(SubExprs[CONTROLLING]); } 3953f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3954f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// Whether this generic selection is result-dependent. 3955f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne bool isResultDependent() const { return ResultIndex == -1U; } 3956f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3957f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// The zero-based index of the result expression's generic association in 3958f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// the generic selection's association list. Defined only if the 3959f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// generic selection is not result-dependent. 3960f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned getResultIndex() const { 3961f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne assert(!isResultDependent() && "Generic selection is result-dependent"); 3962f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return ResultIndex; 3963f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 3964f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3965f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// The generic selection's result expression. Defined only if the 3966f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// generic selection is not result-dependent. 3967f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const Expr *getResultExpr() const { return getAssocExpr(getResultIndex()); } 3968f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Expr *getResultExpr() { return getAssocExpr(getResultIndex()); } 3969f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3970f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceRange getSourceRange() const { 3971f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return SourceRange(GenericLoc, RParenLoc); 3972f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 3973f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne static bool classof(const Stmt *T) { 3974f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return T->getStmtClass() == GenericSelectionExprClass; 3975f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 3976f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne static bool classof(const GenericSelectionExpr *) { return true; } 3977f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3978f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne child_range children() { 3979f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return child_range(SubExprs, SubExprs+END_EXPR+NumAssocs); 3980f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 3981f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3982f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne friend class ASTStmtReader; 3983f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne}; 3984f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 39854eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===// 39864eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff// Clang Extensions 39874eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===// 39884eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 3989a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 3990a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// ExtVectorElementExpr - This represents access to specific elements of a 3991a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// vector, and may occur on the left hand side or right hand side. For example 3992a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// the following is legal: "V.xy = V.zw" if V is a 4 element extended vector. 3993a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// 399473525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// Note that the base may have either vector or pointer to vector type, just 399573525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// like a struct field reference. 399673525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// 3997a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerclass ExtVectorElementExpr : public Expr { 3998a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner Stmt *Base; 3999d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor IdentifierInfo *Accessor; 4000a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner SourceLocation AccessorLoc; 4001a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerpublic: 4002f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExtVectorElementExpr(QualType ty, ExprValueKind VK, Expr *base, 4003f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall IdentifierInfo &accessor, SourceLocation loc) 40040943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall : Expr(ExtVectorElementExprClass, ty, VK, 40050943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall (VK == VK_RValue ? OK_Ordinary : OK_VectorComponent), 4006bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->isTypeDependent(), base->isValueDependent(), 4007561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor base->isInstantiationDependent(), 4008bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->containsUnexpandedParameterPack()), 4009d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor Base(base), Accessor(&accessor), AccessorLoc(loc) {} 40101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4011d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor /// \brief Build an empty vector element expression. 4012d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor explicit ExtVectorElementExpr(EmptyShell Empty) 4013d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor : Expr(ExtVectorElementExprClass, Empty) { } 4014d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 4015a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner const Expr *getBase() const { return cast<Expr>(Base); } 4016a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner Expr *getBase() { return cast<Expr>(Base); } 4017d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setBase(Expr *E) { Base = E; } 4018d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 4019d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor IdentifierInfo &getAccessor() const { return *Accessor; } 4020d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setAccessor(IdentifierInfo *II) { Accessor = II; } 4021d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 4022d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getAccessorLoc() const { return AccessorLoc; } 4023d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setAccessorLoc(SourceLocation L) { AccessorLoc = L; } 4024d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 4025a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// getNumElements - Get the number of components being selected. 4026a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner unsigned getNumElements() const; 40271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4028a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// containsDuplicateElements - Return true if any element access is 4029a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// repeated. 4030a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner bool containsDuplicateElements() const; 40311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4032a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// getEncodedElementAccess - Encode the elements accessed into an llvm 4033a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// aggregate Constant of ConstantInt(s). 4034686775deca8b8685eb90801495880e3abdd844c2Chris Lattner void getEncodedElementAccess(SmallVectorImpl<unsigned> &Elts) const; 40351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 403663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 4037a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner return SourceRange(getBase()->getLocStart(), AccessorLoc); 4038a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner } 40391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 40402140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner /// isArrow - Return true if the base expression is a pointer to vector, 40412140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner /// return false if the base expression is a vector. 40422140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner bool isArrow() const; 40431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 40441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 40451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ExtVectorElementExprClass; 4046a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner } 4047a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner static bool classof(const ExtVectorElementExpr *) { return true; } 40481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4049a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner // Iterators 405063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Base, &Base+1); } 4051a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner}; 4052a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 4053a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 405456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff/// BlockExpr - Adaptor class for mixing a BlockDecl with expressions. 40559c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff/// ^{ statement-body } or ^(int arg1, float arg2){ statement-body } 40564eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockExpr : public Expr { 405756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroffprotected: 405856ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff BlockDecl *TheBlock; 40594eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic: 4060469a1eb996e1cb0be54f9b210f836afbddcbb2ccJohn McCall BlockExpr(BlockDecl *BD, QualType ty) 4061f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(BlockExprClass, ty, VK_RValue, OK_Ordinary, 4062561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ty->isDependentType(), false, 4063561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor // FIXME: Check for instantiate-dependence in the statement? 4064561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ty->isInstantiationDependentType(), 4065561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false), 4066469a1eb996e1cb0be54f9b210f836afbddcbb2ccJohn McCall TheBlock(BD) {} 40679c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 406884af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor /// \brief Build an empty block expression. 406984af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor explicit BlockExpr(EmptyShell Empty) : Expr(BlockExprClass, Empty) { } 407084af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor 4071d5cab5435371b8cc74a9e05ebd40b5995ebad149Anders Carlsson const BlockDecl *getBlockDecl() const { return TheBlock; } 407256ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff BlockDecl *getBlockDecl() { return TheBlock; } 407384af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor void setBlockDecl(BlockDecl *BD) { TheBlock = BD; } 407484af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor 407556ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff // Convenience functions for probing the underlying BlockDecl. 407656ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff SourceLocation getCaretLocation() const; 407756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff const Stmt *getBody() const; 407856ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff Stmt *getBody(); 40799c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 408063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 408156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff return SourceRange(getCaretLocation(), getBody()->getLocEnd()); 40829c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff } 40839c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 408456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff /// getFunctionType - Return the underlying function type for this block. 408556ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff const FunctionType *getFunctionType() const; 408656ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 40871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 40889c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff return T->getStmtClass() == BlockExprClass; 40894eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff } 40904eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff static bool classof(const BlockExpr *) { return true; } 40911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 40924eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff // Iterators 409363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 40944eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff}; 40951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 40966b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall/// BlockDeclRefExpr - A reference to a local variable declared in an 40976b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall/// enclosing scope. 40984eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockDeclRefExpr : public Expr { 40996b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall VarDecl *D; 41004eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff SourceLocation Loc; 41017d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool IsByRef : 1; 41027d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool ConstQualAdded : 1; 41034eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic: 41046b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall BlockDeclRefExpr(VarDecl *d, QualType t, ExprValueKind VK, 41056b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall SourceLocation l, bool ByRef, bool constAdded = false); 410694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 410794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor // \brief Build an empty reference to a declared variable in a 410894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor // block. 410994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor explicit BlockDeclRefExpr(EmptyShell Empty) 411094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor : Expr(BlockDeclRefExprClass, Empty) { } 41111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 41126b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall VarDecl *getDecl() { return D; } 41136b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall const VarDecl *getDecl() const { return D; } 41146b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall void setDecl(VarDecl *VD) { D = VD; } 411594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 411694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getLocation() const { return Loc; } 411794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setLocation(SourceLocation L) { Loc = L; } 411894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 411963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 41201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 41214eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff bool isByRef() const { return IsByRef; } 412294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setByRef(bool BR) { IsByRef = BR; } 41231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 41247d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool isConstQualAdded() const { return ConstQualAdded; } 41257d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian void setConstQualAdded(bool C) { ConstQualAdded = C; } 412689f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian 41271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 41281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == BlockDeclRefExprClass; 41294eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff } 41304eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff static bool classof(const BlockDeclRefExpr *) { return true; } 41311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 41324eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff // Iterators 413363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 41344eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff}; 41354eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 413661eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner/// AsTypeExpr - Clang builtin function __builtin_astype [OpenCL 6.2.4.2] 413761eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner/// This AST node provides support for reinterpreting a type to another 413861eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner/// type of the same size. 4139379010addb0e84fd0fbc37c829baf658958521bdJohn McCallclass AsTypeExpr : public Expr { // Should this be an ExplicitCastExpr? 414061eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattnerprivate: 4141379010addb0e84fd0fbc37c829baf658958521bdJohn McCall Stmt *SrcExpr; 414261eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner SourceLocation BuiltinLoc, RParenLoc; 4143379010addb0e84fd0fbc37c829baf658958521bdJohn McCall 4144379010addb0e84fd0fbc37c829baf658958521bdJohn McCall friend class ASTReader; 4145379010addb0e84fd0fbc37c829baf658958521bdJohn McCall friend class ASTStmtReader; 4146379010addb0e84fd0fbc37c829baf658958521bdJohn McCall explicit AsTypeExpr(EmptyShell Empty) : Expr(AsTypeExprClass, Empty) {} 414761eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner 414861eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattnerpublic: 414961eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner AsTypeExpr(Expr* SrcExpr, QualType DstType, 415061eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner ExprValueKind VK, ExprObjectKind OK, 415161eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner SourceLocation BuiltinLoc, SourceLocation RParenLoc) 4152561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Expr(AsTypeExprClass, DstType, VK, OK, 4153561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor DstType->isDependentType(), 4154561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor DstType->isDependentType() || SrcExpr->isValueDependent(), 4155561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (DstType->isInstantiationDependentType() || 4156561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor SrcExpr->isInstantiationDependent()), 4157561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (DstType->containsUnexpandedParameterPack() || 4158561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor SrcExpr->containsUnexpandedParameterPack())), 4159379010addb0e84fd0fbc37c829baf658958521bdJohn McCall SrcExpr(SrcExpr), BuiltinLoc(BuiltinLoc), RParenLoc(RParenLoc) {} 416061eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner 416161eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner /// getSrcExpr - Return the Expr to be converted. 4162379010addb0e84fd0fbc37c829baf658958521bdJohn McCall Expr *getSrcExpr() const { return cast<Expr>(SrcExpr); } 4163379010addb0e84fd0fbc37c829baf658958521bdJohn McCall 4164379010addb0e84fd0fbc37c829baf658958521bdJohn McCall /// getBuiltinLoc - Return the location of the __builtin_astype token. 4165379010addb0e84fd0fbc37c829baf658958521bdJohn McCall SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 4166379010addb0e84fd0fbc37c829baf658958521bdJohn McCall 4167379010addb0e84fd0fbc37c829baf658958521bdJohn McCall /// getRParenLoc - Return the location of final right parenthesis. 4168379010addb0e84fd0fbc37c829baf658958521bdJohn McCall SourceLocation getRParenLoc() const { return RParenLoc; } 416961eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner 41707b33c2b3908b178511ccaace8cacb5e5b14552a9Nick Lewycky SourceRange getSourceRange() const { 417161eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner return SourceRange(BuiltinLoc, RParenLoc); 417261eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner } 417361eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner 417461eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner static bool classof(const Stmt *T) { 417561eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner return T->getStmtClass() == AsTypeExprClass; 417661eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner } 417761eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner static bool classof(const AsTypeExpr *) { return true; } 417861eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner 417961eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner // Iterators 4180379010addb0e84fd0fbc37c829baf658958521bdJohn McCall child_range children() { return child_range(&SrcExpr, &SrcExpr+1); } 418161eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner}; 4182276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4183276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman/// AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, 4184276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman/// __atomic_load, __atomic_store, and __atomic_compare_exchange_*, for the 4185276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman/// similarly-named C++0x instructions. All of these instructions take one 4186276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman/// primary pointer and at least one memory order. 4187276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedmanclass AtomicExpr : public Expr { 4188276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedmanpublic: 4189276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman enum AtomicOp { Load, Store, CmpXchgStrong, CmpXchgWeak, Xchg, 4190276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman Add, Sub, And, Or, Xor }; 4191276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedmanprivate: 4192276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman enum { PTR, ORDER, VAL1, ORDER_FAIL, VAL2, END_EXPR }; 4193276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman Stmt* SubExprs[END_EXPR]; 4194276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman unsigned NumSubExprs; 4195276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman SourceLocation BuiltinLoc, RParenLoc; 4196276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman AtomicOp Op; 4197276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4198276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedmanpublic: 4199dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman AtomicExpr(SourceLocation BLoc, Expr **args, unsigned nexpr, QualType t, 4200dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman AtomicOp op, SourceLocation RP); 4201276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4202276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman /// \brief Build an empty AtomicExpr. 4203276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman explicit AtomicExpr(EmptyShell Empty) : Expr(AtomicExprClass, Empty) { } 4204276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4205276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman Expr *getPtr() const { 4206276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return cast<Expr>(SubExprs[PTR]); 4207276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4208276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman void setPtr(Expr *E) { 4209276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman SubExprs[PTR] = E; 4210276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4211276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman Expr *getOrder() const { 4212276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return cast<Expr>(SubExprs[ORDER]); 4213276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4214276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman void setOrder(Expr *E) { 4215276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman SubExprs[ORDER] = E; 4216276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4217276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman Expr *getVal1() const { 4218276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman assert(NumSubExprs >= 3); 4219276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return cast<Expr>(SubExprs[VAL1]); 4220276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4221276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman void setVal1(Expr *E) { 4222276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman assert(NumSubExprs >= 3); 4223276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman SubExprs[VAL1] = E; 4224276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4225276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman Expr *getOrderFail() const { 4226276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman assert(NumSubExprs == 5); 4227276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return cast<Expr>(SubExprs[ORDER_FAIL]); 4228276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4229276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman void setOrderFail(Expr *E) { 4230276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman assert(NumSubExprs == 5); 4231276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman SubExprs[ORDER_FAIL] = E; 4232276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4233276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman Expr *getVal2() const { 4234276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman assert(NumSubExprs == 5); 4235276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return cast<Expr>(SubExprs[VAL2]); 4236276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4237276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman void setVal2(Expr *E) { 4238276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman assert(NumSubExprs == 5); 4239276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman SubExprs[VAL2] = E; 4240276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4241276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4242276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman AtomicOp getOp() const { return Op; } 4243276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman void setOp(AtomicOp op) { Op = op; } 4244276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman unsigned getNumSubExprs() { return NumSubExprs; } 4245276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman void setNumSubExprs(unsigned num) { NumSubExprs = num; } 4246276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4247dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman Expr **getSubExprs() { return reinterpret_cast<Expr **>(SubExprs); } 4248dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman 4249276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman bool isVolatile() const { 4250276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return getPtr()->getType()->getPointeeType().isVolatileQualified(); 4251276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4252276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4253276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman bool isCmpXChg() const { 4254276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return getOp() == AtomicExpr::CmpXchgStrong || 4255276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman getOp() == AtomicExpr::CmpXchgWeak; 4256276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4257276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4258276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 4259276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 4260276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4261276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman SourceLocation getRParenLoc() const { return RParenLoc; } 4262276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman void setRParenLoc(SourceLocation L) { RParenLoc = L; } 4263276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4264276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman SourceRange getSourceRange() const { 4265276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return SourceRange(BuiltinLoc, RParenLoc); 4266276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4267276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman static bool classof(const Stmt *T) { 4268276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return T->getStmtClass() == AtomicExprClass; 4269276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4270276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman static bool classof(const AtomicExpr *) { return true; } 4271276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4272276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman // Iterators 4273276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman child_range children() { 4274276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return child_range(SubExprs, SubExprs+NumSubExprs); 4275276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4276276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman}; 42775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 42785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 42795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 4280