Expr.h revision 31dfd642d5ac33c4ee0cfe1d7a1d4da455dcc7a4
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" 2531dfd642d5ac33c4ee0cfe1d7a1d4da455dcc7a4Akira Hatanaka#include "clang/Basic/TargetInfo.h" 26f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne#include "clang/Basic/TypeTraits.h" 275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/APSInt.h" 28525a05093a4816af961fe2bc6b8a81c17e2e26c2Chris Lattner#include "llvm/ADT/APFloat.h" 293b8d116703db8018f855cbb4733ace426422623bNate Begeman#include "llvm/ADT/SmallVector.h" 30b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar#include "llvm/ADT/StringRef.h" 31403ba3522d1b1c97ae5fad81c1a2c4b3a754e1c1Nick Lewycky#include <cctype> 325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 34590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner class ASTContext; 35c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson class APValue; 36c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class Decl; 37c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class IdentifierInfo; 38c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class ParmVarDecl; 398e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor class NamedDecl; 40c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class ValueDecl; 4156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff class BlockDecl; 42409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson class CXXBaseSpecifier; 4388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor class CXXOperatorCallExpr; 4488a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor class CXXMemberCallExpr; 45f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall class ObjCPropertyRefExpr; 4656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall class OpaqueValueExpr; 4788a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 487ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson/// \brief A simple array of base specifiers. 49686775deca8b8685eb90801495880e3abdd844c2Chris Lattnertypedef SmallVector<CXXBaseSpecifier*, 4> CXXCastPath; 507ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson 515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Expr - This represents one expression. Note that Expr's are subclasses of 525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Stmt. This allows an expression to be transparently used any place a Stmt 535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is required. 545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Expr : public Stmt { 565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType TR; 57898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 588e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCallprotected: 59f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(StmtClass SC, QualType T, ExprValueKind VK, ExprObjectKind OK, 60ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie bool TD, bool VD, bool ID, bool ContainsUnexpandedParameterPack) 61ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie : Stmt(SC) 62561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor { 638e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.TypeDependent = TD; 648e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.ValueDependent = VD; 65561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = ID; 66f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprBits.ValueKind = VK; 67f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprBits.ObjectKind = OK; 68bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack; 69898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor setType(T); 70898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 71898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 720b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Construct an empty expression. 730b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor explicit Expr(StmtClass SC, EmptyShell) : Stmt(SC) { } 740b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 76f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor QualType getType() const { return TR; } 771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setType(QualType t) { 789d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // In C++, the type of an expression is always adjusted so that it 799d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // will not have reference type an expression will never have 809d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // reference type (C++ [expr]p6). Use 819d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // QualType::getNonReferenceType() to retrieve the non-reference 829d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // type. Additionally, inspect Expr::isLvalue to determine whether 839d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // an expression that is adjusted in this manner should be 849d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // considered an lvalue. 85905d11d53aeb6b26744f44fedc2b2820c7a62df6Douglas Gregor assert((t.isNull() || !t->isReferenceType()) && 868320aaaa01d931aa234fc3bce05b399ef41898d5Daniel Dunbar "Expressions can't have reference type"); 87f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor 881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TR = t; 899d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor } 9077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 91898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isValueDependent - Determines whether this expression is 92898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// value-dependent (C++ [temp.dep.constexpr]). For example, the 93898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// array bound of "Chars" in the following example is 941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// value-dependent. 95898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @code 96898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// template<int Size, char (&Chars)[Size]> struct meta_string; 97898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @endcode 988e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall bool isValueDependent() const { return ExprBits.ValueDependent; } 99898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1000b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Set whether this expression is value-dependent or not. 101ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie void setValueDependent(bool VD) { 102ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie ExprBits.ValueDependent = VD; 103561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (VD) 104561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 105561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 1060b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 107898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isTypeDependent - Determines whether this expression is 108898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// type-dependent (C++ [temp.dep.expr]), which means that its type 109898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// could change from one template instantiation to the next. For 110898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// example, the expressions "x" and "x + y" are type-dependent in 111898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// the following code, but "y" is not type-dependent: 112898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @code 1131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// template<typename T> 114898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// void add(T x, int y) { 115898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// x + y; 116898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// } 117898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @endcode 1188e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall bool isTypeDependent() const { return ExprBits.TypeDependent; } 119898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1200b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Set whether this expression is type-dependent or not. 121ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie void setTypeDependent(bool TD) { 122ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie ExprBits.TypeDependent = TD; 123561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (TD) 124561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 125561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 126561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 127561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// \brief Whether this expression is instantiation-dependent, meaning that 128561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// it depends in some way on a template parameter, even if neither its type 129561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// nor (constant) value can change due to the template instantiation. 130561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// 131561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// In the following example, the expression \c sizeof(sizeof(T() + T())) is 132561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// instantiation-dependent (since it involves a template parameter \c T), but 133561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// is neither type- nor value-dependent, since the type of the inner 134561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// \c sizeof is known (\c std::size_t) and therefore the size of the outer 135561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// \c sizeof is known. 136561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// 137561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// \code 138561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// template<typename T> 139561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// void f(T x, T y) { 140561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// sizeof(sizeof(T() + T()); 141561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// } 142561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// \endcode 143561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// 144ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie bool isInstantiationDependent() const { 145ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return ExprBits.InstantiationDependent; 146561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 147ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 148561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// \brief Set whether this expression is instantiation-dependent or not. 149ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie void setInstantiationDependent(bool ID) { 150561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = ID; 151561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 1520b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 153d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \brief Whether this expression contains an unexpanded parameter 154d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// pack (for C++0x variadic templates). 155d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// 156d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// Given the following function template: 157d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// 158d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \code 159d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// template<typename F, typename ...Types> 160d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// void forward(const F &f, Types &&...args) { 161d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// f(static_cast<Types&&>(args)...); 162d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// } 163d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \endcode 164d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// 165d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// The expressions \c args and \c static_cast<Types&&>(args) both 166d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// contain parameter packs. 167ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie bool containsUnexpandedParameterPack() const { 168ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return ExprBits.ContainsUnexpandedParameterPack; 169d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor } 170d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 171bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /// \brief Set the bit that describes whether this expression 172bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /// contains an unexpanded parameter pack. 173bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor void setContainsUnexpandedParameterPack(bool PP = true) { 174bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = PP; 175bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor } 176bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 1775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getExprLoc - Return the preferred location for the arrow when diagnosing 1785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// a problem with a generic expression. 17963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation getExprLoc() const; 1801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 181026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// isUnusedResultAWarning - Return true if this immediate expression should 182026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// be warned about if the result is unused. If so, fill in Loc and Ranges 183026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// with location to warn on and the source range[s] to report with the 184026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// warning. 185026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner bool isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1, 186df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump SourceRange &R2, ASTContext &Ctx) const; 1871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1887eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// isLValue - True if this expression is an "l-value" according to 1897eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// the rules of the current language. C and C++ give somewhat 1907eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// different rules for this concept, but in general, the result of 1917eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// an l-value expression identifies a specific object whereas the 1927eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// result of an r-value expression is a value detached from any 1937eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// specific storage. 1945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 1957eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// C++0x divides the concept of "r-value" into pure r-values 1967eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// ("pr-values") and so-called expiring values ("x-values"), which 1977eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// identify specific objects that can be safely cannibalized for 1987eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// their resources. This is an unfortunate abuse of terminology on 1997eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// the part of the C++ committee. In Clang, when we say "r-value", 2007eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// we generally mean a pr-value. 2017eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall bool isLValue() const { return getValueKind() == VK_LValue; } 2027eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall bool isRValue() const { return getValueKind() == VK_RValue; } 2037eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall bool isXValue() const { return getValueKind() == VK_XValue; } 2047eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall bool isGLValue() const { return getValueKind() != VK_RValue; } 2057eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall 2067eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall enum LValueClassification { 2075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_Valid, 2085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_NotObjectType, 2095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_IncompleteVoidType, 210fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff LV_DuplicateVectorComponents, 21186f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor LV_InvalidExpression, 212077f490d0a514dcc448475f33f799934252b85a7Fariborz Jahanian LV_InvalidMessageExpression, 2132514a309204341798f96912ce7a90841bea59727Fariborz Jahanian LV_MemberFunction, 214e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian LV_SubObjCPropertySetting, 215e873fb74219f48407ae0b8fa083aa7f0b6ff1427Douglas Gregor LV_ClassTemporary 2165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 2177eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// Reasons why an expression might not be an l-value. 2187eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall LValueClassification ClassifyLValue(ASTContext &Ctx) const; 21953202857c60214d80950a975e6e52aebf30bd16aEli Friedman 2205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type, 2215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// does not have an incomplete type, does not have a const-qualified type, 2221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// and if it is a structure or union, does not have any member (including, 2235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// recursively, any member or element of all contained aggregates or unions) 2245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// with a const-qualified type. 22544e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// 22644e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// \param Loc [in] [out] - A source location which *may* be filled 22744e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// in with the location of the expression making this a 22844e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// non-modifiable lvalue, if specified. 2295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum isModifiableLvalueResult { 2305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_Valid, 2315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_NotObjectType, 2325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_IncompleteVoidType, 233fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff MLV_DuplicateVectorComponents, 2345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_InvalidExpression, 235ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner MLV_LValueCast, // Specialized form of MLV_InvalidExpression. 2365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_IncompleteType, 2375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_ConstQualified, 2384f6a7d7ead09b439216c32f2de806a998aeb222aSteve Naroff MLV_ArrayType, 2395daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian MLV_NotBlockQualified, 240ba8d2d684e74a20bef03828c21c991d222c7e9e5Fariborz Jahanian MLV_ReadonlyProperty, 24186f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor MLV_NoSetterProperty, 2422514a309204341798f96912ce7a90841bea59727Fariborz Jahanian MLV_MemberFunction, 243e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian MLV_SubObjCPropertySetting, 244077f490d0a514dcc448475f33f799934252b85a7Fariborz Jahanian MLV_InvalidMessageExpression, 245e873fb74219f48407ae0b8fa083aa7f0b6ff1427Douglas Gregor MLV_ClassTemporary 2465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 24744e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx, 24844e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar SourceLocation *Loc = 0) const; 2491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2502111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \brief The return type of classify(). Represents the C++0x expression 2512111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// taxonomy. 2522111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl class Classification { 2532111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl public: 2542111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \brief The various classification results. Most of these mean prvalue. 2552111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl enum Kinds { 2562111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_LValue, 2572111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_XValue, 2582111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_Function, // Functions cannot be lvalues in C. 2592111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_Void, // Void cannot be an lvalue in C. 2601c860d5640e8eebb11a5d515a761242b66761b0bPeter Collingbourne CL_AddressableVoid, // Void expression whose address can be taken in C. 2612111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_DuplicateVectorComponents, // A vector shuffle with dupes. 2622111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_MemberFunction, // An expression referring to a member function 2632111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_SubObjCPropertySetting, 2642111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_ClassTemporary, // A prvalue of class type 265077f490d0a514dcc448475f33f799934252b85a7Fariborz Jahanian CL_ObjCMessageRValue, // ObjC message is an rvalue 2662111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_PRValue // A prvalue for any other reason, of any other type 2672111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl }; 2682111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \brief The results of modification testing. 2692111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl enum ModifiableType { 2702111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_Untested, // testModifiable was false. 2712111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_Modifiable, 2722111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_RValue, // Not modifiable because it's an rvalue 2732111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_Function, // Not modifiable because it's a function; C++ only 2742111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_LValueCast, // Same as CM_RValue, but indicates GCC cast-as-lvalue ext 2752111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_NotBlockQualified, // Not captured in the closure 2762111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_NoSetterProperty,// Implicit assignment to ObjC property without setter 2772111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_ConstQualified, 2782111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_ArrayType, 2792111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_IncompleteType 2802111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl }; 2812111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2822111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl private: 2832111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl friend class Expr; 2842111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2852111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl unsigned short Kind; 2862111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl unsigned short Modifiable; 2872111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2882111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl explicit Classification(Kinds k, ModifiableType m) 2892111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl : Kind(k), Modifiable(m) 2902111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl {} 2912111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2922111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl public: 2932111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification() {} 2942111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2952111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Kinds getKind() const { return static_cast<Kinds>(Kind); } 2962111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl ModifiableType getModifiable() const { 2972111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl assert(Modifiable != CM_Untested && "Did not test for modifiability."); 2982111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl return static_cast<ModifiableType>(Modifiable); 2992111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl } 3002111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isLValue() const { return Kind == CL_LValue; } 3012111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isXValue() const { return Kind == CL_XValue; } 3022111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isGLValue() const { return Kind <= CL_XValue; } 3032111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isPRValue() const { return Kind >= CL_Function; } 3042111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isRValue() const { return Kind >= CL_XValue; } 3052111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isModifiable() const { return getModifiable() == CM_Modifiable; } 306ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3072c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor /// \brief Create a simple, modifiably lvalue 3082c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor static Classification makeSimpleLValue() { 3092c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor return Classification(CL_LValue, CM_Modifiable); 3102c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor } 311ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3122111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl }; 313369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// \brief Classify - Classify this expression according to the C++0x 3142111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// expression taxonomy. 3152111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// 3162111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// C++0x defines ([basic.lval]) a new taxonomy of expressions to replace the 3172111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// old lvalue vs rvalue. This function determines the type of expression this 3182111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// is. There are three expression types: 3192111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// - lvalues are classical lvalues as in C++03. 3202111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// - prvalues are equivalent to rvalues in C++03. 3212111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// - xvalues are expressions yielding unnamed rvalue references, e.g. a 3222111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// function returning an rvalue reference. 3232111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// lvalues and xvalues are collectively referred to as glvalues, while 3242111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// prvalues and xvalues together form rvalues. 3252111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification Classify(ASTContext &Ctx) const { 3262111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl return ClassifyImpl(Ctx, 0); 3272111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl } 3282111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 329369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// \brief ClassifyModifiable - Classify this expression according to the 3302111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// C++0x expression taxonomy, and see if it is valid on the left side 3312111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// of an assignment. 3322111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// 3332111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// This function extends classify in that it also tests whether the 3342111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// expression is modifiable (C99 6.3.2.1p1). 3352111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \param Loc A source location that might be filled with a relevant location 3362111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// if the expression is not modifiable. 3372111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification ClassifyModifiable(ASTContext &Ctx, SourceLocation &Loc) const{ 3382111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl return ClassifyImpl(Ctx, &Loc); 3392111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl } 3402111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 341f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// getValueKindForType - Given a formal return or parameter type, 342f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// give its value kind. 343f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall static ExprValueKind getValueKindForType(QualType T) { 344f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall if (const ReferenceType *RT = T->getAs<ReferenceType>()) 3450943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall return (isa<LValueReferenceType>(RT) 3460943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall ? VK_LValue 3470943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall : (RT->getPointeeType()->isFunctionType() 3480943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall ? VK_LValue : VK_XValue)); 349f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall return VK_RValue; 350f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall } 351f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 352f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// getValueKind - The value kind that this expression produces. 353f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind getValueKind() const { 354f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall return static_cast<ExprValueKind>(ExprBits.ValueKind); 355f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall } 356f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 357f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// getObjectKind - The object kind that this expression produces. 358f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// Object kinds are meaningful only for expressions that yield an 359f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// l-value or x-value. 360f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprObjectKind getObjectKind() const { 361f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall return static_cast<ExprObjectKind>(ExprBits.ObjectKind); 362f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall } 363f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 36456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall bool isOrdinaryOrBitFieldObject() const { 36556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall ExprObjectKind OK = getObjectKind(); 36656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return (OK == OK_Ordinary || OK == OK_BitField); 36756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 36856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 369f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// setValueKind - Set the value kind produced by this expression. 370f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall void setValueKind(ExprValueKind Cat) { ExprBits.ValueKind = Cat; } 371f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 372f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// setObjectKind - Set the object kind produced by this expression. 373f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall void setObjectKind(ExprObjectKind Cat) { ExprBits.ObjectKind = Cat; } 374f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 3752111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redlprivate: 3762111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification ClassifyImpl(ASTContext &Ctx, SourceLocation *Loc) const; 3772111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 3782111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redlpublic: 3792111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 38033bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor /// \brief If this expression refers to a bit-field, retrieve the 38133bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor /// declaration of that bit-field. 38233bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor FieldDecl *getBitField(); 3835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 38438d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson const FieldDecl *getBitField() const { 38538d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson return const_cast<Expr*>(this)->getBitField(); 38638d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson } 3871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 388f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall /// \brief If this expression is an l-value for an Objective C 389f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall /// property, find the underlying property reference expression. 390f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall const ObjCPropertyRefExpr *getObjCProperty() const; 391f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall 392093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson /// \brief Returns whether this expression refers to a vector element. 393093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson bool refersToVectorElement() const; 3944919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall 3954919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall /// \brief Returns whether this expression has a placeholder type. 3964919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall bool hasPlaceholderType() const { 3974919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall return getType()->isPlaceholderType(); 3984919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall } 3994919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall 4004919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall /// \brief Returns whether this expression has a specific placeholder type. 4014919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall bool hasPlaceholderType(BuiltinType::Kind K) const { 40285def357129b6cdfd69a66ad0e6994506418a2a9John McCall assert(BuiltinType::isPlaceholderTypeKind(K)); 4034919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall if (const BuiltinType *BT = dyn_cast<BuiltinType>(getType())) 4044919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall return BT->getKind() == K; 4054919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall return false; 4064919dfd54e2296ca997e3d1c9dab85976bba8e95John McCall } 407ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 4082b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// isKnownToHaveBooleanValue - Return true if this is an integer expression 4092b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// that is known to return 0 or 1. This happens for _Bool/bool expressions 4102b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// but also int expressions which are produced by things like comparisons in 4112b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// C. 4122b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner bool isKnownToHaveBooleanValue() const; 413ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 4145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isIntegerConstantExpr - Return true if this expression is a valid integer 4155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// constant expression, and, if so, return its value in Result. If not a 4165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// valid i-c-e, return false and fill in Loc (if specified) with the location 4175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// of the invalid expression. 418590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx, 419590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner SourceLocation *Loc = 0, 4205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isEvaluated = true) const; 421f48fdb0937e67f691393f9ffdf75653e5128ea13Richard Smith bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const; 4220e35b4ecee380c2b4c33d75da6bc2fb6f6bc7df3Richard Smith 4230e35b4ecee380c2b4c33d75da6bc2fb6f6bc7df3Richard Smith /// isConstantInitializer - Returns true if this expression can be emitted to 4240e35b4ecee380c2b4c33d75da6bc2fb6f6bc7df3Richard Smith /// IR as a constant, and thus can be used as a constant initializer in C. 4254204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall bool isConstantInitializer(ASTContext &Ctx, bool ForRef) const; 4261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4271e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith /// EvalStatus is a struct with detailed info about an evaluation in progress. 4281e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith struct EvalStatus { 42994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// HasSideEffects - Whether the evaluated expression has side effects. 43094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// For example, (f() && 0) can be folded, but it still has side effects. 43194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson bool HasSideEffects; 4321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 433dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith /// Diag - If this is non-null, it will be filled in with a stack of notes 434dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith /// indicating why evaluation failed (or why it failed to produce a constant 435dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith /// expression). 436dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith /// If the expression is unfoldable, the notes will indicate why it's not 437dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith /// foldable. If the expression is foldable, but not a constant expression, 438dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith /// the notes will describes why it isn't a constant expression. If the 439dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith /// expression *is* a constant expression, no notes will be produced. 440dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith llvm::SmallVectorImpl<PartialDiagnosticAt> *Diag; 441dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith 442dd1f29b6d686899bfd033f26e16cb1621e5549e8Richard Smith EvalStatus() : HasSideEffects(false), Diag(0) {} 443e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara 444e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara // hasSideEffects - Return true if the evaluated expression has 445e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara // side effects. 446e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara bool hasSideEffects() const { 447e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara return HasSideEffects; 448e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara } 44994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson }; 45094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson 4511e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith /// EvalResult is a struct with detailed info about an evaluated expression. 4521e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith struct EvalResult : EvalStatus { 4531e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith /// Val - This is the value the expression can be folded to. 4541e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith APValue Val; 4551e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith 4561e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith // isGlobalLValue - Return true if the evaluated lvalue expression 4571e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith // is global. 4581e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith bool isGlobalLValue() const; 4591e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith }; 4601e12c59e8f9bb76c23628c4e0d0a1dfced0b1fa0Richard Smith 46151f4708c00110940ca3f337961915f2ca1668375Richard Smith /// EvaluateAsRValue - Return true if this is a constant which we can fold to 46251f4708c00110940ca3f337961915f2ca1668375Richard Smith /// an rvalue using any crazy technique (that has nothing to do with language 46351f4708c00110940ca3f337961915f2ca1668375Richard Smith /// standards) that we want to, even if the expression has side-effects. If 46451f4708c00110940ca3f337961915f2ca1668375Richard Smith /// this function returns true, it returns the folded constant in Result. If 46551f4708c00110940ca3f337961915f2ca1668375Richard Smith /// the expression is a glvalue, an lvalue-to-rvalue conversion will be 46651f4708c00110940ca3f337961915f2ca1668375Richard Smith /// applied. 46751f4708c00110940ca3f337961915f2ca1668375Richard Smith bool EvaluateAsRValue(EvalResult &Result, const ASTContext &Ctx) const; 4685b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson 469cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall /// EvaluateAsBooleanCondition - Return true if this is a constant 470cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall /// which we we can fold and convert to a boolean condition using 471a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith /// any crazy technique that we want to, even if the expression has 472a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith /// side-effects. 4734ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool EvaluateAsBooleanCondition(bool &Result, const ASTContext &Ctx) const; 474cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall 47580d4b55db94db2172a04617d1a80feca6bbcea5cRichard Smith enum SideEffectsKind { SE_NoSideEffects, SE_AllowSideEffects }; 47680d4b55db94db2172a04617d1a80feca6bbcea5cRichard Smith 477a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith /// EvaluateAsInt - Return true if this is a constant which we can fold and 47880d4b55db94db2172a04617d1a80feca6bbcea5cRichard Smith /// convert to an integer, using any crazy technique that we want to. 47980d4b55db94db2172a04617d1a80feca6bbcea5cRichard Smith bool EvaluateAsInt(llvm::APSInt &Result, const ASTContext &Ctx, 48080d4b55db94db2172a04617d1a80feca6bbcea5cRichard Smith SideEffectsKind AllowSideEffects = SE_NoSideEffects) const; 481a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith 48251f4708c00110940ca3f337961915f2ca1668375Richard Smith /// isEvaluatable - Call EvaluateAsRValue to see if this expression can be 48351f4708c00110940ca3f337961915f2ca1668375Richard Smith /// constant folded without side-effects, but discard the result. 4844ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool isEvaluatable(const ASTContext &Ctx) const; 485c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson 4866ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian /// HasSideEffects - This routine returns true for all those expressions 48751f4708c00110940ca3f337961915f2ca1668375Richard Smith /// which must be evaluated each time and must not be optimized away 4886ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian /// or evaluated at compile time. Example is a function call, volatile 4896ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian /// variable read. 4904ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool HasSideEffects(const ASTContext &Ctx) const; 49151f4708c00110940ca3f337961915f2ca1668375Richard Smith 49251f4708c00110940ca3f337961915f2ca1668375Richard Smith /// EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded 49351f4708c00110940ca3f337961915f2ca1668375Richard Smith /// integer. This must be called on an expression that constant folds to an 49451f4708c00110940ca3f337961915f2ca1668375Richard Smith /// integer. 495a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx) const; 49651fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson 49751f4708c00110940ca3f337961915f2ca1668375Richard Smith /// EvaluateAsLValue - Evaluate an expression to see if we can fold it to an 49851f4708c00110940ca3f337961915f2ca1668375Richard Smith /// lvalue with link time known address, with no side-effects. 4994ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx) const; 5001b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson 501099e7f647ccda915513f2b2ec53352dc756082d3Richard Smith /// EvaluateAsInitializer - Evaluate an expression as if it were the 502099e7f647ccda915513f2b2ec53352dc756082d3Richard Smith /// initializer of the given declaration. Returns true if the initializer 503099e7f647ccda915513f2b2ec53352dc756082d3Richard Smith /// can be folded to a constant, and produces any relevant notes. In C++11, 504099e7f647ccda915513f2b2ec53352dc756082d3Richard Smith /// notes will be produced if the expression is not a constant expression. 505099e7f647ccda915513f2b2ec53352dc756082d3Richard Smith bool EvaluateAsInitializer(APValue &Result, const ASTContext &Ctx, 506099e7f647ccda915513f2b2ec53352dc756082d3Richard Smith const VarDecl *VD, 507099e7f647ccda915513f2b2ec53352dc756082d3Richard Smith llvm::SmallVectorImpl<PartialDiagnosticAt> &Notes) const; 508099e7f647ccda915513f2b2ec53352dc756082d3Richard Smith 50982214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Enumeration used to describe the kind of Null pointer constant 51082214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// returned from \c isNullPointerConstant(). 51182214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth enum NullPointerConstantKind { 51282214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Expression is not a Null pointer constant. 51382214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NPCK_NotNull = 0, 51482214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 51582214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Expression is a Null pointer constant built from a zero integer. 51682214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NPCK_ZeroInteger, 51782214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 51882214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Expression is a C++0X nullptr. 51982214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NPCK_CXX0X_nullptr, 52082214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 52182214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Expression is a GNU-style __null constant. 52282214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NPCK_GNUNull 52382214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth }; 52482214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 525ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Enumeration used to describe how \c isNullPointerConstant() 526ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// should cope with value-dependent expressions. 527ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor enum NullPointerConstantValueDependence { 528ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that the expression should never be value-dependent. 529ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_NeverValueDependent = 0, 530ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 531ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that a value-dependent expression of integral or 532ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// dependent type should be considered a null pointer constant. 533ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_ValueDependentIsNull, 534ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 535ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that a value-dependent expression should be considered 536ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// to never be a null pointer constant. 537ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_ValueDependentIsNotNull 538ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor }; 539ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 54082214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to 54182214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// a Null pointer constant. The return value can further distinguish the 54282214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// kind of NULL pointer constant that was detected. 54382214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NullPointerConstantKind isNullPointerConstant( 54482214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth ASTContext &Ctx, 54582214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NullPointerConstantValueDependence NPC) const; 546efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson 54744baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian /// isOBJCGCCandidate - Return true if this expression may be used in a read/ 5481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// write barrier. 549102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian bool isOBJCGCCandidate(ASTContext &Ctx) const; 5501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 55111ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis /// \brief Returns true if this expression is a bound member function. 55211ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis bool isBoundMemberFunction(ASTContext &Ctx) const; 55311ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis 554864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// \brief Given an expression of bound-member type, find the type 555864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// of the member. Returns null if this is an *overloaded* bound 556864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// member expression. 557864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall static QualType findBoundMemberType(const Expr *expr); 558864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 559369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// \brief Result type of CanThrow(). 560369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl enum CanThrowResult { 561369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CT_Cannot, 562369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CT_Dependent, 563369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CT_Can 564369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl }; 565369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// \brief Test if this expression, if evaluated, might throw, according to 566369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// the rules of C++ [expr.unary.noexcept]. 567369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CanThrowResult CanThrow(ASTContext &C) const; 568369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 56991a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall /// IgnoreImpCasts - Skip past any implicit casts which might 57091a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall /// surround this expression. Only skips ImplicitCastExprs. 57191a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall Expr *IgnoreImpCasts(); 57291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 5737e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall /// IgnoreImplicit - Skip past any implicit AST nodes which might 5747e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall /// surround this expression. 5757e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall Expr *IgnoreImplicit() { return cast<Expr>(Stmt::IgnoreImplicit()); } 5767e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall 5774e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// IgnoreParens - Ignore parentheses. If this Expr is a ParenExpr, return 5781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// its subexpression. If that subexpression is also a ParenExpr, 5794e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// then this method recursively returns its subexpression, and so forth. 5804e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// Otherwise, the method returns the current Expr. 5812b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner Expr *IgnoreParens(); 58256f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner 58356f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner /// IgnoreParenCasts - Ignore parentheses and casts. Strip off any ParenExpr 58427c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor /// or CastExprs, returning their operand. 58556f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner Expr *IgnoreParenCasts(); 5861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 587ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// IgnoreParenImpCasts - Ignore parentheses and implicit casts. Strip off 588ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// any ParenExpr or ImplicitCastExprs, returning their operand. 5892fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall Expr *IgnoreParenImpCasts(); 5902fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall 5912f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg /// IgnoreConversionOperator - Ignore conversion operator. If this Expr is a 5922f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg /// call to a conversion operator, return the argument. 5932f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg Expr *IgnoreConversionOperator(); 5942f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg 5952f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg const Expr *IgnoreConversionOperator() const { 5962f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg return const_cast<Expr*>(this)->IgnoreConversionOperator(); 5972f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg } 5982f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg 5994d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek const Expr *IgnoreParenImpCasts() const { 6004d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek return const_cast<Expr*>(this)->IgnoreParenImpCasts(); 6014d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek } 602ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 603f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall /// Ignore parentheses and lvalue casts. Strip off any ParenExpr and 604f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall /// CastExprs that represent lvalue casts, returning their operand. 605f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall Expr *IgnoreParenLValueCasts(); 606ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 607f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall const Expr *IgnoreParenLValueCasts() const { 608f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall return const_cast<Expr*>(this)->IgnoreParenLValueCasts(); 609f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 6104d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek 611ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the 612ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// value (including ptr->int casts of the same size). Strip off any 613ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// ParenExpr or CastExprs, returning their operand. 614ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Expr *IgnoreParenNoopCasts(ASTContext &Ctx); 6151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6166eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// \brief Determine whether this expression is a default function argument. 6176eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// 6186eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// Default arguments are implicitly generated in the abstract syntax tree 619ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// by semantic analysis for function calls, object constructions, etc. in 6206eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// C++. Default arguments are represented by \c CXXDefaultArgExpr nodes; 6216eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// this routine also looks through any implicit casts to determine whether 6226eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// the expression is a default argument. 6236eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor bool isDefaultArgument() const; 624ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 625558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall /// \brief Determine whether the result of this expression is a 626558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall /// temporary object of the given class type. 627558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const; 6282f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 62975e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor /// \brief Whether this expression is an implicit reference to 'this' in C++. 63075e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor bool isImplicitCXXThis() const; 63191a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 63291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall const Expr *IgnoreImpCasts() const { 63391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall return const_cast<Expr*>(this)->IgnoreImpCasts(); 63491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall } 6352b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner const Expr *IgnoreParens() const { 6364e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek return const_cast<Expr*>(this)->IgnoreParens(); 6374e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek } 63856f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner const Expr *IgnoreParenCasts() const { 63956f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner return const_cast<Expr*>(this)->IgnoreParenCasts(); 64056f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner } 641ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner const Expr *IgnoreParenNoopCasts(ASTContext &Ctx) const { 642ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner return const_cast<Expr*>(this)->IgnoreParenNoopCasts(Ctx); 643ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 6441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 645898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs); 646898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs); 647898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 6481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 6495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() >= firstExprConstant && 6501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump T->getStmtClass() <= lastExprConstant; 6515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Expr *) { return true; } 6535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 6545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6565549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek//===----------------------------------------------------------------------===// 6575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Primary Expressions. 6585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 6595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 66056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// OpaqueValueExpr - An expression referring to an opaque object of a 66156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// fixed type and value class. These don't correspond to concrete 66256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// syntax; instead they're used to express operations (usually copy 66356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// operations) on values whose source is generally obvious from 66456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// context. 66556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass OpaqueValueExpr : public Expr { 66656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall friend class ASTStmtReader; 66756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *SourceExpr; 66856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation Loc; 669ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 67056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallpublic: 671ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie OpaqueValueExpr(SourceLocation Loc, QualType T, ExprValueKind VK, 67256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall ExprObjectKind OK = OK_Ordinary) 67356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : Expr(OpaqueValueExprClass, T, VK, OK, 674ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie T->isDependentType(), T->isDependentType(), 675561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor T->isInstantiationDependentType(), 676ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie false), 67756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceExpr(0), Loc(Loc) { 67856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 67956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 68056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// Given an expression which invokes a copy constructor --- i.e. a 68156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// CXXConstructExpr, possibly wrapped in an ExprWithCleanups --- 68256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// find the OpaqueValueExpr that's the source of the construction. 68356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static const OpaqueValueExpr *findInCopyConstruct(const Expr *expr); 68456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 68556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall explicit OpaqueValueExpr(EmptyShell Empty) 68656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : Expr(OpaqueValueExprClass, Empty) { } 68756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 68856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief Retrieve the location of this expression. 68956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation getLocation() const { return Loc; } 690ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 69156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceRange getSourceRange() const { 69256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (SourceExpr) return SourceExpr->getSourceRange(); 69356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return Loc; 69456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 69556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation getExprLoc() const { 69656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (SourceExpr) return SourceExpr->getExprLoc(); 69756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return Loc; 69856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 69956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 70056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall child_range children() { return child_range(); } 70156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 70256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// The source expression of an opaque value expression is the 70356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// expression which originally generated the value. This is 70456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// provided as a convenience for analyses that don't wish to 70556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// precisely model the execution behavior of the program. 70656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// 70756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// The source expression is typically set when building the 70856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// expression which binds the opaque value expression in the first 70956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// place. 71056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getSourceExpr() const { return SourceExpr; } 71156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall void setSourceExpr(Expr *e) { SourceExpr = e; } 71256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 71356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const Stmt *T) { 71456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return T->getStmtClass() == OpaqueValueExprClass; 71556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 71656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const OpaqueValueExpr *) { return true; } 71756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall}; 71856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 719cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// \brief A reference to a declared variable, function, enum, etc. 720cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// [C99 6.5.1p2] 721cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// 722cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// This encodes all the information about how a declaration is referenced 723cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// within an expression. 724cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// 725cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// There are several optional constructs attached to DeclRefExprs only when 726cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// they apply in order to conserve memory. These are laid out past the end of 727cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// the object, and flags in the DeclRefExprBitfield track whether they exist: 728cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// 729cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// DeclRefExprBits.HasQualifier: 730cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// Specifies when this declaration reference expression has a C++ 731cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// nested-name-specifier. 7323aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth/// DeclRefExprBits.HasFoundDecl: 7333aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth/// Specifies when this declaration reference expression has a record of 7343aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth/// a NamedDecl (different from the referenced ValueDecl) which was found 7353aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth/// during name lookup and/or overload resolution. 736cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// DeclRefExprBits.HasExplicitTemplateArgs: 737cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// Specifies when this declaration reference expression has an explicit 738cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// C++ template argument list. 7395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclRefExpr : public Expr { 740cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth /// \brief The declaration that we are referencing. 741cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth ValueDecl *D; 7422577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 743cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth /// \brief The location of the declaration name itself. 7445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 7459e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis 746cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth /// \brief Provides source/type location info for the declaration name 747cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth /// embedded in D. 7482577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameLoc DNLoc; 7492577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 7506857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// \brief Helper to retrieve the optional NestedNameSpecifierLoc. 7516857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth NestedNameSpecifierLoc &getInternalQualifierLoc() { 7527e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth assert(hasQualifier()); 7536857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth return *reinterpret_cast<NestedNameSpecifierLoc *>(this + 1); 754a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 755cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth 7566857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// \brief Helper to retrieve the optional NestedNameSpecifierLoc. 7576857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth const NestedNameSpecifierLoc &getInternalQualifierLoc() const { 7586857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth return const_cast<DeclRefExpr *>(this)->getInternalQualifierLoc(); 759a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 760096832c5ed5b9106fa177ebc148489760c3bc496John McCall 7613aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// \brief Test whether there is a distinct FoundDecl attached to the end of 7623aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// this DRE. 7633aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth bool hasFoundDecl() const { return DeclRefExprBits.HasFoundDecl; } 7643aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 7653aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// \brief Helper to retrieve the optional NamedDecl through which this 7663aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// reference occured. 7673aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *&getInternalFoundDecl() { 7683aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth assert(hasFoundDecl()); 7693aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth if (hasQualifier()) 7703aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return *reinterpret_cast<NamedDecl **>(&getInternalQualifierLoc() + 1); 7713aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return *reinterpret_cast<NamedDecl **>(this + 1); 7723aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth } 7733aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 7743aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// \brief Helper to retrieve the optional NamedDecl through which this 7753aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// reference occured. 7763aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *getInternalFoundDecl() const { 7773aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return const_cast<DeclRefExpr *>(this)->getInternalFoundDecl(); 7783aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth } 7793aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 7807e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth DeclRefExpr(NestedNameSpecifierLoc QualifierLoc, 7812577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ValueDecl *D, const DeclarationNameInfo &NameInfo, 7823aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *FoundD, 7832577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const TemplateArgumentListInfo *TemplateArgs, 784f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK); 7852577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 786663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis /// \brief Construct an empty declaration reference expression. 787663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis explicit DeclRefExpr(EmptyShell Empty) 788663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis : Expr(DeclRefExprClass, Empty) { } 7897e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 7900da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor /// \brief Computes the type- and value-dependence flags for this 7910da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor /// declaration reference expression. 7920da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor void computeDependence(); 7939e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis 7945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 7955b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor DeclRefExpr(ValueDecl *D, QualType T, ExprValueKind VK, SourceLocation L, 7965b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor const DeclarationNameLoc &LocInfo = DeclarationNameLoc()) 797561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Expr(DeclRefExprClass, T, VK, OK_Ordinary, false, false, false, false), 7985b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor D(D), Loc(L), DNLoc(LocInfo) { 799cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth DeclRefExprBits.HasQualifier = 0; 800cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth DeclRefExprBits.HasExplicitTemplateArgs = 0; 8013aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth DeclRefExprBits.HasFoundDecl = 0; 8027cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara DeclRefExprBits.HadMultipleCandidates = 0; 8030da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor computeDependence(); 8040da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor } 8051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 806a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor static DeclRefExpr *Create(ASTContext &Context, 80740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 808dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *D, 809a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation NameLoc, 810f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK, 8113aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *FoundD = 0, 8120da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor const TemplateArgumentListInfo *TemplateArgs = 0); 813663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis 8142577743c5650c646fb705df01403707e94f2df04Abramo Bagnara static DeclRefExpr *Create(ASTContext &Context, 81540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 8162577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ValueDecl *D, 8172577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 818f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK, 8193aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *FoundD = 0, 8202577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const TemplateArgumentListInfo *TemplateArgs = 0); 8212577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 822663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis /// \brief Construct an empty declaration reference expression. 823663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis static DeclRefExpr *CreateEmpty(ASTContext &Context, 8243aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth bool HasQualifier, 8253aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth bool HasFoundDecl, 826def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor bool HasExplicitTemplateArgs, 827def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor unsigned NumTemplateArgs); 8287e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 829cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth ValueDecl *getDecl() { return D; } 830cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth const ValueDecl *getDecl() const { return D; } 831cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth void setDecl(ValueDecl *NewD) { D = NewD; } 832904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor 8332577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo getNameInfo() const { 8342577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(getDecl()->getDeclName(), Loc, DNLoc); 8352577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 8362577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 8379e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis SourceLocation getLocation() const { return Loc; } 8380b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 83963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const; 8401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 841a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Determine whether this declaration reference was preceded by a 842a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// C++ nested-name-specifier, e.g., \c N::foo. 843cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth bool hasQualifier() const { return DeclRefExprBits.HasQualifier; } 8447e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 8457e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth /// \brief If the name was qualified, retrieves the nested-name-specifier 846a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// that precedes the name. Otherwise, returns NULL. 847a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NestedNameSpecifier *getQualifier() const { 848a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (!hasQualifier()) 849a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 8507e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 8516857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth return getInternalQualifierLoc().getNestedNameSpecifier(); 852a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 85340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor 8547e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth /// \brief If the name was qualified, retrieves the nested-name-specifier 85540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor /// that precedes the name, with source-location information. 85640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc getQualifierLoc() const { 85740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (!hasQualifier()) 85840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return NestedNameSpecifierLoc(); 8597e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 8606857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth return getInternalQualifierLoc(); 86140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor } 86240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor 8633aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// \brief Get the NamedDecl through which this reference occured. 8643aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// 8653aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// This Decl may be different from the ValueDecl actually referred to in the 8663aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// presence of using declarations, etc. It always returns non-NULL, and may 8673aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// simple return the ValueDecl when appropriate. 8683aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *getFoundDecl() { 8693aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return hasFoundDecl() ? getInternalFoundDecl() : D; 8703aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth } 8713aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 8723aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// \brief Get the NamedDecl through which this reference occurred. 8733aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// See non-const variant. 8743aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth const NamedDecl *getFoundDecl() const { 8753aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return hasFoundDecl() ? getInternalFoundDecl() : D; 8763aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth } 8773aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 8787e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth /// \brief Determines whether this declaration reference was followed by an 8797e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth /// explict template argument list. 880096832c5ed5b9106fa177ebc148489760c3bc496John McCall bool hasExplicitTemplateArgs() const { 881cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth return DeclRefExprBits.HasExplicitTemplateArgs; 882096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 8837e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 884096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that followed the 885096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// member template name. 886b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 887096832c5ed5b9106fa177ebc148489760c3bc496John McCall assert(hasExplicitTemplateArgs()); 8883aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth if (hasFoundDecl()) 889b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis return *reinterpret_cast<ASTTemplateArgumentListInfo *>( 8903aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth &getInternalFoundDecl() + 1); 8913aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 8923aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth if (hasQualifier()) 893b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis return *reinterpret_cast<ASTTemplateArgumentListInfo *>( 8943aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth &getInternalQualifierLoc() + 1); 8957e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 896b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis return *reinterpret_cast<ASTTemplateArgumentListInfo *>(this + 1); 897096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 8987e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 899096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that followed the 900096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// member template name. 901b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 902096832c5ed5b9106fa177ebc148489760c3bc496John McCall return const_cast<DeclRefExpr *>(this)->getExplicitTemplateArgs(); 903a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 904d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 905096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieves the optional explicit template arguments. 906096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// This points to the same data as getExplicitTemplateArgs(), but 907096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// returns null if there are no explicit template arguments. 908b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis const ASTTemplateArgumentListInfo *getExplicitTemplateArgsOpt() const { 909096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) return 0; 910096832c5ed5b9106fa177ebc148489760c3bc496John McCall return &getExplicitTemplateArgs(); 911096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 9127e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 913d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// \brief Copies the template arguments (if present) into the given 914d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// structure. 915d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 916096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (hasExplicitTemplateArgs()) 917096832c5ed5b9106fa177ebc148489760c3bc496John McCall getExplicitTemplateArgs().copyInto(List); 918d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall } 9197e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 920a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the location of the left angle bracket following the 921a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// member name ('<'), if any. 922a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation getLAngleLoc() const { 923096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 924a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return SourceLocation(); 9257e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 926096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().LAngleLoc; 927a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 9287e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 929a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the template arguments provided as part of this 930a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template-id. 931833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc *getTemplateArgs() const { 932096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 933a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 9347e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 935096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().getTemplateArgs(); 936a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 9377e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 938a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the number of template arguments provided as part of this 939a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template-id. 940a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor unsigned getNumTemplateArgs() const { 941096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 942a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 9437e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 944096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().NumTemplateArgs; 945a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 9467e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 947a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the location of the right angle bracket following the 948a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template arguments ('>'). 949a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation getRAngleLoc() const { 950096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 951a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return SourceLocation(); 9527e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 953096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().RAngleLoc; 954a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 9557e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 9567cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// \brief Returns true if this expression refers to a function that 9577cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// was resolved from an overloaded set having size greater than 1. 9587cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool hadMultipleCandidates() const { 9597cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara return DeclRefExprBits.HadMultipleCandidates; 9607cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara } 9617cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// \brief Sets the flag telling whether this expression refers to 9627cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// a function that was resolved from an overloaded set having size 9637cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// greater than 1. 9647cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara void setHadMultipleCandidates(bool V = true) { 9657cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara DeclRefExprBits.HadMultipleCandidates = V; 9667cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara } 9677cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara 9681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 96999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor return T->getStmtClass() == DeclRefExprClass; 9705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const DeclRefExpr *) { return true; } 9721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 97377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 97463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 9757e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 97660adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 9773397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl friend class ASTStmtWriter; 9785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 9795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 980d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner/// PredefinedExpr - [C99 6.4.2.2] - A predefined identifier such as __func__. 981d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattnerclass PredefinedExpr : public Expr { 982227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic: 983227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson enum IdentType { 984227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson Func, 985227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson Function, 986848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson PrettyFunction, 987848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson /// PrettyFunctionNoVirtual - The same as PrettyFunction, except that the 988848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson /// 'virtual' keyword is omitted for virtual member functions. 989848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson PrettyFunctionNoVirtual 990227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson }; 9911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 992227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonprivate: 993227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson SourceLocation Loc; 994227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson IdentType Type; 995227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic: 9961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump PredefinedExpr(SourceLocation l, QualType type, IdentType IT) 997f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(PredefinedExprClass, type, VK_LValue, OK_Ordinary, 998ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie type->isDependentType(), type->isDependentType(), 999561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor type->isInstantiationDependentType(), 1000bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 1001f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Loc(l), Type(IT) {} 10021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 100317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor /// \brief Construct an empty predefined expression. 10041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit PredefinedExpr(EmptyShell Empty) 100517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor : Expr(PredefinedExprClass, Empty) { } 100617fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 1007227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson IdentType getIdentType() const { return Type; } 100817fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setIdentType(IdentType IT) { Type = IT; } 100917fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 101017fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor SourceLocation getLocation() const { return Loc; } 101117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 101217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 1013848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson static std::string ComputeName(IdentType IT, const Decl *CurrentDecl); 10143a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 101563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 1016227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 10171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 10181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == PredefinedExprClass; 1019227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson } 1020d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner static bool classof(const PredefinedExpr *) { return true; } 10211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 102277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 102363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 1024227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson}; 1025227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 10269996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// \brief Used by IntegerLiteral/FloatingLiteral to store the numeric without 10279996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// leaking memory. 10289996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// 10299996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// For large floats/integers, APFloat/APInt will allocate memory from the heap 10309996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// to represent these numbers. Unfortunately, when we use a BumpPtrAllocator 10319996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// to allocate IntegerLiteral/FloatingLiteral nodes the memory associated with 10329996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// the APFloat/APInt values will never get freed. APNumericStorage uses 10339996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// ASTContext's allocator for memory allocation. 10349996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisclass APNumericStorage { 10359996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis unsigned BitWidth; 10369996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis union { 10379996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis uint64_t VAL; ///< Used to store the <= 64 bits integer value. 10389996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis uint64_t *pVal; ///< Used to store the >64 bits integer value. 10399996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis }; 10409996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10419996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis bool hasAllocation() const { return llvm::APInt::getNumWords(BitWidth) > 1; } 10429996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10439996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APNumericStorage(const APNumericStorage&); // do not implement 10449996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APNumericStorage& operator=(const APNumericStorage&); // do not implement 10459996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10469996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisprotected: 10479996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APNumericStorage() : BitWidth(0), VAL(0) { } 10489996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10499996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APInt getIntValue() const { 10509996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis unsigned NumWords = llvm::APInt::getNumWords(BitWidth); 10519996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis if (NumWords > 1) 10529996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return llvm::APInt(BitWidth, NumWords, pVal); 10539996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis else 10549996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return llvm::APInt(BitWidth, VAL); 10559996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 10569996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setIntValue(ASTContext &C, const llvm::APInt &Val); 10579996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis}; 10589996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10599996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisclass APIntStorage : public APNumericStorage { 1060ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikiepublic: 1061ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie llvm::APInt getValue() const { return getIntValue(); } 10629996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setValue(ASTContext &C, const llvm::APInt &Val) { setIntValue(C, Val); } 10639996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis}; 10649996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10659996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisclass APFloatStorage : public APNumericStorage { 1066ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikiepublic: 106731dfd642d5ac33c4ee0cfe1d7a1d4da455dcc7a4Akira Hatanaka llvm::APFloat getValue(bool IsIEEE) const { 106831dfd642d5ac33c4ee0cfe1d7a1d4da455dcc7a4Akira Hatanaka return llvm::APFloat(getIntValue(), IsIEEE); 106931dfd642d5ac33c4ee0cfe1d7a1d4da455dcc7a4Akira Hatanaka } 10709996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setValue(ASTContext &C, const llvm::APFloat &Val) { 10719996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis setIntValue(C, Val.bitcastToAPInt()); 10729996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 10739996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis}; 10749996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IntegerLiteral : public Expr { 10769996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APIntStorage Num; 10775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 10789996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10799996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis /// \brief Construct an empty integer literal. 10809996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis explicit IntegerLiteral(EmptyShell Empty) 10819996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis : Expr(IntegerLiteralClass, Empty) { } 10829996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 10841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy, 10855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // or UnsignedLongLongTy 10869996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis IntegerLiteral(ASTContext &C, const llvm::APInt &V, 10879996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis QualType type, SourceLocation l) 1088bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(IntegerLiteralClass, type, VK_RValue, OK_Ordinary, false, false, 1089561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false), 1090f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Loc(l) { 10915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(type->isIntegerType() && "Illegal type in IntegerLiteral"); 10921dd986dff9ddfbec687975700770bb377988e9edRichard Trieu assert(V.getBitWidth() == C.getIntWidth(type) && 10931dd986dff9ddfbec687975700770bb377988e9edRichard Trieu "Integer type is not the correct size for constant."); 10949996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis setValue(C, V); 10955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1096a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson 10971dd986dff9ddfbec687975700770bb377988e9edRichard Trieu /// \brief Returns a new integer literal with value 'V' and type 'type'. 10981dd986dff9ddfbec687975700770bb377988e9edRichard Trieu /// \param type - either IntTy, LongTy, LongLongTy, UnsignedIntTy, 10991dd986dff9ddfbec687975700770bb377988e9edRichard Trieu /// UnsignedLongTy, or UnsignedLongLongTy which should match the size of V 11001dd986dff9ddfbec687975700770bb377988e9edRichard Trieu /// \param V - the value that the returned integer literal contains. 11019996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis static IntegerLiteral *Create(ASTContext &C, const llvm::APInt &V, 11029996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis QualType type, SourceLocation l); 11031dd986dff9ddfbec687975700770bb377988e9edRichard Trieu /// \brief Returns a new empty integer literal. 11049996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis static IntegerLiteral *Create(ASTContext &C, EmptyShell Empty); 11050b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 11069996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APInt getValue() const { return Num.getValue(); } 110763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 11085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1109313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Retrieve the location of the literal. 1110313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getLocation() const { return Loc; } 1111313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 11129996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setValue(ASTContext &C, const llvm::APInt &Val) { Num.setValue(C, Val); } 11130b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation Location) { Loc = Location; } 11140b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 11151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 11161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == IntegerLiteralClass; 11175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const IntegerLiteral *) { return true; } 11191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 112077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 112163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 11225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CharacterLiteral : public Expr { 11255cee1195584fa8672253139c86e922daeda69b9eDouglas Gregorpublic: 11265cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor enum CharacterKind { 11275cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor Ascii, 11285cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor Wide, 11295cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor UTF16, 11305cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor UTF32 11315cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor }; 11325cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor 11335cee1195584fa8672253139c86e922daeda69b9eDouglas Gregorprivate: 11345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned Value; 11355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 11365cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor unsigned Kind : 2; 11375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 11385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // type should be IntTy 11395cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor CharacterLiteral(unsigned value, CharacterKind kind, QualType type, 11405cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor SourceLocation l) 1141bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(CharacterLiteralClass, type, VK_RValue, OK_Ordinary, false, false, 1142561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false), 11435cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor Value(value), Loc(l), Kind(kind) { 11445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11450b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 11460b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Construct an empty character literal. 11470b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { } 11480b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 1149018d8e0596dd57401eeddcf11ac84ff0a065fbbeChris Lattner SourceLocation getLocation() const { return Loc; } 11505cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor CharacterKind getKind() const { return static_cast<CharacterKind>(Kind); } 11511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 115263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 11531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getValue() const { return Value; } 11555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11560b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation Location) { Loc = Location; } 11575cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor void setKind(CharacterKind kind) { Kind = kind; } 11580b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setValue(unsigned Val) { Value = Val; } 11590b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 11601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 11611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CharacterLiteralClass; 11625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CharacterLiteral *) { return true; } 116477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 116577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 116663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 11675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FloatingLiteral : public Expr { 11709996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APFloatStorage Num; 117131dfd642d5ac33c4ee0cfe1d7a1d4da455dcc7a4Akira Hatanaka bool IsIEEE : 1; // Distinguishes between PPC128 and IEEE128. 1172720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek bool IsExact : 1; 11735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 11749996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 11759996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis FloatingLiteral(ASTContext &C, const llvm::APFloat &V, bool isexact, 1176720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek QualType Type, SourceLocation L) 1177bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(FloatingLiteralClass, Type, VK_RValue, OK_Ordinary, false, false, 1178561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false), 117931dfd642d5ac33c4ee0cfe1d7a1d4da455dcc7a4Akira Hatanaka IsIEEE(&C.getTargetInfo().getLongDoubleFormat() == 118031dfd642d5ac33c4ee0cfe1d7a1d4da455dcc7a4Akira Hatanaka &llvm::APFloat::IEEEquad), 11819996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis IsExact(isexact), Loc(L) { 11829996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis setValue(C, V); 11839996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 11845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 118517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor /// \brief Construct an empty floating-point literal. 118631dfd642d5ac33c4ee0cfe1d7a1d4da455dcc7a4Akira Hatanaka explicit FloatingLiteral(ASTContext &C, EmptyShell Empty) 118731dfd642d5ac33c4ee0cfe1d7a1d4da455dcc7a4Akira Hatanaka : Expr(FloatingLiteralClass, Empty), 118831dfd642d5ac33c4ee0cfe1d7a1d4da455dcc7a4Akira Hatanaka IsIEEE(&C.getTargetInfo().getLongDoubleFormat() == 118931dfd642d5ac33c4ee0cfe1d7a1d4da455dcc7a4Akira Hatanaka &llvm::APFloat::IEEEquad), 119031dfd642d5ac33c4ee0cfe1d7a1d4da455dcc7a4Akira Hatanaka IsExact(false) { } 119117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 11929996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidispublic: 11939996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis static FloatingLiteral *Create(ASTContext &C, const llvm::APFloat &V, 11949996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis bool isexact, QualType Type, SourceLocation L); 11959996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis static FloatingLiteral *Create(ASTContext &C, EmptyShell Empty); 11969996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 119731dfd642d5ac33c4ee0cfe1d7a1d4da455dcc7a4Akira Hatanaka llvm::APFloat getValue() const { return Num.getValue(IsIEEE); } 11989996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setValue(ASTContext &C, const llvm::APFloat &Val) { 11999996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis Num.setValue(C, Val); 12009996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 120117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 1202720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek bool isExact() const { return IsExact; } 120317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setExact(bool E) { IsExact = E; } 1204c9bec4bfea9090a08dd83a7b213f0c8adf8d78ecChris Lattner 1205da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// getValueAsApproximateDouble - This returns the value as an inaccurate 1206da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// double. Note that this may cause loss of precision, but is useful for 1207da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// debugging dumps, etc. 1208da8249e57f3badecf925571881fe57243935c6c1Chris Lattner double getValueAsApproximateDouble() const; 12091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 121017fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor SourceLocation getLocation() const { return Loc; } 121117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 121217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 121363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 12145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 12161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == FloatingLiteralClass; 12175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const FloatingLiteral *) { return true; } 12191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 122077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 122163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 12225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 12235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12245d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// ImaginaryLiteral - We support imaginary integer and floating point literals, 12255d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// like "1.0i". We represent these as a wrapper around FloatingLiteral and 12265d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// IntegerLiteral classes. Instances of this class always have a Complex type 12275d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// whose element type matches the subexpression. 12285d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// 12295d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerclass ImaginaryLiteral : public Expr { 12305549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 12315d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerpublic: 12325d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner ImaginaryLiteral(Expr *val, QualType Ty) 1233bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(ImaginaryLiteralClass, Ty, VK_RValue, OK_Ordinary, false, false, 1234561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false), 1235f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Val(val) {} 12361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1237cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor /// \brief Build an empty imaginary literal. 12381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ImaginaryLiteral(EmptyShell Empty) 1239cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor : Expr(ImaginaryLiteralClass, Empty) { } 1240cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 12415549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 12425549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 1243cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 1244cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 124563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return Val->getSourceRange(); } 12461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 12471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ImaginaryLiteralClass; 12485d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner } 12495d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner static bool classof(const ImaginaryLiteral *) { return true; } 12501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12515d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner // Iterators 125263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Val, &Val+1); } 12535d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner}; 12545d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner 1255e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// StringLiteral - This represents a string literal expression, e.g. "foo" 1256e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// or L"bar" (wide strings). The actual string is returned by getStrData() 1257e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// is NOT null-terminated, and the length of the string is determined by 1258a7ad98ff0919d6a24ea7c46634ea29bea551c1a0Chris Lattner/// calling getByteLength(). The C type for a string is always a 1259c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// ConstantArrayType. In C++, the char type is const qualified, in C it is 1260c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// not. 1261690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// 1262690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// Note that strings in C can be formed by concatenation of multiple string 12638bea7c0ee44c71c817de7dc2be932b73bec90c9fChris Lattner/// literal pptokens in translation phase #6. This keeps track of the locations 1264690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// of each of these pieces. 1265c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// 1266c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// Strings in C can also be truncated and extended by assigning into arrays, 1267c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// e.g. with constructs like: 1268c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// char X[2] = "foobar"; 1269c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// In this case, getByteLength() will return 6, but the string literal will 1270c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// have type "char[2]". 12715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass StringLiteral : public Expr { 12725cee1195584fa8672253139c86e922daeda69b9eDouglas Gregorpublic: 12735cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor enum StringKind { 12745cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor Ascii, 12755cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor Wide, 12765cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor UTF8, 12775cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor UTF16, 12785cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor UTF32 12795cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor }; 12805cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor 12815cee1195584fa8672253139c86e922daeda69b9eDouglas Gregorprivate: 12823e2193ce5feb2feb092e5ae615e85148e06e9fd2Anders Carlsson friend class ASTStmtReader; 12833e2193ce5feb2feb092e5ae615e85148e06e9fd2Anders Carlsson 128464f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman union { 128564f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman const char *asChar; 128664f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman const uint16_t *asUInt16; 128764f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman const uint32_t *asUInt32; 128864f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman } StrData; 128964f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman unsigned Length; 129064f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman unsigned CharByteWidth; 1291726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner unsigned NumConcatenated; 12925cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor unsigned Kind : 3; 12935cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor bool IsPascal : 1; 1294726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner SourceLocation TokLocs[1]; 12952085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner 1296f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall StringLiteral(QualType Ty) : 1297561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Expr(StringLiteralClass, Ty, VK_LValue, OK_Ordinary, false, false, false, 1298561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false) {} 12991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 130064f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman static int mapCharByteWidth(TargetInfo const &target,StringKind k); 130164f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman 13025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 13032085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// This is the "fully general" constructor that allows representation of 13042085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// strings formed from multiple concatenated tokens. 13055cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor static StringLiteral *Create(ASTContext &C, StringRef Str, StringKind Kind, 130665aa6885818d4b4eea2e5a9d12085b2398148662Jay Foad bool Pascal, QualType Ty, 1307a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson const SourceLocation *Loc, unsigned NumStrs); 13082085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner 13092085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// Simple constructor for string literals made from one token. 13105cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor static StringLiteral *Create(ASTContext &C, StringRef Str, StringKind Kind, 13115cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor bool Pascal, QualType Ty, 13125cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor SourceLocation Loc) { 13135cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor return Create(C, Str, Kind, Pascal, Ty, &Loc, 1); 13142085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 1315a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson 1316673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor /// \brief Construct an empty string literal. 1317673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor static StringLiteral *CreateEmpty(ASTContext &C, unsigned NumStrs); 1318673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 1319686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef getString() const { 132064f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman assert(CharByteWidth==1 132164f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman && "This function is used in places that assume strings use char"); 132264f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman return StringRef(StrData.asChar, getByteLength()); 132364f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman } 132464f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman 132564f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman /// Allow clients that need the byte representation, such as ASTWriterStmt 132664f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman /// ::VisitStringLiteral(), access. 132764f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman StringRef getBytes() const { 132864f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman // FIXME: StringRef may not be the right type to use as a result for this... 132964f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman assert((CharByteWidth==1 || CharByteWidth==2 || CharByteWidth==4) 133064f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman && "unsupported CharByteWidth"); 133164f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman if (CharByteWidth==4) { 133264f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman return StringRef(reinterpret_cast<const char*>(StrData.asUInt32), 133364f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman getByteLength()); 133464f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman } else if (CharByteWidth==2) { 133564f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman return StringRef(reinterpret_cast<const char*>(StrData.asUInt16), 133664f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman getByteLength()); 133764f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman } else { 133864f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman return StringRef(StrData.asChar, getByteLength()); 133964f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman } 1340b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar } 13412f4eaef37476ae6891ede8ba215d0f6fd093629bBenjamin Kramer 134264f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman uint32_t getCodeUnit(size_t i) const { 134364f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman assert(i<Length && "out of bounds access"); 134464f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman assert((CharByteWidth==1 || CharByteWidth==2 || CharByteWidth==4) 134564f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman && "unsupported CharByteWidth"); 134664f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman if (CharByteWidth==4) { 134764f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman return StrData.asUInt32[i]; 134864f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman } else if (CharByteWidth==2) { 134964f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman return StrData.asUInt16[i]; 135064f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman } else { 135164f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman return static_cast<unsigned char>(StrData.asChar[i]); 135264f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman } 135364f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman } 135464f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman 135564f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman unsigned getByteLength() const { return CharByteWidth*Length; } 135664f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman unsigned getLength() const { return Length; } 135764f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman unsigned getCharByteWidth() const { return CharByteWidth; } 1358673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 1359673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor /// \brief Sets the string data to the given string data. 136064f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman void setString(ASTContext &C, StringRef Str, 136164f45a24b19eb89ff88f7c3ff0df9be8e861ac97Eli Friedman StringKind Kind, bool IsPascal); 1362673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 13635cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor StringKind getKind() const { return static_cast<StringKind>(Kind); } 1364ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1365ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 13665cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor bool isAscii() const { return Kind == Ascii; } 13675cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor bool isWide() const { return Kind == Wide; } 13685cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor bool isUTF8() const { return Kind == UTF8; } 13695cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor bool isUTF16() const { return Kind == UTF16; } 13705cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor bool isUTF32() const { return Kind == UTF32; } 13713e2193ce5feb2feb092e5ae615e85148e06e9fd2Anders Carlsson bool isPascal() const { return IsPascal; } 13725cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor 13738d4141f83d9de379547cf05bd75d4c6cf894b189Steve Naroff bool containsNonAsciiOrNull() const { 1374686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef Str = getString(); 1375b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar for (unsigned i = 0, e = Str.size(); i != e; ++i) 1376b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar if (!isascii(Str[i]) || !Str[i]) 137733fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff return true; 137833fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff return false; 137933fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff } 1380ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1381726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner /// getNumConcatenated - Get the number of string literal tokens that were 1382726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner /// concatenated in translation phase #6 to form this string literal. 1383726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner unsigned getNumConcatenated() const { return NumConcatenated; } 13841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1385726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner SourceLocation getStrTokenLoc(unsigned TokNum) const { 1386726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner assert(TokNum < NumConcatenated && "Invalid tok number"); 1387726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner return TokLocs[TokNum]; 1388726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner } 13891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setStrTokenLoc(unsigned TokNum, SourceLocation L) { 1390673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor assert(TokNum < NumConcatenated && "Invalid tok number"); 1391673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor TokLocs[TokNum] = L; 1392673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor } 1393ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 139408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// getLocationOfByte - Return a source location that points to the specified 139508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// byte of this string literal. 139608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// 139708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// Strings are amazingly complex. They can be formed from multiple tokens 139808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// and can have escape sequences in them in addition to the usual trigraph 139908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// and escaped newline business. This routine handles this complexity. 140008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// 140108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner SourceLocation getLocationOfByte(unsigned ByteNo, const SourceManager &SM, 140208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner const LangOptions &Features, 140308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner const TargetInfo &Target) const; 1404673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 1405b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner typedef const SourceLocation *tokloc_iterator; 1406b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner tokloc_iterator tokloc_begin() const { return TokLocs; } 1407b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner tokloc_iterator tokloc_end() const { return TokLocs+NumConcatenated; } 14085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 140963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 14101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(TokLocs[0], TokLocs[NumConcatenated-1]); 14115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 14121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 14131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == StringLiteralClass; 14145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 14155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const StringLiteral *) { return true; } 14161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 141777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 141863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 14195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 14205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ParenExpr - This represents a parethesized expression, e.g. "(1)". This 14225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// AST node is only formed if full location information is requested. 14235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ParenExpr : public Expr { 14245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation L, R; 14255549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 14265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 14275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ParenExpr(SourceLocation l, SourceLocation r, Expr *val) 1428898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Expr(ParenExprClass, val->getType(), 1429f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall val->getValueKind(), val->getObjectKind(), 1430bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor val->isTypeDependent(), val->isValueDependent(), 1431561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor val->isInstantiationDependent(), 1432bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor val->containsUnexpandedParameterPack()), 1433898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor L(l), R(r), Val(val) {} 14341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1435c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor /// \brief Construct an empty parenthesized expression. 14361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ParenExpr(EmptyShell Empty) 1437c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor : Expr(ParenExprClass, Empty) { } 1438c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor 14395549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 14405549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 1441c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 1442c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor 144363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(L, R); } 14445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1445313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Get the location of the left parentheses '('. 1446313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getLParen() const { return L; } 1447c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setLParen(SourceLocation Loc) { L = Loc; } 1448313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 1449313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Get the location of the right parentheses ')'. 1450313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getRParen() const { return R; } 1451c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setRParen(SourceLocation Loc) { R = Loc; } 1452313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 14531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 14541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ParenExprClass; 14555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 14565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ParenExpr *) { return true; } 14571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 145877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 145963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Val, &Val+1); } 14605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 14615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14630518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// UnaryOperator - This represents the unary-expression's (except sizeof and 14640518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// alignof), the postinc/postdec operators from postfix-expression, and various 14655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// extensions. 1466dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 1467dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Notes on various nodes: 1468dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 1469dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Real/Imag - These return the real/imag part of a complex operand. If 1470dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// applied to a non-complex value, the former returns its operand and the 1471dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// later returns zero in the type of the operand. 1472dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 14735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass UnaryOperator : public Expr { 14745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 14755baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall typedef UnaryOperatorKind Opcode; 14765baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 14775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 14780799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall unsigned Opc : 5; 14795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 14800799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Stmt *Val; 14811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 14825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1483f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall UnaryOperator(Expr *input, Opcode opc, QualType type, 1484f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, SourceLocation l) 1485f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(UnaryOperatorClass, type, VK, OK, 1486de7e66256b1bdfcf6526994825a8c8fced52a31cEli Friedman input->isTypeDependent() || type->isDependentType(), 1487bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor input->isValueDependent(), 1488ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie (input->isInstantiationDependent() || 1489561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor type->isInstantiationDependentType()), 1490bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor input->containsUnexpandedParameterPack()), 14910799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Opc(opc), Loc(l), Val(input) {} 14925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14930b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor /// \brief Build an empty unary operator. 14941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit UnaryOperator(EmptyShell Empty) 14952de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall : Expr(UnaryOperatorClass, Empty), Opc(UO_AddrOf) { } 14960b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 14970799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Opcode getOpcode() const { return static_cast<Opcode>(Opc); } 14980b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOpcode(Opcode O) { Opc = O; } 14990b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 15005549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() const { return cast<Expr>(Val); } 15010b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setSubExpr(Expr *E) { Val = E; } 15020b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 15035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOperatorLoc - Return the location of the operator. 15045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getOperatorLoc() const { return Loc; } 15050b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOperatorLoc(SourceLocation L) { Loc = L; } 15060b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 15075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isPostfix - Return true if this is a postfix operation, like x++. 15082085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static bool isPostfix(Opcode Op) { 15092de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Op == UO_PostInc || Op == UO_PostDec; 15102085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 15115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1512cc7bd10c0de9449b795bda3c5dcc6d83cc48436bZhanyong Wan /// isPrefix - Return true if this is a prefix operation, like --x. 15132085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static bool isPrefix(Opcode Op) { 15142de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Op == UO_PreInc || Op == UO_PreDec; 15152085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 15165a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek 15170799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isPrefix() const { return isPrefix(getOpcode()); } 15180799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isPostfix() const { return isPostfix(getOpcode()); } 15193c3b7f90a863af43fa63043d396553ecf205351cJohn McCall 15203c3b7f90a863af43fa63043d396553ecf205351cJohn McCall static bool isIncrementOp(Opcode Op) { 15213c3b7f90a863af43fa63043d396553ecf205351cJohn McCall return Op == UO_PreInc || Op == UO_PostInc; 15223c3b7f90a863af43fa63043d396553ecf205351cJohn McCall } 15232de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall bool isIncrementOp() const { 15243c3b7f90a863af43fa63043d396553ecf205351cJohn McCall return isIncrementOp(getOpcode()); 15253c3b7f90a863af43fa63043d396553ecf205351cJohn McCall } 15263c3b7f90a863af43fa63043d396553ecf205351cJohn McCall 15273c3b7f90a863af43fa63043d396553ecf205351cJohn McCall static bool isDecrementOp(Opcode Op) { 15283c3b7f90a863af43fa63043d396553ecf205351cJohn McCall return Op == UO_PreDec || Op == UO_PostDec; 15292de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 15303c3b7f90a863af43fa63043d396553ecf205351cJohn McCall bool isDecrementOp() const { 15313c3b7f90a863af43fa63043d396553ecf205351cJohn McCall return isDecrementOp(getOpcode()); 15323c3b7f90a863af43fa63043d396553ecf205351cJohn McCall } 15333c3b7f90a863af43fa63043d396553ecf205351cJohn McCall 15343c3b7f90a863af43fa63043d396553ecf205351cJohn McCall static bool isIncrementDecrementOp(Opcode Op) { return Op <= UO_PreDec; } 15352de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall bool isIncrementDecrementOp() const { 15363c3b7f90a863af43fa63043d396553ecf205351cJohn McCall return isIncrementDecrementOp(getOpcode()); 15372de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 15383c3b7f90a863af43fa63043d396553ecf205351cJohn McCall 15392de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isArithmeticOp(Opcode Op) { 15402de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Op >= UO_Plus && Op <= UO_LNot; 15412de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 15420799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isArithmeticOp() const { return isArithmeticOp(getOpcode()); } 15431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 15455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// corresponds to, e.g. "sizeof" or "[pre]++" 15465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static const char *getOpcodeStr(Opcode Op); 15475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1548bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// \brief Retrieve the unary opcode that corresponds to the given 1549bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// overloaded operator. 1550bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix); 1551bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 1552bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// \brief Retrieve the overloaded operator kind that corresponds to 1553bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// the given unary opcode. 1554bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); 1555bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 155663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 15575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (isPostfix()) 15585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(Val->getLocStart(), Loc); 15595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else 15605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(Loc, Val->getLocEnd()); 15615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 156263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation getExprLoc() const { return Loc; } 15631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 15651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == UnaryOperatorClass; 15665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 15675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const UnaryOperator *) { return true; } 15681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 156977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 157063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Val, &Val+1); } 15715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 15725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15738ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// OffsetOfExpr - [C99 7.17] - This represents an expression of the form 15748ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// offsetof(record-type, member-designator). For example, given: 15758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// @code 15768ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct S { 15778ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// float f; 1578ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// double d; 15798ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// }; 15808ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct T { 15818ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// int i; 15828ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct S s[10]; 15838ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// }; 15848ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// @endcode 1585ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// we can represent and evaluate the expression @c offsetof(struct T, s[2].d). 15868ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 15878ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorclass OffsetOfExpr : public Expr { 15888ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorpublic: 15898ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // __builtin_offsetof(type, identifier(.identifier|[expr])*) 15908ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor class OffsetOfNode { 15918ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor public: 15928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief The kind of offsetof node we have. 15938ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor enum Kind { 1594cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief An index into an array. 15958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Array = 0x00, 1596cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief A field. 15978ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Field = 0x01, 1598cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief A field in a dependent type, known only by its name. 1599cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor Identifier = 0x02, 1600cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief An implicit indirection through a C++ base class, when the 1601cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// field found is in a base class. 1602cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor Base = 0x03 16038ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor }; 16048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 16058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor private: 16068ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor enum { MaskBits = 2, Mask = 0x03 }; 1607ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 16088ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief The source range that covers this part of the designator. 16098ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceRange Range; 1610ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 16118ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief The data describing the designator, which comes in three 16128ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// different forms, depending on the lower two bits. 1613ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// - An unsigned index into the array of Expr*'s stored after this node 16148ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// in memory, for [constant-expression] designators. 16158ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// - A FieldDecl*, for references to a known field. 16168ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// - An IdentifierInfo*, for references to a field with a given name 16178ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// when the class type is dependent. 1618ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// - A CXXBaseSpecifier*, for references that look at a field in a 1619cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// base class. 16208ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor uintptr_t Data; 1621ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 16228ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor public: 16238ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Create an offsetof node that refers to an array element. 1624ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie OffsetOfNode(SourceLocation LBracketLoc, unsigned Index, 16258ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RBracketLoc) 16268ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor : Range(LBracketLoc, RBracketLoc), Data((Index << 2) | Array) { } 1627ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 16288ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Create an offsetof node that refers to a field. 1629ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie OffsetOfNode(SourceLocation DotLoc, FieldDecl *Field, 16308ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation NameLoc) 1631ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc), 16328ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Data(reinterpret_cast<uintptr_t>(Field) | OffsetOfNode::Field) { } 1633ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 16348ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Create an offsetof node that refers to an identifier. 16358ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor OffsetOfNode(SourceLocation DotLoc, IdentifierInfo *Name, 16368ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation NameLoc) 1637ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc), 16388ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Data(reinterpret_cast<uintptr_t>(Name) | Identifier) { } 1639cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor 1640cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief Create an offsetof node that refers into a C++ base class. 1641cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor explicit OffsetOfNode(const CXXBaseSpecifier *Base) 1642cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor : Range(), Data(reinterpret_cast<uintptr_t>(Base) | OffsetOfNode::Base) {} 1643ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 16448ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Determine what kind of offsetof node this is. 1645ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie Kind getKind() const { 16468ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return static_cast<Kind>(Data & Mask); 16478ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1648ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 16498ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief For an array element node, returns the index into the array 16508ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// of expressions. 16518ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned getArrayExprIndex() const { 16528ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(getKind() == Array); 16538ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return Data >> 2; 16548ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 16558ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 16568ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief For a field offsetof node, returns the field. 16578ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor FieldDecl *getField() const { 16588ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(getKind() == Field); 1659cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor return reinterpret_cast<FieldDecl *>(Data & ~(uintptr_t)Mask); 16608ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1661ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 16628ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief For a field or identifier offsetof node, returns the name of 16638ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// the field. 16648ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor IdentifierInfo *getFieldName() const; 1665ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1666cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief For a base class node, returns the base specifier. 1667cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor CXXBaseSpecifier *getBase() const { 1668cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor assert(getKind() == Base); 1669ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return reinterpret_cast<CXXBaseSpecifier *>(Data & ~(uintptr_t)Mask); 1670cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor } 1671ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 16728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Retrieve the source range that covers this offsetof node. 16738ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// 16748ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// For an array element node, the source range contains the locations of 16758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// the square brackets. For a field or identifier node, the source range 1676ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// contains the location of the period (if there is one) and the 16778ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// identifier. 167806dec892b5300b43263d25c5476b506c9d6cfbadAbramo Bagnara SourceRange getSourceRange() const { return Range; } 16798ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor }; 16808ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 16818ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorprivate: 1682ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 16838ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation OperatorLoc, RParenLoc; 16848ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Base type; 16858ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TypeSourceInfo *TSInfo; 16868ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Number of sub-components (i.e. instances of OffsetOfNode). 16878ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumComps; 16888ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Number of sub-expressions (i.e. array subscript expressions). 16898ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumExprs; 1690ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1691ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie OffsetOfExpr(ASTContext &C, QualType type, 16928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation OperatorLoc, TypeSourceInfo *tsi, 1693ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie OffsetOfNode* compsPtr, unsigned numComps, 16948ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr** exprsPtr, unsigned numExprs, 16958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc); 16968ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 16978ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor explicit OffsetOfExpr(unsigned numComps, unsigned numExprs) 16988ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor : Expr(OffsetOfExprClass, EmptyShell()), 1699ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie TSInfo(0), NumComps(numComps), NumExprs(numExprs) {} 17008ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 17018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorpublic: 1702ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 1703ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie static OffsetOfExpr *Create(ASTContext &C, QualType type, 1704ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie SourceLocation OperatorLoc, TypeSourceInfo *tsi, 1705ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie OffsetOfNode* compsPtr, unsigned numComps, 17068ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr** exprsPtr, unsigned numExprs, 17078ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc); 17088ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 1709ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie static OffsetOfExpr *CreateEmpty(ASTContext &C, 17108ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumComps, unsigned NumExprs); 17118ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 17128ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// getOperatorLoc - Return the location of the operator. 17138ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation getOperatorLoc() const { return OperatorLoc; } 17148ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setOperatorLoc(SourceLocation L) { OperatorLoc = L; } 17158ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 17168ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Return the location of the right parentheses. 17178ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 17188ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setRParenLoc(SourceLocation R) { RParenLoc = R; } 1719ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 17208ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TypeSourceInfo *getTypeSourceInfo() const { 17218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return TSInfo; 17228ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 17238ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setTypeSourceInfo(TypeSourceInfo *tsi) { 17248ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TSInfo = tsi; 17258ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1726ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 17278cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne const OffsetOfNode &getComponent(unsigned Idx) const { 17288ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumComps && "Subscript out of range"); 17298cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne return reinterpret_cast<const OffsetOfNode *> (this + 1)[Idx]; 17308ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 17318ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 17328ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setComponent(unsigned Idx, OffsetOfNode ON) { 17338ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumComps && "Subscript out of range"); 17348ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<OffsetOfNode *> (this + 1)[Idx] = ON; 17358ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1736ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 17378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned getNumComponents() const { 17388ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return NumComps; 17398ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 17408ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 17418ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr* getIndexExpr(unsigned Idx) { 17428ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumExprs && "Subscript out of range"); 17438ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return reinterpret_cast<Expr **>( 17448ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx]; 17458ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 17468cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne const Expr *getIndexExpr(unsigned Idx) const { 17478cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne return const_cast<OffsetOfExpr*>(this)->getIndexExpr(Idx); 17488cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne } 17498ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 17508ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setIndexExpr(unsigned Idx, Expr* E) { 17518ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumComps && "Subscript out of range"); 17528ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<Expr **>( 17538ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx] = E; 17548ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1755ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 17568ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned getNumExpressions() const { 17578ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return NumExprs; 17588ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 17598ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 176063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 17618ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return SourceRange(OperatorLoc, RParenLoc); 17628ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 17638ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 17648ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor static bool classof(const Stmt *T) { 17658ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return T->getStmtClass() == OffsetOfExprClass; 17668ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 17678ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 17688ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor static bool classof(const OffsetOfExpr *) { return true; } 17698ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 17708ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Iterators 177163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 177263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt **begin = 177363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall reinterpret_cast<Stmt**>(reinterpret_cast<OffsetOfNode*>(this + 1) 177463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall + NumComps); 177563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(begin, begin + NumExprs); 177663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 17778ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor}; 17788ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 1779f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne/// UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) 1780f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne/// expression operand. Used for sizeof/alignof (C99 6.5.3.4) and 1781f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne/// vec_step (OpenCL 1.1 6.11.12). 1782f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourneclass UnaryExprOrTypeTraitExpr : public Expr { 1783f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne unsigned Kind : 2; 17840518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl bool isType : 1; // true if operand is a type, false if an expression 1785d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl union { 1786a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *Ty; 1787d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl Stmt *Ex; 1788d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl } Argument; 17895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation OpLoc, RParenLoc; 179042602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor 17915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1792f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, TypeSourceInfo *TInfo, 1793f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne QualType resultType, SourceLocation op, 1794f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne SourceLocation rp) : 1795f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_RValue, OK_Ordinary, 1796ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor false, // Never type-dependent (C++ [temp.dep.expr]p3). 17972850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl // Value-dependent if the argument is type-dependent. 1798bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor TInfo->getType()->isDependentType(), 1799561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor TInfo->getType()->isInstantiationDependentType(), 1800bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor TInfo->getType()->containsUnexpandedParameterPack()), 1801f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne Kind(ExprKind), isType(true), OpLoc(op), RParenLoc(rp) { 1802a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall Argument.Ty = TInfo; 1803ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor } 1804ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor 1805f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, Expr *E, 1806f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne QualType resultType, SourceLocation op, 1807f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne SourceLocation rp) : 1808f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_RValue, OK_Ordinary, 1809ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor false, // Never type-dependent (C++ [temp.dep.expr]p3). 1810ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor // Value-dependent if the argument is type-dependent. 1811bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor E->isTypeDependent(), 1812561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor E->isInstantiationDependent(), 1813bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor E->containsUnexpandedParameterPack()), 1814f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne Kind(ExprKind), isType(false), OpLoc(op), RParenLoc(rp) { 1815ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor Argument.Ex = E; 1816d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl } 18170518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl 18180b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor /// \brief Construct an empty sizeof/alignof expression. 1819f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne explicit UnaryExprOrTypeTraitExpr(EmptyShell Empty) 1820f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne : Expr(UnaryExprOrTypeTraitExprClass, Empty) { } 18210b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 1822f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne UnaryExprOrTypeTrait getKind() const { 1823f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne return static_cast<UnaryExprOrTypeTrait>(Kind); 1824f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne } 1825f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne void setKind(UnaryExprOrTypeTrait K) { Kind = K; } 18260b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 18270518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl bool isArgumentType() const { return isType; } 18280518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType getArgumentType() const { 18295ab75172051a6d2ea71a80a79e81c65519fd3462John McCall return getArgumentTypeInfo()->getType(); 18305ab75172051a6d2ea71a80a79e81c65519fd3462John McCall } 1831a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *getArgumentTypeInfo() const { 18320518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl assert(isArgumentType() && "calling getArgumentType() when arg is expr"); 18335ab75172051a6d2ea71a80a79e81c65519fd3462John McCall return Argument.Ty; 18340518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 1835caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner Expr *getArgumentExpr() { 18360518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl assert(!isArgumentType() && "calling getArgumentExpr() when arg is type"); 1837d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl return static_cast<Expr*>(Argument.Ex); 18380518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 1839caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner const Expr *getArgumentExpr() const { 1840f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne return const_cast<UnaryExprOrTypeTraitExpr*>(this)->getArgumentExpr(); 1841caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner } 18420b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 18430b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setArgument(Expr *E) { Argument.Ex = E; isType = false; } 1844a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall void setArgument(TypeSourceInfo *TInfo) { 1845a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall Argument.Ty = TInfo; 18461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump isType = true; 18470b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor } 18480b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 18490518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl /// Gets the argument type, or the type of the argument expression, whichever 18500518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl /// is appropriate. 18510518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType getTypeOfArgument() const { 18520518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl return isArgumentType() ? getArgumentType() : getArgumentExpr()->getType(); 18530518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 18540518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl 185576e773a443be9f006610f46529e07d4c8d857680Chris Lattner SourceLocation getOperatorLoc() const { return OpLoc; } 18560b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOperatorLoc(SourceLocation L) { OpLoc = L; } 18570b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 18580b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 18590b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1860866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek 186163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 1862866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek return SourceRange(OpLoc, RParenLoc); 1863866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek } 18645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 18651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 1866f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne return T->getStmtClass() == UnaryExprOrTypeTraitExprClass; 18675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1868f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne static bool classof(const UnaryExprOrTypeTraitExpr *) { return true; } 18691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 187077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 187163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children(); 18725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 18735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 18745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 18755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Postfix Operators. 18765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 18775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 18785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting. 18795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ArraySubscriptExpr : public Expr { 188077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek enum { LHS, RHS, END_EXPR=2 }; 18811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Stmt* SubExprs[END_EXPR]; 18825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation RBracketLoc; 18835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 18842324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t, 1885f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 188673d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SourceLocation rbracketloc) 1887f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ArraySubscriptExprClass, t, VK, OK, 18882850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl lhs->isTypeDependent() || rhs->isTypeDependent(), 1889bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor lhs->isValueDependent() || rhs->isValueDependent(), 1890561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (lhs->isInstantiationDependent() || 1891561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhs->isInstantiationDependent()), 1892bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (lhs->containsUnexpandedParameterPack() || 1893bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhs->containsUnexpandedParameterPack())), 18942850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl RBracketLoc(rbracketloc) { 189573d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SubExprs[LHS] = lhs; 189673d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SubExprs[RHS] = rhs; 189773d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner } 18981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1899cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor /// \brief Create an empty array subscript expression. 1900cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor explicit ArraySubscriptExpr(EmptyShell Shell) 1901cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor : Expr(ArraySubscriptExprClass, Shell) { } 1902cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 19032324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// An array access can be written A[4] or 4[A] (both are equivalent). 19042324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// - getBase() and getIdx() always present the normalized view: A[4]. 19052324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// In this case getBase() returns "A" and getIdx() returns "4". 19062324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// - getLHS() and getRHS() present the syntactic view. e.g. for 19072324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// 4[A] getLHS() returns "4". 190833fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// Note: Because vector element access is also written A[4] we must 190933fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// predicate the format conversion in getBase and getIdx only on the 191033fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// the type of the RHS, as it is possible for the LHS to be a vector of 191133fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// integer type 19125549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); } 19135549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 1914cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 1915cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 19165549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); } 19175549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 1918cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 19191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getBase() { 19215549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS()); 192277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek } 19231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr *getBase() const { 19255549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS()); 19262324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek } 19271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getIdx() { 19295549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS()); 19302324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek } 19311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 193277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek const Expr *getIdx() const { 19335549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS()); 19341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 19351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 193663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 193777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek return SourceRange(getLHS()->getLocStart(), RBracketLoc); 19385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 19391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1940026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getRBracketLoc() const { return RBracketLoc; } 1941cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setRBracketLoc(SourceLocation L) { RBracketLoc = L; } 1942cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 194363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation getExprLoc() const { return getBase()->getExprLoc(); } 19445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 19451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 19461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ArraySubscriptExprClass; 19475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 19485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ArraySubscriptExpr *) { return true; } 19491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 195077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 195163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 195263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 195363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 19545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 19555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 19565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1957b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]). 19581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CallExpr itself represents a normal function call, e.g., "f(x, 2)", 1959b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// while its subclasses may represent alternative syntax that (semantically) 19601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// results in a function call. For example, CXXOperatorCallExpr is 1961b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// a subclass for overloaded operator calls that use operator syntax, e.g., 1962b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// "str1 + str2" to resolve to a function call. 19635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CallExpr : public Expr { 1964cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne enum { FN=0, PREARGS_START=1 }; 19655549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt **SubExprs; 19665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned NumArgs; 19675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation RParenLoc; 19681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1969b4609806e9232593ece09ce08b630836e825865cDouglas Gregorprotected: 1970cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne // These versions of the constructor are for derived classes. 1971cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExpr(ASTContext& C, StmtClass SC, Expr *fn, unsigned NumPreArgs, 1972cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne Expr **args, unsigned numargs, QualType t, ExprValueKind VK, 1973cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SourceLocation rparenloc); 1974cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExpr(ASTContext &C, StmtClass SC, unsigned NumPreArgs, EmptyShell Empty); 1975cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne 1976cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne Stmt *getPreArg(unsigned i) { 1977cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne assert(i < getNumPreArgs() && "Prearg access out of range!"); 1978cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs[PREARGS_START+i]; 1979cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 1980cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne const Stmt *getPreArg(unsigned i) const { 1981cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne assert(i < getNumPreArgs() && "Prearg access out of range!"); 1982cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs[PREARGS_START+i]; 1983cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 1984cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne void setPreArg(unsigned i, Stmt *PreArg) { 1985cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne assert(i < getNumPreArgs() && "Prearg access out of range!"); 1986cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs[PREARGS_START+i] = PreArg; 1987cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 1988cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne 1989cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne unsigned getNumPreArgs() const { return CallExprBits.NumPreArgs; } 199042602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor 19915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 19921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, QualType t, 1993f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, SourceLocation rparenloc); 19941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19951f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor /// \brief Build an empty call expression. 1996ba0a9006dbc4814e1e35f82812cb5a1dad65e8b8Argyrios Kyrtzidis CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty); 19971f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 19985549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); } 19995549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCallee() { return cast<Expr>(SubExprs[FN]); } 200018b2515e1bf8c86a4900792692e42fe1296be28dChris Lattner void setCallee(Expr *F) { SubExprs[FN] = F; } 2001a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 2002d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes Decl *getCalleeDecl(); 2003d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes const Decl *getCalleeDecl() const { 2004d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes return const_cast<CallExpr*>(this)->getCalleeDecl(); 2005d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes } 2006d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes 2007a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu /// \brief If the callee is a FunctionDecl, return it. Otherwise return 0. 2008a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu FunctionDecl *getDirectCallee(); 2009bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner const FunctionDecl *getDirectCallee() const { 2010bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner return const_cast<CallExpr*>(this)->getDirectCallee(); 2011bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner } 2012a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 20135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getNumArgs - Return the number of actual arguments to this call. 20145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 20155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumArgs() const { return NumArgs; } 20161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2017aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \brief Retrieve the call arguments. 2018cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne Expr **getArgs() { 2019cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return reinterpret_cast<Expr **>(SubExprs+getNumPreArgs()+PREARGS_START); 2020cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 2021d0dcceae2a8ca0e37b5dd471a704de8583d49c95Richard Smith const Expr *const *getArgs() const { 2022d0dcceae2a8ca0e37b5dd471a704de8583d49c95Richard Smith return const_cast<CallExpr*>(this)->getArgs(); 2023d0dcceae2a8ca0e37b5dd471a704de8583d49c95Richard Smith } 2024ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 20255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getArg - Return the specified argument. 20265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Expr *getArg(unsigned Arg) { 20275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(Arg < NumArgs && "Arg access out of range!"); 2028cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return cast<Expr>(SubExprs[Arg+getNumPreArgs()+PREARGS_START]); 20295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 20305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const Expr *getArg(unsigned Arg) const { 20315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(Arg < NumArgs && "Arg access out of range!"); 2032cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return cast<Expr>(SubExprs[Arg+getNumPreArgs()+PREARGS_START]); 20335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 20341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2035934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff /// setArg - Set the specified argument. 2036934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff void setArg(unsigned Arg, Expr *ArgExpr) { 2037934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff assert(Arg < NumArgs && "Arg access out of range!"); 2038cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs[Arg+getNumPreArgs()+PREARGS_START] = ArgExpr; 2039934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff } 20401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2041d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// setNumArgs - This changes the number of arguments present in this call. 2042d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// Any orphaned expressions are deleted by this, and any new operands are set 2043d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// to null. 20448189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek void setNumArgs(ASTContext& C, unsigned NumArgs); 20451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20465549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek typedef ExprIterator arg_iterator; 20475549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek typedef ConstExprIterator const_arg_iterator; 20481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2049cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne arg_iterator arg_begin() { return SubExprs+PREARGS_START+getNumPreArgs(); } 2050cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne arg_iterator arg_end() { 2051cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs+PREARGS_START+getNumPreArgs()+getNumArgs(); 2052cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 2053cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne const_arg_iterator arg_begin() const { 2054cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs+PREARGS_START+getNumPreArgs(); 2055cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 2056cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne const_arg_iterator arg_end() const { 2057cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs+PREARGS_START+getNumPreArgs()+getNumArgs(); 2058cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 20591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getNumCommas - Return the number of commas that must have been present in 20615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// this function call. 20625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; } 20635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2064cb888967400a03504c88acedd5248d6778a82f46Chris Lattner /// isBuiltinCall - If this is a call to a builtin, return the builtin ID. If 2065cb888967400a03504c88acedd5248d6778a82f46Chris Lattner /// not, return 0. 2066180f47959a066795cc0f409433023af448bb0328Richard Smith unsigned isBuiltinCall() const; 20671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// getCallReturnType - Get the return type of the call expr. This is not 20691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// always the type of the expr itself, if the return type is a reference 20706dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson /// type. 20716dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson QualType getCallReturnType() const; 20721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2073d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner SourceLocation getRParenLoc() const { return RParenLoc; } 20741f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 2075866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek 20762882eca5a184c78f793188083f6ce539740a5cf2John McCall SourceRange getSourceRange() const; 20771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 20794bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return T->getStmtClass() >= firstCallExprConstant && 20804bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt T->getStmtClass() <= lastCallExprConstant; 20815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 20825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CallExpr *) { return true; } 208388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 208477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 208563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 208663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], 208763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall &SubExprs[0]+NumArgs+getNumPreArgs()+PREARGS_START); 208863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 20895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 20905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2091ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner/// MemberExpr - [C99 6.5.2.3] Structure and Union Members. X->F and X.F. 20925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 20935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass MemberExpr : public Expr { 20946bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// Extra data stored in some member expressions. 20956857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth struct MemberNameQualifier { 20966857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// \brief The nested-name-specifier that qualifies the name, including 20976857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// source-location information. 20986857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth NestedNameSpecifierLoc QualifierLoc; 20996857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth 21006857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// \brief The DeclAccessPair through which the MemberDecl was found due to 21016857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// name qualifiers. 2102161755a09898c95d21bfff33707da9ca41cd53c5John McCall DeclAccessPair FoundDecl; 21036bb8017bb9e828d118e15e59d71c66bba323c364John McCall }; 21046bb8017bb9e828d118e15e59d71c66bba323c364John McCall 2105ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// Base - the expression for the base pointer or structure references. In 2106ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// X.F, this is "X". 21075549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Base; 21081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2109ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// MemberDecl - This is the decl being referenced by the field/member name. 2110ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// In X.F, this is the decl referenced by F. 2111f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *MemberDecl; 21121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2113ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// MemberLoc - This is the location of the member name. 21145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation MemberLoc; 21151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21162577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// MemberDNLoc - Provides source/type location info for the 21172577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// declaration name embedded in MemberDecl. 21182577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameLoc MemberDNLoc; 21192577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 2120ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// IsArrow - True if this is "X->F", false if this is "X.F". 212183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor bool IsArrow : 1; 21221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 212383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief True if this member expression used a nested-name-specifier to 21246bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// refer to the member, e.g., "x->Base::f", or found its member via a using 21256bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// declaration. When true, a MemberNameQualifier 2126c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// structure is allocated immediately after the MemberExpr. 21276bb8017bb9e828d118e15e59d71c66bba323c364John McCall bool HasQualifierOrFoundDecl : 1; 21281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2129c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief True if this member expression specified a template argument list 2130c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// explicitly, e.g., x->f<int>. When true, an ExplicitTemplateArgumentList 2131c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// structure (and its TemplateArguments) are allocated immediately after 2132c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// the MemberExpr or, if the member expression also has a qualifier, after 21336bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// the MemberNameQualifier structure. 2134c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor bool HasExplicitTemplateArgumentList : 1; 21351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21367cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// \brief True if this member expression refers to a method that 21377cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// was resolved from an overloaded set having size greater than 1. 21387cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool HadMultipleCandidates : 1; 21397cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara 214083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief Retrieve the qualifier that preceded the member name, if any. 21416bb8017bb9e828d118e15e59d71c66bba323c364John McCall MemberNameQualifier *getMemberQualifier() { 21426bb8017bb9e828d118e15e59d71c66bba323c364John McCall assert(HasQualifierOrFoundDecl); 21436bb8017bb9e828d118e15e59d71c66bba323c364John McCall return reinterpret_cast<MemberNameQualifier *> (this + 1); 214483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 214583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor 214683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief Retrieve the qualifier that preceded the member name, if any. 21476bb8017bb9e828d118e15e59d71c66bba323c364John McCall const MemberNameQualifier *getMemberQualifier() const { 2148c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return const_cast<MemberExpr *>(this)->getMemberQualifier(); 2149c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 21501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 2152f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl, 2153f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall const DeclarationNameInfo &NameInfo, QualType ty, 2154f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK) 2155f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(MemberExprClass, ty, VK, OK, 2156ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie base->isTypeDependent(), 2157561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor base->isValueDependent(), 2158561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor base->isInstantiationDependent(), 2159bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->containsUnexpandedParameterPack()), 21602577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Base(base), MemberDecl(memberdecl), MemberLoc(NameInfo.getLoc()), 21612577743c5650c646fb705df01403707e94f2df04Abramo Bagnara MemberDNLoc(NameInfo.getInfo()), IsArrow(isarrow), 21627cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara HasQualifierOrFoundDecl(false), HasExplicitTemplateArgumentList(false), 21637cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara HadMultipleCandidates(false) { 21642577743c5650c646fb705df01403707e94f2df04Abramo Bagnara assert(memberdecl->getDeclName() == NameInfo.getName()); 21652577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 21662577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 21672577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // NOTE: this constructor should be used only when it is known that 21682577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // the member name can not provide additional syntactic info 21692577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // (i.e., source locations for C++ operator names or type source info 21702577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // for constructors, destructors and conversion oeprators). 21712577743c5650c646fb705df01403707e94f2df04Abramo Bagnara MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl, 2172f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall SourceLocation l, QualType ty, 2173f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK) 2174f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(MemberExprClass, ty, VK, OK, 2175bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->isTypeDependent(), base->isValueDependent(), 2176561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor base->isInstantiationDependent(), 2177bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->containsUnexpandedParameterPack()), 21782577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Base(base), MemberDecl(memberdecl), MemberLoc(l), MemberDNLoc(), 21792577743c5650c646fb705df01403707e94f2df04Abramo Bagnara IsArrow(isarrow), 21807cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara HasQualifierOrFoundDecl(false), HasExplicitTemplateArgumentList(false), 21817cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara HadMultipleCandidates(false) {} 2182510190777c4bd53e960eea4665b204778fec1b64Eli Friedman 21831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static MemberExpr *Create(ASTContext &C, Expr *base, bool isarrow, 218440d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 2185161755a09898c95d21bfff33707da9ca41cd53c5John McCall ValueDecl *memberdecl, DeclAccessPair founddecl, 21862577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo MemberNameInfo, 2187d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *targs, 2188f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType ty, ExprValueKind VK, ExprObjectKind OK); 21891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 219088a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor void setBase(Expr *E) { Base = E; } 21915549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getBase() const { return cast<Expr>(Base); } 219257e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor 219357e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// \brief Retrieve the member declaration to which this expression refers. 219457e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// 219557e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// The returned declaration will either be a FieldDecl or (in C++) 219657e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// a CXXMethodDecl. 2197f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *getMemberDecl() const { return MemberDecl; } 2198f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman void setMemberDecl(ValueDecl *D) { MemberDecl = D; } 21991f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 22006bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// \brief Retrieves the declaration found by lookup. 2201161755a09898c95d21bfff33707da9ca41cd53c5John McCall DeclAccessPair getFoundDecl() const { 22026bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (!HasQualifierOrFoundDecl) 2203161755a09898c95d21bfff33707da9ca41cd53c5John McCall return DeclAccessPair::make(getMemberDecl(), 2204161755a09898c95d21bfff33707da9ca41cd53c5John McCall getMemberDecl()->getAccess()); 22056bb8017bb9e828d118e15e59d71c66bba323c364John McCall return getMemberQualifier()->FoundDecl; 22066bb8017bb9e828d118e15e59d71c66bba323c364John McCall } 22076bb8017bb9e828d118e15e59d71c66bba323c364John McCall 22081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Determines whether this member expression actually had 22090979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor /// a C++ nested-name-specifier prior to the name of the member, e.g., 22100979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor /// x->Base::foo. 22116bb8017bb9e828d118e15e59d71c66bba323c364John McCall bool hasQualifier() const { return getQualifier() != 0; } 22121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief If the member name was qualified, retrieves the 221483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// nested-name-specifier that precedes the member name. Otherwise, returns 221583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// NULL. 22161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump NestedNameSpecifier *getQualifier() const { 22176bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (!HasQualifierOrFoundDecl) 221883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return 0; 22191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 222040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return getMemberQualifier()->QualifierLoc.getNestedNameSpecifier(); 222140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor } 222240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor 2223ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie /// \brief If the member name was qualified, retrieves the 222440d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor /// nested-name-specifier that precedes the member name, with source-location 222540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor /// information. 222640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc getQualifierLoc() const { 222740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (!hasQualifier()) 222840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return NestedNameSpecifierLoc(); 2229ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 223040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return getMemberQualifier()->QualifierLoc; 223183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 2232c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor 2233c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Determines whether this member expression actually had a C++ 2234c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template argument list explicitly specified, e.g., x.f<int>. 2235096832c5ed5b9106fa177ebc148489760c3bc496John McCall bool hasExplicitTemplateArgs() const { 22361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return HasExplicitTemplateArgumentList; 2237c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 22381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2239d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// \brief Copies the template arguments (if present) into the given 2240d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// structure. 2241d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 2242096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (hasExplicitTemplateArgs()) 2243096832c5ed5b9106fa177ebc148489760c3bc496John McCall getExplicitTemplateArgs().copyInto(List); 2244096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 2245096832c5ed5b9106fa177ebc148489760c3bc496John McCall 2246096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that 2247096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// follow the member template name. This must only be called on an 2248096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// expression with explicit template arguments. 2249b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 2250096832c5ed5b9106fa177ebc148489760c3bc496John McCall assert(HasExplicitTemplateArgumentList); 2251096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!HasQualifierOrFoundDecl) 2252b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis return *reinterpret_cast<ASTTemplateArgumentListInfo *>(this + 1); 2253096832c5ed5b9106fa177ebc148489760c3bc496John McCall 2254b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis return *reinterpret_cast<ASTTemplateArgumentListInfo *>( 2255096832c5ed5b9106fa177ebc148489760c3bc496John McCall getMemberQualifier() + 1); 2256096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 2257096832c5ed5b9106fa177ebc148489760c3bc496John McCall 2258096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that 2259096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// followed the member template name. This must only be called on 2260096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// an expression with explicit template arguments. 2261b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 2262096832c5ed5b9106fa177ebc148489760c3bc496John McCall return const_cast<MemberExpr *>(this)->getExplicitTemplateArgs(); 2263096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 2264096832c5ed5b9106fa177ebc148489760c3bc496John McCall 2265096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieves the optional explicit template arguments. 2266096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// This points to the same data as getExplicitTemplateArgs(), but 2267096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// returns null if there are no explicit template arguments. 2268b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const { 2269096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) return 0; 2270096832c5ed5b9106fa177ebc148489760c3bc496John McCall return &getExplicitTemplateArgs(); 2271d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall } 2272ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 22731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Retrieve the location of the left angle bracket following the 2274c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// member name ('<'), if any. 22751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation getLAngleLoc() const { 2276c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 2277c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return SourceLocation(); 22781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2279096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().LAngleLoc; 2280c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 22811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2282c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Retrieve the template arguments provided as part of this 2283c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template-id. 2284833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc *getTemplateArgs() const { 2285c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 22861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return 0; 22871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2288096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().getTemplateArgs(); 2289c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 22901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2291c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Retrieve the number of template arguments provided as part of this 2292c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template-id. 22931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned getNumTemplateArgs() const { 2294c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 22951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return 0; 22961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2297096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().NumTemplateArgs; 2298c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 22991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Retrieve the location of the right angle bracket following the 2301c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template arguments ('>'). 23021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation getRAngleLoc() const { 2303c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 2304c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return SourceLocation(); 23051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2306096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().RAngleLoc; 2307c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 23081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23092577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// \brief Retrieve the member declaration name info. 23102577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo getMemberNameInfo() const { 23112577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(MemberDecl->getDeclName(), 23122577743c5650c646fb705df01403707e94f2df04Abramo Bagnara MemberLoc, MemberDNLoc); 23132577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 23142577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 23155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isArrow() const { return IsArrow; } 23161f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setArrow(bool A) { IsArrow = A; } 23171f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 2318ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// getMemberLoc - Return the location of the "member", in X->F, it is the 2319ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// location of 'F'. 2320026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getMemberLoc() const { return MemberLoc; } 23211f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setMemberLoc(SourceLocation L) { MemberLoc = L; } 23225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 232375e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor SourceRange getSourceRange() const; 2324ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 232563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation getExprLoc() const { return MemberLoc; } 23265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 232775e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor /// \brief Determine whether the base of this explicit is implicit. 232875e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor bool isImplicitAccess() const { 232975e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor return getBase() && getBase()->isImplicitCXXThis(); 233075e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } 23317cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara 23327cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// \brief Returns true if this member expression refers to a method that 23337cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// was resolved from an overloaded set having size greater than 1. 23347cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool hadMultipleCandidates() const { 23357cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara return HadMultipleCandidates; 23367cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara } 23377cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// \brief Sets the flag telling whether this expression refers to 23387cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// a method that was resolved from an overloaded set having size 23397cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara /// greater than 1. 23407cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara void setHadMultipleCandidates(bool V = true) { 23417cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara HadMultipleCandidates = V; 23427cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara } 23437cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara 23441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 234583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return T->getStmtClass() == MemberExprClass; 23465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 23475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const MemberExpr *) { return true; } 23481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23491237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 235063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Base, &Base+1); } 23514045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis 23524045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTReader; 23534045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTStmtWriter; 23545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 23555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 23561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CompoundLiteralExpr - [C99 6.5.2.5] 2357aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff/// 2358aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffclass CompoundLiteralExpr : public Expr { 23590fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// LParenLoc - If non-null, this is the location of the left paren in a 23600fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// compound literal like "(int){4}". This can be null if this is a 23610fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// synthesized compound expression. 23620fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner SourceLocation LParenLoc; 23631d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall 23641d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall /// The type as written. This can be an incomplete array type, in 23651d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall /// which case the actual expression type will be different. 236642f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *TInfo; 23675549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Init; 2368e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff bool FileScope; 2369aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffpublic: 237042f56b50062cd3b3c6b23fdb9053578ae9145664John McCall CompoundLiteralExpr(SourceLocation lparenloc, TypeSourceInfo *tinfo, 2371f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK, Expr *init, bool fileScope) 2372f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CompoundLiteralExprClass, T, VK, OK_Ordinary, 2373ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie tinfo->getType()->isDependentType(), 2374bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor init->isValueDependent(), 2375561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (init->isInstantiationDependent() || 2376561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor tinfo->getType()->isInstantiationDependentType()), 2377bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor init->containsUnexpandedParameterPack()), 237842f56b50062cd3b3c6b23fdb9053578ae9145664John McCall LParenLoc(lparenloc), TInfo(tinfo), Init(init), FileScope(fileScope) {} 23791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2380ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor /// \brief Construct an empty compound literal. 2381ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor explicit CompoundLiteralExpr(EmptyShell Empty) 2382ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor : Expr(CompoundLiteralExprClass, Empty) { } 2383ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 23845549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getInitializer() const { return cast<Expr>(Init); } 23855549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getInitializer() { return cast<Expr>(Init); } 2386ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setInitializer(Expr *E) { Init = E; } 2387e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff 2388e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff bool isFileScope() const { return FileScope; } 2389ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setFileScope(bool FS) { FileScope = FS; } 2390ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 23910fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner SourceLocation getLParenLoc() const { return LParenLoc; } 2392ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setLParenLoc(SourceLocation L) { LParenLoc = L; } 2393ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 239442f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *getTypeSourceInfo() const { return TInfo; } 239542f56b50062cd3b3c6b23fdb9053578ae9145664John McCall void setTypeSourceInfo(TypeSourceInfo* tinfo) { TInfo = tinfo; } 239642f56b50062cd3b3c6b23fdb9053578ae9145664John McCall 239763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 23980fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner // FIXME: Init should never be null. 23990fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner if (!Init) 24000fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner return SourceRange(); 24010fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner if (LParenLoc.isInvalid()) 240273d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner return Init->getSourceRange(); 24030fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner return SourceRange(LParenLoc, Init->getLocEnd()); 240473d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner } 2405aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff 24061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 24071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CompoundLiteralExprClass; 2408aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff } 2409aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff static bool classof(const CompoundLiteralExpr *) { return true; } 24101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24111237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 241263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Init, &Init+1); } 2413aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff}; 2414aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff 241549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CastExpr - Base class for type casts, including both implicit 241649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// casts (ImplicitCastExpr) and explicit casts that have some 241749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// representation in the source code (ExplicitCastExpr's derived 241849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// classes). 24190835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass CastExpr : public Expr { 2420cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlssonpublic: 24215baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall typedef clang::CastKind CastKind; 24221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2423cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlssonprivate: 24240835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis Stmt *Op; 2425409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson 24261d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall void CheckCastConsistency() const; 2427409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson 2428f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXBaseSpecifier * const *path_buffer() const { 2429f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return const_cast<CastExpr*>(this)->path_buffer(); 2430f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall } 2431f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CXXBaseSpecifier **path_buffer(); 2432f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2433654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis void setBasePathSize(unsigned basePathSize) { 2434654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis CastExprBits.BasePathSize = basePathSize; 2435654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis assert(CastExprBits.BasePathSize == basePathSize && 2436654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis "basePathSize doesn't fit in bits of CastExprBits.BasePathSize!"); 2437654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis } 2438654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis 24390835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisprotected: 2440f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CastExpr(StmtClass SC, QualType ty, ExprValueKind VK, 2441f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall const CastKind kind, Expr *op, unsigned BasePathSize) : 2442f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(SC, ty, VK, OK_Ordinary, 2443898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Cast expressions are type-dependent if the type is 2444898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // dependent (C++ [temp.dep.expr]p3). 2445898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ty->isDependentType(), 2446898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Cast expressions are value-dependent if the type is 2447898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // dependent or if the subexpression is value-dependent. 2448bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ty->isDependentType() || (op && op->isValueDependent()), 2449ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie (ty->isInstantiationDependentType() || 2450561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (op && op->isInstantiationDependent())), 2451bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (ty->containsUnexpandedParameterPack() || 2452bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor op->containsUnexpandedParameterPack())), 24538e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall Op(op) { 2454daa8e4e888758d55a7a759dd4a91b83921cef222John McCall assert(kind != CK_Invalid && "creating cast with invalid cast kind"); 24558e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CastExprBits.Kind = kind; 2456654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis setBasePathSize(BasePathSize); 24571d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall#ifndef NDEBUG 2458daa8e4e888758d55a7a759dd4a91b83921cef222John McCall CheckCastConsistency(); 24591d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall#endif 2460f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall } 24611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2462087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor /// \brief Construct an empty cast. 2463f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastExpr(StmtClass SC, EmptyShell Empty, unsigned BasePathSize) 24648e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall : Expr(SC, Empty) { 2465654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis setBasePathSize(BasePathSize); 24668e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall } 24671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24680835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidispublic: 24698e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CastKind getCastKind() const { return (CastKind) CastExprBits.Kind; } 24708e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall void setCastKind(CastKind K) { CastExprBits.Kind = K; } 2471f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson const char *getCastKindName() const; 2472f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson 24730835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis Expr *getSubExpr() { return cast<Expr>(Op); } 24740835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis const Expr *getSubExpr() const { return cast<Expr>(Op); } 2475087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor void setSubExpr(Expr *E) { Op = E; } 2476087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor 24776eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// \brief Retrieve the cast subexpression as it was written in the source 24786eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// code, looking through any implicit casts or other intermediate nodes 24796eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// introduced by semantic analysis. 24806eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor Expr *getSubExprAsWritten(); 24816eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor const Expr *getSubExprAsWritten() const { 24826eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return const_cast<CastExpr *>(this)->getSubExprAsWritten(); 24836eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor } 248441b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson 2485f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall typedef CXXBaseSpecifier **path_iterator; 2486f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall typedef const CXXBaseSpecifier * const *path_const_iterator; 24878e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall bool path_empty() const { return CastExprBits.BasePathSize == 0; } 24888e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned path_size() const { return CastExprBits.BasePathSize; } 2489f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_iterator path_begin() { return path_buffer(); } 2490f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_iterator path_end() { return path_buffer() + path_size(); } 2491f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_const_iterator path_begin() const { return path_buffer(); } 2492f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_const_iterator path_end() const { return path_buffer() + path_size(); } 2493f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2494f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall void setCastPath(const CXXCastPath &Path); 249541b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson 24961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 24974bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return T->getStmtClass() >= firstCastExprConstant && 24984bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt T->getStmtClass() <= lastCastExprConstant; 24990835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis } 25000835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis static bool classof(const CastExpr *) { return true; } 25011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25020835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis // Iterators 250363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Op, &Op+1); } 25040835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis}; 25050835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis 250649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ImplicitCastExpr - Allows us to explicitly represent implicit type 250749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// conversions, which have no direct representation in the original 250849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// source code. For example: converting T[]->T*, void f()->void 250949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (*f)(), float->double, short->int, etc. 251049b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff/// 2511bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// In C, implicit casts always produce rvalues. However, in C++, an 2512bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// implicit cast whose result is being bound to a reference will be 2513906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// an lvalue or xvalue. For example: 2514bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// 2515bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @code 2516bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Base { }; 2517bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Derived : public Base { }; 2518906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// Derived &&ref(); 25191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// void f(Derived d) { 2520906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// Base& b = d; // initializer is an ImplicitCastExpr 2521906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// // to an lvalue of type Base 2522906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// Base&& r = ref(); // initializer is an ImplicitCastExpr 2523906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// // to an xvalue of type Base 2524bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// } 2525bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @endcode 25260835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ImplicitCastExpr : public CastExpr { 2527906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redlprivate: 2528f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ImplicitCastExpr(QualType ty, CastKind kind, Expr *op, 25295baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall unsigned BasePathLength, ExprValueKind VK) 2530f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, BasePathLength) { 25315baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall } 253290045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff 2533087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor /// \brief Construct an empty implicit cast. 2534f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall explicit ImplicitCastExpr(EmptyShell Shell, unsigned PathSize) 2535f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : CastExpr(ImplicitCastExprClass, Shell, PathSize) { } 2536f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2537f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 2538f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall enum OnStack_t { OnStack }; 2539f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ImplicitCastExpr(OnStack_t _, QualType ty, CastKind kind, Expr *op, 25405baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall ExprValueKind VK) 2541f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, 0) { 25425baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall } 2543f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2544f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static ImplicitCastExpr *Create(ASTContext &Context, QualType T, 2545f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastKind Kind, Expr *Operand, 2546f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXCastPath *BasePath, 25475baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall ExprValueKind Cat); 2548f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2549f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static ImplicitCastExpr *CreateEmpty(ASTContext &Context, unsigned PathSize); 2550087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor 255163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 25520835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis return getSubExpr()->getSourceRange(); 25530835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis } 255490045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff 25551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 25561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ImplicitCastExprClass; 255749b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff } 255849b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff static bool classof(const ImplicitCastExpr *) { return true; } 255949b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff}; 256049b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff 256191a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCallinline Expr *Expr::IgnoreImpCasts() { 256291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall Expr *e = this; 256391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall while (ImplicitCastExpr *ice = dyn_cast<ImplicitCastExpr>(e)) 256491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall e = ice->getSubExpr(); 256591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall return e; 256691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall} 256791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 256849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ExplicitCastExpr - An explicit cast written in the source 25691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// code. 257049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// 257149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This class is effectively an abstract class, because it provides 257249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// the basic representation of an explicitly-written cast without 257349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// specifying which kind of cast (C cast, functional cast, static 257449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast, etc.) was written; specific derived classes represent the 257549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// particular style of cast and its location information. 25765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 257749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// Unlike implicit casts, explicit cast nodes have two different 257849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// types: the type that was written into the source code, and the 257949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// actual type of the expression as determined by semantic 258049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// analysis. These types may differ slightly. For example, in C++ one 258149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// can cast to a reference type, which indicates that the resulting 2582906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// expression will be an lvalue or xvalue. The reference type, however, 2583906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// will not be used as the type of the expression. 25840835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ExplicitCastExpr : public CastExpr { 25859d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// TInfo - Source type info for the (written) type 25869d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// this expression is casting to. 25879d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo; 258849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 258949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorprotected: 2590f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExplicitCastExpr(StmtClass SC, QualType exprTy, ExprValueKind VK, 2591f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CastKind kind, Expr *op, unsigned PathSize, 2592f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall TypeSourceInfo *writtenTy) 2593f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : CastExpr(SC, exprTy, VK, kind, op, PathSize), TInfo(writtenTy) {} 259449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 2595db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty explicit cast. 2596f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ExplicitCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize) 2597f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : CastExpr(SC, Shell, PathSize) { } 2598db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 259949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorpublic: 26009d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// getTypeInfoAsWritten - Returns the type source info for the type 26019d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// that this expression is casting to. 26029d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *getTypeInfoAsWritten() const { return TInfo; } 26039d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall void setTypeInfoAsWritten(TypeSourceInfo *writtenTy) { TInfo = writtenTy; } 26049d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall 260549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// getTypeAsWritten - Returns the type that this expression is 260649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// casting to, as written in the source code. 26079d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall QualType getTypeAsWritten() const { return TInfo->getType(); } 260849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 26091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 26104bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return T->getStmtClass() >= firstExplicitCastExprConstant && 26114bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt T->getStmtClass() <= lastExplicitCastExprConstant; 261249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor } 261349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor static bool classof(const ExplicitCastExpr *) { return true; } 261449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor}; 261549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 26166eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor/// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style 261749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast in C++ (C++ [expr.cast]), which uses the syntax 261849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (Type)expr. For example: @c (int)f. 26196eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregorclass CStyleCastExpr : public ExplicitCastExpr { 2620b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation LPLoc; // the location of the left paren 2621b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation RPLoc; // the location of the right paren 2622f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2623f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CStyleCastExpr(QualType exprTy, ExprValueKind vk, CastKind kind, Expr *op, 2624f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned PathSize, TypeSourceInfo *writtenTy, 262541b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson SourceLocation l, SourceLocation r) 2626f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : ExplicitCastExpr(CStyleCastExprClass, exprTy, vk, kind, op, PathSize, 262741b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson writtenTy), LPLoc(l), RPLoc(r) {} 262849b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff 2629db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty C-style explicit cast. 2630f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall explicit CStyleCastExpr(EmptyShell Shell, unsigned PathSize) 2631f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : ExplicitCastExpr(CStyleCastExprClass, Shell, PathSize) { } 2632f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2633f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 2634f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall static CStyleCastExpr *Create(ASTContext &Context, QualType T, 2635f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, CastKind K, 2636f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall Expr *Op, const CXXCastPath *BasePath, 2637f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall TypeSourceInfo *WrittenTy, SourceLocation L, 2638f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall SourceLocation R); 2639f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2640f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CStyleCastExpr *CreateEmpty(ASTContext &Context, unsigned PathSize); 2641db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 2642b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation getLParenLoc() const { return LPLoc; } 2643db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setLParenLoc(SourceLocation L) { LPLoc = L; } 2644db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 2645b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation getRParenLoc() const { return RPLoc; } 2646db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setRParenLoc(SourceLocation L) { RPLoc = L; } 2647db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 264863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 2649b2f9e516327310d95840d442416084508f80c183Steve Naroff return SourceRange(LPLoc, getSubExpr()->getSourceRange().getEnd()); 26505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 26511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 26521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CStyleCastExprClass; 26535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 26546eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor static bool classof(const CStyleCastExpr *) { return true; } 26555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 26565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 26573fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// \brief A builtin binary operation expression such as "x + y" or "x <= y". 26583fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 26593fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// This expression node kind describes a builtin binary operation, 26603fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// such as "x + y" for integer values "x" and "y". The operands will 26613fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// already have been converted to appropriate types (e.g., by 26623fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// performing promotions or conversions). 26633fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 26643fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// In C++, where operators may be overloaded, a different kind of 26653fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// expression node (CXXOperatorCallExpr) is used to express the 26663fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// invocation of an overloaded operator with operator syntax. Within 26673fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is 26683fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to store an expression "x + y" depends on the subexpressions 26693fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// for x and y. If neither x or y is type-dependent, and the "+" 26703fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// operator resolves to a built-in operation, BinaryOperator will be 26713fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to express the computation (x and y may still be 26723fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// value-dependent). If either x or y is type-dependent, or if the 26733fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// "+" resolves to an overloaded operator, CXXOperatorCallExpr will 26743fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// be used to express the computation. 26755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BinaryOperator : public Expr { 26765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 26775baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall typedef BinaryOperatorKind Opcode; 26785baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 267917d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattnerprivate: 26800799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall unsigned Opc : 6; 26810799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall SourceLocation OpLoc; 26820799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall 268317d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner enum { LHS, RHS, END_EXPR }; 26845549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; 26851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 26861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 268717d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 2688f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 268917d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation opLoc) 2690f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(BinaryOperatorClass, ResTy, VK, OK, 2691898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor lhs->isTypeDependent() || rhs->isTypeDependent(), 2692bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor lhs->isValueDependent() || rhs->isValueDependent(), 2693561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (lhs->isInstantiationDependent() || 2694561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhs->isInstantiationDependent()), 2695bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (lhs->containsUnexpandedParameterPack() || 2696bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhs->containsUnexpandedParameterPack())), 2697898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Opc(opc), OpLoc(opLoc) { 26981237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 26991237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 27001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(!isCompoundAssignmentOp() && 27015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Use ArithAssignBinaryOperator for compound assignments"); 27025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 27035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2704db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty binary operator. 27051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit BinaryOperator(EmptyShell Empty) 27062de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall : Expr(BinaryOperatorClass, Empty), Opc(BO_Comma) { } 2707db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 27082def77399ab3088106a2d61372344f5b7104e1a2David Blaikie SourceLocation getExprLoc() const { return OpLoc; } 270917d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation getOperatorLoc() const { return OpLoc; } 2710db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setOperatorLoc(SourceLocation L) { OpLoc = L; } 2711db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 27120799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Opcode getOpcode() const { return static_cast<Opcode>(Opc); } 2713db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setOpcode(Opcode O) { Opc = O; } 2714db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 27155549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 2716db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 27175549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 2718db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 2719db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 272063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 27215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd()); 27225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 27231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 27255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// corresponds to, e.g. "<<=". 27265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static const char *getOpcodeStr(Opcode Op); 27275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 27280799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall const char *getOpcodeStr() const { return getOpcodeStr(getOpcode()); } 2729a84c02d0f4d63975a1c52b9bb8308d88e9d79352Ted Kremenek 2730063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// \brief Retrieve the binary opcode that corresponds to the given 2731063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// overloaded operator. 2732063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static Opcode getOverloadedOpcode(OverloadedOperatorKind OO); 2733063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 2734063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// \brief Retrieve the overloaded operator kind that corresponds to 2735063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// the given binary opcode. 2736063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); 2737063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 27385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// predicates to categorize the respective opcodes. 2739200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl bool isPtrMemOp() const { return Opc == BO_PtrMemD || Opc == BO_PtrMemI; } 27402de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall bool isMultiplicativeOp() const { return Opc >= BO_Mul && Opc <= BO_Rem; } 27412de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isAdditiveOp(Opcode Opc) { return Opc == BO_Add || Opc==BO_Sub; } 27420799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isAdditiveOp() const { return isAdditiveOp(getOpcode()); } 27432de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isShiftOp(Opcode Opc) { return Opc == BO_Shl || Opc == BO_Shr; } 27440799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isShiftOp() const { return isShiftOp(getOpcode()); } 2745aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl 27462de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isBitwiseOp(Opcode Opc) { return Opc >= BO_And && Opc <= BO_Or; } 27470799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isBitwiseOp() const { return isBitwiseOp(getOpcode()); } 2748f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 27492de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isRelationalOp(Opcode Opc) { return Opc >= BO_LT && Opc<=BO_GE; } 27500799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isRelationalOp() const { return isRelationalOp(getOpcode()); } 2751f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 27522de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isEqualityOp(Opcode Opc) { return Opc == BO_EQ || Opc == BO_NE; } 27530799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isEqualityOp() const { return isEqualityOp(getOpcode()); } 27541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27552de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isComparisonOp(Opcode Opc) { return Opc >= BO_LT && Opc<=BO_NE; } 27560799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isComparisonOp() const { return isComparisonOp(getOpcode()); } 2757aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl 27582de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isLogicalOp(Opcode Opc) { return Opc == BO_LAnd || Opc==BO_LOr; } 27590799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isLogicalOp() const { return isLogicalOp(getOpcode()); } 2760f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 27610e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall static bool isAssignmentOp(Opcode Opc) { 27620e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall return Opc >= BO_Assign && Opc <= BO_OrAssign; 27630e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall } 27640e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall bool isAssignmentOp() const { return isAssignmentOp(getOpcode()); } 27650e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall 27660e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall static bool isCompoundAssignmentOp(Opcode Opc) { 27672de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Opc > BO_Assign && Opc <= BO_OrAssign; 27682de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 27690e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall bool isCompoundAssignmentOp() const { 27700e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall return isCompoundAssignmentOp(getOpcode()); 27710e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall } 27724b9c2d235fb9449e249d74f48ecfec601650de93John McCall static Opcode getOpForCompoundAssignment(Opcode Opc) { 27734b9c2d235fb9449e249d74f48ecfec601650de93John McCall assert(isCompoundAssignmentOp(Opc)); 2774b92e5d0acbb21e57498fcc4157e108a50c82b857John McCall if (Opc >= BO_AndAssign) 2775b92e5d0acbb21e57498fcc4157e108a50c82b857John McCall return Opcode(unsigned(Opc) - BO_AndAssign + BO_And); 27764b9c2d235fb9449e249d74f48ecfec601650de93John McCall else 27774b9c2d235fb9449e249d74f48ecfec601650de93John McCall return Opcode(unsigned(Opc) - BO_MulAssign + BO_Mul); 27784b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 27790e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall 27800e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall static bool isShiftAssignOp(Opcode Opc) { 27812de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Opc == BO_ShlAssign || Opc == BO_ShrAssign; 27822de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 27830e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall bool isShiftAssignOp() const { 27840e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall return isShiftAssignOp(getOpcode()); 27850e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall } 27861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *S) { 27884bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return S->getStmtClass() >= firstBinaryOperatorConstant && 27894bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt S->getStmtClass() <= lastBinaryOperatorConstant; 27905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 27915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const BinaryOperator *) { return true; } 27921237c673c07f9d827129ba02720108816abde562Ted Kremenek 27931237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 279463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 279563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 279663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 27971237c673c07f9d827129ba02720108816abde562Ted Kremenek 27985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 279917d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 2800f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 28012333f7727f97018d6742e1e0938133bcfad967abEli Friedman SourceLocation opLoc, bool dead) 2802f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CompoundAssignOperatorClass, ResTy, VK, OK, 28032333f7727f97018d6742e1e0938133bcfad967abEli Friedman lhs->isTypeDependent() || rhs->isTypeDependent(), 2804bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor lhs->isValueDependent() || rhs->isValueDependent(), 2805561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (lhs->isInstantiationDependent() || 2806561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhs->isInstantiationDependent()), 2807bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (lhs->containsUnexpandedParameterPack() || 2808bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhs->containsUnexpandedParameterPack())), 28092333f7727f97018d6742e1e0938133bcfad967abEli Friedman Opc(opc), OpLoc(opLoc) { 28101237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 28111237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 28125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2813ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 28141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump BinaryOperator(StmtClass SC, EmptyShell Empty) 28152de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall : Expr(SC, Empty), Opc(BO_MulAssign) { } 28165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 28175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 28185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep 28195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// track of the type the operation is performed in. Due to the semantics of 2820ec5bc81fd55bfcc26fc4bde6d5e33113d94c2209Zhongxing Xu/// these operators, the operands are promoted, the arithmetic performed, an 28215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// implicit conversion back to the result type done, then the assignment takes 28225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// place. This captures the intermediate type which the computation is done 28235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// in. 28245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CompoundAssignOperator : public BinaryOperator { 2825ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType ComputationLHSType; 2826ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType ComputationResultType; 28275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 2828f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResType, 2829f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 2830f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType CompLHSType, QualType CompResultType, 283117d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation OpLoc) 2832f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : BinaryOperator(lhs, rhs, opc, ResType, VK, OK, OpLoc, true), 2833ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman ComputationLHSType(CompLHSType), 2834ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman ComputationResultType(CompResultType) { 28351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(isCompoundAssignmentOp() && 28365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Only should be used for compound assignments"); 28375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 28385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2839ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor /// \brief Build an empty compound assignment operator expression. 2840ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor explicit CompoundAssignOperator(EmptyShell Empty) 2841ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor : BinaryOperator(CompoundAssignOperatorClass, Empty) { } 2842ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 2843ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // The two computation types are the type the LHS is converted 2844ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // to for the computation and the type of the result; the two are 2845ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // distinct in a few cases (specifically, int+=ptr and ptr-=ptr). 2846ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType getComputationLHSType() const { return ComputationLHSType; } 2847ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setComputationLHSType(QualType T) { ComputationLHSType = T; } 2848ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 2849ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType getComputationResultType() const { return ComputationResultType; } 2850ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setComputationResultType(QualType T) { ComputationResultType = T; } 2851ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 28525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CompoundAssignOperator *) { return true; } 28531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *S) { 28541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return S->getStmtClass() == CompoundAssignOperatorClass; 28555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 28565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 28575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 285856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// AbstractConditionalOperator - An abstract base class for 285956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// ConditionalOperator and BinaryConditionalOperator. 286056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass AbstractConditionalOperator : public Expr { 286156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation QuestionLoc, ColonLoc; 286256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall friend class ASTStmtReader; 286356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 286456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallprotected: 286556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall AbstractConditionalOperator(StmtClass SC, QualType T, 286656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall ExprValueKind VK, ExprObjectKind OK, 2867561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool TD, bool VD, bool ID, 286856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall bool ContainsUnexpandedParameterPack, 286956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation qloc, 287056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation cloc) 2871561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Expr(SC, T, VK, OK, TD, VD, ID, ContainsUnexpandedParameterPack), 287256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall QuestionLoc(qloc), ColonLoc(cloc) {} 287356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 287456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall AbstractConditionalOperator(StmtClass SC, EmptyShell Empty) 287556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : Expr(SC, Empty) { } 287656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 287756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallpublic: 287856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getCond - Return the expression representing the condition for 287956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the ?: operator. 288056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getCond() const; 288156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 288256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getTrueExpr - Return the subexpression representing the value of 288356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the expression if the condition evaluates to true. 288456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getTrueExpr() const; 288556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 288656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getFalseExpr - Return the subexpression representing the value of 288756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the expression if the condition evaluates to false. This is 288856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the same as getRHS. 288956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getFalseExpr() const; 289056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 289156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation getQuestionLoc() const { return QuestionLoc; } 289256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation getColonLoc() const { return ColonLoc; } 289356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 289456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const Stmt *T) { 289556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return T->getStmtClass() == ConditionalOperatorClass || 289656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall T->getStmtClass() == BinaryConditionalOperatorClass; 289756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 289856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const AbstractConditionalOperator *) { return true; } 289956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall}; 290056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 290156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// ConditionalOperator - The ?: ternary operator. The GNU "missing 290256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// middle" extension is a BinaryConditionalOperator. 290356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass ConditionalOperator : public AbstractConditionalOperator { 29041237c673c07f9d827129ba02720108816abde562Ted Kremenek enum { COND, LHS, RHS, END_EXPR }; 29055549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 290656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 290756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall friend class ASTStmtReader; 29085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 290947e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor ConditionalOperator(Expr *cond, SourceLocation QLoc, Expr *lhs, 291056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation CLoc, Expr *rhs, 29110943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall QualType t, ExprValueKind VK, ExprObjectKind OK) 291256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : AbstractConditionalOperator(ConditionalOperatorClass, t, VK, OK, 2913898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // FIXME: the type of the conditional operator doesn't 2914898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // depend on the type of the conditional, but the standard 2915898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // seems to imply that it could. File a bug! 291656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (lhs->isTypeDependent() || rhs->isTypeDependent()), 291756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (cond->isValueDependent() || lhs->isValueDependent() || 291856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall rhs->isValueDependent()), 2919561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (cond->isInstantiationDependent() || 2920561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor lhs->isInstantiationDependent() || 2921561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhs->isInstantiationDependent()), 2922bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (cond->containsUnexpandedParameterPack() || 292356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall lhs->containsUnexpandedParameterPack() || 292456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall rhs->containsUnexpandedParameterPack()), 292556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall QLoc, CLoc) { 29261237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[COND] = cond; 29271237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 29281237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 29291237c673c07f9d827129ba02720108816abde562Ted Kremenek } 29305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2931ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor /// \brief Build an empty conditional operator. 2932ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor explicit ConditionalOperator(EmptyShell Empty) 293356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : AbstractConditionalOperator(ConditionalOperatorClass, Empty) { } 2934ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 2935395a2abf0028968d85958610e393e067885dc14fTed Kremenek // getCond - Return the expression representing the condition for 293656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the ?: operator. 29375549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 2938395a2abf0028968d85958610e393e067885dc14fTed Kremenek 293956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getTrueExpr - Return the subexpression representing the value of 294056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the expression if the condition evaluates to true. 294156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getTrueExpr() const { return cast<Expr>(SubExprs[LHS]); } 29421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 294356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getFalseExpr - Return the subexpression representing the value of 294456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the expression if the condition evaluates to false. This is 294556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the same as getRHS. 29465549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); } 2947ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 294856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 29495549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 295047e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor 295163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 29525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd()); 29535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 29541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 29551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ConditionalOperatorClass; 29565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 29575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ConditionalOperator *) { return true; } 29581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29591237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 296063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 296163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 296263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 29635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 29645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 296556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// BinaryConditionalOperator - The GNU extension to the conditional 296656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// operator which allows the middle operand to be omitted. 296756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// 296856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// This is a different expression kind on the assumption that almost 296956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// every client ends up needing to know that these are different. 297056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass BinaryConditionalOperator : public AbstractConditionalOperator { 297156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall enum { COMMON, COND, LHS, RHS, NUM_SUBEXPRS }; 297256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 297356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// - the common condition/left-hand-side expression, which will be 297456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// evaluated as the opaque value 297556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// - the condition, expressed in terms of the opaque value 297656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// - the left-hand-side, expressed in terms of the opaque value 297756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// - the right-hand-side 297856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Stmt *SubExprs[NUM_SUBEXPRS]; 297956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValueExpr *OpaqueValue; 298056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 298156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall friend class ASTStmtReader; 298256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallpublic: 298356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall BinaryConditionalOperator(Expr *common, OpaqueValueExpr *opaqueValue, 298456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *cond, Expr *lhs, Expr *rhs, 298556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation qloc, SourceLocation cloc, 298656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall QualType t, ExprValueKind VK, ExprObjectKind OK) 298756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : AbstractConditionalOperator(BinaryConditionalOperatorClass, t, VK, OK, 298856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (common->isTypeDependent() || rhs->isTypeDependent()), 298956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (common->isValueDependent() || rhs->isValueDependent()), 2990561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (common->isInstantiationDependent() || 2991561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhs->isInstantiationDependent()), 299256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (common->containsUnexpandedParameterPack() || 299356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall rhs->containsUnexpandedParameterPack()), 299456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall qloc, cloc), 299556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValue(opaqueValue) { 299656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SubExprs[COMMON] = common; 299756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SubExprs[COND] = cond; 299856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SubExprs[LHS] = lhs; 299956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SubExprs[RHS] = rhs; 300056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 300156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValue->setSourceExpr(common); 300256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 300356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 300456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief Build an empty conditional operator. 300556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall explicit BinaryConditionalOperator(EmptyShell Empty) 300656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : AbstractConditionalOperator(BinaryConditionalOperatorClass, Empty) { } 300756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 300856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getCommon - Return the common expression, written to the 300956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// left of the condition. The opaque value will be bound to the 301056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// result of this expression. 301156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getCommon() const { return cast<Expr>(SubExprs[COMMON]); } 301256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 301356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getOpaqueValue - Return the opaque value placeholder. 301456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValueExpr *getOpaqueValue() const { return OpaqueValue; } 301556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 301656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getCond - Return the condition expression; this is defined 301756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// in terms of the opaque value. 301856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 301956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 302056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getTrueExpr - Return the subexpression which will be 302156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// evaluated if the condition evaluates to true; this is defined 302256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// in terms of the opaque value. 302356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getTrueExpr() const { 302456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<Expr>(SubExprs[LHS]); 302556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 302656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 302756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getFalseExpr - Return the subexpression which will be 302856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// evaluated if the condnition evaluates to false; this is 302956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// defined in terms of the opaque value. 303056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getFalseExpr() const { 303156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<Expr>(SubExprs[RHS]); 303256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 3033ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 303456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceRange getSourceRange() const { 303556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return SourceRange(getCommon()->getLocStart(), getFalseExpr()->getLocEnd()); 303656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 303756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const Stmt *T) { 303856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return T->getStmtClass() == BinaryConditionalOperatorClass; 303956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 304056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const BinaryConditionalOperator *) { return true; } 304156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 304256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // Iterators 304356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall child_range children() { 304456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return child_range(SubExprs, SubExprs + NUM_SUBEXPRS); 304556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 304656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall}; 304756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 304856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallinline Expr *AbstractConditionalOperator::getCond() const { 304956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this)) 305056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return co->getCond(); 305156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<BinaryConditionalOperator>(this)->getCond(); 305256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall} 305356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 305456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallinline Expr *AbstractConditionalOperator::getTrueExpr() const { 305556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this)) 305656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return co->getTrueExpr(); 305756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<BinaryConditionalOperator>(this)->getTrueExpr(); 305856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall} 305956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 306056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallinline Expr *AbstractConditionalOperator::getFalseExpr() const { 306156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this)) 306256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return co->getFalseExpr(); 306356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<BinaryConditionalOperator>(this)->getFalseExpr(); 306456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall} 306556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 30666481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner/// AddrLabelExpr - The GNU address of label extension, representing &&label. 30676481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattnerclass AddrLabelExpr : public Expr { 30685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation AmpAmpLoc, LabelLoc; 3069ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *Label; 30705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 3071ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelDecl *L, 30726481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner QualType t) 3073561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Expr(AddrLabelExprClass, t, VK_RValue, OK_Ordinary, false, false, false, 3074561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false), 30752333f7727f97018d6742e1e0938133bcfad967abEli Friedman AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {} 30761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30777d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor /// \brief Build an empty address of a label expression. 30781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit AddrLabelExpr(EmptyShell Empty) 30797d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor : Expr(AddrLabelExprClass, Empty) { } 30807d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 30817d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; } 30827d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; } 30837d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor SourceLocation getLabelLoc() const { return LabelLoc; } 30847d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setLabelLoc(SourceLocation L) { LabelLoc = L; } 30857d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 308663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 30875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(AmpAmpLoc, LabelLoc); 30885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 30891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3090ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *getLabel() const { return Label; } 3091ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner void setLabel(LabelDecl *L) { Label = L; } 30927d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 30935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 30941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == AddrLabelExprClass; 30955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 30966481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner static bool classof(const AddrLabelExpr *) { return true; } 30971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30981237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 309963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 31005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 3101ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner 3102ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}). 3103ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// The StmtExpr contains a single CompoundStmt node, which it evaluates and 3104ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// takes the value of the last subexpression. 3105f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall/// 3106f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall/// A StmtExpr is always an r-value; values "returned" out of a 3107f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall/// StmtExpr will be copied. 3108ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerclass StmtExpr : public Expr { 31095549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *SubStmt; 3110ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner SourceLocation LParenLoc, RParenLoc; 3111ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerpublic: 31122333f7727f97018d6742e1e0938133bcfad967abEli Friedman // FIXME: Does type-dependence need to be computed differently? 3113561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor // FIXME: Do we need to compute instantiation instantiation-dependence for 3114561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor // statements? (ugh!) 3115d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff StmtExpr(CompoundStmt *substmt, QualType T, 3116d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff SourceLocation lp, SourceLocation rp) : 3117f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(StmtExprClass, T, VK_RValue, OK_Ordinary, 3118561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor T->isDependentType(), false, false, false), 31192333f7727f97018d6742e1e0938133bcfad967abEli Friedman SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) { } 31201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 31216a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor /// \brief Build an empty statement expression. 31226a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { } 31236a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor 31245549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); } 31255549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); } 31266a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setSubStmt(CompoundStmt *S) { SubStmt = S; } 31276a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor 312863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 3129ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner return SourceRange(LParenLoc, RParenLoc); 3130ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner } 31311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3132026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getLParenLoc() const { return LParenLoc; } 31336a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setLParenLoc(SourceLocation L) { LParenLoc = L; } 3134026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getRParenLoc() const { return RParenLoc; } 31356a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 31361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3137ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner static bool classof(const Stmt *T) { 31381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == StmtExprClass; 3139ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner } 3140ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner static bool classof(const StmtExpr *) { return true; } 31411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 31421237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 314363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&SubStmt, &SubStmt+1); } 3144ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner}; 3145ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner 3146d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff 3147d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// ShuffleVectorExpr - clang-specific builtin-in function 3148d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// __builtin_shufflevector. 3149d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// This AST node represents a operator that does a constant 3150d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// shuffle, similar to LLVM's shufflevector instruction. It takes 3151d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// two vectors and a variable number of constant indices, 3152d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// and returns the appropriately shuffled vector. 3153d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanclass ShuffleVectorExpr : public Expr { 3154d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman SourceLocation BuiltinLoc, RParenLoc; 3155d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 3156d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // SubExprs - the list of values passed to the __builtin_shufflevector 3157d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // function. The first two are vectors, and the rest are constant 3158d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // indices. The number of values in this list is always 3159d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // 2+the number of indices in the vector type. 31605549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt **SubExprs; 3161d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman unsigned NumExprs; 3162d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 3163d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanpublic: 3164a88dc3079bedf70a5cfc39791727e43a10383006Nate Begeman ShuffleVectorExpr(ASTContext &C, Expr **args, unsigned nexpr, 31651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType Type, SourceLocation BLoc, 3166bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor SourceLocation RP); 316794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 316894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor /// \brief Build an empty vector-shuffle expression. 31691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ShuffleVectorExpr(EmptyShell Empty) 317094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor : Expr(ShuffleVectorExprClass, Empty), SubExprs(0) { } 317194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 317294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 317394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 31741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 317594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 317694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 317794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 317863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 3179d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman return SourceRange(BuiltinLoc, RParenLoc); 3180d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 3181d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman static bool classof(const Stmt *T) { 31821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ShuffleVectorExprClass; 3183d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 3184d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman static bool classof(const ShuffleVectorExpr *) { return true; } 31851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3186d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// getNumSubExprs - Return the size of the SubExprs array. This includes the 3187d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// constant expression, the actual arguments passed in, and the function 3188d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// pointers. 3189d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman unsigned getNumSubExprs() const { return NumExprs; } 31901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3191aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \brief Retrieve the array of expressions. 3192aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Expr **getSubExprs() { return reinterpret_cast<Expr **>(SubExprs); } 3193ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 3194d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// getExpr - Return the Expr at the specified index. 3195d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman Expr *getExpr(unsigned Index) { 3196d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman assert((Index < NumExprs) && "Arg access out of range!"); 31975549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Index]); 3198d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 3199d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman const Expr *getExpr(unsigned Index) const { 3200d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman assert((Index < NumExprs) && "Arg access out of range!"); 32015549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Index]); 3202d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 32031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3204888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman void setExprs(ASTContext &C, Expr ** Exprs, unsigned NumExprs); 320594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 3206dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman unsigned getShuffleMaskIdx(ASTContext &Ctx, unsigned N) { 3207dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman assert((N < NumExprs - 2) && "Shuffle idx out of range!"); 3208a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith return getExpr(N+2)->EvaluateKnownConstInt(Ctx).getZExtValue(); 3209d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 32101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3211d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // Iterators 321263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 321363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+NumExprs); 321463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 3215d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman}; 3216d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 3217d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// ChooseExpr - GNU builtin-in function __builtin_choose_expr. 32181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// This AST node is similar to the conditional operator (?:) in C, with 3219d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// the following exceptions: 32207976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the test expression must be a integer constant expression. 32217976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the expression returned acts like the chosen subexpression in every 32227976932a1c256d447316ffac58e9821417725e34Eli Friedman/// visible way: the type is the same as that of the chosen subexpression, 32237976932a1c256d447316ffac58e9821417725e34Eli Friedman/// and all predicates (whether it's an l-value, whether it's an integer 32247976932a1c256d447316ffac58e9821417725e34Eli Friedman/// constant expression, etc.) return the same result as for the chosen 32257976932a1c256d447316ffac58e9821417725e34Eli Friedman/// sub-expression. 3226d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffclass ChooseExpr : public Expr { 32271237c673c07f9d827129ba02720108816abde562Ted Kremenek enum { COND, LHS, RHS, END_EXPR }; 32285549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 3229d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff SourceLocation BuiltinLoc, RParenLoc; 3230d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffpublic: 3231f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, 3232f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType t, ExprValueKind VK, ExprObjectKind OK, 3233ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor SourceLocation RP, bool TypeDependent, bool ValueDependent) 3234bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(ChooseExprClass, t, VK, OK, TypeDependent, ValueDependent, 3235561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (cond->isInstantiationDependent() || 3236561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor lhs->isInstantiationDependent() || 3237561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhs->isInstantiationDependent()), 3238bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (cond->containsUnexpandedParameterPack() || 3239bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor lhs->containsUnexpandedParameterPack() || 3240bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhs->containsUnexpandedParameterPack())), 32411237c673c07f9d827129ba02720108816abde562Ted Kremenek BuiltinLoc(BLoc), RParenLoc(RP) { 32421237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[COND] = cond; 32431237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 32441237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 32451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 32467976932a1c256d447316ffac58e9821417725e34Eli Friedman 324744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor /// \brief Build an empty __builtin_choose_expr. 324844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { } 324944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 32507976932a1c256d447316ffac58e9821417725e34Eli Friedman /// isConditionTrue - Return whether the condition is true (i.e. not 32517976932a1c256d447316ffac58e9821417725e34Eli Friedman /// equal to zero). 32524ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool isConditionTrue(const ASTContext &C) const; 32537976932a1c256d447316ffac58e9821417725e34Eli Friedman 32547976932a1c256d447316ffac58e9821417725e34Eli Friedman /// getChosenSubExpr - Return the subexpression chosen according to the 32557976932a1c256d447316ffac58e9821417725e34Eli Friedman /// condition. 32564ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad Expr *getChosenSubExpr(const ASTContext &C) const { 32577976932a1c256d447316ffac58e9821417725e34Eli Friedman return isConditionTrue(C) ? getLHS() : getRHS(); 32587976932a1c256d447316ffac58e9821417725e34Eli Friedman } 32597976932a1c256d447316ffac58e9821417725e34Eli Friedman 32605549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 326144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setCond(Expr *E) { SubExprs[COND] = E; } 32625549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 326344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 32645549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 326544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 326644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 326744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 326844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 32691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 327044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 327144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 32721237c673c07f9d827129ba02720108816abde562Ted Kremenek 327363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 3274d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff return SourceRange(BuiltinLoc, RParenLoc); 3275d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff } 3276d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff static bool classof(const Stmt *T) { 32771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ChooseExprClass; 3278d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff } 3279d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff static bool classof(const ChooseExpr *) { return true; } 32801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32811237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 328263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 328363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 328463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 3285d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff}; 3286d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff 32872d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// GNUNullExpr - Implements the GNU __null extension, which is a name 32882d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// for a null pointer constant that has integral type (e.g., int or 32892d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// long) and is the same size and alignment as a pointer. The __null 32902d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// extension is typically only used by system headers, which define 32912d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// NULL as __null in C++ rather than using 0 (which is an integer 32922d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// that may not match the size of a pointer). 32932d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorclass GNUNullExpr : public Expr { 32942d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor /// TokenLoc - The location of the __null keyword. 32952d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor SourceLocation TokenLoc; 32962d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 32972d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorpublic: 32981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump GNUNullExpr(QualType Ty, SourceLocation Loc) 3299561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Expr(GNUNullExprClass, Ty, VK_RValue, OK_Ordinary, false, false, false, 3300561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false), 3301f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall TokenLoc(Loc) { } 33022d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 330344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor /// \brief Build an empty GNU __null expression. 330444cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { } 330544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 33062d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor /// getTokenLocation - The location of the __null token. 33072d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor SourceLocation getTokenLocation() const { return TokenLoc; } 330844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setTokenLocation(SourceLocation L) { TokenLoc = L; } 33092d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 331063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 33112d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor return SourceRange(TokenLoc); 33122d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } 33132d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor static bool classof(const Stmt *T) { 33141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == GNUNullExprClass; 33152d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } 33162d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor static bool classof(const GNUNullExpr *) { return true; } 33171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 33182d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor // Iterators 331963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 33202d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor}; 33212d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 332274626d6ef2e194fcc911e071556660ff331eb4a8Zhongxing Xu/// VAArgExpr, used for the builtin function __builtin_va_arg. 33237c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonclass VAArgExpr : public Expr { 33245549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 33252cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara TypeSourceInfo *TInfo; 33267c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson SourceLocation BuiltinLoc, RParenLoc; 33277c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonpublic: 33282cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara VAArgExpr(SourceLocation BLoc, Expr* e, TypeSourceInfo *TInfo, 33292cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara SourceLocation RPLoc, QualType t) 3330f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(VAArgExprClass, t, VK_RValue, OK_Ordinary, 3331bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor t->isDependentType(), false, 3332561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (TInfo->getType()->isInstantiationDependentType() || 3333561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor e->isInstantiationDependent()), 3334bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (TInfo->getType()->containsUnexpandedParameterPack() || 3335bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor e->containsUnexpandedParameterPack())), 33362cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara Val(e), TInfo(TInfo), 33377c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson BuiltinLoc(BLoc), 33387c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson RParenLoc(RPLoc) { } 33391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 334074626d6ef2e194fcc911e071556660ff331eb4a8Zhongxing Xu /// \brief Create an empty __builtin_va_arg expression. 3341d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor explicit VAArgExpr(EmptyShell Empty) : Expr(VAArgExprClass, Empty) { } 3342d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 33435549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 33445549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 3345d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 3346d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 33472cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara TypeSourceInfo *getWrittenTypeInfo() const { return TInfo; } 33482cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara void setWrittenTypeInfo(TypeSourceInfo *TI) { TInfo = TI; } 33492cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara 3350d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 3351d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 33521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3353d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 3354d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 3355d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 335663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 33577c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson return SourceRange(BuiltinLoc, RParenLoc); 33581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 33597c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson static bool classof(const Stmt *T) { 33607c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson return T->getStmtClass() == VAArgExprClass; 33617c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson } 33627c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson static bool classof(const VAArgExpr *) { return true; } 33631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 33647c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson // Iterators 336563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Val, &Val+1); } 33667c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson}; 33671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 33684c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @brief Describes an C or C++ initializer list. 33694c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// 33704c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// InitListExpr describes an initializer list, which can be used to 33714c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initialize objects of different types, including 33724c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct/class/union types, arrays, and vectors. For example: 33734c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// 33744c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @code 33754c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct foo x = { 1, { 2, 3 } }; 33764c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @endcode 3377196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 33784c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Prior to semantic analysis, an initializer list will represent the 33794c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer list as written by the user, but will have the 33804c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// placeholder type "void". This initializer list is called the 33814c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// syntactic form of the initializer, and may contain C99 designated 33824c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializers (represented as DesignatedInitExprs), initializations 33834c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// of subobject members without explicit braces, and so on. Clients 33844c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// interested in the original syntax of the initializer list should 33854c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// use the syntactic form of the initializer list. 3386196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 33874c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// After semantic analysis, the initializer list will represent the 33884c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// semantic form of the initializer, where the initializations of all 33894c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// subobjects are made explicit with nested InitListExpr nodes and 33904c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// C99 designators have been eliminated by placing the designated 33914c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializations into the subobject they initialize. Additionally, 33924c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// any "holes" in the initialization, where no initializer has been 33934c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// specified for a particular subobject, will be replaced with 33943498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// implicitly-generated ImplicitValueInitExpr expressions that 33954c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// value-initialize the subobjects. Note, however, that the 33964c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer lists may still have fewer initializers than there are 33974c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// elements to initialize within the object. 3398196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 33994c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Given the semantic form of the initializer list, one can retrieve 34004c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// the original syntactic form of that initializer list (if it 34014c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// exists) using getSyntacticForm(). Since many initializer lists 34024c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// have the same syntactic and semantic forms, getSyntacticForm() may 34034c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// return NULL, indicating that the current initializer list also 34044c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// serves as its syntactic form. 340566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonclass InitListExpr : public Expr { 3406ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek // FIXME: Eliminate this vector in favor of ASTContext allocation 3407709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek typedef ASTVector<Stmt *> InitExprsTy; 3408709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprsTy InitExprs; 340966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson SourceLocation LBraceLoc, RBraceLoc; 34101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 34114c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// Contains the initializer list that describes the syntactic form 34124c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// written in the source code. 34134c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitListExpr *SyntacticForm; 34144c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 34154423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// \brief Either: 34164423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// If this initializer list initializes an array with more elements than 34174423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// there are initializers in the list, specifies an expression to be used 34184423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// for value initialization of the rest of the elements. 34194423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// Or 34204423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// If this initializer list initializes a union, specifies which 34214423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// field within the union will be initialized. 34224423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis llvm::PointerUnion<Expr *, FieldDecl *> ArrayFillerOrUnionFieldInit; 34230bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor 3424a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor /// Whether this initializer list originally had a GNU array-range 3425a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor /// designator in it. This is a temporary marker used by CodeGen. 3426a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor bool HadArrayRangeDesignator; 3427a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor 342866b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonpublic: 3429709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitListExpr(ASTContext &C, SourceLocation lbraceloc, 3430709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek Expr **initexprs, unsigned numinits, 3431ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek SourceLocation rbraceloc); 3432d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3433d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Build an empty initializer list. 3434709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek explicit InitListExpr(ASTContext &C, EmptyShell Empty) 3435709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek : Expr(InitListExprClass, Empty), InitExprs(C) { } 34361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3437ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek unsigned getNumInits() const { return InitExprs.size(); } 34381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3439aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \brief Retrieve the set of initializers. 3440aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Expr **getInits() { return reinterpret_cast<Expr **>(InitExprs.data()); } 3441ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 344216c5dea6c2d3e4cf529de9d9b37f6a40441acb2cChris Lattner const Expr *getInit(unsigned Init) const { 3443c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 34444c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return cast_or_null<Expr>(InitExprs[Init]); 344566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 34461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 344716c5dea6c2d3e4cf529de9d9b37f6a40441acb2cChris Lattner Expr *getInit(unsigned Init) { 3448c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 34494c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return cast_or_null<Expr>(InitExprs[Init]); 345066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 34511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 34521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setInit(unsigned Init, Expr *expr) { 3453c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 34549e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff InitExprs[Init] = expr; 34559e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff } 3456c5ae899b4bbf65488445316c63168079177db0edSteve Naroff 3457fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor /// \brief Reserve space for some number of initializers. 3458709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek void reserveInits(ASTContext &C, unsigned NumInits); 34591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 34604c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Specify the number of initializers 34614c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 34624c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// If there are more than @p NumInits initializers, the remaining 34634c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// initializers will be destroyed. If there are fewer than @p 34644c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// NumInits initializers, NULL expressions will be added for the 34654c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// unknown initializers. 34664c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor void resizeInits(ASTContext &Context, unsigned NumInits); 34674c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 34684c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Updates the initializer at index @p Init with the new 34694c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// expression @p expr, and returns the old expression at that 34704c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// location. 34714c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 34724c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// When @p Init is out of range for this initializer list, the 34734c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// initializer list will be extended with NULL expressions to 3474fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner /// accommodate the new entry. 3475709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek Expr *updateInit(ASTContext &C, unsigned Init, Expr *expr); 3476c5ae899b4bbf65488445316c63168079177db0edSteve Naroff 34774423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// \brief If this initializer list initializes an array with more elements 34784423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// than there are initializers in the list, specifies an expression to be 34794423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// used for value initialization of the rest of the elements. 34804423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis Expr *getArrayFiller() { 34814423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis return ArrayFillerOrUnionFieldInit.dyn_cast<Expr *>(); 34824423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis } 34838cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne const Expr *getArrayFiller() const { 34848cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne return const_cast<InitListExpr *>(this)->getArrayFiller(); 34858cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne } 34863e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis void setArrayFiller(Expr *filler); 34874423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis 348821f77cd0c3da8a1dbaf6245cae43baf4c0b80ea4Argyrios Kyrtzidis /// \brief Return true if this is an array initializer and its array "filler" 348921f77cd0c3da8a1dbaf6245cae43baf4c0b80ea4Argyrios Kyrtzidis /// has been set. 349021f77cd0c3da8a1dbaf6245cae43baf4c0b80ea4Argyrios Kyrtzidis bool hasArrayFiller() const { return getArrayFiller(); } 349121f77cd0c3da8a1dbaf6245cae43baf4c0b80ea4Argyrios Kyrtzidis 34920bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// \brief If this initializes a union, specifies which field in the 34930bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// union to initialize. 34940bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// 34950bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// Typically, this field is the first named field within the 34960bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// union. However, a designated initializer can specify the 34970bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// initialization of a different field within the union. 34984423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis FieldDecl *getInitializedFieldInUnion() { 34994423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis return ArrayFillerOrUnionFieldInit.dyn_cast<FieldDecl *>(); 35004423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis } 35018cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne const FieldDecl *getInitializedFieldInUnion() const { 35028cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne return const_cast<InitListExpr *>(this)->getInitializedFieldInUnion(); 35038cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne } 35044423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis void setInitializedFieldInUnion(FieldDecl *FD) { 35054423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis ArrayFillerOrUnionFieldInit = FD; 35064423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis } 35070bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor 3508c5ae899b4bbf65488445316c63168079177db0edSteve Naroff // Explicit InitListExpr's originate from source code (and have valid source 3509c5ae899b4bbf65488445316c63168079177db0edSteve Naroff // locations). Implicit InitListExpr's are created by the semantic analyzer. 3510b3eef68111ffc220e449be96da1747998c057790Douglas Gregor bool isExplicit() { 3511b3eef68111ffc220e449be96da1747998c057790Douglas Gregor return LBraceLoc.isValid() && RBraceLoc.isValid(); 3512b3eef68111ffc220e449be96da1747998c057790Douglas Gregor } 35131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3514d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor SourceLocation getLBraceLoc() const { return LBraceLoc; } 3515d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setLBraceLoc(SourceLocation Loc) { LBraceLoc = Loc; } 3516d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor SourceLocation getRBraceLoc() const { return RBraceLoc; } 351787fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; } 351887fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor 35194c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Retrieve the initializer list that describes the 35204c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// syntactic form of the initializer. 35214c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 35221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 35234c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitListExpr *getSyntacticForm() const { return SyntacticForm; } 35244c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor void setSyntacticForm(InitListExpr *Init) { SyntacticForm = Init; } 35254c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 3526a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor bool hadArrayRangeDesignator() const { return HadArrayRangeDesignator; } 35271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void sawArrayRangeDesignator(bool ARD = true) { 3528d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor HadArrayRangeDesignator = ARD; 3529a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor } 3530a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor 353163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const; 3532c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek 353366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson static bool classof(const Stmt *T) { 35341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == InitListExprClass; 353566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 353666b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson static bool classof(const InitListExpr *) { return true; } 35371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 353866b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson // Iterators 353963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 354063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall if (InitExprs.empty()) return child_range(); 354163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&InitExprs[0], &InitExprs[0] + InitExprs.size()); 354263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 35431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3544709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek typedef InitExprsTy::iterator iterator; 35458111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu typedef InitExprsTy::const_iterator const_iterator; 3546709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek typedef InitExprsTy::reverse_iterator reverse_iterator; 35478111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu typedef InitExprsTy::const_reverse_iterator const_reverse_iterator; 35481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3549ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek iterator begin() { return InitExprs.begin(); } 35508111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_iterator begin() const { return InitExprs.begin(); } 3551ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek iterator end() { return InitExprs.end(); } 35528111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_iterator end() const { return InitExprs.end(); } 3553ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek reverse_iterator rbegin() { return InitExprs.rbegin(); } 35548111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_reverse_iterator rbegin() const { return InitExprs.rbegin(); } 3555ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek reverse_iterator rend() { return InitExprs.rend(); } 35568111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_reverse_iterator rend() const { return InitExprs.rend(); } 35574423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis 35584423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis friend class ASTStmtReader; 35594423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis friend class ASTStmtWriter; 356066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson}; 356166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson 356205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @brief Represents a C99 designated initializer expression. 356305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// 356405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// A designated initializer expression (C99 6.7.8) contains one or 356505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// more designators (which can be field designators, array 356605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, or GNU array-range designators) followed by an 356705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// expression that initializes the field or element(s) that the 356805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators refer to. For example, given: 35691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 357005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @code 357105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point { 357205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// double x; 357305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// double y; 357405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// }; 357505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 }; 357605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @endcode 357705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// 357805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// The InitListExpr contains three DesignatedInitExprs, the first of 357905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// which covers @c [2].y=1.0. This DesignatedInitExpr will have two 358005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, one array designator for @c [2] followed by one field 358105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designator for @c .y. The initalization expression will be 1.0. 358205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorclass DesignatedInitExpr : public Expr { 3583ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorpublic: 3584ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief Forward declaration of the Designator class. 3585ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor class Designator; 3586ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 3587ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorprivate: 358805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '=' or ':' prior to the actual initializer 358905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// expression. 359005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EqualOrColonLoc; 359105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3592eeae8f072748affce25ab4064982626361293390Douglas Gregor /// Whether this designated initializer used the GNU deprecated 359305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// syntax rather than the C99 '=' syntax. 3594eeae8f072748affce25ab4064982626361293390Douglas Gregor bool GNUSyntax : 1; 359505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 359605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The number of designators in this initializer expression. 359705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators : 15; 359805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3599ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief The designators in this designated initialization 3600ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// expression. 3601ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designator *Designators; 3602ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 360305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The number of subexpressions of this initializer expression, 360405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// which contains both the initializer and any additional 360505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// expressions used by array and array-range designators. 360605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumSubExprs : 16; 360705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3608ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 3609319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor DesignatedInitExpr(ASTContext &C, QualType Ty, unsigned NumDesignators, 3610ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Designators, 3611eeae8f072748affce25ab4064982626361293390Douglas Gregor SourceLocation EqualOrColonLoc, bool GNUSyntax, 36129ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr **IndexExprs, unsigned NumIndexExprs, 36139ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *Init); 361405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3615d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor explicit DesignatedInitExpr(unsigned NumSubExprs) 3616d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor : Expr(DesignatedInitExprClass, EmptyShell()), 3617d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor NumDesignators(0), Designators(0), NumSubExprs(NumSubExprs) { } 3618d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 361905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorpublic: 362005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// A field designator, e.g., ".x". 362105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct FieldDesignator { 362205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// Refers to the field that is being initialized. The low bit 362305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// of this field determines whether this is actually a pointer 362405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When 362505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initially constructed, a field designator will store an 362605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// IdentifierInfo*. After semantic analysis has resolved that 362705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// name, the field designator will instead store a FieldDecl*. 362805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor uintptr_t NameOrField; 36291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 363005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '.' in the designated initializer. 363105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned DotLoc; 36321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 363305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the field name in the designated initializer. 363405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned FieldLoc; 363505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 363605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 363705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". 363805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct ArrayOrRangeDesignator { 363905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// Location of the first index expression within the designated 364005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initializer expression's list of subexpressions. 364105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned Index; 364205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '[' starting the array range designator. 364305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned LBracketLoc; 364405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the ellipsis separating the start and end 364505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// indices. Only valid for GNU array-range designators. 364605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned EllipsisLoc; 364705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the ']' terminating the array range designator. 36481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned RBracketLoc; 364905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 365005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 365105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Represents a single C99 designator. 365205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// 365305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @todo This class is infuriatingly similar to clang::Designator, 365405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// but minor differences (storing indices vs. storing pointers) 365505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// keep us from reusing it. Try harder, later, to rectify these 365605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// differences. 365705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor class Designator { 365805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief The kind of designator this describes. 365905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor enum { 366005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor FieldDesignator, 366105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayDesignator, 366205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayRangeDesignator 366305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } Kind; 366405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 366505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor union { 366605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// A field designator, e.g., ".x". 366705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct FieldDesignator Field; 366805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". 366905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct ArrayOrRangeDesignator ArrayOrRange; 367005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 367105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor friend class DesignatedInitExpr; 367205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 367305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor public: 3674ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designator() {} 3675ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 367605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes a field designator. 36771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc, 36781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation FieldLoc) 367905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(FieldDesignator) { 368005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01; 368105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.DotLoc = DotLoc.getRawEncoding(); 368205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.FieldLoc = FieldLoc.getRawEncoding(); 368305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 368405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 368505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes an array designator. 36861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(unsigned Index, SourceLocation LBracketLoc, 368705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation RBracketLoc) 368805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(ArrayDesignator) { 368905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.Index = Index; 369005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding(); 369105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding(); 369205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding(); 369305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 369405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 369505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes a GNU array-range designator. 36961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(unsigned Index, SourceLocation LBracketLoc, 369705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EllipsisLoc, SourceLocation RBracketLoc) 369805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(ArrayRangeDesignator) { 369905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.Index = Index; 370005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding(); 370105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding(); 370205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding(); 370305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 370405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 370505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isFieldDesignator() const { return Kind == FieldDesignator; } 370605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isArrayDesignator() const { return Kind == ArrayDesignator; } 370705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; } 370805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3709b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth IdentifierInfo *getFieldName() const; 371005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3711b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth FieldDecl *getField() const { 371205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 371305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor if (Field.NameOrField & 0x01) 371405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return 0; 371505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor else 371605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return reinterpret_cast<FieldDecl *>(Field.NameOrField); 371705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 371805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 371905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor void setField(FieldDecl *FD) { 372005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 372105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.NameOrField = reinterpret_cast<uintptr_t>(FD); 372205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 372305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 372487f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor SourceLocation getDotLoc() const { 372587f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 372687f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor return SourceLocation::getFromRawEncoding(Field.DotLoc); 372787f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor } 372887f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor 372905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getFieldLoc() const { 373005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 373105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(Field.FieldLoc); 373205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 373305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 373405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getLBracketLoc() const { 373505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 373605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array or array-range designator"); 373705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc); 373805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 373905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 374005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getRBracketLoc() const { 374105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 374205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array or array-range designator"); 374305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc); 374405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 374505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 374605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getEllipsisLoc() const { 374705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == ArrayRangeDesignator && 374805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array-range designator"); 374905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc); 375005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 37514c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 3752d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned getFirstExprIndex() const { 3753d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 3754d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor "Only valid on an array or array-range designator"); 3755d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor return ArrayOrRange.Index; 3756d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 3757d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 37584c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor SourceLocation getStartLocation() const { 37594c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor if (Kind == FieldDesignator) 37604c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return getDotLoc().isInvalid()? getFieldLoc() : getDotLoc(); 37614c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor else 37624c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return getLBracketLoc(); 37634c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor } 376424f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara SourceLocation getEndLocation() const { 376524f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara return Kind == FieldDesignator ? getFieldLoc() : getRBracketLoc(); 376624f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara } 376724f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara SourceRange getSourceRange() const { 376824f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara return SourceRange(getStartLocation(), getEndLocation()); 376924f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara } 377005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 377105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 37721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static DesignatedInitExpr *Create(ASTContext &C, Designator *Designators, 377305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators, 377405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr **IndexExprs, unsigned NumIndexExprs, 377505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EqualOrColonLoc, 3776eeae8f072748affce25ab4064982626361293390Douglas Gregor bool GNUSyntax, Expr *Init); 377705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3778d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor static DesignatedInitExpr *CreateEmpty(ASTContext &C, unsigned NumIndexExprs); 3779d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 378005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Returns the number of designators in this initializer. 378105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned size() const { return NumDesignators; } 378205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 378305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor // Iterator access to the designators. 3784b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth typedef Designator *designators_iterator; 3785ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor designators_iterator designators_begin() { return Designators; } 37861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump designators_iterator designators_end() { 37871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return Designators + NumDesignators; 3788ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor } 378905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3790b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth typedef const Designator *const_designators_iterator; 3791b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth const_designators_iterator designators_begin() const { return Designators; } 3792b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth const_designators_iterator designators_end() const { 3793b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth return Designators + NumDesignators; 3794b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth } 3795b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth 3796cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek typedef std::reverse_iterator<designators_iterator> 3797cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek reverse_designators_iterator; 3798cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek reverse_designators_iterator designators_rbegin() { 3799cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek return reverse_designators_iterator(designators_end()); 3800cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek } 3801cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek reverse_designators_iterator designators_rend() { 3802cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek return reverse_designators_iterator(designators_begin()); 3803cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek } 3804cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek 3805b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth typedef std::reverse_iterator<const_designators_iterator> 3806b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth const_reverse_designators_iterator; 3807b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth const_reverse_designators_iterator designators_rbegin() const { 3808b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth return const_reverse_designators_iterator(designators_end()); 3809b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth } 3810b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth const_reverse_designators_iterator designators_rend() const { 3811b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth return const_reverse_designators_iterator(designators_begin()); 3812b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth } 3813b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth 3814711997184366d584c9c437102cae1e9d9927b986Douglas Gregor Designator *getDesignator(unsigned Idx) { return &designators_begin()[Idx]; } 3815711997184366d584c9c437102cae1e9d9927b986Douglas Gregor 3816ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie void setDesignators(ASTContext &C, const Designator *Desigs, 3817319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor unsigned NumDesigs); 3818d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 381905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayIndex(const Designator& D); 382005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayRangeStart(const Designator& D); 382105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayRangeEnd(const Designator& D); 382205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 382305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Retrieve the location of the '=' that precedes the 382405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initializer value itself, if present. 382505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; } 3826d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setEqualOrColonLoc(SourceLocation L) { EqualOrColonLoc = L; } 382705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 382805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Determines whether this designated initializer used the 3829eeae8f072748affce25ab4064982626361293390Douglas Gregor /// deprecated GNU syntax for designated initializers. 3830eeae8f072748affce25ab4064982626361293390Douglas Gregor bool usesGNUSyntax() const { return GNUSyntax; } 3831d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setGNUSyntax(bool GNU) { GNUSyntax = GNU; } 383205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 383305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Retrieve the initializer value. 38341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getInit() const { 383505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin()); 383605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 383705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 383805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor void setInit(Expr *init) { 383905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor *child_begin() = init; 384005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 384105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3842d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Retrieve the total number of subexpressions in this 3843d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// designated initializer expression, including the actual 3844d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// initialized value and any expressions that occur within array 3845d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// and array-range designators. 3846d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned getNumSubExprs() const { return NumSubExprs; } 3847d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3848d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Expr *getSubExpr(unsigned Idx) { 3849d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert(Idx < NumSubExprs && "Subscript out of range"); 3850d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 3851d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 3852d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor return reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx]; 3853d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 3854d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3855d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setSubExpr(unsigned Idx, Expr *E) { 3856d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert(Idx < NumSubExprs && "Subscript out of range"); 3857d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 3858d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 3859d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx] = E; 3860d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 3861d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3862ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief Replaces the designator at index @p Idx with the series 3863ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// of designators in [First, Last). 3864319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor void ExpandDesignator(ASTContext &C, unsigned Idx, const Designator *First, 3865ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Last); 3866ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 386724f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara SourceRange getDesignatorsSourceRange() const; 386824f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara 386963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const; 387005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 387105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor static bool classof(const Stmt *T) { 38721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == DesignatedInitExprClass; 387305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 387405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor static bool classof(const DesignatedInitExpr *) { return true; } 387505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 387605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor // Iterators 387763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 387863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt **begin = reinterpret_cast<Stmt**>(this + 1); 387963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(begin, begin + NumSubExprs); 388063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 38813498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor}; 38823498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 38833498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// \brief Represents an implicitly-generated value initialization of 38843498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// an object of a given type. 38853498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// 38861a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// Implicit value initializations occur within semantic initializer 38871a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// list expressions (InitListExpr) as placeholders for subobject 38883498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// initializations not explicitly specified by the user. 38891a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// 38901a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// \see InitListExpr 38911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass ImplicitValueInitExpr : public Expr { 38923498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregorpublic: 38931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ImplicitValueInitExpr(QualType ty) 3894f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ImplicitValueInitExprClass, ty, VK_RValue, OK_Ordinary, 3895561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false, ty->isInstantiationDependentType(), false) { } 38963498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 3897d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Construct an empty implicit value initialization. 3898d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor explicit ImplicitValueInitExpr(EmptyShell Empty) 3899d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor : Expr(ImplicitValueInitExprClass, Empty) { } 3900d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 39011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 39023498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return T->getStmtClass() == ImplicitValueInitExprClass; 39033498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor } 39043498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor static bool classof(const ImplicitValueInitExpr *) { return true; } 39053498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 390663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 39073498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return SourceRange(); 39083498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor } 39093498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 39103498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor // Iterators 391163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 391205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}; 391305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 39142ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 39152ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanclass ParenListExpr : public Expr { 39162ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman Stmt **Exprs; 39172ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman unsigned NumExprs; 39182ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation LParenLoc, RParenLoc; 39192ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 39202ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanpublic: 39211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParenListExpr(ASTContext& C, SourceLocation lparenloc, Expr **exprs, 39220d9106fc97cde979a995e26b18bcd2643f8afb55Manuel Klimek unsigned numexprs, SourceLocation rparenloc, QualType T); 39232ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 39242ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman /// \brief Build an empty paren list. 392537bdfe284ad365f753741d1d89c078c148b3f4afArgyrios Kyrtzidis explicit ParenListExpr(EmptyShell Empty) : Expr(ParenListExprClass, Empty) { } 39261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 39272ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman unsigned getNumExprs() const { return NumExprs; } 39281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 39291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr* getExpr(unsigned Init) const { 39302ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman assert(Init < getNumExprs() && "Initializer access out of range!"); 39312ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return cast_or_null<Expr>(Exprs[Init]); 39322ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 39331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 39341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr* getExpr(unsigned Init) { 39352ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman assert(Init < getNumExprs() && "Initializer access out of range!"); 39362ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return cast_or_null<Expr>(Exprs[Init]); 39372ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 39382ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 393983ddad3ab513f5d73698cf9fbeb4ed3f011bc3b9Douglas Gregor Expr **getExprs() { return reinterpret_cast<Expr **>(Exprs); } 39401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 39412ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation getLParenLoc() const { return LParenLoc; } 39422ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation getRParenLoc() const { return RParenLoc; } 39432ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 394463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 39452ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return SourceRange(LParenLoc, RParenLoc); 39461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 39472ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman static bool classof(const Stmt *T) { 39481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ParenListExprClass; 39492ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 39502ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman static bool classof(const ParenListExpr *) { return true; } 39511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 39522ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman // Iterators 395363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 395463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&Exprs[0], &Exprs[0]+NumExprs); 395563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 395637bdfe284ad365f753741d1d89c078c148b3f4afArgyrios Kyrtzidis 395760adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 39583397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl friend class ASTStmtWriter; 39592ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman}; 39602ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 39611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3962ffbe9b9c64ab2e94b9d48ec56e511f75826fc80aBenjamin Kramer/// \brief Represents a C11 generic selection. 3963f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// 3964ffbe9b9c64ab2e94b9d48ec56e511f75826fc80aBenjamin Kramer/// A generic selection (C11 6.5.1.1) contains an unevaluated controlling 3965f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// expression, followed by one or more generic associations. Each generic 3966f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// association specifies a type name and an expression, or "default" and an 3967f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// expression (in which case it is known as a default generic association). 3968f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// The type and value of the generic selection are identical to those of its 3969f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// result expression, which is defined as the expression in the generic 3970f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// association with a type name that is compatible with the type of the 3971f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// controlling expression, or the expression in the default generic association 3972f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// if no types are compatible. For example: 3973f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// 3974f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// @code 3975f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// _Generic(X, double: 1, float: 2, default: 3) 3976f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// @endcode 3977f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// 3978f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// The above expression evaluates to 1 if 1.0 is substituted for X, 2 if 1.0f 3979f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// or 3 if "hello". 3980f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// 3981f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// As an extension, generic selections are allowed in C++, where the following 3982f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// additional semantics apply: 3983f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// 3984f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// Any generic selection whose controlling expression is type-dependent or 3985f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// which names a dependent type in its association list is result-dependent, 3986f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// which means that the choice of result expression is dependent. 3987f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// Result-dependent generic associations are both type- and value-dependent. 3988f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourneclass GenericSelectionExpr : public Expr { 3989f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne enum { CONTROLLING, END_EXPR }; 3990f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo **AssocTypes; 3991f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Stmt **SubExprs; 3992f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned NumAssocs, ResultIndex; 3993f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation GenericLoc, DefaultLoc, RParenLoc; 3994f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3995f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbournepublic: 3996f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne GenericSelectionExpr(ASTContext &Context, 3997f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation GenericLoc, Expr *ControllingExpr, 3998f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo **AssocTypes, Expr **AssocExprs, 3999f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned NumAssocs, SourceLocation DefaultLoc, 4000f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation RParenLoc, 4001f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne bool ContainsUnexpandedParameterPack, 4002f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned ResultIndex); 4003f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4004f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// This constructor is used in the result-dependent case. 4005f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne GenericSelectionExpr(ASTContext &Context, 4006f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation GenericLoc, Expr *ControllingExpr, 4007f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo **AssocTypes, Expr **AssocExprs, 4008f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned NumAssocs, SourceLocation DefaultLoc, 4009f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation RParenLoc, 4010f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne bool ContainsUnexpandedParameterPack); 4011f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4012f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne explicit GenericSelectionExpr(EmptyShell Empty) 4013f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne : Expr(GenericSelectionExprClass, Empty) { } 4014f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4015f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned getNumAssocs() const { return NumAssocs; } 4016f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4017f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation getGenericLoc() const { return GenericLoc; } 4018f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation getDefaultLoc() const { return DefaultLoc; } 4019f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation getRParenLoc() const { return RParenLoc; } 4020f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4021f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const Expr *getAssocExpr(unsigned i) const { 4022f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<Expr>(SubExprs[END_EXPR+i]); 4023f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 4024f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Expr *getAssocExpr(unsigned i) { return cast<Expr>(SubExprs[END_EXPR+i]); } 4025f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4026f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const TypeSourceInfo *getAssocTypeSourceInfo(unsigned i) const { 4027f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return AssocTypes[i]; 4028f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 4029f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo *getAssocTypeSourceInfo(unsigned i) { return AssocTypes[i]; } 4030f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4031f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne QualType getAssocType(unsigned i) const { 4032f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (const TypeSourceInfo *TS = getAssocTypeSourceInfo(i)) 4033f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return TS->getType(); 4034f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne else 4035f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return QualType(); 4036f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 4037f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4038f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const Expr *getControllingExpr() const { 4039f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<Expr>(SubExprs[CONTROLLING]); 4040f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 4041f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Expr *getControllingExpr() { return cast<Expr>(SubExprs[CONTROLLING]); } 4042f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4043f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// Whether this generic selection is result-dependent. 4044f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne bool isResultDependent() const { return ResultIndex == -1U; } 4045f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4046f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// The zero-based index of the result expression's generic association in 4047f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// the generic selection's association list. Defined only if the 4048f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// generic selection is not result-dependent. 4049f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned getResultIndex() const { 4050f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne assert(!isResultDependent() && "Generic selection is result-dependent"); 4051f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return ResultIndex; 4052f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 4053f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4054f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// The generic selection's result expression. Defined only if the 4055f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// generic selection is not result-dependent. 4056f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const Expr *getResultExpr() const { return getAssocExpr(getResultIndex()); } 4057f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Expr *getResultExpr() { return getAssocExpr(getResultIndex()); } 4058f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4059f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceRange getSourceRange() const { 4060f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return SourceRange(GenericLoc, RParenLoc); 4061f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 4062f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne static bool classof(const Stmt *T) { 4063f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return T->getStmtClass() == GenericSelectionExprClass; 4064f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 4065f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne static bool classof(const GenericSelectionExpr *) { return true; } 4066f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4067f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne child_range children() { 4068f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return child_range(SubExprs, SubExprs+END_EXPR+NumAssocs); 4069f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 4070f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 4071f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne friend class ASTStmtReader; 4072f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne}; 4073f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 40744eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===// 40754eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff// Clang Extensions 40764eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===// 40774eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 4078a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 4079a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// ExtVectorElementExpr - This represents access to specific elements of a 4080a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// vector, and may occur on the left hand side or right hand side. For example 4081a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// the following is legal: "V.xy = V.zw" if V is a 4 element extended vector. 4082a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// 408373525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// Note that the base may have either vector or pointer to vector type, just 408473525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// like a struct field reference. 408573525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// 4086a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerclass ExtVectorElementExpr : public Expr { 4087a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner Stmt *Base; 4088d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor IdentifierInfo *Accessor; 4089a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner SourceLocation AccessorLoc; 4090a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerpublic: 4091f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExtVectorElementExpr(QualType ty, ExprValueKind VK, Expr *base, 4092f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall IdentifierInfo &accessor, SourceLocation loc) 40930943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall : Expr(ExtVectorElementExprClass, ty, VK, 40940943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall (VK == VK_RValue ? OK_Ordinary : OK_VectorComponent), 4095bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->isTypeDependent(), base->isValueDependent(), 4096561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor base->isInstantiationDependent(), 4097bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->containsUnexpandedParameterPack()), 4098d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor Base(base), Accessor(&accessor), AccessorLoc(loc) {} 40991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4100d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor /// \brief Build an empty vector element expression. 4101d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor explicit ExtVectorElementExpr(EmptyShell Empty) 4102d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor : Expr(ExtVectorElementExprClass, Empty) { } 4103d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 4104a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner const Expr *getBase() const { return cast<Expr>(Base); } 4105a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner Expr *getBase() { return cast<Expr>(Base); } 4106d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setBase(Expr *E) { Base = E; } 4107d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 4108d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor IdentifierInfo &getAccessor() const { return *Accessor; } 4109d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setAccessor(IdentifierInfo *II) { Accessor = II; } 4110d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 4111d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getAccessorLoc() const { return AccessorLoc; } 4112d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setAccessorLoc(SourceLocation L) { AccessorLoc = L; } 4113d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 4114a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// getNumElements - Get the number of components being selected. 4115a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner unsigned getNumElements() const; 41161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4117a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// containsDuplicateElements - Return true if any element access is 4118a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// repeated. 4119a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner bool containsDuplicateElements() const; 41201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4121a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// getEncodedElementAccess - Encode the elements accessed into an llvm 4122a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// aggregate Constant of ConstantInt(s). 4123686775deca8b8685eb90801495880e3abdd844c2Chris Lattner void getEncodedElementAccess(SmallVectorImpl<unsigned> &Elts) const; 41241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 412563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 4126a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner return SourceRange(getBase()->getLocStart(), AccessorLoc); 4127a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner } 41281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 41292140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner /// isArrow - Return true if the base expression is a pointer to vector, 41302140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner /// return false if the base expression is a vector. 41312140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner bool isArrow() const; 41321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 41331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 41341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ExtVectorElementExprClass; 4135a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner } 4136a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner static bool classof(const ExtVectorElementExpr *) { return true; } 41371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4138a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner // Iterators 413963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Base, &Base+1); } 4140a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner}; 4141a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 4142a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 414356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff/// BlockExpr - Adaptor class for mixing a BlockDecl with expressions. 41449c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff/// ^{ statement-body } or ^(int arg1, float arg2){ statement-body } 41454eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockExpr : public Expr { 414656ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroffprotected: 414756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff BlockDecl *TheBlock; 41484eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic: 4149469a1eb996e1cb0be54f9b210f836afbddcbb2ccJohn McCall BlockExpr(BlockDecl *BD, QualType ty) 4150f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(BlockExprClass, ty, VK_RValue, OK_Ordinary, 4151ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie ty->isDependentType(), false, 4152561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor // FIXME: Check for instantiate-dependence in the statement? 4153561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ty->isInstantiationDependentType(), 4154561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false), 4155469a1eb996e1cb0be54f9b210f836afbddcbb2ccJohn McCall TheBlock(BD) {} 41569c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 415784af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor /// \brief Build an empty block expression. 415884af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor explicit BlockExpr(EmptyShell Empty) : Expr(BlockExprClass, Empty) { } 415984af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor 4160d5cab5435371b8cc74a9e05ebd40b5995ebad149Anders Carlsson const BlockDecl *getBlockDecl() const { return TheBlock; } 416156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff BlockDecl *getBlockDecl() { return TheBlock; } 416284af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor void setBlockDecl(BlockDecl *BD) { TheBlock = BD; } 416384af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor 416456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff // Convenience functions for probing the underlying BlockDecl. 416556ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff SourceLocation getCaretLocation() const; 416656ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff const Stmt *getBody() const; 416756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff Stmt *getBody(); 41689c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 416963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 417056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff return SourceRange(getCaretLocation(), getBody()->getLocEnd()); 41719c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff } 41729c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 417356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff /// getFunctionType - Return the underlying function type for this block. 417456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff const FunctionType *getFunctionType() const; 417556ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 41761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 41779c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff return T->getStmtClass() == BlockExprClass; 41784eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff } 41794eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff static bool classof(const BlockExpr *) { return true; } 41801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 41814eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff // Iterators 418263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 41834eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff}; 41841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 41856b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall/// BlockDeclRefExpr - A reference to a local variable declared in an 41866b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall/// enclosing scope. 41874eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockDeclRefExpr : public Expr { 41886b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall VarDecl *D; 41894eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff SourceLocation Loc; 41907d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool IsByRef : 1; 41917d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool ConstQualAdded : 1; 41924eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic: 41936b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall BlockDeclRefExpr(VarDecl *d, QualType t, ExprValueKind VK, 41946b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall SourceLocation l, bool ByRef, bool constAdded = false); 419594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 419694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor // \brief Build an empty reference to a declared variable in a 419794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor // block. 419894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor explicit BlockDeclRefExpr(EmptyShell Empty) 419994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor : Expr(BlockDeclRefExprClass, Empty) { } 42001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42016b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall VarDecl *getDecl() { return D; } 42026b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall const VarDecl *getDecl() const { return D; } 42036b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall void setDecl(VarDecl *VD) { D = VD; } 420494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 420594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getLocation() const { return Loc; } 420694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setLocation(SourceLocation L) { Loc = L; } 420794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 420863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 42091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42104eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff bool isByRef() const { return IsByRef; } 421194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setByRef(bool BR) { IsByRef = BR; } 42121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42137d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool isConstQualAdded() const { return ConstQualAdded; } 42147d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian void setConstQualAdded(bool C) { ConstQualAdded = C; } 4215ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 42161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 42171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == BlockDeclRefExprClass; 42184eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff } 42194eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff static bool classof(const BlockDeclRefExpr *) { return true; } 42201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42214eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff // Iterators 422263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 42234eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff}; 42244eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 422561eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner/// AsTypeExpr - Clang builtin function __builtin_astype [OpenCL 6.2.4.2] 422661eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner/// This AST node provides support for reinterpreting a type to another 422761eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner/// type of the same size. 4228379010addb0e84fd0fbc37c829baf658958521bdJohn McCallclass AsTypeExpr : public Expr { // Should this be an ExplicitCastExpr? 422961eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattnerprivate: 4230379010addb0e84fd0fbc37c829baf658958521bdJohn McCall Stmt *SrcExpr; 423161eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner SourceLocation BuiltinLoc, RParenLoc; 4232379010addb0e84fd0fbc37c829baf658958521bdJohn McCall 4233379010addb0e84fd0fbc37c829baf658958521bdJohn McCall friend class ASTReader; 4234379010addb0e84fd0fbc37c829baf658958521bdJohn McCall friend class ASTStmtReader; 4235379010addb0e84fd0fbc37c829baf658958521bdJohn McCall explicit AsTypeExpr(EmptyShell Empty) : Expr(AsTypeExprClass, Empty) {} 4236ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 423761eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattnerpublic: 423861eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner AsTypeExpr(Expr* SrcExpr, QualType DstType, 423961eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner ExprValueKind VK, ExprObjectKind OK, 424061eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner SourceLocation BuiltinLoc, SourceLocation RParenLoc) 4241ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie : Expr(AsTypeExprClass, DstType, VK, OK, 4242561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor DstType->isDependentType(), 4243561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor DstType->isDependentType() || SrcExpr->isValueDependent(), 4244561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (DstType->isInstantiationDependentType() || 4245561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor SrcExpr->isInstantiationDependent()), 4246561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (DstType->containsUnexpandedParameterPack() || 4247561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor SrcExpr->containsUnexpandedParameterPack())), 4248379010addb0e84fd0fbc37c829baf658958521bdJohn McCall SrcExpr(SrcExpr), BuiltinLoc(BuiltinLoc), RParenLoc(RParenLoc) {} 4249ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 425061eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner /// getSrcExpr - Return the Expr to be converted. 4251379010addb0e84fd0fbc37c829baf658958521bdJohn McCall Expr *getSrcExpr() const { return cast<Expr>(SrcExpr); } 4252379010addb0e84fd0fbc37c829baf658958521bdJohn McCall 4253379010addb0e84fd0fbc37c829baf658958521bdJohn McCall /// getBuiltinLoc - Return the location of the __builtin_astype token. 4254379010addb0e84fd0fbc37c829baf658958521bdJohn McCall SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 4255379010addb0e84fd0fbc37c829baf658958521bdJohn McCall 4256379010addb0e84fd0fbc37c829baf658958521bdJohn McCall /// getRParenLoc - Return the location of final right parenthesis. 4257379010addb0e84fd0fbc37c829baf658958521bdJohn McCall SourceLocation getRParenLoc() const { return RParenLoc; } 4258ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 42597b33c2b3908b178511ccaace8cacb5e5b14552a9Nick Lewycky SourceRange getSourceRange() const { 426061eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner return SourceRange(BuiltinLoc, RParenLoc); 426161eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner } 4262ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 426361eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner static bool classof(const Stmt *T) { 4264ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return T->getStmtClass() == AsTypeExprClass; 426561eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner } 426661eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner static bool classof(const AsTypeExpr *) { return true; } 4267ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie 426861eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner // Iterators 4269379010addb0e84fd0fbc37c829baf658958521bdJohn McCall child_range children() { return child_range(&SrcExpr, &SrcExpr+1); } 427061eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner}; 4271276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 42724b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// PseudoObjectExpr - An expression which accesses a pseudo-object 42734b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// l-value. A pseudo-object is an abstract object, accesses to which 42744b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// are translated to calls. The pseudo-object expression has a 42754b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// syntactic form, which shows how the expression was actually 42764b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// written in the source code, and a semantic form, which is a series 42774b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// of expressions to be executed in order which detail how the 42784b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// operation is actually evaluated. Optionally, one of the semantic 42794b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// forms may also provide a result value for the expression. 42804b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// 42814b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// If any of the semantic-form expressions is an OpaqueValueExpr, 42824b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// that OVE is required to have a source expression, and it is bound 42834b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// to the result of that source expression. Such OVEs may appear 42844b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// only in subsequent semantic-form expressions and as 42854b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// sub-expressions of the syntactic form. 42864b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// 42874b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// PseudoObjectExpr should be used only when an operation can be 42884b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// usefully described in terms of fairly simple rewrite rules on 42894b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// objects and functions that are meant to be used by end-developers. 42904b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// For example, under the Itanium ABI, dynamic casts are implemented 42914b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// as a call to a runtime function called __dynamic_cast; using this 42924b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// class to describe that would be inappropriate because that call is 42934b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// not really part of the user-visible semantics, and instead the 42944b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// cast is properly reflected in the AST and IR-generation has been 42954b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// taught to generate the call as necessary. In contrast, an 42964b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// Objective-C property access is semantically defined to be 42974b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// equivalent to a particular message send, and this is very much 42984b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// part of the user model. The name of this class encourages this 42994b9c2d235fb9449e249d74f48ecfec601650de93John McCall/// modelling design. 43004b9c2d235fb9449e249d74f48ecfec601650de93John McCallclass PseudoObjectExpr : public Expr { 43014b9c2d235fb9449e249d74f48ecfec601650de93John McCall // PseudoObjectExprBits.NumSubExprs - The number of sub-expressions. 43024b9c2d235fb9449e249d74f48ecfec601650de93John McCall // Always at least two, because the first sub-expression is the 43034b9c2d235fb9449e249d74f48ecfec601650de93John McCall // syntactic form. 43044b9c2d235fb9449e249d74f48ecfec601650de93John McCall 43054b9c2d235fb9449e249d74f48ecfec601650de93John McCall // PseudoObjectExprBits.ResultIndex - The index of the 43064b9c2d235fb9449e249d74f48ecfec601650de93John McCall // sub-expression holding the result. 0 means the result is void, 43074b9c2d235fb9449e249d74f48ecfec601650de93John McCall // which is unambiguous because it's the index of the syntactic 43084b9c2d235fb9449e249d74f48ecfec601650de93John McCall // form. Note that this is therefore 1 higher than the value passed 43094b9c2d235fb9449e249d74f48ecfec601650de93John McCall // in to Create, which is an index within the semantic forms. 43104b9c2d235fb9449e249d74f48ecfec601650de93John McCall // Note also that ASTStmtWriter assumes this encoding. 43114b9c2d235fb9449e249d74f48ecfec601650de93John McCall 43124b9c2d235fb9449e249d74f48ecfec601650de93John McCall Expr **getSubExprsBuffer() { return reinterpret_cast<Expr**>(this + 1); } 43134b9c2d235fb9449e249d74f48ecfec601650de93John McCall const Expr * const *getSubExprsBuffer() const { 43144b9c2d235fb9449e249d74f48ecfec601650de93John McCall return reinterpret_cast<const Expr * const *>(this + 1); 43154b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 43164b9c2d235fb9449e249d74f48ecfec601650de93John McCall 43174b9c2d235fb9449e249d74f48ecfec601650de93John McCall friend class ASTStmtReader; 43184b9c2d235fb9449e249d74f48ecfec601650de93John McCall 43194b9c2d235fb9449e249d74f48ecfec601650de93John McCall PseudoObjectExpr(QualType type, ExprValueKind VK, 43204b9c2d235fb9449e249d74f48ecfec601650de93John McCall Expr *syntactic, ArrayRef<Expr*> semantic, 43214b9c2d235fb9449e249d74f48ecfec601650de93John McCall unsigned resultIndex); 43224b9c2d235fb9449e249d74f48ecfec601650de93John McCall 43234b9c2d235fb9449e249d74f48ecfec601650de93John McCall PseudoObjectExpr(EmptyShell shell, unsigned numSemanticExprs); 43244b9c2d235fb9449e249d74f48ecfec601650de93John McCall 43254b9c2d235fb9449e249d74f48ecfec601650de93John McCall unsigned getNumSubExprs() const { 43264b9c2d235fb9449e249d74f48ecfec601650de93John McCall return PseudoObjectExprBits.NumSubExprs; 43274b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 43284b9c2d235fb9449e249d74f48ecfec601650de93John McCall 43294b9c2d235fb9449e249d74f48ecfec601650de93John McCallpublic: 43304b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// NoResult - A value for the result index indicating that there is 43314b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// no semantic result. 43324b9c2d235fb9449e249d74f48ecfec601650de93John McCall enum { NoResult = ~0U }; 43334b9c2d235fb9449e249d74f48ecfec601650de93John McCall 43344b9c2d235fb9449e249d74f48ecfec601650de93John McCall static PseudoObjectExpr *Create(ASTContext &Context, Expr *syntactic, 43354b9c2d235fb9449e249d74f48ecfec601650de93John McCall ArrayRef<Expr*> semantic, 43364b9c2d235fb9449e249d74f48ecfec601650de93John McCall unsigned resultIndex); 43374b9c2d235fb9449e249d74f48ecfec601650de93John McCall 43384b9c2d235fb9449e249d74f48ecfec601650de93John McCall static PseudoObjectExpr *Create(ASTContext &Context, EmptyShell shell, 43394b9c2d235fb9449e249d74f48ecfec601650de93John McCall unsigned numSemanticExprs); 43404b9c2d235fb9449e249d74f48ecfec601650de93John McCall 43414b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// Return the syntactic form of this expression, i.e. the 43424b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// expression it actually looks like. Likely to be expressed in 43434b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// terms of OpaqueValueExprs bound in the semantic form. 43444b9c2d235fb9449e249d74f48ecfec601650de93John McCall Expr *getSyntacticForm() { return getSubExprsBuffer()[0]; } 43454b9c2d235fb9449e249d74f48ecfec601650de93John McCall const Expr *getSyntacticForm() const { return getSubExprsBuffer()[0]; } 43464b9c2d235fb9449e249d74f48ecfec601650de93John McCall 43474b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// Return the index of the result-bearing expression into the semantics 43484b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// expressions, or PseudoObjectExpr::NoResult if there is none. 43494b9c2d235fb9449e249d74f48ecfec601650de93John McCall unsigned getResultExprIndex() const { 43504b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (PseudoObjectExprBits.ResultIndex == 0) return NoResult; 43514b9c2d235fb9449e249d74f48ecfec601650de93John McCall return PseudoObjectExprBits.ResultIndex - 1; 43524b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 43534b9c2d235fb9449e249d74f48ecfec601650de93John McCall 43544b9c2d235fb9449e249d74f48ecfec601650de93John McCall /// Return the result-bearing expression, or null if there is none. 43554b9c2d235fb9449e249d74f48ecfec601650de93John McCall Expr *getResultExpr() { 43564b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (PseudoObjectExprBits.ResultIndex == 0) 43574b9c2d235fb9449e249d74f48ecfec601650de93John McCall return 0; 43584b9c2d235fb9449e249d74f48ecfec601650de93John McCall return getSubExprsBuffer()[PseudoObjectExprBits.ResultIndex]; 43594b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 43604b9c2d235fb9449e249d74f48ecfec601650de93John McCall const Expr *getResultExpr() const { 43614b9c2d235fb9449e249d74f48ecfec601650de93John McCall return const_cast<PseudoObjectExpr*>(this)->getResultExpr(); 43624b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 43634b9c2d235fb9449e249d74f48ecfec601650de93John McCall 43644b9c2d235fb9449e249d74f48ecfec601650de93John McCall unsigned getNumSemanticExprs() const { return getNumSubExprs() - 1; } 43654b9c2d235fb9449e249d74f48ecfec601650de93John McCall 43664b9c2d235fb9449e249d74f48ecfec601650de93John McCall typedef Expr * const *semantics_iterator; 43674b9c2d235fb9449e249d74f48ecfec601650de93John McCall typedef const Expr * const *const_semantics_iterator; 43684b9c2d235fb9449e249d74f48ecfec601650de93John McCall semantics_iterator semantics_begin() { 43694b9c2d235fb9449e249d74f48ecfec601650de93John McCall return getSubExprsBuffer() + 1; 43704b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 43714b9c2d235fb9449e249d74f48ecfec601650de93John McCall const_semantics_iterator semantics_begin() const { 43724b9c2d235fb9449e249d74f48ecfec601650de93John McCall return getSubExprsBuffer() + 1; 43734b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 43744b9c2d235fb9449e249d74f48ecfec601650de93John McCall semantics_iterator semantics_end() { 43754b9c2d235fb9449e249d74f48ecfec601650de93John McCall return getSubExprsBuffer() + getNumSubExprs(); 43764b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 43774b9c2d235fb9449e249d74f48ecfec601650de93John McCall const_semantics_iterator semantics_end() const { 43784b9c2d235fb9449e249d74f48ecfec601650de93John McCall return getSubExprsBuffer() + getNumSubExprs(); 43794b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 43804b9c2d235fb9449e249d74f48ecfec601650de93John McCall Expr *getSemanticExpr(unsigned index) { 43814b9c2d235fb9449e249d74f48ecfec601650de93John McCall assert(index + 1 < getNumSubExprs()); 43824b9c2d235fb9449e249d74f48ecfec601650de93John McCall return getSubExprsBuffer()[index + 1]; 43834b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 43844b9c2d235fb9449e249d74f48ecfec601650de93John McCall const Expr *getSemanticExpr(unsigned index) const { 43854b9c2d235fb9449e249d74f48ecfec601650de93John McCall return const_cast<PseudoObjectExpr*>(this)->getSemanticExpr(index); 43864b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 43874b9c2d235fb9449e249d74f48ecfec601650de93John McCall 43884b9c2d235fb9449e249d74f48ecfec601650de93John McCall SourceLocation getExprLoc() const { 43894b9c2d235fb9449e249d74f48ecfec601650de93John McCall return getSyntacticForm()->getExprLoc(); 43904b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 43914b9c2d235fb9449e249d74f48ecfec601650de93John McCall SourceRange getSourceRange() const { 43924b9c2d235fb9449e249d74f48ecfec601650de93John McCall return getSyntacticForm()->getSourceRange(); 43934b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 43944b9c2d235fb9449e249d74f48ecfec601650de93John McCall 43954b9c2d235fb9449e249d74f48ecfec601650de93John McCall child_range children() { 43964b9c2d235fb9449e249d74f48ecfec601650de93John McCall Stmt **cs = reinterpret_cast<Stmt**>(getSubExprsBuffer()); 43974b9c2d235fb9449e249d74f48ecfec601650de93John McCall return child_range(cs, cs + getNumSubExprs()); 43984b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 43994b9c2d235fb9449e249d74f48ecfec601650de93John McCall 44004b9c2d235fb9449e249d74f48ecfec601650de93John McCall static bool classof(const Stmt *T) { 44014b9c2d235fb9449e249d74f48ecfec601650de93John McCall return T->getStmtClass() == PseudoObjectExprClass; 44024b9c2d235fb9449e249d74f48ecfec601650de93John McCall } 44034b9c2d235fb9449e249d74f48ecfec601650de93John McCall static bool classof(const PseudoObjectExpr *) { return true; } 44044b9c2d235fb9449e249d74f48ecfec601650de93John McCall}; 44054b9c2d235fb9449e249d74f48ecfec601650de93John McCall 4406276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman/// AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, 4407276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman/// __atomic_load, __atomic_store, and __atomic_compare_exchange_*, for the 4408276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman/// similarly-named C++0x instructions. All of these instructions take one 4409276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman/// primary pointer and at least one memory order. 4410276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedmanclass AtomicExpr : public Expr { 4411276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedmanpublic: 4412276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman enum AtomicOp { Load, Store, CmpXchgStrong, CmpXchgWeak, Xchg, 4413276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman Add, Sub, And, Or, Xor }; 4414276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedmanprivate: 4415276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman enum { PTR, ORDER, VAL1, ORDER_FAIL, VAL2, END_EXPR }; 4416276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman Stmt* SubExprs[END_EXPR]; 4417276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman unsigned NumSubExprs; 4418276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman SourceLocation BuiltinLoc, RParenLoc; 4419276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman AtomicOp Op; 4420276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4421276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedmanpublic: 4422dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman AtomicExpr(SourceLocation BLoc, Expr **args, unsigned nexpr, QualType t, 4423dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman AtomicOp op, SourceLocation RP); 4424276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4425276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman /// \brief Build an empty AtomicExpr. 4426276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman explicit AtomicExpr(EmptyShell Empty) : Expr(AtomicExprClass, Empty) { } 4427276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4428276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman Expr *getPtr() const { 4429276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return cast<Expr>(SubExprs[PTR]); 4430276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4431276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman void setPtr(Expr *E) { 4432276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman SubExprs[PTR] = E; 4433276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4434276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman Expr *getOrder() const { 4435276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return cast<Expr>(SubExprs[ORDER]); 4436276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4437276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman void setOrder(Expr *E) { 4438276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman SubExprs[ORDER] = E; 4439276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4440276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman Expr *getVal1() const { 4441276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman assert(NumSubExprs >= 3); 4442276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return cast<Expr>(SubExprs[VAL1]); 4443276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4444276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman void setVal1(Expr *E) { 4445276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman assert(NumSubExprs >= 3); 4446276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman SubExprs[VAL1] = E; 4447276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4448276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman Expr *getOrderFail() const { 4449276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman assert(NumSubExprs == 5); 4450276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return cast<Expr>(SubExprs[ORDER_FAIL]); 4451276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4452276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman void setOrderFail(Expr *E) { 4453276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman assert(NumSubExprs == 5); 4454276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman SubExprs[ORDER_FAIL] = E; 4455276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4456276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman Expr *getVal2() const { 4457276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman assert(NumSubExprs == 5); 4458276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return cast<Expr>(SubExprs[VAL2]); 4459276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4460276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman void setVal2(Expr *E) { 4461276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman assert(NumSubExprs == 5); 4462276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman SubExprs[VAL2] = E; 4463276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4464276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4465276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman AtomicOp getOp() const { return Op; } 4466276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman void setOp(AtomicOp op) { Op = op; } 4467276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman unsigned getNumSubExprs() { return NumSubExprs; } 4468276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman void setNumSubExprs(unsigned num) { NumSubExprs = num; } 4469276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4470dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman Expr **getSubExprs() { return reinterpret_cast<Expr **>(SubExprs); } 4471dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman 4472276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman bool isVolatile() const { 4473276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return getPtr()->getType()->getPointeeType().isVolatileQualified(); 4474276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4475276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4476276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman bool isCmpXChg() const { 4477276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return getOp() == AtomicExpr::CmpXchgStrong || 4478276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman getOp() == AtomicExpr::CmpXchgWeak; 4479276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4480276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4481276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 4482276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 4483276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4484276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman SourceLocation getRParenLoc() const { return RParenLoc; } 4485276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman void setRParenLoc(SourceLocation L) { RParenLoc = L; } 4486276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4487276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman SourceRange getSourceRange() const { 4488276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return SourceRange(BuiltinLoc, RParenLoc); 4489276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4490276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman static bool classof(const Stmt *T) { 4491276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return T->getStmtClass() == AtomicExprClass; 4492276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4493276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman static bool classof(const AtomicExpr *) { return true; } 4494276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 4495276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman // Iterators 4496276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman child_range children() { 4497276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman return child_range(SubExprs, SubExprs+NumSubExprs); 4498276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman } 4499276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman}; 45005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 45015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 45025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 4503