Expr.h revision 71a7605977113c795edd44fcbd2302ad49506653
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- Expr.h - Classes for representing expressions ----------*- C++ -*-===// 25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// The LLVM Compiler Infrastructure 45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source 60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details. 75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// This file defines the Expr interface and subclasses. 115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#ifndef LLVM_CLANG_AST_EXPR_H 155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#define LLVM_CLANG_AST_EXPR_H 165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson#include "clang/AST/APValue.h" 185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Stmt.h" 195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/Type.h" 20161755a09898c95d21bfff33707da9ca41cd53c5John McCall#include "clang/AST/DeclAccessPair.h" 215baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall#include "clang/AST/OperationKinds.h" 22709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek#include "clang/AST/ASTVector.h" 2371a7605977113c795edd44fcbd2302ad49506653Argyrios Kyrtzidis#include "clang/AST/TemplateBase.h" 24409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson#include "clang/AST/UsuallyTinyPtrVector.h" 25f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne#include "clang/Basic/TypeTraits.h" 265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/APSInt.h" 27525a05093a4816af961fe2bc6b8a81c17e2e26c2Chris Lattner#include "llvm/ADT/APFloat.h" 283b8d116703db8018f855cbb4733ace426422623bNate Begeman#include "llvm/ADT/SmallVector.h" 29b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar#include "llvm/ADT/StringRef.h" 30403ba3522d1b1c97ae5fad81c1a2c4b3a754e1c1Nick Lewycky#include <cctype> 315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 33590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner class ASTContext; 34c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson class APValue; 35c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class Decl; 36c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class IdentifierInfo; 37c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class ParmVarDecl; 388e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor class NamedDecl; 39c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class ValueDecl; 4056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff class BlockDecl; 41409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson class CXXBaseSpecifier; 4288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor class CXXOperatorCallExpr; 4388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor class CXXMemberCallExpr; 44f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall class ObjCPropertyRefExpr; 4556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall class OpaqueValueExpr; 4688a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 477ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson/// \brief A simple array of base specifiers. 48686775deca8b8685eb90801495880e3abdd844c2Chris Lattnertypedef SmallVector<CXXBaseSpecifier*, 4> CXXCastPath; 497ab9d574d27ecee1f130e5755aa403e5ab529b6bAnders Carlsson 505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Expr - This represents one expression. Note that Expr's are subclasses of 515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Stmt. This allows an expression to be transparently used any place a Stmt 525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is required. 535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Expr : public Stmt { 555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType TR; 56898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 578e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCallprotected: 58f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(StmtClass SC, QualType T, ExprValueKind VK, ExprObjectKind OK, 59561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool TD, bool VD, bool ID, bool ContainsUnexpandedParameterPack) 60561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Stmt(SC) 61561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor { 628e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.TypeDependent = TD; 638e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall ExprBits.ValueDependent = VD; 64561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = ID; 65f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprBits.ValueKind = VK; 66f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprBits.ObjectKind = OK; 67bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack; 68898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor setType(T); 69898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 70898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 710b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Construct an empty expression. 720b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor explicit Expr(StmtClass SC, EmptyShell) : Stmt(SC) { } 730b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 75f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor QualType getType() const { return TR; } 761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setType(QualType t) { 779d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // In C++, the type of an expression is always adjusted so that it 789d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // will not have reference type an expression will never have 799d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // reference type (C++ [expr]p6). Use 809d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // QualType::getNonReferenceType() to retrieve the non-reference 819d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // type. Additionally, inspect Expr::isLvalue to determine whether 829d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // an expression that is adjusted in this manner should be 839d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // considered an lvalue. 84905d11d53aeb6b26744f44fedc2b2820c7a62df6Douglas Gregor assert((t.isNull() || !t->isReferenceType()) && 858320aaaa01d931aa234fc3bce05b399ef41898d5Daniel Dunbar "Expressions can't have reference type"); 86f7c2aa0b049272d8f318988c1965760dcb852578Douglas Gregor 871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TR = t; 889d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor } 8977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 90898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isValueDependent - Determines whether this expression is 91898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// value-dependent (C++ [temp.dep.constexpr]). For example, the 92898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// array bound of "Chars" in the following example is 931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// value-dependent. 94898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @code 95898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// template<int Size, char (&Chars)[Size]> struct meta_string; 96898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @endcode 978e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall bool isValueDependent() const { return ExprBits.ValueDependent; } 98898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 990b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Set whether this expression is value-dependent or not. 100561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor void setValueDependent(bool VD) { 101561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.ValueDependent = VD; 102561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (VD) 103561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 104561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 1050b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 106898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isTypeDependent - Determines whether this expression is 107898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// type-dependent (C++ [temp.dep.expr]), which means that its type 108898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// could change from one template instantiation to the next. For 109898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// example, the expressions "x" and "x + y" are type-dependent in 110898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// the following code, but "y" is not type-dependent: 111898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @code 1121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// template<typename T> 113898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// void add(T x, int y) { 114898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// x + y; 115898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// } 116898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// @endcode 1178e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall bool isTypeDependent() const { return ExprBits.TypeDependent; } 118898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1190b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Set whether this expression is type-dependent or not. 120561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor void setTypeDependent(bool TD) { 121561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.TypeDependent = TD; 122561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (TD) 123561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = true; 124561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 125561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 126561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// \brief Whether this expression is instantiation-dependent, meaning that 127561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// it depends in some way on a template parameter, even if neither its type 128561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// nor (constant) value can change due to the template instantiation. 129561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// 130561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// In the following example, the expression \c sizeof(sizeof(T() + T())) is 131561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// instantiation-dependent (since it involves a template parameter \c T), but 132561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// is neither type- nor value-dependent, since the type of the inner 133561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// \c sizeof is known (\c std::size_t) and therefore the size of the outer 134561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// \c sizeof is known. 135561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// 136561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// \code 137561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// template<typename T> 138561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// void f(T x, T y) { 139561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// sizeof(sizeof(T() + T()); 140561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// } 141561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// \endcode 142561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// 143561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool isInstantiationDependent() const { 144561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor return ExprBits.InstantiationDependent; 145561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 146561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 147561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor /// \brief Set whether this expression is instantiation-dependent or not. 148561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor void setInstantiationDependent(bool ID) { 149561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ExprBits.InstantiationDependent = ID; 150561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor } 1510b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 152d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \brief Whether this expression contains an unexpanded parameter 153d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// pack (for C++0x variadic templates). 154d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// 155d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// Given the following function template: 156d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// 157d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \code 158d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// template<typename F, typename ...Types> 159d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// void forward(const F &f, Types &&...args) { 160d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// f(static_cast<Types&&>(args)...); 161d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// } 162d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// \endcode 163d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// 164d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// The expressions \c args and \c static_cast<Types&&>(args) both 165d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor /// contain parameter packs. 166d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor bool containsUnexpandedParameterPack() const { 167d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor return ExprBits.ContainsUnexpandedParameterPack; 168d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor } 169d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor 170bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /// \brief Set the bit that describes whether this expression 171bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /// contains an unexpanded parameter pack. 172bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor void setContainsUnexpandedParameterPack(bool PP = true) { 173bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ExprBits.ContainsUnexpandedParameterPack = PP; 174bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor } 175bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor 1765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getExprLoc - Return the preferred location for the arrow when diagnosing 1775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// a problem with a generic expression. 17863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation getExprLoc() const; 1791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 180026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// isUnusedResultAWarning - Return true if this immediate expression should 181026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// be warned about if the result is unused. If so, fill in Loc and Ranges 182026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// with location to warn on and the source range[s] to report with the 183026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner /// warning. 184026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner bool isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1, 185df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump SourceRange &R2, ASTContext &Ctx) const; 1861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1877eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// isLValue - True if this expression is an "l-value" according to 1887eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// the rules of the current language. C and C++ give somewhat 1897eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// different rules for this concept, but in general, the result of 1907eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// an l-value expression identifies a specific object whereas the 1917eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// result of an r-value expression is a value detached from any 1927eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// specific storage. 1935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 1947eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// C++0x divides the concept of "r-value" into pure r-values 1957eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// ("pr-values") and so-called expiring values ("x-values"), which 1967eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// identify specific objects that can be safely cannibalized for 1977eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// their resources. This is an unfortunate abuse of terminology on 1987eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// the part of the C++ committee. In Clang, when we say "r-value", 1997eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// we generally mean a pr-value. 2007eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall bool isLValue() const { return getValueKind() == VK_LValue; } 2017eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall bool isRValue() const { return getValueKind() == VK_RValue; } 2027eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall bool isXValue() const { return getValueKind() == VK_XValue; } 2037eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall bool isGLValue() const { return getValueKind() != VK_RValue; } 2047eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall 2057eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall enum LValueClassification { 2065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_Valid, 2075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_NotObjectType, 2085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LV_IncompleteVoidType, 209fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff LV_DuplicateVectorComponents, 21086f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor LV_InvalidExpression, 211077f490d0a514dcc448475f33f799934252b85a7Fariborz Jahanian LV_InvalidMessageExpression, 2122514a309204341798f96912ce7a90841bea59727Fariborz Jahanian LV_MemberFunction, 213e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian LV_SubObjCPropertySetting, 214e873fb74219f48407ae0b8fa083aa7f0b6ff1427Douglas Gregor LV_ClassTemporary 2155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 2167eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall /// Reasons why an expression might not be an l-value. 2177eb0a9eb0cde8444b97f9c5b713d9be7a6f1e607John McCall LValueClassification ClassifyLValue(ASTContext &Ctx) const; 21853202857c60214d80950a975e6e52aebf30bd16aEli Friedman 2195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type, 2205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// does not have an incomplete type, does not have a const-qualified type, 2211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// and if it is a structure or union, does not have any member (including, 2225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// recursively, any member or element of all contained aggregates or unions) 2235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// with a const-qualified type. 22444e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// 22544e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// \param Loc [in] [out] - A source location which *may* be filled 22644e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// in with the location of the expression making this a 22744e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar /// non-modifiable lvalue, if specified. 2285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum isModifiableLvalueResult { 2295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_Valid, 2305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_NotObjectType, 2315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_IncompleteVoidType, 232fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff MLV_DuplicateVectorComponents, 2335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_InvalidExpression, 234ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner MLV_LValueCast, // Specialized form of MLV_InvalidExpression. 2355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_IncompleteType, 2365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer MLV_ConstQualified, 2374f6a7d7ead09b439216c32f2de806a998aeb222aSteve Naroff MLV_ArrayType, 2385daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian MLV_NotBlockQualified, 239ba8d2d684e74a20bef03828c21c991d222c7e9e5Fariborz Jahanian MLV_ReadonlyProperty, 24086f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor MLV_NoSetterProperty, 2412514a309204341798f96912ce7a90841bea59727Fariborz Jahanian MLV_MemberFunction, 242e9ff443040cb571ae2c5c2626c4dc9a9a812d84aFariborz Jahanian MLV_SubObjCPropertySetting, 243077f490d0a514dcc448475f33f799934252b85a7Fariborz Jahanian MLV_InvalidMessageExpression, 244e873fb74219f48407ae0b8fa083aa7f0b6ff1427Douglas Gregor MLV_ClassTemporary 2455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 24644e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx, 24744e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar SourceLocation *Loc = 0) const; 2481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2492111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \brief The return type of classify(). Represents the C++0x expression 2502111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// taxonomy. 2512111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl class Classification { 2522111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl public: 2532111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \brief The various classification results. Most of these mean prvalue. 2542111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl enum Kinds { 2552111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_LValue, 2562111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_XValue, 2572111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_Function, // Functions cannot be lvalues in C. 2582111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_Void, // Void cannot be an lvalue in C. 2591c860d5640e8eebb11a5d515a761242b66761b0bPeter Collingbourne CL_AddressableVoid, // Void expression whose address can be taken in C. 2602111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_DuplicateVectorComponents, // A vector shuffle with dupes. 2612111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_MemberFunction, // An expression referring to a member function 2622111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_SubObjCPropertySetting, 2632111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_ClassTemporary, // A prvalue of class type 264077f490d0a514dcc448475f33f799934252b85a7Fariborz Jahanian CL_ObjCMessageRValue, // ObjC message is an rvalue 2652111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CL_PRValue // A prvalue for any other reason, of any other type 2662111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl }; 2672111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \brief The results of modification testing. 2682111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl enum ModifiableType { 2692111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_Untested, // testModifiable was false. 2702111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_Modifiable, 2712111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_RValue, // Not modifiable because it's an rvalue 2722111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_Function, // Not modifiable because it's a function; C++ only 2732111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_LValueCast, // Same as CM_RValue, but indicates GCC cast-as-lvalue ext 2742111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_NotBlockQualified, // Not captured in the closure 2752111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_NoSetterProperty,// Implicit assignment to ObjC property without setter 2762111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_ConstQualified, 2772111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_ArrayType, 2782111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl CM_IncompleteType 2792111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl }; 2802111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2812111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl private: 2822111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl friend class Expr; 2832111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2842111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl unsigned short Kind; 2852111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl unsigned short Modifiable; 2862111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2872111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl explicit Classification(Kinds k, ModifiableType m) 2882111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl : Kind(k), Modifiable(m) 2892111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl {} 2902111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2912111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl public: 2922111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification() {} 2932111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 2942111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Kinds getKind() const { return static_cast<Kinds>(Kind); } 2952111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl ModifiableType getModifiable() const { 2962111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl assert(Modifiable != CM_Untested && "Did not test for modifiability."); 2972111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl return static_cast<ModifiableType>(Modifiable); 2982111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl } 2992111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isLValue() const { return Kind == CL_LValue; } 3002111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isXValue() const { return Kind == CL_XValue; } 3012111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isGLValue() const { return Kind <= CL_XValue; } 3022111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isPRValue() const { return Kind >= CL_Function; } 3032111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isRValue() const { return Kind >= CL_XValue; } 3042111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl bool isModifiable() const { return getModifiable() == CM_Modifiable; } 3052c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor 3062c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor /// \brief Create a simple, modifiably lvalue 3072c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor static Classification makeSimpleLValue() { 3082c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor return Classification(CL_LValue, CM_Modifiable); 3092c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor } 3102c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor 3112111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl }; 312369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// \brief Classify - Classify this expression according to the C++0x 3132111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// expression taxonomy. 3142111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// 3152111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// C++0x defines ([basic.lval]) a new taxonomy of expressions to replace the 3162111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// old lvalue vs rvalue. This function determines the type of expression this 3172111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// is. There are three expression types: 3182111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// - lvalues are classical lvalues as in C++03. 3192111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// - prvalues are equivalent to rvalues in C++03. 3202111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// - xvalues are expressions yielding unnamed rvalue references, e.g. a 3212111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// function returning an rvalue reference. 3222111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// lvalues and xvalues are collectively referred to as glvalues, while 3232111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// prvalues and xvalues together form rvalues. 3242111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification Classify(ASTContext &Ctx) const { 3252111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl return ClassifyImpl(Ctx, 0); 3262111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl } 3272111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 328369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// \brief ClassifyModifiable - Classify this expression according to the 3292111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// C++0x expression taxonomy, and see if it is valid on the left side 3302111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// of an assignment. 3312111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// 3322111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// This function extends classify in that it also tests whether the 3332111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// expression is modifiable (C99 6.3.2.1p1). 3342111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// \param Loc A source location that might be filled with a relevant location 3352111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl /// if the expression is not modifiable. 3362111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification ClassifyModifiable(ASTContext &Ctx, SourceLocation &Loc) const{ 3372111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl return ClassifyImpl(Ctx, &Loc); 3382111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl } 3392111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 340f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// getValueKindForType - Given a formal return or parameter type, 341f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// give its value kind. 342f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall static ExprValueKind getValueKindForType(QualType T) { 343f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall if (const ReferenceType *RT = T->getAs<ReferenceType>()) 3440943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall return (isa<LValueReferenceType>(RT) 3450943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall ? VK_LValue 3460943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall : (RT->getPointeeType()->isFunctionType() 3470943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall ? VK_LValue : VK_XValue)); 348f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall return VK_RValue; 349f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall } 350f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 351f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// getValueKind - The value kind that this expression produces. 352f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind getValueKind() const { 353f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall return static_cast<ExprValueKind>(ExprBits.ValueKind); 354f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall } 355f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 356f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// getObjectKind - The object kind that this expression produces. 357f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// Object kinds are meaningful only for expressions that yield an 358f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// l-value or x-value. 359f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprObjectKind getObjectKind() const { 360f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall return static_cast<ExprObjectKind>(ExprBits.ObjectKind); 361f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall } 362f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 36356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall bool isOrdinaryOrBitFieldObject() const { 36456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall ExprObjectKind OK = getObjectKind(); 36556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return (OK == OK_Ordinary || OK == OK_BitField); 36656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 36756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 368f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// setValueKind - Set the value kind produced by this expression. 369f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall void setValueKind(ExprValueKind Cat) { ExprBits.ValueKind = Cat; } 370f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 371f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall /// setObjectKind - Set the object kind produced by this expression. 372f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall void setObjectKind(ExprObjectKind Cat) { ExprBits.ObjectKind = Cat; } 373f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall 3742111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redlprivate: 3752111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl Classification ClassifyImpl(ASTContext &Ctx, SourceLocation *Loc) const; 3762111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 3772111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redlpublic: 3782111c855343a0530e236bf0862358ec8d67b28f3Sebastian Redl 37933bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor /// \brief If this expression refers to a bit-field, retrieve the 38033bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor /// declaration of that bit-field. 38133bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor FieldDecl *getBitField(); 3825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 38338d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson const FieldDecl *getBitField() const { 38438d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson return const_cast<Expr*>(this)->getBitField(); 38538d068e8f13a119b89a3b8b0f79f35cab1ffd09aAnders Carlsson } 3861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 387f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall /// \brief If this expression is an l-value for an Objective C 388f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall /// property, find the underlying property reference expression. 389f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall const ObjCPropertyRefExpr *getObjCProperty() const; 390f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall 391093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson /// \brief Returns whether this expression refers to a vector element. 392093802675b1548f2a5f44c29938d65cce00d58bbAnders Carlsson bool refersToVectorElement() const; 393c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3942b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// isKnownToHaveBooleanValue - Return true if this is an integer expression 3952b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// that is known to return 0 or 1. This happens for _Bool/bool expressions 3962b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// but also int expressions which are produced by things like comparisons in 3972b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner /// C. 3982b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner bool isKnownToHaveBooleanValue() const; 399c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 4005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isIntegerConstantExpr - Return true if this expression is a valid integer 4015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// constant expression, and, if so, return its value in Result. If not a 4025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// valid i-c-e, return false and fill in Loc (if specified) with the location 4035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// of the invalid expression. 404590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx, 405590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner SourceLocation *Loc = 0, 4065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isEvaluated = true) const; 407590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const { 4088070a8497c0fb3e6f70a557f788405d8945b1208Daniel Dunbar llvm::APSInt X; 409590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner return isIntegerConstantExpr(X, Ctx, Loc); 4105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 411c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman /// isConstantInitializer - Returns true if this expression is a constant 412c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman /// initializer, which can be emitted at compile-time. 4134204f07fc8bffe6d320b2de95fea274ccf37a17bJohn McCall bool isConstantInitializer(ASTContext &Ctx, bool ForRef) const; 4141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 41594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// EvalResult is a struct with detailed info about an evaluated expression. 41694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson struct EvalResult { 4172d6744ff04c1690a1485178d550d2fab84a0270bDaniel Dunbar /// Val - This is the value the expression can be folded to. 41894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson APValue Val; 4191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// HasSideEffects - Whether the evaluated expression has side effects. 42194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// For example, (f() && 0) can be folded, but it still has side effects. 42294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson bool HasSideEffects; 4231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// Diag - If the expression is unfoldable, then Diag contains a note 42594deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// diagnostic indicating why it's not foldable. DiagLoc indicates a caret 42694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// position for the error, and DiagExpr is the expression that caused 42794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// the error. 42894deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// If the expression is foldable, but not an integer constant expression, 42994deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// Diag contains a note diagnostic that describes why it isn't an integer 43094deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// constant expression. If the expression *is* an integer constant 43194deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson /// expression, then Diag will be zero. 43294deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson unsigned Diag; 43394deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson const Expr *DiagExpr; 43494deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson SourceLocation DiagLoc; 4351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 43694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson EvalResult() : HasSideEffects(false), Diag(0), DiagExpr(0) {} 437e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara 438e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara // isGlobalLValue - Return true if the evaluated lvalue expression 439e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara // is global. 440e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara bool isGlobalLValue() const; 441e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara // hasSideEffects - Return true if the evaluated expression has 442e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara // side effects. 443e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara bool hasSideEffects() const { 444e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara return HasSideEffects; 445e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara } 44694deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson }; 44794deaf675ae60e11c2d9475c6dbfd0c7123160f5Anders Carlsson 4486ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner /// Evaluate - Return true if this is a constant which we can fold using 449019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner /// any crazy technique (that has nothing to do with language standards) that 450019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner /// we want to. If this function returns true, it returns the folded constant 451019f4e858e78587f2241ff1a76c747d7bcd7578cChris Lattner /// in Result. 4524ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool Evaluate(EvalResult &Result, const ASTContext &Ctx) const; 4535b45d4ef1ea3f04ec863daf8aa29be6c6e021750Anders Carlsson 454cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall /// EvaluateAsBooleanCondition - Return true if this is a constant 455cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall /// which we we can fold and convert to a boolean condition using 456cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall /// any crazy technique that we want to. 4574ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool EvaluateAsBooleanCondition(bool &Result, const ASTContext &Ctx) const; 458cd7a445c6b46c5585580dfb652300c8483c0cb6bJohn McCall 4596ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner /// isEvaluatable - Call Evaluate to see if this expression can be constant 46045b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner /// folded, but discard the result. 4614ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool isEvaluatable(const ASTContext &Ctx) const; 462c44eec6dd29ee9415cbd38a35deff4c8b67abb6aAnders Carlsson 4636ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian /// HasSideEffects - This routine returns true for all those expressions 464138d6a6890c171068ac60430431eaadb3fcef9abGabor Greif /// which must be evaluated each time and must not be optimized away 4656ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian /// or evaluated at compile time. Example is a function call, volatile 4666ddf4784a22b994b954ed74c6061d4603d474639Fariborz Jahanian /// variable read. 4674ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool HasSideEffects(const ASTContext &Ctx) const; 468c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 46951fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson /// EvaluateAsInt - Call Evaluate and return the folded integer. This 47051fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson /// must be called on an expression that constant folds to an integer. 4714ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad llvm::APSInt EvaluateAsInt(const ASTContext &Ctx) const; 47251fe996231b1d7199f76e4005ff4c943d5deeecdAnders Carlsson 473b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman /// EvaluateAsLValue - Evaluate an expression to see if it's a lvalue 474b2f295c8050fb8c141bf2cf38eed0a56e99d0092Eli Friedman /// with link time known address. 4754ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx) const; 4761b78276a75a5a0f496a82429c1ff9604d622a76dAnders Carlsson 477e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara /// EvaluateAsLValue - Evaluate an expression to see if it's a lvalue. 4784ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool EvaluateAsAnyLValue(EvalResult &Result, const ASTContext &Ctx) const; 479e17a6436b429e4b18a5e157061fb13bbc677b3b0Abramo Bagnara 48082214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Enumeration used to describe the kind of Null pointer constant 48182214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// returned from \c isNullPointerConstant(). 48282214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth enum NullPointerConstantKind { 48382214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Expression is not a Null pointer constant. 48482214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NPCK_NotNull = 0, 48582214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 48682214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Expression is a Null pointer constant built from a zero integer. 48782214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NPCK_ZeroInteger, 48882214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 48982214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Expression is a C++0X nullptr. 49082214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NPCK_CXX0X_nullptr, 49182214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 49282214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// \brief Expression is a GNU-style __null constant. 49382214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NPCK_GNUNull 49482214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth }; 49582214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth 496ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Enumeration used to describe how \c isNullPointerConstant() 497ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// should cope with value-dependent expressions. 498ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor enum NullPointerConstantValueDependence { 499ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that the expression should never be value-dependent. 500ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_NeverValueDependent = 0, 501c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 502ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that a value-dependent expression of integral or 503ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// dependent type should be considered a null pointer constant. 504ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_ValueDependentIsNull, 505c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 506ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// \brief Specifies that a value-dependent expression should be considered 507ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor /// to never be a null pointer constant. 508ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor NPC_ValueDependentIsNotNull 509ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor }; 510c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 51182214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to 51282214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// a Null pointer constant. The return value can further distinguish the 51382214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth /// kind of NULL pointer constant that was detected. 51482214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NullPointerConstantKind isNullPointerConstant( 51582214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth ASTContext &Ctx, 51682214a80c0163e01e4d8dec1426023c89277dbb4Chandler Carruth NullPointerConstantValueDependence NPC) const; 517efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson 51844baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian /// isOBJCGCCandidate - Return true if this expression may be used in a read/ 5191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// write barrier. 520102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian bool isOBJCGCCandidate(ASTContext &Ctx) const; 5211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 52211ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis /// \brief Returns true if this expression is a bound member function. 52311ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis bool isBoundMemberFunction(ASTContext &Ctx) const; 52411ab79030938209f50691acae0ddb65e72a58ca9Argyrios Kyrtzidis 525864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// \brief Given an expression of bound-member type, find the type 526864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// of the member. Returns null if this is an *overloaded* bound 527864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall /// member expression. 528864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall static QualType findBoundMemberType(const Expr *expr); 529864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 530369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// \brief Result type of CanThrow(). 531369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl enum CanThrowResult { 532369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CT_Cannot, 533369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CT_Dependent, 534369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CT_Can 535369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl }; 536369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// \brief Test if this expression, if evaluated, might throw, according to 537369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl /// the rules of C++ [expr.unary.noexcept]. 538369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl CanThrowResult CanThrow(ASTContext &C) const; 539369e51fa400aeb5835bb9af4634ea516c11429a7Sebastian Redl 54091a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall /// IgnoreImpCasts - Skip past any implicit casts which might 54191a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall /// surround this expression. Only skips ImplicitCastExprs. 54291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall Expr *IgnoreImpCasts(); 54391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 5447e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall /// IgnoreImplicit - Skip past any implicit AST nodes which might 5457e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall /// surround this expression. 5467e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall Expr *IgnoreImplicit() { return cast<Expr>(Stmt::IgnoreImplicit()); } 5477e5e5f4cc36fe50f46ad76dca7a266434c94f475John McCall 5484e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// IgnoreParens - Ignore parentheses. If this Expr is a ParenExpr, return 5491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// its subexpression. If that subexpression is also a ParenExpr, 5504e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// then this method recursively returns its subexpression, and so forth. 5514e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek /// Otherwise, the method returns the current Expr. 5522b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner Expr *IgnoreParens(); 55356f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner 55456f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner /// IgnoreParenCasts - Ignore parentheses and casts. Strip off any ParenExpr 55527c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor /// or CastExprs, returning their operand. 55656f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner Expr *IgnoreParenCasts(); 5571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5582fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall /// IgnoreParenImpCasts - Ignore parentheses and implicit casts. Strip off any 5592fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall /// ParenExpr or ImplicitCastExprs, returning their operand. 5602fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall Expr *IgnoreParenImpCasts(); 5612fc46bf1a9bc31d50f82de37c70ea257d3cded27John McCall 5622f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg /// IgnoreConversionOperator - Ignore conversion operator. If this Expr is a 5632f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg /// call to a conversion operator, return the argument. 5642f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg Expr *IgnoreConversionOperator(); 5652f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg 5662f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg const Expr *IgnoreConversionOperator() const { 5672f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg return const_cast<Expr*>(this)->IgnoreConversionOperator(); 5682f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg } 5692f072b442879b8bba8c5dea11d7c61bedb1924aeHans Wennborg 5704d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek const Expr *IgnoreParenImpCasts() const { 5714d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek return const_cast<Expr*>(this)->IgnoreParenImpCasts(); 5724d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek } 573f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall 574f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall /// Ignore parentheses and lvalue casts. Strip off any ParenExpr and 575f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall /// CastExprs that represent lvalue casts, returning their operand. 576f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall Expr *IgnoreParenLValueCasts(); 577f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall 578f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall const Expr *IgnoreParenLValueCasts() const { 579f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall return const_cast<Expr*>(this)->IgnoreParenLValueCasts(); 580f6a1648197562e0b133440d612d9af297d0a86ccJohn McCall } 5814d3175c1e5a44251ea97b0c81e80f060629d9c08Ted Kremenek 582ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the 583ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// value (including ptr->int casts of the same size). Strip off any 584ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner /// ParenExpr or CastExprs, returning their operand. 585ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Expr *IgnoreParenNoopCasts(ASTContext &Ctx); 5861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5876eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// \brief Determine whether this expression is a default function argument. 5886eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// 5896eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// Default arguments are implicitly generated in the abstract syntax tree 590c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// by semantic analysis for function calls, object constructions, etc. in 5916eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// C++. Default arguments are represented by \c CXXDefaultArgExpr nodes; 5926eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// this routine also looks through any implicit casts to determine whether 5936eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// the expression is a default argument. 5946eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor bool isDefaultArgument() const; 595c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 596558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall /// \brief Determine whether the result of this expression is a 597558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall /// temporary object of the given class type. 598558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const; 5992f59979a7cc7929f53c9984423b0abeb83113442Douglas Gregor 60075e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor /// \brief Whether this expression is an implicit reference to 'this' in C++. 60175e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor bool isImplicitCXXThis() const; 60291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 60391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall const Expr *IgnoreImpCasts() const { 60491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall return const_cast<Expr*>(this)->IgnoreImpCasts(); 60591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall } 6062b334bb3126a67895813e49e6228dad4aec0b4d6Chris Lattner const Expr *IgnoreParens() const { 6074e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek return const_cast<Expr*>(this)->IgnoreParens(); 6084e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek } 60956f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner const Expr *IgnoreParenCasts() const { 61056f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner return const_cast<Expr*>(this)->IgnoreParenCasts(); 61156f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner } 612ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner const Expr *IgnoreParenNoopCasts(ASTContext &Ctx) const { 613ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner return const_cast<Expr*>(this)->IgnoreParenNoopCasts(Ctx); 614ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 6151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 616898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs); 617898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs); 618898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 6191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 6205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getStmtClass() >= firstExprConstant && 6211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump T->getStmtClass() <= lastExprConstant; 6225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Expr *) { return true; } 6245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 6255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6275549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek//===----------------------------------------------------------------------===// 6285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Primary Expressions. 6295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 6305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 63156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// OpaqueValueExpr - An expression referring to an opaque object of a 63256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// fixed type and value class. These don't correspond to concrete 63356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// syntax; instead they're used to express operations (usually copy 63456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// operations) on values whose source is generally obvious from 63556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// context. 63656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass OpaqueValueExpr : public Expr { 63756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall friend class ASTStmtReader; 63856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *SourceExpr; 63956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation Loc; 64056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 64156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallpublic: 64256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValueExpr(SourceLocation Loc, QualType T, ExprValueKind VK, 64356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall ExprObjectKind OK = OK_Ordinary) 64456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : Expr(OpaqueValueExprClass, T, VK, OK, 645561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor T->isDependentType(), T->isDependentType(), 646561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor T->isInstantiationDependentType(), 647561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false), 64856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceExpr(0), Loc(Loc) { 64956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 65056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 65156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// Given an expression which invokes a copy constructor --- i.e. a 65256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// CXXConstructExpr, possibly wrapped in an ExprWithCleanups --- 65356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// find the OpaqueValueExpr that's the source of the construction. 65456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static const OpaqueValueExpr *findInCopyConstruct(const Expr *expr); 65556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 65656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall explicit OpaqueValueExpr(EmptyShell Empty) 65756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : Expr(OpaqueValueExprClass, Empty) { } 65856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 65956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief Retrieve the location of this expression. 66056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation getLocation() const { return Loc; } 66156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 66256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceRange getSourceRange() const { 66356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (SourceExpr) return SourceExpr->getSourceRange(); 66456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return Loc; 66556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 66656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation getExprLoc() const { 66756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (SourceExpr) return SourceExpr->getExprLoc(); 66856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return Loc; 66956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 67056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 67156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall child_range children() { return child_range(); } 67256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 67356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// The source expression of an opaque value expression is the 67456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// expression which originally generated the value. This is 67556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// provided as a convenience for analyses that don't wish to 67656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// precisely model the execution behavior of the program. 67756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// 67856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// The source expression is typically set when building the 67956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// expression which binds the opaque value expression in the first 68056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// place. 68156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getSourceExpr() const { return SourceExpr; } 68256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall void setSourceExpr(Expr *e) { SourceExpr = e; } 68356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 68456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const Stmt *T) { 68556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return T->getStmtClass() == OpaqueValueExprClass; 68656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 68756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const OpaqueValueExpr *) { return true; } 68856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall}; 68956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 690cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// \brief A reference to a declared variable, function, enum, etc. 691cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// [C99 6.5.1p2] 692cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// 693cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// This encodes all the information about how a declaration is referenced 694cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// within an expression. 695cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// 696cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// There are several optional constructs attached to DeclRefExprs only when 697cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// they apply in order to conserve memory. These are laid out past the end of 698cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// the object, and flags in the DeclRefExprBitfield track whether they exist: 699cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// 700cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// DeclRefExprBits.HasQualifier: 701cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// Specifies when this declaration reference expression has a C++ 702cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// nested-name-specifier. 7033aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth/// DeclRefExprBits.HasFoundDecl: 7043aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth/// Specifies when this declaration reference expression has a record of 7053aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth/// a NamedDecl (different from the referenced ValueDecl) which was found 7063aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth/// during name lookup and/or overload resolution. 707cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// DeclRefExprBits.HasExplicitTemplateArgs: 708cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// Specifies when this declaration reference expression has an explicit 709cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth/// C++ template argument list. 7105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass DeclRefExpr : public Expr { 711cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth /// \brief The declaration that we are referencing. 712cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth ValueDecl *D; 7132577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 714cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth /// \brief The location of the declaration name itself. 7155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 7169e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis 717cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth /// \brief Provides source/type location info for the declaration name 718cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth /// embedded in D. 7192577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameLoc DNLoc; 7202577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 7216857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// \brief Helper to retrieve the optional NestedNameSpecifierLoc. 7226857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth NestedNameSpecifierLoc &getInternalQualifierLoc() { 7237e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth assert(hasQualifier()); 7246857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth return *reinterpret_cast<NestedNameSpecifierLoc *>(this + 1); 725a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 726cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth 7276857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// \brief Helper to retrieve the optional NestedNameSpecifierLoc. 7286857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth const NestedNameSpecifierLoc &getInternalQualifierLoc() const { 7296857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth return const_cast<DeclRefExpr *>(this)->getInternalQualifierLoc(); 730a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 731096832c5ed5b9106fa177ebc148489760c3bc496John McCall 7323aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// \brief Test whether there is a distinct FoundDecl attached to the end of 7333aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// this DRE. 7343aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth bool hasFoundDecl() const { return DeclRefExprBits.HasFoundDecl; } 7353aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 7363aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// \brief Helper to retrieve the optional NamedDecl through which this 7373aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// reference occured. 7383aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *&getInternalFoundDecl() { 7393aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth assert(hasFoundDecl()); 7403aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth if (hasQualifier()) 7413aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return *reinterpret_cast<NamedDecl **>(&getInternalQualifierLoc() + 1); 7423aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return *reinterpret_cast<NamedDecl **>(this + 1); 7433aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth } 7443aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 7453aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// \brief Helper to retrieve the optional NamedDecl through which this 7463aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// reference occured. 7473aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *getInternalFoundDecl() const { 7483aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return const_cast<DeclRefExpr *>(this)->getInternalFoundDecl(); 7493aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth } 7503aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 7517e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth DeclRefExpr(NestedNameSpecifierLoc QualifierLoc, 7522577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ValueDecl *D, const DeclarationNameInfo &NameInfo, 7533aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *FoundD, 7542577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const TemplateArgumentListInfo *TemplateArgs, 755f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK); 7562577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 757663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis /// \brief Construct an empty declaration reference expression. 758663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis explicit DeclRefExpr(EmptyShell Empty) 759663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis : Expr(DeclRefExprClass, Empty) { } 7607e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 7610da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor /// \brief Computes the type- and value-dependence flags for this 7620da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor /// declaration reference expression. 7630da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor void computeDependence(); 7649e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis 7655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 7665b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor DeclRefExpr(ValueDecl *D, QualType T, ExprValueKind VK, SourceLocation L, 7675b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor const DeclarationNameLoc &LocInfo = DeclarationNameLoc()) 768561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Expr(DeclRefExprClass, T, VK, OK_Ordinary, false, false, false, false), 7695b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor D(D), Loc(L), DNLoc(LocInfo) { 770cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth DeclRefExprBits.HasQualifier = 0; 771cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth DeclRefExprBits.HasExplicitTemplateArgs = 0; 7723aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth DeclRefExprBits.HasFoundDecl = 0; 7730da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor computeDependence(); 7740da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor } 7751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 776a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor static DeclRefExpr *Create(ASTContext &Context, 77740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 778dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *D, 779a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation NameLoc, 780f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK, 7813aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *FoundD = 0, 7820da76df9218d7c27b471b0a4d83a5b29fe24e5b4Douglas Gregor const TemplateArgumentListInfo *TemplateArgs = 0); 783663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis 7842577743c5650c646fb705df01403707e94f2df04Abramo Bagnara static DeclRefExpr *Create(ASTContext &Context, 78540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 7862577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ValueDecl *D, 7872577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 788f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK, 7893aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *FoundD = 0, 7902577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const TemplateArgumentListInfo *TemplateArgs = 0); 7912577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 792663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis /// \brief Construct an empty declaration reference expression. 793663e380d7b2de2bbf20e886e05371195bea9adc4Argyrios Kyrtzidis static DeclRefExpr *CreateEmpty(ASTContext &Context, 7943aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth bool HasQualifier, 7953aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth bool HasFoundDecl, 796def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor bool HasExplicitTemplateArgs, 797def0354384d9c4431f7b58b664b59896d4623028Douglas Gregor unsigned NumTemplateArgs); 7987e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 799cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth ValueDecl *getDecl() { return D; } 800cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth const ValueDecl *getDecl() const { return D; } 801cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth void setDecl(ValueDecl *NewD) { D = NewD; } 802904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor 8032577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo getNameInfo() const { 8042577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(getDecl()->getDeclName(), Loc, DNLoc); 8052577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 8062577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 8079e922b1663ecb95dc7eee03002fd66ed18fb3192Argyrios Kyrtzidis SourceLocation getLocation() const { return Loc; } 8080b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 80963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const; 8101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 811a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Determine whether this declaration reference was preceded by a 812a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// C++ nested-name-specifier, e.g., \c N::foo. 813cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth bool hasQualifier() const { return DeclRefExprBits.HasQualifier; } 8147e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 8157e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth /// \brief If the name was qualified, retrieves the nested-name-specifier 816a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// that precedes the name. Otherwise, returns NULL. 817a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NestedNameSpecifier *getQualifier() const { 818a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (!hasQualifier()) 819a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 8207e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 8216857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth return getInternalQualifierLoc().getNestedNameSpecifier(); 822a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 82340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor 8247e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth /// \brief If the name was qualified, retrieves the nested-name-specifier 82540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor /// that precedes the name, with source-location information. 82640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc getQualifierLoc() const { 82740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (!hasQualifier()) 82840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return NestedNameSpecifierLoc(); 8297e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 8306857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth return getInternalQualifierLoc(); 83140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor } 83240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor 8333aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// \brief Get the NamedDecl through which this reference occured. 8343aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// 8353aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// This Decl may be different from the ValueDecl actually referred to in the 8363aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// presence of using declarations, etc. It always returns non-NULL, and may 8373aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// simple return the ValueDecl when appropriate. 8383aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth NamedDecl *getFoundDecl() { 8393aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return hasFoundDecl() ? getInternalFoundDecl() : D; 8403aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth } 8413aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 8423aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// \brief Get the NamedDecl through which this reference occurred. 8433aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth /// See non-const variant. 8443aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth const NamedDecl *getFoundDecl() const { 8453aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth return hasFoundDecl() ? getInternalFoundDecl() : D; 8463aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth } 8473aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 8487e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth /// \brief Determines whether this declaration reference was followed by an 8497e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth /// explict template argument list. 850096832c5ed5b9106fa177ebc148489760c3bc496John McCall bool hasExplicitTemplateArgs() const { 851cb66cff8fdf641f57f85dedb515a5f3240e3a9bbChandler Carruth return DeclRefExprBits.HasExplicitTemplateArgs; 852096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 8537e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 854096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that followed the 855096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// member template name. 856b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 857096832c5ed5b9106fa177ebc148489760c3bc496John McCall assert(hasExplicitTemplateArgs()); 8583aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth if (hasFoundDecl()) 859b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis return *reinterpret_cast<ASTTemplateArgumentListInfo *>( 8603aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth &getInternalFoundDecl() + 1); 8613aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth 8623aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth if (hasQualifier()) 863b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis return *reinterpret_cast<ASTTemplateArgumentListInfo *>( 8643aa8140bde5b9bedf13e46ec0a668daa54814196Chandler Carruth &getInternalQualifierLoc() + 1); 8657e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 866b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis return *reinterpret_cast<ASTTemplateArgumentListInfo *>(this + 1); 867096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 8687e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 869096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that followed the 870096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// member template name. 871b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 872096832c5ed5b9106fa177ebc148489760c3bc496John McCall return const_cast<DeclRefExpr *>(this)->getExplicitTemplateArgs(); 873a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 874d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 875096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieves the optional explicit template arguments. 876096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// This points to the same data as getExplicitTemplateArgs(), but 877096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// returns null if there are no explicit template arguments. 878b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis const ASTTemplateArgumentListInfo *getExplicitTemplateArgsOpt() const { 879096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) return 0; 880096832c5ed5b9106fa177ebc148489760c3bc496John McCall return &getExplicitTemplateArgs(); 881096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 8827e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 883d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// \brief Copies the template arguments (if present) into the given 884d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// structure. 885d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 886096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (hasExplicitTemplateArgs()) 887096832c5ed5b9106fa177ebc148489760c3bc496John McCall getExplicitTemplateArgs().copyInto(List); 888d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall } 8897e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 890a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the location of the left angle bracket following the 891a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// member name ('<'), if any. 892a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation getLAngleLoc() const { 893096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 894a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return SourceLocation(); 8957e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 896096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().LAngleLoc; 897a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 8987e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 899a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the template arguments provided as part of this 900a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template-id. 901833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc *getTemplateArgs() const { 902096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 903a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 9047e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 905096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().getTemplateArgs(); 906a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 9077e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 908a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the number of template arguments provided as part of this 909a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template-id. 910a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor unsigned getNumTemplateArgs() const { 911096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 912a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return 0; 9137e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 914096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().NumTemplateArgs; 915a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 9167e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 917a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// \brief Retrieve the location of the right angle bracket following the 918a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor /// template arguments ('>'). 919a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SourceLocation getRAngleLoc() const { 920096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) 921a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return SourceLocation(); 9227e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 923096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().RAngleLoc; 924a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 9257e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 9261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 92799e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor return T->getStmtClass() == DeclRefExprClass; 9285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const DeclRefExpr *) { return true; } 9301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 93177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 93263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 9337e740bd36772aae16b5cc5e605998ccc5eaf26dbChandler Carruth 93460adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 9353397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl friend class ASTStmtWriter; 9365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 9375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 938d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner/// PredefinedExpr - [C99 6.4.2.2] - A predefined identifier such as __func__. 939d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattnerclass PredefinedExpr : public Expr { 940227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic: 941227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson enum IdentType { 942227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson Func, 943227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson Function, 944848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson PrettyFunction, 945848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson /// PrettyFunctionNoVirtual - The same as PrettyFunction, except that the 946848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson /// 'virtual' keyword is omitted for virtual member functions. 947848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson PrettyFunctionNoVirtual 948227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson }; 9491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 950227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonprivate: 951227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson SourceLocation Loc; 952227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson IdentType Type; 953227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlssonpublic: 9541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump PredefinedExpr(SourceLocation l, QualType type, IdentType IT) 955f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(PredefinedExprClass, type, VK_LValue, OK_Ordinary, 956bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor type->isDependentType(), type->isDependentType(), 957561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor type->isInstantiationDependentType(), 958bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor /*ContainsUnexpandedParameterPack=*/false), 959f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Loc(l), Type(IT) {} 9601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 96117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor /// \brief Construct an empty predefined expression. 9621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit PredefinedExpr(EmptyShell Empty) 96317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor : Expr(PredefinedExprClass, Empty) { } 96417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 965227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson IdentType getIdentType() const { return Type; } 96617fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setIdentType(IdentType IT) { Type = IT; } 96717fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 96817fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor SourceLocation getLocation() const { return Loc; } 96917fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 97017fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 971848fa64143fbe5ae62a601ad61277f741e54dfabAnders Carlsson static std::string ComputeName(IdentType IT, const Decl *CurrentDecl); 9723a082d81006e7a2e01a6e431a22e21c78490ff8fAnders Carlsson 97363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 974227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 9751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 9761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == PredefinedExprClass; 977227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson } 978d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner static bool classof(const PredefinedExpr *) { return true; } 9791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 98077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 98163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 982227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson}; 983227426661be33ff3e21f2b6b9f97971da2da044fAnders Carlsson 9849996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// \brief Used by IntegerLiteral/FloatingLiteral to store the numeric without 9859996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// leaking memory. 9869996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// 9879996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// For large floats/integers, APFloat/APInt will allocate memory from the heap 9889996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// to represent these numbers. Unfortunately, when we use a BumpPtrAllocator 9899996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// to allocate IntegerLiteral/FloatingLiteral nodes the memory associated with 9909996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// the APFloat/APInt values will never get freed. APNumericStorage uses 9919996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis/// ASTContext's allocator for memory allocation. 9929996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisclass APNumericStorage { 9939996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis unsigned BitWidth; 9949996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis union { 9959996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis uint64_t VAL; ///< Used to store the <= 64 bits integer value. 9969996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis uint64_t *pVal; ///< Used to store the >64 bits integer value. 9979996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis }; 9989996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 9999996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis bool hasAllocation() const { return llvm::APInt::getNumWords(BitWidth) > 1; } 10009996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10019996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APNumericStorage(const APNumericStorage&); // do not implement 10029996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APNumericStorage& operator=(const APNumericStorage&); // do not implement 10039996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10049996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisprotected: 10059996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APNumericStorage() : BitWidth(0), VAL(0) { } 10069996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10079996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APInt getIntValue() const { 10089996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis unsigned NumWords = llvm::APInt::getNumWords(BitWidth); 10099996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis if (NumWords > 1) 10109996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return llvm::APInt(BitWidth, NumWords, pVal); 10119996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis else 10129996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis return llvm::APInt(BitWidth, VAL); 10139996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 10149996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setIntValue(ASTContext &C, const llvm::APInt &Val); 10159996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis}; 10169996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10179996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisclass APIntStorage : public APNumericStorage { 10189996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidispublic: 10199996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APInt getValue() const { return getIntValue(); } 10209996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setValue(ASTContext &C, const llvm::APInt &Val) { setIntValue(C, Val); } 10219996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis}; 10229996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10239996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidisclass APFloatStorage : public APNumericStorage { 10249996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidispublic: 10259996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APFloat getValue() const { return llvm::APFloat(getIntValue()); } 10269996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setValue(ASTContext &C, const llvm::APFloat &Val) { 10279996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis setIntValue(C, Val.bitcastToAPInt()); 10289996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 10299996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis}; 10309996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass IntegerLiteral : public Expr { 10329996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APIntStorage Num; 10335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 10349996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10359996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis /// \brief Construct an empty integer literal. 10369996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis explicit IntegerLiteral(EmptyShell Empty) 10379996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis : Expr(IntegerLiteralClass, Empty) { } 10389996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 10395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 10401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy, 10415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // or UnsignedLongLongTy 10429996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis IntegerLiteral(ASTContext &C, const llvm::APInt &V, 10439996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis QualType type, SourceLocation l) 1044bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(IntegerLiteralClass, type, VK_RValue, OK_Ordinary, false, false, 1045561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false), 1046f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Loc(l) { 10475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(type->isIntegerType() && "Illegal type in IntegerLiteral"); 10481dd986dff9ddfbec687975700770bb377988e9edRichard Trieu assert(V.getBitWidth() == C.getIntWidth(type) && 10491dd986dff9ddfbec687975700770bb377988e9edRichard Trieu "Integer type is not the correct size for constant."); 10509996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis setValue(C, V); 10515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1052a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson 10531dd986dff9ddfbec687975700770bb377988e9edRichard Trieu /// \brief Returns a new integer literal with value 'V' and type 'type'. 10541dd986dff9ddfbec687975700770bb377988e9edRichard Trieu /// \param type - either IntTy, LongTy, LongLongTy, UnsignedIntTy, 10551dd986dff9ddfbec687975700770bb377988e9edRichard Trieu /// UnsignedLongTy, or UnsignedLongLongTy which should match the size of V 10561dd986dff9ddfbec687975700770bb377988e9edRichard Trieu /// \param V - the value that the returned integer literal contains. 10579996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis static IntegerLiteral *Create(ASTContext &C, const llvm::APInt &V, 10589996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis QualType type, SourceLocation l); 10591dd986dff9ddfbec687975700770bb377988e9edRichard Trieu /// \brief Returns a new empty integer literal. 10609996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis static IntegerLiteral *Create(ASTContext &C, EmptyShell Empty); 10610b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 10629996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APInt getValue() const { return Num.getValue(); } 106363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 10645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1065313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Retrieve the location of the literal. 1066313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getLocation() const { return Loc; } 1067313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 10689996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setValue(ASTContext &C, const llvm::APInt &Val) { Num.setValue(C, Val); } 10690b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation Location) { Loc = Location; } 10700b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 10711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 10721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == IntegerLiteralClass; 10735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const IntegerLiteral *) { return true; } 10751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 107677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 107763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 10785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CharacterLiteral : public Expr { 10815cee1195584fa8672253139c86e922daeda69b9eDouglas Gregorpublic: 10825cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor enum CharacterKind { 10835cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor Ascii, 10845cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor Wide, 10855cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor UTF16, 10865cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor UTF32 10875cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor }; 10885cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor 10895cee1195584fa8672253139c86e922daeda69b9eDouglas Gregorprivate: 10905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned Value; 10915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 10925cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor unsigned Kind : 2; 10935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 10945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // type should be IntTy 10955cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor CharacterLiteral(unsigned value, CharacterKind kind, QualType type, 10965cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor SourceLocation l) 1097bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(CharacterLiteralClass, type, VK_RValue, OK_Ordinary, false, false, 1098561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false), 10995cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor Value(value), Loc(l), Kind(kind) { 11005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11010b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 11020b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor /// \brief Construct an empty character literal. 11030b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { } 11040b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 1105018d8e0596dd57401eeddcf11ac84ff0a065fbbeChris Lattner SourceLocation getLocation() const { return Loc; } 11065cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor CharacterKind getKind() const { return static_cast<CharacterKind>(Kind); } 11071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 110863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 11091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getValue() const { return Value; } 11115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11120b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setLocation(SourceLocation Location) { Loc = Location; } 11135cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor void setKind(CharacterKind kind) { Kind = kind; } 11140b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor void setValue(unsigned Val) { Value = Val; } 11150b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor 11161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 11171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CharacterLiteralClass; 11185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CharacterLiteral *) { return true; } 112077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 112177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 112263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 11235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FloatingLiteral : public Expr { 11269996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis APFloatStorage Num; 1127720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek bool IsExact : 1; 11285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 11299996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 11309996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis FloatingLiteral(ASTContext &C, const llvm::APFloat &V, bool isexact, 1131720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek QualType Type, SourceLocation L) 1132bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(FloatingLiteralClass, Type, VK_RValue, OK_Ordinary, false, false, 1133561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false), 11349996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis IsExact(isexact), Loc(L) { 11359996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis setValue(C, V); 11369996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 11375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 113817fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor /// \brief Construct an empty floating-point literal. 11391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit FloatingLiteral(EmptyShell Empty) 11409996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis : Expr(FloatingLiteralClass, Empty), IsExact(false) { } 114117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 11429996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidispublic: 11439996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis static FloatingLiteral *Create(ASTContext &C, const llvm::APFloat &V, 11449996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis bool isexact, QualType Type, SourceLocation L); 11459996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis static FloatingLiteral *Create(ASTContext &C, EmptyShell Empty); 11469996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis 11479996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis llvm::APFloat getValue() const { return Num.getValue(); } 11489996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis void setValue(ASTContext &C, const llvm::APFloat &Val) { 11499996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis Num.setValue(C, Val); 11509996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis } 115117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 1152720c4ec57b6110873cd533ad434853a27e7c3f4aTed Kremenek bool isExact() const { return IsExact; } 115317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setExact(bool E) { IsExact = E; } 1154c9bec4bfea9090a08dd83a7b213f0c8adf8d78ecChris Lattner 1155da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// getValueAsApproximateDouble - This returns the value as an inaccurate 1156da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// double. Note that this may cause loss of precision, but is useful for 1157da8249e57f3badecf925571881fe57243935c6c1Chris Lattner /// debugging dumps, etc. 1158da8249e57f3badecf925571881fe57243935c6c1Chris Lattner double getValueAsApproximateDouble() const; 11591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 116017fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor SourceLocation getLocation() const { return Loc; } 116117fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor void setLocation(SourceLocation L) { Loc = L; } 116217fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor 116363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 11645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 11661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == FloatingLiteralClass; 11675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const FloatingLiteral *) { return true; } 11691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 117077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 117163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 11725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11745d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// ImaginaryLiteral - We support imaginary integer and floating point literals, 11755d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// like "1.0i". We represent these as a wrapper around FloatingLiteral and 11765d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// IntegerLiteral classes. Instances of this class always have a Complex type 11775d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// whose element type matches the subexpression. 11785d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner/// 11795d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerclass ImaginaryLiteral : public Expr { 11805549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 11815d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattnerpublic: 11825d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner ImaginaryLiteral(Expr *val, QualType Ty) 1183bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(ImaginaryLiteralClass, Ty, VK_RValue, OK_Ordinary, false, false, 1184561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false), 1185f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Val(val) {} 11861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1187cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor /// \brief Build an empty imaginary literal. 11881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ImaginaryLiteral(EmptyShell Empty) 1189cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor : Expr(ImaginaryLiteralClass, Empty) { } 1190cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 11915549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 11925549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 1193cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 1194cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 119563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return Val->getSourceRange(); } 11961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 11971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ImaginaryLiteralClass; 11985d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner } 11995d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner static bool classof(const ImaginaryLiteral *) { return true; } 12001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12015d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner // Iterators 120263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Val, &Val+1); } 12035d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner}; 12045d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner 1205e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// StringLiteral - This represents a string literal expression, e.g. "foo" 1206e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// or L"bar" (wide strings). The actual string is returned by getStrData() 1207e6a82b2c29ad05534841e5f8fd033fb17b6f61e2Ted Kremenek/// is NOT null-terminated, and the length of the string is determined by 1208a7ad98ff0919d6a24ea7c46634ea29bea551c1a0Chris Lattner/// calling getByteLength(). The C type for a string is always a 1209c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// ConstantArrayType. In C++, the char type is const qualified, in C it is 1210c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// not. 1211690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// 1212690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// Note that strings in C can be formed by concatenation of multiple string 12138bea7c0ee44c71c817de7dc2be932b73bec90c9fChris Lattner/// literal pptokens in translation phase #6. This keeps track of the locations 1214690398188ea5b428f06aa13c7d4ce6eb741ad4f9Chris Lattner/// of each of these pieces. 1215c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// 1216c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// Strings in C can also be truncated and extended by assigning into arrays, 1217c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// e.g. with constructs like: 1218c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// char X[2] = "foobar"; 1219c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// In this case, getByteLength() will return 6, but the string literal will 1220c4a09c189981b4561428e4b56fd250718e2717bbChris Lattner/// have type "char[2]". 12215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass StringLiteral : public Expr { 12225cee1195584fa8672253139c86e922daeda69b9eDouglas Gregorpublic: 12235cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor enum StringKind { 12245cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor Ascii, 12255cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor Wide, 12265cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor UTF8, 12275cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor UTF16, 12285cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor UTF32 12295cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor }; 12305cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor 12315cee1195584fa8672253139c86e922daeda69b9eDouglas Gregorprivate: 12323e2193ce5feb2feb092e5ae615e85148e06e9fd2Anders Carlsson friend class ASTStmtReader; 12333e2193ce5feb2feb092e5ae615e85148e06e9fd2Anders Carlsson 12345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *StrData; 12355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned ByteLength; 1236726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner unsigned NumConcatenated; 12375cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor unsigned Kind : 3; 12385cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor bool IsPascal : 1; 1239726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner SourceLocation TokLocs[1]; 12402085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner 1241f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall StringLiteral(QualType Ty) : 1242561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor Expr(StringLiteralClass, Ty, VK_LValue, OK_Ordinary, false, false, false, 1243561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false) {} 12441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 12462085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// This is the "fully general" constructor that allows representation of 12472085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// strings formed from multiple concatenated tokens. 12485cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor static StringLiteral *Create(ASTContext &C, StringRef Str, StringKind Kind, 124965aa6885818d4b4eea2e5a9d12085b2398148662Jay Foad bool Pascal, QualType Ty, 1250a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson const SourceLocation *Loc, unsigned NumStrs); 12512085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner 12522085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner /// Simple constructor for string literals made from one token. 12535cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor static StringLiteral *Create(ASTContext &C, StringRef Str, StringKind Kind, 12545cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor bool Pascal, QualType Ty, 12555cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor SourceLocation Loc) { 12565cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor return Create(C, Str, Kind, Pascal, Ty, &Loc, 1); 12572085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 1258a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson 1259673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor /// \brief Construct an empty string literal. 1260673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor static StringLiteral *CreateEmpty(ASTContext &C, unsigned NumStrs); 1261673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 1262686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef getString() const { 1263686775deca8b8685eb90801495880e3abdd844c2Chris Lattner return StringRef(StrData, ByteLength); 1264b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar } 12652f4eaef37476ae6891ede8ba215d0f6fd093629bBenjamin Kramer 12665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getByteLength() const { return ByteLength; } 1267673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 1268673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor /// \brief Sets the string data to the given string data. 1269686775deca8b8685eb90801495880e3abdd844c2Chris Lattner void setString(ASTContext &C, StringRef Str); 1270673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 12715cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor StringKind getKind() const { return static_cast<StringKind>(Kind); } 12725cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor bool isAscii() const { return Kind == Ascii; } 12735cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor bool isWide() const { return Kind == Wide; } 12745cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor bool isUTF8() const { return Kind == UTF8; } 12755cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor bool isUTF16() const { return Kind == UTF16; } 12765cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor bool isUTF32() const { return Kind == UTF32; } 12773e2193ce5feb2feb092e5ae615e85148e06e9fd2Anders Carlsson bool isPascal() const { return IsPascal; } 12785cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor 12798d4141f83d9de379547cf05bd75d4c6cf894b189Steve Naroff bool containsNonAsciiOrNull() const { 1280686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef Str = getString(); 1281b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar for (unsigned i = 0, e = Str.size(); i != e; ++i) 1282b648023da23e8b227cdda57a241db4c6f368726bDaniel Dunbar if (!isascii(Str[i]) || !Str[i]) 128333fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff return true; 128433fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff return false; 128533fdb738a6c125f4c788733897021b7c1a062b0cSteve Naroff } 1286726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner /// getNumConcatenated - Get the number of string literal tokens that were 1287726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner /// concatenated in translation phase #6 to form this string literal. 1288726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner unsigned getNumConcatenated() const { return NumConcatenated; } 12891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1290726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner SourceLocation getStrTokenLoc(unsigned TokNum) const { 1291726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner assert(TokNum < NumConcatenated && "Invalid tok number"); 1292726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner return TokLocs[TokNum]; 1293726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner } 12941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setStrTokenLoc(unsigned TokNum, SourceLocation L) { 1295673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor assert(TokNum < NumConcatenated && "Invalid tok number"); 1296673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor TokLocs[TokNum] = L; 1297673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor } 129808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner 129908f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// getLocationOfByte - Return a source location that points to the specified 130008f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// byte of this string literal. 130108f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// 130208f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// Strings are amazingly complex. They can be formed from multiple tokens 130308f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// and can have escape sequences in them in addition to the usual trigraph 130408f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// and escaped newline business. This routine handles this complexity. 130508f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner /// 130608f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner SourceLocation getLocationOfByte(unsigned ByteNo, const SourceManager &SM, 130708f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner const LangOptions &Features, 130808f92e3a5dead1f1ee656678a7f06e43279d6e50Chris Lattner const TargetInfo &Target) const; 1309673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 1310b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner typedef const SourceLocation *tokloc_iterator; 1311b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner tokloc_iterator tokloc_begin() const { return TokLocs; } 1312b137299ce5bb6c36fbba651858600857fda4dd50Chris Lattner tokloc_iterator tokloc_end() const { return TokLocs+NumConcatenated; } 13135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 131463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 13151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SourceRange(TokLocs[0], TokLocs[NumConcatenated-1]); 13165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 13181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == StringLiteralClass; 13195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const StringLiteral *) { return true; } 13211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 132277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 132363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 13245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 13255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ParenExpr - This represents a parethesized expression, e.g. "(1)". This 13275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// AST node is only formed if full location information is requested. 13285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ParenExpr : public Expr { 13295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation L, R; 13305549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 13315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 13325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ParenExpr(SourceLocation l, SourceLocation r, Expr *val) 1333898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Expr(ParenExprClass, val->getType(), 1334f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall val->getValueKind(), val->getObjectKind(), 1335bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor val->isTypeDependent(), val->isValueDependent(), 1336561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor val->isInstantiationDependent(), 1337bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor val->containsUnexpandedParameterPack()), 1338898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor L(l), R(r), Val(val) {} 13391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1340c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor /// \brief Construct an empty parenthesized expression. 13411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ParenExpr(EmptyShell Empty) 1342c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor : Expr(ParenExprClass, Empty) { } 1343c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor 13445549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 13455549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 1346c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 1347c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor 134863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(L, R); } 13495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1350313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Get the location of the left parentheses '('. 1351313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getLParen() const { return L; } 1352c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setLParen(SourceLocation Loc) { L = Loc; } 1353313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 1354313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor /// \brief Get the location of the right parentheses ')'. 1355313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor SourceLocation getRParen() const { return R; } 1356c04db4feefa2b0dbbc6876cb4eeeee108aa6791dDouglas Gregor void setRParen(SourceLocation Loc) { R = Loc; } 1357313a81dd820c9b2c0203bdcd974c781a81e4f0cfDouglas Gregor 13581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 13591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ParenExprClass; 13605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ParenExpr *) { return true; } 13621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 136377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 136463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Val, &Val+1); } 13655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 13665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13680518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// UnaryOperator - This represents the unary-expression's (except sizeof and 13690518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl/// alignof), the postinc/postdec operators from postfix-expression, and various 13705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// extensions. 1371dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 1372dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Notes on various nodes: 1373dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 1374dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// Real/Imag - These return the real/imag part of a complex operand. If 1375dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// applied to a non-complex value, the former returns its operand and the 1376dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// later returns zero in the type of the operand. 1377dbb36971c68ea944ac4b1fbe2d97fe7cca3b20acChris Lattner/// 13785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass UnaryOperator : public Expr { 13795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 13805baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall typedef UnaryOperatorKind Opcode; 13815baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 13825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 13830799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall unsigned Opc : 5; 13845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation Loc; 13850799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Stmt *Val; 13861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 13875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1388f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall UnaryOperator(Expr *input, Opcode opc, QualType type, 1389f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, SourceLocation l) 1390f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(UnaryOperatorClass, type, VK, OK, 1391de7e66256b1bdfcf6526994825a8c8fced52a31cEli Friedman input->isTypeDependent() || type->isDependentType(), 1392bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor input->isValueDependent(), 1393561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (input->isInstantiationDependent() || 1394561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor type->isInstantiationDependentType()), 1395bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor input->containsUnexpandedParameterPack()), 13960799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Opc(opc), Loc(l), Val(input) {} 13975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13980b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor /// \brief Build an empty unary operator. 13991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit UnaryOperator(EmptyShell Empty) 14002de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall : Expr(UnaryOperatorClass, Empty), Opc(UO_AddrOf) { } 14010b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 14020799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Opcode getOpcode() const { return static_cast<Opcode>(Opc); } 14030b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOpcode(Opcode O) { Opc = O; } 14040b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 14055549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() const { return cast<Expr>(Val); } 14060b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setSubExpr(Expr *E) { Val = E; } 14070b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 14085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOperatorLoc - Return the location of the operator. 14095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation getOperatorLoc() const { return Loc; } 14100b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOperatorLoc(SourceLocation L) { Loc = L; } 14110b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 14125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isPostfix - Return true if this is a postfix operation, like x++. 14132085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static bool isPostfix(Opcode Op) { 14142de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Op == UO_PostInc || Op == UO_PostDec; 14152085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 14165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1417cc7bd10c0de9449b795bda3c5dcc6d83cc48436bZhanyong Wan /// isPrefix - Return true if this is a prefix operation, like --x. 14182085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner static bool isPrefix(Opcode Op) { 14192de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Op == UO_PreInc || Op == UO_PreDec; 14202085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner } 14215a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek 14220799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isPrefix() const { return isPrefix(getOpcode()); } 14230799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isPostfix() const { return isPostfix(getOpcode()); } 14242de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall bool isIncrementOp() const { 1425993cdca0fed7deb646e4654dfb2607227a497faaBenjamin Kramer return Opc == UO_PreInc || Opc == UO_PostInc; 14262de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 14272de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall bool isIncrementDecrementOp() const { 1428993cdca0fed7deb646e4654dfb2607227a497faaBenjamin Kramer return Opc <= UO_PreDec; 14292de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 14302de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isArithmeticOp(Opcode Op) { 14312de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Op >= UO_Plus && Op <= UO_LNot; 14322de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 14330799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isArithmeticOp() const { return isArithmeticOp(getOpcode()); } 14341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 14365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// corresponds to, e.g. "sizeof" or "[pre]++" 14375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static const char *getOpcodeStr(Opcode Op); 14385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1439bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// \brief Retrieve the unary opcode that corresponds to the given 1440bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// overloaded operator. 1441bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix); 1442bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 1443bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// \brief Retrieve the overloaded operator kind that corresponds to 1444bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor /// the given unary opcode. 1445bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); 1446bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 144763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 14485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (isPostfix()) 14495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(Val->getLocStart(), Loc); 14505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else 14515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(Loc, Val->getLocEnd()); 14525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 145363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation getExprLoc() const { return Loc; } 14541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 14561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == UnaryOperatorClass; 14575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 14585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const UnaryOperator *) { return true; } 14591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 146077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 146163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Val, &Val+1); } 14625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 14635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14648ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// OffsetOfExpr - [C99 7.17] - This represents an expression of the form 14658ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// offsetof(record-type, member-designator). For example, given: 14668ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// @code 14678ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct S { 14688ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// float f; 1469c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt/// double d; 14708ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// }; 14718ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct T { 14728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// int i; 14738ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// struct S s[10]; 14748ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// }; 14758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor/// @endcode 1476c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt/// we can represent and evaluate the expression @c offsetof(struct T, s[2].d). 14778ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 14788ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorclass OffsetOfExpr : public Expr { 14798ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorpublic: 14808ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // __builtin_offsetof(type, identifier(.identifier|[expr])*) 14818ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor class OffsetOfNode { 14828ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor public: 14838ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief The kind of offsetof node we have. 14848ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor enum Kind { 1485cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief An index into an array. 14868ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Array = 0x00, 1487cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief A field. 14888ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Field = 0x01, 1489cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief A field in a dependent type, known only by its name. 1490cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor Identifier = 0x02, 1491cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief An implicit indirection through a C++ base class, when the 1492cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// field found is in a base class. 1493cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor Base = 0x03 14948ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor }; 14958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 14968ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor private: 14978ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor enum { MaskBits = 2, Mask = 0x03 }; 1498c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 14998ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief The source range that covers this part of the designator. 15008ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceRange Range; 1501c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15028ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief The data describing the designator, which comes in three 15038ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// different forms, depending on the lower two bits. 1504c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// - An unsigned index into the array of Expr*'s stored after this node 15058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// in memory, for [constant-expression] designators. 15068ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// - A FieldDecl*, for references to a known field. 15078ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// - An IdentifierInfo*, for references to a field with a given name 15088ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// when the class type is dependent. 1509c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// - A CXXBaseSpecifier*, for references that look at a field in a 1510cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// base class. 15118ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor uintptr_t Data; 1512c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15138ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor public: 15148ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Create an offsetof node that refers to an array element. 1515c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode(SourceLocation LBracketLoc, unsigned Index, 15168ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RBracketLoc) 15178ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor : Range(LBracketLoc, RBracketLoc), Data((Index << 2) | Array) { } 1518c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15198ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Create an offsetof node that refers to a field. 1520c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode(SourceLocation DotLoc, FieldDecl *Field, 15218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation NameLoc) 1522c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc), 15238ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Data(reinterpret_cast<uintptr_t>(Field) | OffsetOfNode::Field) { } 1524c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15258ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Create an offsetof node that refers to an identifier. 15268ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor OffsetOfNode(SourceLocation DotLoc, IdentifierInfo *Name, 15278ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation NameLoc) 1528c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc), 15298ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Data(reinterpret_cast<uintptr_t>(Name) | Identifier) { } 1530cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor 1531cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief Create an offsetof node that refers into a C++ base class. 1532cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor explicit OffsetOfNode(const CXXBaseSpecifier *Base) 1533cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor : Range(), Data(reinterpret_cast<uintptr_t>(Base) | OffsetOfNode::Base) {} 1534c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15358ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Determine what kind of offsetof node this is. 1536c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Kind getKind() const { 15378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return static_cast<Kind>(Data & Mask); 15388ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1539c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15408ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief For an array element node, returns the index into the array 15418ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// of expressions. 15428ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned getArrayExprIndex() const { 15438ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(getKind() == Array); 15448ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return Data >> 2; 15458ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 15468ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 15478ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief For a field offsetof node, returns the field. 15488ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor FieldDecl *getField() const { 15498ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(getKind() == Field); 1550cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor return reinterpret_cast<FieldDecl *>(Data & ~(uintptr_t)Mask); 15518ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1552c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15538ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief For a field or identifier offsetof node, returns the name of 15548ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// the field. 15558ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor IdentifierInfo *getFieldName() const; 1556c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1557cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor /// \brief For a base class node, returns the base specifier. 1558cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor CXXBaseSpecifier *getBase() const { 1559cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor assert(getKind() == Base); 1560c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return reinterpret_cast<CXXBaseSpecifier *>(Data & ~(uintptr_t)Mask); 1561cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor } 1562c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15638ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Retrieve the source range that covers this offsetof node. 15648ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// 15658ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// For an array element node, the source range contains the locations of 15668ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// the square brackets. For a field or identifier node, the source range 1567c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// contains the location of the period (if there is one) and the 15688ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// identifier. 156906dec892b5300b43263d25c5476b506c9d6cfbadAbramo Bagnara SourceRange getSourceRange() const { return Range; } 15708ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor }; 15718ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 15728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorprivate: 1573c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 15748ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation OperatorLoc, RParenLoc; 15758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Base type; 15768ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TypeSourceInfo *TSInfo; 15778ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Number of sub-components (i.e. instances of OffsetOfNode). 15788ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumComps; 15798ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Number of sub-expressions (i.e. array subscript expressions). 15808ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumExprs; 1581c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1582c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfExpr(ASTContext &C, QualType type, 15838ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation OperatorLoc, TypeSourceInfo *tsi, 1584c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode* compsPtr, unsigned numComps, 15858ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr** exprsPtr, unsigned numExprs, 15868ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc); 15878ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 15888ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor explicit OffsetOfExpr(unsigned numComps, unsigned numExprs) 15898ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor : Expr(OffsetOfExprClass, EmptyShell()), 1590c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt TSInfo(0), NumComps(numComps), NumExprs(numExprs) {} 15918ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 15928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregorpublic: 1593c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1594c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt static OffsetOfExpr *Create(ASTContext &C, QualType type, 1595c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt SourceLocation OperatorLoc, TypeSourceInfo *tsi, 1596c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt OffsetOfNode* compsPtr, unsigned numComps, 15978ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr** exprsPtr, unsigned numExprs, 15988ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc); 15998ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 1600c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt static OffsetOfExpr *CreateEmpty(ASTContext &C, 16018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumComps, unsigned NumExprs); 16028ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 16038ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// getOperatorLoc - Return the location of the operator. 16048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation getOperatorLoc() const { return OperatorLoc; } 16058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setOperatorLoc(SourceLocation L) { OperatorLoc = L; } 16068ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 16078ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Return the location of the right parentheses. 16088ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 16098ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setRParenLoc(SourceLocation R) { RParenLoc = R; } 1610c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 16118ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TypeSourceInfo *getTypeSourceInfo() const { 16128ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return TSInfo; 16138ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 16148ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setTypeSourceInfo(TypeSourceInfo *tsi) { 16158ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TSInfo = tsi; 16168ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1617c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 16188cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne const OffsetOfNode &getComponent(unsigned Idx) const { 16198ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumComps && "Subscript out of range"); 16208cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne return reinterpret_cast<const OffsetOfNode *> (this + 1)[Idx]; 16218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 16228ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 16238ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setComponent(unsigned Idx, OffsetOfNode ON) { 16248ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumComps && "Subscript out of range"); 16258ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<OffsetOfNode *> (this + 1)[Idx] = ON; 16268ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1627c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 16288ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned getNumComponents() const { 16298ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return NumComps; 16308ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 16318ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 16328ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr* getIndexExpr(unsigned Idx) { 16338ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumExprs && "Subscript out of range"); 16348ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return reinterpret_cast<Expr **>( 16358ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx]; 16368ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 16378cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne const Expr *getIndexExpr(unsigned Idx) const { 16388cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne return const_cast<OffsetOfExpr*>(this)->getIndexExpr(Idx); 16398cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne } 16408ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 16418ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor void setIndexExpr(unsigned Idx, Expr* E) { 16428ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor assert(Idx < NumComps && "Subscript out of range"); 16438ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<Expr **>( 16448ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx] = E; 16458ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1646c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 16478ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned getNumExpressions() const { 16488ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return NumExprs; 16498ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 16508ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 165163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 16528ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return SourceRange(OperatorLoc, RParenLoc); 16538ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 16548ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 16558ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor static bool classof(const Stmt *T) { 16568ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return T->getStmtClass() == OffsetOfExprClass; 16578ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 16588ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 16598ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor static bool classof(const OffsetOfExpr *) { return true; } 16608ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 16618ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Iterators 166263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 166363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt **begin = 166463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall reinterpret_cast<Stmt**>(reinterpret_cast<OffsetOfNode*>(this + 1) 166563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall + NumComps); 166663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(begin, begin + NumExprs); 166763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 16688ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor}; 16698ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 1670f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne/// UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) 1671f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne/// expression operand. Used for sizeof/alignof (C99 6.5.3.4) and 1672f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne/// vec_step (OpenCL 1.1 6.11.12). 1673f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourneclass UnaryExprOrTypeTraitExpr : public Expr { 1674f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne unsigned Kind : 2; 16750518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl bool isType : 1; // true if operand is a type, false if an expression 1676d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl union { 1677a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *Ty; 1678d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl Stmt *Ex; 1679d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl } Argument; 16805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation OpLoc, RParenLoc; 168142602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor 16825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1683f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, TypeSourceInfo *TInfo, 1684f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne QualType resultType, SourceLocation op, 1685f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne SourceLocation rp) : 1686f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_RValue, OK_Ordinary, 1687ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor false, // Never type-dependent (C++ [temp.dep.expr]p3). 16882850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl // Value-dependent if the argument is type-dependent. 1689bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor TInfo->getType()->isDependentType(), 1690561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor TInfo->getType()->isInstantiationDependentType(), 1691bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor TInfo->getType()->containsUnexpandedParameterPack()), 1692f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne Kind(ExprKind), isType(true), OpLoc(op), RParenLoc(rp) { 1693a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall Argument.Ty = TInfo; 1694ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor } 1695ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor 1696f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, Expr *E, 1697f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne QualType resultType, SourceLocation op, 1698f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne SourceLocation rp) : 1699f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_RValue, OK_Ordinary, 1700ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor false, // Never type-dependent (C++ [temp.dep.expr]p3). 1701ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor // Value-dependent if the argument is type-dependent. 1702bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor E->isTypeDependent(), 1703561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor E->isInstantiationDependent(), 1704bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor E->containsUnexpandedParameterPack()), 1705f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne Kind(ExprKind), isType(false), OpLoc(op), RParenLoc(rp) { 1706ba49817c5b9f502602672861cf369fd0e53966e8Douglas Gregor Argument.Ex = E; 1707d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl } 17080518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl 17090b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor /// \brief Construct an empty sizeof/alignof expression. 1710f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne explicit UnaryExprOrTypeTraitExpr(EmptyShell Empty) 1711f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne : Expr(UnaryExprOrTypeTraitExprClass, Empty) { } 17120b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 1713f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne UnaryExprOrTypeTrait getKind() const { 1714f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne return static_cast<UnaryExprOrTypeTrait>(Kind); 1715f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne } 1716f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne void setKind(UnaryExprOrTypeTrait K) { Kind = K; } 17170b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 17180518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl bool isArgumentType() const { return isType; } 17190518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType getArgumentType() const { 17205ab75172051a6d2ea71a80a79e81c65519fd3462John McCall return getArgumentTypeInfo()->getType(); 17215ab75172051a6d2ea71a80a79e81c65519fd3462John McCall } 1722a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *getArgumentTypeInfo() const { 17230518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl assert(isArgumentType() && "calling getArgumentType() when arg is expr"); 17245ab75172051a6d2ea71a80a79e81c65519fd3462John McCall return Argument.Ty; 17250518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 1726caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner Expr *getArgumentExpr() { 17270518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl assert(!isArgumentType() && "calling getArgumentExpr() when arg is type"); 1728d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl return static_cast<Expr*>(Argument.Ex); 17290518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 1730caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner const Expr *getArgumentExpr() const { 1731f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne return const_cast<UnaryExprOrTypeTraitExpr*>(this)->getArgumentExpr(); 1732caae7b099a0324b7c15dc89a9b70969d5d7ce996Chris Lattner } 17330b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 17340b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setArgument(Expr *E) { Argument.Ex = E; isType = false; } 1735a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall void setArgument(TypeSourceInfo *TInfo) { 1736a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall Argument.Ty = TInfo; 17371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump isType = true; 17380b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor } 17390b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 17400518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl /// Gets the argument type, or the type of the argument expression, whichever 17410518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl /// is appropriate. 17420518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl QualType getTypeOfArgument() const { 17430518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl return isArgumentType() ? getArgumentType() : getArgumentExpr()->getType(); 17440518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 17450518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl 174676e773a443be9f006610f46529e07d4c8d857680Chris Lattner SourceLocation getOperatorLoc() const { return OpLoc; } 17470b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setOperatorLoc(SourceLocation L) { OpLoc = L; } 17480b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor 17490b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 17500b0b77fa29c74c99a77548ed86ca8a04f7cf6b02Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1751866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek 175263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 1753866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek return SourceRange(OpLoc, RParenLoc); 1754866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek } 17555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 17561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 1757f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne return T->getStmtClass() == UnaryExprOrTypeTraitExprClass; 17585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1759f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne static bool classof(const UnaryExprOrTypeTraitExpr *) { return true; } 17601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 176177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 176263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children(); 17635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 17645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 17655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 17665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Postfix Operators. 17675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 17685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 17695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting. 17705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ArraySubscriptExpr : public Expr { 177177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek enum { LHS, RHS, END_EXPR=2 }; 17721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Stmt* SubExprs[END_EXPR]; 17735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation RBracketLoc; 17745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 17752324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t, 1776f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 177773d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SourceLocation rbracketloc) 1778f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ArraySubscriptExprClass, t, VK, OK, 17792850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl lhs->isTypeDependent() || rhs->isTypeDependent(), 1780bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor lhs->isValueDependent() || rhs->isValueDependent(), 1781561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (lhs->isInstantiationDependent() || 1782561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhs->isInstantiationDependent()), 1783bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (lhs->containsUnexpandedParameterPack() || 1784bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhs->containsUnexpandedParameterPack())), 17852850784bda09416fc7e9d57f5baa36c9351c757cSebastian Redl RBracketLoc(rbracketloc) { 178673d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SubExprs[LHS] = lhs; 178773d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner SubExprs[RHS] = rhs; 178873d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner } 17891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1790cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor /// \brief Create an empty array subscript expression. 1791cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor explicit ArraySubscriptExpr(EmptyShell Shell) 1792cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor : Expr(ArraySubscriptExprClass, Shell) { } 1793cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 17942324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// An array access can be written A[4] or 4[A] (both are equivalent). 17952324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// - getBase() and getIdx() always present the normalized view: A[4]. 17962324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// In this case getBase() returns "A" and getIdx() returns "4". 17972324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// - getLHS() and getRHS() present the syntactic view. e.g. for 17982324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek /// 4[A] getLHS() returns "4". 179933fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// Note: Because vector element access is also written A[4] we must 180033fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// predicate the format conversion in getBase and getIdx only on the 180133fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// the type of the RHS, as it is possible for the LHS to be a vector of 180233fd5c124aac15bab7cad95e4e0e7761356d2c06Christopher Lamb /// integer type 18035549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); } 18045549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 1805cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 1806cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 18075549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); } 18085549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 1809cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 18101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getBase() { 18125549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS()); 181377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek } 18141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr *getBase() const { 18165549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS()); 18172324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek } 18181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getIdx() { 18205549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS()); 18212324512285caac0332bbbc6e4cab6245d2a370a1Ted Kremenek } 18221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 182377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek const Expr *getIdx() const { 18245549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS()); 18251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 18261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 182763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 182877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek return SourceRange(getLHS()->getLocStart(), RBracketLoc); 18295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 18301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1831026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getRBracketLoc() const { return RBracketLoc; } 1832cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor void setRBracketLoc(SourceLocation L) { RBracketLoc = L; } 1833cb2ca73c1d7e76cc1358ce51457d2d5837d84f9bDouglas Gregor 183463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation getExprLoc() const { return getBase()->getExprLoc(); } 18355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 18361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 18371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ArraySubscriptExprClass; 18385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 18395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ArraySubscriptExpr *) { return true; } 18401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 184177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 184263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 184363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 184463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 18455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 18465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 18475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1848b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]). 18491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CallExpr itself represents a normal function call, e.g., "f(x, 2)", 1850b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// while its subclasses may represent alternative syntax that (semantically) 18511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// results in a function call. For example, CXXOperatorCallExpr is 1852b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// a subclass for overloaded operator calls that use operator syntax, e.g., 1853b4609806e9232593ece09ce08b630836e825865cDouglas Gregor/// "str1 + str2" to resolve to a function call. 18545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CallExpr : public Expr { 1855cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne enum { FN=0, PREARGS_START=1 }; 18565549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt **SubExprs; 18575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned NumArgs; 18585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation RParenLoc; 18591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1860b4609806e9232593ece09ce08b630836e825865cDouglas Gregorprotected: 1861cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne // These versions of the constructor are for derived classes. 1862cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExpr(ASTContext& C, StmtClass SC, Expr *fn, unsigned NumPreArgs, 1863cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne Expr **args, unsigned numargs, QualType t, ExprValueKind VK, 1864cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SourceLocation rparenloc); 1865cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne CallExpr(ASTContext &C, StmtClass SC, unsigned NumPreArgs, EmptyShell Empty); 1866cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne 1867cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne Stmt *getPreArg(unsigned i) { 1868cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne assert(i < getNumPreArgs() && "Prearg access out of range!"); 1869cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs[PREARGS_START+i]; 1870cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 1871cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne const Stmt *getPreArg(unsigned i) const { 1872cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne assert(i < getNumPreArgs() && "Prearg access out of range!"); 1873cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs[PREARGS_START+i]; 1874cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 1875cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne void setPreArg(unsigned i, Stmt *PreArg) { 1876cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne assert(i < getNumPreArgs() && "Prearg access out of range!"); 1877cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs[PREARGS_START+i] = PreArg; 1878cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 1879cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne 1880cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne unsigned getNumPreArgs() const { return CallExprBits.NumPreArgs; } 188142602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor 18825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 18831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, QualType t, 1884f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, SourceLocation rparenloc); 18851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18861f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor /// \brief Build an empty call expression. 1887ba0a9006dbc4814e1e35f82812cb5a1dad65e8b8Argyrios Kyrtzidis CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty); 18881f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 18895549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); } 18905549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCallee() { return cast<Expr>(SubExprs[FN]); } 189118b2515e1bf8c86a4900792692e42fe1296be28dChris Lattner void setCallee(Expr *F) { SubExprs[FN] = F; } 1892a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 1893d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes Decl *getCalleeDecl(); 1894d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes const Decl *getCalleeDecl() const { 1895d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes return const_cast<CallExpr*>(this)->getCalleeDecl(); 1896d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes } 1897d20254f2875d0004c57ee766f258dbcee29f4841Nuno Lopes 1898a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu /// \brief If the callee is a FunctionDecl, return it. Otherwise return 0. 1899a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu FunctionDecl *getDirectCallee(); 1900bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner const FunctionDecl *getDirectCallee() const { 1901bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner return const_cast<CallExpr*>(this)->getDirectCallee(); 1902bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6Chris Lattner } 1903a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 19045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getNumArgs - Return the number of actual arguments to this call. 19055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 19065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumArgs() const { return NumArgs; } 19071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1908aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \brief Retrieve the call arguments. 1909cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne Expr **getArgs() { 1910cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return reinterpret_cast<Expr **>(SubExprs+getNumPreArgs()+PREARGS_START); 1911cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 1912aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 19135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getArg - Return the specified argument. 19145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Expr *getArg(unsigned Arg) { 19155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(Arg < NumArgs && "Arg access out of range!"); 1916cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return cast<Expr>(SubExprs[Arg+getNumPreArgs()+PREARGS_START]); 19175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 19185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const Expr *getArg(unsigned Arg) const { 19195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(Arg < NumArgs && "Arg access out of range!"); 1920cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return cast<Expr>(SubExprs[Arg+getNumPreArgs()+PREARGS_START]); 19215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 19221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1923934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff /// setArg - Set the specified argument. 1924934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff void setArg(unsigned Arg, Expr *ArgExpr) { 1925934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff assert(Arg < NumArgs && "Arg access out of range!"); 1926cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne SubExprs[Arg+getNumPreArgs()+PREARGS_START] = ArgExpr; 1927934f276cc5b45e19cd12ebb2d04fd7972a23865cSteve Naroff } 19281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1929d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// setNumArgs - This changes the number of arguments present in this call. 1930d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// Any orphaned expressions are deleted by this, and any new operands are set 1931d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner /// to null. 19328189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek void setNumArgs(ASTContext& C, unsigned NumArgs); 19331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19345549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek typedef ExprIterator arg_iterator; 19355549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek typedef ConstExprIterator const_arg_iterator; 19361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1937cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne arg_iterator arg_begin() { return SubExprs+PREARGS_START+getNumPreArgs(); } 1938cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne arg_iterator arg_end() { 1939cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs+PREARGS_START+getNumPreArgs()+getNumArgs(); 1940cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 1941cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne const_arg_iterator arg_begin() const { 1942cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs+PREARGS_START+getNumPreArgs(); 1943cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 1944cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne const_arg_iterator arg_end() const { 1945cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne return SubExprs+PREARGS_START+getNumPreArgs()+getNumArgs(); 1946cc324ad80ab940efca006b0064f7ca70a6181816Peter Collingbourne } 19471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getNumCommas - Return the number of commas that must have been present in 19495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// this function call. 19505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; } 19515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1952cb888967400a03504c88acedd5248d6778a82f46Chris Lattner /// isBuiltinCall - If this is a call to a builtin, return the builtin ID. If 1953cb888967400a03504c88acedd5248d6778a82f46Chris Lattner /// not, return 0. 19544ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad unsigned isBuiltinCall(const ASTContext &Context) const; 19551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// getCallReturnType - Get the return type of the call expr. This is not 19571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// always the type of the expr itself, if the return type is a reference 19586dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson /// type. 19596dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson QualType getCallReturnType() const; 19601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1961d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner SourceLocation getRParenLoc() const { return RParenLoc; } 19621f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1963866b5c03e3b9c01cf496ad97b85a05afc917345bTed Kremenek 19642882eca5a184c78f793188083f6ce539740a5cf2John McCall SourceRange getSourceRange() const; 19651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 19674bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return T->getStmtClass() >= firstCallExprConstant && 19684bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt T->getStmtClass() <= lastCallExprConstant; 19695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 19705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CallExpr *) { return true; } 197188a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor 197277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek // Iterators 197363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 197463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], 197563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall &SubExprs[0]+NumArgs+getNumPreArgs()+PREARGS_START); 197663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 19775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 19785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1979ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner/// MemberExpr - [C99 6.5.2.3] Structure and Union Members. X->F and X.F. 19805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 19815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass MemberExpr : public Expr { 19826bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// Extra data stored in some member expressions. 19836857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth struct MemberNameQualifier { 19846857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// \brief The nested-name-specifier that qualifies the name, including 19856857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// source-location information. 19866857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth NestedNameSpecifierLoc QualifierLoc; 19876857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth 19886857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// \brief The DeclAccessPair through which the MemberDecl was found due to 19896857c3e12c86fd0271eb46baab5b18756a94f4cbChandler Carruth /// name qualifiers. 1990161755a09898c95d21bfff33707da9ca41cd53c5John McCall DeclAccessPair FoundDecl; 19916bb8017bb9e828d118e15e59d71c66bba323c364John McCall }; 19926bb8017bb9e828d118e15e59d71c66bba323c364John McCall 1993ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// Base - the expression for the base pointer or structure references. In 1994ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// X.F, this is "X". 19955549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Base; 19961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1997ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// MemberDecl - This is the decl being referenced by the field/member name. 1998ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// In X.F, this is the decl referenced by F. 1999f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *MemberDecl; 20001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2001ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// MemberLoc - This is the location of the member name. 20025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation MemberLoc; 20031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20042577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// MemberDNLoc - Provides source/type location info for the 20052577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// declaration name embedded in MemberDecl. 20062577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameLoc MemberDNLoc; 20072577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 2008ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// IsArrow - True if this is "X->F", false if this is "X.F". 200983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor bool IsArrow : 1; 20101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 201183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief True if this member expression used a nested-name-specifier to 20126bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// refer to the member, e.g., "x->Base::f", or found its member via a using 20136bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// declaration. When true, a MemberNameQualifier 2014c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// structure is allocated immediately after the MemberExpr. 20156bb8017bb9e828d118e15e59d71c66bba323c364John McCall bool HasQualifierOrFoundDecl : 1; 20161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2017c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief True if this member expression specified a template argument list 2018c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// explicitly, e.g., x->f<int>. When true, an ExplicitTemplateArgumentList 2019c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// structure (and its TemplateArguments) are allocated immediately after 2020c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// the MemberExpr or, if the member expression also has a qualifier, after 20216bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// the MemberNameQualifier structure. 2022c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor bool HasExplicitTemplateArgumentList : 1; 20231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 202483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief Retrieve the qualifier that preceded the member name, if any. 20256bb8017bb9e828d118e15e59d71c66bba323c364John McCall MemberNameQualifier *getMemberQualifier() { 20266bb8017bb9e828d118e15e59d71c66bba323c364John McCall assert(HasQualifierOrFoundDecl); 20276bb8017bb9e828d118e15e59d71c66bba323c364John McCall return reinterpret_cast<MemberNameQualifier *> (this + 1); 202883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 202983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor 203083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// \brief Retrieve the qualifier that preceded the member name, if any. 20316bb8017bb9e828d118e15e59d71c66bba323c364John McCall const MemberNameQualifier *getMemberQualifier() const { 2032c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return const_cast<MemberExpr *>(this)->getMemberQualifier(); 2033c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 20341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 2036f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl, 2037f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall const DeclarationNameInfo &NameInfo, QualType ty, 2038f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK) 2039f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(MemberExprClass, ty, VK, OK, 2040561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor base->isTypeDependent(), 2041561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor base->isValueDependent(), 2042561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor base->isInstantiationDependent(), 2043bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->containsUnexpandedParameterPack()), 20442577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Base(base), MemberDecl(memberdecl), MemberLoc(NameInfo.getLoc()), 20452577743c5650c646fb705df01403707e94f2df04Abramo Bagnara MemberDNLoc(NameInfo.getInfo()), IsArrow(isarrow), 20462577743c5650c646fb705df01403707e94f2df04Abramo Bagnara HasQualifierOrFoundDecl(false), HasExplicitTemplateArgumentList(false) { 20472577743c5650c646fb705df01403707e94f2df04Abramo Bagnara assert(memberdecl->getDeclName() == NameInfo.getName()); 20482577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 20492577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 20502577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // NOTE: this constructor should be used only when it is known that 20512577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // the member name can not provide additional syntactic info 20522577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // (i.e., source locations for C++ operator names or type source info 20532577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // for constructors, destructors and conversion oeprators). 20542577743c5650c646fb705df01403707e94f2df04Abramo Bagnara MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl, 2055f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall SourceLocation l, QualType ty, 2056f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK) 2057f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(MemberExprClass, ty, VK, OK, 2058bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->isTypeDependent(), base->isValueDependent(), 2059561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor base->isInstantiationDependent(), 2060bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->containsUnexpandedParameterPack()), 20612577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Base(base), MemberDecl(memberdecl), MemberLoc(l), MemberDNLoc(), 20622577743c5650c646fb705df01403707e94f2df04Abramo Bagnara IsArrow(isarrow), 20636bb8017bb9e828d118e15e59d71c66bba323c364John McCall HasQualifierOrFoundDecl(false), HasExplicitTemplateArgumentList(false) {} 2064510190777c4bd53e960eea4665b204778fec1b64Eli Friedman 20651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static MemberExpr *Create(ASTContext &C, Expr *base, bool isarrow, 206640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 2067161755a09898c95d21bfff33707da9ca41cd53c5John McCall ValueDecl *memberdecl, DeclAccessPair founddecl, 20682577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo MemberNameInfo, 2069d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *targs, 2070f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType ty, ExprValueKind VK, ExprObjectKind OK); 20711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 207288a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor void setBase(Expr *E) { Base = E; } 20735549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getBase() const { return cast<Expr>(Base); } 207457e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor 207557e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// \brief Retrieve the member declaration to which this expression refers. 207657e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// 207757e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// The returned declaration will either be a FieldDecl or (in C++) 207857e8b05fe9ba03d410db9c161e032cb79c9ab5baDouglas Gregor /// a CXXMethodDecl. 2079f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *getMemberDecl() const { return MemberDecl; } 2080f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman void setMemberDecl(ValueDecl *D) { MemberDecl = D; } 20811f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 20826bb8017bb9e828d118e15e59d71c66bba323c364John McCall /// \brief Retrieves the declaration found by lookup. 2083161755a09898c95d21bfff33707da9ca41cd53c5John McCall DeclAccessPair getFoundDecl() const { 20846bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (!HasQualifierOrFoundDecl) 2085161755a09898c95d21bfff33707da9ca41cd53c5John McCall return DeclAccessPair::make(getMemberDecl(), 2086161755a09898c95d21bfff33707da9ca41cd53c5John McCall getMemberDecl()->getAccess()); 20876bb8017bb9e828d118e15e59d71c66bba323c364John McCall return getMemberQualifier()->FoundDecl; 20886bb8017bb9e828d118e15e59d71c66bba323c364John McCall } 20896bb8017bb9e828d118e15e59d71c66bba323c364John McCall 20901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Determines whether this member expression actually had 20910979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor /// a C++ nested-name-specifier prior to the name of the member, e.g., 20920979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor /// x->Base::foo. 20936bb8017bb9e828d118e15e59d71c66bba323c364John McCall bool hasQualifier() const { return getQualifier() != 0; } 20941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief If the member name was qualified, retrieves the 209683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// nested-name-specifier that precedes the member name. Otherwise, returns 209783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor /// NULL. 20981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump NestedNameSpecifier *getQualifier() const { 20996bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (!HasQualifierOrFoundDecl) 210083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return 0; 21011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 210240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return getMemberQualifier()->QualifierLoc.getNestedNameSpecifier(); 210340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor } 210440d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor 210540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor /// \brief If the member name was qualified, retrieves the 210640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor /// nested-name-specifier that precedes the member name, with source-location 210740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor /// information. 210840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc getQualifierLoc() const { 210940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (!hasQualifier()) 211040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return NestedNameSpecifierLoc(); 211140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor 211240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return getMemberQualifier()->QualifierLoc; 211383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 2114c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor 2115c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Determines whether this member expression actually had a C++ 2116c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template argument list explicitly specified, e.g., x.f<int>. 2117096832c5ed5b9106fa177ebc148489760c3bc496John McCall bool hasExplicitTemplateArgs() const { 21181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return HasExplicitTemplateArgumentList; 2119c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 21201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2121d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// \brief Copies the template arguments (if present) into the given 2122d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall /// structure. 2123d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { 2124096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (hasExplicitTemplateArgs()) 2125096832c5ed5b9106fa177ebc148489760c3bc496John McCall getExplicitTemplateArgs().copyInto(List); 2126096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 2127096832c5ed5b9106fa177ebc148489760c3bc496John McCall 2128096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that 2129096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// follow the member template name. This must only be called on an 2130096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// expression with explicit template arguments. 2131b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis ASTTemplateArgumentListInfo &getExplicitTemplateArgs() { 2132096832c5ed5b9106fa177ebc148489760c3bc496John McCall assert(HasExplicitTemplateArgumentList); 2133096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!HasQualifierOrFoundDecl) 2134b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis return *reinterpret_cast<ASTTemplateArgumentListInfo *>(this + 1); 2135096832c5ed5b9106fa177ebc148489760c3bc496John McCall 2136b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis return *reinterpret_cast<ASTTemplateArgumentListInfo *>( 2137096832c5ed5b9106fa177ebc148489760c3bc496John McCall getMemberQualifier() + 1); 2138096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 2139096832c5ed5b9106fa177ebc148489760c3bc496John McCall 2140096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieve the explicit template argument list that 2141096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// followed the member template name. This must only be called on 2142096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// an expression with explicit template arguments. 2143b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const { 2144096832c5ed5b9106fa177ebc148489760c3bc496John McCall return const_cast<MemberExpr *>(this)->getExplicitTemplateArgs(); 2145096832c5ed5b9106fa177ebc148489760c3bc496John McCall } 2146096832c5ed5b9106fa177ebc148489760c3bc496John McCall 2147096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// \brief Retrieves the optional explicit template arguments. 2148096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// This points to the same data as getExplicitTemplateArgs(), but 2149096832c5ed5b9106fa177ebc148489760c3bc496John McCall /// returns null if there are no explicit template arguments. 2150b0c3e0909bb04af0bfb82ad01ab6909649d68ccaArgyrios Kyrtzidis const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() const { 2151096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (!hasExplicitTemplateArgs()) return 0; 2152096832c5ed5b9106fa177ebc148489760c3bc496John McCall return &getExplicitTemplateArgs(); 2153d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall } 2154c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 21551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Retrieve the location of the left angle bracket following the 2156c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// member name ('<'), if any. 21571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation getLAngleLoc() const { 2158c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 2159c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return SourceLocation(); 21601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2161096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().LAngleLoc; 2162c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 21631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2164c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Retrieve the template arguments provided as part of this 2165c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template-id. 2166833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc *getTemplateArgs() const { 2167c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 21681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return 0; 21691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2170096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().getTemplateArgs(); 2171c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 21721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2173c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// \brief Retrieve the number of template arguments provided as part of this 2174c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template-id. 21751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned getNumTemplateArgs() const { 2176c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 21771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return 0; 21781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2179096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().NumTemplateArgs; 2180c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 21811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Retrieve the location of the right angle bracket following the 2183c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor /// template arguments ('>'). 21841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation getRAngleLoc() const { 2185c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (!HasExplicitTemplateArgumentList) 2186c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return SourceLocation(); 21871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2188096832c5ed5b9106fa177ebc148489760c3bc496John McCall return getExplicitTemplateArgs().RAngleLoc; 2189c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 21901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21912577743c5650c646fb705df01403707e94f2df04Abramo Bagnara /// \brief Retrieve the member declaration name info. 21922577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo getMemberNameInfo() const { 21932577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(MemberDecl->getDeclName(), 21942577743c5650c646fb705df01403707e94f2df04Abramo Bagnara MemberLoc, MemberDNLoc); 21952577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 21962577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 21975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isArrow() const { return IsArrow; } 21981f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setArrow(bool A) { IsArrow = A; } 21991f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 2200ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// getMemberLoc - Return the location of the "member", in X->F, it is the 2201ddca44e86281bb7dcf5fdcaf1563434c524e3861Chris Lattner /// location of 'F'. 2202026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getMemberLoc() const { return MemberLoc; } 22031f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor void setMemberLoc(SourceLocation L) { MemberLoc = L; } 22045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 220575e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor SourceRange getSourceRange() const; 220675e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 220763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceLocation getExprLoc() const { return MemberLoc; } 22085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 220975e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor /// \brief Determine whether the base of this explicit is implicit. 221075e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor bool isImplicitAccess() const { 221175e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor return getBase() && getBase()->isImplicitCXXThis(); 221275e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor } 221375e85048e73fcde2ce9d8a48dfdb1220e132eb59Douglas Gregor 22141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 221583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor return T->getStmtClass() == MemberExprClass; 22165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 22175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const MemberExpr *) { return true; } 22181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22191237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 222063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Base, &Base+1); } 22214045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis 22224045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTReader; 22234045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis friend class ASTStmtWriter; 22245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 22255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 22261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// CompoundLiteralExpr - [C99 6.5.2.5] 2227aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff/// 2228aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffclass CompoundLiteralExpr : public Expr { 22290fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// LParenLoc - If non-null, this is the location of the left paren in a 22300fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// compound literal like "(int){4}". This can be null if this is a 22310fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner /// synthesized compound expression. 22320fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner SourceLocation LParenLoc; 22331d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall 22341d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall /// The type as written. This can be an incomplete array type, in 22351d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall /// which case the actual expression type will be different. 223642f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *TInfo; 22375549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Init; 2238e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff bool FileScope; 2239aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroffpublic: 224042f56b50062cd3b3c6b23fdb9053578ae9145664John McCall CompoundLiteralExpr(SourceLocation lparenloc, TypeSourceInfo *tinfo, 2241f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType T, ExprValueKind VK, Expr *init, bool fileScope) 2242f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CompoundLiteralExprClass, T, VK, OK_Ordinary, 2243bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor tinfo->getType()->isDependentType(), 2244bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor init->isValueDependent(), 2245561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (init->isInstantiationDependent() || 2246561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor tinfo->getType()->isInstantiationDependentType()), 2247bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor init->containsUnexpandedParameterPack()), 224842f56b50062cd3b3c6b23fdb9053578ae9145664John McCall LParenLoc(lparenloc), TInfo(tinfo), Init(init), FileScope(fileScope) {} 22491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2250ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor /// \brief Construct an empty compound literal. 2251ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor explicit CompoundLiteralExpr(EmptyShell Empty) 2252ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor : Expr(CompoundLiteralExprClass, Empty) { } 2253ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 22545549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getInitializer() const { return cast<Expr>(Init); } 22555549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getInitializer() { return cast<Expr>(Init); } 2256ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setInitializer(Expr *E) { Init = E; } 2257e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff 2258e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff bool isFileScope() const { return FileScope; } 2259ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setFileScope(bool FS) { FileScope = FS; } 2260ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 22610fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner SourceLocation getLParenLoc() const { return LParenLoc; } 2262ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor void setLParenLoc(SourceLocation L) { LParenLoc = L; } 2263ba6d7e7fa5f79959d3eef39adb5620d845ba5198Douglas Gregor 226442f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *getTypeSourceInfo() const { return TInfo; } 226542f56b50062cd3b3c6b23fdb9053578ae9145664John McCall void setTypeSourceInfo(TypeSourceInfo* tinfo) { TInfo = tinfo; } 226642f56b50062cd3b3c6b23fdb9053578ae9145664John McCall 226763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 22680fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner // FIXME: Init should never be null. 22690fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner if (!Init) 22700fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner return SourceRange(); 22710fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner if (LParenLoc.isInvalid()) 227273d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner return Init->getSourceRange(); 22730fc53dfc7a33f68e71ef245389c4e7cd34a62a39Chris Lattner return SourceRange(LParenLoc, Init->getLocEnd()); 227473d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner } 2275aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff 22761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 22771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CompoundLiteralExprClass; 2278aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff } 2279aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff static bool classof(const CompoundLiteralExpr *) { return true; } 22801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22811237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 228263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Init, &Init+1); } 2283aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff}; 2284aff1edd84aaafef15b737acd8ec61abcca6d6bc3Steve Naroff 228549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// CastExpr - Base class for type casts, including both implicit 228649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// casts (ImplicitCastExpr) and explicit casts that have some 228749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// representation in the source code (ExplicitCastExpr's derived 228849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// classes). 22890835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass CastExpr : public Expr { 2290cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlssonpublic: 22915baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall typedef clang::CastKind CastKind; 22921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2293cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4Anders Carlssonprivate: 22940835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis Stmt *Op; 2295409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson 22961d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall void CheckCastConsistency() const; 2297409c99edb8b623403fade6f3a9e9c86acda74455Anders Carlsson 2298f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXBaseSpecifier * const *path_buffer() const { 2299f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall return const_cast<CastExpr*>(this)->path_buffer(); 2300f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall } 2301f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CXXBaseSpecifier **path_buffer(); 2302f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2303654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis void setBasePathSize(unsigned basePathSize) { 2304654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis CastExprBits.BasePathSize = basePathSize; 2305654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis assert(CastExprBits.BasePathSize == basePathSize && 2306654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis "basePathSize doesn't fit in bits of CastExprBits.BasePathSize!"); 2307654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis } 2308654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis 23090835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisprotected: 2310f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CastExpr(StmtClass SC, QualType ty, ExprValueKind VK, 2311f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall const CastKind kind, Expr *op, unsigned BasePathSize) : 2312f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(SC, ty, VK, OK_Ordinary, 2313898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Cast expressions are type-dependent if the type is 2314898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // dependent (C++ [temp.dep.expr]p3). 2315898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ty->isDependentType(), 2316898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Cast expressions are value-dependent if the type is 2317898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // dependent or if the subexpression is value-dependent. 2318bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor ty->isDependentType() || (op && op->isValueDependent()), 2319561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (ty->isInstantiationDependentType() || 2320561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (op && op->isInstantiationDependent())), 2321bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (ty->containsUnexpandedParameterPack() || 2322bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor op->containsUnexpandedParameterPack())), 23238e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall Op(op) { 2324daa8e4e888758d55a7a759dd4a91b83921cef222John McCall assert(kind != CK_Invalid && "creating cast with invalid cast kind"); 23258e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CastExprBits.Kind = kind; 2326654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis setBasePathSize(BasePathSize); 23271d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall#ifndef NDEBUG 2328daa8e4e888758d55a7a759dd4a91b83921cef222John McCall CheckCastConsistency(); 23291d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall#endif 2330f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall } 23311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2332087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor /// \brief Construct an empty cast. 2333f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastExpr(StmtClass SC, EmptyShell Empty, unsigned BasePathSize) 23348e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall : Expr(SC, Empty) { 2335654f6b2b53af2c950c62ef0161fa021648accbcbArgyrios Kyrtzidis setBasePathSize(BasePathSize); 23368e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall } 23371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23380835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidispublic: 23398e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall CastKind getCastKind() const { return (CastKind) CastExprBits.Kind; } 23408e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall void setCastKind(CastKind K) { CastExprBits.Kind = K; } 2341f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson const char *getCastKindName() const; 2342f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson 23430835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis Expr *getSubExpr() { return cast<Expr>(Op); } 23440835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis const Expr *getSubExpr() const { return cast<Expr>(Op); } 2345087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor void setSubExpr(Expr *E) { Op = E; } 2346087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor 23476eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// \brief Retrieve the cast subexpression as it was written in the source 23486eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// code, looking through any implicit casts or other intermediate nodes 23496eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// introduced by semantic analysis. 23506eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor Expr *getSubExprAsWritten(); 23516eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor const Expr *getSubExprAsWritten() const { 23526eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return const_cast<CastExpr *>(this)->getSubExprAsWritten(); 23536eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor } 235441b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson 2355f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall typedef CXXBaseSpecifier **path_iterator; 2356f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall typedef const CXXBaseSpecifier * const *path_const_iterator; 23578e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall bool path_empty() const { return CastExprBits.BasePathSize == 0; } 23588e6285af719adc6f86d6faa235d22a08eb68ee3aJohn McCall unsigned path_size() const { return CastExprBits.BasePathSize; } 2359f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_iterator path_begin() { return path_buffer(); } 2360f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_iterator path_end() { return path_buffer() + path_size(); } 2361f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_const_iterator path_begin() const { return path_buffer(); } 2362f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall path_const_iterator path_end() const { return path_buffer() + path_size(); } 2363f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2364f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall void setCastPath(const CXXCastPath &Path); 236541b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson 23661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 23674bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return T->getStmtClass() >= firstCastExprConstant && 23684bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt T->getStmtClass() <= lastCastExprConstant; 23690835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis } 23700835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis static bool classof(const CastExpr *) { return true; } 23711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23720835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis // Iterators 237363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Op, &Op+1); } 23740835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis}; 23750835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis 237649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ImplicitCastExpr - Allows us to explicitly represent implicit type 237749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// conversions, which have no direct representation in the original 237849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// source code. For example: converting T[]->T*, void f()->void 237949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (*f)(), float->double, short->int, etc. 238049b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff/// 2381bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// In C, implicit casts always produce rvalues. However, in C++, an 2382bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// implicit cast whose result is being bound to a reference will be 2383906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// an lvalue or xvalue. For example: 2384bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// 2385bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @code 2386bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Base { }; 2387bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// class Derived : public Base { }; 2388906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// Derived &&ref(); 23891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// void f(Derived d) { 2390906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// Base& b = d; // initializer is an ImplicitCastExpr 2391906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// // to an lvalue of type Base 2392906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// Base&& r = ref(); // initializer is an ImplicitCastExpr 2393906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// // to an xvalue of type Base 2394bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// } 2395bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor/// @endcode 23960835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ImplicitCastExpr : public CastExpr { 2397906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redlprivate: 2398f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ImplicitCastExpr(QualType ty, CastKind kind, Expr *op, 23995baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall unsigned BasePathLength, ExprValueKind VK) 2400f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, BasePathLength) { 24015baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall } 240290045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff 2403087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor /// \brief Construct an empty implicit cast. 2404f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall explicit ImplicitCastExpr(EmptyShell Shell, unsigned PathSize) 2405f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : CastExpr(ImplicitCastExprClass, Shell, PathSize) { } 2406f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2407f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 2408f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall enum OnStack_t { OnStack }; 2409f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ImplicitCastExpr(OnStack_t _, QualType ty, CastKind kind, Expr *op, 24105baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall ExprValueKind VK) 2411f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, 0) { 24125baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall } 2413f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2414f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static ImplicitCastExpr *Create(ASTContext &Context, QualType T, 2415f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall CastKind Kind, Expr *Operand, 2416f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall const CXXCastPath *BasePath, 24175baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall ExprValueKind Cat); 2418f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2419f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static ImplicitCastExpr *CreateEmpty(ASTContext &Context, unsigned PathSize); 2420087fd536809ebe754d91c641a98917e02dd7452dDouglas Gregor 242163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 24220835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis return getSubExpr()->getSourceRange(); 24230835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis } 242490045e8ebabf50d6f1b3a67081a621b20b5e5341Steve Naroff 24251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 24261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ImplicitCastExprClass; 242749b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff } 242849b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff static bool classof(const ImplicitCastExpr *) { return true; } 242949b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff}; 243049b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff 243191a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCallinline Expr *Expr::IgnoreImpCasts() { 243291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall Expr *e = this; 243391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall while (ImplicitCastExpr *ice = dyn_cast<ImplicitCastExpr>(e)) 243491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall e = ice->getSubExpr(); 243591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall return e; 243691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall} 243791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 243849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// ExplicitCastExpr - An explicit cast written in the source 24391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// code. 244049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// 244149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// This class is effectively an abstract class, because it provides 244249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// the basic representation of an explicitly-written cast without 244349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// specifying which kind of cast (C cast, functional cast, static 244449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast, etc.) was written; specific derived classes represent the 244549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// particular style of cast and its location information. 24465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 244749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// Unlike implicit casts, explicit cast nodes have two different 244849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// types: the type that was written into the source code, and the 244949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// actual type of the expression as determined by semantic 245049badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// analysis. These types may differ slightly. For example, in C++ one 245149badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// can cast to a reference type, which indicates that the resulting 2452906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// expression will be an lvalue or xvalue. The reference type, however, 2453906082edf2aea1c6de2926f93a8d7121e49d2a54Sebastian Redl/// will not be used as the type of the expression. 24540835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidisclass ExplicitCastExpr : public CastExpr { 24559d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// TInfo - Source type info for the (written) type 24569d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// this expression is casting to. 24579d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo; 245849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 245949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorprotected: 2460f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExplicitCastExpr(StmtClass SC, QualType exprTy, ExprValueKind VK, 2461f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CastKind kind, Expr *op, unsigned PathSize, 2462f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall TypeSourceInfo *writtenTy) 2463f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : CastExpr(SC, exprTy, VK, kind, op, PathSize), TInfo(writtenTy) {} 246449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 2465db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty explicit cast. 2466f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall ExplicitCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize) 2467f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : CastExpr(SC, Shell, PathSize) { } 2468db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 246949badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregorpublic: 24709d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// getTypeInfoAsWritten - Returns the type source info for the type 24719d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall /// that this expression is casting to. 24729d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *getTypeInfoAsWritten() const { return TInfo; } 24739d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall void setTypeInfoAsWritten(TypeSourceInfo *writtenTy) { TInfo = writtenTy; } 24749d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall 247549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// getTypeAsWritten - Returns the type that this expression is 247649badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor /// casting to, as written in the source code. 24779d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall QualType getTypeAsWritten() const { return TInfo->getType(); } 247849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 24791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 24804bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return T->getStmtClass() >= firstExplicitCastExprConstant && 24814bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt T->getStmtClass() <= lastExplicitCastExprConstant; 248249badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor } 248349badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor static bool classof(const ExplicitCastExpr *) { return true; } 248449badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor}; 248549badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor 24866eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor/// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style 248749badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// cast in C++ (C++ [expr.cast]), which uses the syntax 248849badde06e066d058d6c7fcf4e628a72999b65a9Douglas Gregor/// (Type)expr. For example: @c (int)f. 24896eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregorclass CStyleCastExpr : public ExplicitCastExpr { 2490b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation LPLoc; // the location of the left paren 2491b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation RPLoc; // the location of the right paren 2492f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2493f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CStyleCastExpr(QualType exprTy, ExprValueKind vk, CastKind kind, Expr *op, 2494f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall unsigned PathSize, TypeSourceInfo *writtenTy, 249541b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson SourceLocation l, SourceLocation r) 2496f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : ExplicitCastExpr(CStyleCastExprClass, exprTy, vk, kind, op, PathSize, 249741b2dcd465f1e438502c420effc9d0c747f9db8fAnders Carlsson writtenTy), LPLoc(l), RPLoc(r) {} 249849b4526992a8c8a6a290aa3efa9828154a24af8dSteve Naroff 2499db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty C-style explicit cast. 2500f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall explicit CStyleCastExpr(EmptyShell Shell, unsigned PathSize) 2501f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall : ExplicitCastExpr(CStyleCastExprClass, Shell, PathSize) { } 2502f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2503f871d0cc377a1367b519a6cce26be74607566ebaJohn McCallpublic: 2504f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall static CStyleCastExpr *Create(ASTContext &Context, QualType T, 2505f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, CastKind K, 2506f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall Expr *Op, const CXXCastPath *BasePath, 2507f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall TypeSourceInfo *WrittenTy, SourceLocation L, 2508f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall SourceLocation R); 2509f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall 2510f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall static CStyleCastExpr *CreateEmpty(ASTContext &Context, unsigned PathSize); 2511db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 2512b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation getLParenLoc() const { return LPLoc; } 2513db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setLParenLoc(SourceLocation L) { LPLoc = L; } 2514db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 2515b2f9e516327310d95840d442416084508f80c183Steve Naroff SourceLocation getRParenLoc() const { return RPLoc; } 2516db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setRParenLoc(SourceLocation L) { RPLoc = L; } 2517db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 251863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 2519b2f9e516327310d95840d442416084508f80c183Steve Naroff return SourceRange(LPLoc, getSubExpr()->getSourceRange().getEnd()); 25205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 25211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 25221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == CStyleCastExprClass; 25235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 25246eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor static bool classof(const CStyleCastExpr *) { return true; } 25255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 25265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 25273fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// \brief A builtin binary operation expression such as "x + y" or "x <= y". 25283fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 25293fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// This expression node kind describes a builtin binary operation, 25303fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// such as "x + y" for integer values "x" and "y". The operands will 25313fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// already have been converted to appropriate types (e.g., by 25323fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// performing promotions or conversions). 25333fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// 25343fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// In C++, where operators may be overloaded, a different kind of 25353fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// expression node (CXXOperatorCallExpr) is used to express the 25363fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// invocation of an overloaded operator with operator syntax. Within 25373fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is 25383fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to store an expression "x + y" depends on the subexpressions 25393fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// for x and y. If neither x or y is type-dependent, and the "+" 25403fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// operator resolves to a built-in operation, BinaryOperator will be 25413fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// used to express the computation (x and y may still be 25423fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// value-dependent). If either x or y is type-dependent, or if the 25433fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// "+" resolves to an overloaded operator, CXXOperatorCallExpr will 25443fd95ce225393fe4a3623e429766a8c3f487ff9dDouglas Gregor/// be used to express the computation. 25455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BinaryOperator : public Expr { 25465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 25475baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall typedef BinaryOperatorKind Opcode; 25485baba9d98364a3525d6afa15a04cdad82fd6dd30John McCall 254917d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattnerprivate: 25500799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall unsigned Opc : 6; 25510799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall SourceLocation OpLoc; 25520799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall 255317d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner enum { LHS, RHS, END_EXPR }; 25545549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; 25551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 25561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 255717d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 2558f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 255917d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation opLoc) 2560f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(BinaryOperatorClass, ResTy, VK, OK, 2561898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor lhs->isTypeDependent() || rhs->isTypeDependent(), 2562bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor lhs->isValueDependent() || rhs->isValueDependent(), 2563561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (lhs->isInstantiationDependent() || 2564561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhs->isInstantiationDependent()), 2565bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (lhs->containsUnexpandedParameterPack() || 2566bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhs->containsUnexpandedParameterPack())), 2567898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Opc(opc), OpLoc(opLoc) { 25681237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 25691237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 25701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(!isCompoundAssignmentOp() && 25715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Use ArithAssignBinaryOperator for compound assignments"); 25725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 25735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2574db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor /// \brief Construct an empty binary operator. 25751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit BinaryOperator(EmptyShell Empty) 25762de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall : Expr(BinaryOperatorClass, Empty), Opc(BO_Comma) { } 2577db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 257817d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation getOperatorLoc() const { return OpLoc; } 2579db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setOperatorLoc(SourceLocation L) { OpLoc = L; } 2580db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 25810799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall Opcode getOpcode() const { return static_cast<Opcode>(Opc); } 2582db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setOpcode(Opcode O) { Opc = O; } 2583db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 25845549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 2585db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 25865549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 2587db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 2588db600c330a37b1c3ab4533310729910ee188f900Douglas Gregor 258963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 25905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd()); 25915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 25921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 25945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// corresponds to, e.g. "<<=". 25955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static const char *getOpcodeStr(Opcode Op); 25965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 25970799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall const char *getOpcodeStr() const { return getOpcodeStr(getOpcode()); } 2598a84c02d0f4d63975a1c52b9bb8308d88e9d79352Ted Kremenek 2599063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// \brief Retrieve the binary opcode that corresponds to the given 2600063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// overloaded operator. 2601063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static Opcode getOverloadedOpcode(OverloadedOperatorKind OO); 2602063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 2603063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// \brief Retrieve the overloaded operator kind that corresponds to 2604063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /// the given binary opcode. 2605063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); 2606063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 26075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// predicates to categorize the respective opcodes. 2608200121569dc6cff10a1fb6ed7500098770b9dd25Sebastian Redl bool isPtrMemOp() const { return Opc == BO_PtrMemD || Opc == BO_PtrMemI; } 26092de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall bool isMultiplicativeOp() const { return Opc >= BO_Mul && Opc <= BO_Rem; } 26102de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isAdditiveOp(Opcode Opc) { return Opc == BO_Add || Opc==BO_Sub; } 26110799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isAdditiveOp() const { return isAdditiveOp(getOpcode()); } 26122de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isShiftOp(Opcode Opc) { return Opc == BO_Shl || Opc == BO_Shr; } 26130799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isShiftOp() const { return isShiftOp(getOpcode()); } 2614aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl 26152de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isBitwiseOp(Opcode Opc) { return Opc >= BO_And && Opc <= BO_Or; } 26160799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isBitwiseOp() const { return isBitwiseOp(getOpcode()); } 2617f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 26182de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isRelationalOp(Opcode Opc) { return Opc >= BO_LT && Opc<=BO_GE; } 26190799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isRelationalOp() const { return isRelationalOp(getOpcode()); } 2620f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 26212de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isEqualityOp(Opcode Opc) { return Opc == BO_EQ || Opc == BO_NE; } 26220799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isEqualityOp() const { return isEqualityOp(getOpcode()); } 26231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 26242de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isComparisonOp(Opcode Opc) { return Opc >= BO_LT && Opc<=BO_NE; } 26250799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isComparisonOp() const { return isComparisonOp(getOpcode()); } 2626aee3c9375f97a49edef2a36f15df6abd9748e2a1Sebastian Redl 26272de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall static bool isLogicalOp(Opcode Opc) { return Opc == BO_LAnd || Opc==BO_LOr; } 26280799c53fc2bb7acf937c8a8e165033dba1a5aba3John McCall bool isLogicalOp() const { return isLogicalOp(getOpcode()); } 2629f2da7a06f6b98c3886d9b871ab839f5085b1c238Ted Kremenek 26300e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall static bool isAssignmentOp(Opcode Opc) { 26310e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall return Opc >= BO_Assign && Opc <= BO_OrAssign; 26320e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall } 26330e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall bool isAssignmentOp() const { return isAssignmentOp(getOpcode()); } 26340e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall 26350e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall static bool isCompoundAssignmentOp(Opcode Opc) { 26362de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Opc > BO_Assign && Opc <= BO_OrAssign; 26372de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 26380e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall bool isCompoundAssignmentOp() const { 26390e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall return isCompoundAssignmentOp(getOpcode()); 26400e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall } 26410e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall 26420e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall static bool isShiftAssignOp(Opcode Opc) { 26432de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall return Opc == BO_ShlAssign || Opc == BO_ShrAssign; 26442de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall } 26450e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall bool isShiftAssignOp() const { 26460e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall return isShiftAssignOp(getOpcode()); 26470e800c9c20d1a658a91096c756c4a4a9e90264fcJohn McCall } 26481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 26491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *S) { 26504bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt return S->getStmtClass() >= firstBinaryOperatorConstant && 26514bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt S->getStmtClass() <= lastBinaryOperatorConstant; 26525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 26535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const BinaryOperator *) { return true; } 26541237c673c07f9d827129ba02720108816abde562Ted Kremenek 26551237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 265663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 265763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 265863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 26591237c673c07f9d827129ba02720108816abde562Ted Kremenek 26605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 266117d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 2662f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 26632333f7727f97018d6742e1e0938133bcfad967abEli Friedman SourceLocation opLoc, bool dead) 2664f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(CompoundAssignOperatorClass, ResTy, VK, OK, 26652333f7727f97018d6742e1e0938133bcfad967abEli Friedman lhs->isTypeDependent() || rhs->isTypeDependent(), 2666bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor lhs->isValueDependent() || rhs->isValueDependent(), 2667561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (lhs->isInstantiationDependent() || 2668561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhs->isInstantiationDependent()), 2669bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (lhs->containsUnexpandedParameterPack() || 2670bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhs->containsUnexpandedParameterPack())), 26712333f7727f97018d6742e1e0938133bcfad967abEli Friedman Opc(opc), OpLoc(opLoc) { 26721237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 26731237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 26745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2675ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 26761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump BinaryOperator(StmtClass SC, EmptyShell Empty) 26772de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall : Expr(SC, Empty), Opc(BO_MulAssign) { } 26785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 26795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 26805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep 26815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// track of the type the operation is performed in. Due to the semantics of 2682ec5bc81fd55bfcc26fc4bde6d5e33113d94c2209Zhongxing Xu/// these operators, the operands are promoted, the arithmetic performed, an 26835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// implicit conversion back to the result type done, then the assignment takes 26845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// place. This captures the intermediate type which the computation is done 26855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// in. 26865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CompoundAssignOperator : public BinaryOperator { 2687ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType ComputationLHSType; 2688ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType ComputationResultType; 26895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 2690f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResType, 2691f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK, ExprObjectKind OK, 2692f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType CompLHSType, QualType CompResultType, 269317d1b2ac9f8371a0a2e79d4f8e0008658164f080Chris Lattner SourceLocation OpLoc) 2694f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : BinaryOperator(lhs, rhs, opc, ResType, VK, OK, OpLoc, true), 2695ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman ComputationLHSType(CompLHSType), 2696ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman ComputationResultType(CompResultType) { 26971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(isCompoundAssignmentOp() && 26985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer "Only should be used for compound assignments"); 26995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 27005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2701ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor /// \brief Build an empty compound assignment operator expression. 2702ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor explicit CompoundAssignOperator(EmptyShell Empty) 2703ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor : BinaryOperator(CompoundAssignOperatorClass, Empty) { } 2704ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 2705ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // The two computation types are the type the LHS is converted 2706ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // to for the computation and the type of the result; the two are 2707ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman // distinct in a few cases (specifically, int+=ptr and ptr-=ptr). 2708ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType getComputationLHSType() const { return ComputationLHSType; } 2709ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setComputationLHSType(QualType T) { ComputationLHSType = T; } 2710ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 2711ab3a852ae713189444dcbf75e70accf1e8c2b7f2Eli Friedman QualType getComputationResultType() const { return ComputationResultType; } 2712ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor void setComputationResultType(QualType T) { ComputationResultType = T; } 2713ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 27145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const CompoundAssignOperator *) { return true; } 27151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *S) { 27161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return S->getStmtClass() == CompoundAssignOperatorClass; 27175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 27185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 27195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 272056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// AbstractConditionalOperator - An abstract base class for 272156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// ConditionalOperator and BinaryConditionalOperator. 272256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass AbstractConditionalOperator : public Expr { 272356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation QuestionLoc, ColonLoc; 272456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall friend class ASTStmtReader; 272556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 272656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallprotected: 272756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall AbstractConditionalOperator(StmtClass SC, QualType T, 272856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall ExprValueKind VK, ExprObjectKind OK, 2729561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor bool TD, bool VD, bool ID, 273056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall bool ContainsUnexpandedParameterPack, 273156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation qloc, 273256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation cloc) 2733561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Expr(SC, T, VK, OK, TD, VD, ID, ContainsUnexpandedParameterPack), 273456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall QuestionLoc(qloc), ColonLoc(cloc) {} 273556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 273656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall AbstractConditionalOperator(StmtClass SC, EmptyShell Empty) 273756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : Expr(SC, Empty) { } 273856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 273956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallpublic: 274056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getCond - Return the expression representing the condition for 274156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the ?: operator. 274256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getCond() const; 274356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 274456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getTrueExpr - Return the subexpression representing the value of 274556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the expression if the condition evaluates to true. 274656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getTrueExpr() const; 274756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 274856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getFalseExpr - Return the subexpression representing the value of 274956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the expression if the condition evaluates to false. This is 275056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the same as getRHS. 275156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getFalseExpr() const; 275256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 275356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation getQuestionLoc() const { return QuestionLoc; } 275456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation getColonLoc() const { return ColonLoc; } 275556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 275656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const Stmt *T) { 275756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return T->getStmtClass() == ConditionalOperatorClass || 275856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall T->getStmtClass() == BinaryConditionalOperatorClass; 275956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 276056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const AbstractConditionalOperator *) { return true; } 276156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall}; 276256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 276356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// ConditionalOperator - The ?: ternary operator. The GNU "missing 276456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// middle" extension is a BinaryConditionalOperator. 276556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass ConditionalOperator : public AbstractConditionalOperator { 27661237c673c07f9d827129ba02720108816abde562Ted Kremenek enum { COND, LHS, RHS, END_EXPR }; 27675549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 276856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 276956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall friend class ASTStmtReader; 27705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 277147e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor ConditionalOperator(Expr *cond, SourceLocation QLoc, Expr *lhs, 277256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation CLoc, Expr *rhs, 27730943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall QualType t, ExprValueKind VK, ExprObjectKind OK) 277456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : AbstractConditionalOperator(ConditionalOperatorClass, t, VK, OK, 2775898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // FIXME: the type of the conditional operator doesn't 2776898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // depend on the type of the conditional, but the standard 2777898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // seems to imply that it could. File a bug! 277856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (lhs->isTypeDependent() || rhs->isTypeDependent()), 277956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (cond->isValueDependent() || lhs->isValueDependent() || 278056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall rhs->isValueDependent()), 2781561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (cond->isInstantiationDependent() || 2782561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor lhs->isInstantiationDependent() || 2783561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhs->isInstantiationDependent()), 2784bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (cond->containsUnexpandedParameterPack() || 278556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall lhs->containsUnexpandedParameterPack() || 278656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall rhs->containsUnexpandedParameterPack()), 278756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall QLoc, CLoc) { 27881237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[COND] = cond; 27891237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 27901237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 27911237c673c07f9d827129ba02720108816abde562Ted Kremenek } 27925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2793ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor /// \brief Build an empty conditional operator. 2794ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor explicit ConditionalOperator(EmptyShell Empty) 279556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : AbstractConditionalOperator(ConditionalOperatorClass, Empty) { } 2796ad90e96fb7eed26d5217dd06ba50ecbbbebb59e6Douglas Gregor 2797395a2abf0028968d85958610e393e067885dc14fTed Kremenek // getCond - Return the expression representing the condition for 279856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the ?: operator. 27995549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 2800395a2abf0028968d85958610e393e067885dc14fTed Kremenek 280156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getTrueExpr - Return the subexpression representing the value of 280256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the expression if the condition evaluates to true. 280356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getTrueExpr() const { return cast<Expr>(SubExprs[LHS]); } 28041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 280556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // getFalseExpr - Return the subexpression representing the value of 280656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the expression if the condition evaluates to false. This is 280756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // the same as getRHS. 28085549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); } 2809f9b949fecf339a2c9bd97dd11a272c4878f85ce4Fariborz Jahanian 281056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 28115549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 281247e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor 281363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 28145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd()); 28155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 28161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 28171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ConditionalOperatorClass; 28185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 28195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ConditionalOperator *) { return true; } 28201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28211237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 282263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 282363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 282463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 28255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 28265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 282756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// BinaryConditionalOperator - The GNU extension to the conditional 282856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// operator which allows the middle operand to be omitted. 282956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// 283056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// This is a different expression kind on the assumption that almost 283156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall/// every client ends up needing to know that these are different. 283256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass BinaryConditionalOperator : public AbstractConditionalOperator { 283356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall enum { COMMON, COND, LHS, RHS, NUM_SUBEXPRS }; 283456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 283556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// - the common condition/left-hand-side expression, which will be 283656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// evaluated as the opaque value 283756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// - the condition, expressed in terms of the opaque value 283856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// - the left-hand-side, expressed in terms of the opaque value 283956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// - the right-hand-side 284056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Stmt *SubExprs[NUM_SUBEXPRS]; 284156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValueExpr *OpaqueValue; 284256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 284356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall friend class ASTStmtReader; 284456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallpublic: 284556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall BinaryConditionalOperator(Expr *common, OpaqueValueExpr *opaqueValue, 284656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *cond, Expr *lhs, Expr *rhs, 284756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation qloc, SourceLocation cloc, 284856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall QualType t, ExprValueKind VK, ExprObjectKind OK) 284956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : AbstractConditionalOperator(BinaryConditionalOperatorClass, t, VK, OK, 285056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (common->isTypeDependent() || rhs->isTypeDependent()), 285156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (common->isValueDependent() || rhs->isValueDependent()), 2852561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (common->isInstantiationDependent() || 2853561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhs->isInstantiationDependent()), 285456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall (common->containsUnexpandedParameterPack() || 285556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall rhs->containsUnexpandedParameterPack()), 285656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall qloc, cloc), 285756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValue(opaqueValue) { 285856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SubExprs[COMMON] = common; 285956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SubExprs[COND] = cond; 286056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SubExprs[LHS] = lhs; 286156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SubExprs[RHS] = rhs; 286256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 286356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValue->setSourceExpr(common); 286456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 286556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 286656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief Build an empty conditional operator. 286756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall explicit BinaryConditionalOperator(EmptyShell Empty) 286856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall : AbstractConditionalOperator(BinaryConditionalOperatorClass, Empty) { } 286956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 287056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getCommon - Return the common expression, written to the 287156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// left of the condition. The opaque value will be bound to the 287256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// result of this expression. 287356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getCommon() const { return cast<Expr>(SubExprs[COMMON]); } 287456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 287556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getOpaqueValue - Return the opaque value placeholder. 287656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall OpaqueValueExpr *getOpaqueValue() const { return OpaqueValue; } 287756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 287856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getCond - Return the condition expression; this is defined 287956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// in terms of the opaque value. 288056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 288156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 288256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getTrueExpr - Return the subexpression which will be 288356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// evaluated if the condition evaluates to true; this is defined 288456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// in terms of the opaque value. 288556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getTrueExpr() const { 288656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<Expr>(SubExprs[LHS]); 288756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 288856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 288956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// \brief getFalseExpr - Return the subexpression which will be 289056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// evaluated if the condnition evaluates to false; this is 289156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall /// defined in terms of the opaque value. 289256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *getFalseExpr() const { 289356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<Expr>(SubExprs[RHS]); 289456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 289556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 289656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceRange getSourceRange() const { 289756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return SourceRange(getCommon()->getLocStart(), getFalseExpr()->getLocEnd()); 289856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 289956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const Stmt *T) { 290056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return T->getStmtClass() == BinaryConditionalOperatorClass; 290156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 290256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall static bool classof(const BinaryConditionalOperator *) { return true; } 290356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 290456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // Iterators 290556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall child_range children() { 290656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return child_range(SubExprs, SubExprs + NUM_SUBEXPRS); 290756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall } 290856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall}; 290956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 291056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallinline Expr *AbstractConditionalOperator::getCond() const { 291156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this)) 291256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return co->getCond(); 291356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<BinaryConditionalOperator>(this)->getCond(); 291456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall} 291556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 291656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallinline Expr *AbstractConditionalOperator::getTrueExpr() const { 291756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this)) 291856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return co->getTrueExpr(); 291956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<BinaryConditionalOperator>(this)->getTrueExpr(); 292056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall} 292156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 292256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallinline Expr *AbstractConditionalOperator::getFalseExpr() const { 292356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this)) 292456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return co->getFalseExpr(); 292556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return cast<BinaryConditionalOperator>(this)->getFalseExpr(); 292656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall} 292756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 29286481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner/// AddrLabelExpr - The GNU address of label extension, representing &&label. 29296481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattnerclass AddrLabelExpr : public Expr { 29305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SourceLocation AmpAmpLoc, LabelLoc; 2931ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *Label; 29325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 2933ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelDecl *L, 29346481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner QualType t) 2935561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Expr(AddrLabelExprClass, t, VK_RValue, OK_Ordinary, false, false, false, 2936561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false), 29372333f7727f97018d6742e1e0938133bcfad967abEli Friedman AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {} 29381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29397d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor /// \brief Build an empty address of a label expression. 29401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit AddrLabelExpr(EmptyShell Empty) 29417d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor : Expr(AddrLabelExprClass, Empty) { } 29427d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 29437d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; } 29447d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; } 29457d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor SourceLocation getLabelLoc() const { return LabelLoc; } 29467d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor void setLabelLoc(SourceLocation L) { LabelLoc = L; } 29477d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 294863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 29495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return SourceRange(AmpAmpLoc, LabelLoc); 29505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 29511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2952ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *getLabel() const { return Label; } 2953ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner void setLabel(LabelDecl *L) { Label = L; } 29547d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregor 29555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Stmt *T) { 29561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == AddrLabelExprClass; 29575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 29586481a57fefbf1a313ff439028470fe4c27a3b7a3Chris Lattner static bool classof(const AddrLabelExpr *) { return true; } 29591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29601237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 296163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 29625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 2963ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner 2964ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}). 2965ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// The StmtExpr contains a single CompoundStmt node, which it evaluates and 2966ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner/// takes the value of the last subexpression. 2967f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall/// 2968f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall/// A StmtExpr is always an r-value; values "returned" out of a 2969f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall/// StmtExpr will be copied. 2970ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerclass StmtExpr : public Expr { 29715549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *SubStmt; 2972ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner SourceLocation LParenLoc, RParenLoc; 2973ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattnerpublic: 29742333f7727f97018d6742e1e0938133bcfad967abEli Friedman // FIXME: Does type-dependence need to be computed differently? 2975561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor // FIXME: Do we need to compute instantiation instantiation-dependence for 2976561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor // statements? (ugh!) 2977d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff StmtExpr(CompoundStmt *substmt, QualType T, 2978d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff SourceLocation lp, SourceLocation rp) : 2979f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr(StmtExprClass, T, VK_RValue, OK_Ordinary, 2980561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor T->isDependentType(), false, false, false), 29812333f7727f97018d6742e1e0938133bcfad967abEli Friedman SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) { } 29821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29836a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor /// \brief Build an empty statement expression. 29846a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { } 29856a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor 29865549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); } 29875549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); } 29886a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setSubStmt(CompoundStmt *S) { SubStmt = S; } 29896a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor 299063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 2991ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner return SourceRange(LParenLoc, RParenLoc); 2992ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner } 29931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2994026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getLParenLoc() const { return LParenLoc; } 29956a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setLParenLoc(SourceLocation L) { LParenLoc = L; } 2996026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner SourceLocation getRParenLoc() const { return RParenLoc; } 29976a2dd55b0b3ae376d449a4b07bbb6b2d30b26330Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 29981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2999ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner static bool classof(const Stmt *T) { 30001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == StmtExprClass; 3001ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner } 3002ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner static bool classof(const StmtExpr *) { return true; } 30031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30041237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 300563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&SubStmt, &SubStmt+1); } 3006ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner}; 3007ab18c4c0ac1a46a38aa84c2c8ea485612e21a614Chris Lattner 3008d34e915f33224c508ad55fbf975bd10b7876e197Steve Naroff 3009d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// ShuffleVectorExpr - clang-specific builtin-in function 3010d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// __builtin_shufflevector. 3011d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// This AST node represents a operator that does a constant 3012d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// shuffle, similar to LLVM's shufflevector instruction. It takes 3013d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// two vectors and a variable number of constant indices, 3014d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman/// and returns the appropriately shuffled vector. 3015d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanclass ShuffleVectorExpr : public Expr { 3016d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman SourceLocation BuiltinLoc, RParenLoc; 3017d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 3018d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // SubExprs - the list of values passed to the __builtin_shufflevector 3019d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // function. The first two are vectors, and the rest are constant 3020d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // indices. The number of values in this list is always 3021d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // 2+the number of indices in the vector type. 30225549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt **SubExprs; 3023d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman unsigned NumExprs; 3024d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 3025d38617c8a50f9729c254ab76cd359af797c6739bEli Friedmanpublic: 3026a88dc3079bedf70a5cfc39791727e43a10383006Nate Begeman ShuffleVectorExpr(ASTContext &C, Expr **args, unsigned nexpr, 30271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType Type, SourceLocation BLoc, 3028bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor SourceLocation RP); 302994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 303094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor /// \brief Build an empty vector-shuffle expression. 30311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ShuffleVectorExpr(EmptyShell Empty) 303294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor : Expr(ShuffleVectorExprClass, Empty), SubExprs(0) { } 303394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 303494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 303594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 30361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 303794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 303894cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 303994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 304063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 3041d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman return SourceRange(BuiltinLoc, RParenLoc); 3042d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 3043d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman static bool classof(const Stmt *T) { 30441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ShuffleVectorExprClass; 3045d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 3046d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman static bool classof(const ShuffleVectorExpr *) { return true; } 30471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3048d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// getNumSubExprs - Return the size of the SubExprs array. This includes the 3049d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// constant expression, the actual arguments passed in, and the function 3050d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// pointers. 3051d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman unsigned getNumSubExprs() const { return NumExprs; } 30521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3053aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \brief Retrieve the array of expressions. 3054aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Expr **getSubExprs() { return reinterpret_cast<Expr **>(SubExprs); } 3055aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 3056d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman /// getExpr - Return the Expr at the specified index. 3057d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman Expr *getExpr(unsigned Index) { 3058d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman assert((Index < NumExprs) && "Arg access out of range!"); 30595549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Index]); 3060d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 3061d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman const Expr *getExpr(unsigned Index) const { 3062d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman assert((Index < NumExprs) && "Arg access out of range!"); 30635549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return cast<Expr>(SubExprs[Index]); 3064d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 30651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3066888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman void setExprs(ASTContext &C, Expr ** Exprs, unsigned NumExprs); 306794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 3068dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman unsigned getShuffleMaskIdx(ASTContext &Ctx, unsigned N) { 3069dde8c94873976632e3ada4d8d067e1e244184d51Eli Friedman assert((N < NumExprs - 2) && "Shuffle idx out of range!"); 30709a901bb63990574ff0bcc12ff851d7a71cff8ddbEli Friedman return getExpr(N+2)->EvaluateAsInt(Ctx).getZExtValue(); 3071d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman } 30721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3073d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman // Iterators 307463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 307563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+NumExprs); 307663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 3077d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman}; 3078d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 3079d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// ChooseExpr - GNU builtin-in function __builtin_choose_expr. 30801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// This AST node is similar to the conditional operator (?:) in C, with 3081d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff/// the following exceptions: 30827976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the test expression must be a integer constant expression. 30837976932a1c256d447316ffac58e9821417725e34Eli Friedman/// - the expression returned acts like the chosen subexpression in every 30847976932a1c256d447316ffac58e9821417725e34Eli Friedman/// visible way: the type is the same as that of the chosen subexpression, 30857976932a1c256d447316ffac58e9821417725e34Eli Friedman/// and all predicates (whether it's an l-value, whether it's an integer 30867976932a1c256d447316ffac58e9821417725e34Eli Friedman/// constant expression, etc.) return the same result as for the chosen 30877976932a1c256d447316ffac58e9821417725e34Eli Friedman/// sub-expression. 3088d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffclass ChooseExpr : public Expr { 30891237c673c07f9d827129ba02720108816abde562Ted Kremenek enum { COND, LHS, RHS, END_EXPR }; 30905549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 3091d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff SourceLocation BuiltinLoc, RParenLoc; 3092d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroffpublic: 3093f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, 3094f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall QualType t, ExprValueKind VK, ExprObjectKind OK, 3095ce94049b69f75b44c18584fe79cd238978b6b0d5Douglas Gregor SourceLocation RP, bool TypeDependent, bool ValueDependent) 3096bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor : Expr(ChooseExprClass, t, VK, OK, TypeDependent, ValueDependent, 3097561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (cond->isInstantiationDependent() || 3098561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor lhs->isInstantiationDependent() || 3099561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor rhs->isInstantiationDependent()), 3100bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (cond->containsUnexpandedParameterPack() || 3101bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor lhs->containsUnexpandedParameterPack() || 3102bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor rhs->containsUnexpandedParameterPack())), 31031237c673c07f9d827129ba02720108816abde562Ted Kremenek BuiltinLoc(BLoc), RParenLoc(RP) { 31041237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[COND] = cond; 31051237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[LHS] = lhs; 31061237c673c07f9d827129ba02720108816abde562Ted Kremenek SubExprs[RHS] = rhs; 31071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 31087976932a1c256d447316ffac58e9821417725e34Eli Friedman 310944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor /// \brief Build an empty __builtin_choose_expr. 311044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { } 311144cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 31127976932a1c256d447316ffac58e9821417725e34Eli Friedman /// isConditionTrue - Return whether the condition is true (i.e. not 31137976932a1c256d447316ffac58e9821417725e34Eli Friedman /// equal to zero). 31144ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool isConditionTrue(const ASTContext &C) const; 31157976932a1c256d447316ffac58e9821417725e34Eli Friedman 31167976932a1c256d447316ffac58e9821417725e34Eli Friedman /// getChosenSubExpr - Return the subexpression chosen according to the 31177976932a1c256d447316ffac58e9821417725e34Eli Friedman /// condition. 31184ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad Expr *getChosenSubExpr(const ASTContext &C) const { 31197976932a1c256d447316ffac58e9821417725e34Eli Friedman return isConditionTrue(C) ? getLHS() : getRHS(); 31207976932a1c256d447316ffac58e9821417725e34Eli Friedman } 31217976932a1c256d447316ffac58e9821417725e34Eli Friedman 31225549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getCond() const { return cast<Expr>(SubExprs[COND]); } 312344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setCond(Expr *E) { SubExprs[COND] = E; } 31245549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); } 312544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setLHS(Expr *E) { SubExprs[LHS] = E; } 31265549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } 312744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setRHS(Expr *E) { SubExprs[RHS] = E; } 312844cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 312944cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 313044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 31311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 313244cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 313344cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 31341237c673c07f9d827129ba02720108816abde562Ted Kremenek 313563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 3136d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff return SourceRange(BuiltinLoc, RParenLoc); 3137d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff } 3138d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff static bool classof(const Stmt *T) { 31391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ChooseExprClass; 3140d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff } 3141d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff static bool classof(const ChooseExpr *) { return true; } 31421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 31431237c673c07f9d827129ba02720108816abde562Ted Kremenek // Iterators 314463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 314563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 314663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 3147d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff}; 3148d04fdd5f99f985abf2e7b7d7d4d427eebe001e55Steve Naroff 31492d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// GNUNullExpr - Implements the GNU __null extension, which is a name 31502d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// for a null pointer constant that has integral type (e.g., int or 31512d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// long) and is the same size and alignment as a pointer. The __null 31522d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// extension is typically only used by system headers, which define 31532d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// NULL as __null in C++ rather than using 0 (which is an integer 31542d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor/// that may not match the size of a pointer). 31552d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorclass GNUNullExpr : public Expr { 31562d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor /// TokenLoc - The location of the __null keyword. 31572d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor SourceLocation TokenLoc; 31582d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 31592d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregorpublic: 31601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump GNUNullExpr(QualType Ty, SourceLocation Loc) 3161561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Expr(GNUNullExprClass, Ty, VK_RValue, OK_Ordinary, false, false, false, 3162561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false), 3163f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall TokenLoc(Loc) { } 31642d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 316544cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor /// \brief Build an empty GNU __null expression. 316644cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { } 316744cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor 31682d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor /// getTokenLocation - The location of the __null token. 31692d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor SourceLocation getTokenLocation() const { return TokenLoc; } 317044cae0c8669cdf83618cbe7fd36ea7a8e51cf97fDouglas Gregor void setTokenLocation(SourceLocation L) { TokenLoc = L; } 31712d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 317263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 31732d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor return SourceRange(TokenLoc); 31742d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } 31752d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor static bool classof(const Stmt *T) { 31761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == GNUNullExprClass; 31772d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } 31782d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor static bool classof(const GNUNullExpr *) { return true; } 31791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 31802d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor // Iterators 318163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 31822d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor}; 31832d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 318474626d6ef2e194fcc911e071556660ff331eb4a8Zhongxing Xu/// VAArgExpr, used for the builtin function __builtin_va_arg. 31857c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonclass VAArgExpr : public Expr { 31865549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Stmt *Val; 31872cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara TypeSourceInfo *TInfo; 31887c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson SourceLocation BuiltinLoc, RParenLoc; 31897c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlssonpublic: 31902cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara VAArgExpr(SourceLocation BLoc, Expr* e, TypeSourceInfo *TInfo, 31912cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara SourceLocation RPLoc, QualType t) 3192f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(VAArgExprClass, t, VK_RValue, OK_Ordinary, 3193bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor t->isDependentType(), false, 3194561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (TInfo->getType()->isInstantiationDependentType() || 3195561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor e->isInstantiationDependent()), 3196bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor (TInfo->getType()->containsUnexpandedParameterPack() || 3197bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor e->containsUnexpandedParameterPack())), 31982cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara Val(e), TInfo(TInfo), 31997c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson BuiltinLoc(BLoc), 32007c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson RParenLoc(RPLoc) { } 32011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 320274626d6ef2e194fcc911e071556660ff331eb4a8Zhongxing Xu /// \brief Create an empty __builtin_va_arg expression. 3203d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor explicit VAArgExpr(EmptyShell Empty) : Expr(VAArgExprClass, Empty) { } 3204d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 32055549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek const Expr *getSubExpr() const { return cast<Expr>(Val); } 32065549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek Expr *getSubExpr() { return cast<Expr>(Val); } 3207d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setSubExpr(Expr *E) { Val = E; } 3208d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 32092cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara TypeSourceInfo *getWrittenTypeInfo() const { return TInfo; } 32102cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara void setWrittenTypeInfo(TypeSourceInfo *TI) { TInfo = TI; } 32112cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara 3212d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 3213d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; } 32141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3215d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getRParenLoc() const { return RParenLoc; } 3216d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setRParenLoc(SourceLocation L) { RParenLoc = L; } 3217d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 321863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 32197c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson return SourceRange(BuiltinLoc, RParenLoc); 32201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 32217c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson static bool classof(const Stmt *T) { 32227c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson return T->getStmtClass() == VAArgExprClass; 32237c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson } 32247c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson static bool classof(const VAArgExpr *) { return true; } 32251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32267c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson // Iterators 322763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Val, &Val+1); } 32287c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson}; 32291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32304c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @brief Describes an C or C++ initializer list. 32314c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// 32324c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// InitListExpr describes an initializer list, which can be used to 32334c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initialize objects of different types, including 32344c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct/class/union types, arrays, and vectors. For example: 32354c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// 32364c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @code 32374c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// struct foo x = { 1, { 2, 3 } }; 32384c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// @endcode 3239196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 32404c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Prior to semantic analysis, an initializer list will represent the 32414c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer list as written by the user, but will have the 32424c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// placeholder type "void". This initializer list is called the 32434c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// syntactic form of the initializer, and may contain C99 designated 32444c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializers (represented as DesignatedInitExprs), initializations 32454c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// of subobject members without explicit braces, and so on. Clients 32464c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// interested in the original syntax of the initializer list should 32474c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// use the syntactic form of the initializer list. 3248196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 32494c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// After semantic analysis, the initializer list will represent the 32504c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// semantic form of the initializer, where the initializations of all 32514c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// subobjects are made explicit with nested InitListExpr nodes and 32524c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// C99 designators have been eliminated by placing the designated 32534c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializations into the subobject they initialize. Additionally, 32544c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// any "holes" in the initialization, where no initializer has been 32554c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// specified for a particular subobject, will be replaced with 32563498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// implicitly-generated ImplicitValueInitExpr expressions that 32574c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// value-initialize the subobjects. Note, however, that the 32584c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// initializer lists may still have fewer initializers than there are 32594c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// elements to initialize within the object. 3260196ef51bc4d008ec1c69851fb3b0f8d036065931Chris Lattner/// 32614c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// Given the semantic form of the initializer list, one can retrieve 32624c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// the original syntactic form of that initializer list (if it 32634c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// exists) using getSyntacticForm(). Since many initializer lists 32644c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// have the same syntactic and semantic forms, getSyntacticForm() may 32654c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// return NULL, indicating that the current initializer list also 32664c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor/// serves as its syntactic form. 326766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonclass InitListExpr : public Expr { 3268ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek // FIXME: Eliminate this vector in favor of ASTContext allocation 3269709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek typedef ASTVector<Stmt *> InitExprsTy; 3270709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitExprsTy InitExprs; 327166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson SourceLocation LBraceLoc, RBraceLoc; 32721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32734c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// Contains the initializer list that describes the syntactic form 32744c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// written in the source code. 32754c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitListExpr *SyntacticForm; 32764c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 32774423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// \brief Either: 32784423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// If this initializer list initializes an array with more elements than 32794423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// there are initializers in the list, specifies an expression to be used 32804423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// for value initialization of the rest of the elements. 32814423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// Or 32824423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// If this initializer list initializes a union, specifies which 32834423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// field within the union will be initialized. 32844423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis llvm::PointerUnion<Expr *, FieldDecl *> ArrayFillerOrUnionFieldInit; 32850bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor 3286a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor /// Whether this initializer list originally had a GNU array-range 3287a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor /// designator in it. This is a temporary marker used by CodeGen. 3288a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor bool HadArrayRangeDesignator; 3289a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor 329066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlssonpublic: 3291709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek InitListExpr(ASTContext &C, SourceLocation lbraceloc, 3292709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek Expr **initexprs, unsigned numinits, 3293ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek SourceLocation rbraceloc); 3294d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3295d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Build an empty initializer list. 3296709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek explicit InitListExpr(ASTContext &C, EmptyShell Empty) 3297709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek : Expr(InitListExprClass, Empty), InitExprs(C) { } 32981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3299ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek unsigned getNumInits() const { return InitExprs.size(); } 33001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3301aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \brief Retrieve the set of initializers. 3302aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Expr **getInits() { return reinterpret_cast<Expr **>(InitExprs.data()); } 3303aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 330416c5dea6c2d3e4cf529de9d9b37f6a40441acb2cChris Lattner const Expr *getInit(unsigned Init) const { 3305c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 33064c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return cast_or_null<Expr>(InitExprs[Init]); 330766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 33081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 330916c5dea6c2d3e4cf529de9d9b37f6a40441acb2cChris Lattner Expr *getInit(unsigned Init) { 3310c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 33114c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return cast_or_null<Expr>(InitExprs[Init]); 331266b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 33131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 33141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void setInit(unsigned Init, Expr *expr) { 3315c5ae899b4bbf65488445316c63168079177db0edSteve Naroff assert(Init < getNumInits() && "Initializer access out of range!"); 33169e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff InitExprs[Init] = expr; 33179e8925e72f53a9e2c4633b6b48e965ed01702fe4Steve Naroff } 3318c5ae899b4bbf65488445316c63168079177db0edSteve Naroff 3319fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor /// \brief Reserve space for some number of initializers. 3320709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek void reserveInits(ASTContext &C, unsigned NumInits); 33211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 33224c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Specify the number of initializers 33234c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 33244c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// If there are more than @p NumInits initializers, the remaining 33254c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// initializers will be destroyed. If there are fewer than @p 33264c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// NumInits initializers, NULL expressions will be added for the 33274c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// unknown initializers. 33284c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor void resizeInits(ASTContext &Context, unsigned NumInits); 33294c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 33304c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Updates the initializer at index @p Init with the new 33314c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// expression @p expr, and returns the old expression at that 33324c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// location. 33334c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 33344c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// When @p Init is out of range for this initializer list, the 33354c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// initializer list will be extended with NULL expressions to 3336fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner /// accommodate the new entry. 3337709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek Expr *updateInit(ASTContext &C, unsigned Init, Expr *expr); 3338c5ae899b4bbf65488445316c63168079177db0edSteve Naroff 33394423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// \brief If this initializer list initializes an array with more elements 33404423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// than there are initializers in the list, specifies an expression to be 33414423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis /// used for value initialization of the rest of the elements. 33424423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis Expr *getArrayFiller() { 33434423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis return ArrayFillerOrUnionFieldInit.dyn_cast<Expr *>(); 33444423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis } 33458cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne const Expr *getArrayFiller() const { 33468cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne return const_cast<InitListExpr *>(this)->getArrayFiller(); 33478cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne } 33483e8dc2ac8926dfbebd8f2f6b74ceba4befccd4d2Argyrios Kyrtzidis void setArrayFiller(Expr *filler); 33494423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis 33500bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// \brief If this initializes a union, specifies which field in the 33510bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// union to initialize. 33520bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// 33530bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// Typically, this field is the first named field within the 33540bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// union. However, a designated initializer can specify the 33550bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor /// initialization of a different field within the union. 33564423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis FieldDecl *getInitializedFieldInUnion() { 33574423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis return ArrayFillerOrUnionFieldInit.dyn_cast<FieldDecl *>(); 33584423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis } 33598cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne const FieldDecl *getInitializedFieldInUnion() const { 33608cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne return const_cast<InitListExpr *>(this)->getInitializedFieldInUnion(); 33618cad3046be06ea73ff8892d947697a21d7a440d3Peter Collingbourne } 33624423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis void setInitializedFieldInUnion(FieldDecl *FD) { 33634423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis ArrayFillerOrUnionFieldInit = FD; 33644423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis } 33650bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor 3366c5ae899b4bbf65488445316c63168079177db0edSteve Naroff // Explicit InitListExpr's originate from source code (and have valid source 3367c5ae899b4bbf65488445316c63168079177db0edSteve Naroff // locations). Implicit InitListExpr's are created by the semantic analyzer. 3368b3eef68111ffc220e449be96da1747998c057790Douglas Gregor bool isExplicit() { 3369b3eef68111ffc220e449be96da1747998c057790Douglas Gregor return LBraceLoc.isValid() && RBraceLoc.isValid(); 3370b3eef68111ffc220e449be96da1747998c057790Douglas Gregor } 33711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3372d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor SourceLocation getLBraceLoc() const { return LBraceLoc; } 3373d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setLBraceLoc(SourceLocation Loc) { LBraceLoc = Loc; } 3374d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor SourceLocation getRBraceLoc() const { return RBraceLoc; } 337587fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; } 337687fd703e097c27d63479cb83b687d4000a22bbb1Douglas Gregor 33774c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// @brief Retrieve the initializer list that describes the 33784c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// syntactic form of the initializer. 33794c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor /// 33801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 33814c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitListExpr *getSyntacticForm() const { return SyntacticForm; } 33824c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor void setSyntacticForm(InitListExpr *Init) { SyntacticForm = Init; } 33834c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 3384a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor bool hadArrayRangeDesignator() const { return HadArrayRangeDesignator; } 33851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void sawArrayRangeDesignator(bool ARD = true) { 3386d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor HadArrayRangeDesignator = ARD; 3387a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor } 3388a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor 338963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const; 3390c4ba51f365a3cd3374b3ef87272a9b3e517cd5d3Ted Kremenek 339166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson static bool classof(const Stmt *T) { 33921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == InitListExprClass; 339366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson } 339466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson static bool classof(const InitListExpr *) { return true; } 33951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 339666b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson // Iterators 339763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 339863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall if (InitExprs.empty()) return child_range(); 339963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&InitExprs[0], &InitExprs[0] + InitExprs.size()); 340063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 34011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3402709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek typedef InitExprsTy::iterator iterator; 34038111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu typedef InitExprsTy::const_iterator const_iterator; 3404709210feee317b8d6690dd1d15c2b74cfe55e261Ted Kremenek typedef InitExprsTy::reverse_iterator reverse_iterator; 34058111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu typedef InitExprsTy::const_reverse_iterator const_reverse_iterator; 34061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3407ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek iterator begin() { return InitExprs.begin(); } 34088111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_iterator begin() const { return InitExprs.begin(); } 3409ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek iterator end() { return InitExprs.end(); } 34108111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_iterator end() const { return InitExprs.end(); } 3411ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek reverse_iterator rbegin() { return InitExprs.rbegin(); } 34128111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_reverse_iterator rbegin() const { return InitExprs.rbegin(); } 3413ba7bc5584b8d46f4e8deb3a9d363256908fa86eaTed Kremenek reverse_iterator rend() { return InitExprs.rend(); } 34148111a6150cb68a238d55a31f9f4f90869a43f988Zhongxing Xu const_reverse_iterator rend() const { return InitExprs.rend(); } 34154423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis 34164423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis friend class ASTStmtReader; 34174423ac0282acb8ba801eb05b38712438dc0c1e3eArgyrios Kyrtzidis friend class ASTStmtWriter; 341866b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson}; 341966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson 342005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @brief Represents a C99 designated initializer expression. 342105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// 342205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// A designated initializer expression (C99 6.7.8) contains one or 342305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// more designators (which can be field designators, array 342405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, or GNU array-range designators) followed by an 342505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// expression that initializes the field or element(s) that the 342605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators refer to. For example, given: 34271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 342805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @code 342905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point { 343005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// double x; 343105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// double y; 343205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// }; 343305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 }; 343405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// @endcode 343505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// 343605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// The InitListExpr contains three DesignatedInitExprs, the first of 343705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// which covers @c [2].y=1.0. This DesignatedInitExpr will have two 343805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designators, one array designator for @c [2] followed by one field 343905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor/// designator for @c .y. The initalization expression will be 1.0. 344005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorclass DesignatedInitExpr : public Expr { 3441ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorpublic: 3442ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief Forward declaration of the Designator class. 3443ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor class Designator; 3444ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 3445ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorprivate: 344605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '=' or ':' prior to the actual initializer 344705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// expression. 344805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EqualOrColonLoc; 344905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3450eeae8f072748affce25ab4064982626361293390Douglas Gregor /// Whether this designated initializer used the GNU deprecated 345105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// syntax rather than the C99 '=' syntax. 3452eeae8f072748affce25ab4064982626361293390Douglas Gregor bool GNUSyntax : 1; 345305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 345405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The number of designators in this initializer expression. 345505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators : 15; 345605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3457ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief The designators in this designated initialization 3458ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// expression. 3459ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designator *Designators; 3460ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 346105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The number of subexpressions of this initializer expression, 346205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// which contains both the initializer and any additional 346305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// expressions used by array and array-range designators. 346405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumSubExprs : 16; 346505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3466ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 3467319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor DesignatedInitExpr(ASTContext &C, QualType Ty, unsigned NumDesignators, 3468ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Designators, 3469eeae8f072748affce25ab4064982626361293390Douglas Gregor SourceLocation EqualOrColonLoc, bool GNUSyntax, 34709ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr **IndexExprs, unsigned NumIndexExprs, 34719ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *Init); 347205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3473d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor explicit DesignatedInitExpr(unsigned NumSubExprs) 3474d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor : Expr(DesignatedInitExprClass, EmptyShell()), 3475d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor NumDesignators(0), Designators(0), NumSubExprs(NumSubExprs) { } 3476d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 347705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregorpublic: 347805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// A field designator, e.g., ".x". 347905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct FieldDesignator { 348005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// Refers to the field that is being initialized. The low bit 348105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// of this field determines whether this is actually a pointer 348205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When 348305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initially constructed, a field designator will store an 348405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// IdentifierInfo*. After semantic analysis has resolved that 348505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// name, the field designator will instead store a FieldDecl*. 348605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor uintptr_t NameOrField; 34871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 348805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '.' in the designated initializer. 348905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned DotLoc; 34901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 349105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the field name in the designated initializer. 349205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned FieldLoc; 349305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 349405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 349505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". 349605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct ArrayOrRangeDesignator { 349705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// Location of the first index expression within the designated 349805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initializer expression's list of subexpressions. 349905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned Index; 350005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the '[' starting the array range designator. 350105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned LBracketLoc; 350205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the ellipsis separating the start and end 350305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// indices. Only valid for GNU array-range designators. 350405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned EllipsisLoc; 350505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// The location of the ']' terminating the array range designator. 35061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned RBracketLoc; 350705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 350805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 350905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Represents a single C99 designator. 351005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// 351105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @todo This class is infuriatingly similar to clang::Designator, 351205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// but minor differences (storing indices vs. storing pointers) 351305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// keep us from reusing it. Try harder, later, to rectify these 351405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// differences. 351505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor class Designator { 351605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief The kind of designator this describes. 351705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor enum { 351805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor FieldDesignator, 351905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayDesignator, 352005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayRangeDesignator 352105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } Kind; 352205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 352305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor union { 352405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// A field designator, e.g., ".x". 352505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct FieldDesignator Field; 352605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]". 352705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor struct ArrayOrRangeDesignator ArrayOrRange; 352805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 352905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor friend class DesignatedInitExpr; 353005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 353105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor public: 3532ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designator() {} 3533ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 353405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes a field designator. 35351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc, 35361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation FieldLoc) 353705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(FieldDesignator) { 353805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01; 353905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.DotLoc = DotLoc.getRawEncoding(); 354005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.FieldLoc = FieldLoc.getRawEncoding(); 354105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 354205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 354305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes an array designator. 35441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(unsigned Index, SourceLocation LBracketLoc, 354505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation RBracketLoc) 354605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(ArrayDesignator) { 354705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.Index = Index; 354805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding(); 354905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding(); 355005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding(); 355105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 355205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 355305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Initializes a GNU array-range designator. 35541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Designator(unsigned Index, SourceLocation LBracketLoc, 355505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EllipsisLoc, SourceLocation RBracketLoc) 355605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor : Kind(ArrayRangeDesignator) { 355705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.Index = Index; 355805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding(); 355905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding(); 356005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding(); 356105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 356205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 356305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isFieldDesignator() const { return Kind == FieldDesignator; } 356405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isArrayDesignator() const { return Kind == ArrayDesignator; } 356505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; } 356605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3567b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth IdentifierInfo *getFieldName() const; 356805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3569b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth FieldDecl *getField() const { 357005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 357105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor if (Field.NameOrField & 0x01) 357205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return 0; 357305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor else 357405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return reinterpret_cast<FieldDecl *>(Field.NameOrField); 357505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 357605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 357705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor void setField(FieldDecl *FD) { 357805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 357905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Field.NameOrField = reinterpret_cast<uintptr_t>(FD); 358005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 358105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 358287f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor SourceLocation getDotLoc() const { 358387f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 358487f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor return SourceLocation::getFromRawEncoding(Field.DotLoc); 358587f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor } 358687f55cf59e82f246d8605733e9300d0c5f6830a6Douglas Gregor 358705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getFieldLoc() const { 358805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 358905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(Field.FieldLoc); 359005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 359105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 359205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getLBracketLoc() const { 359305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 359405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array or array-range designator"); 359505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc); 359605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 359705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 359805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getRBracketLoc() const { 359905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 360005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array or array-range designator"); 360105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc); 360205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 360305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 360405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getEllipsisLoc() const { 360505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == ArrayRangeDesignator && 360605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Only valid on an array-range designator"); 360705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc); 360805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 36094c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 3610d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned getFirstExprIndex() const { 3611d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) && 3612d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor "Only valid on an array or array-range designator"); 3613d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor return ArrayOrRange.Index; 3614d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 3615d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 36164c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor SourceLocation getStartLocation() const { 36174c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor if (Kind == FieldDesignator) 36184c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return getDotLoc().isInvalid()? getFieldLoc() : getDotLoc(); 36194c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor else 36204c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return getLBracketLoc(); 36214c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor } 362224f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara SourceLocation getEndLocation() const { 362324f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara return Kind == FieldDesignator ? getFieldLoc() : getRBracketLoc(); 362424f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara } 362524f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara SourceRange getSourceRange() const { 362624f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara return SourceRange(getStartLocation(), getEndLocation()); 362724f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara } 362805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor }; 362905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 36301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static DesignatedInitExpr *Create(ASTContext &C, Designator *Designators, 363105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators, 363205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr **IndexExprs, unsigned NumIndexExprs, 363305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation EqualOrColonLoc, 3634eeae8f072748affce25ab4064982626361293390Douglas Gregor bool GNUSyntax, Expr *Init); 363505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3636d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor static DesignatedInitExpr *CreateEmpty(ASTContext &C, unsigned NumIndexExprs); 3637d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 363805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Returns the number of designators in this initializer. 363905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned size() const { return NumDesignators; } 364005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 364105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor // Iterator access to the designators. 3642b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth typedef Designator *designators_iterator; 3643ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor designators_iterator designators_begin() { return Designators; } 36441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump designators_iterator designators_end() { 36451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return Designators + NumDesignators; 3646ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor } 364705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3648b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth typedef const Designator *const_designators_iterator; 3649b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth const_designators_iterator designators_begin() const { return Designators; } 3650b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth const_designators_iterator designators_end() const { 3651b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth return Designators + NumDesignators; 3652b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth } 3653b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth 3654cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek typedef std::reverse_iterator<designators_iterator> 3655cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek reverse_designators_iterator; 3656cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek reverse_designators_iterator designators_rbegin() { 3657cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek return reverse_designators_iterator(designators_end()); 3658cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek } 3659cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek reverse_designators_iterator designators_rend() { 3660cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek return reverse_designators_iterator(designators_begin()); 3661cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek } 3662cdba6595a61a7bd31f504260abf63c900a759d0fTed Kremenek 3663b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth typedef std::reverse_iterator<const_designators_iterator> 3664b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth const_reverse_designators_iterator; 3665b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth const_reverse_designators_iterator designators_rbegin() const { 3666b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth return const_reverse_designators_iterator(designators_end()); 3667b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth } 3668b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth const_reverse_designators_iterator designators_rend() const { 3669b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth return const_reverse_designators_iterator(designators_begin()); 3670b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth } 3671b11382497a923b0d7009e85a1d8eb7bf93ec6d0dChandler Carruth 3672711997184366d584c9c437102cae1e9d9927b986Douglas Gregor Designator *getDesignator(unsigned Idx) { return &designators_begin()[Idx]; } 3673711997184366d584c9c437102cae1e9d9927b986Douglas Gregor 3674c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt void setDesignators(ASTContext &C, const Designator *Desigs, 3675319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor unsigned NumDesigs); 3676d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 367705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayIndex(const Designator& D); 367805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayRangeStart(const Designator& D); 367905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr *getArrayRangeEnd(const Designator& D); 368005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 368105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Retrieve the location of the '=' that precedes the 368205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// initializer value itself, if present. 368305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; } 3684d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setEqualOrColonLoc(SourceLocation L) { EqualOrColonLoc = L; } 368505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 368605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Determines whether this designated initializer used the 3687eeae8f072748affce25ab4064982626361293390Douglas Gregor /// deprecated GNU syntax for designated initializers. 3688eeae8f072748affce25ab4064982626361293390Douglas Gregor bool usesGNUSyntax() const { return GNUSyntax; } 3689d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setGNUSyntax(bool GNU) { GNUSyntax = GNU; } 369005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 369105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor /// @brief Retrieve the initializer value. 36921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getInit() const { 369305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin()); 369405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 369505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 369605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor void setInit(Expr *init) { 369705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor *child_begin() = init; 369805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 369905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 3700d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Retrieve the total number of subexpressions in this 3701d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// designated initializer expression, including the actual 3702d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// initialized value and any expressions that occur within array 3703d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// and array-range designators. 3704d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned getNumSubExprs() const { return NumSubExprs; } 3705d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3706d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Expr *getSubExpr(unsigned Idx) { 3707d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert(Idx < NumSubExprs && "Subscript out of range"); 3708d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 3709d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 3710d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor return reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx]; 3711d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 3712d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3713d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void setSubExpr(unsigned Idx, Expr *E) { 3714d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor assert(Idx < NumSubExprs && "Subscript out of range"); 3715d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 3716d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 3717d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx] = E; 3718d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor } 3719d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 3720ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// \brief Replaces the designator at index @p Idx with the series 3721ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor /// of designators in [First, Last). 3722319d57f21600dd2c4d52ccc27bd12ce260b174e7Douglas Gregor void ExpandDesignator(ASTContext &C, unsigned Idx, const Designator *First, 3723ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Last); 3724ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 372524f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara SourceRange getDesignatorsSourceRange() const; 372624f4674e697fb53587f0e8485e9c6592f7021ef2Abramo Bagnara 372763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const; 372805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 372905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor static bool classof(const Stmt *T) { 37301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == DesignatedInitExprClass; 373105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } 373205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor static bool classof(const DesignatedInitExpr *) { return true; } 373305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 373405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor // Iterators 373563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 373663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall Stmt **begin = reinterpret_cast<Stmt**>(this + 1); 373763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(begin, begin + NumSubExprs); 373863c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 37393498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor}; 37403498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 37413498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// \brief Represents an implicitly-generated value initialization of 37423498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// an object of a given type. 37433498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// 37441a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// Implicit value initializations occur within semantic initializer 37451a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// list expressions (InitListExpr) as placeholders for subobject 37463498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor/// initializations not explicitly specified by the user. 37471a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// 37481a51b4a11b7db25cac2134249711ecaaf9d1c0a8Douglas Gregor/// \see InitListExpr 37491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass ImplicitValueInitExpr : public Expr { 37503498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregorpublic: 37511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump explicit ImplicitValueInitExpr(QualType ty) 3752f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(ImplicitValueInitExprClass, ty, VK_RValue, OK_Ordinary, 3753561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false, false, ty->isInstantiationDependentType(), false) { } 37543498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 3755d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor /// \brief Construct an empty implicit value initialization. 3756d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor explicit ImplicitValueInitExpr(EmptyShell Empty) 3757d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor : Expr(ImplicitValueInitExprClass, Empty) { } 3758d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 37591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 37603498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return T->getStmtClass() == ImplicitValueInitExprClass; 37613498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor } 37623498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor static bool classof(const ImplicitValueInitExpr *) { return true; } 37633498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 376463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 37653498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return SourceRange(); 37663498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor } 37673498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 37683498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor // Iterators 376963c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 377005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor}; 377105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 37722ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 37732ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanclass ParenListExpr : public Expr { 37742ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman Stmt **Exprs; 37752ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman unsigned NumExprs; 37762ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation LParenLoc, RParenLoc; 37772ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 37782ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanpublic: 37791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParenListExpr(ASTContext& C, SourceLocation lparenloc, Expr **exprs, 37800d9106fc97cde979a995e26b18bcd2643f8afb55Manuel Klimek unsigned numexprs, SourceLocation rparenloc, QualType T); 37812ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 37822ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman /// \brief Build an empty paren list. 378337bdfe284ad365f753741d1d89c078c148b3f4afArgyrios Kyrtzidis explicit ParenListExpr(EmptyShell Empty) : Expr(ParenListExprClass, Empty) { } 37841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37852ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman unsigned getNumExprs() const { return NumExprs; } 37861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Expr* getExpr(unsigned Init) const { 37882ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman assert(Init < getNumExprs() && "Initializer access out of range!"); 37892ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return cast_or_null<Expr>(Exprs[Init]); 37902ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 37911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr* getExpr(unsigned Init) { 37932ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman assert(Init < getNumExprs() && "Initializer access out of range!"); 37942ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return cast_or_null<Expr>(Exprs[Init]); 37952ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 37962ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 379783ddad3ab513f5d73698cf9fbeb4ed3f011bc3b9Douglas Gregor Expr **getExprs() { return reinterpret_cast<Expr **>(Exprs); } 37981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37992ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation getLParenLoc() const { return LParenLoc; } 38002ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation getRParenLoc() const { return RParenLoc; } 38012ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 380263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 38032ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return SourceRange(LParenLoc, RParenLoc); 38041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 38052ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman static bool classof(const Stmt *T) { 38061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ParenListExprClass; 38072ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman } 38082ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman static bool classof(const ParenListExpr *) { return true; } 38091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 38102ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman // Iterators 381163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { 381263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall return child_range(&Exprs[0], &Exprs[0]+NumExprs); 381363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall } 381437bdfe284ad365f753741d1d89c078c148b3f4afArgyrios Kyrtzidis 381560adf4acf40b72227740bf966fb87eebddff3f37Sebastian Redl friend class ASTStmtReader; 38163397c5570369f19b2d6c52e898f708d75ceede1fSebastian Redl friend class ASTStmtWriter; 38172ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman}; 38182ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 38191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3820f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// \brief Represents a C1X generic selection. 3821f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// 3822f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// A generic selection (C1X 6.5.1.1) contains an unevaluated controlling 3823f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// expression, followed by one or more generic associations. Each generic 3824f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// association specifies a type name and an expression, or "default" and an 3825f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// expression (in which case it is known as a default generic association). 3826f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// The type and value of the generic selection are identical to those of its 3827f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// result expression, which is defined as the expression in the generic 3828f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// association with a type name that is compatible with the type of the 3829f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// controlling expression, or the expression in the default generic association 3830f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// if no types are compatible. For example: 3831f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// 3832f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// @code 3833f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// _Generic(X, double: 1, float: 2, default: 3) 3834f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// @endcode 3835f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// 3836f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// The above expression evaluates to 1 if 1.0 is substituted for X, 2 if 1.0f 3837f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// or 3 if "hello". 3838f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// 3839f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// As an extension, generic selections are allowed in C++, where the following 3840f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// additional semantics apply: 3841f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// 3842f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// Any generic selection whose controlling expression is type-dependent or 3843f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// which names a dependent type in its association list is result-dependent, 3844f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// which means that the choice of result expression is dependent. 3845f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne/// Result-dependent generic associations are both type- and value-dependent. 3846f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourneclass GenericSelectionExpr : public Expr { 3847f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne enum { CONTROLLING, END_EXPR }; 3848f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo **AssocTypes; 3849f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Stmt **SubExprs; 3850f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned NumAssocs, ResultIndex; 3851f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation GenericLoc, DefaultLoc, RParenLoc; 3852f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3853f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbournepublic: 3854f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne GenericSelectionExpr(ASTContext &Context, 3855f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation GenericLoc, Expr *ControllingExpr, 3856f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo **AssocTypes, Expr **AssocExprs, 3857f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned NumAssocs, SourceLocation DefaultLoc, 3858f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation RParenLoc, 3859f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne bool ContainsUnexpandedParameterPack, 3860f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned ResultIndex); 3861f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3862f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// This constructor is used in the result-dependent case. 3863f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne GenericSelectionExpr(ASTContext &Context, 3864f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation GenericLoc, Expr *ControllingExpr, 3865f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo **AssocTypes, Expr **AssocExprs, 3866f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned NumAssocs, SourceLocation DefaultLoc, 3867f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation RParenLoc, 3868f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne bool ContainsUnexpandedParameterPack); 3869f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3870f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne explicit GenericSelectionExpr(EmptyShell Empty) 3871f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne : Expr(GenericSelectionExprClass, Empty) { } 3872f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3873f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned getNumAssocs() const { return NumAssocs; } 3874f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3875f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation getGenericLoc() const { return GenericLoc; } 3876f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation getDefaultLoc() const { return DefaultLoc; } 3877f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation getRParenLoc() const { return RParenLoc; } 3878f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3879f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const Expr *getAssocExpr(unsigned i) const { 3880f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<Expr>(SubExprs[END_EXPR+i]); 3881f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 3882f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Expr *getAssocExpr(unsigned i) { return cast<Expr>(SubExprs[END_EXPR+i]); } 3883f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3884f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const TypeSourceInfo *getAssocTypeSourceInfo(unsigned i) const { 3885f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return AssocTypes[i]; 3886f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 3887f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo *getAssocTypeSourceInfo(unsigned i) { return AssocTypes[i]; } 3888f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3889f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne QualType getAssocType(unsigned i) const { 3890f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (const TypeSourceInfo *TS = getAssocTypeSourceInfo(i)) 3891f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return TS->getType(); 3892f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne else 3893f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return QualType(); 3894f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 3895f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3896f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const Expr *getControllingExpr() const { 3897f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return cast<Expr>(SubExprs[CONTROLLING]); 3898f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 3899f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Expr *getControllingExpr() { return cast<Expr>(SubExprs[CONTROLLING]); } 3900f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3901f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// Whether this generic selection is result-dependent. 3902f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne bool isResultDependent() const { return ResultIndex == -1U; } 3903f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3904f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// The zero-based index of the result expression's generic association in 3905f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// the generic selection's association list. Defined only if the 3906f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// generic selection is not result-dependent. 3907f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned getResultIndex() const { 3908f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne assert(!isResultDependent() && "Generic selection is result-dependent"); 3909f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return ResultIndex; 3910f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 3911f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3912f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// The generic selection's result expression. Defined only if the 3913f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// generic selection is not result-dependent. 3914f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne const Expr *getResultExpr() const { return getAssocExpr(getResultIndex()); } 3915f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Expr *getResultExpr() { return getAssocExpr(getResultIndex()); } 3916f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3917f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceRange getSourceRange() const { 3918f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return SourceRange(GenericLoc, RParenLoc); 3919f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 3920f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne static bool classof(const Stmt *T) { 3921f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return T->getStmtClass() == GenericSelectionExprClass; 3922f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 3923f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne static bool classof(const GenericSelectionExpr *) { return true; } 3924f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3925f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne child_range children() { 3926f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return child_range(SubExprs, SubExprs+END_EXPR+NumAssocs); 3927f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 3928f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 3929f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne friend class ASTStmtReader; 3930f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne}; 3931f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 39324eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===// 39334eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff// Clang Extensions 39344eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff//===----------------------------------------------------------------------===// 39354eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 3936a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 3937a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// ExtVectorElementExpr - This represents access to specific elements of a 3938a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// vector, and may occur on the left hand side or right hand side. For example 3939a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// the following is legal: "V.xy = V.zw" if V is a 4 element extended vector. 3940a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner/// 394173525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// Note that the base may have either vector or pointer to vector type, just 394273525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// like a struct field reference. 394373525de7fd9bdd534382dc89a24f1f76db3e04b9Chris Lattner/// 3944a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerclass ExtVectorElementExpr : public Expr { 3945a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner Stmt *Base; 3946d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor IdentifierInfo *Accessor; 3947a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner SourceLocation AccessorLoc; 3948a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattnerpublic: 3949f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExtVectorElementExpr(QualType ty, ExprValueKind VK, Expr *base, 3950f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall IdentifierInfo &accessor, SourceLocation loc) 39510943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall : Expr(ExtVectorElementExprClass, ty, VK, 39520943168ac126b8047f30f6bd215fbe7db14d61baJohn McCall (VK == VK_RValue ? OK_Ordinary : OK_VectorComponent), 3953bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->isTypeDependent(), base->isValueDependent(), 3954561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor base->isInstantiationDependent(), 3955bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor base->containsUnexpandedParameterPack()), 3956d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor Base(base), Accessor(&accessor), AccessorLoc(loc) {} 39571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3958d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor /// \brief Build an empty vector element expression. 3959d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor explicit ExtVectorElementExpr(EmptyShell Empty) 3960d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor : Expr(ExtVectorElementExprClass, Empty) { } 3961d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 3962a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner const Expr *getBase() const { return cast<Expr>(Base); } 3963a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner Expr *getBase() { return cast<Expr>(Base); } 3964d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setBase(Expr *E) { Base = E; } 3965d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 3966d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor IdentifierInfo &getAccessor() const { return *Accessor; } 3967d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setAccessor(IdentifierInfo *II) { Accessor = II; } 3968d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 3969d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor SourceLocation getAccessorLoc() const { return AccessorLoc; } 3970d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor void setAccessorLoc(SourceLocation L) { AccessorLoc = L; } 3971d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor 3972a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// getNumElements - Get the number of components being selected. 3973a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner unsigned getNumElements() const; 39741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3975a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// containsDuplicateElements - Return true if any element access is 3976a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// repeated. 3977a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner bool containsDuplicateElements() const; 39781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3979a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// getEncodedElementAccess - Encode the elements accessed into an llvm 3980a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner /// aggregate Constant of ConstantInt(s). 3981686775deca8b8685eb90801495880e3abdd844c2Chris Lattner void getEncodedElementAccess(SmallVectorImpl<unsigned> &Elts) const; 39821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 398363c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 3984a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner return SourceRange(getBase()->getLocStart(), AccessorLoc); 3985a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner } 39861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 39872140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner /// isArrow - Return true if the base expression is a pointer to vector, 39882140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner /// return false if the base expression is a vector. 39892140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner bool isArrow() const; 39901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 39911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 39921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == ExtVectorElementExprClass; 3993a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner } 3994a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner static bool classof(const ExtVectorElementExpr *) { return true; } 39951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3996a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner // Iterators 399763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(&Base, &Base+1); } 3998a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner}; 3999a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 4000a09f585a7fdbb01b4bf9de3679fd37005379ca66Chris Lattner 400156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff/// BlockExpr - Adaptor class for mixing a BlockDecl with expressions. 40029c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff/// ^{ statement-body } or ^(int arg1, float arg2){ statement-body } 40034eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockExpr : public Expr { 400456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroffprotected: 400556ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff BlockDecl *TheBlock; 40064eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic: 4007469a1eb996e1cb0be54f9b210f836afbddcbb2ccJohn McCall BlockExpr(BlockDecl *BD, QualType ty) 4008f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall : Expr(BlockExprClass, ty, VK_RValue, OK_Ordinary, 4009561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ty->isDependentType(), false, 4010561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor // FIXME: Check for instantiate-dependence in the statement? 4011561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor ty->isInstantiationDependentType(), 4012561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor false), 4013469a1eb996e1cb0be54f9b210f836afbddcbb2ccJohn McCall TheBlock(BD) {} 40149c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 401584af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor /// \brief Build an empty block expression. 401684af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor explicit BlockExpr(EmptyShell Empty) : Expr(BlockExprClass, Empty) { } 401784af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor 4018d5cab5435371b8cc74a9e05ebd40b5995ebad149Anders Carlsson const BlockDecl *getBlockDecl() const { return TheBlock; } 401956ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff BlockDecl *getBlockDecl() { return TheBlock; } 402084af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor void setBlockDecl(BlockDecl *BD) { TheBlock = BD; } 402184af7c27cdc615ff917a501d61256b4049383c97Douglas Gregor 402256ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff // Convenience functions for probing the underlying BlockDecl. 402356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff SourceLocation getCaretLocation() const; 402456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff const Stmt *getBody() const; 402556ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff Stmt *getBody(); 40269c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 402763c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { 402856ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff return SourceRange(getCaretLocation(), getBody()->getLocEnd()); 40299c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff } 40309c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff 403156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff /// getFunctionType - Return the underlying function type for this block. 403256ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff const FunctionType *getFunctionType() const; 403356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 40341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 40359c3c902835ef7d37300463ad47176ec21a67dc8bSteve Naroff return T->getStmtClass() == BlockExprClass; 40364eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff } 40374eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff static bool classof(const BlockExpr *) { return true; } 40381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 40394eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff // Iterators 404063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 40414eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff}; 40421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 40436b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall/// BlockDeclRefExpr - A reference to a local variable declared in an 40446b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall/// enclosing scope. 40454eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffclass BlockDeclRefExpr : public Expr { 40466b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall VarDecl *D; 40474eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff SourceLocation Loc; 40487d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool IsByRef : 1; 40497d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool ConstQualAdded : 1; 40504eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffpublic: 40516b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall BlockDeclRefExpr(VarDecl *d, QualType t, ExprValueKind VK, 40526b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall SourceLocation l, bool ByRef, bool constAdded = false); 405394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 405494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor // \brief Build an empty reference to a declared variable in a 405594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor // block. 405694cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor explicit BlockDeclRefExpr(EmptyShell Empty) 405794cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor : Expr(BlockDeclRefExprClass, Empty) { } 40581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 40596b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall VarDecl *getDecl() { return D; } 40606b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall const VarDecl *getDecl() const { return D; } 40616b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall void setDecl(VarDecl *VD) { D = VD; } 406294cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 406394cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor SourceLocation getLocation() const { return Loc; } 406494cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setLocation(SourceLocation L) { Loc = L; } 406594cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 406663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall SourceRange getSourceRange() const { return SourceRange(Loc); } 40671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 40684eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff bool isByRef() const { return IsByRef; } 406994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor void setByRef(bool BR) { IsByRef = BR; } 40701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 40717d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian bool isConstQualAdded() const { return ConstQualAdded; } 40727d5c74ecbbd8719436c071f38657bc8e97ee4a24Fariborz Jahanian void setConstQualAdded(bool C) { ConstQualAdded = C; } 407389f9d3a7651d1225f3f56ae3387c83b98a26da00Fariborz Jahanian 40741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Stmt *T) { 40751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getStmtClass() == BlockDeclRefExprClass; 40764eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff } 40774eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff static bool classof(const BlockDeclRefExpr *) { return true; } 40781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 40794eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff // Iterators 408063c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall child_range children() { return child_range(); } 40814eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff}; 40824eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 408361eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner/// AsTypeExpr - Clang builtin function __builtin_astype [OpenCL 6.2.4.2] 408461eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner/// This AST node provides support for reinterpreting a type to another 408561eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner/// type of the same size. 4086379010addb0e84fd0fbc37c829baf658958521bdJohn McCallclass AsTypeExpr : public Expr { // Should this be an ExplicitCastExpr? 408761eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattnerprivate: 4088379010addb0e84fd0fbc37c829baf658958521bdJohn McCall Stmt *SrcExpr; 408961eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner SourceLocation BuiltinLoc, RParenLoc; 4090379010addb0e84fd0fbc37c829baf658958521bdJohn McCall 4091379010addb0e84fd0fbc37c829baf658958521bdJohn McCall friend class ASTReader; 4092379010addb0e84fd0fbc37c829baf658958521bdJohn McCall friend class ASTStmtReader; 4093379010addb0e84fd0fbc37c829baf658958521bdJohn McCall explicit AsTypeExpr(EmptyShell Empty) : Expr(AsTypeExprClass, Empty) {} 409461eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner 409561eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattnerpublic: 409661eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner AsTypeExpr(Expr* SrcExpr, QualType DstType, 409761eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner ExprValueKind VK, ExprObjectKind OK, 409861eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner SourceLocation BuiltinLoc, SourceLocation RParenLoc) 4099561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor : Expr(AsTypeExprClass, DstType, VK, OK, 4100561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor DstType->isDependentType(), 4101561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor DstType->isDependentType() || SrcExpr->isValueDependent(), 4102561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (DstType->isInstantiationDependentType() || 4103561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor SrcExpr->isInstantiationDependent()), 4104561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor (DstType->containsUnexpandedParameterPack() || 4105561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor SrcExpr->containsUnexpandedParameterPack())), 4106379010addb0e84fd0fbc37c829baf658958521bdJohn McCall SrcExpr(SrcExpr), BuiltinLoc(BuiltinLoc), RParenLoc(RParenLoc) {} 410761eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner 410861eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner /// getSrcExpr - Return the Expr to be converted. 4109379010addb0e84fd0fbc37c829baf658958521bdJohn McCall Expr *getSrcExpr() const { return cast<Expr>(SrcExpr); } 4110379010addb0e84fd0fbc37c829baf658958521bdJohn McCall 4111379010addb0e84fd0fbc37c829baf658958521bdJohn McCall /// getBuiltinLoc - Return the location of the __builtin_astype token. 4112379010addb0e84fd0fbc37c829baf658958521bdJohn McCall SourceLocation getBuiltinLoc() const { return BuiltinLoc; } 4113379010addb0e84fd0fbc37c829baf658958521bdJohn McCall 4114379010addb0e84fd0fbc37c829baf658958521bdJohn McCall /// getRParenLoc - Return the location of final right parenthesis. 4115379010addb0e84fd0fbc37c829baf658958521bdJohn McCall SourceLocation getRParenLoc() const { return RParenLoc; } 411661eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner 41177b33c2b3908b178511ccaace8cacb5e5b14552a9Nick Lewycky SourceRange getSourceRange() const { 411861eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner return SourceRange(BuiltinLoc, RParenLoc); 411961eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner } 412061eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner 412161eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner static bool classof(const Stmt *T) { 412261eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner return T->getStmtClass() == AsTypeExprClass; 412361eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner } 412461eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner static bool classof(const AsTypeExpr *) { return true; } 412561eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner 412661eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner // Iterators 4127379010addb0e84fd0fbc37c829baf658958521bdJohn McCall child_range children() { return child_range(&SrcExpr, &SrcExpr+1); } 412861eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner}; 41295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 41305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 41315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 4132